png.c revision 847370c32c6b67817205f49897c43c540fd670c4
13ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 23ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 33ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 43ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 53ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 63ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% PPPP N N GGGG % 73ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% P P NN N G % 83ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% PPPP N N N G GG % 93ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% P N NN G G % 103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% P N N GGG % 113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Read/Write Portable Network Graphics Image Format % 143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Software Design % 163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% John Cristy % 173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Glenn Randers-Pehrson % 183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% November 1997 % 193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 217e41fe84a841d7b9d7b36b245b65e9dcb3314943cristy% Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization % 223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% dedicated to making software imaging solutions freely available. % 233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% You may not use this file except in compliance with the License. You may % 253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% obtain a copy of the License at % 263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% http://www.imagemagick.org/script/license.php % 283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Unless required by applicable law or agreed to in writing, software % 303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% distributed under the License is distributed on an "AS IS" BASIS, % 313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % 323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% See the License for the specific language governing permissions and % 333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% limitations under the License. % 343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Include declarations. 433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 444c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/studio.h" 454c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/artifact.h" 464c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/attribute.h" 474c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/blob.h" 484c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/blob-private.h" 494c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/cache.h" 504c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/color.h" 514c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/color-private.h" 524c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/colormap.h" 534c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/colorspace.h" 544c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/constitute.h" 554c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/enhance.h" 564c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/exception.h" 574c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/exception-private.h" 584c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/geometry.h" 594c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/histogram.h" 604c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/image.h" 614c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/image-private.h" 624c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/layer.h" 634c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/list.h" 644c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/log.h" 654c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/MagickCore.h" 664c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/memory_.h" 674c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/module.h" 684c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/monitor.h" 694c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/monitor-private.h" 704c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/option.h" 714c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/pixel.h" 724c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/pixel-accessor.h" 734c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/profile.h" 744c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/property.h" 754c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/quantum-private.h" 764c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/resource_.h" 774c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/semaphore.h" 784c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/quantum-private.h" 794c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/static.h" 804c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/statistic.h" 814c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/string_.h" 824c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/string-private.h" 834c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/transform.h" 844c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/utility.h" 853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_PNG_DELEGATE) 86286a6355c4544b794da2b6df973faad07c69e541glennrp 877ef138c2e0e2bd4acefd810968b0324f6dc469f1glennrp/* Suppress libpng pedantic warnings that were added in 887ef138c2e0e2bd4acefd810968b0324f6dc469f1glennrp * libpng-1.2.41 and libpng-1.4.0. If you are working on 89faa852bad40107edae19405e76a299057668d795glennrp * migration to libpng-1.5, remove these defines and then 907ef138c2e0e2bd4acefd810968b0324f6dc469f1glennrp * fix any code that generates warnings. 917ef138c2e0e2bd4acefd810968b0324f6dc469f1glennrp */ 92991e92a91acb9e432cd6c05843e4f6a57643e29dglennrp/* #define PNG_DEPRECATED Use of this function is deprecated */ 93faa852bad40107edae19405e76a299057668d795glennrp/* #define PNG_USE_RESULT The result of this function must be checked */ 94faa852bad40107edae19405e76a299057668d795glennrp/* #define PNG_NORETURN This function does not return */ 95faa852bad40107edae19405e76a299057668d795glennrp/* #define PNG_ALLOCATED The result of the function is new memory */ 968371ecc013ff231ce380d8717e517312e62e1f01glennrp/* #define PNG_DEPSTRUCT Access to this struct member is deprecated */ 975b927348e949d94f3a64b055eccb03459f115c69glennrp 985b927348e949d94f3a64b055eccb03459f115c69glennrp/* PNG_PTR_NORETURN does not work on some platforms, in libpng-1.5.x */ 9975cfe702843fd25dba7cb241c05fa65957c67129cristy#define PNG_PTR_NORETURN 100286a6355c4544b794da2b6df973faad07c69e541glennrp 1013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "png.h" 1023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "zlib.h" 1033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* ImageMagick differences */ 1053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define first_scene scene 1063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 107d5045b44ae266ec7d6d2fca5e7c8a69a28938ec4glennrp#if PNG_LIBPNG_VER > 10011 1083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 1093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Optional declarations. Define or undefine them as you like. 1103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 1113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* #define PNG_DEBUG -- turning this on breaks VisualC compiling */ 1123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 1143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Features under construction. Define these to work on them. 1153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 1163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#undef MNG_OBJECT_BUFFERS 1173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#undef MNG_BASI_SUPPORTED 1183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define MNG_COALESCE_LAYERS /* In 5.4.4, this interfered with MMAP'ed files. */ 1193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define MNG_INSERT_LAYERS /* Troublesome, but seem to work as of 5.4.4 */ 1203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_JPEG_DELEGATE) 1213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy# define JNG_SUPPORTED /* Not finished as of 5.5.2. See "To do" comments. */ 1223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 1233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if !defined(RGBColorMatchExact) 1243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define IsPNGColorEqual(color,target) \ 1258e045c8f9e00ec89df5b20bf07c059d60e7aaa77glennrp (((color).red == (target).red) && \ 1268e045c8f9e00ec89df5b20bf07c059d60e7aaa77glennrp ((color).green == (target).green) && \ 1278e045c8f9e00ec89df5b20bf07c059d60e7aaa77glennrp ((color).blue == (target).blue)) 1283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 1293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1308e58efdecda887b08ef730d68290a61081ef2566glennrp/* Macros for left-bit-replication to ensure that pixels 1318e58efdecda887b08ef730d68290a61081ef2566glennrp * and PixelPackets all have the image->depth, and for use 1328e58efdecda887b08ef730d68290a61081ef2566glennrp * in PNG8 quantization. 1338e58efdecda887b08ef730d68290a61081ef2566glennrp */ 1348e58efdecda887b08ef730d68290a61081ef2566glennrp 1358e58efdecda887b08ef730d68290a61081ef2566glennrp 1368e58efdecda887b08ef730d68290a61081ef2566glennrp/* LBR01: Replicate top bit */ 1378e58efdecda887b08ef730d68290a61081ef2566glennrp 1384c08aed51c5899665ade97263692328eea4af106cristy#define LBR01PixelPacketRed(pixelpacket) \ 1398e58efdecda887b08ef730d68290a61081ef2566glennrp (pixelpacket).red=(ScaleQuantumToChar((pixelpacket).red) < 0x10 ? \ 1408e58efdecda887b08ef730d68290a61081ef2566glennrp 0 : QuantumRange); 1418e58efdecda887b08ef730d68290a61081ef2566glennrp 14291d99255dd77083750426ba5463e002a586bc9a6glennrp#define LBR01PacketGreen(pixelpacket) \ 1438e58efdecda887b08ef730d68290a61081ef2566glennrp (pixelpacket).green=(ScaleQuantumToChar((pixelpacket).green) < 0x10 ? \ 1448e58efdecda887b08ef730d68290a61081ef2566glennrp 0 : QuantumRange); 1458e58efdecda887b08ef730d68290a61081ef2566glennrp 14691d99255dd77083750426ba5463e002a586bc9a6glennrp#define LBR01PacketBlue(pixelpacket) \ 1478e58efdecda887b08ef730d68290a61081ef2566glennrp (pixelpacket).blue=(ScaleQuantumToChar((pixelpacket).blue) < 0x10 ? \ 1488e58efdecda887b08ef730d68290a61081ef2566glennrp 0 : QuantumRange); 1498e58efdecda887b08ef730d68290a61081ef2566glennrp 1504c08aed51c5899665ade97263692328eea4af106cristy#define LBR01PacketAlpha(pixelpacket) \ 1514c08aed51c5899665ade97263692328eea4af106cristy (pixelpacket).alpha=(ScaleQuantumToChar((pixelpacket).alpha) < 0x10 ? \ 1528e58efdecda887b08ef730d68290a61081ef2566glennrp 0 : QuantumRange); 1538e58efdecda887b08ef730d68290a61081ef2566glennrp 15491d99255dd77083750426ba5463e002a586bc9a6glennrp#define LBR01PacketRGB(pixelpacket) \ 155bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp { \ 1564c08aed51c5899665ade97263692328eea4af106cristy LBR01PixelPacketRed((pixelpacket)); \ 15791d99255dd77083750426ba5463e002a586bc9a6glennrp LBR01PacketGreen((pixelpacket)); \ 15891d99255dd77083750426ba5463e002a586bc9a6glennrp LBR01PacketBlue((pixelpacket)); \ 159bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp } 1608e58efdecda887b08ef730d68290a61081ef2566glennrp 16191d99255dd77083750426ba5463e002a586bc9a6glennrp#define LBR01PacketRGBO(pixelpacket) \ 162bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp { \ 16391d99255dd77083750426ba5463e002a586bc9a6glennrp LBR01PacketRGB((pixelpacket)); \ 1644c08aed51c5899665ade97263692328eea4af106cristy LBR01PacketAlpha((pixelpacket)); \ 165bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp } 1668e58efdecda887b08ef730d68290a61081ef2566glennrp 167ef61831f94757bbb7fd66e3f5d1aca8a19c0b58ecristy#define LBR01PixelRed(pixel) \ 1684c08aed51c5899665ade97263692328eea4af106cristy (ScaleQuantumToChar(GetPixelRed(image,(pixel))) < 0x10 ? \ 1698e58efdecda887b08ef730d68290a61081ef2566glennrp 0 : QuantumRange); 1708e58efdecda887b08ef730d68290a61081ef2566glennrp 1714c08aed51c5899665ade97263692328eea4af106cristy#define LBR01Green(pixel) \ 1724c08aed51c5899665ade97263692328eea4af106cristy (ScaleQuantumToChar(GetPixelGreen(image,(pixel))) < 0x10 ? \ 1738e58efdecda887b08ef730d68290a61081ef2566glennrp 0 : QuantumRange); 1748e58efdecda887b08ef730d68290a61081ef2566glennrp 1754c08aed51c5899665ade97263692328eea4af106cristy#define LBR01Blue(pixel) \ 1764c08aed51c5899665ade97263692328eea4af106cristy (ScaleQuantumToChar(GetPixelBlue(image,(pixel))) < 0x10 ? \ 1778e58efdecda887b08ef730d68290a61081ef2566glennrp 0 : QuantumRange); 1788e58efdecda887b08ef730d68290a61081ef2566glennrp 1794c08aed51c5899665ade97263692328eea4af106cristy#define LBR01Alpha(pixel) \ 1804c08aed51c5899665ade97263692328eea4af106cristy (ScaleQuantumToChar(GetPixelAlpha(image,(pixel))) < 0x10 ? \ 1818e58efdecda887b08ef730d68290a61081ef2566glennrp 0 : QuantumRange); 1828e58efdecda887b08ef730d68290a61081ef2566glennrp 1834c08aed51c5899665ade97263692328eea4af106cristy#define LBR01RGB(pixel) \ 184bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp { \ 185ef61831f94757bbb7fd66e3f5d1aca8a19c0b58ecristy LBR01PixelRed((pixel)); \ 1864c08aed51c5899665ade97263692328eea4af106cristy LBR01Green((pixel)); \ 1874c08aed51c5899665ade97263692328eea4af106cristy LBR01Blue((pixel)); \ 188bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp } 1898e58efdecda887b08ef730d68290a61081ef2566glennrp 1904c08aed51c5899665ade97263692328eea4af106cristy#define LBR01RGBA(pixel) \ 191bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp { \ 1924c08aed51c5899665ade97263692328eea4af106cristy LBR01RGB((pixel)); \ 1934c08aed51c5899665ade97263692328eea4af106cristy LBR01Alpha((pixel)); \ 194bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp } 1958e58efdecda887b08ef730d68290a61081ef2566glennrp 1968e58efdecda887b08ef730d68290a61081ef2566glennrp/* LBR02: Replicate top 2 bits */ 1978e58efdecda887b08ef730d68290a61081ef2566glennrp 1984c08aed51c5899665ade97263692328eea4af106cristy#define LBR02PixelPacketRed(pixelpacket) \ 1998e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 2008e58efdecda887b08ef730d68290a61081ef2566glennrp unsigned char lbr_bits=ScaleQuantumToChar((pixelpacket).red) & 0xc0; \ 2018e58efdecda887b08ef730d68290a61081ef2566glennrp (pixelpacket).red=ScaleCharToQuantum( \ 2028e58efdecda887b08ef730d68290a61081ef2566glennrp (lbr_bits | (lbr_bits >> 2) | (lbr_bits >> 4) | (lbr_bits >> 6))); \ 2038e58efdecda887b08ef730d68290a61081ef2566glennrp } 20491d99255dd77083750426ba5463e002a586bc9a6glennrp#define LBR02PacketGreen(pixelpacket) \ 2058e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 2068e58efdecda887b08ef730d68290a61081ef2566glennrp unsigned char lbr_bits=ScaleQuantumToChar((pixelpacket).green) & 0xc0; \ 2078e58efdecda887b08ef730d68290a61081ef2566glennrp (pixelpacket).green=ScaleCharToQuantum( \ 2088e58efdecda887b08ef730d68290a61081ef2566glennrp (lbr_bits | (lbr_bits >> 2) | (lbr_bits >> 4) | (lbr_bits >> 6))); \ 2098e58efdecda887b08ef730d68290a61081ef2566glennrp } 21091d99255dd77083750426ba5463e002a586bc9a6glennrp#define LBR02PacketBlue(pixelpacket) \ 2118e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 2128e58efdecda887b08ef730d68290a61081ef2566glennrp unsigned char lbr_bits=ScaleQuantumToChar((pixelpacket).blue) & 0xc0; \ 2138e58efdecda887b08ef730d68290a61081ef2566glennrp (pixelpacket).blue=ScaleCharToQuantum( \ 2148e58efdecda887b08ef730d68290a61081ef2566glennrp (lbr_bits | (lbr_bits >> 2) | (lbr_bits >> 4) | (lbr_bits >> 6))); \ 2158e58efdecda887b08ef730d68290a61081ef2566glennrp } 2164c08aed51c5899665ade97263692328eea4af106cristy#define LBR02PacketAlpha(pixelpacket) \ 2178e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 2184c08aed51c5899665ade97263692328eea4af106cristy unsigned char lbr_bits=ScaleQuantumToChar((pixelpacket).alpha) & 0xc0; \ 2194c08aed51c5899665ade97263692328eea4af106cristy (pixelpacket).alpha=ScaleCharToQuantum( \ 2208e58efdecda887b08ef730d68290a61081ef2566glennrp (lbr_bits | (lbr_bits >> 2) | (lbr_bits >> 4) | (lbr_bits >> 6))); \ 2218e58efdecda887b08ef730d68290a61081ef2566glennrp } 2228e58efdecda887b08ef730d68290a61081ef2566glennrp 22391d99255dd77083750426ba5463e002a586bc9a6glennrp#define LBR02PacketRGB(pixelpacket) \ 224bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp { \ 2254c08aed51c5899665ade97263692328eea4af106cristy LBR02PixelPacketRed((pixelpacket)); \ 22691d99255dd77083750426ba5463e002a586bc9a6glennrp LBR02PacketGreen((pixelpacket)); \ 22791d99255dd77083750426ba5463e002a586bc9a6glennrp LBR02PacketBlue((pixelpacket)); \ 228bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp } 2298e58efdecda887b08ef730d68290a61081ef2566glennrp 23091d99255dd77083750426ba5463e002a586bc9a6glennrp#define LBR02PacketRGBO(pixelpacket) \ 231bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp { \ 23291d99255dd77083750426ba5463e002a586bc9a6glennrp LBR02PacketRGB((pixelpacket)); \ 2334c08aed51c5899665ade97263692328eea4af106cristy LBR02PacketAlpha((pixelpacket)); \ 234bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp } 2358e58efdecda887b08ef730d68290a61081ef2566glennrp 236ef61831f94757bbb7fd66e3f5d1aca8a19c0b58ecristy#define LBR02PixelRed(pixel) \ 2378e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 2384c08aed51c5899665ade97263692328eea4af106cristy unsigned char lbr_bits=ScaleQuantumToChar(GetPixelRed(image,(pixel))) \ 2398e58efdecda887b08ef730d68290a61081ef2566glennrp & 0xc0; \ 2404c08aed51c5899665ade97263692328eea4af106cristy SetPixelRed(image, ScaleCharToQuantum( \ 241847370c32c6b67817205f49897c43c540fd670c4glennrp (lbr_bits | (lbr_bits >> 2) | (lbr_bits >> 4) | (lbr_bits >> 6))), \ 242847370c32c6b67817205f49897c43c540fd670c4glennrp (pixel)); \ 2438e58efdecda887b08ef730d68290a61081ef2566glennrp } 2444c08aed51c5899665ade97263692328eea4af106cristy#define LBR02Green(pixel) \ 2458e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 2464c08aed51c5899665ade97263692328eea4af106cristy unsigned char lbr_bits=ScaleQuantumToChar(GetPixelGreen(image,(pixel)))\ 2478e58efdecda887b08ef730d68290a61081ef2566glennrp & 0xc0; \ 2484c08aed51c5899665ade97263692328eea4af106cristy SetPixelGreen(image, ScaleCharToQuantum( \ 249847370c32c6b67817205f49897c43c540fd670c4glennrp (lbr_bits | (lbr_bits >> 2) | (lbr_bits >> 4) | (lbr_bits >> 6))), \ 250847370c32c6b67817205f49897c43c540fd670c4glennrp (pixel)); \ 2518e58efdecda887b08ef730d68290a61081ef2566glennrp } 2524c08aed51c5899665ade97263692328eea4af106cristy#define LBR02Blue(pixel) \ 2538e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 2548e58efdecda887b08ef730d68290a61081ef2566glennrp unsigned char lbr_bits= \ 2554c08aed51c5899665ade97263692328eea4af106cristy ScaleQuantumToChar(GetPixelBlue(image,(pixel))) & 0xc0; \ 2564c08aed51c5899665ade97263692328eea4af106cristy SetPixelBlue(image, ScaleCharToQuantum( \ 257847370c32c6b67817205f49897c43c540fd670c4glennrp (lbr_bits | (lbr_bits >> 2) | (lbr_bits >> 4) | (lbr_bits >> 6))), \ 258847370c32c6b67817205f49897c43c540fd670c4glennrp (pixel)); \ 2598e58efdecda887b08ef730d68290a61081ef2566glennrp } 2604c08aed51c5899665ade97263692328eea4af106cristy#define LBR02Alpha(pixel) \ 2618e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 2628e58efdecda887b08ef730d68290a61081ef2566glennrp unsigned char lbr_bits= \ 2634c08aed51c5899665ade97263692328eea4af106cristy ScaleQuantumToChar(GetPixelAlpha(image,(pixel))) & 0xc0; \ 2644c08aed51c5899665ade97263692328eea4af106cristy SetPixelAlpha(image, ScaleCharToQuantum( \ 265847370c32c6b67817205f49897c43c540fd670c4glennrp (lbr_bits | (lbr_bits >> 2) | (lbr_bits >> 4) | (lbr_bits >> 6))), \ 266847370c32c6b67817205f49897c43c540fd670c4glennrp (pixel) ); \ 2678e58efdecda887b08ef730d68290a61081ef2566glennrp } 2688e58efdecda887b08ef730d68290a61081ef2566glennrp 2694c08aed51c5899665ade97263692328eea4af106cristy#define LBR02RGB(pixel) \ 270bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp { \ 271ef61831f94757bbb7fd66e3f5d1aca8a19c0b58ecristy LBR02PixelRed((pixel)); \ 2724c08aed51c5899665ade97263692328eea4af106cristy LBR02Green((pixel)); \ 2734c08aed51c5899665ade97263692328eea4af106cristy LBR02Blue((pixel)); \ 274bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp } 2758e58efdecda887b08ef730d68290a61081ef2566glennrp 2764c08aed51c5899665ade97263692328eea4af106cristy#define LBR02RGBA(pixel) \ 277bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp { \ 2784c08aed51c5899665ade97263692328eea4af106cristy LBR02RGB((pixel)); \ 2794c08aed51c5899665ade97263692328eea4af106cristy LBR02Alpha((pixel)); \ 280bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp } 2818e58efdecda887b08ef730d68290a61081ef2566glennrp 2828e58efdecda887b08ef730d68290a61081ef2566glennrp/* LBR03: Replicate top 3 bits (only used with opaque pixels during 2838e58efdecda887b08ef730d68290a61081ef2566glennrp PNG8 quantization) */ 2848e58efdecda887b08ef730d68290a61081ef2566glennrp 2854c08aed51c5899665ade97263692328eea4af106cristy#define LBR03PixelPacketRed(pixelpacket) \ 2868e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 2878e58efdecda887b08ef730d68290a61081ef2566glennrp unsigned char lbr_bits=ScaleQuantumToChar((pixelpacket).red) & 0xe0; \ 2888e58efdecda887b08ef730d68290a61081ef2566glennrp (pixelpacket).red=ScaleCharToQuantum( \ 2898e58efdecda887b08ef730d68290a61081ef2566glennrp (lbr_bits | (lbr_bits >> 3) | (lbr_bits >> 6))); \ 2908e58efdecda887b08ef730d68290a61081ef2566glennrp } 29191d99255dd77083750426ba5463e002a586bc9a6glennrp#define LBR03PacketGreen(pixelpacket) \ 2928e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 2938e58efdecda887b08ef730d68290a61081ef2566glennrp unsigned char lbr_bits=ScaleQuantumToChar((pixelpacket).green) & 0xe0; \ 2948e58efdecda887b08ef730d68290a61081ef2566glennrp (pixelpacket).green=ScaleCharToQuantum( \ 2958e58efdecda887b08ef730d68290a61081ef2566glennrp (lbr_bits | (lbr_bits >> 3) | (lbr_bits >> 6))); \ 2968e58efdecda887b08ef730d68290a61081ef2566glennrp } 29791d99255dd77083750426ba5463e002a586bc9a6glennrp#define LBR03PacketBlue(pixelpacket) \ 2988e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 2998e58efdecda887b08ef730d68290a61081ef2566glennrp unsigned char lbr_bits=ScaleQuantumToChar((pixelpacket).blue) & 0xe0; \ 3008e58efdecda887b08ef730d68290a61081ef2566glennrp (pixelpacket).blue=ScaleCharToQuantum( \ 3018e58efdecda887b08ef730d68290a61081ef2566glennrp (lbr_bits | (lbr_bits >> 3) | (lbr_bits >> 6))); \ 3028e58efdecda887b08ef730d68290a61081ef2566glennrp } 3038e58efdecda887b08ef730d68290a61081ef2566glennrp 30491d99255dd77083750426ba5463e002a586bc9a6glennrp#define LBR03PacketRGB(pixelpacket) \ 305bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp { \ 3064c08aed51c5899665ade97263692328eea4af106cristy LBR03PixelPacketRed((pixelpacket)); \ 30791d99255dd77083750426ba5463e002a586bc9a6glennrp LBR03PacketGreen((pixelpacket)); \ 30891d99255dd77083750426ba5463e002a586bc9a6glennrp LBR03PacketBlue((pixelpacket)); \ 309bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp } 3108e58efdecda887b08ef730d68290a61081ef2566glennrp 311ef61831f94757bbb7fd66e3f5d1aca8a19c0b58ecristy#define LBR03PixelRed(pixel) \ 3128e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 3134c08aed51c5899665ade97263692328eea4af106cristy unsigned char lbr_bits=ScaleQuantumToChar(GetPixelRed(image,(pixel))) \ 3148e58efdecda887b08ef730d68290a61081ef2566glennrp & 0xe0; \ 3154c08aed51c5899665ade97263692328eea4af106cristy SetPixelRed(image, ScaleCharToQuantum( \ 3164c08aed51c5899665ade97263692328eea4af106cristy (lbr_bits | (lbr_bits >> 3) | (lbr_bits >> 6))), (pixel)); \ 3178e58efdecda887b08ef730d68290a61081ef2566glennrp } 3184c08aed51c5899665ade97263692328eea4af106cristy#define LBR03Green(pixel) \ 3198e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 3204c08aed51c5899665ade97263692328eea4af106cristy unsigned char lbr_bits=ScaleQuantumToChar(GetPixelGreen(image,(pixel)))\ 3218e58efdecda887b08ef730d68290a61081ef2566glennrp & 0xe0; \ 3224c08aed51c5899665ade97263692328eea4af106cristy SetPixelGreen(image, ScaleCharToQuantum( \ 3234c08aed51c5899665ade97263692328eea4af106cristy (lbr_bits | (lbr_bits >> 3) | (lbr_bits >> 6))), (pixel)); \ 3248e58efdecda887b08ef730d68290a61081ef2566glennrp } 3254c08aed51c5899665ade97263692328eea4af106cristy#define LBR03Blue(pixel) \ 3268e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 3274c08aed51c5899665ade97263692328eea4af106cristy unsigned char lbr_bits=ScaleQuantumToChar(GetPixelBlue(image,(pixel))) \ 3288e58efdecda887b08ef730d68290a61081ef2566glennrp & 0xe0; \ 3294c08aed51c5899665ade97263692328eea4af106cristy SetPixelBlue(image, ScaleCharToQuantum( \ 3304c08aed51c5899665ade97263692328eea4af106cristy (lbr_bits | (lbr_bits >> 3) | (lbr_bits >> 6))), (pixel)); \ 3318e58efdecda887b08ef730d68290a61081ef2566glennrp } 3328e58efdecda887b08ef730d68290a61081ef2566glennrp 3334c08aed51c5899665ade97263692328eea4af106cristy#define LBR03RGB(pixel) \ 334bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp { \ 335ef61831f94757bbb7fd66e3f5d1aca8a19c0b58ecristy LBR03PixelRed((pixel)); \ 3364c08aed51c5899665ade97263692328eea4af106cristy LBR03Green((pixel)); \ 3374c08aed51c5899665ade97263692328eea4af106cristy LBR03Blue((pixel)); \ 338bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp } 3398e58efdecda887b08ef730d68290a61081ef2566glennrp 3408e58efdecda887b08ef730d68290a61081ef2566glennrp/* LBR04: Replicate top 4 bits */ 3418e58efdecda887b08ef730d68290a61081ef2566glennrp 3424c08aed51c5899665ade97263692328eea4af106cristy#define LBR04PixelPacketRed(pixelpacket) \ 3438e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 3448e58efdecda887b08ef730d68290a61081ef2566glennrp unsigned char lbr_bits=ScaleQuantumToChar((pixelpacket).red) & 0xf0; \ 3458e58efdecda887b08ef730d68290a61081ef2566glennrp (pixelpacket).red=ScaleCharToQuantum((lbr_bits | (lbr_bits >> 4))); \ 3468e58efdecda887b08ef730d68290a61081ef2566glennrp } 34791d99255dd77083750426ba5463e002a586bc9a6glennrp#define LBR04PacketGreen(pixelpacket) \ 3488e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 3498e58efdecda887b08ef730d68290a61081ef2566glennrp unsigned char lbr_bits=ScaleQuantumToChar((pixelpacket).green) & 0xf0; \ 3508e58efdecda887b08ef730d68290a61081ef2566glennrp (pixelpacket).green=ScaleCharToQuantum((lbr_bits | (lbr_bits >> 4))); \ 3518e58efdecda887b08ef730d68290a61081ef2566glennrp } 35291d99255dd77083750426ba5463e002a586bc9a6glennrp#define LBR04PacketBlue(pixelpacket) \ 3538e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 3548e58efdecda887b08ef730d68290a61081ef2566glennrp unsigned char lbr_bits=ScaleQuantumToChar((pixelpacket).blue) & 0xf0; \ 3558e58efdecda887b08ef730d68290a61081ef2566glennrp (pixelpacket).blue=ScaleCharToQuantum((lbr_bits | (lbr_bits >> 4))); \ 3568e58efdecda887b08ef730d68290a61081ef2566glennrp } 3574c08aed51c5899665ade97263692328eea4af106cristy#define LBR04PacketAlpha(pixelpacket) \ 3588e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 3594c08aed51c5899665ade97263692328eea4af106cristy unsigned char lbr_bits=ScaleQuantumToChar((pixelpacket).alpha) & 0xf0; \ 3604c08aed51c5899665ade97263692328eea4af106cristy (pixelpacket).alpha=ScaleCharToQuantum((lbr_bits | (lbr_bits >> 4))); \ 3618e58efdecda887b08ef730d68290a61081ef2566glennrp } 3628e58efdecda887b08ef730d68290a61081ef2566glennrp 36391d99255dd77083750426ba5463e002a586bc9a6glennrp#define LBR04PacketRGB(pixelpacket) \ 364bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp { \ 3654c08aed51c5899665ade97263692328eea4af106cristy LBR04PixelPacketRed((pixelpacket)); \ 36691d99255dd77083750426ba5463e002a586bc9a6glennrp LBR04PacketGreen((pixelpacket)); \ 36791d99255dd77083750426ba5463e002a586bc9a6glennrp LBR04PacketBlue((pixelpacket)); \ 368bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp } 3698e58efdecda887b08ef730d68290a61081ef2566glennrp 37091d99255dd77083750426ba5463e002a586bc9a6glennrp#define LBR04PacketRGBO(pixelpacket) \ 371bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp { \ 37291d99255dd77083750426ba5463e002a586bc9a6glennrp LBR04PacketRGB((pixelpacket)); \ 3734c08aed51c5899665ade97263692328eea4af106cristy LBR04PacketAlpha((pixelpacket)); \ 374bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp } 3758e58efdecda887b08ef730d68290a61081ef2566glennrp 376ef61831f94757bbb7fd66e3f5d1aca8a19c0b58ecristy#define LBR04PixelRed(pixel) \ 3778e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 3784c08aed51c5899665ade97263692328eea4af106cristy unsigned char lbr_bits=ScaleQuantumToChar(GetPixelRed(image,(pixel))) \ 3798e58efdecda887b08ef730d68290a61081ef2566glennrp & 0xf0; \ 3804c08aed51c5899665ade97263692328eea4af106cristy SetPixelRed(image,\ 3814c08aed51c5899665ade97263692328eea4af106cristy ScaleCharToQuantum((lbr_bits | (lbr_bits >> 4))), (pixel)); \ 3828e58efdecda887b08ef730d68290a61081ef2566glennrp } 3834c08aed51c5899665ade97263692328eea4af106cristy#define LBR04Green(pixel) \ 3848e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 3854c08aed51c5899665ade97263692328eea4af106cristy unsigned char lbr_bits=ScaleQuantumToChar(GetPixelGreen(image,(pixel)))\ 3868e58efdecda887b08ef730d68290a61081ef2566glennrp & 0xf0; \ 3874c08aed51c5899665ade97263692328eea4af106cristy SetPixelGreen(image,\ 3884c08aed51c5899665ade97263692328eea4af106cristy ScaleCharToQuantum((lbr_bits | (lbr_bits >> 4))), (pixel)); \ 3898e58efdecda887b08ef730d68290a61081ef2566glennrp } 3904c08aed51c5899665ade97263692328eea4af106cristy#define LBR04Blue(pixel) \ 3918e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 3928e58efdecda887b08ef730d68290a61081ef2566glennrp unsigned char lbr_bits= \ 3934c08aed51c5899665ade97263692328eea4af106cristy ScaleQuantumToChar(GetPixelBlue(image,(pixel))) & 0xf0; \ 3944c08aed51c5899665ade97263692328eea4af106cristy SetPixelBlue(image,\ 3954c08aed51c5899665ade97263692328eea4af106cristy ScaleCharToQuantum((lbr_bits | (lbr_bits >> 4))), (pixel)); \ 3968e58efdecda887b08ef730d68290a61081ef2566glennrp } 3974c08aed51c5899665ade97263692328eea4af106cristy#define LBR04Alpha(pixel) \ 3988e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 3998e58efdecda887b08ef730d68290a61081ef2566glennrp unsigned char lbr_bits= \ 4004c08aed51c5899665ade97263692328eea4af106cristy ScaleQuantumToChar(GetPixelAlpha(image,(pixel))) & 0xf0; \ 4014c08aed51c5899665ade97263692328eea4af106cristy SetPixelAlpha(image,\ 4024c08aed51c5899665ade97263692328eea4af106cristy ScaleCharToQuantum((lbr_bits | (lbr_bits >> 4))), (pixel)); \ 4038e58efdecda887b08ef730d68290a61081ef2566glennrp } 4048e58efdecda887b08ef730d68290a61081ef2566glennrp 4054c08aed51c5899665ade97263692328eea4af106cristy#define LBR04RGB(pixel) \ 406bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp { \ 407ef61831f94757bbb7fd66e3f5d1aca8a19c0b58ecristy LBR04PixelRed((pixel)); \ 4084c08aed51c5899665ade97263692328eea4af106cristy LBR04Green((pixel)); \ 4094c08aed51c5899665ade97263692328eea4af106cristy LBR04Blue((pixel)); \ 410bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp } 4118e58efdecda887b08ef730d68290a61081ef2566glennrp 4124c08aed51c5899665ade97263692328eea4af106cristy#define LBR04RGBA(pixel) \ 413bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp { \ 4144c08aed51c5899665ade97263692328eea4af106cristy LBR04RGB((pixel)); \ 4154c08aed51c5899665ade97263692328eea4af106cristy LBR04Alpha((pixel)); \ 416bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp } 4178e58efdecda887b08ef730d68290a61081ef2566glennrp 4188e58efdecda887b08ef730d68290a61081ef2566glennrp 4198e58efdecda887b08ef730d68290a61081ef2566glennrp/* LBR08: Replicate top 8 bits */ 4208e58efdecda887b08ef730d68290a61081ef2566glennrp 4214c08aed51c5899665ade97263692328eea4af106cristy#define LBR08PixelPacketRed(pixelpacket) \ 4228e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 4238e58efdecda887b08ef730d68290a61081ef2566glennrp unsigned char lbr_bits=ScaleQuantumToChar((pixelpacket).red); \ 4248e58efdecda887b08ef730d68290a61081ef2566glennrp (pixelpacket).red=ScaleCharToQuantum((lbr_bits)); \ 4258e58efdecda887b08ef730d68290a61081ef2566glennrp } 42691d99255dd77083750426ba5463e002a586bc9a6glennrp#define LBR08PacketGreen(pixelpacket) \ 4278e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 4288e58efdecda887b08ef730d68290a61081ef2566glennrp unsigned char lbr_bits=ScaleQuantumToChar((pixelpacket).green); \ 4298e58efdecda887b08ef730d68290a61081ef2566glennrp (pixelpacket).green=ScaleCharToQuantum((lbr_bits)); \ 4308e58efdecda887b08ef730d68290a61081ef2566glennrp } 43191d99255dd77083750426ba5463e002a586bc9a6glennrp#define LBR08PacketBlue(pixelpacket) \ 4328e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 4338e58efdecda887b08ef730d68290a61081ef2566glennrp unsigned char lbr_bits=ScaleQuantumToChar((pixelpacket).blue); \ 4348e58efdecda887b08ef730d68290a61081ef2566glennrp (pixelpacket).blue=ScaleCharToQuantum((lbr_bits)); \ 4358e58efdecda887b08ef730d68290a61081ef2566glennrp } 4364c08aed51c5899665ade97263692328eea4af106cristy#define LBR08PacketAlpha(pixelpacket) \ 4378e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 4384c08aed51c5899665ade97263692328eea4af106cristy unsigned char lbr_bits=ScaleQuantumToChar((pixelpacket).alpha); \ 4394c08aed51c5899665ade97263692328eea4af106cristy (pixelpacket).alpha=ScaleCharToQuantum((lbr_bits)); \ 4408e58efdecda887b08ef730d68290a61081ef2566glennrp } 4418e58efdecda887b08ef730d68290a61081ef2566glennrp 44291d99255dd77083750426ba5463e002a586bc9a6glennrp#define LBR08PacketRGB(pixelpacket) \ 443bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp { \ 4444c08aed51c5899665ade97263692328eea4af106cristy LBR08PixelPacketRed((pixelpacket)); \ 44591d99255dd77083750426ba5463e002a586bc9a6glennrp LBR08PacketGreen((pixelpacket)); \ 44691d99255dd77083750426ba5463e002a586bc9a6glennrp LBR08PacketBlue((pixelpacket)); \ 447bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp } 4488e58efdecda887b08ef730d68290a61081ef2566glennrp 44991d99255dd77083750426ba5463e002a586bc9a6glennrp#define LBR08PacketRGBO(pixelpacket) \ 450bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp { \ 45191d99255dd77083750426ba5463e002a586bc9a6glennrp LBR08PacketRGB((pixelpacket)); \ 4524c08aed51c5899665ade97263692328eea4af106cristy LBR08PacketAlpha((pixelpacket)); \ 453bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp } 4548e58efdecda887b08ef730d68290a61081ef2566glennrp 455ef61831f94757bbb7fd66e3f5d1aca8a19c0b58ecristy#define LBR08PixelRed(pixel) \ 4568e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 4578e58efdecda887b08ef730d68290a61081ef2566glennrp unsigned char lbr_bits= \ 4584c08aed51c5899665ade97263692328eea4af106cristy ScaleQuantumToChar(GetPixelRed(image,(pixel))); \ 4594c08aed51c5899665ade97263692328eea4af106cristy SetPixelRed(image,\ 4604c08aed51c5899665ade97263692328eea4af106cristy ScaleCharToQuantum((lbr_bits)), (pixel)); \ 4618e58efdecda887b08ef730d68290a61081ef2566glennrp } 4624c08aed51c5899665ade97263692328eea4af106cristy#define LBR08Green(pixel) \ 4638e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 4648e58efdecda887b08ef730d68290a61081ef2566glennrp unsigned char lbr_bits= \ 4654c08aed51c5899665ade97263692328eea4af106cristy ScaleQuantumToChar(GetPixelGreen(image,(pixel))); \ 4664c08aed51c5899665ade97263692328eea4af106cristy SetPixelGreen(image,\ 4674c08aed51c5899665ade97263692328eea4af106cristy ScaleCharToQuantum((lbr_bits)), (pixel)); \ 4688e58efdecda887b08ef730d68290a61081ef2566glennrp } 4694c08aed51c5899665ade97263692328eea4af106cristy#define LBR08Blue(pixel) \ 4708e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 4718e58efdecda887b08ef730d68290a61081ef2566glennrp unsigned char lbr_bits= \ 4724c08aed51c5899665ade97263692328eea4af106cristy ScaleQuantumToChar(GetPixelBlue(image,(pixel))); \ 4734c08aed51c5899665ade97263692328eea4af106cristy SetPixelBlue(image,\ 4744c08aed51c5899665ade97263692328eea4af106cristy ScaleCharToQuantum((lbr_bits)), (pixel)); \ 4758e58efdecda887b08ef730d68290a61081ef2566glennrp } 4764c08aed51c5899665ade97263692328eea4af106cristy#define LBR08Alpha(pixel) \ 4778e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 4788e58efdecda887b08ef730d68290a61081ef2566glennrp unsigned char lbr_bits= \ 4794c08aed51c5899665ade97263692328eea4af106cristy ScaleQuantumToChar(GetPixelAlpha(image,(pixel))); \ 4804c08aed51c5899665ade97263692328eea4af106cristy SetPixelAlpha(image,\ 4814c08aed51c5899665ade97263692328eea4af106cristy ScaleCharToQuantum((lbr_bits)), (pixel)); \ 4828e58efdecda887b08ef730d68290a61081ef2566glennrp } 4838e58efdecda887b08ef730d68290a61081ef2566glennrp 4844c08aed51c5899665ade97263692328eea4af106cristy#define LBR08RGB(pixel) \ 485bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp { \ 486ef61831f94757bbb7fd66e3f5d1aca8a19c0b58ecristy LBR08PixelRed((pixel)); \ 4874c08aed51c5899665ade97263692328eea4af106cristy LBR08Green((pixel)); \ 4884c08aed51c5899665ade97263692328eea4af106cristy LBR08Blue((pixel)); \ 489bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp } 4908e58efdecda887b08ef730d68290a61081ef2566glennrp 4914c08aed51c5899665ade97263692328eea4af106cristy#define LBR08RGBA(pixel) \ 492bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp { \ 4934c08aed51c5899665ade97263692328eea4af106cristy LBR08RGB((pixel)); \ 4944c08aed51c5899665ade97263692328eea4af106cristy LBR08Alpha((pixel)); \ 495bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp } 4968e58efdecda887b08ef730d68290a61081ef2566glennrp 4978e58efdecda887b08ef730d68290a61081ef2566glennrp 4988e58efdecda887b08ef730d68290a61081ef2566glennrp/* LBR16: Replicate top 16 bits */ 4998e58efdecda887b08ef730d68290a61081ef2566glennrp 5004c08aed51c5899665ade97263692328eea4af106cristy#define LBR16PixelPacketRed(pixelpacket) \ 5018e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 5028e58efdecda887b08ef730d68290a61081ef2566glennrp unsigned short lbr_bits=ScaleQuantumToShort((pixelpacket).red); \ 5038e58efdecda887b08ef730d68290a61081ef2566glennrp (pixelpacket).red=ScaleShortToQuantum((lbr_bits)); \ 5048e58efdecda887b08ef730d68290a61081ef2566glennrp } 50591d99255dd77083750426ba5463e002a586bc9a6glennrp#define LBR16PacketGreen(pixelpacket) \ 5068e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 5078e58efdecda887b08ef730d68290a61081ef2566glennrp unsigned short lbr_bits=ScaleQuantumToShort((pixelpacket).green); \ 5088e58efdecda887b08ef730d68290a61081ef2566glennrp (pixelpacket).green=ScaleShortToQuantum((lbr_bits)); \ 5098e58efdecda887b08ef730d68290a61081ef2566glennrp } 51091d99255dd77083750426ba5463e002a586bc9a6glennrp#define LBR16PacketBlue(pixelpacket) \ 5118e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 5128e58efdecda887b08ef730d68290a61081ef2566glennrp unsigned short lbr_bits=ScaleQuantumToShort((pixelpacket).blue); \ 5138e58efdecda887b08ef730d68290a61081ef2566glennrp (pixelpacket).blue=ScaleShortToQuantum((lbr_bits)); \ 5148e58efdecda887b08ef730d68290a61081ef2566glennrp } 5154c08aed51c5899665ade97263692328eea4af106cristy#define LBR16PacketAlpha(pixelpacket) \ 5168e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 5174c08aed51c5899665ade97263692328eea4af106cristy unsigned short lbr_bits=ScaleQuantumToShort((pixelpacket).alpha); \ 5184c08aed51c5899665ade97263692328eea4af106cristy (pixelpacket).alpha=ScaleShortToQuantum((lbr_bits)); \ 5198e58efdecda887b08ef730d68290a61081ef2566glennrp } 5208e58efdecda887b08ef730d68290a61081ef2566glennrp 52191d99255dd77083750426ba5463e002a586bc9a6glennrp#define LBR16PacketRGB(pixelpacket) \ 522bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp { \ 5234c08aed51c5899665ade97263692328eea4af106cristy LBR16PixelPacketRed((pixelpacket)); \ 52491d99255dd77083750426ba5463e002a586bc9a6glennrp LBR16PacketGreen((pixelpacket)); \ 52591d99255dd77083750426ba5463e002a586bc9a6glennrp LBR16PacketBlue((pixelpacket)); \ 526bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp } 5278e58efdecda887b08ef730d68290a61081ef2566glennrp 52891d99255dd77083750426ba5463e002a586bc9a6glennrp#define LBR16PacketRGBO(pixelpacket) \ 529bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp { \ 53091d99255dd77083750426ba5463e002a586bc9a6glennrp LBR16PacketRGB((pixelpacket)); \ 5314c08aed51c5899665ade97263692328eea4af106cristy LBR16PacketAlpha((pixelpacket)); \ 532bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp } 5338e58efdecda887b08ef730d68290a61081ef2566glennrp 534ef61831f94757bbb7fd66e3f5d1aca8a19c0b58ecristy#define LBR16PixelRed(pixel) \ 5358e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 5368e58efdecda887b08ef730d68290a61081ef2566glennrp unsigned short lbr_bits= \ 5374c08aed51c5899665ade97263692328eea4af106cristy ScaleQuantumToShort(GetPixelRed(image,(pixel))); \ 5384c08aed51c5899665ade97263692328eea4af106cristy SetPixelRed(image,\ 5394c08aed51c5899665ade97263692328eea4af106cristy ScaleShortToQuantum((lbr_bits)),(pixel)); \ 5408e58efdecda887b08ef730d68290a61081ef2566glennrp } 5414c08aed51c5899665ade97263692328eea4af106cristy#define LBR16Green(pixel) \ 5428e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 5438e58efdecda887b08ef730d68290a61081ef2566glennrp unsigned short lbr_bits= \ 5444c08aed51c5899665ade97263692328eea4af106cristy ScaleQuantumToShort(GetPixelGreen(image,(pixel))); \ 5454c08aed51c5899665ade97263692328eea4af106cristy SetPixelGreen(image,\ 5464c08aed51c5899665ade97263692328eea4af106cristy ScaleShortToQuantum((lbr_bits)),(pixel)); \ 5478e58efdecda887b08ef730d68290a61081ef2566glennrp } 5484c08aed51c5899665ade97263692328eea4af106cristy#define LBR16Blue(pixel) \ 5498e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 5508e58efdecda887b08ef730d68290a61081ef2566glennrp unsigned short lbr_bits= \ 5514c08aed51c5899665ade97263692328eea4af106cristy ScaleQuantumToShort(GetPixelBlue(image,(pixel))); \ 5524c08aed51c5899665ade97263692328eea4af106cristy SetPixelBlue(image,\ 5534c08aed51c5899665ade97263692328eea4af106cristy ScaleShortToQuantum((lbr_bits)),(pixel)); \ 5548e58efdecda887b08ef730d68290a61081ef2566glennrp } 5554c08aed51c5899665ade97263692328eea4af106cristy#define LBR16Alpha(pixel) \ 5568e58efdecda887b08ef730d68290a61081ef2566glennrp { \ 5578e58efdecda887b08ef730d68290a61081ef2566glennrp unsigned short lbr_bits= \ 5584c08aed51c5899665ade97263692328eea4af106cristy ScaleQuantumToShort(GetPixelAlpha(image,(pixel))); \ 5594c08aed51c5899665ade97263692328eea4af106cristy SetPixelAlpha(image,\ 5604c08aed51c5899665ade97263692328eea4af106cristy ScaleShortToQuantum((lbr_bits)),(pixel)); \ 5618e58efdecda887b08ef730d68290a61081ef2566glennrp } 5628e58efdecda887b08ef730d68290a61081ef2566glennrp 5634c08aed51c5899665ade97263692328eea4af106cristy#define LBR16RGB(pixel) \ 564bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp { \ 565ef61831f94757bbb7fd66e3f5d1aca8a19c0b58ecristy LBR16PixelRed((pixel)); \ 5664c08aed51c5899665ade97263692328eea4af106cristy LBR16Green((pixel)); \ 5674c08aed51c5899665ade97263692328eea4af106cristy LBR16Blue((pixel)); \ 568bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp } 5698e58efdecda887b08ef730d68290a61081ef2566glennrp 5704c08aed51c5899665ade97263692328eea4af106cristy#define LBR16RGBA(pixel) \ 571bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp { \ 5724c08aed51c5899665ade97263692328eea4af106cristy LBR16RGB((pixel)); \ 5734c08aed51c5899665ade97263692328eea4af106cristy LBR16Alpha((pixel)); \ 574bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp } 5758e58efdecda887b08ef730d68290a61081ef2566glennrp 5763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 5773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Establish thread safety. 5783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy setjmp/longjmp is claimed to be safe on these platforms: 5793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy setjmp/longjmp is alleged to be unsafe on these platforms: 5803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 5813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#ifndef SETJMP_IS_THREAD_SAFE 5823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define PNG_SETJMP_NOT_THREAD_SAFE 5833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 5843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 5853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(PNG_SETJMP_NOT_THREAD_SAFE) 5863ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic SemaphoreInfo 587cf002022280cc4dedb2748ad6f415aac1d44f530glennrp *ping_semaphore = (SemaphoreInfo *) NULL; 5883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 5893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 5903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 5913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy This temporary until I set up malloc'ed object attributes array. 5923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Recompile with MNG_MAX_OBJECTS=65536L to avoid this limit but 5933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy waste more memory. 5943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 5953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define MNG_MAX_OBJECTS 256 5963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 5973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 5983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy If this not defined, spec is interpreted strictly. If it is 5993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy defined, an attempt will be made to recover from some errors, 6003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy including 6013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy o global PLTE too short 6023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 6033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#undef MNG_LOOSE 6043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 6053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 6063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Don't try to define PNG_MNG_FEATURES_SUPPORTED here. Make sure 6073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy it's defined in libpng/pngconf.h, version 1.0.9 or later. It won't work 6083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy with earlier versions of libpng. From libpng-1.0.3a to libpng-1.0.8, 6093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNG_READ|WRITE_EMPTY_PLTE were used but those have been deprecated in 6103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy libpng in favor of PNG_MNG_FEATURES_SUPPORTED, so we set them here. 6113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNG_MNG_FEATURES_SUPPORTED is disabled by default in libpng-1.0.9 and 6123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy will be enabled by default in libpng-1.2.0. 6133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 6143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#ifdef PNG_MNG_FEATURES_SUPPORTED 6153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy# ifndef PNG_READ_EMPTY_PLTE_SUPPORTED 6163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy# define PNG_READ_EMPTY_PLTE_SUPPORTED 6173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy# endif 6183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy# ifndef PNG_WRITE_EMPTY_PLTE_SUPPORTED 6193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy# define PNG_WRITE_EMPTY_PLTE_SUPPORTED 6203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy# endif 6213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 6223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 6233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 624bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy Maximum valid size_t in PNG/MNG chunks is (2^31)-1 6253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy This macro is only defined in libpng-1.0.3 and later. 6263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Previously it was PNG_MAX_UINT but that was deprecated in libpng-1.2.6 6273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 6283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#ifndef PNG_UINT_31_MAX 6293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define PNG_UINT_31_MAX (png_uint_32) 0x7fffffffL 6303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 6313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 6323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 6333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Constant strings for known chunk types. If you need to add a chunk, 6343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy add a string holding the name here. To make the code more 6353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy portable, we use ASCII numbers like this, not characters. 6363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 6373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 6383ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_MHDR[5]={ 77, 72, 68, 82, (png_byte) '\0'}; 6393ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_BACK[5]={ 66, 65, 67, 75, (png_byte) '\0'}; 6403ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_BASI[5]={ 66, 65, 83, 73, (png_byte) '\0'}; 6413ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_CLIP[5]={ 67, 76, 73, 80, (png_byte) '\0'}; 6423ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_CLON[5]={ 67, 76, 79, 78, (png_byte) '\0'}; 6433ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_DEFI[5]={ 68, 69, 70, 73, (png_byte) '\0'}; 6443ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_DHDR[5]={ 68, 72, 68, 82, (png_byte) '\0'}; 6453ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_DISC[5]={ 68, 73, 83, 67, (png_byte) '\0'}; 6463ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_ENDL[5]={ 69, 78, 68, 76, (png_byte) '\0'}; 6473ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_FRAM[5]={ 70, 82, 65, 77, (png_byte) '\0'}; 6483ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_IEND[5]={ 73, 69, 78, 68, (png_byte) '\0'}; 6493ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_IHDR[5]={ 73, 72, 68, 82, (png_byte) '\0'}; 6503ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_JHDR[5]={ 74, 72, 68, 82, (png_byte) '\0'}; 6513ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_LOOP[5]={ 76, 79, 79, 80, (png_byte) '\0'}; 6523ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_MAGN[5]={ 77, 65, 71, 78, (png_byte) '\0'}; 6533ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_MEND[5]={ 77, 69, 78, 68, (png_byte) '\0'}; 6543ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_MOVE[5]={ 77, 79, 86, 69, (png_byte) '\0'}; 6553ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_PAST[5]={ 80, 65, 83, 84, (png_byte) '\0'}; 6563ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_PLTE[5]={ 80, 76, 84, 69, (png_byte) '\0'}; 6573ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_SAVE[5]={ 83, 65, 86, 69, (png_byte) '\0'}; 6583ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_SEEK[5]={ 83, 69, 69, 75, (png_byte) '\0'}; 6593ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_SHOW[5]={ 83, 72, 79, 87, (png_byte) '\0'}; 6603ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_TERM[5]={ 84, 69, 82, 77, (png_byte) '\0'}; 6613ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_bKGD[5]={ 98, 75, 71, 68, (png_byte) '\0'}; 6623ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_cHRM[5]={ 99, 72, 82, 77, (png_byte) '\0'}; 6633ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_gAMA[5]={103, 65, 77, 65, (png_byte) '\0'}; 6643ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_iCCP[5]={105, 67, 67, 80, (png_byte) '\0'}; 6653ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_nEED[5]={110, 69, 69, 68, (png_byte) '\0'}; 6663ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_pHYg[5]={112, 72, 89, 103, (png_byte) '\0'}; 6673ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_vpAg[5]={118, 112, 65, 103, (png_byte) '\0'}; 6683ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_pHYs[5]={112, 72, 89, 115, (png_byte) '\0'}; 6693ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_sBIT[5]={115, 66, 73, 84, (png_byte) '\0'}; 6703ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_sRGB[5]={115, 82, 71, 66, (png_byte) '\0'}; 6713ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_tRNS[5]={116, 82, 78, 83, (png_byte) '\0'}; 6723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 6733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(JNG_SUPPORTED) 6743ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_IDAT[5]={ 73, 68, 65, 84, (png_byte) '\0'}; 6753ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_JDAT[5]={ 74, 68, 65, 84, (png_byte) '\0'}; 6763ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_JDAA[5]={ 74, 68, 65, 65, (png_byte) '\0'}; 6773ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_JdAA[5]={ 74, 100, 65, 65, (png_byte) '\0'}; 6783ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_JSEP[5]={ 74, 83, 69, 80, (png_byte) '\0'}; 6793ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_oFFs[5]={111, 70, 70, 115, (png_byte) '\0'}; 6803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 6813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 6823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 6833ed852eea50f9d4cd633efb8c2b054b8e33c253cristyOther known chunks that are not yet supported by ImageMagick: 6843ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_hIST[5]={104, 73, 83, 84, (png_byte) '\0'}; 6853ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_iCCP[5]={105, 67, 67, 80, (png_byte) '\0'}; 6863ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_iTXt[5]={105, 84, 88, 116, (png_byte) '\0'}; 6873ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_sPLT[5]={115, 80, 76, 84, (png_byte) '\0'}; 6883ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_sTER[5]={115, 84, 69, 82, (png_byte) '\0'}; 6893ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_tEXt[5]={116, 69, 88, 116, (png_byte) '\0'}; 6903ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_tIME[5]={116, 73, 77, 69, (png_byte) '\0'}; 6913ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic png_byte FARDATA mng_zTXt[5]={122, 84, 88, 116, (png_byte) '\0'}; 6923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 6933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 6943ed852eea50f9d4cd633efb8c2b054b8e33c253cristytypedef struct _MngBox 6953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 6968182b0758e3429fb8dcd1700f09643fd4d80a41ccristy long 6973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy left, 6983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy right, 6993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy top, 7003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy bottom; 7013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} MngBox; 7023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 7033ed852eea50f9d4cd633efb8c2b054b8e33c253cristytypedef struct _MngPair 7043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 7058182b0758e3429fb8dcd1700f09643fd4d80a41ccristy volatile long 7063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy a, 7073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy b; 7083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} MngPair; 7093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 7103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#ifdef MNG_OBJECT_BUFFERS 7113ed852eea50f9d4cd633efb8c2b054b8e33c253cristytypedef struct _MngBuffer 7123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 7133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 714bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy size_t 7153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy height, 7163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy width; 7173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 7183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Image 7193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *image; 7203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 7213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_color 7223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy plte[256]; 7233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 7243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy int 7253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy reference_count; 7263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 7273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy unsigned char 7283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy alpha_sample_depth, 7293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy compression_method, 7303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy color_type, 7313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy concrete, 7323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy filter_method, 7333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy frozen, 7343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image_type, 7353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy interlace_method, 7363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel_sample_depth, 7373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy plte_length, 7383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy sample_depth, 7393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy viewable; 7403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} MngBuffer; 7413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 7423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 7433ed852eea50f9d4cd633efb8c2b054b8e33c253cristytypedef struct _MngInfo 7443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 7453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 7463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#ifdef MNG_OBJECT_BUFFERS 7473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngBuffer 7483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *ob[MNG_MAX_OBJECTS]; 7493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 7503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 7513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Image * 7523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image; 7533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 7543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy RectangleInfo 7553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy page; 7563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 7573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy int 7583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy adjoin, 7593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#ifndef PNG_READ_EMPTY_PLTE_SUPPORTED 7603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy bytes_in_read_buffer, 7613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy found_empty_plte, 7623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 7633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy equal_backgrounds, 7643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy equal_chrms, 7653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy equal_gammas, 7663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED) || \ 7673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy defined(PNG_MNG_FEATURES_SUPPORTED) 7683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy equal_palettes, 7693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 7703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy equal_physs, 7713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy equal_srgbs, 7723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy framing_mode, 7733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy have_global_bkgd, 7743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy have_global_chrm, 7753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy have_global_gama, 7763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy have_global_phys, 7773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy have_global_sbit, 7783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy have_global_srgb, 7793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy have_saved_bkgd_index, 7803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy have_write_global_chrm, 7813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy have_write_global_gama, 7823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy have_write_global_plte, 7833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy have_write_global_srgb, 7843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy need_fram, 7853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy object_id, 7863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy old_framing_mode, 7873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy saved_bkgd_index; 7883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 7893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy int 7903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy new_number_colors; 7913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 792bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy ssize_t 7933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image_found, 7943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy loop_count[256], 7953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy loop_iteration[256], 7963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy scenes_found, 7973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy x_off[MNG_MAX_OBJECTS], 7983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy y_off[MNG_MAX_OBJECTS]; 7993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 8003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngBox 8013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy clip, 8023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy frame, 8033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image_box, 8043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy object_clip[MNG_MAX_OBJECTS]; 8053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 8063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy unsigned char 8073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* These flags could be combined into one byte */ 8083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy exists[MNG_MAX_OBJECTS], 8093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy frozen[MNG_MAX_OBJECTS], 8103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy loop_active[256], 8113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy invisible[MNG_MAX_OBJECTS], 8123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy viewable[MNG_MAX_OBJECTS]; 8133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 8143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MagickOffsetType 8153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy loop_jump[256]; 8163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 8173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_colorp 8183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy global_plte; 8193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 8203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_color_8 8213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy global_sbit; 8223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 8233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_byte 8243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#ifndef PNG_READ_EMPTY_PLTE_SUPPORTED 8253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy read_buffer[8], 8263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 8273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy global_trns[256]; 8283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 8293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy float 8303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy global_gamma; 8313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 8323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ChromaticityInfo 8333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy global_chrm; 8343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 8353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy RenderingIntent 8363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy global_srgb_intent; 8373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 83835ef824baa82511126ff0072ae30eee0da9c05a3cristy unsigned int 8393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy delay, 8403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy global_plte_length, 8413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy global_trns_length, 8423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy global_x_pixels_per_unit, 8433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy global_y_pixels_per_unit, 8443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_width, 8453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_height, 8463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ticks_per_second; 8473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 848b9cfe27bef51dbbd1f05aef89c767749d7e37864glennrp MagickBooleanType 849b9cfe27bef51dbbd1f05aef89c767749d7e37864glennrp need_blob; 850b9cfe27bef51dbbd1f05aef89c767749d7e37864glennrp 8513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy unsigned int 8523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy IsPalette, 8533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy global_phys_unit_type, 8543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy basi_warning, 8553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy clon_warning, 8563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy dhdr_warning, 8573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jhdr_warning, 8583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_warning, 8593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy past_warning, 8603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy phyg_warning, 8613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy phys_warning, 8623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy sbit_warning, 8633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy show_warning, 8643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_type, 8653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy write_mng, 8663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy write_png_colortype, 8673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy write_png_depth, 8681868258559ddf946fa73ef72dd43507b32623705glennrp write_png_compression_level, 8691868258559ddf946fa73ef72dd43507b32623705glennrp write_png_compression_strategy, 8701868258559ddf946fa73ef72dd43507b32623705glennrp write_png_compression_filter, 8713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy write_png8, 8723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy write_png24, 8733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy write_png32; 8743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 8753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#ifdef MNG_BASI_SUPPORTED 876bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy size_t 8773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy basi_width, 8783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy basi_height; 8793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 8803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy unsigned int 8813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy basi_depth, 8823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy basi_color_type, 8833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy basi_compression_method, 8843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy basi_filter_type, 8853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy basi_interlace_method, 8863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy basi_red, 8873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy basi_green, 8883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy basi_blue, 8893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy basi_alpha, 8903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy basi_viewable; 8913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 8923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 8933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_uint_16 8943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_first, 8953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_last, 8963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_mb, 8973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_ml, 8983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_mr, 8993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_mt, 9003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_mx, 9013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_my, 9023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_methx, 9033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_methy; 9043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 9053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PixelPacket 9063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_global_bkgd; 9073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 90826f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp /* Added at version 6.6.6-7 */ 90926f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp MagickBooleanType 91026f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp ping_exclude_bKGD, 91126f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp ping_exclude_cHRM, 912a0ed009a1e9480ac6f3f4520e9ef29d6d37e27dcglennrp ping_exclude_date, 91326f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp ping_exclude_EXIF, 91426f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp ping_exclude_gAMA, 91526f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp ping_exclude_iCCP, 91626f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp /* ping_exclude_iTXt, */ 91726f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp ping_exclude_oFFs, 91826f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp ping_exclude_pHYs, 91926f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp ping_exclude_sRGB, 92026f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp ping_exclude_tEXt, 921a1e3b7b4887860a199d00bddbf4b12e0a93ee1e5glennrp ping_exclude_tRNS, 92226f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp ping_exclude_vpAg, 92326f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp ping_exclude_zCCP, /* hex-encoded iCCP */ 9248d3d6e584829223ac5f6e6653c3caa38a2562a74glennrp ping_exclude_zTXt, 9258d3d6e584829223ac5f6e6653c3caa38a2562a74glennrp ping_preserve_colormap; 92626f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp 9273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} MngInfo; 9283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif /* VER */ 9293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 9303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 9313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Forward declarations. 9323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 9333ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic MagickBooleanType 9343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy WritePNGImage(const ImageInfo *,Image *); 9350c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp 9363ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic MagickBooleanType 9373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy WriteMNGImage(const ImageInfo *,Image *); 9380c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp 9393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(JNG_SUPPORTED) 9403ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic MagickBooleanType 9413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy WriteJNGImage(const ImageInfo *,Image *); 9423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 9433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 9440c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp#if PNG_LIBPNG_VER > 10011 9450c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp 946fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp 9470c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp#if (MAGICKCORE_QUANTUM_DEPTH >= 16) 9480c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrpstatic MagickBooleanType 949fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrpLosslessReduceDepthOK(Image *image) 9500c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp{ 9519d0ea4d0d750fa124d7b83da98ed582d59c1aab0glennrp /* Reduce bit depth if it can be reduced losslessly from 16+ to 8. 95267b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp * 95367b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp * This is true if the high byte and the next highest byte of 95467b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp * each sample of the image, the colormap, and the background color 9553faa9a3fb01696daaf976d595f492cb530bffb21glennrp * are equal to each other. We check this by seeing if the samples 9563faa9a3fb01696daaf976d595f492cb530bffb21glennrp * are unchanged when we scale them down to 8 and back up to Quantum. 95767b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp * 95867b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp * We don't use the method GetImageDepth() because it doesn't check 9593faa9a3fb01696daaf976d595f492cb530bffb21glennrp * background and doesn't handle PseudoClass specially. 9609d0ea4d0d750fa124d7b83da98ed582d59c1aab0glennrp */ 96105a549971fd661147ade177e2bc10f6cfcfc32b4glennrp 9623faa9a3fb01696daaf976d595f492cb530bffb21glennrp#define QuantumToCharToQuantumEqQuantum(quantum) \ 9633faa9a3fb01696daaf976d595f492cb530bffb21glennrp ((ScaleCharToQuantum((unsigned char) ScaleQuantumToChar(quantum))) == quantum) 9643faa9a3fb01696daaf976d595f492cb530bffb21glennrp 96567b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp MagickBooleanType 96667b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp ok_to_reduce=MagickFalse; 96767b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp 96803e11f6e8d7f01a32b53d7e8e6a3bfd5ef1c5c9dglennrp if (image->depth >= 16) 9690c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp { 9700c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp 9714c08aed51c5899665ade97263692328eea4af106cristy const Quantum 9720c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp *p; 9730c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp 9740c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp ok_to_reduce= 9753faa9a3fb01696daaf976d595f492cb530bffb21glennrp QuantumToCharToQuantumEqQuantum(image->background_color.red) && 9763faa9a3fb01696daaf976d595f492cb530bffb21glennrp QuantumToCharToQuantumEqQuantum(image->background_color.green) && 9773faa9a3fb01696daaf976d595f492cb530bffb21glennrp QuantumToCharToQuantumEqQuantum(image->background_color.blue) ? 9783faa9a3fb01696daaf976d595f492cb530bffb21glennrp MagickTrue : MagickFalse; 9790c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp 9800c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp if (ok_to_reduce != MagickFalse && image->storage_class == PseudoClass) 9810c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp { 9820c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp int indx; 9830c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp 9840c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp for (indx=0; indx < (ssize_t) image->colors; indx++) 9850c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp { 9863faa9a3fb01696daaf976d595f492cb530bffb21glennrp ok_to_reduce=( 9873faa9a3fb01696daaf976d595f492cb530bffb21glennrp QuantumToCharToQuantumEqQuantum( 9883faa9a3fb01696daaf976d595f492cb530bffb21glennrp image->colormap[indx].red) && 9893faa9a3fb01696daaf976d595f492cb530bffb21glennrp QuantumToCharToQuantumEqQuantum( 9903faa9a3fb01696daaf976d595f492cb530bffb21glennrp image->colormap[indx].green) && 9913faa9a3fb01696daaf976d595f492cb530bffb21glennrp QuantumToCharToQuantumEqQuantum( 9923faa9a3fb01696daaf976d595f492cb530bffb21glennrp image->colormap[indx].blue)) ? 9933faa9a3fb01696daaf976d595f492cb530bffb21glennrp MagickTrue : MagickFalse; 9943faa9a3fb01696daaf976d595f492cb530bffb21glennrp 9950c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp if (ok_to_reduce == MagickFalse) 9963faa9a3fb01696daaf976d595f492cb530bffb21glennrp break; 9970c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp } 9980c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp } 9990c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp 10000c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp if ((ok_to_reduce != MagickFalse) && 10010c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp (image->storage_class != PseudoClass)) 10020c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp { 10030c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp ssize_t 10040c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp y; 10050c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp 10060c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp register ssize_t 10070c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp x; 10080c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp 10090c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp for (y=0; y < (ssize_t) image->rows; y++) 10100c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp { 10110c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception); 10120c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp 10134c08aed51c5899665ade97263692328eea4af106cristy if (p == (const Quantum *) NULL) 10140c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp { 10150c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp ok_to_reduce = MagickFalse; 10160c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp break; 10170c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp } 10180c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp 10190c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp for (x=(ssize_t) image->columns-1; x >= 0; x--) 10200c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp { 10213faa9a3fb01696daaf976d595f492cb530bffb21glennrp ok_to_reduce= 10224c08aed51c5899665ade97263692328eea4af106cristy QuantumToCharToQuantumEqQuantum(GetPixelRed(image,p)) && 10234c08aed51c5899665ade97263692328eea4af106cristy QuantumToCharToQuantumEqQuantum(GetPixelGreen(image,p)) && 10244c08aed51c5899665ade97263692328eea4af106cristy QuantumToCharToQuantumEqQuantum(GetPixelBlue(image,p)) ? 10253faa9a3fb01696daaf976d595f492cb530bffb21glennrp MagickTrue : MagickFalse; 10260c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp 10270c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp if (ok_to_reduce == MagickFalse) 10280c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp break; 10290c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp 10304c08aed51c5899665ade97263692328eea4af106cristy p+=GetPixelChannels(image); 10310c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp } 10328640fb5e9b1094f35f8beab436f81661b8a99448glennrp if (x >= 0) 10330c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp break; 10340c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp } 10350c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp } 10360c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp 10370c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp if (ok_to_reduce != MagickFalse) 10380c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp { 10390c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 1040fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp " OK to reduce PNG bit depth to 8 without loss of info"); 10410c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp } 1042a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp else 1043a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp { 1044a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 1045fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp " Not OK to reduce PNG bit depth to 8 without loss of info"); 1046a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp } 10470c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp } 10480c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp 10490c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp return ok_to_reduce; 10500c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp} 10510c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp#endif /* MAGICKCORE_QUANTUM_DEPTH >= 16 */ 10520c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp 1053e610a071534e448c46460a5aa39ede33bf56b329glennrpstatic int 1054cf002022280cc4dedb2748ad6f415aac1d44f530glennrpMagick_RenderingIntent_to_PNG_RenderingIntent(const RenderingIntent intent) 10550fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp{ 1056e610a071534e448c46460a5aa39ede33bf56b329glennrp switch (intent) 1057e610a071534e448c46460a5aa39ede33bf56b329glennrp { 1058e610a071534e448c46460a5aa39ede33bf56b329glennrp case PerceptualIntent: 1059e610a071534e448c46460a5aa39ede33bf56b329glennrp return 0; 10600fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 1061e610a071534e448c46460a5aa39ede33bf56b329glennrp case RelativeIntent: 1062e610a071534e448c46460a5aa39ede33bf56b329glennrp return 1; 10630fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 1064e610a071534e448c46460a5aa39ede33bf56b329glennrp case SaturationIntent: 1065e610a071534e448c46460a5aa39ede33bf56b329glennrp return 2; 10660fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 1067e610a071534e448c46460a5aa39ede33bf56b329glennrp case AbsoluteIntent: 1068e610a071534e448c46460a5aa39ede33bf56b329glennrp return 3; 10690fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 1070e610a071534e448c46460a5aa39ede33bf56b329glennrp default: 1071e610a071534e448c46460a5aa39ede33bf56b329glennrp return -1; 1072e610a071534e448c46460a5aa39ede33bf56b329glennrp } 1073e610a071534e448c46460a5aa39ede33bf56b329glennrp} 1074e610a071534e448c46460a5aa39ede33bf56b329glennrp 1075e610a071534e448c46460a5aa39ede33bf56b329glennrpstatic RenderingIntent 1076cf002022280cc4dedb2748ad6f415aac1d44f530glennrpMagick_RenderingIntent_from_PNG_RenderingIntent(const int ping_intent) 10770fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp{ 1078cf002022280cc4dedb2748ad6f415aac1d44f530glennrp switch (ping_intent) 1079e610a071534e448c46460a5aa39ede33bf56b329glennrp { 1080e610a071534e448c46460a5aa39ede33bf56b329glennrp case 0: 1081e610a071534e448c46460a5aa39ede33bf56b329glennrp return PerceptualIntent; 10820fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 1083e610a071534e448c46460a5aa39ede33bf56b329glennrp case 1: 1084e610a071534e448c46460a5aa39ede33bf56b329glennrp return RelativeIntent; 10850fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 1086e610a071534e448c46460a5aa39ede33bf56b329glennrp case 2: 1087e610a071534e448c46460a5aa39ede33bf56b329glennrp return SaturationIntent; 10880fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 1089e610a071534e448c46460a5aa39ede33bf56b329glennrp case 3: 1090e610a071534e448c46460a5aa39ede33bf56b329glennrp return AbsoluteIntent; 10910fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 1092e610a071534e448c46460a5aa39ede33bf56b329glennrp default: 1093e610a071534e448c46460a5aa39ede33bf56b329glennrp return UndefinedIntent; 1094e610a071534e448c46460a5aa39ede33bf56b329glennrp } 1095e610a071534e448c46460a5aa39ede33bf56b329glennrp} 1096e610a071534e448c46460a5aa39ede33bf56b329glennrp 1097bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristystatic inline ssize_t MagickMax(const ssize_t x,const ssize_t y) 10983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 10993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (x > y) 11003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(x); 11010fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 11023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(y); 11033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 11040c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp 1105bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristystatic inline ssize_t MagickMin(const ssize_t x,const ssize_t y) 11063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 11073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (x < y) 11083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(x); 11090fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 11103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(y); 11113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 11120c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp 1113dbb105fc25903e800273f7e980c0553060858a68glennrp 11143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 11153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 11163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 11173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 11183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 1119dbb105fc25903e800273f7e980c0553060858a68glennrp% I m a g e I s G r a y % 11203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 11213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 11223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 11233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 1124dbb105fc25903e800273f7e980c0553060858a68glennrp% % 11254c08aed51c5899665ade97263692328eea4af106cristy% Like IsImageGray except does not change DirectClass to PseudoClass % 1126dbb105fc25903e800273f7e980c0553060858a68glennrp% % 1127dbb105fc25903e800273f7e980c0553060858a68glennrp%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 11283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 1129dbb105fc25903e800273f7e980c0553060858a68glennrpstatic MagickBooleanType ImageIsGray(Image *image) 11303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 11314c08aed51c5899665ade97263692328eea4af106cristy register const Quantum 11323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *p; 11333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1134bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy register ssize_t 11353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy i, 1136dbb105fc25903e800273f7e980c0553060858a68glennrp x, 1137dbb105fc25903e800273f7e980c0553060858a68glennrp y; 11383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 11393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(image != (Image *) NULL); 11403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(image->signature == MagickSignature); 11413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->debug != MagickFalse) 1142dbb105fc25903e800273f7e980c0553060858a68glennrp (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); 1143dbb105fc25903e800273f7e980c0553060858a68glennrp 1144dbb105fc25903e800273f7e980c0553060858a68glennrp if (image->storage_class == PseudoClass) 11453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 1146dbb105fc25903e800273f7e980c0553060858a68glennrp for (i=0; i < (ssize_t) image->colors; i++) 11474c08aed51c5899665ade97263692328eea4af106cristy if (IsPixelPacketGray(image->colormap+i) == MagickFalse) 1148dbb105fc25903e800273f7e980c0553060858a68glennrp return(MagickFalse); 1149dbb105fc25903e800273f7e980c0553060858a68glennrp return(MagickTrue); 11503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 1151bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (y=0; y < (ssize_t) image->rows; y++) 11523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 11533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception); 11544c08aed51c5899665ade97263692328eea4af106cristy if (p == (const Quantum *) NULL) 1155dbb105fc25903e800273f7e980c0553060858a68glennrp return(MagickFalse); 1156dbb105fc25903e800273f7e980c0553060858a68glennrp for (x=(ssize_t) image->columns-1; x >= 0; x--) 1157dbb105fc25903e800273f7e980c0553060858a68glennrp { 11584c08aed51c5899665ade97263692328eea4af106cristy if (IsPixelGray(image,p) == MagickFalse) 1159dbb105fc25903e800273f7e980c0553060858a68glennrp return(MagickFalse); 11604c08aed51c5899665ade97263692328eea4af106cristy p+=GetPixelChannels(image); 1161dbb105fc25903e800273f7e980c0553060858a68glennrp } 11623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 1163dbb105fc25903e800273f7e980c0553060858a68glennrp return(MagickTrue); 1164dbb105fc25903e800273f7e980c0553060858a68glennrp} 1165d5045b44ae266ec7d6d2fca5e7c8a69a28938ec4glennrp#endif /* PNG_LIBPNG_VER > 10011 */ 11663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif /* MAGICKCORE_PNG_DELEGATE */ 11673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 11683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 11693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 11703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 11713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 11723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 11733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% I s M N G % 11743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 11753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 11763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 11773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 11783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 11793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% IsMNG() returns MagickTrue if the image format type, identified by the 11803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% magick string, is MNG. 11813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 11823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% The format of the IsMNG method is: 11833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 11843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% MagickBooleanType IsMNG(const unsigned char *magick,const size_t length) 11853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 11863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% A description of each parameter follows: 11873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 11883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o magick: compare image format pattern against these bytes. 11893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 11903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o length: Specifies the length of the magick string. 11913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 11923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 11933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 11943ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic MagickBooleanType IsMNG(const unsigned char *magick,const size_t length) 11953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 11963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length < 8) 11973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(MagickFalse); 11980fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 11993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(magick,"\212MNG\r\n\032\n",8) == 0) 12003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(MagickTrue); 12010fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 12023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(MagickFalse); 12033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 12043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 12053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 12063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 12073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 12083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 12093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 12103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% I s J N G % 12113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 12123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 12133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 12143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 12153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 12163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% IsJNG() returns MagickTrue if the image format type, identified by the 12173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% magick string, is JNG. 12183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 12193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% The format of the IsJNG method is: 12203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 12213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% MagickBooleanType IsJNG(const unsigned char *magick,const size_t length) 12223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 12233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% A description of each parameter follows: 12243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 12253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o magick: compare image format pattern against these bytes. 12263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 12273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o length: Specifies the length of the magick string. 12283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 12293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 12303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 12313ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic MagickBooleanType IsJNG(const unsigned char *magick,const size_t length) 12323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 12333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length < 8) 12343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(MagickFalse); 12350fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 12363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(magick,"\213JNG\r\n\032\n",8) == 0) 12373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(MagickTrue); 12380fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 12393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(MagickFalse); 12403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 12413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 12423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 12433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 12443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 12453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 12463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 12473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% I s P N G % 12483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 12493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 12503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 12513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 12523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 12533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% IsPNG() returns MagickTrue if the image format type, identified by the 12543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% magick string, is PNG. 12553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 12563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% The format of the IsPNG method is: 12573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 12583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% MagickBooleanType IsPNG(const unsigned char *magick,const size_t length) 12593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 12603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% A description of each parameter follows: 12613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 12623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o magick: compare image format pattern against these bytes. 12633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 12643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o length: Specifies the length of the magick string. 12653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 12663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 12673ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic MagickBooleanType IsPNG(const unsigned char *magick,const size_t length) 12683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 12693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length < 8) 12703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(MagickFalse); 12710fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 12723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(magick,"\211PNG\r\n\032\n",8) == 0) 12733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(MagickTrue); 12740fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 12753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(MagickFalse); 12763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 12773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 12783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_PNG_DELEGATE) 12793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(__cplusplus) || defined(c_plusplus) 12803ed852eea50f9d4cd633efb8c2b054b8e33c253cristyextern "C" { 12813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 12823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1283d5045b44ae266ec7d6d2fca5e7c8a69a28938ec4glennrp#if (PNG_LIBPNG_VER > 10011) 1284bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristystatic size_t WriteBlobMSBULong(Image *image,const size_t value) 12853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 12863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy unsigned char 12873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy buffer[4]; 12883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 12893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(image != (Image *) NULL); 12903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(image->signature == MagickSignature); 12913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy buffer[0]=(unsigned char) (value >> 24); 12923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy buffer[1]=(unsigned char) (value >> 16); 12933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy buffer[2]=(unsigned char) (value >> 8); 12943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy buffer[3]=(unsigned char) value; 12953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return((size_t) WriteBlob(image,4,buffer)); 12963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 12973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 12983ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic void PNGLong(png_bytep p,png_uint_32 value) 12993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 13003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *p++=(png_byte) ((value >> 24) & 0xff); 13013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *p++=(png_byte) ((value >> 16) & 0xff); 13023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *p++=(png_byte) ((value >> 8) & 0xff); 13033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *p++=(png_byte) (value & 0xff); 13043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 13053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1306a521b2fe1f4c8b8ab9412bd6ef23b6736b90e43dglennrp#if defined(JNG_SUPPORTED) 13073ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic void PNGsLong(png_bytep p,png_int_32 value) 13083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 13093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *p++=(png_byte) ((value >> 24) & 0xff); 13103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *p++=(png_byte) ((value >> 16) & 0xff); 13113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *p++=(png_byte) ((value >> 8) & 0xff); 13123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *p++=(png_byte) (value & 0xff); 13133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 1314a521b2fe1f4c8b8ab9412bd6ef23b6736b90e43dglennrp#endif 13153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 13163ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic void PNGShort(png_bytep p,png_uint_16 value) 13173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 13183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *p++=(png_byte) ((value >> 8) & 0xff); 13193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *p++=(png_byte) (value & 0xff); 13203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 13213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 13223ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic void PNGType(png_bytep p,png_bytep type) 13233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 13243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) CopyMagickMemory(p,type,4*sizeof(png_byte)); 13253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 13263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 132703812ae402fb53d548f0e1d7d14720768f803c2dglennrpstatic void LogPNGChunk(MagickBooleanType logging, png_bytep type, 132803812ae402fb53d548f0e1d7d14720768f803c2dglennrp size_t length) 13293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 13303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 13313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 1332e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " Writing %c%c%c%c chunk, length: %.20g", 1333e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy type[0],type[1],type[2],type[3],(double) length); 13343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 1335d5045b44ae266ec7d6d2fca5e7c8a69a28938ec4glennrp#endif /* PNG_LIBPNG_VER > 10011 */ 13363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 13373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(__cplusplus) || defined(c_plusplus) 13383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 13393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 13403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1341d5045b44ae266ec7d6d2fca5e7c8a69a28938ec4glennrp#if PNG_LIBPNG_VER > 10011 13423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 13433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 13443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 13453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 13463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 13473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% R e a d P N G I m a g e % 13483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 13493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 13503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 13513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 13523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 13533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% ReadPNGImage() reads a Portable Network Graphics (PNG) or 13543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Multiple-image Network Graphics (MNG) image file and returns it. It 13553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% allocates the memory necessary for the new Image structure and returns a 13563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% pointer to the new image or set of images. 13573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 13583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% MNG support written by Glenn Randers-Pehrson, glennrp@image... 13593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 13603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% The format of the ReadPNGImage method is: 13613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 13623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Image *ReadPNGImage(const ImageInfo *image_info,ExceptionInfo *exception) 13633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 13643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% A description of each parameter follows: 13653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 13663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o image_info: the image info. 13673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 13683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o exception: return any errors or warnings in this structure. 13693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 13703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% To do, more or less in chronological order (as of version 5.5.2, 13713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% November 26, 2002 -- glennrp -- see also "To do" under WriteMNGImage): 13723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 13733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Get 16-bit cheap transparency working. 13743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 13753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% (At this point, PNG decoding is supposed to be in full MNG-LC compliance) 13763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 13773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Preserve all unknown and not-yet-handled known chunks found in input 13783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% PNG file and copy them into output PNG files according to the PNG 13793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% copying rules. 13803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 13813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% (At this point, PNG encoding should be in full MNG compliance) 13823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 13833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Provide options for choice of background to use when the MNG BACK 13843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% chunk is not present or is not mandatory (i.e., leave transparent, 13853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% user specified, MNG BACK, PNG bKGD) 13863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 13873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Implement LOOP/ENDL [done, but could do discretionary loops more 13883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% efficiently by linking in the duplicate frames.]. 13893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 13903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Decode and act on the MHDR simplicity profile (offer option to reject 13913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% files or attempt to process them anyway when the profile isn't LC or VLC). 13923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 13933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Upgrade to full MNG without Delta-PNG. 13943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 13953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o BACK [done a while ago except for background image ID] 13963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o MOVE [done 15 May 1999] 13973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o CLIP [done 15 May 1999] 13983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o DISC [done 19 May 1999] 13993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o SAVE [partially done 19 May 1999 (marks objects frozen)] 14003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o SEEK [partially done 19 May 1999 (discard function only)] 14013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o SHOW 14023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o PAST 14033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o BASI 14043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o MNG-level tEXt/iTXt/zTXt 14053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o pHYg 14063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o pHYs 14073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o sBIT 14083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o bKGD 14093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o iTXt (wait for libpng implementation). 14103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 14113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Use the scene signature to discover when an identical scene is 14123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% being reused, and just point to the original image->exception instead 14133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% of storing another set of pixels. This not specific to MNG 14143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% but could be applied generally. 14153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 14163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Upgrade to full MNG with Delta-PNG. 14173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 14183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% JNG tEXt/iTXt/zTXt 14193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 14203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% We will not attempt to read files containing the CgBI chunk. 14213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% They are really Xcode files meant for display on the iPhone. 14223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% These are not valid PNG files and it is impossible to recover 1423f54e295d6fa414fa04aa4f43767c20eda8ae555eglennrp% the original PNG from files that have been converted to Xcode-PNG, 14243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% since irretrievable loss of color data has occurred due to the 14253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% use of premultiplied alpha. 14263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 14273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 14283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(__cplusplus) || defined(c_plusplus) 14293ed852eea50f9d4cd633efb8c2b054b8e33c253cristyextern "C" { 14303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 14313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 14323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 14333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy This the function that does the actual reading of data. It is 14343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy the same as the one supplied in libpng, except that it receives the 14353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy datastream from the ReadBlob() function instead of standard input. 14363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 14373ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic void png_get_data(png_structp png_ptr,png_bytep data,png_size_t length) 14383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 14393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Image 14403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *image; 14413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 14423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=(Image *) png_get_io_ptr(png_ptr); 14433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length) 14443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 14453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_size_t 14463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy check; 14473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 14483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy check=(png_size_t) ReadBlob(image,(size_t) length,data); 14493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (check != length) 14503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 14513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy char 14523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy msg[MaxTextExtent]; 14533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 14543b6fd2ec2d9f69f9404445dba0aff5bac02e685ccristy (void) FormatLocaleString(msg,MaxTextExtent, 1455e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy "Expected %.20g bytes; found %.20g bytes",(double) length, 1456e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy (double) check); 14573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_warning(png_ptr,msg); 14583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_error(png_ptr,"Read Exception"); 14593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 14603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 14613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 14623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 14633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if !defined(PNG_READ_EMPTY_PLTE_SUPPORTED) && \ 14643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy !defined(PNG_MNG_FEATURES_SUPPORTED) 14653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* We use mng_get_data() instead of png_get_data() if we have a libpng 14663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy * older than libpng-1.0.3a, which was the first to allow the empty 14673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy * PLTE, or a newer libpng in which PNG_MNG_FEATURES_SUPPORTED was 14683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy * ifdef'ed out. Earlier versions would crash if the bKGD chunk was 14693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy * encountered after an empty PLTE, so we have to look ahead for bKGD 14703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy * chunks and remove them from the datastream that is passed to libpng, 14713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy * and store their contents for later use. 14723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 14733ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic void mng_get_data(png_structp png_ptr,png_bytep data,png_size_t length) 14743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 14753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngInfo 14763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *mng_info; 14773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 14783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Image 14793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *image; 14803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 14813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_size_t 14823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy check; 14833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1484bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy register ssize_t 14853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy i; 14863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 14873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy i=0; 14883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info=(MngInfo *) png_get_io_ptr(png_ptr); 14893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=(Image *) mng_info->image; 14903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy while (mng_info->bytes_in_read_buffer && length) 14913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 14923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy data[i]=mng_info->read_buffer[i]; 14933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->bytes_in_read_buffer--; 14943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy length--; 14953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy i++; 14963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 14973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length) 14983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 14993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy check=(png_size_t) ReadBlob(image,(size_t) length,(char *) data); 15000fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 15013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (check != length) 15023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_error(png_ptr,"Read Exception"); 15030fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 15043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length == 4) 15053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 15063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((data[0] == 0) && (data[1] == 0) && (data[2] == 0) && 15073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (data[3] == 0)) 15083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 15093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy check=(png_size_t) ReadBlob(image,(size_t) length, 15103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (char *) mng_info->read_buffer); 15113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->read_buffer[4]=0; 15123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->bytes_in_read_buffer=4; 15133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(mng_info->read_buffer,mng_PLTE,4) == 0) 15143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->found_empty_plte=MagickTrue; 15153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(mng_info->read_buffer,mng_IEND,4) == 0) 15163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 15173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->found_empty_plte=MagickFalse; 15183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->have_saved_bkgd_index=MagickFalse; 15193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 15203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 15210fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 15223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((data[0] == 0) && (data[1] == 0) && (data[2] == 0) && 15233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (data[3] == 1)) 15243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 15253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy check=(png_size_t) ReadBlob(image,(size_t) length, 15263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (char *) mng_info->read_buffer); 15273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->read_buffer[4]=0; 15283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->bytes_in_read_buffer=4; 15293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(mng_info->read_buffer,mng_bKGD,4) == 0) 15303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->found_empty_plte) 15313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 15323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 15333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Skip the bKGD data byte and CRC. 15343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 15353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy check=(png_size_t) 15363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ReadBlob(image,5,(char *) mng_info->read_buffer); 15373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy check=(png_size_t) ReadBlob(image,(size_t) length, 15383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (char *) mng_info->read_buffer); 15393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->saved_bkgd_index=mng_info->read_buffer[0]; 15403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->have_saved_bkgd_index=MagickTrue; 15413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->bytes_in_read_buffer=0; 15423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 15433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 15443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 15453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 15463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 15473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 15483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 15493ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic void png_put_data(png_structp png_ptr,png_bytep data,png_size_t length) 15503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 15513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Image 15523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *image; 15533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 15543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=(Image *) png_get_io_ptr(png_ptr); 15553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length) 15563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 15573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_size_t 15583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy check; 15593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1560bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy check=(png_size_t) WriteBlob(image,(size_t) length,data); 15610fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 15623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (check != length) 15633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_error(png_ptr,"WriteBlob Failed"); 15643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 15653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 15663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 15673ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic void png_flush_data(png_structp png_ptr) 15683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 15693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) png_ptr; 15703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 15713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 15723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#ifdef PNG_WRITE_EMPTY_PLTE_SUPPORTED 15733ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic int PalettesAreEqual(Image *a,Image *b) 15743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 1575bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy ssize_t 15763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy i; 15773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 15783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((a == (Image *) NULL) || (b == (Image *) NULL)) 15793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return((int) MagickFalse); 15800fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 15813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (a->storage_class != PseudoClass || b->storage_class != PseudoClass) 15823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return((int) MagickFalse); 15830fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 15843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (a->colors != b->colors) 15853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return((int) MagickFalse); 15860fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 1587bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (i=0; i < (ssize_t) a->colors; i++) 15883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 15893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((a->colormap[i].red != b->colormap[i].red) || 15903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (a->colormap[i].green != b->colormap[i].green) || 15913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (a->colormap[i].blue != b->colormap[i].blue)) 15923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return((int) MagickFalse); 15933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 15940fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 15953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return((int) MagickTrue); 15963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 15973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 15983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 15993ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic void MngInfoDiscardObject(MngInfo *mng_info,int i) 16003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 16013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (i && (i < MNG_MAX_OBJECTS) && (mng_info != (MngInfo *) NULL) && 16023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->exists[i] && !mng_info->frozen[i]) 16033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 16043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#ifdef MNG_OBJECT_BUFFERS 16053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->ob[i] != (MngBuffer *) NULL) 16063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 16073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->ob[i]->reference_count > 0) 16083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->ob[i]->reference_count--; 16090fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 16103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->ob[i]->reference_count == 0) 16113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 16123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->ob[i]->image != (Image *) NULL) 16133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->ob[i]->image=DestroyImage(mng_info->ob[i]->image); 16140fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 16153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->ob[i]=DestroyString(mng_info->ob[i]); 16163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 16173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 16183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->ob[i]=(MngBuffer *) NULL; 16193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 16203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->exists[i]=MagickFalse; 16213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->invisible[i]=MagickFalse; 16223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->viewable[i]=MagickFalse; 16233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->frozen[i]=MagickFalse; 16243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->x_off[i]=0; 16253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->y_off[i]=0; 16263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->object_clip[i].left=0; 1627bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy mng_info->object_clip[i].right=(ssize_t) PNG_UINT_31_MAX; 16283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->object_clip[i].top=0; 1629bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy mng_info->object_clip[i].bottom=(ssize_t) PNG_UINT_31_MAX; 16303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 16313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 16323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 163321f0e6211a440c0f96134ea25a1bfe7c5f91c29cglennrpstatic void MngInfoFreeStruct(MngInfo *mng_info, 163421f0e6211a440c0f96134ea25a1bfe7c5f91c29cglennrp MagickBooleanType *have_mng_structure) 16353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 163621f0e6211a440c0f96134ea25a1bfe7c5f91c29cglennrp if (*have_mng_structure != MagickFalse && (mng_info != (MngInfo *) NULL)) 16373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 1638bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy register ssize_t 16393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy i; 16403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 16413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy for (i=1; i < MNG_MAX_OBJECTS; i++) 16423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngInfoDiscardObject(mng_info,i); 16430fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 16443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->global_plte != (png_colorp) NULL) 16453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->global_plte=(png_colorp) 16463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy RelinquishMagickMemory(mng_info->global_plte); 16470fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 16483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info=(MngInfo *) RelinquishMagickMemory(mng_info); 16493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *have_mng_structure=MagickFalse; 16503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 16513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 16523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 16533ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic MngBox mng_minimum_box(MngBox box1,MngBox box2) 16543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 16553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngBox 16563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy box; 16573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 16583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy box=box1; 16593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (box.left < box2.left) 16603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy box.left=box2.left; 16610fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 16623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (box.top < box2.top) 16633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy box.top=box2.top; 16640fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 16653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (box.right > box2.right) 16663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy box.right=box2.right; 16670fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 16683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (box.bottom > box2.bottom) 16693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy box.bottom=box2.bottom; 16700fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 16713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return box; 16723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 16733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 16743ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic MngBox mng_read_box(MngBox previous_box,char delta_type,unsigned char *p) 16753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 16763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngBox 16773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy box; 16783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 16793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 16803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Read clipping boundaries from DEFI, CLIP, FRAM, or PAST chunk. 16813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 1682bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy box.left=(ssize_t) ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]); 1683bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy box.right=(ssize_t) ((p[4] << 24) | (p[5] << 16) | (p[6] << 8) | p[7]); 1684bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy box.top=(ssize_t) ((p[8] << 24) | (p[9] << 16) | (p[10] << 8) | p[11]); 1685bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy box.bottom=(ssize_t) ((p[12] << 24) | (p[13] << 16) | (p[14] << 8) | p[15]); 16863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (delta_type != 0) 16873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 16883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy box.left+=previous_box.left; 16893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy box.right+=previous_box.right; 16903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy box.top+=previous_box.top; 16913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy box.bottom+=previous_box.bottom; 16923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 16930fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 16943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(box); 16953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 16963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 16973ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic MngPair mng_read_pair(MngPair previous_pair,int delta_type, 16983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy unsigned char *p) 16993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 17003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngPair 17013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pair; 17023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 1703bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy Read two ssize_ts from CLON, MOVE or PAST chunk 17043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 17058182b0758e3429fb8dcd1700f09643fd4d80a41ccristy pair.a=(long) ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]); 17068182b0758e3429fb8dcd1700f09643fd4d80a41ccristy pair.b=(long) ((p[4] << 24) | (p[5] << 16) | (p[6] << 8) | p[7]); 17070fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 17083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (delta_type != 0) 17093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 17103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pair.a+=previous_pair.a; 17113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pair.b+=previous_pair.b; 17123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 17130fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 17143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(pair); 17153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 17163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 17178182b0758e3429fb8dcd1700f09643fd4d80a41ccristystatic long mng_get_long(unsigned char *p) 17183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 17198182b0758e3429fb8dcd1700f09643fd4d80a41ccristy return((long) ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3])); 17203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 17213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1722cf002022280cc4dedb2748ad6f415aac1d44f530glennrpstatic void MagickPNGErrorHandler(png_struct *ping,png_const_charp message) 17233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 17243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Image 17253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *image; 17263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 17273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=(Image *) png_get_error_ptr(ping); 17280fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 17293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->debug != MagickFalse) 17303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 17313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " libpng-%s error: %s", PNG_LIBPNG_VER_STRING,message); 17320fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 17333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ThrowMagickException(&image->exception,GetMagickModule(),CoderError, 17343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy message,"`%s'",image->filename); 17350fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 1736e4017e34baec05ee0a45800ed8efb2ff6d5c9f5aglennrp#if (PNG_LIBPNG_VER < 10500) 17378371ecc013ff231ce380d8717e517312e62e1f01glennrp /* A warning about deprecated use of jmpbuf here is unavoidable if you 17388371ecc013ff231ce380d8717e517312e62e1f01glennrp * are building with libpng-1.4.x and can be ignored. 17398371ecc013ff231ce380d8717e517312e62e1f01glennrp */ 17403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy longjmp(ping->jmpbuf,1); 1741faa852bad40107edae19405e76a299057668d795glennrp#else 1742faa852bad40107edae19405e76a299057668d795glennrp png_longjmp(ping,1); 1743faa852bad40107edae19405e76a299057668d795glennrp#endif 17443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 17453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1746cf002022280cc4dedb2748ad6f415aac1d44f530glennrpstatic void MagickPNGWarningHandler(png_struct *ping,png_const_charp message) 17473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 17483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Image 17493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *image; 17503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 17513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (LocaleCompare(message, "Missing PLTE before tRNS") == 0) 17523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_error(ping, message); 17530fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 17543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=(Image *) png_get_error_ptr(ping); 17553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->debug != MagickFalse) 17563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 1757cc23b9a188db6b1f240825f6d4c52310f5f69765cristy " libpng-%s warning: %s", PNG_LIBPNG_VER_STRING,message); 17580fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 17593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ThrowMagickException(&image->exception,GetMagickModule(),CoderWarning, 17603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy message,"`%s'",image->filename); 17613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 17623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 17633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#ifdef PNG_USER_MEM_SUPPORTED 1764cf002022280cc4dedb2748ad6f415aac1d44f530glennrpstatic png_voidp Magick_png_malloc(png_structp png_ptr,png_uint_32 size) 17653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 17663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if (PNG_LIBPNG_VER < 10011) 17673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_voidp 17683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ret; 17693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 17703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_ptr=png_ptr; 17713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ret=((png_voidp) AcquireMagickMemory((size_t) size)); 17720fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 17733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (ret == NULL) 17743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_error("Insufficient memory."); 17750fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 17763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(ret); 17773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#else 17783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_ptr=png_ptr; 17793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return((png_voidp) AcquireMagickMemory((size_t) size)); 17803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 17813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 17823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 17833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 17843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Free a pointer. It is removed from the list at the same time. 17853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 1786cf002022280cc4dedb2748ad6f415aac1d44f530glennrpstatic png_free_ptr Magick_png_free(png_structp png_ptr,png_voidp ptr) 17873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 17883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_ptr=png_ptr; 17893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ptr=RelinquishMagickMemory(ptr); 17903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return((png_free_ptr) NULL); 17913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 17923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 17933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 17943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(__cplusplus) || defined(c_plusplus) 17953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 17963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 17973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 17983ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic int 1799cf002022280cc4dedb2748ad6f415aac1d44f530glennrpMagick_png_read_raw_profile(Image *image, const ImageInfo *image_info, 18003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_textp text,int ii) 18013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 1802bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy register ssize_t 18033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy i; 18043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 18053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy register unsigned char 18063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *dp; 18073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 18083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy register png_charp 18093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy sp; 18103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 18113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_uint_32 18123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy length, 18133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy nibbles; 18143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 18153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy StringInfo 18163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *profile; 18173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 18180c3e06bd4809f97aeceaeb7c2334d8b2b850c2e1glennrp const unsigned char 18193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy unhex[103]={0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 18203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 18213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 0,0,0,0,0,0,0,0,0,1, 2,3,4,5,6,7,8,9,0,0, 18223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 18233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,10,11,12, 18243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 13,14,15}; 18253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 18263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy sp=text[ii].text+1; 18273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* look for newline */ 18283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy while (*sp != '\n') 18293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy sp++; 18300fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 18313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* look for length */ 18323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy while (*sp == '\0' || *sp == ' ' || *sp == '\n') 18333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy sp++; 18340fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 1835f2f2727f17ecbb23d902f70bb98f81faabc92dbdcristy length=(png_uint_32) StringToLong(sp); 18360fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 183797f90e23c85b9c58387880125c29d8c99126f83aglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 183897f90e23c85b9c58387880125c29d8c99126f83aglennrp " length: %lu",(unsigned long) length); 183997f90e23c85b9c58387880125c29d8c99126f83aglennrp 18403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy while (*sp != ' ' && *sp != '\n') 18413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy sp++; 18420fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 18433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* allocate space */ 18443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length == 0) 18453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 18463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ThrowMagickException(&image->exception,GetMagickModule(), 18473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy CoderWarning,"UnableToCopyProfile","`%s'","invalid profile length"); 18483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(MagickFalse); 18493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 18500fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 18513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy profile=AcquireStringInfo(length); 18520fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 18533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (profile == (StringInfo *) NULL) 18543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 18553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ThrowMagickException(&image->exception,GetMagickModule(), 18563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ResourceLimitError,"MemoryAllocationFailed","`%s'", 18573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy "unable to copy profile"); 18583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(MagickFalse); 18593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 18600fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 18613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* copy profile, skipping white space and column 1 "=" signs */ 18623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy dp=GetStringInfoDatum(profile); 18633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy nibbles=length*2; 18640fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 1865bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (i=0; i < (ssize_t) nibbles; i++) 18663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 18673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy while (*sp < '0' || (*sp > '9' && *sp < 'a') || *sp > 'f') 18683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 18693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (*sp == '\0') 18703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 18713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ThrowMagickException(&image->exception,GetMagickModule(), 18723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy CoderWarning,"UnableToCopyProfile","`%s'","ran out of data"); 18733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy profile=DestroyStringInfo(profile); 18743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(MagickFalse); 18753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 18763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy sp++; 18773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 18780fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 18793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (i%2 == 0) 18803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *dp=(unsigned char) (16*unhex[(int) *sp++]); 18810fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 18823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 18833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (*dp++)+=unhex[(int) *sp++]; 18843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 18853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 18863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy We have already read "Raw profile type. 18873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 18883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) SetImageProfile(image,&text[ii].key[17],profile); 18893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy profile=DestroyStringInfo(profile); 18900fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 18913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image_info->verbose) 18923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) printf(" Found a generic profile, type %s\n",&text[ii].key[17]); 18930fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 18943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return MagickTrue; 18953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 18963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 18973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) 18983ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic int read_vpag_chunk_callback(png_struct *ping, png_unknown_chunkp chunk) 18993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 19003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Image 19013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *image; 19023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 19033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 19043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* The unknown chunk structure contains the chunk data: 19053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_byte name[5]; 19063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_byte *data; 19073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_size_t size; 19083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 19093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Note that libpng has already taken care of the CRC handling. 19103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 19113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 19123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 19133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (chunk->name[0] != 118 || chunk->name[1] != 112 || 19143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk->name[2] != 65 ||chunk-> name[3] != 103) 19153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(0); /* Did not recognize */ 19163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 19173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* recognized vpAg */ 19183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 19193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (chunk->size != 9) 19203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(-1); /* Error return */ 19213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 19223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (chunk->data[8] != 0) 19233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(0); /* ImageMagick requires pixel units */ 19243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 19253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=(Image *) png_get_user_chunk_ptr(ping); 19263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1927bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy image->page.width=(size_t) ((chunk->data[0] << 24) | 19283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (chunk->data[1] << 16) | (chunk->data[2] << 8) | chunk->data[3]); 19290fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 1930bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy image->page.height=(size_t) ((chunk->data[4] << 24) | 19313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (chunk->data[5] << 16) | (chunk->data[6] << 8) | chunk->data[7]); 19323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 19333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Return one of the following: */ 19343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* return(-n); chunk had an error */ 19353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* return(0); did not recognize */ 19363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* return(n); success */ 19373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 19383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(1); 19393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 19403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 19413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 19423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 19433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 19443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 19453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 19463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 19473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 19483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% R e a d O n e P N G I m a g e % 19493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 19503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 19513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 19523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 19533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 19543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% ReadOnePNGImage() reads a Portable Network Graphics (PNG) image file 19553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% (minus the 8-byte signature) and returns it. It allocates the memory 19563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% necessary for the new Image structure and returns a pointer to the new 19573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% image. 19583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 19593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% The format of the ReadOnePNGImage method is: 19603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 19613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Image *ReadOnePNGImage(MngInfo *mng_info, const ImageInfo *image_info, 19623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% ExceptionInfo *exception) 19633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 19643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% A description of each parameter follows: 19653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 19663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o mng_info: Specifies a pointer to a MngInfo structure. 19673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 19683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o image_info: the image info. 19693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 19703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o exception: return any errors or warnings in this structure. 19713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 19723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 19733ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic Image *ReadOnePNGImage(MngInfo *mng_info, 19743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy const ImageInfo *image_info, ExceptionInfo *exception) 19753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 19763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Read one PNG image */ 19773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1978cc95c3f37f025a52b71d927cba8009c4f8bc83a5glennrp /* To do: Read the tIME chunk into the date:modify property */ 1979cc95c3f37f025a52b71d927cba8009c4f8bc83a5glennrp /* To do: Read the tEXt/Creation Time chunk into the date:create property */ 1980cc95c3f37f025a52b71d927cba8009c4f8bc83a5glennrp 19813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Image 19823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *image; 19833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 19843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy int 19854eb3931feb349dd87142c78503b779228f3e1a0fglennrp intent, 1986cb395ac9c5c50c2829a9988f95fd8aea7af82c00glennrp num_raw_profiles, 19873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy num_text, 19884eb3931feb349dd87142c78503b779228f3e1a0fglennrp num_text_total, 19893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy num_passes, 1990faa852bad40107edae19405e76a299057668d795glennrp pass, 1991faa852bad40107edae19405e76a299057668d795glennrp ping_bit_depth, 1992faa852bad40107edae19405e76a299057668d795glennrp ping_color_type, 1993faa852bad40107edae19405e76a299057668d795glennrp ping_interlace_method, 1994faa852bad40107edae19405e76a299057668d795glennrp ping_compression_method, 1995faa852bad40107edae19405e76a299057668d795glennrp ping_filter_method, 19964eb3931feb349dd87142c78503b779228f3e1a0fglennrp ping_num_trans, 19974eb3931feb349dd87142c78503b779228f3e1a0fglennrp unit_type; 19984eb3931feb349dd87142c78503b779228f3e1a0fglennrp 19994eb3931feb349dd87142c78503b779228f3e1a0fglennrp double 20004eb3931feb349dd87142c78503b779228f3e1a0fglennrp file_gamma; 20013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 2002a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp LongPixelPacket 2003a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp transparent_color; 2004a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp 20053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MagickBooleanType 20064383ec8c3c8811128f5a8a034d67c47db5e7e75acristy logging, 20073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status; 20083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 2009faa852bad40107edae19405e76a299057668d795glennrp png_bytep 2010faa852bad40107edae19405e76a299057668d795glennrp ping_trans_alpha; 2011faa852bad40107edae19405e76a299057668d795glennrp 2012faa852bad40107edae19405e76a299057668d795glennrp png_color_16p 2013faa852bad40107edae19405e76a299057668d795glennrp ping_background, 2014faa852bad40107edae19405e76a299057668d795glennrp ping_trans_color; 2015faa852bad40107edae19405e76a299057668d795glennrp 20163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_info 20173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *end_info, 20183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *ping_info; 20193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 20203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_struct 20213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *ping; 20223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 20233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_textp 20243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy text; 20253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 2026faa852bad40107edae19405e76a299057668d795glennrp png_uint_32 2027faa852bad40107edae19405e76a299057668d795glennrp ping_height, 2028faa852bad40107edae19405e76a299057668d795glennrp ping_width, 20294eb3931feb349dd87142c78503b779228f3e1a0fglennrp ping_rowbytes, 20304eb3931feb349dd87142c78503b779228f3e1a0fglennrp x_resolution, 20314eb3931feb349dd87142c78503b779228f3e1a0fglennrp y_resolution; 2032faa852bad40107edae19405e76a299057668d795glennrp 20333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy QuantumInfo 20343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *quantum_info; 20353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 20363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy unsigned char 2037cf002022280cc4dedb2748ad6f415aac1d44f530glennrp *ping_pixels; 20383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 2039bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy ssize_t 20403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy y; 20413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 20423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy register unsigned char 20433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *p; 20443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 2045bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy register ssize_t 20463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy i, 20473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy x; 20483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 20494c08aed51c5899665ade97263692328eea4af106cristy register Quantum 20503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *q; 20513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 20523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy size_t 205339992b4dd9b12ef752d55b8e402c069698851f72glennrp length, 20543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy row_offset; 20553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 2056eb3b22a03f31af7f724573d8537cd91fca06ee41cristy ssize_t 2057eb3b22a03f31af7f724573d8537cd91fca06ee41cristy j; 2058eb3b22a03f31af7f724573d8537cd91fca06ee41cristy 20593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) 20603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_byte unused_chunks[]= 20613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 20623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 104, 73, 83, 84, (png_byte) '\0', /* hIST */ 20633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 105, 84, 88, 116, (png_byte) '\0', /* iTXt */ 20643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 112, 67, 65, 76, (png_byte) '\0', /* pCAL */ 20653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 115, 67, 65, 76, (png_byte) '\0', /* sCAL */ 20663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 115, 80, 76, 84, (png_byte) '\0', /* sPLT */ 20673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 116, 73, 77, 69, (png_byte) '\0', /* tIME */ 20683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy }; 20693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 20703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 20713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy logging=LogMagickEvent(CoderEvent,GetMagickModule(), 2072fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp " Enter ReadOnePNGImage()"); 20733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 20743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(PNG_SETJMP_NOT_THREAD_SAFE) 2075cf002022280cc4dedb2748ad6f415aac1d44f530glennrp LockSemaphoreInfo(ping_semaphore); 20763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 20773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 207825c1e2baba76d9cf3ec582f217f96af95259e747glennrp#if (PNG_LIBPNG_VER < 10200) 20793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image_info->verbose) 20803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy printf("Your PNG library (libpng-%s) is rather old.\n", 20813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNG_LIBPNG_VER_STRING); 20823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 20833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 208461b4c957269727a0a2526edc2331881da8346100glennrp#if (PNG_LIBPNG_VER >= 10400) 208561b4c957269727a0a2526edc2331881da8346100glennrp# ifndef PNG_TRANSFORM_GRAY_TO_RGB /* Added at libpng-1.4.0beta67 */ 208661b4c957269727a0a2526edc2331881da8346100glennrp if (image_info->verbose) 208761b4c957269727a0a2526edc2331881da8346100glennrp { 208861b4c957269727a0a2526edc2331881da8346100glennrp printf("Your PNG library (libpng-%s) is an old beta version.\n", 208961b4c957269727a0a2526edc2331881da8346100glennrp PNG_LIBPNG_VER_STRING); 209061b4c957269727a0a2526edc2331881da8346100glennrp printf("Please update it.\n"); 209161b4c957269727a0a2526edc2331881da8346100glennrp } 209261b4c957269727a0a2526edc2331881da8346100glennrp# endif 209361b4c957269727a0a2526edc2331881da8346100glennrp#endif 209461b4c957269727a0a2526edc2331881da8346100glennrp 209561b4c957269727a0a2526edc2331881da8346100glennrp 2096ed5525230af20461366cdc5b8bbe0f7f9b166c44cristy quantum_info = (QuantumInfo *) NULL; 20973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=mng_info->image; 20983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 2099a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp if (logging != MagickFalse) 2100a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp (void)LogMagickEvent(CoderEvent,GetMagickModule(), 2101a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp " image->matte=%d",(int) image->matte); 2102a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp 21030e319739731741c52a6303723e0c8678a0df5579glennrp /* Set to an out-of-range color unless tRNS chunk is present */ 21040e319739731741c52a6303723e0c8678a0df5579glennrp transparent_color.red=65537; 21050e319739731741c52a6303723e0c8678a0df5579glennrp transparent_color.green=65537; 21060e319739731741c52a6303723e0c8678a0df5579glennrp transparent_color.blue=65537; 21074c08aed51c5899665ade97263692328eea4af106cristy transparent_color.alpha=65537; 21080e319739731741c52a6303723e0c8678a0df5579glennrp 2109cb395ac9c5c50c2829a9988f95fd8aea7af82c00glennrp num_text = 0; 21104eb3931feb349dd87142c78503b779228f3e1a0fglennrp num_text_total = 0; 2111cb395ac9c5c50c2829a9988f95fd8aea7af82c00glennrp num_raw_profiles = 0; 2112cb395ac9c5c50c2829a9988f95fd8aea7af82c00glennrp 21133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 21143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Allocate the PNG structures 21153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 21163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#ifdef PNG_USER_MEM_SUPPORTED 21173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ping=png_create_read_struct_2(PNG_LIBPNG_VER_STRING, image, 2118cf002022280cc4dedb2748ad6f415aac1d44f530glennrp MagickPNGErrorHandler,MagickPNGWarningHandler, NULL, 2119cf002022280cc4dedb2748ad6f415aac1d44f530glennrp (png_malloc_ptr) Magick_png_malloc,(png_free_ptr) Magick_png_free); 21203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#else 21213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ping=png_create_read_struct(PNG_LIBPNG_VER_STRING,image, 2122cf002022280cc4dedb2748ad6f415aac1d44f530glennrp MagickPNGErrorHandler,MagickPNGWarningHandler); 21233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 21243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (ping == (png_struct *) NULL) 21253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); 21260fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 21273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ping_info=png_create_info_struct(ping); 21280fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 21293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (ping_info == (png_info *) NULL) 21303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 21313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_destroy_read_struct(&ping,(png_info **) NULL,(png_info **) NULL); 21323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); 21333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 21340fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 21353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy end_info=png_create_info_struct(ping); 21360fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 21373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (end_info == (png_info *) NULL) 21383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 21393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_destroy_read_struct(&ping,&ping_info,(png_info **) NULL); 21403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); 21413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 21420fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 2143cf002022280cc4dedb2748ad6f415aac1d44f530glennrp ping_pixels=(unsigned char *) NULL; 21440fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 2145faa852bad40107edae19405e76a299057668d795glennrp if (setjmp(png_jmpbuf(ping))) 21463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 21473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 21483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNG image is corrupt. 21493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 21503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_destroy_read_struct(&ping,&ping_info,&end_info); 21513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(PNG_SETJMP_NOT_THREAD_SAFE) 2152cf002022280cc4dedb2748ad6f415aac1d44f530glennrp UnlockSemaphoreInfo(ping_semaphore); 21533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 21543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 21553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 21563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " exit ReadOnePNGImage() with error."); 21570fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 21583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image != (Image *) NULL) 21597b755eb4f94efbb57160cce0d7afe7f8ed4ef066cristy { 21607b755eb4f94efbb57160cce0d7afe7f8ed4ef066cristy InheritException(exception,&image->exception); 21617b755eb4f94efbb57160cce0d7afe7f8ed4ef066cristy image->columns=0; 21627b755eb4f94efbb57160cce0d7afe7f8ed4ef066cristy } 21630fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 21643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(GetFirstImageInList(image)); 21653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 21663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 21673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Prepare PNG for reading. 21683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 2169faa852bad40107edae19405e76a299057668d795glennrp 21703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->image_found++; 21713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_set_sig_bytes(ping,8); 21720fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 21733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (LocaleCompare(image_info->magick,"MNG") == 0) 21743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 21753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(PNG_MNG_FEATURES_SUPPORTED) 21763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) png_permit_mng_features(ping,PNG_ALL_MNG_FEATURES); 21773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_set_read_fn(ping,image,png_get_data); 21783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#else 21793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) 21803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_permit_empty_plte(ping,MagickTrue); 21813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_set_read_fn(ping,image,png_get_data); 21823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#else 21833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->image=image; 21843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->bytes_in_read_buffer=0; 21853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->found_empty_plte=MagickFalse; 21863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->have_saved_bkgd_index=MagickFalse; 21873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_set_read_fn(ping,mng_info,mng_get_data); 21883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 21893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 21903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 21910fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 21923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 21933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_set_read_fn(ping,image,png_get_data); 21943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 21953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) 21963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Ignore unused chunks and all unknown chunks except for vpAg */ 21973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_set_keep_unknown_chunks(ping, 1, NULL, 0); 21983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_set_keep_unknown_chunks(ping, 2, mng_vpAg, 1); 21993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_set_keep_unknown_chunks(ping, 1, unused_chunks, 22003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (int)sizeof(unused_chunks)/5); 22013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Callback for other unknown chunks */ 22023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_set_read_user_chunk_fn(ping, image, read_vpag_chunk_callback); 22033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 22043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 2205991e92a91acb9e432cd6c05843e4f6a57643e29dglennrp#if (PNG_LIBPNG_VER < 10400) 2206991e92a91acb9e432cd6c05843e4f6a57643e29dglennrp# if defined(PNG_USE_PNGGCCRD) && defined(PNG_ASSEMBLER_CODE_SUPPORTED) && \ 2207991e92a91acb9e432cd6c05843e4f6a57643e29dglennrp (PNG_LIBPNG_VER >= 10200) && (PNG_LIBPNG_VER < 10220) && defined(__i386__) 22083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Disable thread-unsafe features of pnggccrd */ 22093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (png_access_version_number() >= 10200) 22103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 22113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_uint_32 mmx_disable_mask=0; 22123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_uint_32 asm_flags; 22133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 22143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mmx_disable_mask |= ( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \ 22153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy | PNG_ASM_FLAG_MMX_READ_FILTER_SUB \ 22163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy | PNG_ASM_FLAG_MMX_READ_FILTER_AVG \ 22173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ); 22183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy asm_flags=png_get_asm_flags(ping); 22193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_set_asm_flags(ping, asm_flags & ~mmx_disable_mask); 22203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 2221991e92a91acb9e432cd6c05843e4f6a57643e29dglennrp# endif 22223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 22233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 22243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_read_info(ping,ping_info); 2225faa852bad40107edae19405e76a299057668d795glennrp 2226faa852bad40107edae19405e76a299057668d795glennrp png_get_IHDR(ping,ping_info,&ping_width,&ping_height, 2227faa852bad40107edae19405e76a299057668d795glennrp &ping_bit_depth,&ping_color_type, 2228faa852bad40107edae19405e76a299057668d795glennrp &ping_interlace_method,&ping_compression_method, 2229faa852bad40107edae19405e76a299057668d795glennrp &ping_filter_method); 2230faa852bad40107edae19405e76a299057668d795glennrp 2231faa852bad40107edae19405e76a299057668d795glennrp (void) png_get_tRNS(ping, ping_info, &ping_trans_alpha, &ping_num_trans, 2232faa852bad40107edae19405e76a299057668d795glennrp &ping_trans_color); 2233faa852bad40107edae19405e76a299057668d795glennrp 2234faa852bad40107edae19405e76a299057668d795glennrp (void) png_get_bKGD(ping, ping_info, &ping_background); 2235faa852bad40107edae19405e76a299057668d795glennrp 2236faa852bad40107edae19405e76a299057668d795glennrp if (ping_bit_depth < 8) 22373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 2238faa852bad40107edae19405e76a299057668d795glennrp if (((int) ping_color_type == PNG_COLOR_TYPE_PALETTE)) 2239faa852bad40107edae19405e76a299057668d795glennrp { 2240faa852bad40107edae19405e76a299057668d795glennrp png_set_packing(ping); 2241faa852bad40107edae19405e76a299057668d795glennrp ping_bit_depth = 8; 2242faa852bad40107edae19405e76a299057668d795glennrp } 22433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 2244faa852bad40107edae19405e76a299057668d795glennrp 2245faa852bad40107edae19405e76a299057668d795glennrp image->depth=ping_bit_depth; 22463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->depth=GetImageQuantumDepth(image,MagickFalse); 2247faa852bad40107edae19405e76a299057668d795glennrp image->interlace=ping_interlace_method != 0 ? PNGInterlace : NoInterlace; 22483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 22493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 22503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 2251e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " PNG width: %.20g, height: %.20g", 2252e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy (double) ping_width, (double) ping_height); 22530fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 22543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 22553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " PNG color_type: %d, bit_depth: %d", 2256faa852bad40107edae19405e76a299057668d795glennrp ping_color_type, ping_bit_depth); 22570fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 22583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 22593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " PNG compression_method: %d", 2260faa852bad40107edae19405e76a299057668d795glennrp ping_compression_method); 22610fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 22623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 22633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " PNG interlace_method: %d, filter_method: %d", 2264faa852bad40107edae19405e76a299057668d795glennrp ping_interlace_method,ping_filter_method); 22653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 22663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 2267faa852bad40107edae19405e76a299057668d795glennrp#ifdef PNG_READ_iCCP_SUPPORTED 2268faa852bad40107edae19405e76a299057668d795glennrp if (png_get_valid(ping,ping_info,PNG_INFO_iCCP)) 22693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 22703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy int 22713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy compression; 22723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 2273e4017e34baec05ee0a45800ed8efb2ff6d5c9f5aglennrp#if (PNG_LIBPNG_VER < 10500) 2274e4017e34baec05ee0a45800ed8efb2ff6d5c9f5aglennrp png_charp 2275e4017e34baec05ee0a45800ed8efb2ff6d5c9f5aglennrp info; 2276e4017e34baec05ee0a45800ed8efb2ff6d5c9f5aglennrp#else 2277e4017e34baec05ee0a45800ed8efb2ff6d5c9f5aglennrp png_bytep 2278e4017e34baec05ee0a45800ed8efb2ff6d5c9f5aglennrp info; 2279e4017e34baec05ee0a45800ed8efb2ff6d5c9f5aglennrp#endif 2280e4017e34baec05ee0a45800ed8efb2ff6d5c9f5aglennrp 22813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_charp 22823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy name; 22833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 22843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_uint_32 22853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy profile_length; 22863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 22873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) png_get_iCCP(ping,ping_info,&name,(int *) &compression,&info, 22883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy &profile_length); 22890fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 22903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (profile_length != 0) 22913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 22923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy StringInfo 22933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *profile; 22943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 22953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 22963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 22973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Reading PNG iCCP chunk."); 22983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy profile=AcquireStringInfo(profile_length); 22993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy SetStringInfoDatum(profile,(const unsigned char *) info); 23003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) SetImageProfile(image,"icc",profile); 23013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy profile=DestroyStringInfo(profile); 23023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 23033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 23043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 23053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(PNG_READ_sRGB_SUPPORTED) 23063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 23073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->have_global_srgb) 2308cf002022280cc4dedb2748ad6f415aac1d44f530glennrp image->rendering_intent=Magick_RenderingIntent_from_PNG_RenderingIntent 2309cf002022280cc4dedb2748ad6f415aac1d44f530glennrp (mng_info->global_srgb_intent); 23100fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 23113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (png_get_sRGB(ping,ping_info,&intent)) 23123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 2313cf002022280cc4dedb2748ad6f415aac1d44f530glennrp image->rendering_intent=Magick_RenderingIntent_from_PNG_RenderingIntent 2314cf002022280cc4dedb2748ad6f415aac1d44f530glennrp (intent); 23150fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 23163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 23173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 2318e610a071534e448c46460a5aa39ede33bf56b329glennrp " Reading PNG sRGB chunk: rendering_intent: %d",intent); 23193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 23203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 23213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 23223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 2323faa852bad40107edae19405e76a299057668d795glennrp if (!png_get_gAMA(ping,ping_info,&file_gamma)) 2324faa852bad40107edae19405e76a299057668d795glennrp if (mng_info->have_global_gama) 2325faa852bad40107edae19405e76a299057668d795glennrp png_set_gAMA(ping,ping_info,mng_info->global_gamma); 23260fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 23273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (png_get_gAMA(ping,ping_info,&file_gamma)) 23283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 23293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->gamma=(float) file_gamma; 23303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 23313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 23323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Reading PNG gAMA chunk: gamma: %f",file_gamma); 23333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 23343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 2335faa852bad40107edae19405e76a299057668d795glennrp if (!png_get_valid(ping,ping_info,PNG_INFO_cHRM)) 2336faa852bad40107edae19405e76a299057668d795glennrp { 2337faa852bad40107edae19405e76a299057668d795glennrp if (mng_info->have_global_chrm != MagickFalse) 2338faa852bad40107edae19405e76a299057668d795glennrp { 2339faa852bad40107edae19405e76a299057668d795glennrp (void) png_set_cHRM(ping,ping_info, 2340faa852bad40107edae19405e76a299057668d795glennrp mng_info->global_chrm.white_point.x, 2341faa852bad40107edae19405e76a299057668d795glennrp mng_info->global_chrm.white_point.y, 2342faa852bad40107edae19405e76a299057668d795glennrp mng_info->global_chrm.red_primary.x, 2343faa852bad40107edae19405e76a299057668d795glennrp mng_info->global_chrm.red_primary.y, 2344faa852bad40107edae19405e76a299057668d795glennrp mng_info->global_chrm.green_primary.x, 2345faa852bad40107edae19405e76a299057668d795glennrp mng_info->global_chrm.green_primary.y, 2346faa852bad40107edae19405e76a299057668d795glennrp mng_info->global_chrm.blue_primary.x, 2347faa852bad40107edae19405e76a299057668d795glennrp mng_info->global_chrm.blue_primary.y); 2348faa852bad40107edae19405e76a299057668d795glennrp } 2349faa852bad40107edae19405e76a299057668d795glennrp } 23500fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 2351faa852bad40107edae19405e76a299057668d795glennrp if (png_get_valid(ping,ping_info,PNG_INFO_cHRM)) 23523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 23533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) png_get_cHRM(ping,ping_info, 23543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy &image->chromaticity.white_point.x, 23553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy &image->chromaticity.white_point.y, 23563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy &image->chromaticity.red_primary.x, 23573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy &image->chromaticity.red_primary.y, 23583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy &image->chromaticity.green_primary.x, 23593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy &image->chromaticity.green_primary.y, 23603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy &image->chromaticity.blue_primary.x, 23613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy &image->chromaticity.blue_primary.y); 23620fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 23633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 23643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 23653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Reading PNG cHRM chunk."); 23663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 23670fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 2368e610a071534e448c46460a5aa39ede33bf56b329glennrp if (image->rendering_intent != UndefinedIntent) 23693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 2370e610a071534e448c46460a5aa39ede33bf56b329glennrp png_set_sRGB(ping,ping_info, 2371cf002022280cc4dedb2748ad6f415aac1d44f530glennrp Magick_RenderingIntent_to_PNG_RenderingIntent 2372cf002022280cc4dedb2748ad6f415aac1d44f530glennrp (image->rendering_intent)); 2373faa852bad40107edae19405e76a299057668d795glennrp png_set_gAMA(ping,ping_info,0.45455f); 2374faa852bad40107edae19405e76a299057668d795glennrp png_set_cHRM(ping,ping_info, 2375faa852bad40107edae19405e76a299057668d795glennrp 0.6400f, 0.3300f, 0.3000f, 0.6000f, 2376faa852bad40107edae19405e76a299057668d795glennrp 0.1500f, 0.0600f, 0.3127f, 0.3290f); 23773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 23783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(PNG_oFFs_SUPPORTED) 2379faa852bad40107edae19405e76a299057668d795glennrp if (png_get_valid(ping,ping_info,PNG_INFO_oFFs)) 23803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 2381905ef80dad2c83a01a607533f7039528ca7766b9cristy image->page.x=(ssize_t) png_get_x_offset_pixels(ping, ping_info); 2382905ef80dad2c83a01a607533f7039528ca7766b9cristy image->page.y=(ssize_t) png_get_y_offset_pixels(ping, ping_info); 23830fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 23843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 23853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->page.x || image->page.y) 23863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 2387e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " Reading PNG oFFs chunk: x: %.20g, y: %.20g.",(double) 2388e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy image->page.x,(double) image->page.y); 23893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 23903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 23913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(PNG_pHYs_SUPPORTED) 2392faa852bad40107edae19405e76a299057668d795glennrp if (!png_get_valid(ping,ping_info,PNG_INFO_pHYs)) 2393faa852bad40107edae19405e76a299057668d795glennrp { 2394faa852bad40107edae19405e76a299057668d795glennrp if (mng_info->have_global_phys) 2395faa852bad40107edae19405e76a299057668d795glennrp { 2396faa852bad40107edae19405e76a299057668d795glennrp png_set_pHYs(ping,ping_info, 2397faa852bad40107edae19405e76a299057668d795glennrp mng_info->global_x_pixels_per_unit, 2398faa852bad40107edae19405e76a299057668d795glennrp mng_info->global_y_pixels_per_unit, 2399faa852bad40107edae19405e76a299057668d795glennrp mng_info->global_phys_unit_type); 2400faa852bad40107edae19405e76a299057668d795glennrp } 2401faa852bad40107edae19405e76a299057668d795glennrp } 2402faa852bad40107edae19405e76a299057668d795glennrp 2403faa852bad40107edae19405e76a299057668d795glennrp if (png_get_valid(ping,ping_info,PNG_INFO_pHYs)) 24043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 24053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 24063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Set image resolution. 24073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 24083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) png_get_pHYs(ping,ping_info,&x_resolution,&y_resolution, 24090881b52ab4fee8427578a694081946c4c4e92b35cristy &unit_type); 24100881b52ab4fee8427578a694081946c4c4e92b35cristy image->x_resolution=(double) x_resolution; 24110881b52ab4fee8427578a694081946c4c4e92b35cristy image->y_resolution=(double) y_resolution; 24120fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 24133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (unit_type == PNG_RESOLUTION_METER) 24143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 24153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->units=PixelsPerCentimeterResolution; 24163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->x_resolution=(double) x_resolution/100.0; 24173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->y_resolution=(double) y_resolution/100.0; 24183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 24190fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 24203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 24213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 2422e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " Reading PNG pHYs chunk: xres: %.20g, yres: %.20g, units: %d.", 2423e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy (double) x_resolution,(double) y_resolution,unit_type); 24243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 24253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 2426823b55c200d7fc1818ab539b036a9c24feaecda8glennrp 2427faa852bad40107edae19405e76a299057668d795glennrp if (png_get_valid(ping,ping_info,PNG_INFO_PLTE)) 24283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 24293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy int 24303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy number_colors; 24313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 24323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_colorp 24333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy palette; 24343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 24353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) png_get_PLTE(ping,ping_info,&palette,&number_colors); 24360fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 24373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((number_colors == 0) && 2438faa852bad40107edae19405e76a299057668d795glennrp ((int) ping_color_type == PNG_COLOR_TYPE_PALETTE)) 24393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 24403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->global_plte_length) 24413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 24423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_set_PLTE(ping,ping_info,mng_info->global_plte, 24433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (int) mng_info->global_plte_length); 24440fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 2445faa852bad40107edae19405e76a299057668d795glennrp if (!png_get_valid(ping,ping_info,PNG_INFO_tRNS)) 24463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->global_trns_length) 24473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 24483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->global_trns_length > 24493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->global_plte_length) 24503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ThrowMagickException(&image->exception, 24513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy GetMagickModule(),CoderError, 24523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy "global tRNS has more entries than global PLTE", 24533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy "`%s'",image_info->filename); 24543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_set_tRNS(ping,ping_info,mng_info->global_trns, 24553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (int) mng_info->global_trns_length,NULL); 24563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 2457bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp#ifdef PNG_READ_bKGD_SUPPORTED 24583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ( 24593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#ifndef PNG_READ_EMPTY_PLTE_SUPPORTED 24603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->have_saved_bkgd_index || 24613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 2462faa852bad40107edae19405e76a299057668d795glennrp png_get_valid(ping,ping_info,PNG_INFO_bKGD)) 24633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 24643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_color_16 24653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy background; 24663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 24673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#ifndef PNG_READ_EMPTY_PLTE_SUPPORTED 24683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->have_saved_bkgd_index) 24693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy background.index=mng_info->saved_bkgd_index; 24703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 2471faa852bad40107edae19405e76a299057668d795glennrp if (png_get_valid(ping, ping_info, PNG_INFO_bKGD)) 2472faa852bad40107edae19405e76a299057668d795glennrp background.index=ping_background->index; 24730fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 24743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy background.red=(png_uint_16) 24753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->global_plte[background.index].red; 24760fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 24773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy background.green=(png_uint_16) 24783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->global_plte[background.index].green; 24790fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 24803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy background.blue=(png_uint_16) 24813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->global_plte[background.index].blue; 24820fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 2483c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp background.gray=(png_uint_16) 2484c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp mng_info->global_plte[background.index].green; 2485c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp 24863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_set_bKGD(ping,ping_info,&background); 24873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 24883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 24893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 24903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 24913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ThrowMagickException(&image->exception,GetMagickModule(), 24923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy CoderError,"No global PLTE in file","`%s'", 24933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image_info->filename); 24943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 24953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 24963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 2497bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp#ifdef PNG_READ_bKGD_SUPPORTED 2498faa852bad40107edae19405e76a299057668d795glennrp if (mng_info->have_global_bkgd && 2499faa852bad40107edae19405e76a299057668d795glennrp (!png_get_valid(ping,ping_info,PNG_INFO_bKGD))) 25003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->background_color=mng_info->mng_global_bkgd; 25010fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 2502faa852bad40107edae19405e76a299057668d795glennrp if (png_get_valid(ping,ping_info,PNG_INFO_bKGD)) 25033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 2504bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp unsigned int 2505bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp bkgd_scale; 2506bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp 25073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 25083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Set image background color. 25093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 25103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 25113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 25123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Reading PNG bKGD chunk."); 25130fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 2514bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp /* Scale background components to 16-bit, then scale 2515bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp * to quantum depth 2516bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp */ 2517bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp if (logging != MagickFalse) 2518bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 2519bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp " raw ping_background=(%d,%d,%d).",ping_background->red, 2520bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp ping_background->green,ping_background->blue); 25212cbb4489df0a2a31907769956f217d4b9d982bd0glennrp 2522bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp bkgd_scale = 1; 25230fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 2524bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp if (ping_bit_depth == 1) 2525bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp bkgd_scale = 255; 25260fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 2527bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp else if (ping_bit_depth == 2) 2528bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp bkgd_scale = 85; 25290fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 2530bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp else if (ping_bit_depth == 4) 2531bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp bkgd_scale = 17; 25320fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 2533bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp if (ping_bit_depth <= 8) 2534bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp bkgd_scale *= 257; 25352cbb4489df0a2a31907769956f217d4b9d982bd0glennrp 2536bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp ping_background->red *= bkgd_scale; 2537bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp ping_background->green *= bkgd_scale; 2538bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp ping_background->blue *= bkgd_scale; 25392cbb4489df0a2a31907769956f217d4b9d982bd0glennrp 2540bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp if (logging != MagickFalse) 2541bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp { 25422cbb4489df0a2a31907769956f217d4b9d982bd0glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 25432cbb4489df0a2a31907769956f217d4b9d982bd0glennrp " bkgd_scale=%d.",bkgd_scale); 25440fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 25452cbb4489df0a2a31907769956f217d4b9d982bd0glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 25462cbb4489df0a2a31907769956f217d4b9d982bd0glennrp " ping_background=(%d,%d,%d).",ping_background->red, 25472cbb4489df0a2a31907769956f217d4b9d982bd0glennrp ping_background->green,ping_background->blue); 2548bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp } 25492cbb4489df0a2a31907769956f217d4b9d982bd0glennrp 2550bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp image->background_color.red= 2551faa852bad40107edae19405e76a299057668d795glennrp ScaleShortToQuantum(ping_background->red); 25520fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 2553bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp image->background_color.green= 2554faa852bad40107edae19405e76a299057668d795glennrp ScaleShortToQuantum(ping_background->green); 25550fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 2556bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp image->background_color.blue= 2557bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp ScaleShortToQuantum(ping_background->blue); 25580fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 25594c08aed51c5899665ade97263692328eea4af106cristy image->background_color.alpha=OpaqueAlpha; 25602cbb4489df0a2a31907769956f217d4b9d982bd0glennrp 2561bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp if (logging != MagickFalse) 2562bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 2563bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp " image->background_color=(%.20g,%.20g,%.20g).", 2564bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp (double) image->background_color.red, 2565bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp (double) image->background_color.green, 2566bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp (double) image->background_color.blue); 25673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 2568bfd9e61977198bea7d1ba9bf432226c6de0c38beglennrp#endif /* PNG_READ_bKGD_SUPPORTED */ 2569a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp 2570faa852bad40107edae19405e76a299057668d795glennrp if (png_get_valid(ping,ping_info,PNG_INFO_tRNS)) 25713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 25723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 2573a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp Image has a tRNS chunk. 25743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 25753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy int 25763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy max_sample; 25773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 257835ef824baa82511126ff0072ae30eee0da9c05a3cristy size_t 257935ef824baa82511126ff0072ae30eee0da9c05a3cristy one=1; 258035ef824baa82511126ff0072ae30eee0da9c05a3cristy 25813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 25823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 25833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Reading PNG tRNS chunk."); 25843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 2585f9cca6af1ff9b913c32a2cec81eda059877a8832cristy max_sample = (int) ((one << ping_bit_depth) - 1); 25863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 2587faa852bad40107edae19405e76a299057668d795glennrp if ((ping_color_type == PNG_COLOR_TYPE_GRAY && 2588faa852bad40107edae19405e76a299057668d795glennrp (int)ping_trans_color->gray > max_sample) || 2589faa852bad40107edae19405e76a299057668d795glennrp (ping_color_type == PNG_COLOR_TYPE_RGB && 2590faa852bad40107edae19405e76a299057668d795glennrp ((int)ping_trans_color->red > max_sample || 2591faa852bad40107edae19405e76a299057668d795glennrp (int)ping_trans_color->green > max_sample || 2592faa852bad40107edae19405e76a299057668d795glennrp (int)ping_trans_color->blue > max_sample))) 25933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 25943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 25953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 25963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Ignoring PNG tRNS chunk with out-of-range sample."); 25973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_free_data(ping, ping_info, PNG_FREE_TRNS, 0); 2598faa852bad40107edae19405e76a299057668d795glennrp png_set_invalid(ping,ping_info,PNG_INFO_tRNS); 25993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->matte=MagickFalse; 26003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 26013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 26023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 2603a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp int 2604a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp scale_to_short; 2605a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp 2606a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp scale_to_short = 65535L/((1UL << ping_bit_depth)-1); 2607a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp 2608a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp /* Scale transparent_color to short */ 2609a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp transparent_color.red= scale_to_short*ping_trans_color->red; 2610a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp transparent_color.green= scale_to_short*ping_trans_color->green; 2611a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp transparent_color.blue= scale_to_short*ping_trans_color->blue; 26124c08aed51c5899665ade97263692328eea4af106cristy transparent_color.alpha= scale_to_short*ping_trans_color->gray; 261305eb4a94b088c7f75605e7c1ec06bd13a6b34a3fglennrp 2614faa852bad40107edae19405e76a299057668d795glennrp if (ping_color_type == PNG_COLOR_TYPE_GRAY) 26153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 26160f111984738842d27d04aed2a3f823d82a943506glennrp if (logging != MagickFalse) 26170f111984738842d27d04aed2a3f823d82a943506glennrp { 26180f111984738842d27d04aed2a3f823d82a943506glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 26190f111984738842d27d04aed2a3f823d82a943506glennrp " Raw tRNS graylevel is %d.",ping_trans_color->gray); 26200fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 26210f111984738842d27d04aed2a3f823d82a943506glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 26224c08aed51c5899665ade97263692328eea4af106cristy " scaled graylevel is %d.",transparent_color.alpha); 26230f111984738842d27d04aed2a3f823d82a943506glennrp } 26244c08aed51c5899665ade97263692328eea4af106cristy transparent_color.red=transparent_color.alpha; 26254c08aed51c5899665ade97263692328eea4af106cristy transparent_color.green=transparent_color.alpha; 26264c08aed51c5899665ade97263692328eea4af106cristy transparent_color.blue=transparent_color.alpha; 26273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 26283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 26293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 26303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(PNG_READ_sBIT_SUPPORTED) 26313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->have_global_sbit) 26323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 2633faa852bad40107edae19405e76a299057668d795glennrp if (!png_get_valid(ping,ping_info,PNG_INFO_sBIT)) 26343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_set_sBIT(ping,ping_info,&mng_info->global_sbit); 26353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 26363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 26373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy num_passes=png_set_interlace_handling(ping); 2638faa852bad40107edae19405e76a299057668d795glennrp 26393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_read_update_info(ping,ping_info); 2640faa852bad40107edae19405e76a299057668d795glennrp 2641faa852bad40107edae19405e76a299057668d795glennrp ping_rowbytes=png_get_rowbytes(ping,ping_info); 2642faa852bad40107edae19405e76a299057668d795glennrp 26433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 26443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Initialize image structure. 26453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 26463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->image_box.left=0; 2647bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy mng_info->image_box.right=(ssize_t) ping_width; 26483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->image_box.top=0; 2649bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy mng_info->image_box.bottom=(ssize_t) ping_height; 26503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->mng_type == 0) 26513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 2652faa852bad40107edae19405e76a299057668d795glennrp mng_info->mng_width=ping_width; 2653faa852bad40107edae19405e76a299057668d795glennrp mng_info->mng_height=ping_height; 26543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->frame=mng_info->image_box; 26553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->clip=mng_info->image_box; 26563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 26570fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 26583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 26593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 26603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->page.y=mng_info->y_off[mng_info->object_id]; 26613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 26620fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 26633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->compression=ZipCompression; 2664faa852bad40107edae19405e76a299057668d795glennrp image->columns=ping_width; 2665faa852bad40107edae19405e76a299057668d795glennrp image->rows=ping_height; 2666faa852bad40107edae19405e76a299057668d795glennrp if (((int) ping_color_type == PNG_COLOR_TYPE_PALETTE) || 2667faa852bad40107edae19405e76a299057668d795glennrp ((int) ping_color_type == PNG_COLOR_TYPE_GRAY)) 26683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 2669befe4d21bf21c8f8fb5c8cc01fe60fe4accac47fcristy size_t 2670befe4d21bf21c8f8fb5c8cc01fe60fe4accac47fcristy one; 2671befe4d21bf21c8f8fb5c8cc01fe60fe4accac47fcristy 26723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->storage_class=PseudoClass; 2673befe4d21bf21c8f8fb5c8cc01fe60fe4accac47fcristy one=1; 2674befe4d21bf21c8f8fb5c8cc01fe60fe4accac47fcristy image->colors=one << ping_bit_depth; 26753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if (MAGICKCORE_QUANTUM_DEPTH == 8) 26763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->colors > 256) 267767b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp image->colors=256; 267867b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp#else 267967b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp if (image->colors > 65536L) 268067b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp image->colors=65536L; 26813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 2682faa852bad40107edae19405e76a299057668d795glennrp if ((int) ping_color_type == PNG_COLOR_TYPE_PALETTE) 26833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 26843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy int 26853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy number_colors; 26863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 26873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_colorp 26883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy palette; 26893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 26903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) png_get_PLTE(ping,ping_info,&palette,&number_colors); 2691bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy image->colors=(size_t) number_colors; 26920fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 26933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 26943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 26953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Reading PNG PLTE chunk: number_colors: %d.",number_colors); 26963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 26973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 26983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 26993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->storage_class == PseudoClass) 27003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 27013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 27023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Initialize image colormap. 27033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 27043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (AcquireImageColormap(image,image->colors) == MagickFalse) 27053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); 27060fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 2707faa852bad40107edae19405e76a299057668d795glennrp if ((int) ping_color_type == PNG_COLOR_TYPE_PALETTE) 27083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 27093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy int 27103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy number_colors; 27113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 27123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_colorp 27133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy palette; 27143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 27153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) png_get_PLTE(ping,ping_info,&palette,&number_colors); 27160fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 27176af6cf1a950b111ad0ac706269a703086693ba71glennrp for (i=0; i < (ssize_t) number_colors; i++) 27183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 27193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->colormap[i].red=ScaleCharToQuantum(palette[i].red); 27203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->colormap[i].green=ScaleCharToQuantum(palette[i].green); 27213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->colormap[i].blue=ScaleCharToQuantum(palette[i].blue); 27223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 27236af6cf1a950b111ad0ac706269a703086693ba71glennrp 272467b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp for ( ; i < (ssize_t) image->colors; i++) 27256af6cf1a950b111ad0ac706269a703086693ba71glennrp { 27266af6cf1a950b111ad0ac706269a703086693ba71glennrp image->colormap[i].red=0; 27276af6cf1a950b111ad0ac706269a703086693ba71glennrp image->colormap[i].green=0; 27286af6cf1a950b111ad0ac706269a703086693ba71glennrp image->colormap[i].blue=0; 27296af6cf1a950b111ad0ac706269a703086693ba71glennrp } 27303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 27310fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 27323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 27333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 2734bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy size_t 27353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy scale; 27363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 2737faa852bad40107edae19405e76a299057668d795glennrp scale=(QuantumRange/((1UL << ping_bit_depth)-1)); 27380fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 27393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (scale < 1) 27403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy scale=1; 27410fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 2742bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (i=0; i < (ssize_t) image->colors; i++) 27433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 27443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->colormap[i].red=(Quantum) (i*scale); 27453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->colormap[i].green=(Quantum) (i*scale); 27463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->colormap[i].blue=(Quantum) (i*scale); 27473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 27483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 27493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 2750147bc91f6859c598c4f57b6a162111b2f63614d9glennrp 2751cb395ac9c5c50c2829a9988f95fd8aea7af82c00glennrp /* Set some properties for reporting by "identify" */ 2752cb395ac9c5c50c2829a9988f95fd8aea7af82c00glennrp { 2753147bc91f6859c598c4f57b6a162111b2f63614d9glennrp char 2754147bc91f6859c598c4f57b6a162111b2f63614d9glennrp msg[MaxTextExtent]; 2755147bc91f6859c598c4f57b6a162111b2f63614d9glennrp 2756147bc91f6859c598c4f57b6a162111b2f63614d9glennrp /* encode ping_width, ping_height, ping_bit_depth, ping_color_type, 2757147bc91f6859c598c4f57b6a162111b2f63614d9glennrp ping_interlace_method in value */ 2758147bc91f6859c598c4f57b6a162111b2f63614d9glennrp 27593b6fd2ec2d9f69f9404445dba0aff5bac02e685ccristy (void) FormatLocaleString(msg,MaxTextExtent, 27607cdb11cd177ff29a9d2d8503ad4c920b404eade4glennrp "%d, %d",(int) ping_width, (int) ping_height); 27617cdb11cd177ff29a9d2d8503ad4c920b404eade4glennrp (void) SetImageProperty(image,"PNG:IHDR.width,height ",msg); 2762147bc91f6859c598c4f57b6a162111b2f63614d9glennrp 27633b6fd2ec2d9f69f9404445dba0aff5bac02e685ccristy (void) FormatLocaleString(msg,MaxTextExtent,"%d",(int) ping_bit_depth); 2764147bc91f6859c598c4f57b6a162111b2f63614d9glennrp (void) SetImageProperty(image,"PNG:IHDR.bit_depth ",msg); 2765147bc91f6859c598c4f57b6a162111b2f63614d9glennrp 27663b6fd2ec2d9f69f9404445dba0aff5bac02e685ccristy (void) FormatLocaleString(msg,MaxTextExtent,"%d",(int) ping_color_type); 2767147bc91f6859c598c4f57b6a162111b2f63614d9glennrp (void) SetImageProperty(image,"PNG:IHDR.color_type ",msg); 2768147bc91f6859c598c4f57b6a162111b2f63614d9glennrp 27693b6fd2ec2d9f69f9404445dba0aff5bac02e685ccristy (void) FormatLocaleString(msg,MaxTextExtent,"%d", 2770147bc91f6859c598c4f57b6a162111b2f63614d9glennrp (int) ping_interlace_method); 2771147bc91f6859c598c4f57b6a162111b2f63614d9glennrp (void) SetImageProperty(image,"PNG:IHDR.interlace_method",msg); 2772cb395ac9c5c50c2829a9988f95fd8aea7af82c00glennrp } 2773147bc91f6859c598c4f57b6a162111b2f63614d9glennrp 27743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 27753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Read image scanlines. 27763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 27773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->delay != 0) 27783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->scenes_found++; 27790fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 27800ca69b143ae83fb90449a01e0b0900cb83a1cbc8glennrp if ((mng_info->mng_type == 0 && (image->ping != MagickFalse)) || ( 2781347e40f2829bd04656674c58927cc50cda195475glennrp (image_info->number_scenes != 0) && (mng_info->scenes_found > (ssize_t) 2782347e40f2829bd04656674c58927cc50cda195475glennrp (image_info->first_scene+image_info->number_scenes)))) 27833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 27843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 27853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 2786e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " Skipping PNG image data for scene %.20g",(double) 27873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->scenes_found-1); 27883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_destroy_read_struct(&ping,&ping_info,&end_info); 27893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(PNG_SETJMP_NOT_THREAD_SAFE) 2790cf002022280cc4dedb2748ad6f415aac1d44f530glennrp UnlockSemaphoreInfo(ping_semaphore); 27913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 27923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 27933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 27943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " exit ReadOnePNGImage()."); 27950fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 27963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(image); 27973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 27980fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 27993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 28003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 28013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Reading PNG IDAT chunk(s)"); 28020fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 28033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (num_passes > 1) 2804cf002022280cc4dedb2748ad6f415aac1d44f530glennrp ping_pixels=(unsigned char *) AcquireQuantumMemory(image->rows, 2805cf002022280cc4dedb2748ad6f415aac1d44f530glennrp ping_rowbytes*sizeof(*ping_pixels)); 28060fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 28073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 2808cf002022280cc4dedb2748ad6f415aac1d44f530glennrp ping_pixels=(unsigned char *) AcquireQuantumMemory(ping_rowbytes, 2809cf002022280cc4dedb2748ad6f415aac1d44f530glennrp sizeof(*ping_pixels)); 28100fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 2811cf002022280cc4dedb2748ad6f415aac1d44f530glennrp if (ping_pixels == (unsigned char *) NULL) 28123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); 28130fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 28143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 28153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 28163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Converting PNG pixels to pixel packets"); 28173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 28183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Convert PNG pixels to pixel packets. 28193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 2820faa852bad40107edae19405e76a299057668d795glennrp if (setjmp(png_jmpbuf(ping))) 28213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 28223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 28233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNG image is corrupt. 28243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 28253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_destroy_read_struct(&ping,&ping_info,&end_info); 28263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(PNG_SETJMP_NOT_THREAD_SAFE) 2827cf002022280cc4dedb2748ad6f415aac1d44f530glennrp UnlockSemaphoreInfo(ping_semaphore); 28283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 28293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (quantum_info != (QuantumInfo *) NULL) 28303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy quantum_info = DestroyQuantumInfo(quantum_info); 28310fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 2832cf002022280cc4dedb2748ad6f415aac1d44f530glennrp if (ping_pixels != (unsigned char *) NULL) 2833cf002022280cc4dedb2748ad6f415aac1d44f530glennrp ping_pixels=(unsigned char *) RelinquishMagickMemory(ping_pixels); 28340fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 28353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 28363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 28373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " exit ReadOnePNGImage() with error."); 28380fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 28393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image != (Image *) NULL) 28407b755eb4f94efbb57160cce0d7afe7f8ed4ef066cristy { 28417b755eb4f94efbb57160cce0d7afe7f8ed4ef066cristy InheritException(exception,&image->exception); 28427b755eb4f94efbb57160cce0d7afe7f8ed4ef066cristy image->columns=0; 28437b755eb4f94efbb57160cce0d7afe7f8ed4ef066cristy } 28440fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 28453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(GetFirstImageInList(image)); 28463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 28470fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 2848ed5525230af20461366cdc5b8bbe0f7f9b166c44cristy quantum_info=AcquireQuantumInfo(image_info,image); 28490fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 2850ed5525230af20461366cdc5b8bbe0f7f9b166c44cristy if (quantum_info == (QuantumInfo *) NULL) 2851ed5525230af20461366cdc5b8bbe0f7f9b166c44cristy ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); 28520fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 2853c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp { 2854c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp 2855c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp MagickBooleanType 2856c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp found_transparent_pixel; 2857c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp 2858c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp found_transparent_pixel=MagickFalse; 2859c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp 28603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->storage_class == DirectClass) 28613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 2862c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp for (pass=0; pass < num_passes; pass++) 2863c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp { 2864c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp /* 2865c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp Convert image to DirectClass pixel packets. 2866c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp */ 286767b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp#if (MAGICKCORE_QUANTUM_DEPTH == 8) 286867b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp int 286967b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp depth; 287067b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp 287167b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp depth=(ssize_t) ping_bit_depth; 287267b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp#endif 2873c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp image->matte=(((int) ping_color_type == PNG_COLOR_TYPE_RGB_ALPHA) || 2874c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp ((int) ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA) || 2875c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp (png_get_valid(ping,ping_info,PNG_INFO_tRNS))) ? 2876c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp MagickTrue : MagickFalse; 28770fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 2878c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp for (y=0; y < (ssize_t) image->rows; y++) 2879c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp { 2880c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp if (num_passes > 1) 2881c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp row_offset=ping_rowbytes*y; 28820fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 2883c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp else 2884c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp row_offset=0; 28850fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 2886cf002022280cc4dedb2748ad6f415aac1d44f530glennrp png_read_row(ping,ping_pixels+row_offset,NULL); 2887c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); 28883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 28894c08aed51c5899665ade97263692328eea4af106cristy if (q == (const Quantum *) NULL) 2890c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp break; 28910fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 2892c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp if ((int) ping_color_type == PNG_COLOR_TYPE_GRAY) 28933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info, 2894cf002022280cc4dedb2748ad6f415aac1d44f530glennrp GrayQuantum,ping_pixels+row_offset,exception); 28950fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 2896c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp else if ((int) ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA) 28973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info, 2898cf002022280cc4dedb2748ad6f415aac1d44f530glennrp GrayAlphaQuantum,ping_pixels+row_offset,exception); 28990fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 2900c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp else if ((int) ping_color_type == PNG_COLOR_TYPE_RGB_ALPHA) 29013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info, 2902cf002022280cc4dedb2748ad6f415aac1d44f530glennrp RGBAQuantum,ping_pixels+row_offset,exception); 29030fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 2904c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp else if ((int) ping_color_type == PNG_COLOR_TYPE_PALETTE) 2905c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info, 2906cf002022280cc4dedb2748ad6f415aac1d44f530glennrp IndexQuantum,ping_pixels+row_offset,exception); 29070fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 2908c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp else /* ping_color_type == PNG_COLOR_TYPE_RGB */ 2909c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info, 2910cf002022280cc4dedb2748ad6f415aac1d44f530glennrp RGBQuantum,ping_pixels+row_offset,exception); 29113faa9a3fb01696daaf976d595f492cb530bffb21glennrp 2912c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp if (found_transparent_pixel == MagickFalse) 2913c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp { 2914c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp /* Is there a transparent pixel in the row? */ 2915a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp if (y== 0 && logging != MagickFalse) 2916a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 2917a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp " Looking for cheap transparent pixel"); 2918a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp 2919c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp for (x=(ssize_t) image->columns-1; x >= 0; x--) 2920c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp { 29215aa37f69df93407ddf94afdfd2504f708d8b3242glennrp if ((ping_color_type == PNG_COLOR_TYPE_RGBA || 29225aa37f69df93407ddf94afdfd2504f708d8b3242glennrp ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA) && 29234c08aed51c5899665ade97263692328eea4af106cristy (GetPixelAlpha(image,q) != OpaqueAlpha)) 2924c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp { 2925a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp if (logging != MagickFalse) 2926a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 2927a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp " ...got one."); 2928a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp 2929c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp found_transparent_pixel = MagickTrue; 2930c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp break; 2931c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp } 29324f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp if ((ping_color_type == PNG_COLOR_TYPE_RGB || 29334f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp ping_color_type == PNG_COLOR_TYPE_GRAY) && 2934847370c32c6b67817205f49897c43c540fd670c4glennrp (ScaleQuantumToShort(GetPixelRed(image,q)) == 2935847370c32c6b67817205f49897c43c540fd670c4glennrp transparent_color.red && 2936847370c32c6b67817205f49897c43c540fd670c4glennrp ScaleQuantumToShort(GetPixelGreen(image,q)) == 2937847370c32c6b67817205f49897c43c540fd670c4glennrp transparent_color.green && 2938847370c32c6b67817205f49897c43c540fd670c4glennrp ScaleQuantumToShort(GetPixelBlue(image,q)) == 2939847370c32c6b67817205f49897c43c540fd670c4glennrp transparent_color.blue)) 29404f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp { 2941a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp if (logging != MagickFalse) 2942a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 2943a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp " ...got one."); 29444f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp found_transparent_pixel = MagickTrue; 29454f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp break; 29464f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp } 29474c08aed51c5899665ade97263692328eea4af106cristy q+=GetPixelChannels(image); 2948c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp } 2949c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp } 29500fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 2951c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp if ((image->previous == (Image *) NULL) && (num_passes == 1)) 2952c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp { 2953c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, 2954c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp image->rows); 29550fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 2956c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp if (status == MagickFalse) 2957c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp break; 2958c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp } 2959c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp if (SyncAuthenticPixels(image,exception) == MagickFalse) 2960c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp break; 2961c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp } 29620fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 2963c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp if ((image->previous == (Image *) NULL) && (num_passes != 1)) 29647a287bfadeadea12e47c2376ca78a5d101687142cristy { 2965c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp status=SetImageProgress(image,LoadImageTag,pass,num_passes); 29667a287bfadeadea12e47c2376ca78a5d101687142cristy if (status == MagickFalse) 29677a287bfadeadea12e47c2376ca78a5d101687142cristy break; 29687a287bfadeadea12e47c2376ca78a5d101687142cristy } 29693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 29703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 29710fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 29723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else /* image->storage_class != DirectClass */ 2973c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp 29743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy for (pass=0; pass < num_passes; pass++) 29753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 29763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Quantum 29773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *quantum_scanline; 29783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 29793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy register Quantum 29803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *r; 29813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 29823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 29833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Convert grayscale image to PseudoClass pixel packets. 29843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 2985c17d96f447438bb27d874f1440ed05f6493fde1fglennrp if (logging != MagickFalse) 2986c17d96f447438bb27d874f1440ed05f6493fde1fglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 2987c17d96f447438bb27d874f1440ed05f6493fde1fglennrp " Converting grayscale pixels to pixel packets"); 29884c08aed51c5899665ade97263692328eea4af106cristy 2989faa852bad40107edae19405e76a299057668d795glennrp image->matte=ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA ? 29903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MagickTrue : MagickFalse; 29910fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 29923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy quantum_scanline=(Quantum *) AcquireQuantumMemory(image->columns, 29933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (image->matte ? 2 : 1)*sizeof(*quantum_scanline)); 29940fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 29953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (quantum_scanline == (Quantum *) NULL) 29963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); 29970fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 2998bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (y=0; y < (ssize_t) image->rows; y++) 29993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 30003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (num_passes > 1) 3001faa852bad40107edae19405e76a299057668d795glennrp row_offset=ping_rowbytes*y; 3002c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp 30033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 30043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy row_offset=0; 3005c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp 3006cf002022280cc4dedb2748ad6f415aac1d44f530glennrp png_read_row(ping,ping_pixels+row_offset,NULL); 30073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy q=GetAuthenticPixels(image,0,y,image->columns,1,exception); 30080fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 30094c08aed51c5899665ade97263692328eea4af106cristy if (q == (const Quantum *) NULL) 30103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 30110fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 3012cf002022280cc4dedb2748ad6f415aac1d44f530glennrp p=ping_pixels+row_offset; 30133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy r=quantum_scanline; 3014c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp 3015faa852bad40107edae19405e76a299057668d795glennrp switch (ping_bit_depth) 30163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 30173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case 1: 30183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 3019bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy register ssize_t 30203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy bit; 30213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 3022bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (x=(ssize_t) image->columns-7; x > 0; x-=8) 30233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 30243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy for (bit=7; bit >= 0; bit--) 3025a18d5bc7daf77f267862e1dfeee6fa0e5e2ea6e8glennrp *r++=(Quantum) ((*p) & (0x01 << bit) ? 0x01 : 0x00); 30263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy p++; 30273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 30280fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 30293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((image->columns % 8) != 0) 30303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 3031bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (bit=7; bit >= (ssize_t) (8-(image->columns % 8)); bit--) 3032a18d5bc7daf77f267862e1dfeee6fa0e5e2ea6e8glennrp *r++=(Quantum) ((*p) & (0x01 << bit) ? 0x01 : 0x00); 30333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 30340fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 30353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 30363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 303747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 30383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case 2: 30393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 3040bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (x=(ssize_t) image->columns-3; x > 0; x-=4) 30413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 3042a18d5bc7daf77f267862e1dfeee6fa0e5e2ea6e8glennrp *r++=(*p >> 6) & 0x03; 3043a18d5bc7daf77f267862e1dfeee6fa0e5e2ea6e8glennrp *r++=(*p >> 4) & 0x03; 3044a18d5bc7daf77f267862e1dfeee6fa0e5e2ea6e8glennrp *r++=(*p >> 2) & 0x03; 3045a18d5bc7daf77f267862e1dfeee6fa0e5e2ea6e8glennrp *r++=(*p++) & 0x03; 30463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 30470fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 30483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((image->columns % 4) != 0) 30493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 3050bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (i=3; i >= (ssize_t) (4-(image->columns % 4)); i--) 3051a18d5bc7daf77f267862e1dfeee6fa0e5e2ea6e8glennrp *r++=(Quantum) ((*p >> (i*2)) & 0x03); 30523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 30530fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 30543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 30553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 305647b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 30573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case 4: 30583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 3059bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (x=(ssize_t) image->columns-1; x > 0; x-=2) 30603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 3061a18d5bc7daf77f267862e1dfeee6fa0e5e2ea6e8glennrp *r++=(*p >> 4) & 0x0f; 3062a18d5bc7daf77f267862e1dfeee6fa0e5e2ea6e8glennrp *r++=(*p++) & 0x0f; 30633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 30640fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 30653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((image->columns % 2) != 0) 3066a18d5bc7daf77f267862e1dfeee6fa0e5e2ea6e8glennrp *r++=(*p++ >> 4) & 0x0f; 30670fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 30683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 30693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 307047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 30713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case 8: 30723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 3073faa852bad40107edae19405e76a299057668d795glennrp if (ping_color_type == 4) 3074bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (x=(ssize_t) image->columns-1; x >= 0; x--) 30753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 3076a18d5bc7daf77f267862e1dfeee6fa0e5e2ea6e8glennrp *r++=*p++; 30774c08aed51c5899665ade97263692328eea4af106cristy SetPixelAlpha(image,ScaleCharToQuantum((unsigned char) *p++),q); 30784c08aed51c5899665ade97263692328eea4af106cristy if (GetPixelAlpha(image,q) != OpaqueAlpha) 30790b206f5daa453dc1035db5890cabc899736dc2d0glennrp found_transparent_pixel = MagickTrue; 30804c08aed51c5899665ade97263692328eea4af106cristy q+=GetPixelChannels(image); 30813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 30820fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 30833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 3084bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (x=(ssize_t) image->columns-1; x >= 0; x--) 3085a18d5bc7daf77f267862e1dfeee6fa0e5e2ea6e8glennrp *r++=*p++; 30860fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 30873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 30883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 308947b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 30903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case 16: 30913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 3092bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (x=(ssize_t) image->columns-1; x >= 0; x--) 3093a18d5bc7daf77f267862e1dfeee6fa0e5e2ea6e8glennrp { 3094c17d96f447438bb27d874f1440ed05f6493fde1fglennrp#if (MAGICKCORE_QUANTUM_DEPTH == 16) || (MAGICKCORE_QUANTUM_DEPTH == 32) 309558f77c7678f35e372fd218e4bb0b9cb8937daed7glennrp size_t 309658f77c7678f35e372fd218e4bb0b9cb8937daed7glennrp quantum; 309758f77c7678f35e372fd218e4bb0b9cb8937daed7glennrp 309858f77c7678f35e372fd218e4bb0b9cb8937daed7glennrp if (image->colors > 256) 3099c17d96f447438bb27d874f1440ed05f6493fde1fglennrp quantum=((*p++) << 8); 310058f77c7678f35e372fd218e4bb0b9cb8937daed7glennrp 310158f77c7678f35e372fd218e4bb0b9cb8937daed7glennrp else 3102c17d96f447438bb27d874f1440ed05f6493fde1fglennrp quantum=0; 310358f77c7678f35e372fd218e4bb0b9cb8937daed7glennrp 310458f77c7678f35e372fd218e4bb0b9cb8937daed7glennrp quantum|=(*p++); 3105c17d96f447438bb27d874f1440ed05f6493fde1fglennrp *r=ScaleShortToQuantum(quantum); 310658f77c7678f35e372fd218e4bb0b9cb8937daed7glennrp r++; 31070fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 3108faa852bad40107edae19405e76a299057668d795glennrp if (ping_color_type == 4) 31093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 3110c17d96f447438bb27d874f1440ed05f6493fde1fglennrp if (image->colors > 256) 3111c17d96f447438bb27d874f1440ed05f6493fde1fglennrp quantum=((*p++) << 8); 3112c17d96f447438bb27d874f1440ed05f6493fde1fglennrp else 3113c17d96f447438bb27d874f1440ed05f6493fde1fglennrp quantum=0; 3114c17d96f447438bb27d874f1440ed05f6493fde1fglennrp 3115c17d96f447438bb27d874f1440ed05f6493fde1fglennrp quantum|=(*p++); 31164c08aed51c5899665ade97263692328eea4af106cristy SetPixelAlpha(image,ScaleShortToQuantum(quantum),q); 31174c08aed51c5899665ade97263692328eea4af106cristy if (GetPixelAlpha(image,q) != OpaqueAlpha) 311858f77c7678f35e372fd218e4bb0b9cb8937daed7glennrp found_transparent_pixel = MagickTrue; 31194c08aed51c5899665ade97263692328eea4af106cristy q+=GetPixelChannels(image); 312058f77c7678f35e372fd218e4bb0b9cb8937daed7glennrp } 312158f77c7678f35e372fd218e4bb0b9cb8937daed7glennrp 312258f77c7678f35e372fd218e4bb0b9cb8937daed7glennrp#else /* MAGICKCORE_QUANTUM_DEPTH == 8 */ 312358f77c7678f35e372fd218e4bb0b9cb8937daed7glennrp *r++=(*p++); 312458f77c7678f35e372fd218e4bb0b9cb8937daed7glennrp p++; /* strip low byte */ 312547b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 312658f77c7678f35e372fd218e4bb0b9cb8937daed7glennrp if (ping_color_type == 4) 312758f77c7678f35e372fd218e4bb0b9cb8937daed7glennrp { 31284c08aed51c5899665ade97263692328eea4af106cristy SetPixelAlpha(image,*p++,q); 31294c08aed51c5899665ade97263692328eea4af106cristy if (GetPixelAlpha(image,q) != OpaqueAlpha) 31300b206f5daa453dc1035db5890cabc899736dc2d0glennrp found_transparent_pixel = MagickTrue; 313158f77c7678f35e372fd218e4bb0b9cb8937daed7glennrp p++; 31324c08aed51c5899665ade97263692328eea4af106cristy q+=GetPixelChannels(image); 31333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 31343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 3135a18d5bc7daf77f267862e1dfeee6fa0e5e2ea6e8glennrp } 313647b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 31373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 31383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 313947b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 31403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy default: 31413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 31423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 31433faa9a3fb01696daaf976d595f492cb530bffb21glennrp 31443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 31453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Transfer image scanline. 31463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 31473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy r=quantum_scanline; 31480fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 31494c08aed51c5899665ade97263692328eea4af106cristy q=GetAuthenticPixels(image,0,y,image->columns,1,exception); 31504c08aed51c5899665ade97263692328eea4af106cristy 31514c08aed51c5899665ade97263692328eea4af106cristy if (q == (const Quantum *) NULL) 31524c08aed51c5899665ade97263692328eea4af106cristy break; 3153bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (x=0; x < (ssize_t) image->columns; x++) 31544c08aed51c5899665ade97263692328eea4af106cristy { 31554c08aed51c5899665ade97263692328eea4af106cristy SetPixelIndex(image,*r++,q); 31564c08aed51c5899665ade97263692328eea4af106cristy q+=GetPixelChannels(image); 31574c08aed51c5899665ade97263692328eea4af106cristy } 31580fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 31593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (SyncAuthenticPixels(image,exception) == MagickFalse) 31603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 31610fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 31627a287bfadeadea12e47c2376ca78a5d101687142cristy if ((image->previous == (Image *) NULL) && (num_passes == 1)) 31637a287bfadeadea12e47c2376ca78a5d101687142cristy { 3164cee9711bbc334b5677d5ec4ea1cc70340d35ee35cristy status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, 31659fff7b4fa7d657da7bfed66239982b85c6337de9cristy image->rows); 316647b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 31677a287bfadeadea12e47c2376ca78a5d101687142cristy if (status == MagickFalse) 31687a287bfadeadea12e47c2376ca78a5d101687142cristy break; 31697a287bfadeadea12e47c2376ca78a5d101687142cristy } 31703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 3171c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp 31727a287bfadeadea12e47c2376ca78a5d101687142cristy if ((image->previous == (Image *) NULL) && (num_passes != 1)) 31733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 31743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status=SetImageProgress(image,LoadImageTag,pass,num_passes); 317547b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 31763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (status == MagickFalse) 31773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 31783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 3179c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp 31803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy quantum_scanline=(Quantum *) RelinquishMagickMemory(quantum_scanline); 31813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 3182c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp 3183c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp image->matte=found_transparent_pixel; 3184c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp 3185c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp if (logging != MagickFalse) 3186c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp { 3187c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp if (found_transparent_pixel != MagickFalse) 3188c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 3189c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp " Found transparent pixel"); 3190c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp else 31915aa37f69df93407ddf94afdfd2504f708d8b3242glennrp { 31925aa37f69df93407ddf94afdfd2504f708d8b3242glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 31935aa37f69df93407ddf94afdfd2504f708d8b3242glennrp " No transparent pixel was found"); 3194bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp 31955aa37f69df93407ddf94afdfd2504f708d8b3242glennrp ping_color_type&=0x03; 31965aa37f69df93407ddf94afdfd2504f708d8b3242glennrp } 3197c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp } 3198c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp } 3199c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp 3200b32b90a7e1ee2275333589072c496b5f69e17feccristy if (quantum_info != (QuantumInfo *) NULL) 3201b32b90a7e1ee2275333589072c496b5f69e17feccristy quantum_info=DestroyQuantumInfo(quantum_info); 32020fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 32035c6f789db7a30bad01ace12b09ad9cd471339e94cristy if (image->storage_class == PseudoClass) 32045c6f789db7a30bad01ace12b09ad9cd471339e94cristy { 3205aeb2cbc4eb61cc6a04744db1dc52f5319c466e29cristy MagickBooleanType 32065c6f789db7a30bad01ace12b09ad9cd471339e94cristy matte; 32075c6f789db7a30bad01ace12b09ad9cd471339e94cristy 32085c6f789db7a30bad01ace12b09ad9cd471339e94cristy matte=image->matte; 32095c6f789db7a30bad01ace12b09ad9cd471339e94cristy image->matte=MagickFalse; 32105c6f789db7a30bad01ace12b09ad9cd471339e94cristy (void) SyncImage(image); 3211aeb2cbc4eb61cc6a04744db1dc52f5319c466e29cristy image->matte=matte; 32125c6f789db7a30bad01ace12b09ad9cd471339e94cristy } 321347b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 32144eb3931feb349dd87142c78503b779228f3e1a0fglennrp png_read_end(ping,end_info); 32153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 32163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image_info->number_scenes != 0 && mng_info->scenes_found-1 < 3217bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy (ssize_t) image_info->first_scene && image->delay != 0) 32183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 32193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_destroy_read_struct(&ping,&ping_info,&end_info); 3220cf002022280cc4dedb2748ad6f415aac1d44f530glennrp ping_pixels=(unsigned char *) RelinquishMagickMemory(ping_pixels); 32213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->colors=2; 32223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) SetImageBackgroundColor(image); 32233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(PNG_SETJMP_NOT_THREAD_SAFE) 3224cf002022280cc4dedb2748ad6f415aac1d44f530glennrp UnlockSemaphoreInfo(ping_semaphore); 32253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 32263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 32273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 32283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " exit ReadOnePNGImage() early."); 32293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(image); 32303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 323147b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 3232faa852bad40107edae19405e76a299057668d795glennrp if (png_get_valid(ping,ping_info,PNG_INFO_tRNS)) 32333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 32343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ClassType 32353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy storage_class; 32363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 32373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 32383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Image has a transparent background. 32393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 32403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy storage_class=image->storage_class; 32413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->matte=MagickTrue; 3242c11cf6a442f3046940608a5743a68cc891deb13eglennrp 32433c21811cab8a3b168295e3f0da1909c4e2a7da15glennrp/* Balfour fix from imagemagick discourse server, 5 Feb 2010 */ 3244c11cf6a442f3046940608a5743a68cc891deb13eglennrp 32450fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp if (storage_class == PseudoClass) 32460fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp { 32470fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp if ((int) ping_color_type == PNG_COLOR_TYPE_PALETTE) 3248c11cf6a442f3046940608a5743a68cc891deb13eglennrp { 32490fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp for (x=0; x < ping_num_trans; x++) 32500fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp { 32514c08aed51c5899665ade97263692328eea4af106cristy image->colormap[x].alpha = 32524c08aed51c5899665ade97263692328eea4af106cristy ScaleCharToQuantum((unsigned char)ping_trans_alpha[x]); 32530fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp } 3254c11cf6a442f3046940608a5743a68cc891deb13eglennrp } 325547b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 32560fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp else if (ping_color_type == PNG_COLOR_TYPE_GRAY) 32570fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp { 32580fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp for (x=0; x < (int) image->colors; x++) 32590fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp { 32600fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp if (ScaleQuantumToShort(image->colormap[x].red) == 32614c08aed51c5899665ade97263692328eea4af106cristy transparent_color.alpha) 32620fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp { 32634c08aed51c5899665ade97263692328eea4af106cristy image->colormap[x].alpha = (Quantum) TransparentAlpha; 32640fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp } 32650fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp } 32660fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp } 32670fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp (void) SyncImage(image); 32680fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp } 326947b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 3270a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp#if 1 /* Should have already been done above, but glennrp problem P10 3271a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp * needs this. 3272a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp */ 32730fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp else 32740fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp { 32750fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp for (y=0; y < (ssize_t) image->rows; y++) 32760fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp { 32770fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp image->storage_class=storage_class; 32780fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp q=GetAuthenticPixels(image,0,y,image->columns,1,exception); 3279c11cf6a442f3046940608a5743a68cc891deb13eglennrp 32804c08aed51c5899665ade97263692328eea4af106cristy if (q == (const Quantum *) NULL) 32810fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp break; 3282c11cf6a442f3046940608a5743a68cc891deb13eglennrp 32830fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 3284a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp /* Caution: on a Q8 build, this does not distinguish between 3285a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp * 16-bit colors that differ only in the low byte 3286a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp */ 32870fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp for (x=(ssize_t) image->columns-1; x >= 0; x--) 32880fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp { 3289847370c32c6b67817205f49897c43c540fd670c4glennrp if (ScaleQuantumToShort(GetPixelRed(image,q)) == 3290847370c32c6b67817205f49897c43c540fd670c4glennrp transparent_color.red && 3291847370c32c6b67817205f49897c43c540fd670c4glennrp ScaleQuantumToShort(GetPixelGreen(image,q)) == 3292847370c32c6b67817205f49897c43c540fd670c4glennrp transparent_color.green && 3293847370c32c6b67817205f49897c43c540fd670c4glennrp ScaleQuantumToShort(GetPixelBlue(image,q)) == 3294847370c32c6b67817205f49897c43c540fd670c4glennrp transparent_color.blue) 32954f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp { 32964c08aed51c5899665ade97263692328eea4af106cristy SetPixelAlpha(image,TransparentAlpha,q); 32974f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp } 32980fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 329967b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp#if 0 /* I have not found a case where this is needed. */ 33000fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp else 33014f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp { 33024c08aed51c5899665ade97263692328eea4af106cristy SetPixelAlpha(image,q)=(Quantum) OpaqueAlpha; 33034f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp } 3304a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp#endif 33050fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 33064c08aed51c5899665ade97263692328eea4af106cristy q+=GetPixelChannels(image); 33070fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp } 33080fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 33090fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp if (SyncAuthenticPixels(image,exception) == MagickFalse) 33100fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp break; 3311c11cf6a442f3046940608a5743a68cc891deb13eglennrp } 33120fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp } 3313a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp#endif 3314c11cf6a442f3046940608a5743a68cc891deb13eglennrp 33153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->storage_class=DirectClass; 33163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 33173c21811cab8a3b168295e3f0da1909c4e2a7da15glennrp 3318b40fc46321caef77f32743c0dc22e9a4bcc88e71cristy if ((ping_color_type == PNG_COLOR_TYPE_GRAY) || 3319b40fc46321caef77f32743c0dc22e9a4bcc88e71cristy (ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA)) 3320b40fc46321caef77f32743c0dc22e9a4bcc88e71cristy image->colorspace=GRAYColorspace; 332147b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 3322eb3b22a03f31af7f724573d8537cd91fca06ee41cristy for (j = 0; j < 2; j++) 33234eb3931feb349dd87142c78503b779228f3e1a0fglennrp { 33244eb3931feb349dd87142c78503b779228f3e1a0fglennrp if (j == 0) 3325a0ed009a1e9480ac6f3f4520e9ef29d6d37e27dcglennrp status = png_get_text(ping,ping_info,&text,&num_text) != 0 ? 3326a0ed009a1e9480ac6f3f4520e9ef29d6d37e27dcglennrp MagickTrue : MagickFalse; 33274eb3931feb349dd87142c78503b779228f3e1a0fglennrp else 3328a0ed009a1e9480ac6f3f4520e9ef29d6d37e27dcglennrp status = png_get_text(ping,end_info,&text,&num_text) != 0 ? 3329a0ed009a1e9480ac6f3f4520e9ef29d6d37e27dcglennrp MagickTrue : MagickFalse; 33303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 33314eb3931feb349dd87142c78503b779228f3e1a0fglennrp if (status != MagickFalse) 33324eb3931feb349dd87142c78503b779228f3e1a0fglennrp for (i=0; i < (ssize_t) num_text; i++) 33334eb3931feb349dd87142c78503b779228f3e1a0fglennrp { 33344eb3931feb349dd87142c78503b779228f3e1a0fglennrp /* Check for a profile */ 33350fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 33364eb3931feb349dd87142c78503b779228f3e1a0fglennrp if (logging != MagickFalse) 33374eb3931feb349dd87142c78503b779228f3e1a0fglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 33384eb3931feb349dd87142c78503b779228f3e1a0fglennrp " Reading PNG text chunk"); 33390fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 33404eb3931feb349dd87142c78503b779228f3e1a0fglennrp if (memcmp(text[i].key, "Raw profile type ",17) == 0) 33414eb3931feb349dd87142c78503b779228f3e1a0fglennrp { 33424eb3931feb349dd87142c78503b779228f3e1a0fglennrp (void) Magick_png_read_raw_profile(image,image_info,text,(int) i); 33434eb3931feb349dd87142c78503b779228f3e1a0fglennrp num_raw_profiles++; 33444eb3931feb349dd87142c78503b779228f3e1a0fglennrp } 33454eb3931feb349dd87142c78503b779228f3e1a0fglennrp 33464eb3931feb349dd87142c78503b779228f3e1a0fglennrp else 33474eb3931feb349dd87142c78503b779228f3e1a0fglennrp { 33484eb3931feb349dd87142c78503b779228f3e1a0fglennrp char 33494eb3931feb349dd87142c78503b779228f3e1a0fglennrp *value; 33504eb3931feb349dd87142c78503b779228f3e1a0fglennrp 33514eb3931feb349dd87142c78503b779228f3e1a0fglennrp length=text[i].text_length; 33524eb3931feb349dd87142c78503b779228f3e1a0fglennrp value=(char *) AcquireQuantumMemory(length+MaxTextExtent, 33534eb3931feb349dd87142c78503b779228f3e1a0fglennrp sizeof(*value)); 33544eb3931feb349dd87142c78503b779228f3e1a0fglennrp if (value == (char *) NULL) 33554eb3931feb349dd87142c78503b779228f3e1a0fglennrp { 33564eb3931feb349dd87142c78503b779228f3e1a0fglennrp (void) ThrowMagickException(&image->exception,GetMagickModule(), 33574eb3931feb349dd87142c78503b779228f3e1a0fglennrp ResourceLimitError,"MemoryAllocationFailed","`%s'", 33584eb3931feb349dd87142c78503b779228f3e1a0fglennrp image->filename); 33594eb3931feb349dd87142c78503b779228f3e1a0fglennrp break; 33604eb3931feb349dd87142c78503b779228f3e1a0fglennrp } 33614eb3931feb349dd87142c78503b779228f3e1a0fglennrp *value='\0'; 33624eb3931feb349dd87142c78503b779228f3e1a0fglennrp (void) ConcatenateMagickString(value,text[i].text,length+2); 33634eb3931feb349dd87142c78503b779228f3e1a0fglennrp 33644eb3931feb349dd87142c78503b779228f3e1a0fglennrp /* Don't save "density" or "units" property if we have a pHYs 33654eb3931feb349dd87142c78503b779228f3e1a0fglennrp * chunk 33664eb3931feb349dd87142c78503b779228f3e1a0fglennrp */ 33674eb3931feb349dd87142c78503b779228f3e1a0fglennrp if (!png_get_valid(ping,ping_info,PNG_INFO_pHYs) || 33684eb3931feb349dd87142c78503b779228f3e1a0fglennrp (LocaleCompare(text[i].key,"density") != 0 && 33694eb3931feb349dd87142c78503b779228f3e1a0fglennrp LocaleCompare(text[i].key,"units") != 0)) 33704eb3931feb349dd87142c78503b779228f3e1a0fglennrp (void) SetImageProperty(image,text[i].key,value); 33713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 33724eb3931feb349dd87142c78503b779228f3e1a0fglennrp if (logging != MagickFalse) 33733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 33744eb3931feb349dd87142c78503b779228f3e1a0fglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 33754eb3931feb349dd87142c78503b779228f3e1a0fglennrp " length: %lu",(unsigned long) length); 33764eb3931feb349dd87142c78503b779228f3e1a0fglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 33774eb3931feb349dd87142c78503b779228f3e1a0fglennrp " Keyword: %s",text[i].key); 33783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 33790fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 33804eb3931feb349dd87142c78503b779228f3e1a0fglennrp value=DestroyString(value); 338197f90e23c85b9c58387880125c29d8c99126f83aglennrp } 33824eb3931feb349dd87142c78503b779228f3e1a0fglennrp } 33834eb3931feb349dd87142c78503b779228f3e1a0fglennrp num_text_total += num_text; 33843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 33853c21811cab8a3b168295e3f0da1909c4e2a7da15glennrp 33863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#ifdef MNG_OBJECT_BUFFERS 33873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 33883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Store the object if necessary. 33893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 33903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (object_id && !mng_info->frozen[object_id]) 33913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 33923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->ob[object_id] == (MngBuffer *) NULL) 33933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 33943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 33953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy create a new object buffer. 33963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 33973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->ob[object_id]=(MngBuffer *) 339873bd4a51b419e914565bdf204bf1540dc4c8ee26cristy AcquireMagickMemory(sizeof(MngBuffer)); 33990fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 34003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->ob[object_id] != (MngBuffer *) NULL) 34013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 34023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->ob[object_id]->image=(Image *) NULL; 34033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->ob[object_id]->reference_count=1; 34043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 34053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 340647b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 34073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((mng_info->ob[object_id] == (MngBuffer *) NULL) || 34083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->ob[object_id]->frozen) 34093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 34103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->ob[object_id] == (MngBuffer *) NULL) 34113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ThrowMagickException(&image->exception,GetMagickModule(), 34123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ResourceLimitError,"MemoryAllocationFailed","`%s'", 34133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->filename); 34140fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 34153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->ob[object_id]->frozen) 34163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ThrowMagickException(&image->exception,GetMagickModule(), 34173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ResourceLimitError,"Cannot overwrite frozen MNG object buffer", 34183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy "`%s'",image->filename); 34193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 34200fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 34213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 34223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 34233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 34243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->ob[object_id]->image != (Image *) NULL) 34253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->ob[object_id]->image=DestroyImage 34263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (mng_info->ob[object_id]->image); 34270fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 34283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->ob[object_id]->image=CloneImage(image,0,0,MagickTrue, 34293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy &image->exception); 34300fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 34313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->ob[object_id]->image != (Image *) NULL) 34323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->ob[object_id]->image->file=(FILE *) NULL; 34330fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 34343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 34353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ThrowMagickException(&image->exception,GetMagickModule(), 34363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ResourceLimitError,"Cloning image for object buffer failed", 34373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy "`%s'",image->filename); 34380fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 3439faa852bad40107edae19405e76a299057668d795glennrp if (ping_width > 250000L || ping_height > 250000L) 34403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_error(ping,"PNG Image dimensions are too large."); 34410fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 3442faa852bad40107edae19405e76a299057668d795glennrp mng_info->ob[object_id]->width=ping_width; 3443faa852bad40107edae19405e76a299057668d795glennrp mng_info->ob[object_id]->height=ping_height; 3444faa852bad40107edae19405e76a299057668d795glennrp mng_info->ob[object_id]->color_type=ping_color_type; 3445faa852bad40107edae19405e76a299057668d795glennrp mng_info->ob[object_id]->sample_depth=ping_bit_depth; 3446faa852bad40107edae19405e76a299057668d795glennrp mng_info->ob[object_id]->interlace_method=ping_interlace_method; 3447faa852bad40107edae19405e76a299057668d795glennrp mng_info->ob[object_id]->compression_method= 3448faa852bad40107edae19405e76a299057668d795glennrp ping_compression_method; 3449faa852bad40107edae19405e76a299057668d795glennrp mng_info->ob[object_id]->filter_method=ping_filter_method; 34500fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 3451faa852bad40107edae19405e76a299057668d795glennrp if (png_get_valid(ping,ping_info,PNG_INFO_PLTE)) 34523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 34533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy int 34543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy number_colors; 34553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 34563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_colorp 34573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy plte; 34583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 34593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 34603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Copy the PLTE to the object buffer. 34613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 34623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_get_PLTE(ping,ping_info,&plte,&number_colors); 34633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->ob[object_id]->plte_length=number_colors; 34643c21811cab8a3b168295e3f0da1909c4e2a7da15glennrp 34653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy for (i=0; i < number_colors; i++) 34663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 34673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->ob[object_id]->plte[i]=plte[i]; 34683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 34693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 347047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 34713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 34723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->ob[object_id]->plte_length=0; 34733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 34743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 34753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 34760a55b4c577b5e63eca6f108dea6f5c42191f78acglennrp 34770a55b4c577b5e63eca6f108dea6f5c42191f78acglennrp /* Set image->matte to MagickTrue if the input colortype supports 34780a55b4c577b5e63eca6f108dea6f5c42191f78acglennrp * alpha or if a valid tRNS chunk is present, no matter whether there 34790a55b4c577b5e63eca6f108dea6f5c42191f78acglennrp * is actual transparency present. 34800a55b4c577b5e63eca6f108dea6f5c42191f78acglennrp */ 34810a55b4c577b5e63eca6f108dea6f5c42191f78acglennrp image->matte=(((int) ping_color_type == PNG_COLOR_TYPE_RGB_ALPHA) || 34820a55b4c577b5e63eca6f108dea6f5c42191f78acglennrp ((int) ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA) || 34830a55b4c577b5e63eca6f108dea6f5c42191f78acglennrp (png_get_valid(ping,ping_info,PNG_INFO_tRNS))) ? 34840a55b4c577b5e63eca6f108dea6f5c42191f78acglennrp MagickTrue : MagickFalse; 34850a55b4c577b5e63eca6f108dea6f5c42191f78acglennrp 3486cb395ac9c5c50c2829a9988f95fd8aea7af82c00glennrp /* Set more properties for identify to retrieve */ 3487cb395ac9c5c50c2829a9988f95fd8aea7af82c00glennrp { 3488cb395ac9c5c50c2829a9988f95fd8aea7af82c00glennrp char 3489cb395ac9c5c50c2829a9988f95fd8aea7af82c00glennrp msg[MaxTextExtent]; 3490cb395ac9c5c50c2829a9988f95fd8aea7af82c00glennrp 34914eb3931feb349dd87142c78503b779228f3e1a0fglennrp if (num_text_total != 0) 3492cb395ac9c5c50c2829a9988f95fd8aea7af82c00glennrp { 3493cb395ac9c5c50c2829a9988f95fd8aea7af82c00glennrp /* libpng doesn't tell us whether they were tEXt, zTXt, or iTXt */ 34943b6fd2ec2d9f69f9404445dba0aff5bac02e685ccristy (void) FormatLocaleString(msg,MaxTextExtent, 3495613276d97a7f0e40c1055f9ff5ddfcfa8896e20bglennrp "%d tEXt/zTXt/iTXt chunks were found", num_text_total); 3496cb395ac9c5c50c2829a9988f95fd8aea7af82c00glennrp (void) SetImageProperty(image,"PNG:text ",msg); 3497cb395ac9c5c50c2829a9988f95fd8aea7af82c00glennrp } 3498cb395ac9c5c50c2829a9988f95fd8aea7af82c00glennrp 3499cb395ac9c5c50c2829a9988f95fd8aea7af82c00glennrp if (num_raw_profiles != 0) 3500cb395ac9c5c50c2829a9988f95fd8aea7af82c00glennrp { 35013b6fd2ec2d9f69f9404445dba0aff5bac02e685ccristy (void) FormatLocaleString(msg,MaxTextExtent, 3502cb395ac9c5c50c2829a9988f95fd8aea7af82c00glennrp "%d were found", num_raw_profiles); 3503cb395ac9c5c50c2829a9988f95fd8aea7af82c00glennrp (void) SetImageProperty(image,"PNG:text-encoded profiles",msg); 3504cb395ac9c5c50c2829a9988f95fd8aea7af82c00glennrp } 3505cb395ac9c5c50c2829a9988f95fd8aea7af82c00glennrp 3506cb395ac9c5c50c2829a9988f95fd8aea7af82c00glennrp if (png_get_valid(ping,ping_info,PNG_INFO_cHRM)) 35075961225e531a5f26ae179c1d919582d5cdaa44bbglennrp { 35083b6fd2ec2d9f69f9404445dba0aff5bac02e685ccristy (void) FormatLocaleString(msg,MaxTextExtent,"%s", 35095961225e531a5f26ae179c1d919582d5cdaa44bbglennrp "chunk was found (see Chromaticity, above)"); 35105961225e531a5f26ae179c1d919582d5cdaa44bbglennrp (void) SetImageProperty(image,"PNG:cHRM ",msg); 35115961225e531a5f26ae179c1d919582d5cdaa44bbglennrp } 3512cb395ac9c5c50c2829a9988f95fd8aea7af82c00glennrp 3513cb395ac9c5c50c2829a9988f95fd8aea7af82c00glennrp if (png_get_valid(ping,ping_info,PNG_INFO_bKGD)) 35145961225e531a5f26ae179c1d919582d5cdaa44bbglennrp { 35153b6fd2ec2d9f69f9404445dba0aff5bac02e685ccristy (void) FormatLocaleString(msg,MaxTextExtent,"%s", 35165961225e531a5f26ae179c1d919582d5cdaa44bbglennrp "chunk was found (see Background color, above)"); 35175961225e531a5f26ae179c1d919582d5cdaa44bbglennrp (void) SetImageProperty(image,"PNG:bKGD ",msg); 35185961225e531a5f26ae179c1d919582d5cdaa44bbglennrp } 35195961225e531a5f26ae179c1d919582d5cdaa44bbglennrp 35203b6fd2ec2d9f69f9404445dba0aff5bac02e685ccristy (void) FormatLocaleString(msg,MaxTextExtent,"%s", 35215961225e531a5f26ae179c1d919582d5cdaa44bbglennrp "chunk was found"); 3522cb395ac9c5c50c2829a9988f95fd8aea7af82c00glennrp 3523cb395ac9c5c50c2829a9988f95fd8aea7af82c00glennrp if (png_get_valid(ping,ping_info,PNG_INFO_iCCP)) 3524cb395ac9c5c50c2829a9988f95fd8aea7af82c00glennrp (void) SetImageProperty(image,"PNG:iCCP ",msg); 3525cb395ac9c5c50c2829a9988f95fd8aea7af82c00glennrp 35264eb3931feb349dd87142c78503b779228f3e1a0fglennrp if (png_get_valid(ping,ping_info,PNG_INFO_tRNS)) 35274eb3931feb349dd87142c78503b779228f3e1a0fglennrp (void) SetImageProperty(image,"PNG:tRNS ",msg); 35284eb3931feb349dd87142c78503b779228f3e1a0fglennrp 35294eb3931feb349dd87142c78503b779228f3e1a0fglennrp#if defined(PNG_sRGB_SUPPORTED) 3530cb395ac9c5c50c2829a9988f95fd8aea7af82c00glennrp if (png_get_valid(ping,ping_info,PNG_INFO_sRGB)) 35314eb3931feb349dd87142c78503b779228f3e1a0fglennrp { 35323b6fd2ec2d9f69f9404445dba0aff5bac02e685ccristy (void) FormatLocaleString(msg,MaxTextExtent, 353307523c7d2e40370804c2036295571e4b6426f94dglennrp "intent=%d (See Rendering intent)", 35344eb3931feb349dd87142c78503b779228f3e1a0fglennrp (int) intent); 35354eb3931feb349dd87142c78503b779228f3e1a0fglennrp (void) SetImageProperty(image,"PNG:sRGB ",msg); 35364eb3931feb349dd87142c78503b779228f3e1a0fglennrp } 35374eb3931feb349dd87142c78503b779228f3e1a0fglennrp#endif 35384eb3931feb349dd87142c78503b779228f3e1a0fglennrp 35394eb3931feb349dd87142c78503b779228f3e1a0fglennrp if (png_get_valid(ping,ping_info,PNG_INFO_gAMA)) 35404eb3931feb349dd87142c78503b779228f3e1a0fglennrp { 35413b6fd2ec2d9f69f9404445dba0aff5bac02e685ccristy (void) FormatLocaleString(msg,MaxTextExtent, 354207523c7d2e40370804c2036295571e4b6426f94dglennrp "gamma=%.8g (See Gamma, above)", 35434eb3931feb349dd87142c78503b779228f3e1a0fglennrp file_gamma); 35444eb3931feb349dd87142c78503b779228f3e1a0fglennrp (void) SetImageProperty(image,"PNG:gAMA ",msg); 35454eb3931feb349dd87142c78503b779228f3e1a0fglennrp } 3546cb395ac9c5c50c2829a9988f95fd8aea7af82c00glennrp 35474eb3931feb349dd87142c78503b779228f3e1a0fglennrp#if defined(PNG_pHYs_SUPPORTED) 3548cb395ac9c5c50c2829a9988f95fd8aea7af82c00glennrp if (png_get_valid(ping,ping_info,PNG_INFO_pHYs)) 35494eb3931feb349dd87142c78503b779228f3e1a0fglennrp { 35503b6fd2ec2d9f69f9404445dba0aff5bac02e685ccristy (void) FormatLocaleString(msg,MaxTextExtent, 355107523c7d2e40370804c2036295571e4b6426f94dglennrp "x_res=%.10g, y_res=%.10g, units=%d", 35524eb3931feb349dd87142c78503b779228f3e1a0fglennrp (double) x_resolution,(double) y_resolution, unit_type); 35534eb3931feb349dd87142c78503b779228f3e1a0fglennrp (void) SetImageProperty(image,"PNG:pHYs ",msg); 35544eb3931feb349dd87142c78503b779228f3e1a0fglennrp } 35554eb3931feb349dd87142c78503b779228f3e1a0fglennrp#endif 3556cb395ac9c5c50c2829a9988f95fd8aea7af82c00glennrp 35574eb3931feb349dd87142c78503b779228f3e1a0fglennrp#if defined(PNG_oFFs_SUPPORTED) 35584eb3931feb349dd87142c78503b779228f3e1a0fglennrp if (png_get_valid(ping,ping_info,PNG_INFO_oFFs)) 35594eb3931feb349dd87142c78503b779228f3e1a0fglennrp { 35603b6fd2ec2d9f69f9404445dba0aff5bac02e685ccristy (void) FormatLocaleString(msg,MaxTextExtent,"x_off=%.20g, y_off=%.20g", 35614eb3931feb349dd87142c78503b779228f3e1a0fglennrp (double) image->page.x,(double) image->page.y); 35624eb3931feb349dd87142c78503b779228f3e1a0fglennrp (void) SetImageProperty(image,"PNG:oFFs ",msg); 35634eb3931feb349dd87142c78503b779228f3e1a0fglennrp } 35644eb3931feb349dd87142c78503b779228f3e1a0fglennrp#endif 35654eb3931feb349dd87142c78503b779228f3e1a0fglennrp 356607523c7d2e40370804c2036295571e4b6426f94dglennrp if ((image->page.width != 0 && image->page.width != image->columns) || 356707523c7d2e40370804c2036295571e4b6426f94dglennrp (image->page.height != 0 && image->page.height != image->rows)) 356807523c7d2e40370804c2036295571e4b6426f94dglennrp { 35693b6fd2ec2d9f69f9404445dba0aff5bac02e685ccristy (void) FormatLocaleString(msg,MaxTextExtent, 357007523c7d2e40370804c2036295571e4b6426f94dglennrp "width=%.20g, height=%.20g", 357107523c7d2e40370804c2036295571e4b6426f94dglennrp (double) image->page.width,(double) image->page.height); 357207523c7d2e40370804c2036295571e4b6426f94dglennrp (void) SetImageProperty(image,"PNG:vpAg ",msg); 357307523c7d2e40370804c2036295571e4b6426f94dglennrp } 3574cb395ac9c5c50c2829a9988f95fd8aea7af82c00glennrp } 3575cb395ac9c5c50c2829a9988f95fd8aea7af82c00glennrp 35763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 35773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Relinquish resources. 35783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 35793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_destroy_read_struct(&ping,&ping_info,&end_info); 35803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 3581cf002022280cc4dedb2748ad6f415aac1d44f530glennrp ping_pixels=(unsigned char *) RelinquishMagickMemory(ping_pixels); 35823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(PNG_SETJMP_NOT_THREAD_SAFE) 3583cf002022280cc4dedb2748ad6f415aac1d44f530glennrp UnlockSemaphoreInfo(ping_semaphore); 35843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 35853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 35863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 35873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 35883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " exit ReadOnePNGImage()"); 35890fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 35903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(image); 35913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 35923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* end of reading one PNG image */ 35933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 35943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 35953ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic Image *ReadPNGImage(const ImageInfo *image_info,ExceptionInfo *exception) 35963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 35973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Image 35983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *image, 35993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *previous; 36003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 36013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MagickBooleanType 360221f0e6211a440c0f96134ea25a1bfe7c5f91c29cglennrp have_mng_structure, 360321f0e6211a440c0f96134ea25a1bfe7c5f91c29cglennrp logging, 36043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status; 36053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 36063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngInfo 36073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *mng_info; 36083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 36093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy char 36103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magic_number[MaxTextExtent]; 36113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 36123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ssize_t 36133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy count; 36143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 36153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 36163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Open image file. 36173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 36183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(image_info != (const ImageInfo *) NULL); 36193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(image_info->signature == MagickSignature); 362047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 36213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image_info->debug != MagickFalse) 36223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", 36233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image_info->filename); 362447b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 36253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(exception != (ExceptionInfo *) NULL); 36263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(exception->signature == MagickSignature); 3627fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp logging=LogMagickEvent(CoderEvent,GetMagickModule(),"Enter ReadPNGImage()"); 36283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=AcquireImage(image_info); 36293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info=(MngInfo *) NULL; 36303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); 363147b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 36323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (status == MagickFalse) 36333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowReaderException(FileOpenError,"UnableToOpenFile"); 363447b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 36353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 36363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Verify PNG signature. 36373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 36383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy count=ReadBlob(image,8,(unsigned char *) magic_number); 363947b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 3640dde35db6e37a8fd3adaa19bdfe20c7a54b2085efglennrp if (count < 8 || memcmp(magic_number,"\211PNG\r\n\032\n",8) != 0) 36413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowReaderException(CorruptImageError,"ImproperImageHeader"); 364247b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 36433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 36443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Allocate a MngInfo structure. 36453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 36463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy have_mng_structure=MagickFalse; 364773bd4a51b419e914565bdf204bf1540dc4c8ee26cristy mng_info=(MngInfo *) AcquireMagickMemory(sizeof(MngInfo)); 364847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 36493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info == (MngInfo *) NULL) 36503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); 365147b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 36523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 36533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Initialize members of the MngInfo structure. 36543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 36553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ResetMagickMemory(mng_info,0,sizeof(MngInfo)); 36563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->image=image; 36573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy have_mng_structure=MagickTrue; 36583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 36593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy previous=image; 36603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=ReadOnePNGImage(mng_info,image_info,exception); 36613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngInfoFreeStruct(mng_info,&have_mng_structure); 366247b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 36633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image == (Image *) NULL) 36643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 36653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (previous != (Image *) NULL) 36663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 36673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (previous->signature != MagickSignature) 36683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowReaderException(CorruptImageError,"CorruptImage"); 36690fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 36703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) CloseBlob(previous); 36713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) DestroyImageList(previous); 36723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 36730fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 36743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 36753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 36763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy "exit ReadPNGImage() with error"); 36770fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 36783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return((Image *) NULL); 36793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 368047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 36813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) CloseBlob(image); 368247b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 36833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((image->columns == 0) || (image->rows == 0)) 36843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 36853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 36863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 36873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy "exit ReadPNGImage() with error."); 36880fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 36893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowReaderException(CorruptImageError,"CorruptImage"); 36903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 369147b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 36923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (LocaleCompare(image_info->magick,"PNG24") == 0) 36933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 36943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) SetImageType(image,TrueColorType); 36953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->matte=MagickFalse; 36963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 36970fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 36983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (LocaleCompare(image_info->magick,"PNG32") == 0) 36993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) SetImageType(image,TrueColorMatteType); 37000fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 37013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 370297f90e23c85b9c58387880125c29d8c99126f83aglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 370397f90e23c85b9c58387880125c29d8c99126f83aglennrp " page.w: %.20g, page.h: %.20g,page.x: %.20g, page.y: %.20g.", 370497f90e23c85b9c58387880125c29d8c99126f83aglennrp (double) image->page.width,(double) image->page.height, 370597f90e23c85b9c58387880125c29d8c99126f83aglennrp (double) image->page.x,(double) image->page.y); 370697f90e23c85b9c58387880125c29d8c99126f83aglennrp 370797f90e23c85b9c58387880125c29d8c99126f83aglennrp if (logging != MagickFalse) 37083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(),"exit ReadPNGImage()"); 37090fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 37103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(image); 37113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 37123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 37133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 37143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 37153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(JNG_SUPPORTED) 37163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 37173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 37183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 37193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 37203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 37213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% R e a d O n e J N G I m a g e % 37223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 37233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 37243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 37253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 37263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 37273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% ReadOneJNGImage() reads a JPEG Network Graphics (JNG) image file 37283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% (minus the 8-byte signature) and returns it. It allocates the memory 37293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% necessary for the new Image structure and returns a pointer to the new 37303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% image. 37313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 37323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% JNG support written by Glenn Randers-Pehrson, glennrp@image... 37333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 37343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% The format of the ReadOneJNGImage method is: 37353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 37363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Image *ReadOneJNGImage(MngInfo *mng_info, const ImageInfo *image_info, 37373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% ExceptionInfo *exception) 37383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 37393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% A description of each parameter follows: 37403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 37413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o mng_info: Specifies a pointer to a MngInfo structure. 37423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 37433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o image_info: the image info. 37443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 37453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o exception: return any errors or warnings in this structure. 37463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 37473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 37483ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic Image *ReadOneJNGImage(MngInfo *mng_info, 37493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy const ImageInfo *image_info, ExceptionInfo *exception) 37503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 37513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Image 37523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *alpha_image, 37533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *color_image, 37543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *image, 37553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *jng_image; 37563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 37573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ImageInfo 37583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *alpha_image_info, 37593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *color_image_info; 37603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 37614383ec8c3c8811128f5a8a034d67c47db5e7e75acristy MagickBooleanType 37624383ec8c3c8811128f5a8a034d67c47db5e7e75acristy logging; 37634383ec8c3c8811128f5a8a034d67c47db5e7e75acristy 3764bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy ssize_t 37653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy y; 37663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 37673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MagickBooleanType 37683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status; 37693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 37703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_uint_32 37713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_height, 37723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_width; 37733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 37743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_byte 37753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_color_type, 37763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_image_sample_depth, 37773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_image_compression_method, 37783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_image_interlace_method, 37793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_alpha_sample_depth, 37803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_alpha_compression_method, 37813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_alpha_filter_method, 37823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_alpha_interlace_method; 37833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 37844c08aed51c5899665ade97263692328eea4af106cristy register const Quantum 37853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *s; 37863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 3787bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy register ssize_t 37883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy i, 37893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy x; 37903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 37914c08aed51c5899665ade97263692328eea4af106cristy register Quantum 37923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *q; 37933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 37943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy register unsigned char 37953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *p; 37963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 37973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy unsigned int 37983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy read_JSEP, 37993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy reading_idat, 38003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy skip_to_iend; 38013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 3802bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy size_t 38033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy length; 38043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 38053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_alpha_compression_method=0; 38063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_alpha_sample_depth=8; 38073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_color_type=0; 38083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_height=0; 38093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_width=0; 38103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy alpha_image=(Image *) NULL; 38113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy color_image=(Image *) NULL; 38123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy alpha_image_info=(ImageInfo *) NULL; 38133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy color_image_info=(ImageInfo *) NULL; 38143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 38153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy logging=LogMagickEvent(CoderEvent,GetMagickModule(), 3816fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp " Enter ReadOneJNGImage()"); 38173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 38183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=mng_info->image; 38190fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 38204c08aed51c5899665ade97263692328eea4af106cristy if (GetAuthenticPixelQueue(image) != (Quantum *) NULL) 38213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 38223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 38233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Allocate next image structure. 38243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 38253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 38263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 38273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " AcquireNextImage()"); 38280fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 38293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy AcquireNextImage(image_info,image); 38300fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 38313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (GetNextImageInList(image) == (Image *) NULL) 38323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return((Image *) NULL); 38330fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 38343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=SyncNextImageInList(image); 38353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 38363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->image=image; 38373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 38383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 38393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Signature bytes have already been read. 38403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 38413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 38423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy read_JSEP=MagickFalse; 38433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy reading_idat=MagickFalse; 38443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy skip_to_iend=MagickFalse; 38453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy for (;;) 38463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 38473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy char 38483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy type[MaxTextExtent]; 38493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 38503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy unsigned char 38513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *chunk; 38523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 38533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy unsigned int 38543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy count; 38553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 38563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 38573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Read a new JNG chunk. 38583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 38593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status=SetImageProgress(image,LoadImagesTag,TellBlob(image), 38603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 2*GetBlobSize(image)); 38610fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 38623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (status == MagickFalse) 38633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 38640fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 38653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy type[0]='\0'; 38663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ConcatenateMagickString(type,"errr",MaxTextExtent); 38673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy length=ReadBlobMSBLong(image); 38683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy count=(unsigned int) ReadBlob(image,4,(unsigned char *) type); 38693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 38703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 38713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 3872e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " Reading JNG chunk type %c%c%c%c, length: %.20g", 3873e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy type[0],type[1],type[2],type[3],(double) length); 38743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 38753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length > PNG_UINT_31_MAX || count == 0) 38763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowReaderException(CorruptImageError,"CorruptImage"); 38770fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 38783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy p=NULL; 38793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) NULL; 388047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 38813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length) 38823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 38833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) AcquireQuantumMemory(length,sizeof(*chunk)); 38840fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 38853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (chunk == (unsigned char *) NULL) 38863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); 38870fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 3888bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (i=0; i < (ssize_t) length; i++) 38893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[i]=(unsigned char) ReadBlobByte(image); 38900fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 38913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy p=chunk; 38923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 389347b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 38943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ReadBlobMSBLong(image); /* read crc word */ 38953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 38963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (skip_to_iend) 38973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 38983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length) 38993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 390047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 39013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 39023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 39033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 39043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_JHDR,4) == 0) 39053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 39063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length == 16) 39073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 3908bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy jng_width=(size_t) ((p[0] << 24) | (p[1] << 16) | 39093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (p[2] << 8) | p[3]); 3910bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy jng_height=(size_t) ((p[4] << 24) | (p[5] << 16) | 39113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (p[6] << 8) | p[7]); 39123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_color_type=p[8]; 39133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_image_sample_depth=p[9]; 39143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_image_compression_method=p[10]; 39153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_image_interlace_method=p[11]; 391647b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 39173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->interlace=jng_image_interlace_method != 0 ? PNGInterlace : 39183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy NoInterlace; 391947b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 39203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_alpha_sample_depth=p[12]; 39213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_alpha_compression_method=p[13]; 39223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_alpha_filter_method=p[14]; 39233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_alpha_interlace_method=p[15]; 392447b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 39253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 39263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 39273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 3928f2faecf9facdbbb14fcba373365f9f691a9658e0cristy " jng_width: %16lu",(unsigned long) jng_width); 392947b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 39303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 3931f2faecf9facdbbb14fcba373365f9f691a9658e0cristy " jng_width: %16lu",(unsigned long) jng_height); 393247b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 39333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 39343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " jng_color_type: %16d",jng_color_type); 393547b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 39363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 39373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " jng_image_sample_depth: %3d", 39383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_image_sample_depth); 393947b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 39403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 39413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " jng_image_compression_method:%3d", 39423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_image_compression_method); 394347b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 39443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 39453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " jng_image_interlace_method: %3d", 39463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_image_interlace_method); 394747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 39483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 39493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " jng_alpha_sample_depth: %3d", 39503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_alpha_sample_depth); 395147b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 39523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 39533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " jng_alpha_compression_method:%3d", 39543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_alpha_compression_method); 395547b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 39563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 39573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " jng_alpha_filter_method: %3d", 39583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_alpha_filter_method); 395947b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 39603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 39613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " jng_alpha_interlace_method: %3d", 39623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_alpha_interlace_method); 39633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 39643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 396547b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 39663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length) 39673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 396847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 39693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 39703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 39713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 39723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 39733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((reading_idat == MagickFalse) && (read_JSEP == MagickFalse) && 39743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ((memcmp(type,mng_JDAT,4) == 0) || (memcmp(type,mng_JdAA,4) == 0) || 39753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (memcmp(type,mng_IDAT,4) == 0) || (memcmp(type,mng_JDAA,4) == 0))) 39763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 39773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 39783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy o create color_image 39793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy o open color_blob, attached to color_image 39803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy o if (color type has alpha) 39813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy open alpha_blob, attached to alpha_image 39823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 39833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 398473bd4a51b419e914565bdf204bf1540dc4c8ee26cristy color_image_info=(ImageInfo *)AcquireMagickMemory(sizeof(ImageInfo)); 398547b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 39863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (color_image_info == (ImageInfo *) NULL) 39873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); 398847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 39893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy GetImageInfo(color_image_info); 39903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy color_image=AcquireImage(color_image_info); 39910fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 39923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (color_image == (Image *) NULL) 39933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); 39943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 39953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 39963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 39973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Creating color_blob."); 39980fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 39993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) AcquireUniqueFilename(color_image->filename); 40003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status=OpenBlob(color_image_info,color_image,WriteBinaryBlobMode, 40013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy exception); 40020fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 40033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (status == MagickFalse) 40043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return((Image *) NULL); 40053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 40063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((image_info->ping == MagickFalse) && (jng_color_type >= 12)) 40073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 40083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy alpha_image_info=(ImageInfo *) 400973bd4a51b419e914565bdf204bf1540dc4c8ee26cristy AcquireMagickMemory(sizeof(ImageInfo)); 40100fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 40113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (alpha_image_info == (ImageInfo *) NULL) 40123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); 40130fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 40143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy GetImageInfo(alpha_image_info); 40153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy alpha_image=AcquireImage(alpha_image_info); 40160fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 40173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (alpha_image == (Image *) NULL) 40183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 40193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy alpha_image=DestroyImage(alpha_image); 40203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowReaderException(ResourceLimitError, 40213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy "MemoryAllocationFailed"); 40223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 40230fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 40243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 40253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 40263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Creating alpha_blob."); 40270fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 40283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) AcquireUniqueFilename(alpha_image->filename); 40293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status=OpenBlob(alpha_image_info,alpha_image,WriteBinaryBlobMode, 40303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy exception); 40310fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 40323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (status == MagickFalse) 40333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return((Image *) NULL); 40340fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 40353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (jng_alpha_compression_method == 0) 40363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 40373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy unsigned char 40383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy data[18]; 40393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 40403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 40413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 40423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Writing IHDR chunk to alpha_blob."); 40430fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 40443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(alpha_image,8,(const unsigned char *) 40453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy "\211PNG\r\n\032\n"); 40460fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 40473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(alpha_image,13L); 40483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGType(data,mng_IHDR); 404903812ae402fb53d548f0e1d7d14720768f803c2dglennrp LogPNGChunk(logging,mng_IHDR,13L); 40503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGLong(data+4,jng_width); 40513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGLong(data+8,jng_height); 40523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy data[12]=jng_alpha_sample_depth; 40533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy data[13]=0; /* color_type gray */ 40543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy data[14]=0; /* compression method 0 */ 40553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy data[15]=0; /* filter_method 0 */ 40563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy data[16]=0; /* interlace_method 0 */ 40573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(alpha_image,17,data); 40583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(alpha_image,crc32(0,data,17)); 40593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 40603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 40613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy reading_idat=MagickTrue; 40623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 40633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 40643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_JDAT,4) == 0) 40653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 406647b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp /* Copy chunk to color_image->blob */ 40673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 40683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 40693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 40703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Copying JDAT chunk data to color_blob."); 40713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 40723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(color_image,length,chunk); 407347b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 40743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length) 40753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 407647b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 40773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 40783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 40793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 40803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_IDAT,4) == 0) 40813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 40823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_byte 40833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy data[5]; 40843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 408547b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp /* Copy IDAT header and chunk data to alpha_image->blob */ 40863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 40873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image_info->ping == MagickFalse) 40883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 40893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 40903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 40913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Copying IDAT chunk data to alpha_blob."); 40923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 4093bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy (void) WriteBlobMSBULong(alpha_image,(size_t) length); 40943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGType(data,mng_IDAT); 409503812ae402fb53d548f0e1d7d14720768f803c2dglennrp LogPNGChunk(logging,mng_IDAT,length); 40963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(alpha_image,4,data); 40973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(alpha_image,length,chunk); 40983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(alpha_image, 40993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy crc32(crc32(0,data,4),chunk,(uInt) length)); 41003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 41010fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 41023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length) 41033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 41040fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 41053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 41063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 41073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 41083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((memcmp(type,mng_JDAA,4) == 0) || (memcmp(type,mng_JdAA,4) == 0)) 41093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 411047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp /* Copy chunk data to alpha_image->blob */ 41113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 41123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image_info->ping == MagickFalse) 41133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 41143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 41153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 41163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Copying JDAA chunk data to alpha_blob."); 41173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 41183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(alpha_image,length,chunk); 41193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 41200fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 41213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length) 41223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 41230fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 41243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 41253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 41263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 41273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_JSEP,4) == 0) 41283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 41293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy read_JSEP=MagickTrue; 41300fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 41313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length) 41323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 41330fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 41343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 41353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 41363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 41373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_bKGD,4) == 0) 41383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 41393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length == 2) 41403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 41413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->background_color.red=ScaleCharToQuantum(p[1]); 41423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->background_color.green=image->background_color.red; 41433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->background_color.blue=image->background_color.red; 41443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 41450fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 41463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length == 6) 41473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 41483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->background_color.red=ScaleCharToQuantum(p[1]); 41493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->background_color.green=ScaleCharToQuantum(p[3]); 41503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->background_color.blue=ScaleCharToQuantum(p[5]); 41513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 41520fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 41533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 41543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 41553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 41563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 41573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_gAMA,4) == 0) 41583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 41593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length == 4) 41608182b0758e3429fb8dcd1700f09643fd4d80a41ccristy image->gamma=((float) mng_get_long(p))*0.00001; 41610fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 41623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 41633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 41643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 41653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 41663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_cHRM,4) == 0) 41673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 41683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length == 32) 41693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 41708182b0758e3429fb8dcd1700f09643fd4d80a41ccristy image->chromaticity.white_point.x=0.00001*mng_get_long(p); 41718182b0758e3429fb8dcd1700f09643fd4d80a41ccristy image->chromaticity.white_point.y=0.00001*mng_get_long(&p[4]); 41728182b0758e3429fb8dcd1700f09643fd4d80a41ccristy image->chromaticity.red_primary.x=0.00001*mng_get_long(&p[8]); 41738182b0758e3429fb8dcd1700f09643fd4d80a41ccristy image->chromaticity.red_primary.y=0.00001*mng_get_long(&p[12]); 41748182b0758e3429fb8dcd1700f09643fd4d80a41ccristy image->chromaticity.green_primary.x=0.00001*mng_get_long(&p[16]); 41758182b0758e3429fb8dcd1700f09643fd4d80a41ccristy image->chromaticity.green_primary.y=0.00001*mng_get_long(&p[20]); 41768182b0758e3429fb8dcd1700f09643fd4d80a41ccristy image->chromaticity.blue_primary.x=0.00001*mng_get_long(&p[24]); 41778182b0758e3429fb8dcd1700f09643fd4d80a41ccristy image->chromaticity.blue_primary.y=0.00001*mng_get_long(&p[28]); 41783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 417947b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 41803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 41813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 41823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 41833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 41843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_sRGB,4) == 0) 41853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 41863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length == 1) 41873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 4188e610a071534e448c46460a5aa39ede33bf56b329glennrp image->rendering_intent= 4189cf002022280cc4dedb2748ad6f415aac1d44f530glennrp Magick_RenderingIntent_from_PNG_RenderingIntent(p[0]); 41903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->gamma=0.45455f; 41913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->chromaticity.red_primary.x=0.6400f; 41923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->chromaticity.red_primary.y=0.3300f; 41933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->chromaticity.green_primary.x=0.3000f; 41943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->chromaticity.green_primary.y=0.6000f; 41953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->chromaticity.blue_primary.x=0.1500f; 41963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->chromaticity.blue_primary.y=0.0600f; 41973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->chromaticity.white_point.x=0.3127f; 41983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->chromaticity.white_point.y=0.3290f; 41993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 420047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 42013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 42023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 42033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 42043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 42053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_oFFs,4) == 0) 42063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 42073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length > 8) 42083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 42095eae76090b1e30c1e546508dd1d17711ddd3fcc0glennrp image->page.x=(ssize_t) mng_get_long(p); 42105eae76090b1e30c1e546508dd1d17711ddd3fcc0glennrp image->page.y=(ssize_t) mng_get_long(&p[4]); 42110fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 42123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((int) p[8] != 0) 42133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 42143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->page.x/=10000; 42153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->page.y/=10000; 42163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 42173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 421847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 42193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length) 42203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 42210fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 42223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 42233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 42243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 42253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_pHYs,4) == 0) 42263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 42273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length > 8) 42283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 42298182b0758e3429fb8dcd1700f09643fd4d80a41ccristy image->x_resolution=(double) mng_get_long(p); 42308182b0758e3429fb8dcd1700f09643fd4d80a41ccristy image->y_resolution=(double) mng_get_long(&p[4]); 42313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((int) p[8] == PNG_RESOLUTION_METER) 42323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 42333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->units=PixelsPerCentimeterResolution; 42343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->x_resolution=image->x_resolution/100.0f; 42353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->y_resolution=image->y_resolution/100.0f; 42363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 42373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 42380fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 42393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 42403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 42413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 42423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 42433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if 0 42443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_iCCP,4) == 0) 42453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 4246fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp /* To do: */ 42473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length) 42483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 42490fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 42503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 42513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 42523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 42533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 42543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length) 42553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 42563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 42573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_IEND,4)) 42583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 42590fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 42603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 42613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 42623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 42633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 42643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* IEND found */ 42653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 42663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 42673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Finish up reading image data: 42683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 42693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy o read main image from color_blob. 42703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 42713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy o close color_blob. 42723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 42733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy o if (color_type has alpha) 42743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if alpha_encoding is PNG 42753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy read secondary image from alpha_blob via ReadPNG 42763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if alpha_encoding is JPEG 42773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy read secondary image from alpha_blob via ReadJPEG 42783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 42793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy o close alpha_blob. 42803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 42813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy o copy intensity of secondary image into 42824c08aed51c5899665ade97263692328eea4af106cristy alpha samples of main image. 42833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 42843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy o destroy the secondary image. 42853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 42863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 42873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) CloseBlob(color_image); 428847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 42893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 42903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 42913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Reading jng_image from color_blob."); 42920fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 42933b6fd2ec2d9f69f9404445dba0aff5bac02e685ccristy (void) FormatLocaleString(color_image_info->filename,MaxTextExtent,"%s", 42943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy color_image->filename); 42950fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 42963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy color_image_info->ping=MagickFalse; /* To do: avoid this */ 42973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_image=ReadImage(color_image_info,exception); 42980fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 42993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (jng_image == (Image *) NULL) 43003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return((Image *) NULL); 43013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 43023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) RelinquishUniqueFileResource(color_image->filename); 43033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy color_image=DestroyImage(color_image); 43043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy color_image_info=DestroyImageInfo(color_image_info); 43053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 43063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (jng_image == (Image *) NULL) 43073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return((Image *) NULL); 43083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 43093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 43103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 43113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Copying jng_image pixels to main image."); 43120fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 43133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->rows=jng_height; 43143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->columns=jng_width; 43150fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 4316bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (y=0; y < (ssize_t) image->rows; y++) 43173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 43183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy s=GetVirtualPixels(jng_image,0,y,image->columns,1,&image->exception); 43193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy q=GetAuthenticPixels(image,0,y,image->columns,1,exception); 43204c08aed51c5899665ade97263692328eea4af106cristy for (x=(ssize_t) image->columns; x != 0; x--) 43214c08aed51c5899665ade97263692328eea4af106cristy { 43224c08aed51c5899665ade97263692328eea4af106cristy SetPixelRed(image,GetPixelRed(jng_image,s),q); 43234c08aed51c5899665ade97263692328eea4af106cristy SetPixelGreen(image,GetPixelGreen(jng_image,s),q); 43244c08aed51c5899665ade97263692328eea4af106cristy SetPixelBlue(image,GetPixelBlue(jng_image,s),q); 43254c08aed51c5899665ade97263692328eea4af106cristy q+=GetPixelChannels(image); 43264c08aed51c5899665ade97263692328eea4af106cristy s+=GetPixelChannels(jng_image); 43274c08aed51c5899665ade97263692328eea4af106cristy } 432847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 43293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (SyncAuthenticPixels(image,exception) == MagickFalse) 43303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 43313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 43320fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 43333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_image=DestroyImage(jng_image); 43340fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 43353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image_info->ping == MagickFalse) 43363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 43373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (jng_color_type >= 12) 43383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 43393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (jng_alpha_compression_method == 0) 43403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 43413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_byte 43423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy data[5]; 43433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(alpha_image,0x00000000L); 43443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGType(data,mng_IEND); 434503812ae402fb53d548f0e1d7d14720768f803c2dglennrp LogPNGChunk(logging,mng_IEND,0L); 43463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(alpha_image,4,data); 43473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(alpha_image,crc32(0,data,4)); 43483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 43490fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 43503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) CloseBlob(alpha_image); 43510fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 43523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 43533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 43544c08aed51c5899665ade97263692328eea4af106cristy " Reading alpha from alpha_blob."); 43553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 43563b6fd2ec2d9f69f9404445dba0aff5bac02e685ccristy (void) FormatLocaleString(alpha_image_info->filename,MaxTextExtent, 43573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy "%s",alpha_image->filename); 43583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 43593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_image=ReadImage(alpha_image_info,exception); 43600fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 43613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (jng_image != (Image *) NULL) 4362bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (y=0; y < (ssize_t) image->rows; y++) 43633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 43643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy s=GetVirtualPixels(jng_image,0,y,image->columns,1, 43654c08aed51c5899665ade97263692328eea4af106cristy &image->exception); 43663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy q=GetAuthenticPixels(image,0,y,image->columns,1,exception); 436747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 43683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->matte != MagickFalse) 43694c08aed51c5899665ade97263692328eea4af106cristy for (x=(ssize_t) image->columns; x != 0; x--) 43704c08aed51c5899665ade97263692328eea4af106cristy { 43714c08aed51c5899665ade97263692328eea4af106cristy SetPixelAlpha(image,GetPixelRed(jng_image,s),q); 43724c08aed51c5899665ade97263692328eea4af106cristy q+=GetPixelChannels(image); 43734c08aed51c5899665ade97263692328eea4af106cristy s+=GetPixelChannels(jng_image); 43744c08aed51c5899665ade97263692328eea4af106cristy } 43750fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 43763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 43774c08aed51c5899665ade97263692328eea4af106cristy for (x=(ssize_t) image->columns; x != 0; x--) 43783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 43794c08aed51c5899665ade97263692328eea4af106cristy SetPixelAlpha(image,GetPixelRed(jng_image,s),q); 43804c08aed51c5899665ade97263692328eea4af106cristy if (GetPixelAlpha(image,q) != OpaqueAlpha) 43813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->matte=MagickTrue; 43824c08aed51c5899665ade97263692328eea4af106cristy q+=GetPixelChannels(image); 43834c08aed51c5899665ade97263692328eea4af106cristy s+=GetPixelChannels(jng_image); 43843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 43850fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 43863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (SyncAuthenticPixels(image,exception) == MagickFalse) 43873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 43883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 43893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) RelinquishUniqueFileResource(alpha_image->filename); 43903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy alpha_image=DestroyImage(alpha_image); 43913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy alpha_image_info=DestroyImageInfo(alpha_image_info); 43923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (jng_image != (Image *) NULL) 43933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_image=DestroyImage(jng_image); 43943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 43953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 43963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 439747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp /* Read the JNG image. */ 439847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 43993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->mng_type == 0) 44003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 44013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->mng_width=jng_width; 44023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->mng_height=jng_height; 44033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 44040fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 44053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->page.width == 0 && image->page.height == 0) 44060fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp { 44070fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp image->page.width=jng_width; 44080fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp image->page.height=jng_height; 44090fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp } 44100fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 44113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->page.x == 0 && image->page.y == 0) 44120fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp { 44130fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp image->page.x=mng_info->x_off[mng_info->object_id]; 44140fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp image->page.y=mng_info->y_off[mng_info->object_id]; 44150fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp } 44160fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 44173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 44180fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp { 44190fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp image->page.y=mng_info->y_off[mng_info->object_id]; 44200fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp } 44210fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 44223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->image_found++; 44233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status=SetImageProgress(image,LoadImagesTag,2*TellBlob(image), 44243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 2*GetBlobSize(image)); 44250fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 44263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 44273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 44283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " exit ReadOneJNGImage()"); 44290fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 44303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(image); 44313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 44323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 44333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 44343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 44353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 44363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 44373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 44383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% R e a d J N G I m a g e % 44393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 44403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 44413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 44423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 44433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 44443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% ReadJNGImage() reads a JPEG Network Graphics (JNG) image file 44453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% (including the 8-byte signature) and returns it. It allocates the memory 44463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% necessary for the new Image structure and returns a pointer to the new 44473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% image. 44483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 44493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% JNG support written by Glenn Randers-Pehrson, glennrp@image... 44503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 44513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% The format of the ReadJNGImage method is: 44523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 44533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Image *ReadJNGImage(const ImageInfo *image_info, ExceptionInfo 44543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% *exception) 44553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 44563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% A description of each parameter follows: 44573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 44583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o image_info: the image info. 44593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 44603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o exception: return any errors or warnings in this structure. 44613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 44623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 44633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 44643ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic Image *ReadJNGImage(const ImageInfo *image_info,ExceptionInfo *exception) 44653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 44663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Image 44673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *image, 44683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *previous; 44693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 44703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MagickBooleanType 447121f0e6211a440c0f96134ea25a1bfe7c5f91c29cglennrp have_mng_structure, 447221f0e6211a440c0f96134ea25a1bfe7c5f91c29cglennrp logging, 44733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status; 44743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 44753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngInfo 44763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *mng_info; 44773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 44783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy char 44793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magic_number[MaxTextExtent]; 44803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 44813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy size_t 44823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy count; 44833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 44843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 44853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Open image file. 44863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 44873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(image_info != (const ImageInfo *) NULL); 44883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(image_info->signature == MagickSignature); 44893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image_info->filename); 44903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(exception != (ExceptionInfo *) NULL); 44913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(exception->signature == MagickSignature); 4492fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp logging=LogMagickEvent(CoderEvent,GetMagickModule(),"Enter ReadJNGImage()"); 44933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=AcquireImage(image_info); 44943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info=(MngInfo *) NULL; 44953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); 44960fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 44973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (status == MagickFalse) 44983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return((Image *) NULL); 44990fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 45003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (LocaleCompare(image_info->magick,"JNG") != 0) 45013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowReaderException(CorruptImageError,"ImproperImageHeader"); 45020fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 450347b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp /* Verify JNG signature. */ 450447b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 45053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy count=(size_t) ReadBlob(image,8,(unsigned char *) magic_number); 450647b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 45073b8763efd02f5343a141d40636f6a8dfdc2c7682glennrp if (count < 8 || memcmp(magic_number,"\213JNG\r\n\032\n",8) != 0) 45083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowReaderException(CorruptImageError,"ImproperImageHeader"); 45090fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 451047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp /* Allocate a MngInfo structure. */ 451147b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 45123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy have_mng_structure=MagickFalse; 451373bd4a51b419e914565bdf204bf1540dc4c8ee26cristy mng_info=(MngInfo *) AcquireMagickMemory(sizeof(*mng_info)); 45140fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 45153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info == (MngInfo *) NULL) 45163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); 45170fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 451847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp /* Initialize members of the MngInfo structure. */ 451947b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 45203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ResetMagickMemory(mng_info,0,sizeof(MngInfo)); 45213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy have_mng_structure=MagickTrue; 45223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 45233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->image=image; 45243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy previous=image; 45253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=ReadOneJNGImage(mng_info,image_info,exception); 45263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngInfoFreeStruct(mng_info,&have_mng_structure); 45270fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 45283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image == (Image *) NULL) 45293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 45303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (IsImageObject(previous) != MagickFalse) 45313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 45323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) CloseBlob(previous); 45333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) DestroyImageList(previous); 45343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 45350fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 45363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 45373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 45383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy "exit ReadJNGImage() with error"); 45390fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 45403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return((Image *) NULL); 45413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 45423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) CloseBlob(image); 454347b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 45443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->columns == 0 || image->rows == 0) 45453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 45463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 45473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 45483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy "exit ReadJNGImage() with error"); 45490fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 45503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowReaderException(CorruptImageError,"CorruptImage"); 45513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 45520fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 45533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 45543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(),"exit ReadJNGImage()"); 45550fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 45563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(image); 45573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 45583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 45593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 45603ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic Image *ReadMNGImage(const ImageInfo *image_info,ExceptionInfo *exception) 45613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 45623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy char 45633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy page_geometry[MaxTextExtent]; 45643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 45653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Image 45663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *image, 45673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *previous; 45683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 45694383ec8c3c8811128f5a8a034d67c47db5e7e75acristy MagickBooleanType 457021f0e6211a440c0f96134ea25a1bfe7c5f91c29cglennrp logging, 457121f0e6211a440c0f96134ea25a1bfe7c5f91c29cglennrp have_mng_structure; 45724383ec8c3c8811128f5a8a034d67c47db5e7e75acristy 45733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy volatile int 45743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy first_mng_object, 45753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy object_id, 45763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy term_chunk_found, 45773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy skip_to_iend; 45783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 4579bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy volatile ssize_t 45803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image_count=0; 45813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 45823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MagickBooleanType 45833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status; 45843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 45853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MagickOffsetType 45863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy offset; 45873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 45883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngInfo 45893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *mng_info; 45903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 45913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngBox 45923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy default_fb, 45933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy fb, 45943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy previous_fb; 45953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 45963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MNG_INSERT_LAYERS) 45973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PixelPacket 45983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_background_color; 45993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 46003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 46013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy register unsigned char 46023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *p; 46033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 4604bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy register ssize_t 46053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy i; 46063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 46073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy size_t 46083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy count; 46093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 4610bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy ssize_t 46113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy loop_level; 46123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 46133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy volatile short 46143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy skipping_loop; 46153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 46163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MNG_INSERT_LAYERS) 46173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy unsigned int 46183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mandatory_back=0; 46193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 46203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 46213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy volatile unsigned int 46223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#ifdef MNG_OBJECT_BUFFERS 46233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_background_object=0, 46243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 46253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_type=0; /* 0: PNG or JNG; 1: MNG; 2: MNG-LC; 3: MNG-VLC */ 46263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 4627bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy size_t 46283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy default_frame_timeout, 46293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy frame_timeout, 46303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MNG_INSERT_LAYERS) 46313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image_height, 46323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image_width, 46333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 46343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy length; 46353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 463638ea08308f079e4d21ad8b8ac465dcc3e1d78458glennrp /* These delays are all measured in image ticks_per_second, 463738ea08308f079e4d21ad8b8ac465dcc3e1d78458glennrp * not in MNG ticks_per_second 463838ea08308f079e4d21ad8b8ac465dcc3e1d78458glennrp */ 4639bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy volatile size_t 46403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy default_frame_delay, 46413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy final_delay, 46423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy final_image_delay, 46433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy frame_delay, 46443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MNG_INSERT_LAYERS) 46453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy insert_layers, 46463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 46473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_iterations=1, 46483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy simplicity=0, 46493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy subframe_height=0, 46503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy subframe_width=0; 46513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 46523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy previous_fb.top=0; 46533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy previous_fb.bottom=0; 46543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy previous_fb.left=0; 46553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy previous_fb.right=0; 46563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy default_fb.top=0; 46573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy default_fb.bottom=0; 46583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy default_fb.left=0; 46593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy default_fb.right=0; 46603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 466147b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp /* Open image file. */ 466247b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 46633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(image_info != (const ImageInfo *) NULL); 46643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(image_info->signature == MagickSignature); 46653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image_info->filename); 46663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(exception != (ExceptionInfo *) NULL); 46673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(exception->signature == MagickSignature); 4668fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp logging=LogMagickEvent(CoderEvent,GetMagickModule(),"Enter ReadMNGImage()"); 46693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=AcquireImage(image_info); 46703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info=(MngInfo *) NULL; 46713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); 46720fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 46733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (status == MagickFalse) 46743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return((Image *) NULL); 46750fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 46763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy first_mng_object=MagickFalse; 46773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy skipping_loop=(-1); 46783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy have_mng_structure=MagickFalse; 467947b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 468047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp /* Allocate a MngInfo structure. */ 468147b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 468273bd4a51b419e914565bdf204bf1540dc4c8ee26cristy mng_info=(MngInfo *) AcquireMagickMemory(sizeof(MngInfo)); 46830fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 46843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info == (MngInfo *) NULL) 46853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); 46860fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 468747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp /* Initialize members of the MngInfo structure. */ 468847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 46893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ResetMagickMemory(mng_info,0,sizeof(MngInfo)); 46903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->image=image; 46913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy have_mng_structure=MagickTrue; 46923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 46933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (LocaleCompare(image_info->magick,"MNG") == 0) 46943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 46953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy char 46963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magic_number[MaxTextExtent]; 46973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 469847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp /* Verify MNG signature. */ 46993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy count=(size_t) ReadBlob(image,8,(unsigned char *) magic_number); 47003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(magic_number,"\212MNG\r\n\032\n",8) != 0) 47013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowReaderException(CorruptImageError,"ImproperImageHeader"); 470247b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 470347b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp /* Initialize some nonzero members of the MngInfo structure. */ 47043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy for (i=0; i < MNG_MAX_OBJECTS; i++) 47053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 4706bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy mng_info->object_clip[i].right=(ssize_t) PNG_UINT_31_MAX; 4707bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy mng_info->object_clip[i].bottom=(ssize_t) PNG_UINT_31_MAX; 47083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 47093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->exists[0]=MagickTrue; 47103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 471147b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 47123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy first_mng_object=MagickTrue; 47133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_type=0; 47143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MNG_INSERT_LAYERS) 47153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy insert_layers=MagickFalse; /* should be False when converting or mogrifying */ 47163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 47173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy default_frame_delay=0; 47183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy default_frame_timeout=0; 47193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy frame_delay=0; 47203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy final_delay=1; 47213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->ticks_per_second=1UL*image->ticks_per_second; 47223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy object_id=0; 47233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy skip_to_iend=MagickFalse; 47243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy term_chunk_found=MagickFalse; 47253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->framing_mode=1; 47263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MNG_INSERT_LAYERS) 47273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mandatory_back=MagickFalse; 47283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 47293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MNG_INSERT_LAYERS) 47303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_background_color=image->background_color; 47313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 47323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy default_fb=mng_info->frame; 47333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy previous_fb=mng_info->frame; 47343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy do 47353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 47363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy char 47373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy type[MaxTextExtent]; 47383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 47393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (LocaleCompare(image_info->magick,"MNG") == 0) 47403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 47413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy unsigned char 47423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *chunk; 47433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 47443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 47453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Read a new chunk. 47463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 47473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy type[0]='\0'; 47483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ConcatenateMagickString(type,"errr",MaxTextExtent); 47493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy length=ReadBlobMSBLong(image); 47503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy count=(size_t) ReadBlob(image,4,(unsigned char *) type); 47513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 47523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 47533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 4754e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " Reading MNG chunk type %c%c%c%c, length: %.20g", 4755e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy type[0],type[1],type[2],type[3],(double) length); 47563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 47573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length > PNG_UINT_31_MAX) 47583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status=MagickFalse; 47590fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 47603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (count == 0) 47613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowReaderException(CorruptImageError,"CorruptImage"); 47620fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 47633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy p=NULL; 47643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) NULL; 47650fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 47663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length) 47673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 47683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) AcquireQuantumMemory(length,sizeof(*chunk)); 476947b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 47703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (chunk == (unsigned char *) NULL) 47713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); 477247b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 4773bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (i=0; i < (ssize_t) length; i++) 47743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[i]=(unsigned char) ReadBlobByte(image); 477547b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 47763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy p=chunk; 47773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 47780fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 47793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ReadBlobMSBLong(image); /* read crc word */ 47803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 47813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if !defined(JNG_SUPPORTED) 47823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_JHDR,4) == 0) 47833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 47843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy skip_to_iend=MagickTrue; 47850fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 47863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->jhdr_warning == 0) 47873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ThrowMagickException(&image->exception,GetMagickModule(), 47883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy CoderError,"JNGCompressNotSupported","`%s'",image->filename); 47890fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 47903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->jhdr_warning++; 47913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 47923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 47933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_DHDR,4) == 0) 47943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 47953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy skip_to_iend=MagickTrue; 47960fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 47973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->dhdr_warning == 0) 47983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ThrowMagickException(&image->exception,GetMagickModule(), 47993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy CoderError,"DeltaPNGNotSupported","`%s'",image->filename); 48000fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 48013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->dhdr_warning++; 48023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 48033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_MEND,4) == 0) 48043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 480547b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 48063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (skip_to_iend) 48073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 48083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_IEND,4) == 0) 48093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy skip_to_iend=MagickFalse; 48100fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 48113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length) 48123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 48130fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 48143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 48153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 48163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Skip to IEND."); 48170fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 48183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 48193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 48200fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 48213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_MHDR,4) == 0) 48223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 4823bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy mng_info->mng_width=(size_t) ((p[0] << 24) | (p[1] << 16) | 48243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (p[2] << 8) | p[3]); 48250fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 4826bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy mng_info->mng_height=(size_t) ((p[4] << 24) | (p[5] << 16) | 48273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (p[6] << 8) | p[7]); 48280fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 48293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 48303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 48313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 4832e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " MNG width: %.20g",(double) mng_info->mng_width); 48333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 4834e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " MNG height: %.20g",(double) mng_info->mng_height); 48353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 48360fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 48373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy p+=8; 48388182b0758e3429fb8dcd1700f09643fd4d80a41ccristy mng_info->ticks_per_second=(size_t) mng_get_long(p); 48390fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 48403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->ticks_per_second == 0) 48413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy default_frame_delay=0; 48420fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 48433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 48443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy default_frame_delay=1UL*image->ticks_per_second/ 48453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->ticks_per_second; 48460fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 48473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy frame_delay=default_frame_delay; 48483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy simplicity=0; 48490fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 48503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length > 16) 48513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 48523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy p+=16; 48538182b0758e3429fb8dcd1700f09643fd4d80a41ccristy simplicity=(size_t) mng_get_long(p); 48543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 48550fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 48563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_type=1; /* Full MNG */ 48570fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 48583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((simplicity != 0) && ((simplicity | 11) == 11)) 48593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_type=2; /* LC */ 48600fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 48613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((simplicity != 0) && ((simplicity | 9) == 9)) 48623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_type=3; /* VLC */ 48630fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 48643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MNG_INSERT_LAYERS) 48653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_type != 3) 48663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy insert_layers=MagickTrue; 48673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 48684c08aed51c5899665ade97263692328eea4af106cristy if (GetAuthenticPixelQueue(image) != (Quantum *) NULL) 48693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 487047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp /* Allocate next image structure. */ 48713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy AcquireNextImage(image_info,image); 48720fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 48733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (GetNextImageInList(image) == (Image *) NULL) 48743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return((Image *) NULL); 48750fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 48763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=SyncNextImageInList(image); 48773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->image=image; 48783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 48793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 48803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((mng_info->mng_width > 65535L) || 48813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (mng_info->mng_height > 65535L)) 48823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowReaderException(ImageError,"WidthOrHeightExceedsLimit"); 48830fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 48843b6fd2ec2d9f69f9404445dba0aff5bac02e685ccristy (void) FormatLocaleString(page_geometry,MaxTextExtent, 4885e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy "%.20gx%.20g+0+0",(double) mng_info->mng_width,(double) 4886f2faecf9facdbbb14fcba373365f9f691a9658e0cristy mng_info->mng_height); 48870fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 48883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->frame.left=0; 4889bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy mng_info->frame.right=(ssize_t) mng_info->mng_width; 48903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->frame.top=0; 4891bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy mng_info->frame.bottom=(ssize_t) mng_info->mng_height; 48923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->clip=default_fb=previous_fb=mng_info->frame; 48930fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 48943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy for (i=0; i < MNG_MAX_OBJECTS; i++) 48953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->object_clip[i]=mng_info->frame; 48960fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 48973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 48983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 48993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 49003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 49013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_TERM,4) == 0) 49023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 49033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy int 49043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy repeat=0; 49053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 49063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 49073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length) 49083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy repeat=p[0]; 49090fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 49103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (repeat == 3) 49113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 49128182b0758e3429fb8dcd1700f09643fd4d80a41ccristy final_delay=(png_uint_32) mng_get_long(&p[2]); 49138182b0758e3429fb8dcd1700f09643fd4d80a41ccristy mng_iterations=(png_uint_32) mng_get_long(&p[6]); 49140fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 49153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_iterations == PNG_UINT_31_MAX) 49163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_iterations=0; 49170fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 49183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->iterations=mng_iterations; 49193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy term_chunk_found=MagickTrue; 49203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 49210fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 49223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 49233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 49243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 49253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " repeat=%d",repeat); 49260fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 49273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 4928e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " final_delay=%.20g",(double) final_delay); 49290fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 49303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 4931e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " image->iterations=%.20g",(double) image->iterations); 49323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 49330fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 49343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 49353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 49363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 49373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_DEFI,4) == 0) 49383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 49393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_type == 3) 49403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ThrowMagickException(&image->exception,GetMagickModule(), 49413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy CoderError,"DEFI chunk found in MNG-VLC datastream","`%s'", 49423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->filename); 49430fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 49443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy object_id=(p[0] << 8) | p[1]; 49450fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 49463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_type == 2 && object_id != 0) 49473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ThrowMagickException(&image->exception,GetMagickModule(), 49483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy CoderError,"Nonzero object_id in MNG-LC datastream","`%s'", 49493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->filename); 49500fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 49513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (object_id > MNG_MAX_OBJECTS) 49523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 49533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 49543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Instead ofsuing a warning we should allocate a larger 49553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngInfo structure and continue. 49563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 49573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ThrowMagickException(&image->exception,GetMagickModule(), 49583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy CoderError,"object id too large","`%s'",image->filename); 49593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy object_id=MNG_MAX_OBJECTS; 49603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 49610fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 49623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->exists[object_id]) 49633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->frozen[object_id]) 49643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 49653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 49663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ThrowMagickException(&image->exception, 49673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy GetMagickModule(),CoderError, 49683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy "DEFI cannot redefine a frozen MNG object","`%s'", 49693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->filename); 49703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 49713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 49720fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 49733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->exists[object_id]=MagickTrue; 49740fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 49753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length > 2) 49763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->invisible[object_id]=p[2]; 49770fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 49783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 49793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Extract object offset info. 49803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 49813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length > 11) 49823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 49830fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp mng_info->x_off[object_id]=(ssize_t) ((p[4] << 24) | 49840fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp (p[5] << 16) | (p[6] << 8) | p[7]); 49850fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 49860fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp mng_info->y_off[object_id]=(ssize_t) ((p[8] << 24) | 49870fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp (p[9] << 16) | (p[10] << 8) | p[11]); 49880fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 49893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 49903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 49913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 4992e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " x_off[%d]: %.20g",object_id,(double) 4993f2faecf9facdbbb14fcba373365f9f691a9658e0cristy mng_info->x_off[object_id]); 49940fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 49953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 4996e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " y_off[%d]: %.20g",object_id,(double) 4997f2faecf9facdbbb14fcba373365f9f691a9658e0cristy mng_info->y_off[object_id]); 49983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 49993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 50000fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 50013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 50023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Extract object clipping info. 50033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 50043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length > 27) 50053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->object_clip[object_id]=mng_read_box(mng_info->frame,0, 50063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy &p[12]); 50070fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 50083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 50093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 50103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 50113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_bKGD,4) == 0) 50123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 50133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->have_global_bkgd=MagickFalse; 50140fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 50153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length > 5) 50163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 50173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->mng_global_bkgd.red= 50183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ScaleShortToQuantum((unsigned short) ((p[0] << 8) | p[1])); 50190fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 50203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->mng_global_bkgd.green= 50213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ScaleShortToQuantum((unsigned short) ((p[2] << 8) | p[3])); 50220fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 50233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->mng_global_bkgd.blue= 50243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ScaleShortToQuantum((unsigned short) ((p[4] << 8) | p[5])); 50250fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 50263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->have_global_bkgd=MagickTrue; 50273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 50280fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 50293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 50303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 50313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 50323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_BACK,4) == 0) 50333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 50343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MNG_INSERT_LAYERS) 50353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length > 6) 50363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mandatory_back=p[6]; 50370fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 50383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 50393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mandatory_back=0; 50400fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 50413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mandatory_back && length > 5) 50423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 50433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_background_color.red= 50443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ScaleShortToQuantum((unsigned short) ((p[0] << 8) | p[1])); 50450fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 50463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_background_color.green= 50473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ScaleShortToQuantum((unsigned short) ((p[2] << 8) | p[3])); 50480fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 50493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_background_color.blue= 50503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ScaleShortToQuantum((unsigned short) ((p[4] << 8) | p[5])); 50510fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 50524c08aed51c5899665ade97263692328eea4af106cristy mng_background_color.alpha=OpaqueAlpha; 50533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 50540fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 50553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#ifdef MNG_OBJECT_BUFFERS 50563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length > 8) 50573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_background_object=(p[7] << 8) | p[8]; 50583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 50593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 50603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 50613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 50623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 506347b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 50643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_PLTE,4) == 0) 50653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 506647b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp /* Read global PLTE. */ 506747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 50683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length && (length < 769)) 50693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 50703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->global_plte == (png_colorp) NULL) 50713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->global_plte=(png_colorp) AcquireQuantumMemory(256, 50723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy sizeof(*mng_info->global_plte)); 50730fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 5074bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (i=0; i < (ssize_t) (length/3); i++) 50753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 50763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->global_plte[i].red=p[3*i]; 50773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->global_plte[i].green=p[3*i+1]; 50783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->global_plte[i].blue=p[3*i+2]; 50793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 50800fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 508135ef824baa82511126ff0072ae30eee0da9c05a3cristy mng_info->global_plte_length=(unsigned int) (length/3); 50823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 50833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#ifdef MNG_LOOSE 50843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy for ( ; i < 256; i++) 50853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 50863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->global_plte[i].red=i; 50873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->global_plte[i].green=i; 50883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->global_plte[i].blue=i; 50893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 50900fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 50913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length) 50923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->global_plte_length=256; 50933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 50943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 50953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->global_plte_length=0; 50960fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 50973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 50983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 50993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 510047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 51013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_tRNS,4) == 0) 51023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 51033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* read global tRNS */ 51043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 51053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length < 257) 5106bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (i=0; i < (ssize_t) length; i++) 51073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->global_trns[i]=p[i]; 51083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 51093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#ifdef MNG_LOOSE 51103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy for ( ; i < 256; i++) 51113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->global_trns[i]=255; 51123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 511312560f31d66b4ef4afdcff2c20807c555dcf2f7dcristy mng_info->global_trns_length=(unsigned int) length; 51143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 51153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 51163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 51173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_gAMA,4) == 0) 51183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 51193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length == 4) 51203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 5121bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy ssize_t 51223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy igamma; 51233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 51248182b0758e3429fb8dcd1700f09643fd4d80a41ccristy igamma=mng_get_long(p); 51253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->global_gamma=((float) igamma)*0.00001; 51263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->have_global_gama=MagickTrue; 51273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 51280fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 51293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 51303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->have_global_gama=MagickFalse; 51310fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 51323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 51333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 51343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 51353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 51363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_cHRM,4) == 0) 51373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 513847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp /* Read global cHRM */ 513947b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 51403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length == 32) 51413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 51428182b0758e3429fb8dcd1700f09643fd4d80a41ccristy mng_info->global_chrm.white_point.x=0.00001*mng_get_long(p); 51438182b0758e3429fb8dcd1700f09643fd4d80a41ccristy mng_info->global_chrm.white_point.y=0.00001*mng_get_long(&p[4]); 51448182b0758e3429fb8dcd1700f09643fd4d80a41ccristy mng_info->global_chrm.red_primary.x=0.00001*mng_get_long(&p[8]); 51453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->global_chrm.red_primary.y=0.00001* 51468182b0758e3429fb8dcd1700f09643fd4d80a41ccristy mng_get_long(&p[12]); 51473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->global_chrm.green_primary.x=0.00001* 51488182b0758e3429fb8dcd1700f09643fd4d80a41ccristy mng_get_long(&p[16]); 51493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->global_chrm.green_primary.y=0.00001* 51508182b0758e3429fb8dcd1700f09643fd4d80a41ccristy mng_get_long(&p[20]); 51513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->global_chrm.blue_primary.x=0.00001* 51528182b0758e3429fb8dcd1700f09643fd4d80a41ccristy mng_get_long(&p[24]); 51533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->global_chrm.blue_primary.y=0.00001* 51548182b0758e3429fb8dcd1700f09643fd4d80a41ccristy mng_get_long(&p[28]); 51553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->have_global_chrm=MagickTrue; 51563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 51573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 51583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->have_global_chrm=MagickFalse; 515947b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 51603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 51613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 51623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 516347b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 51643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_sRGB,4) == 0) 51653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 51663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 51673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Read global sRGB. 51683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 51693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length) 51703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 5171e610a071534e448c46460a5aa39ede33bf56b329glennrp mng_info->global_srgb_intent= 5172cf002022280cc4dedb2748ad6f415aac1d44f530glennrp Magick_RenderingIntent_from_PNG_RenderingIntent(p[0]); 51733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->have_global_srgb=MagickTrue; 51743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 51753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 51763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->have_global_srgb=MagickFalse; 517747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 51783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 51793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 51803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 518147b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 51823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_iCCP,4) == 0) 51833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 5184fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp /* To do: */ 51853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 51863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 51873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Read global iCCP. 51883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 51893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length) 51903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 519147b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 51923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 51933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 519447b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 51953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_FRAM,4) == 0) 51963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 51973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_type == 3) 51983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ThrowMagickException(&image->exception,GetMagickModule(), 51993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy CoderError,"FRAM chunk found in MNG-VLC datastream","`%s'", 52003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->filename); 52010fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 52023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((mng_info->framing_mode == 2) || (mng_info->framing_mode == 4)) 52033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->delay=frame_delay; 52040fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 52053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy frame_delay=default_frame_delay; 52063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy frame_timeout=default_frame_timeout; 52073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy fb=default_fb; 520847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 52093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length) 52103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (p[0]) 52113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->framing_mode=p[0]; 52120fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 52133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 52143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 52153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Framing_mode=%d",mng_info->framing_mode); 52160fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 52173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length > 6) 52183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 521947b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp /* Note the delay and frame clipping boundaries. */ 522047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 52213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy p++; /* framing mode */ 522247b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 5223bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy while (*p && ((p-chunk) < (ssize_t) length)) 52243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy p++; /* frame name */ 522547b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 52263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy p++; /* frame name terminator */ 522747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 5228bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy if ((p-chunk) < (ssize_t) (length-4)) 52293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 52303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy int 52313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy change_delay, 52323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy change_timeout, 52333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy change_clipping; 52343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 52353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy change_delay=(*p++); 52363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy change_timeout=(*p++); 52373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy change_clipping=(*p++); 52383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy p++; /* change_sync */ 523947b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 52403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (change_delay) 52413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 52428182b0758e3429fb8dcd1700f09643fd4d80a41ccristy frame_delay=1UL*image->ticks_per_second* 52438182b0758e3429fb8dcd1700f09643fd4d80a41ccristy mng_get_long(p); 52440fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 52458182b0758e3429fb8dcd1700f09643fd4d80a41ccristy if (mng_info->ticks_per_second != 0) 52468182b0758e3429fb8dcd1700f09643fd4d80a41ccristy frame_delay/=mng_info->ticks_per_second; 52470fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 5248bb010dd620d8cf1743e64bc12f83e2bf1ffeddddglennrp else 5249bb010dd620d8cf1743e64bc12f83e2bf1ffeddddglennrp frame_delay=PNG_UINT_31_MAX; 52500fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 52513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (change_delay == 2) 52523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy default_frame_delay=frame_delay; 52530fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 52543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy p+=4; 52550fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 52563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 52573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 5258e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " Framing_delay=%.20g",(double) frame_delay); 52593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 526047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 52613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (change_timeout) 52623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 5263bb010dd620d8cf1743e64bc12f83e2bf1ffeddddglennrp frame_timeout=1UL*image->ticks_per_second* 5264bb010dd620d8cf1743e64bc12f83e2bf1ffeddddglennrp mng_get_long(p); 52650fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 5266bb010dd620d8cf1743e64bc12f83e2bf1ffeddddglennrp if (mng_info->ticks_per_second != 0) 5267bb010dd620d8cf1743e64bc12f83e2bf1ffeddddglennrp frame_timeout/=mng_info->ticks_per_second; 52680fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 5269bb010dd620d8cf1743e64bc12f83e2bf1ffeddddglennrp else 5270bb010dd620d8cf1743e64bc12f83e2bf1ffeddddglennrp frame_timeout=PNG_UINT_31_MAX; 52710fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 52723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (change_delay == 2) 52733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy default_frame_timeout=frame_timeout; 52740fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 52753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy p+=4; 52760fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 52773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 52783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 5279e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " Framing_timeout=%.20g",(double) frame_timeout); 52803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 528147b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 52823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (change_clipping) 52833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 52843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy fb=mng_read_box(previous_fb,(char) p[0],&p[1]); 52853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy p+=17; 52863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy previous_fb=fb; 52870fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 52883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 52893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 52900fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp " Frame_clip: L=%.20g R=%.20g T=%.20g B=%.20g", 5291e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy (double) fb.left,(double) fb.right,(double) fb.top, 5292e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy (double) fb.bottom); 529347b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 52943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (change_clipping == 2) 52953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy default_fb=fb; 52963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 52973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 52983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 52993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->clip=fb; 53003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->clip=mng_minimum_box(fb,mng_info->frame); 53010fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 5302bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy subframe_width=(size_t) (mng_info->clip.right 53033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy -mng_info->clip.left); 53040fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 5305bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy subframe_height=(size_t) (mng_info->clip.bottom 53063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy -mng_info->clip.top); 53073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 53083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Insert a background layer behind the frame if framing_mode is 4. 53093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 53103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MNG_INSERT_LAYERS) 53113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 53123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 5313e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " subframe_width=%.20g, subframe_height=%.20g",(double) 5314e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy subframe_width,(double) subframe_height); 53150fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 53163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (insert_layers && (mng_info->framing_mode == 4) && 53173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (subframe_width) && (subframe_height)) 53183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 531947b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp /* Allocate next image structure. */ 53204c08aed51c5899665ade97263692328eea4af106cristy if (GetAuthenticPixelQueue(image) != (Quantum *) NULL) 53213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 53223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy AcquireNextImage(image_info,image); 532347b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 53243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (GetNextImageInList(image) == (Image *) NULL) 53253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 53263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=DestroyImageList(image); 53273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngInfoFreeStruct(mng_info,&have_mng_structure); 53283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return((Image *) NULL); 53293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 533047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 53313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=SyncNextImageInList(image); 53323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 53330fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 53343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->image=image; 53350fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 53363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (term_chunk_found) 53373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 53383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->start_loop=MagickTrue; 53393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->iterations=mng_iterations; 53403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy term_chunk_found=MagickFalse; 53413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 53420fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 53433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 53443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->start_loop=MagickFalse; 53450fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 53463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->columns=subframe_width; 53473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->rows=subframe_height; 53483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->page.width=subframe_width; 53493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->page.height=subframe_height; 53503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->page.x=mng_info->clip.left; 53513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->page.y=mng_info->clip.top; 53523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->background_color=mng_background_color; 53533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->matte=MagickFalse; 53543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->delay=0; 53553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) SetImageBackgroundColor(image); 53560fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 53573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 53583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 53590fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp " Insert backgd layer, L=%.20g, R=%.20g T=%.20g, B=%.20g", 5360e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy (double) mng_info->clip.left,(double) mng_info->clip.right, 5361e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy (double) mng_info->clip.top,(double) mng_info->clip.bottom); 53623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 53633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 53643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 53653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 53663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 53673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_CLIP,4) == 0) 53683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 53693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy unsigned int 53703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy first_object, 53713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy last_object; 53723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 53733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 53743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Read CLIP. 53753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 53763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy first_object=(p[0] << 8) | p[1]; 53773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy last_object=(p[2] << 8) | p[3]; 537847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 53793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy for (i=(int) first_object; i <= (int) last_object; i++) 53803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 53813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->exists[i] && !mng_info->frozen[i]) 53823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 53833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngBox 53843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy box; 53853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 53863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy box=mng_info->object_clip[i]; 53873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->object_clip[i]=mng_read_box(box,(char) p[4],&p[5]); 53883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 53893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 539047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 53913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 53923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 53933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 53943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_SAVE,4) == 0) 53953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 53963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy for (i=1; i < MNG_MAX_OBJECTS; i++) 53973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->exists[i]) 53983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 53993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->frozen[i]=MagickTrue; 54003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#ifdef MNG_OBJECT_BUFFERS 54013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->ob[i] != (MngBuffer *) NULL) 54023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->ob[i]->frozen=MagickTrue; 54033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 54043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 54050fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 54063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length) 54073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 54080fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 54093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 54103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 54113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 54123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((memcmp(type,mng_DISC,4) == 0) || (memcmp(type,mng_SEEK,4) == 0)) 54133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 541447b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp /* Read DISC or SEEK. */ 541547b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 54163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((length == 0) || !memcmp(type,mng_SEEK,4)) 54173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 54183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy for (i=1; i < MNG_MAX_OBJECTS; i++) 54193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngInfoDiscardObject(mng_info,i); 54203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 54210fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 54223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 54233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 5424bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy register ssize_t 54253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy j; 54263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 5427bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (j=0; j < (ssize_t) length; j+=2) 54283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 54293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy i=p[j] << 8 | p[j+1]; 54303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngInfoDiscardObject(mng_info,i); 54313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 54323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 54330fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 54343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length) 54353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 54360fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 54373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 54383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 543947b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 54403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_MOVE,4) == 0) 54413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 5442bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy size_t 54433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy first_object, 54443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy last_object; 54453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 544647b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp /* read MOVE */ 544747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 54483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy first_object=(p[0] << 8) | p[1]; 54493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy last_object=(p[2] << 8) | p[3]; 5450bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (i=(ssize_t) first_object; i <= (ssize_t) last_object; i++) 54513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 54523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->exists[i] && !mng_info->frozen[i]) 54533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 54543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngPair 54553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy new_pair; 54563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 54573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngPair 54583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy old_pair; 54593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 54603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy old_pair.a=mng_info->x_off[i]; 54613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy old_pair.b=mng_info->y_off[i]; 54623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy new_pair=mng_read_pair(old_pair,(int) p[4],&p[5]); 54633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->x_off[i]=new_pair.a; 54643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->y_off[i]=new_pair.b; 54653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 54663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 546747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 54683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 54693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 54703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 54713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 54723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_LOOP,4) == 0) 54733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 5474bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy ssize_t loop_iters=1; 54753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy loop_level=chunk[0]; 54763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->loop_active[loop_level]=1; /* mark loop active */ 547747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 547847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp /* Record starting point. */ 54798182b0758e3429fb8dcd1700f09643fd4d80a41ccristy loop_iters=mng_get_long(&chunk[1]); 54800fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 54813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 54823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 5483e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " LOOP level %.20g has %.20g iterations ",(double) loop_level, 5484e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy (double) loop_iters); 54850fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 54863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (loop_iters == 0) 54873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy skipping_loop=loop_level; 54880fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 54893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 54903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 54913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->loop_jump[loop_level]=TellBlob(image); 54923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->loop_count[loop_level]=loop_iters; 54933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 54940fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 54953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->loop_iteration[loop_level]=0; 54963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 54973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 54983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 549947b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 55003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_ENDL,4) == 0) 55013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 55023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy loop_level=chunk[0]; 550347b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 55043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (skipping_loop > 0) 55053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 55063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (skipping_loop == loop_level) 55073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 55083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 55093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Found end of zero-iteration loop. 55103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 55113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy skipping_loop=(-1); 55123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->loop_active[loop_level]=0; 55133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 55143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 551547b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 55163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 55173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 55183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->loop_active[loop_level] == 1) 55193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 55203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->loop_count[loop_level]--; 55213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->loop_iteration[loop_level]++; 55220fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 55233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 55243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 55250fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp " ENDL: LOOP level %.20g has %.20g remaining iters ", 5526e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy (double) loop_level,(double) 5527f2faecf9facdbbb14fcba373365f9f691a9658e0cristy mng_info->loop_count[loop_level]); 552847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 55293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->loop_count[loop_level] != 0) 55303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 55313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy offset=SeekBlob(image,mng_info->loop_jump[loop_level], 55323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy SEEK_SET); 55330fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 55343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (offset < 0) 55353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowReaderException(CorruptImageError, 55363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy "ImproperImageHeader"); 55373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 553847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 55393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 55403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 55413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy short 55423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy last_level; 55433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 55443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 55453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Finished loop. 55463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 55473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->loop_active[loop_level]=0; 55483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy last_level=(-1); 55493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy for (i=0; i < loop_level; i++) 55503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->loop_active[i] == 1) 55513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy last_level=(short) i; 55523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy loop_level=last_level; 55533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 55543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 55553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 555647b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 55573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 55583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 55593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 556047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 55613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_CLON,4) == 0) 55623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 55633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->clon_warning == 0) 55643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ThrowMagickException(&image->exception,GetMagickModule(), 55653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy CoderError,"CLON is not implemented yet","`%s'", 55663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->filename); 556747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 55683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->clon_warning++; 55693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 557047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 55713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_MAGN,4) == 0) 55723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 55733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_uint_16 55743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_first, 55753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_last, 55763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_mb, 55773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_ml, 55783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_mr, 55793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_mt, 55803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_mx, 55813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_my, 55823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_methx, 55833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_methy; 55843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 55853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length > 1) 55863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_first=(p[0] << 8) | p[1]; 55870fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 55883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 55893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_first=0; 55900fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 55913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length > 3) 55923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_last=(p[2] << 8) | p[3]; 55930fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 55943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 55953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_last=magn_first; 55963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#ifndef MNG_OBJECT_BUFFERS 55973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (magn_first || magn_last) 55983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->magn_warning == 0) 55993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 56003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ThrowMagickException(&image->exception, 56013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy GetMagickModule(),CoderError, 56023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy "MAGN is not implemented yet for nonzero objects", 56033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy "`%s'",image->filename); 560447b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 56053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->magn_warning++; 56063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 56073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 56083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length > 4) 56093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_methx=p[4]; 561047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 56113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 56123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_methx=0; 56133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 56143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length > 6) 56153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_mx=(p[5] << 8) | p[6]; 561647b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 56173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 56183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_mx=1; 561947b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 56203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (magn_mx == 0) 56213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_mx=1; 56223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 56233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length > 8) 56243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_my=(p[7] << 8) | p[8]; 562547b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 56263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 56273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_my=magn_mx; 562847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 56293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (magn_my == 0) 56303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_my=1; 56313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 56323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length > 10) 56333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_ml=(p[9] << 8) | p[10]; 563447b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 56353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 56363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_ml=magn_mx; 563747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 56383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (magn_ml == 0) 56393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_ml=1; 56403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 56413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length > 12) 56423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_mr=(p[11] << 8) | p[12]; 564347b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 56443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 56453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_mr=magn_mx; 564647b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 56473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (magn_mr == 0) 56483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_mr=1; 56493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 56503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length > 14) 56513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_mt=(p[13] << 8) | p[14]; 565247b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 56533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 56543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_mt=magn_my; 565547b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 56563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (magn_mt == 0) 56573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_mt=1; 56583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 56593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length > 16) 56603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_mb=(p[15] << 8) | p[16]; 566147b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 56623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 56633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_mb=magn_my; 566447b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 56653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (magn_mb == 0) 56663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_mb=1; 56673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 56683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length > 17) 56693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_methy=p[17]; 567047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 56713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 56723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_methy=magn_methx; 56733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 567447b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 56753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (magn_methx > 5 || magn_methy > 5) 56763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->magn_warning == 0) 56773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 56783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ThrowMagickException(&image->exception, 56793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy GetMagickModule(),CoderError, 56803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy "Unknown MAGN method in MNG datastream","`%s'", 56813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->filename); 568247b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 56833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->magn_warning++; 56843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 56853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#ifdef MNG_OBJECT_BUFFERS 56863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Magnify existing objects in the range magn_first to magn_last */ 56873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 56883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (magn_first == 0 || magn_last == 0) 56893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 56903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Save the magnification factors for object 0 */ 56913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->magn_mb=magn_mb; 56923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->magn_ml=magn_ml; 56933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->magn_mr=magn_mr; 56943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->magn_mt=magn_mt; 56953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->magn_mx=magn_mx; 56963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->magn_my=magn_my; 56973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->magn_methx=magn_methx; 56983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->magn_methy=magn_methy; 56993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 57003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 570147b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 57023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_PAST,4) == 0) 57033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 57043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->past_warning == 0) 57053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ThrowMagickException(&image->exception,GetMagickModule(), 57063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy CoderError,"PAST is not implemented yet","`%s'", 57073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->filename); 570847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 57093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->past_warning++; 57103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 571147b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 57123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_SHOW,4) == 0) 57133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 57143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->show_warning == 0) 57153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ThrowMagickException(&image->exception,GetMagickModule(), 57163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy CoderError,"SHOW is not implemented yet","`%s'", 57173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->filename); 571847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 57193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->show_warning++; 57203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 572147b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 57223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_sBIT,4) == 0) 57233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 57243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length < 4) 57253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->have_global_sbit=MagickFalse; 572647b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 57273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 57283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 57293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->global_sbit.gray=p[0]; 57303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->global_sbit.red=p[0]; 57313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->global_sbit.green=p[1]; 57323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->global_sbit.blue=p[2]; 57333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->global_sbit.alpha=p[3]; 57343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->have_global_sbit=MagickTrue; 57353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 57363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 57373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_pHYs,4) == 0) 57383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 57393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length > 8) 57403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 57413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->global_x_pixels_per_unit= 57428182b0758e3429fb8dcd1700f09643fd4d80a41ccristy (size_t) mng_get_long(p); 57433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->global_y_pixels_per_unit= 57448182b0758e3429fb8dcd1700f09643fd4d80a41ccristy (size_t) mng_get_long(&p[4]); 57453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->global_phys_unit_type=p[8]; 57463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->have_global_phys=MagickTrue; 57473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 574847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 57493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 57503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->have_global_phys=MagickFalse; 57513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 57523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_pHYg,4) == 0) 57533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 57543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->phyg_warning == 0) 57553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ThrowMagickException(&image->exception,GetMagickModule(), 57563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy CoderError,"pHYg is not implemented.","`%s'",image->filename); 575747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 57583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->phyg_warning++; 57593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 57603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_BASI,4) == 0) 57613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 57623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy skip_to_iend=MagickTrue; 576347b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 57643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->basi_warning == 0) 57653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ThrowMagickException(&image->exception,GetMagickModule(), 57663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy CoderError,"BASI is not implemented yet","`%s'", 57673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->filename); 576847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 57693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->basi_warning++; 57703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#ifdef MNG_BASI_SUPPORTED 5771bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy basi_width=(size_t) ((p[0] << 24) | (p[1] << 16) | 57723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (p[2] << 8) | p[3]); 5773bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy basi_height=(size_t) ((p[4] << 24) | (p[5] << 16) | 57743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (p[6] << 8) | p[7]); 57753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy basi_color_type=p[8]; 57763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy basi_compression_method=p[9]; 57773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy basi_filter_type=p[10]; 57783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy basi_interlace_method=p[11]; 57793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length > 11) 57803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy basi_red=(p[12] << 8) & p[13]; 578147b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 57823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 57833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy basi_red=0; 578447b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 57853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length > 13) 57863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy basi_green=(p[14] << 8) & p[15]; 578747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 57883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 57893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy basi_green=0; 579047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 57913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length > 15) 57923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy basi_blue=(p[16] << 8) & p[17]; 579347b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 57943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 57953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy basi_blue=0; 579647b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 57973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length > 17) 57983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy basi_alpha=(p[18] << 8) & p[19]; 579947b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 58003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 58013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 58023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (basi_sample_depth == 16) 58033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy basi_alpha=65535L; 58043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 58053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy basi_alpha=255; 58063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 580747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 58083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length > 19) 58093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy basi_viewable=p[20]; 581047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 58113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 58123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy basi_viewable=0; 581347b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 58143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 58153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 58163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 58173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 581847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 58193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_IHDR,4) 58203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(JNG_SUPPORTED) 58213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy && memcmp(type,mng_JHDR,4) 58223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 58233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ) 58243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 58253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Not an IHDR or JHDR chunk */ 58263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length) 58273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 582847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 58293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 58303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 58313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* Process IHDR */ 58323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 58333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 58343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Processing %c%c%c%c chunk",type[0],type[1],type[2],type[3]); 583547b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 58363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->exists[object_id]=MagickTrue; 58373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->viewable[object_id]=MagickTrue; 583847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 58393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->invisible[object_id]) 58403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 58413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 58423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 58433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Skipping invisible object"); 584447b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 58453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy skip_to_iend=MagickTrue; 58463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 58473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy continue; 58483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 58493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MNG_INSERT_LAYERS) 58503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (length < 8) 58513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowReaderException(CorruptImageError,"ImproperImageHeader"); 585247b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 58538182b0758e3429fb8dcd1700f09643fd4d80a41ccristy image_width=(size_t) mng_get_long(p); 58548182b0758e3429fb8dcd1700f09643fd4d80a41ccristy image_height=(size_t) mng_get_long(&p[4]); 58553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 58563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk=(unsigned char *) RelinquishMagickMemory(chunk); 58573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 58583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 58593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Insert a transparent background layer behind the entire animation 58603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if it is not full screen. 58613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 58623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MNG_INSERT_LAYERS) 58633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (insert_layers && mng_type && first_mng_object) 58643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 58653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((mng_info->clip.left > 0) || (mng_info->clip.top > 0) || 58663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (image_width < mng_info->mng_width) || 5867bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy (mng_info->clip.right < (ssize_t) mng_info->mng_width) || 58683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (image_height < mng_info->mng_height) || 5869bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy (mng_info->clip.bottom < (ssize_t) mng_info->mng_height)) 58703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 58714c08aed51c5899665ade97263692328eea4af106cristy if (GetAuthenticPixelQueue(image) != (Quantum *) NULL) 58723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 58733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 58743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Allocate next image structure. 58753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 58763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy AcquireNextImage(image_info,image); 587747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 58783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (GetNextImageInList(image) == (Image *) NULL) 58793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 58803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=DestroyImageList(image); 58813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngInfoFreeStruct(mng_info,&have_mng_structure); 58823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return((Image *) NULL); 58833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 588447b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 58853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=SyncNextImageInList(image); 58863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 58873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->image=image; 588847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 58893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (term_chunk_found) 58903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 58913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->start_loop=MagickTrue; 58923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->iterations=mng_iterations; 58933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy term_chunk_found=MagickFalse; 58943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 589547b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 58963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 58973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->start_loop=MagickFalse; 589847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 589947b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp /* Make a background rectangle. */ 590047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 59013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->delay=0; 59023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->columns=mng_info->mng_width; 59033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->rows=mng_info->mng_height; 59043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->page.width=mng_info->mng_width; 59053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->page.height=mng_info->mng_height; 59063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->page.x=0; 59073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->page.y=0; 59083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->background_color=mng_background_color; 59093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) SetImageBackgroundColor(image); 59103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 59113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 5912e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " Inserted transparent background layer, W=%.20g, H=%.20g", 5913e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy (double) mng_info->mng_width,(double) mng_info->mng_height); 59143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 59153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 59163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 59173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Insert a background layer behind the upcoming image if 59183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy framing_mode is 3, and we haven't already inserted one. 59193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 59203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (insert_layers && (mng_info->framing_mode == 3) && 59213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (subframe_width) && (subframe_height) && (simplicity == 0 || 59223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (simplicity & 0x08))) 59233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 59244c08aed51c5899665ade97263692328eea4af106cristy if (GetAuthenticPixelQueue(image) != (Quantum *) NULL) 59253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 59263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 59273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Allocate next image structure. 59283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 59293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy AcquireNextImage(image_info,image); 593047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 59313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (GetNextImageInList(image) == (Image *) NULL) 59323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 59333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=DestroyImageList(image); 59343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngInfoFreeStruct(mng_info,&have_mng_structure); 59353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return((Image *) NULL); 59363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 593747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 59383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=SyncNextImageInList(image); 59393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 59400fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 59413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->image=image; 59420fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 59433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (term_chunk_found) 59443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 59453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->start_loop=MagickTrue; 59463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->iterations=mng_iterations; 59473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy term_chunk_found=MagickFalse; 59483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 59490fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 59503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 59513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->start_loop=MagickFalse; 595247b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 59533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->delay=0; 59543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->columns=subframe_width; 59553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->rows=subframe_height; 59563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->page.width=subframe_width; 59573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->page.height=subframe_height; 59583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->page.x=mng_info->clip.left; 59593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->page.y=mng_info->clip.top; 59603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->background_color=mng_background_color; 59613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->matte=MagickFalse; 59623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) SetImageBackgroundColor(image); 59630fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 59643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 59653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 59660fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp " Insert background layer, L=%.20g, R=%.20g T=%.20g, B=%.20g", 5967e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy (double) mng_info->clip.left,(double) mng_info->clip.right, 5968e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy (double) mng_info->clip.top,(double) mng_info->clip.bottom); 59693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 59703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif /* MNG_INSERT_LAYERS */ 59713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy first_mng_object=MagickFalse; 597247b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 59734c08aed51c5899665ade97263692328eea4af106cristy if (GetAuthenticPixelQueue(image) != (Quantum *) NULL) 59743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 59753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 59763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Allocate next image structure. 59773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 59783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy AcquireNextImage(image_info,image); 597947b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 59803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (GetNextImageInList(image) == (Image *) NULL) 59813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 59823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=DestroyImageList(image); 59833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngInfoFreeStruct(mng_info,&have_mng_structure); 59843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return((Image *) NULL); 59853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 598647b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 59873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=SyncNextImageInList(image); 59883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 59893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->image=image; 59903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status=SetImageProgress(image,LoadImagesTag,TellBlob(image), 59913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy GetBlobSize(image)); 59920fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 59933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (status == MagickFalse) 59943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 59950fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 59963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (term_chunk_found) 59973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 59983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->start_loop=MagickTrue; 59993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy term_chunk_found=MagickFalse; 60003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 60010fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 60023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 60033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->start_loop=MagickFalse; 60040fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 60053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->framing_mode == 1 || mng_info->framing_mode == 3) 60063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 60073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->delay=frame_delay; 60083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy frame_delay=default_frame_delay; 60093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 60100fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 60113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 60123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->delay=0; 60130fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 60143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->page.width=mng_info->mng_width; 60153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->page.height=mng_info->mng_height; 60163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->page.x=mng_info->x_off[object_id]; 60173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->page.y=mng_info->y_off[object_id]; 60183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->iterations=mng_iterations; 601947b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 60203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 60213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Seek back to the beginning of the IHDR or JHDR chunk's length field. 60223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 602347b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 60243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 60253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 60263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Seeking back to beginning of %c%c%c%c chunk",type[0],type[1], 60273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy type[2],type[3]); 602847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 6029bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy offset=SeekBlob(image,-((ssize_t) length+12),SEEK_CUR); 603047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 60313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (offset < 0) 60323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowReaderException(CorruptImageError,"ImproperImageHeader"); 60333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 60343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 60353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy previous=image; 60363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->image=image; 60373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->mng_type=mng_type; 60383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->object_id=object_id; 60393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 60403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (memcmp(type,mng_IHDR,4) == 0) 60413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=ReadOnePNGImage(mng_info,image_info,exception); 604247b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 60433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(JNG_SUPPORTED) 60443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 60453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=ReadOneJNGImage(mng_info,image_info,exception); 60463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 60473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 60483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image == (Image *) NULL) 60493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 60503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (IsImageObject(previous) != MagickFalse) 60513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 60523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) DestroyImageList(previous); 60533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) CloseBlob(previous); 60543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 605547b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 60563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngInfoFreeStruct(mng_info,&have_mng_structure); 60573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return((Image *) NULL); 60583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 60590fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 60603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->columns == 0 || image->rows == 0) 60613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 60623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) CloseBlob(image); 60633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=DestroyImageList(image); 60643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngInfoFreeStruct(mng_info,&have_mng_structure); 60653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return((Image *) NULL); 60663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 60670fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 60683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->image=image; 60693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 60703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_type) 60713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 60723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngBox 60733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy crop_box; 60743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 60753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->magn_methx || mng_info->magn_methy) 60763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 60773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_uint_32 60783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magnified_height, 60793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magnified_width; 60803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 60813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 60823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 60833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Processing MNG MAGN chunk"); 60843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 60853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->magn_methx == 1) 60863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 60873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magnified_width=mng_info->magn_ml; 608847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 60893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->columns > 1) 60903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magnified_width += mng_info->magn_mr; 609147b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 60923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->columns > 2) 609347b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp magnified_width += (png_uint_32) 609447b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp ((image->columns-2)*(mng_info->magn_mx)); 60953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 609647b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 60973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 60983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 60994e5bc84ff8bf274c4d9206d5e6ffd1a5e5d75335cristy magnified_width=(png_uint_32) image->columns; 610047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 61013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->columns > 1) 61023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magnified_width += mng_info->magn_ml-1; 610347b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 61043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->columns > 2) 61053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magnified_width += mng_info->magn_mr-1; 610647b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 61073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->columns > 3) 610847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp magnified_width += (png_uint_32) 610947b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp ((image->columns-3)*(mng_info->magn_mx-1)); 61103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 611147b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 61123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->magn_methy == 1) 61133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 61143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magnified_height=mng_info->magn_mt; 611547b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 61163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->rows > 1) 61173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magnified_height += mng_info->magn_mb; 611847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 61193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->rows > 2) 612047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp magnified_height += (png_uint_32) 612147b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp ((image->rows-2)*(mng_info->magn_my)); 61223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 612347b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 61243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 61253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 61264e5bc84ff8bf274c4d9206d5e6ffd1a5e5d75335cristy magnified_height=(png_uint_32) image->rows; 612747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 61283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->rows > 1) 61293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magnified_height += mng_info->magn_mt-1; 613047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 61313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->rows > 2) 61323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magnified_height += mng_info->magn_mb-1; 613347b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 61343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->rows > 3) 613547b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp magnified_height += (png_uint_32) 613647b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp ((image->rows-3)*(mng_info->magn_my-1)); 61373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 613847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 61393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (magnified_height > image->rows || 61403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magnified_width > image->columns) 61413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 61423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Image 61433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *large_image; 61443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 61453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy int 61463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy yy; 61473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 61484c08aed51c5899665ade97263692328eea4af106cristy Quantum 61494c08aed51c5899665ade97263692328eea4af106cristy *next, 61504c08aed51c5899665ade97263692328eea4af106cristy *prev; 61514c08aed51c5899665ade97263692328eea4af106cristy 61524c08aed51c5899665ade97263692328eea4af106cristy png_uint_16 61534c08aed51c5899665ade97263692328eea4af106cristy magn_methx, 61544c08aed51c5899665ade97263692328eea4af106cristy magn_methy; 61554c08aed51c5899665ade97263692328eea4af106cristy 6156bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy ssize_t 61573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy m, 61583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy y; 61593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 61604c08aed51c5899665ade97263692328eea4af106cristy register Quantum 61613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *n, 61623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *q; 61633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 61644c08aed51c5899665ade97263692328eea4af106cristy register ssize_t 61654c08aed51c5899665ade97263692328eea4af106cristy x; 61663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 616747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp /* Allocate next image structure. */ 616847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 61693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 61703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 61713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Allocate magnified image"); 617247b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 61733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy AcquireNextImage(image_info,image); 617447b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 61753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (GetNextImageInList(image) == (Image *) NULL) 61763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 61773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=DestroyImageList(image); 61783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngInfoFreeStruct(mng_info,&have_mng_structure); 61793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return((Image *) NULL); 61803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 61813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 61823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy large_image=SyncNextImageInList(image); 61833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 61843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy large_image->columns=magnified_width; 61853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy large_image->rows=magnified_height; 61863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 61873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_methx=mng_info->magn_methx; 61883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_methy=mng_info->magn_methy; 61893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 61903faa9a3fb01696daaf976d595f492cb530bffb21glennrp#if (MAGICKCORE_QUANTUM_DEPTH > 16) 61913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define QM unsigned short 61923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (magn_methx != 1 || magn_methy != 1) 61933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 61943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 61953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Scale pixels to unsigned shorts to prevent 61963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy overflow of intermediate values of interpolations 61973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 6198bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (y=0; y < (ssize_t) image->rows; y++) 61993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 62003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy q=GetAuthenticPixels(image,0,y,image->columns,1, 62013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy exception); 620247b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 6203bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (x=(ssize_t) image->columns-1; x >= 0; x--) 62043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 62054c08aed51c5899665ade97263692328eea4af106cristy SetPixelRed(image,ScaleQuantumToShort( 62064c08aed51c5899665ade97263692328eea4af106cristy GetPixelRed(image,q)),q); 62074c08aed51c5899665ade97263692328eea4af106cristy SetPixelGreen(image,ScaleQuantumToShort( 62084c08aed51c5899665ade97263692328eea4af106cristy GetPixelGreen(image,q)),q); 62094c08aed51c5899665ade97263692328eea4af106cristy SetPixelBlue(image,ScaleQuantumToShort( 62104c08aed51c5899665ade97263692328eea4af106cristy GetPixelBlue(image,q)),q); 62114c08aed51c5899665ade97263692328eea4af106cristy SetPixelAlpha(image,ScaleQuantumToShort( 62124c08aed51c5899665ade97263692328eea4af106cristy GetPixelAlpha(image,q)),q); 62134c08aed51c5899665ade97263692328eea4af106cristy q+=GetPixelChannels(image); 62143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 621547b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 62163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (SyncAuthenticPixels(image,exception) == MagickFalse) 62173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 62183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 62193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 62203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#else 62213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define QM Quantum 62223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 62233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 62243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->matte != MagickFalse) 62253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) SetImageBackgroundColor(large_image); 622647b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 62273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 62283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 62294c08aed51c5899665ade97263692328eea4af106cristy large_image->background_color.alpha=OpaqueAlpha; 62303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) SetImageBackgroundColor(large_image); 623147b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 62323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (magn_methx == 4) 62333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_methx=2; 623447b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 62353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (magn_methx == 5) 62363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_methx=3; 623747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 62383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (magn_methy == 4) 62393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_methy=2; 624047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 62413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (magn_methy == 5) 62423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy magn_methy=3; 62433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 62443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 62453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* magnify the rows into the right side of the large image */ 62463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 62473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 62483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 6249e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " Magnify the rows to %.20g",(double) large_image->rows); 6250bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy m=(ssize_t) mng_info->magn_mt; 62513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy yy=0; 62523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy length=(size_t) image->columns; 62534c08aed51c5899665ade97263692328eea4af106cristy next=(Quantum *) AcquireQuantumMemory(length,sizeof(*next)); 62544c08aed51c5899665ade97263692328eea4af106cristy prev=(Quantum *) AcquireQuantumMemory(length,sizeof(*prev)); 625547b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 62564c08aed51c5899665ade97263692328eea4af106cristy if ((prev == (Quantum *) NULL) || 62574c08aed51c5899665ade97263692328eea4af106cristy (next == (Quantum *) NULL)) 62583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 62593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=DestroyImageList(image); 62603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngInfoFreeStruct(mng_info,&have_mng_structure); 62613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowReaderException(ResourceLimitError, 62623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy "MemoryAllocationFailed"); 62633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 626447b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 62653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy n=GetAuthenticPixels(image,0,0,image->columns,1,exception); 62663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) CopyMagickMemory(next,n,length); 626747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 6268bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (y=0; y < (ssize_t) image->rows; y++) 62693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 62703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (y == 0) 6271bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy m=(ssize_t) mng_info->magn_mt; 627247b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 6273bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy else if (magn_methy > 1 && y == (ssize_t) image->rows-2) 6274bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy m=(ssize_t) mng_info->magn_mb; 627547b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 6276bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy else if (magn_methy <= 1 && y == (ssize_t) image->rows-1) 6277bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy m=(ssize_t) mng_info->magn_mb; 627847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 6279bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy else if (magn_methy > 1 && y == (ssize_t) image->rows-1) 62803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy m=1; 628147b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 62823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 6283bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy m=(ssize_t) mng_info->magn_my; 628447b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 62853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy n=prev; 62863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy prev=next; 62873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy next=n; 628847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 6289bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy if (y < (ssize_t) image->rows-1) 62903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 62913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy n=GetAuthenticPixels(image,0,y+1,image->columns,1, 62923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy exception); 62933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) CopyMagickMemory(next,n,length); 62943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 629547b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 62963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy for (i=0; i < m; i++, yy++) 62973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 62984c08aed51c5899665ade97263692328eea4af106cristy register Quantum 62993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *pixels; 63003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 6301bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy assert(yy < (ssize_t) large_image->rows); 63023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels=prev; 63033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy n=next; 63043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy q=GetAuthenticPixels(large_image,0,yy,large_image->columns, 63059fff7b4fa7d657da7bfed66239982b85c6337de9cristy 1,exception); 63063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy q+=(large_image->columns-image->columns); 630747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 6308bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (x=(ssize_t) image->columns-1; x >= 0; x--) 63093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 6310fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp /* To do: get color as function of indexes[x] */ 63113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 63123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->storage_class == PseudoClass) 63133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 63143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 63153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 63163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 63173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (magn_methy <= 1) 63183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 6319bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp /* replicate previous */ 63204c08aed51c5899665ade97263692328eea4af106cristy SetPixelRed(large_image,GetPixelRed(image,pixels),q); 6321847370c32c6b67817205f49897c43c540fd670c4glennrp SetPixelGreen(large_image,GetPixelGreen(image, 6322847370c32c6b67817205f49897c43c540fd670c4glennrp pixels),q); 6323847370c32c6b67817205f49897c43c540fd670c4glennrp SetPixelBlue(large_image,GetPixelBlue(image, 6324847370c32c6b67817205f49897c43c540fd670c4glennrp pixels),q); 6325847370c32c6b67817205f49897c43c540fd670c4glennrp SetPixelAlpha(large_image,GetPixelAlpha(image, 6326847370c32c6b67817205f49897c43c540fd670c4glennrp pixels),q); 63273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 632847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 63293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else if (magn_methy == 2 || magn_methy == 4) 63303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 63313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (i == 0) 6332bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp { 6333847370c32c6b67817205f49897c43c540fd670c4glennrp SetPixelRed(large_image,GetPixelRed(image, 6334847370c32c6b67817205f49897c43c540fd670c4glennrp pixels),q); 6335847370c32c6b67817205f49897c43c540fd670c4glennrp SetPixelGreen(large_image,GetPixelGreen(image, 6336847370c32c6b67817205f49897c43c540fd670c4glennrp pixels),q); 6337847370c32c6b67817205f49897c43c540fd670c4glennrp SetPixelBlue(large_image,GetPixelBlue(image, 6338847370c32c6b67817205f49897c43c540fd670c4glennrp pixels),q); 6339847370c32c6b67817205f49897c43c540fd670c4glennrp SetPixelAlpha(large_image,GetPixelAlpha(image, 6340847370c32c6b67817205f49897c43c540fd670c4glennrp pixels),q); 6341bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp } 634247b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 63433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 63443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 63453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Interpolate */ 63464c08aed51c5899665ade97263692328eea4af106cristy SetPixelRed(large_image,((QM) (((ssize_t) 63474c08aed51c5899665ade97263692328eea4af106cristy (2*i*(GetPixelRed(image,n) 63484c08aed51c5899665ade97263692328eea4af106cristy -GetPixelRed(image,pixels)+m))/ 6349bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp ((ssize_t) (m*2)) 63504c08aed51c5899665ade97263692328eea4af106cristy +GetPixelRed(image,pixels)))),q); 63514c08aed51c5899665ade97263692328eea4af106cristy SetPixelGreen(large_image,((QM) (((ssize_t) 63524c08aed51c5899665ade97263692328eea4af106cristy (2*i*(GetPixelGreen(image,n) 63534c08aed51c5899665ade97263692328eea4af106cristy -GetPixelGreen(image,pixels)+m))/ 6354bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp ((ssize_t) (m*2)) 63554c08aed51c5899665ade97263692328eea4af106cristy +GetPixelGreen(image,pixels)))),q); 63564c08aed51c5899665ade97263692328eea4af106cristy SetPixelBlue(large_image,((QM) (((ssize_t) 63574c08aed51c5899665ade97263692328eea4af106cristy (2*i*(GetPixelBlue(image,n) 63584c08aed51c5899665ade97263692328eea4af106cristy -GetPixelBlue(image,pixels)+m))/ 6359bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp ((ssize_t) (m*2)) 63604c08aed51c5899665ade97263692328eea4af106cristy +GetPixelBlue(image,pixels)))),q); 636147b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 63623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->matte != MagickFalse) 63634c08aed51c5899665ade97263692328eea4af106cristy SetPixelAlpha(large_image, ((QM) (((ssize_t) 63644c08aed51c5899665ade97263692328eea4af106cristy (2*i*(GetPixelAlpha(image,n) 63654c08aed51c5899665ade97263692328eea4af106cristy -GetPixelAlpha(image,pixels)+m)) 6366bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp /((ssize_t) (m*2))+ 63674c08aed51c5899665ade97263692328eea4af106cristy GetPixelAlpha(image,pixels)))),q); 63683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 636947b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 63703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (magn_methy == 4) 63713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 63723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Replicate nearest */ 63733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (i <= ((m+1) << 1)) 6374847370c32c6b67817205f49897c43c540fd670c4glennrp SetPixelAlpha(large_image,GetPixelAlpha(image, 6375847370c32c6b67817205f49897c43c540fd670c4glennrp pixels),q); 63763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 6377847370c32c6b67817205f49897c43c540fd670c4glennrp SetPixelAlpha(large_image,GetPixelAlpha(image, 6378847370c32c6b67817205f49897c43c540fd670c4glennrp n),q); 63793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 63803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 638147b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 63823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else /* if (magn_methy == 3 || magn_methy == 5) */ 63833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 63843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Replicate nearest */ 63853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (i <= ((m+1) << 1)) 6386bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp { 6387847370c32c6b67817205f49897c43c540fd670c4glennrp SetPixelRed(large_image,GetPixelRed(image, 6388847370c32c6b67817205f49897c43c540fd670c4glennrp pixels),q); 6389847370c32c6b67817205f49897c43c540fd670c4glennrp SetPixelGreen(large_image,GetPixelGreen(image, 6390847370c32c6b67817205f49897c43c540fd670c4glennrp pixels),q); 6391847370c32c6b67817205f49897c43c540fd670c4glennrp SetPixelBlue(large_image,GetPixelBlue(image, 6392847370c32c6b67817205f49897c43c540fd670c4glennrp pixels),q); 6393847370c32c6b67817205f49897c43c540fd670c4glennrp SetPixelAlpha(large_image,GetPixelAlpha(image, 6394847370c32c6b67817205f49897c43c540fd670c4glennrp pixels),q); 6395bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp } 639647b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 63973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 6398bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp { 63994c08aed51c5899665ade97263692328eea4af106cristy SetPixelRed(large_image,GetPixelRed(image,n),q); 6400847370c32c6b67817205f49897c43c540fd670c4glennrp SetPixelGreen(large_image,GetPixelGreen(image,n), 6401847370c32c6b67817205f49897c43c540fd670c4glennrp q); 6402847370c32c6b67817205f49897c43c540fd670c4glennrp SetPixelBlue(large_image,GetPixelBlue(image,n), 6403847370c32c6b67817205f49897c43c540fd670c4glennrp q); 6404847370c32c6b67817205f49897c43c540fd670c4glennrp SetPixelAlpha(large_image,GetPixelAlpha(image,n), 6405847370c32c6b67817205f49897c43c540fd670c4glennrp q); 6406bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp } 640747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 64083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (magn_methy == 5) 64093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 64104c08aed51c5899665ade97263692328eea4af106cristy SetPixelAlpha(large_image,(QM) (((ssize_t) (2*i* 64114c08aed51c5899665ade97263692328eea4af106cristy (GetPixelAlpha(image,n) 64124c08aed51c5899665ade97263692328eea4af106cristy -GetPixelAlpha(image,pixels)) 6413bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp +m))/((ssize_t) (m*2)) 64144c08aed51c5899665ade97263692328eea4af106cristy +GetPixelAlpha(image,pixels)),q); 64153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 64163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 64174c08aed51c5899665ade97263692328eea4af106cristy n+=GetPixelChannels(image); 64184c08aed51c5899665ade97263692328eea4af106cristy q+=GetPixelChannels(large_image); 64194c08aed51c5899665ade97263692328eea4af106cristy pixels+=GetPixelChannels(image); 64203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } /* x */ 642147b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 64223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (SyncAuthenticPixels(large_image,exception) == 0) 64233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 642447b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 64253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } /* i */ 64263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } /* y */ 642747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 64284c08aed51c5899665ade97263692328eea4af106cristy prev=(Quantum *) RelinquishMagickMemory(prev); 64294c08aed51c5899665ade97263692328eea4af106cristy next=(Quantum *) RelinquishMagickMemory(next); 64303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 64313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy length=image->columns; 64323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 64333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 64343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 64353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Delete original image"); 64363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 64373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy DeleteImageFromList(&image); 64383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 64393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=large_image; 64403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 64413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->image=image; 64423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 64433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* magnify the columns */ 64443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 64453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 6446e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " Magnify the columns to %.20g",(double) image->columns); 64473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 6448bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (y=0; y < (ssize_t) image->rows; y++) 64493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 64504c08aed51c5899665ade97263692328eea4af106cristy register Quantum 64513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *pixels; 64523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 64533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy q=GetAuthenticPixels(image,0,y,image->columns,1,exception); 64544c08aed51c5899665ade97263692328eea4af106cristy pixels=q+(image->columns-length)*GetPixelChannels(image); 64554c08aed51c5899665ade97263692328eea4af106cristy n=pixels+GetPixelChannels(image); 645647b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 6457bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (x=(ssize_t) (image->columns-length); 6458bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy x < (ssize_t) image->columns; x++) 64593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 64607c7b31566a7598be23cac1b5e32c697cfe7082f4glennrp /* To do: Rewrite using Get/Set***PixelComponent() */ 64617c7b31566a7598be23cac1b5e32c697cfe7082f4glennrp 6462bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy if (x == (ssize_t) (image->columns-length)) 6463bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy m=(ssize_t) mng_info->magn_ml; 646447b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 6465bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy else if (magn_methx > 1 && x == (ssize_t) image->columns-2) 6466bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy m=(ssize_t) mng_info->magn_mr; 646747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 6468bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy else if (magn_methx <= 1 && x == (ssize_t) image->columns-1) 6469bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy m=(ssize_t) mng_info->magn_mr; 647047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 6471bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy else if (magn_methx > 1 && x == (ssize_t) image->columns-1) 64723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy m=1; 647347b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 64743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 6475bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy m=(ssize_t) mng_info->magn_mx; 647647b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 64773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy for (i=0; i < m; i++) 64783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 64793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (magn_methx <= 1) 64803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 64813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* replicate previous */ 64824c08aed51c5899665ade97263692328eea4af106cristy SetPixelRed(image,GetPixelRed(image,pixels),q); 64834c08aed51c5899665ade97263692328eea4af106cristy SetPixelGreen(image,GetPixelGreen(image,pixels),q); 64844c08aed51c5899665ade97263692328eea4af106cristy SetPixelBlue(image,GetPixelBlue(image,pixels),q); 64854c08aed51c5899665ade97263692328eea4af106cristy SetPixelAlpha(image,GetPixelAlpha(image,pixels),q); 64863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 648747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 64883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else if (magn_methx == 2 || magn_methx == 4) 64893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 64903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (i == 0) 6491bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp { 64924c08aed51c5899665ade97263692328eea4af106cristy SetPixelRed(image,GetPixelRed(image,pixels),q); 64934c08aed51c5899665ade97263692328eea4af106cristy SetPixelGreen(image,GetPixelGreen(image,pixels),q); 64944c08aed51c5899665ade97263692328eea4af106cristy SetPixelBlue(image,GetPixelBlue(image,pixels),q); 64954c08aed51c5899665ade97263692328eea4af106cristy SetPixelAlpha(image,GetPixelAlpha(image,pixels),q); 6496bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp } 649747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 6498bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp /* To do: Rewrite using Get/Set***PixelComponent() */ 64993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 65003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 65013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Interpolate */ 65024c08aed51c5899665ade97263692328eea4af106cristy SetPixelRed(image,(QM) ((2*i*( 65034c08aed51c5899665ade97263692328eea4af106cristy GetPixelRed(image,n) 65044c08aed51c5899665ade97263692328eea4af106cristy -GetPixelRed(image,pixels))+m) 6505bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp /((ssize_t) (m*2))+ 65064c08aed51c5899665ade97263692328eea4af106cristy GetPixelRed(image,pixels)),q); 6507bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp 65084c08aed51c5899665ade97263692328eea4af106cristy SetPixelGreen(image,(QM) ((2*i*( 65094c08aed51c5899665ade97263692328eea4af106cristy GetPixelGreen(image,n) 65104c08aed51c5899665ade97263692328eea4af106cristy -GetPixelGreen(image,pixels))+m) 6511bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp /((ssize_t) (m*2))+ 65124c08aed51c5899665ade97263692328eea4af106cristy GetPixelGreen(image,pixels)),q); 6513bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp 65144c08aed51c5899665ade97263692328eea4af106cristy SetPixelBlue(image,(QM) ((2*i*( 65154c08aed51c5899665ade97263692328eea4af106cristy GetPixelBlue(image,n) 65164c08aed51c5899665ade97263692328eea4af106cristy -GetPixelBlue(image,pixels))+m) 6517bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp /((ssize_t) (m*2))+ 65184c08aed51c5899665ade97263692328eea4af106cristy GetPixelBlue(image,pixels)),q); 65193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->matte != MagickFalse) 65204c08aed51c5899665ade97263692328eea4af106cristy SetPixelAlpha(image,(QM) ((2*i*( 65214c08aed51c5899665ade97263692328eea4af106cristy GetPixelAlpha(image,n) 65224c08aed51c5899665ade97263692328eea4af106cristy -GetPixelAlpha(image,pixels))+m) 6523bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp /((ssize_t) (m*2))+ 65244c08aed51c5899665ade97263692328eea4af106cristy GetPixelAlpha(image,pixels)),q); 65253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 652647b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 65273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (magn_methx == 4) 65283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 65293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Replicate nearest */ 65303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (i <= ((m+1) << 1)) 6531bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp { 65324c08aed51c5899665ade97263692328eea4af106cristy SetPixelAlpha(image, 65334c08aed51c5899665ade97263692328eea4af106cristy GetPixelAlpha(image,pixels)+0,q); 6534bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp } 65353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 6536bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp { 65374c08aed51c5899665ade97263692328eea4af106cristy SetPixelAlpha(image, 65384c08aed51c5899665ade97263692328eea4af106cristy GetPixelAlpha(image,n)+0,q); 6539bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp } 65403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 65413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 654247b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 65433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else /* if (magn_methx == 3 || magn_methx == 5) */ 65443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 65453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Replicate nearest */ 65463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (i <= ((m+1) << 1)) 6547bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp { 65484c08aed51c5899665ade97263692328eea4af106cristy SetPixelRed(image,GetPixelRed(image,pixels),q); 65494c08aed51c5899665ade97263692328eea4af106cristy SetPixelGreen(image,GetPixelGreen(image,pixels),q); 65504c08aed51c5899665ade97263692328eea4af106cristy SetPixelBlue(image,GetPixelBlue(image,pixels),q); 65514c08aed51c5899665ade97263692328eea4af106cristy SetPixelAlpha(image,GetPixelAlpha(image,pixels),q); 6552bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp } 655347b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 65543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 6555bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp { 65564c08aed51c5899665ade97263692328eea4af106cristy SetPixelRed(image,GetPixelRed(image,n),q); 65574c08aed51c5899665ade97263692328eea4af106cristy SetPixelGreen(image,GetPixelGreen(image,n),q); 65584c08aed51c5899665ade97263692328eea4af106cristy SetPixelBlue(image,GetPixelBlue(image,n),q); 65594c08aed51c5899665ade97263692328eea4af106cristy SetPixelAlpha(image,GetPixelAlpha(image,n),q); 6560bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp } 656147b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 65623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (magn_methx == 5) 65633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 65643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Interpolate */ 65654c08aed51c5899665ade97263692328eea4af106cristy SetPixelAlpha(image, 65664c08aed51c5899665ade97263692328eea4af106cristy (QM) ((2*i*( GetPixelAlpha(image,n) 65674c08aed51c5899665ade97263692328eea4af106cristy -GetPixelAlpha(image,pixels))+m)/ 6568bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp ((ssize_t) (m*2)) 65694c08aed51c5899665ade97263692328eea4af106cristy +GetPixelAlpha(image,pixels)),q); 65703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 65713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 65724c08aed51c5899665ade97263692328eea4af106cristy q+=GetPixelChannels(image); 65733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 65744c08aed51c5899665ade97263692328eea4af106cristy n+=GetPixelChannels(image); 65754c08aed51c5899665ade97263692328eea4af106cristy p+=GetPixelChannels(image); 65763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 657747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 65783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (SyncAuthenticPixels(image,exception) == MagickFalse) 65793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 65803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 65813faa9a3fb01696daaf976d595f492cb530bffb21glennrp#if (MAGICKCORE_QUANTUM_DEPTH > 16) 65823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (magn_methx != 1 || magn_methy != 1) 65833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 65843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 65853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Rescale pixels to Quantum 65863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 6587bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (y=0; y < (ssize_t) image->rows; y++) 65883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 65893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy q=GetAuthenticPixels(image,0,y,image->columns,1,exception); 659047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 6591bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (x=(ssize_t) image->columns-1; x >= 0; x--) 65923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 65934c08aed51c5899665ade97263692328eea4af106cristy SetPixelRed(image,ScaleShortToQuantum( 65944c08aed51c5899665ade97263692328eea4af106cristy GetPixelRed(image,q)),q); 65954c08aed51c5899665ade97263692328eea4af106cristy SetPixelGreen(image,ScaleShortToQuantum( 65964c08aed51c5899665ade97263692328eea4af106cristy GetPixelGreen(image,q)),q); 65974c08aed51c5899665ade97263692328eea4af106cristy SetPixelBlue(image,ScaleShortToQuantum( 65984c08aed51c5899665ade97263692328eea4af106cristy GetPixelBlue(image,q)),q); 65994c08aed51c5899665ade97263692328eea4af106cristy SetPixelAlpha(image,ScaleShortToQuantum( 66004c08aed51c5899665ade97263692328eea4af106cristy GetPixelAlpha(image,q)),q); 66014c08aed51c5899665ade97263692328eea4af106cristy q+=GetPixelChannels(image); 66023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 660347b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 66043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (SyncAuthenticPixels(image,exception) == MagickFalse) 66053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 66063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 66073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 66083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 66093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 66103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 66113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Finished MAGN processing"); 66123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 66133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 66143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 66153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 66163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Crop_box is with respect to the upper left corner of the MNG. 66173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 66183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy crop_box.left=mng_info->image_box.left+mng_info->x_off[object_id]; 66193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy crop_box.right=mng_info->image_box.right+mng_info->x_off[object_id]; 66203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy crop_box.top=mng_info->image_box.top+mng_info->y_off[object_id]; 66213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy crop_box.bottom=mng_info->image_box.bottom+mng_info->y_off[object_id]; 66223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy crop_box=mng_minimum_box(crop_box,mng_info->clip); 66233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy crop_box=mng_minimum_box(crop_box,mng_info->frame); 66243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy crop_box=mng_minimum_box(crop_box,mng_info->object_clip[object_id]); 66253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((crop_box.left != (mng_info->image_box.left 66263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy +mng_info->x_off[object_id])) || 66273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (crop_box.right != (mng_info->image_box.right 66283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy +mng_info->x_off[object_id])) || 66293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (crop_box.top != (mng_info->image_box.top 66303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy +mng_info->y_off[object_id])) || 66313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (crop_box.bottom != (mng_info->image_box.bottom 66323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy +mng_info->y_off[object_id]))) 66333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 66343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 66353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 66363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Crop the PNG image"); 663747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 66383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((crop_box.left < crop_box.right) && 66393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (crop_box.top < crop_box.bottom)) 66403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 66413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Image 66423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *im; 66433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 66443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy RectangleInfo 66453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy crop_info; 66463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 66473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 66483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Crop_info is with respect to the upper left corner of 66493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy the image. 66503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 66513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy crop_info.x=(crop_box.left-mng_info->x_off[object_id]); 66523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy crop_info.y=(crop_box.top-mng_info->y_off[object_id]); 6653bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy crop_info.width=(size_t) (crop_box.right-crop_box.left); 6654bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy crop_info.height=(size_t) (crop_box.bottom-crop_box.top); 66553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->page.width=image->columns; 66563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->page.height=image->rows; 66573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->page.x=0; 66583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->page.y=0; 66593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy im=CropImage(image,&crop_info,exception); 666047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 66613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (im != (Image *) NULL) 66623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 66633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->columns=im->columns; 66643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->rows=im->rows; 66653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy im=DestroyImage(im); 66663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->page.width=image->columns; 66673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->page.height=image->rows; 66683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->page.x=crop_box.left; 66693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->page.y=crop_box.top; 66703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 66713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 667247b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 66733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 66743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 66753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 66763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy No pixels in crop area. The MNG spec still requires 66773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy a layer, though, so make a single transparent pixel in 66783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy the top left corner. 66793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 66803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->columns=1; 66813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->rows=1; 66823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->colors=2; 66833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) SetImageBackgroundColor(image); 66843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->page.width=1; 66853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->page.height=1; 66863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->page.x=0; 66873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->page.y=0; 66883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 66893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 66903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#ifndef PNG_READ_EMPTY_PLTE_SUPPORTED 66913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=mng_info->image; 66923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 66933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 66943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 66952b013e4b9b602533eff410e61c3683fb2a3ab913glennrp#if (MAGICKCORE_QUANTUM_DEPTH > 16) 66962b013e4b9b602533eff410e61c3683fb2a3ab913glennrp /* PNG does not handle depths greater than 16 so reduce it even 66972b013e4b9b602533eff410e61c3683fb2a3ab913glennrp * if lossy 66982b013e4b9b602533eff410e61c3683fb2a3ab913glennrp */ 66992b013e4b9b602533eff410e61c3683fb2a3ab913glennrp if (image->depth > 16) 67002b013e4b9b602533eff410e61c3683fb2a3ab913glennrp image->depth=16; 67012b013e4b9b602533eff410e61c3683fb2a3ab913glennrp#endif 67022b013e4b9b602533eff410e61c3683fb2a3ab913glennrp 67033faa9a3fb01696daaf976d595f492cb530bffb21glennrp#if (MAGICKCORE_QUANTUM_DEPTH > 8) 67048640fb5e9b1094f35f8beab436f81661b8a99448glennrp if (LosslessReduceDepthOK(image) != MagickFalse) 67058640fb5e9b1094f35f8beab436f81661b8a99448glennrp image->depth = 8; 67063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 6707d6afd54fac7c96376ea623fb7ab6c3e398cb7064glennrp 67083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy GetImageException(image,exception); 670947b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 67103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image_info->number_scenes != 0) 67113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 67123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->scenes_found > 6713bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy (ssize_t) (image_info->first_scene+image_info->number_scenes)) 67143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 67153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 6716d6afd54fac7c96376ea623fb7ab6c3e398cb7064glennrp 67173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 67183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 67193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Finished reading image datastream."); 6720d6afd54fac7c96376ea623fb7ab6c3e398cb7064glennrp 67213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } while (LocaleCompare(image_info->magick,"MNG") == 0); 672247b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 67233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) CloseBlob(image); 672447b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 67253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 67263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 67273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Finished reading all image datastreams."); 672847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 67293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MNG_INSERT_LAYERS) 67303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (insert_layers && !mng_info->image_found && (mng_info->mng_width) && 67313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (mng_info->mng_height)) 67323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 67333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 67343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Insert a background layer if nothing else was found. 67353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 67363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 67373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 67383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " No images found. Inserting a background layer."); 67390fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 67404c08aed51c5899665ade97263692328eea4af106cristy if (GetAuthenticPixelQueue(image) != (Quantum *) NULL) 67413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 67423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 67433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Allocate next image structure. 67443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 67453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy AcquireNextImage(image_info,image); 67463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (GetNextImageInList(image) == (Image *) NULL) 67473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 67483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=DestroyImageList(image); 67493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngInfoFreeStruct(mng_info,&have_mng_structure); 675047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 67513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 67523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 67533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Allocation failed, returning NULL."); 675447b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 67553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return((Image *) NULL); 67563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 67573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=SyncNextImageInList(image); 67583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 67593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->columns=mng_info->mng_width; 67603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->rows=mng_info->mng_height; 67613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->page.width=mng_info->mng_width; 67623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->page.height=mng_info->mng_height; 67633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->page.x=0; 67643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->page.y=0; 67653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->background_color=mng_background_color; 67663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->matte=MagickFalse; 67670fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 67683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image_info->ping == MagickFalse) 67693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) SetImageBackgroundColor(image); 67700fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 67713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->image_found++; 67723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 67733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 67743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->iterations=mng_iterations; 67750fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 67763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_iterations == 1) 67773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->start_loop=MagickTrue; 67780fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 67793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy while (GetPreviousImageInList(image) != (Image *) NULL) 67803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 67813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image_count++; 67823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image_count > 10*mng_info->image_found) 67833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 67843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 67853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule()," No beginning"); 678647b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 67873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ThrowMagickException(&image->exception,GetMagickModule(), 67883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy CoderError,"Linked list is corrupted, beginning of list not found", 67893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy "`%s'",image_info->filename); 679047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 67913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return((Image *) NULL); 67923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 67930fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 67943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=GetPreviousImageInList(image); 67950fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 67963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (GetNextImageInList(image) == (Image *) NULL) 67973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 67983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 67993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule()," Corrupt list"); 680047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 68013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ThrowMagickException(&image->exception,GetMagickModule(), 68023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy CoderError,"Linked list is corrupted; next_image is NULL","`%s'", 68033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image_info->filename); 68043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 68053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 680647b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 68073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->ticks_per_second && mng_info->image_found > 1 && 68083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy GetNextImageInList(image) == 68093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (Image *) NULL) 68103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 68113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 68123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 68133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " First image null"); 681447b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 68153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ThrowMagickException(&image->exception,GetMagickModule(), 68163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy CoderError,"image->next for first image is NULL but shouldn't be.", 68173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy "`%s'",image_info->filename); 68183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 681947b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 68203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->image_found == 0) 68213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 68223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 68233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 68243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " No visible images found."); 682547b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 68263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ThrowMagickException(&image->exception,GetMagickModule(), 68273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy CoderError,"No visible images in file","`%s'",image_info->filename); 682847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 68293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image != (Image *) NULL) 68303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=DestroyImageList(image); 683147b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 68323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngInfoFreeStruct(mng_info,&have_mng_structure); 68333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return((Image *) NULL); 68343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 68353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 68363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->ticks_per_second) 68373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy final_delay=1UL*MagickMax(image->ticks_per_second,1L)* 68383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy final_delay/mng_info->ticks_per_second; 68390fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 68403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 68413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->start_loop=MagickTrue; 68420fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 68433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Find final nonzero image delay */ 68443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy final_image_delay=0; 68450fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 68463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy while (GetNextImageInList(image) != (Image *) NULL) 68473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 68483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->delay) 68493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy final_image_delay=image->delay; 685047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 68513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=GetNextImageInList(image); 68523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 68530fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 68543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (final_delay < final_image_delay) 68553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy final_delay=final_image_delay; 68560fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 68573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->delay=final_delay; 68580fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 68593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 68603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 6861e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " image->delay=%.20g, final_delay=%.20g",(double) image->delay, 6862e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy (double) final_delay); 68630fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 68643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 68653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 68663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy int 68673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy scene; 68683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 68693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy scene=0; 68703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=GetFirstImageInList(image); 687147b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 68723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 68733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Before coalesce:"); 687447b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 68753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 6876e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " scene 0 delay=%.20g",(double) image->delay); 687747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 68783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy while (GetNextImageInList(image) != (Image *) NULL) 68793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 68803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=GetNextImageInList(image); 68813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 6882e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " scene %.20g delay=%.20g",(double) scene++,(double) image->delay); 68833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 68843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 68853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 68863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=GetFirstImageInList(image); 68873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#ifdef MNG_COALESCE_LAYERS 68883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (insert_layers) 68893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 68903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Image 68913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *next_image, 68923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *next; 68933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 6894bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy size_t 68953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy scene; 68963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 68973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 68983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule()," Coalesce Images"); 689947b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 69003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy scene=image->scene; 69013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy next_image=CoalesceImages(image,&image->exception); 690247b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 69033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (next_image == (Image *) NULL) 69043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); 690547b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 69063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=DestroyImageList(image); 69073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=next_image; 690847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 69093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy for (next=image; next != (Image *) NULL; next=next_image) 69103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 69113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy next->page.width=mng_info->mng_width; 69123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy next->page.height=mng_info->mng_height; 69133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy next->page.x=0; 69143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy next->page.y=0; 69153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy next->scene=scene++; 69163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy next_image=GetNextImageInList(next); 691747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 69183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (next_image == (Image *) NULL) 69193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 692047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 69213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (next->delay == 0) 69223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 69233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy scene--; 69243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy next_image->previous=GetPreviousImageInList(next); 69253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (GetPreviousImageInList(next) == (Image *) NULL) 69263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=next_image; 69273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 69283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy next->previous->next=next_image; 69293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy next=DestroyImage(next); 69303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 69313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 69323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 69333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 69343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 69353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy while (GetNextImageInList(image) != (Image *) NULL) 69363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=GetNextImageInList(image); 693747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 69383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->dispose=BackgroundDispose; 69393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 69403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 69413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 69423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy int 69433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy scene; 69443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 69453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy scene=0; 69463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=GetFirstImageInList(image); 694747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 69483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 69493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " After coalesce:"); 695047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 69513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 6952e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " scene 0 delay=%.20g dispose=%.20g",(double) image->delay, 6953e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy (double) image->dispose); 695447b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 69553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy while (GetNextImageInList(image) != (Image *) NULL) 6956f2faecf9facdbbb14fcba373365f9f691a9658e0cristy { 6957f2faecf9facdbbb14fcba373365f9f691a9658e0cristy image=GetNextImageInList(image); 695847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 6959f2faecf9facdbbb14fcba373365f9f691a9658e0cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 6960e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " scene %.20g delay=%.20g dispose=%.20g",(double) scene++, 6961e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy (double) image->delay,(double) image->dispose); 6962f2faecf9facdbbb14fcba373365f9f691a9658e0cristy } 6963f2faecf9facdbbb14fcba373365f9f691a9658e0cristy } 696447b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 69653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=GetFirstImageInList(image); 69663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngInfoFreeStruct(mng_info,&have_mng_structure); 69673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy have_mng_structure=MagickFalse; 696847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 69693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 69703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(),"exit ReadMNGImage()"); 697147b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 69723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(GetFirstImageInList(image)); 69733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 697425c1e2baba76d9cf3ec582f217f96af95259e747glennrp#else /* PNG_LIBPNG_VER > 10011 */ 69753ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic Image *ReadPNGImage(const ImageInfo *image_info,ExceptionInfo *exception) 69763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 69773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy printf("Your PNG library is too old: You have libpng-%s\n", 69783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNG_LIBPNG_VER_STRING); 697947b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 69803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ThrowMagickException(exception,GetMagickModule(),CoderError, 69813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy "PNG library is too old","`%s'",image_info->filename); 698247b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 69833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(Image *) NULL; 69843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 698547b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 69863ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic Image *ReadMNGImage(const ImageInfo *image_info,ExceptionInfo *exception) 69873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 69883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(ReadPNGImage(image_info,exception)); 69893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 699025c1e2baba76d9cf3ec582f217f96af95259e747glennrp#endif /* PNG_LIBPNG_VER > 10011 */ 69913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 69923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 69933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 69943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 69953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 69963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 69973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 69983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% R e g i s t e r P N G I m a g e % 69993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 70003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 70013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 70023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 70033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 70043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% RegisterPNGImage() adds properties for the PNG image format to 70053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% the list of supported formats. The properties include the image format 70063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% tag, a method to read and/or write the format, whether the format 70073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% supports the saving of more than one frame to the same file or blob, 70083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% whether the format supports native in-memory I/O, and a brief 70093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% description of the format. 70103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 70113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% The format of the RegisterPNGImage method is: 70123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 7013bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy% size_t RegisterPNGImage(void) 70143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 70153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 7016bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristyModuleExport size_t RegisterPNGImage(void) 70173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 70183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy char 70193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy version[MaxTextExtent]; 70203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 70213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MagickInfo 70223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *entry; 70233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 70243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy static const char 70253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *PNGNote= 70263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 70273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy "See http://www.libpng.org/ for details about the PNG format." 70283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy }, 702947b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 70303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *JNGNote= 70313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 70323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy "See http://www.libpng.org/pub/mng/ for details about the JNG\n" 70333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy "format." 70343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy }, 703547b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 70363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *MNGNote= 70373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 70383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy "See http://www.libpng.org/pub/mng/ for details about the MNG\n" 70393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy "format." 70403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy }; 70413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 70423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *version='\0'; 704347b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 70443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(PNG_LIBPNG_VER_STRING) 70453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ConcatenateMagickString(version,"libpng ",MaxTextExtent); 70463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ConcatenateMagickString(version,PNG_LIBPNG_VER_STRING,MaxTextExtent); 704747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 70483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (LocaleCompare(PNG_LIBPNG_VER_STRING,png_get_header_ver(NULL)) != 0) 70493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 70503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ConcatenateMagickString(version,",",MaxTextExtent); 70513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ConcatenateMagickString(version,png_get_libpng_ver(NULL), 70523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MaxTextExtent); 70533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 70543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 705547b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 70563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry=SetMagickInfo("MNG"); 70573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->seekable_stream=MagickTrue; /* To do: eliminate this. */ 705847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 70593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_PNG_DELEGATE) 70603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->decoder=(DecodeImageHandler *) ReadMNGImage; 70613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->encoder=(EncodeImageHandler *) WriteMNGImage; 70623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 706347b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 70643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->magick=(IsImageFormatHandler *) IsMNG; 70653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->description=ConstantString("Multiple-image Network Graphics"); 706647b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 70673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (*version != '\0') 70683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->version=ConstantString(version); 706947b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 70703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->module=ConstantString("PNG"); 70713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->note=ConstantString(MNGNote); 70723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) RegisterMagickInfo(entry); 70733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 70743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry=SetMagickInfo("PNG"); 707547b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 70763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_PNG_DELEGATE) 70773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->decoder=(DecodeImageHandler *) ReadPNGImage; 70783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->encoder=(EncodeImageHandler *) WritePNGImage; 70793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 708047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 70813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->magick=(IsImageFormatHandler *) IsPNG; 70823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->adjoin=MagickFalse; 70833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->description=ConstantString("Portable Network Graphics"); 70843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->module=ConstantString("PNG"); 708547b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 70863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (*version != '\0') 70873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->version=ConstantString(version); 708847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 70893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->note=ConstantString(PNGNote); 70903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) RegisterMagickInfo(entry); 70913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 70923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry=SetMagickInfo("PNG8"); 709347b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 70943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_PNG_DELEGATE) 70953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->decoder=(DecodeImageHandler *) ReadPNGImage; 70963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->encoder=(EncodeImageHandler *) WritePNGImage; 70973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 709847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 70993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->magick=(IsImageFormatHandler *) IsPNG; 71003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->adjoin=MagickFalse; 71013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->description=ConstantString( 71023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy "8-bit indexed with optional binary transparency"); 71033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->module=ConstantString("PNG"); 71043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) RegisterMagickInfo(entry); 71053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 71063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry=SetMagickInfo("PNG24"); 71073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *version='\0'; 710847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 71093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(ZLIB_VERSION) 71103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ConcatenateMagickString(version,"zlib ",MaxTextExtent); 71113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ConcatenateMagickString(version,ZLIB_VERSION,MaxTextExtent); 711247b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 71133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (LocaleCompare(ZLIB_VERSION,zlib_version) != 0) 71143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 71153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ConcatenateMagickString(version,",",MaxTextExtent); 71163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ConcatenateMagickString(version,zlib_version,MaxTextExtent); 71173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 71183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 711947b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 71203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (*version != '\0') 71213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->version=ConstantString(version); 712247b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 71233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_PNG_DELEGATE) 71243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->decoder=(DecodeImageHandler *) ReadPNGImage; 71253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->encoder=(EncodeImageHandler *) WritePNGImage; 71263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 712747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 71283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->magick=(IsImageFormatHandler *) IsPNG; 71293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->adjoin=MagickFalse; 71303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->description=ConstantString("opaque 24-bit RGB"); 71313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->module=ConstantString("PNG"); 71323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) RegisterMagickInfo(entry); 71333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 71343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry=SetMagickInfo("PNG32"); 713547b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 71363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_PNG_DELEGATE) 71373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->decoder=(DecodeImageHandler *) ReadPNGImage; 71383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->encoder=(EncodeImageHandler *) WritePNGImage; 71393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 714047b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 71413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->magick=(IsImageFormatHandler *) IsPNG; 71423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->adjoin=MagickFalse; 71433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->description=ConstantString("opaque or transparent 32-bit RGBA"); 71443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->module=ConstantString("PNG"); 71453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) RegisterMagickInfo(entry); 71463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 71473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry=SetMagickInfo("JNG"); 714847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 71493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(JNG_SUPPORTED) 71503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_PNG_DELEGATE) 71513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->decoder=(DecodeImageHandler *) ReadJNGImage; 71523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->encoder=(EncodeImageHandler *) WriteJNGImage; 71533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 71543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 715547b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 71563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->magick=(IsImageFormatHandler *) IsJNG; 71573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->adjoin=MagickFalse; 71583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->description=ConstantString("JPEG Network Graphics"); 71593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->module=ConstantString("PNG"); 71603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy entry->note=ConstantString(JNGNote); 71613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) RegisterMagickInfo(entry); 716247b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 716318b17443128598500357da7bff2f01683cf32890cristy#if defined(PNG_SETJMP_NOT_THREAD_SAFE) 7164cf002022280cc4dedb2748ad6f415aac1d44f530glennrp ping_semaphore=AllocateSemaphoreInfo(); 716518b17443128598500357da7bff2f01683cf32890cristy#endif 716647b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 71673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(MagickImageCoderSignature); 71683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 71693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 71703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 71713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 71723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 71733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 71743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 71753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% U n r e g i s t e r P N G I m a g e % 71763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 71773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 71783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 71793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 71803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 71813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% UnregisterPNGImage() removes format registrations made by the 71823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% PNG module from the list of supported formats. 71833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 71843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% The format of the UnregisterPNGImage method is: 71853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 71863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% UnregisterPNGImage(void) 71873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 71883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 71893ed852eea50f9d4cd633efb8c2b054b8e33c253cristyModuleExport void UnregisterPNGImage(void) 71903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 71913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) UnregisterMagickInfo("MNG"); 71923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) UnregisterMagickInfo("PNG"); 71933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) UnregisterMagickInfo("PNG8"); 71943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) UnregisterMagickInfo("PNG24"); 71953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) UnregisterMagickInfo("PNG32"); 71963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) UnregisterMagickInfo("JNG"); 719747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 71983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(PNG_SETJMP_NOT_THREAD_SAFE) 7199cf002022280cc4dedb2748ad6f415aac1d44f530glennrp if (ping_semaphore != (SemaphoreInfo *) NULL) 7200cf002022280cc4dedb2748ad6f415aac1d44f530glennrp DestroySemaphoreInfo(&ping_semaphore); 72013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 72023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 72033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 72043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_PNG_DELEGATE) 720525c1e2baba76d9cf3ec582f217f96af95259e747glennrp#if PNG_LIBPNG_VER > 10011 72063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 72073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 72083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 72093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 72103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 72113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% W r i t e M N G I m a g e % 72123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 72133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 72143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 72153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 72163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 72173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% WriteMNGImage() writes an image in the Portable Network Graphics 72183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Group's "Multiple-image Network Graphics" encoded image format. 72193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 72203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% MNG support written by Glenn Randers-Pehrson, glennrp@image... 72213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 72223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% The format of the WriteMNGImage method is: 72233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 72243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% MagickBooleanType WriteMNGImage(const ImageInfo *image_info,Image *image) 72253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 72263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% A description of each parameter follows. 72273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 72283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o image_info: the image info. 72293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 72303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o image: The image. 72313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 72323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 72333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% To do (as of version 5.5.2, November 26, 2002 -- glennrp -- see also 72343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% "To do" under ReadPNGImage): 72353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 72363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Preserve all unknown and not-yet-handled known chunks found in input 72373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% PNG file and copy them into output PNG files according to the PNG 72383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% copying rules. 72393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 72403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Write the iCCP chunk at MNG level when (icc profile length > 0) 72413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 72423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Improve selection of color type (use indexed-colour or indexed-colour 72433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% with tRNS when 256 or fewer unique RGBA values are present). 72443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 72453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Figure out what to do with "dispose=<restore-to-previous>" (dispose == 3) 72463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% This will be complicated if we limit ourselves to generating MNG-LC 72473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% files. For now we ignore disposal method 3 and simply overlay the next 72483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% image on it. 72493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 72503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Check for identical PLTE's or PLTE/tRNS combinations and use a 72513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% global MNG PLTE or PLTE/tRNS combination when appropriate. 72523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% [mostly done 15 June 1999 but still need to take care of tRNS] 72533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 72543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Check for identical sRGB and replace with a global sRGB (and remove 72553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% gAMA/cHRM if sRGB is found; check for identical gAMA/cHRM and 72563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% replace with global gAMA/cHRM (or with sRGB if appropriate; replace 72573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% local gAMA/cHRM with local sRGB if appropriate). 72583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 72593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Check for identical sBIT chunks and write global ones. 72603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 72613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Provide option to skip writing the signature tEXt chunks. 72623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 72633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Use signatures to detect identical objects and reuse the first 72643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% instance of such objects instead of writing duplicate objects. 72653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 72663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Use a smaller-than-32k value of compression window size when 72673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% appropriate. 72683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 72693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Encode JNG datastreams. Mostly done as of 5.5.2; need to write 72703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% ancillary text chunks and save profiles. 72713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 72723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Provide an option to force LC files (to ensure exact framing rate) 72733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% instead of VLC. 72743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 72753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Provide an option to force VLC files instead of LC, even when offsets 72763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% are present. This will involve expanding the embedded images with a 72773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% transparent region at the top and/or left. 72783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 72793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 72803ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic void 7281cf002022280cc4dedb2748ad6f415aac1d44f530glennrpMagick_png_write_raw_profile(const ImageInfo *image_info,png_struct *ping, 72823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_info *ping_info, unsigned char *profile_type, unsigned char 72833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *profile_description, unsigned char *profile_data, png_uint_32 length) 72843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 72853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_textp 72863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy text; 72873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 7288bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy register ssize_t 72893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy i; 72903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 72913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy unsigned char 72923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *sp; 72933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 72943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_charp 72953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy dp; 72963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 72973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_uint_32 72983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy allocated_length, 72993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy description_length; 73003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 73013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy unsigned char 73023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy hex[16]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'}; 73033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 73043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (LocaleNCompare((char *) profile_type+1, "ng-chunk-",9) == 0) 73053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return; 73063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 73073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image_info->verbose) 73083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 73090fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp (void) printf("writing raw profile: type=%s, length=%.20g\n", 73100fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp (char *) profile_type, (double) length); 73113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 73120fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 73133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy text=(png_textp) png_malloc(ping,(png_uint_32) sizeof(png_text)); 73143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy description_length=(png_uint_32) strlen((const char *) profile_description); 73153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy allocated_length=(png_uint_32) (length*2 + (length >> 5) + 20 73163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy + description_length); 73173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy text[0].text=(png_charp) png_malloc(ping,allocated_length); 73183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy text[0].key=(png_charp) png_malloc(ping, (png_uint_32) 80); 73193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy text[0].key[0]='\0'; 73203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ConcatenateMagickString(text[0].key, 73213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy "Raw profile type ",MaxTextExtent); 73223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ConcatenateMagickString(text[0].key,(const char *) profile_type,62); 73233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy sp=profile_data; 73243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy dp=text[0].text; 73253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *dp++='\n'; 73263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) CopyMagickString(dp,(const char *) profile_description, 73273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy allocated_length); 73283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy dp+=description_length; 73293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *dp++='\n'; 73303b6fd2ec2d9f69f9404445dba0aff5bac02e685ccristy (void) FormatLocaleString(dp,allocated_length- 7331f2faecf9facdbbb14fcba373365f9f691a9658e0cristy (png_size_t) (dp-text[0].text),"%8lu ",(unsigned long) length); 73323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy dp+=8; 733347b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 7334bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (i=0; i < (ssize_t) length; i++) 73353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 73363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (i%36 == 0) 73373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *dp++='\n'; 73383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *(dp++)=(char) hex[((*sp >> 4) & 0x0f)]; 73393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *(dp++)=(char) hex[((*sp++ ) & 0x0f)]; 73403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 734147b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 73423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *dp++='\n'; 73433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *dp='\0'; 73443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy text[0].text_length=(png_size_t) (dp-text[0].text); 73453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy text[0].compression=image_info->compression == NoCompression || 73463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (image_info->compression == UndefinedCompression && 73473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy text[0].text_length < 128) ? -1 : 0; 734847b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 73493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (text[0].text_length <= allocated_length) 73503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_set_text(ping,ping_info,text,1); 735147b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 73523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_free(ping,text[0].text); 73533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_free(ping,text[0].key); 73543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_free(ping,text); 73553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 73563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 7357cf002022280cc4dedb2748ad6f415aac1d44f530glennrpstatic MagickBooleanType Magick_png_write_chunk_from_profile(Image *image, 73584383ec8c3c8811128f5a8a034d67c47db5e7e75acristy const char *string, MagickBooleanType logging) 73593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 73603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy char 73613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *name; 73623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 73633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy const StringInfo 73643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *profile; 73653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 73663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy unsigned char 73673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *data; 73683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 73693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_uint_32 length; 73703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 73713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ResetImageProfileIterator(image); 737247b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 737347b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp for (name=GetNextImageProfile(image); name != (const char *) NULL; ) 737447b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp { 73753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy profile=GetImageProfile(image,name); 737647b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 73773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (profile != (const StringInfo *) NULL) 73783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 73793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy StringInfo 7380cf002022280cc4dedb2748ad6f415aac1d44f530glennrp *ping_profile; 73813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 738247b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp if (LocaleNCompare(name,string,11) == 0) 738347b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp { 738447b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp if (logging != MagickFalse) 738547b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 738647b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp " Found %s profile",name); 738747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 7388cf002022280cc4dedb2748ad6f415aac1d44f530glennrp ping_profile=CloneStringInfo(profile); 7389cf002022280cc4dedb2748ad6f415aac1d44f530glennrp data=GetStringInfoDatum(ping_profile), 7390cf002022280cc4dedb2748ad6f415aac1d44f530glennrp length=(png_uint_32) GetStringInfoLength(ping_profile); 739147b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp data[4]=data[3]; 739247b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp data[3]=data[2]; 739347b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp data[2]=data[1]; 739447b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp data[1]=data[0]; 739547b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp (void) WriteBlobMSBULong(image,length-5); /* data length */ 739647b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp (void) WriteBlob(image,length-1,data+1); 739747b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp (void) WriteBlobMSBULong(image,crc32(0,data+1,(uInt) length-1)); 7398cf002022280cc4dedb2748ad6f415aac1d44f530glennrp ping_profile=DestroyStringInfo(ping_profile); 739947b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp } 74003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 740147b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 74023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy name=GetNextImageProfile(image); 74033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 740447b9dd5e18d5870d82f2a28c6160b32917916ad7glennrp 74053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(MagickTrue); 74063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 74073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 7408b9cfe27bef51dbbd1f05aef89c767749d7e37864glennrp 7409b9cfe27bef51dbbd1f05aef89c767749d7e37864glennrp/* Write one PNG image */ 74103ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic MagickBooleanType WriteOnePNGImage(MngInfo *mng_info, 7411b9cfe27bef51dbbd1f05aef89c767749d7e37864glennrp const ImageInfo *IMimage_info,Image *IMimage) 74123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 7413b9cfe27bef51dbbd1f05aef89c767749d7e37864glennrp Image 7414b9cfe27bef51dbbd1f05aef89c767749d7e37864glennrp *image; 7415b9cfe27bef51dbbd1f05aef89c767749d7e37864glennrp 7416b9cfe27bef51dbbd1f05aef89c767749d7e37864glennrp ImageInfo 7417b9cfe27bef51dbbd1f05aef89c767749d7e37864glennrp *image_info; 7418b9cfe27bef51dbbd1f05aef89c767749d7e37864glennrp 74193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy char 74203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy s[2]; 74213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 74223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy const char 74233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *name, 74243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *property, 74253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *value; 74263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 74273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy const StringInfo 74283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *profile; 74293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 74303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy int 74313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy num_passes, 7432cecd5765c41f64cc68d4a5d77bb4afe92707a49eglennrp pass; 7433cecd5765c41f64cc68d4a5d77bb4afe92707a49eglennrp 7434e9c26dc68fb7cff87adcf2677968737acc9d3d2cglennrp png_byte 7435e9c26dc68fb7cff87adcf2677968737acc9d3d2cglennrp ping_trans_alpha[256]; 74365af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp 743739992b4dd9b12ef752d55b8e402c069698851f72glennrp png_color 743839992b4dd9b12ef752d55b8e402c069698851f72glennrp palette[257]; 74393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 74405af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp png_color_16 74415af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_background, 74425af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_trans_color; 74435af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp 74443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_info 74453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *ping_info; 74463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 74473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_struct 74483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *ping; 74493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 74505af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp png_uint_32 74515af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_height, 74525af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_width; 74535af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp 7454bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy ssize_t 74553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy y; 74563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 74573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MagickBooleanType 745858e017631f66141a6e36ddbe03a54f6e3ee3a253glennrp image_matte, 745921f0e6211a440c0f96134ea25a1bfe7c5f91c29cglennrp logging, 746058e017631f66141a6e36ddbe03a54f6e3ee3a253glennrp matte, 746158e017631f66141a6e36ddbe03a54f6e3ee3a253glennrp 7462da8f3a7bfddac2680a3069a490db541e7944edafglennrp ping_have_blob, 7463fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp ping_have_cheap_transparency, 7464d6bf1617e99df0272b231855a933a74e99b6578fglennrp ping_have_color, 74658d579660c9b96b7a3f3292fc6c518f8b6ca44d50glennrp ping_have_non_bw, 746639992b4dd9b12ef752d55b8e402c069698851f72glennrp ping_have_PLTE, 7467991d11dd9c33e65872778b81aff1347cd2878154glennrp ping_have_bKGD, 7468991d11dd9c33e65872778b81aff1347cd2878154glennrp ping_have_pHYs, 7469991d11dd9c33e65872778b81aff1347cd2878154glennrp ping_have_tRNS, 747026f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp 747126f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp ping_exclude_bKGD, 747226f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp ping_exclude_cHRM, 7473a0ed009a1e9480ac6f3f4520e9ef29d6d37e27dcglennrp ping_exclude_date, 7474e4e2d7916fb10ae2957bc36639b56fa303fd4a0eglennrp /* ping_exclude_EXIF, */ 747526f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp ping_exclude_gAMA, 747626f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp ping_exclude_iCCP, 747726f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp /* ping_exclude_iTXt, */ 747826f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp ping_exclude_oFFs, 747926f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp ping_exclude_pHYs, 748026f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp ping_exclude_sRGB, 748126f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp ping_exclude_tEXt, 7482e4e2d7916fb10ae2957bc36639b56fa303fd4a0eglennrp /* ping_exclude_tRNS, */ 748326f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp ping_exclude_vpAg, 748426f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp ping_exclude_zCCP, /* hex-encoded iCCP */ 748526f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp ping_exclude_zTXt, 748626f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp 74878d3d6e584829223ac5f6e6653c3caa38a2562a74glennrp ping_preserve_colormap, 74880e8ea19baa0666ccfe869d19116372f60fe9230fglennrp ping_need_colortype_warning, 74890e8ea19baa0666ccfe869d19116372f60fe9230fglennrp 749082b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp status, 74918ca51ad2da164dabc55b192ed7884b745fde0e26glennrp tried_332, 7492d337164012450d70d62e71cf4a308a29004f7d57glennrp tried_333, 7493d337164012450d70d62e71cf4a308a29004f7d57glennrp tried_444; 74943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 74953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy QuantumInfo 74963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *quantum_info; 74973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 7498bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy register ssize_t 74993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy i, 75003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy x; 75013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 75023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy unsigned char 7503cf002022280cc4dedb2748ad6f415aac1d44f530glennrp *ping_pixels; 75043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 75055af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp volatile int 7506f09bdedccf9ca10bc002a946227df3367cb58d14glennrp image_colors, 75070fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp ping_bit_depth, 75085af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_color_type, 75095af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_interlace_method, 75105af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_compression_method, 75115af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_filter_method, 75125af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_num_trans; 75135af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp 7514bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy volatile size_t 75155af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp image_depth, 75165af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp old_bit_depth; 75173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 7518bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy size_t 75193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy quality, 75203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy rowbytes, 75213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy save_image_depth; 75223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 7523dfd7080ae717c8ddb013b59958f2d0790f5e3145glennrp int 7524fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp j, 7525f09bdedccf9ca10bc002a946227df3367cb58d14glennrp number_colors, 75268bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp number_opaque, 75278bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp number_semitransparent, 75288bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp number_transparent, 7529dfd7080ae717c8ddb013b59958f2d0790f5e3145glennrp ping_pHYs_unit_type; 7530dfd7080ae717c8ddb013b59958f2d0790f5e3145glennrp 7531dfd7080ae717c8ddb013b59958f2d0790f5e3145glennrp png_uint_32 7532dfd7080ae717c8ddb013b59958f2d0790f5e3145glennrp ping_pHYs_x_resolution, 7533dfd7080ae717c8ddb013b59958f2d0790f5e3145glennrp ping_pHYs_y_resolution; 7534dfd7080ae717c8ddb013b59958f2d0790f5e3145glennrp 75353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy logging=LogMagickEvent(CoderEvent,GetMagickModule(), 7536fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp " Enter WriteOnePNGImage()"); 75373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 7538b9cfe27bef51dbbd1f05aef89c767749d7e37864glennrp image = CloneImage(IMimage,0,0,MagickFalse,&IMimage->exception); 7539b9cfe27bef51dbbd1f05aef89c767749d7e37864glennrp image_info=(ImageInfo *) CloneImageInfo(IMimage_info); 75408d3d6e584829223ac5f6e6653c3caa38a2562a74glennrp if (image_info == (ImageInfo *) NULL) 75417b2cc79f1f54b48a9c3fe4eb3afbc2ebd6f6ec08glennrp ThrowWriterException(ResourceLimitError, "MemoryAllocationFailed"); 7542b9cfe27bef51dbbd1f05aef89c767749d7e37864glennrp 75433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(PNG_SETJMP_NOT_THREAD_SAFE) 7544cf002022280cc4dedb2748ad6f415aac1d44f530glennrp LockSemaphoreInfo(ping_semaphore); 75453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 75463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 75475af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp /* Initialize some stuff */ 75480fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp ping_bit_depth=0, 75495af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_color_type=0, 75505af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_interlace_method=0, 75515af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_compression_method=0, 75525af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_filter_method=0, 75535af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_num_trans = 0; 75545af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp 75555af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_background.red = 0; 75565af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_background.green = 0; 75575af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_background.blue = 0; 75585af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_background.gray = 0; 75595af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_background.index = 0; 75605af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp 75615af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_trans_color.red=0; 75625af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_trans_color.green=0; 75635af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_trans_color.blue=0; 75645af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_trans_color.gray=0; 75655af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp 7566dfd7080ae717c8ddb013b59958f2d0790f5e3145glennrp ping_pHYs_unit_type = 0; 7567dfd7080ae717c8ddb013b59958f2d0790f5e3145glennrp ping_pHYs_x_resolution = 0; 7568dfd7080ae717c8ddb013b59958f2d0790f5e3145glennrp ping_pHYs_y_resolution = 0; 7569dfd7080ae717c8ddb013b59958f2d0790f5e3145glennrp 7570da8f3a7bfddac2680a3069a490db541e7944edafglennrp ping_have_blob=MagickFalse; 7571d6bf1617e99df0272b231855a933a74e99b6578fglennrp ping_have_color=MagickTrue; 75728d579660c9b96b7a3f3292fc6c518f8b6ca44d50glennrp ping_have_non_bw=MagickTrue; 757339992b4dd9b12ef752d55b8e402c069698851f72glennrp ping_have_PLTE=MagickFalse; 7574991d11dd9c33e65872778b81aff1347cd2878154glennrp ping_have_bKGD=MagickFalse; 7575991d11dd9c33e65872778b81aff1347cd2878154glennrp ping_have_pHYs=MagickFalse; 7576991d11dd9c33e65872778b81aff1347cd2878154glennrp ping_have_tRNS=MagickFalse; 7577991d11dd9c33e65872778b81aff1347cd2878154glennrp 75780e8ea19baa0666ccfe869d19116372f60fe9230fglennrp ping_exclude_bKGD=mng_info->ping_exclude_bKGD; 75790e8ea19baa0666ccfe869d19116372f60fe9230fglennrp ping_exclude_cHRM=mng_info->ping_exclude_cHRM; 7580a0ed009a1e9480ac6f3f4520e9ef29d6d37e27dcglennrp ping_exclude_date=mng_info->ping_exclude_date; 7581dde35db6e37a8fd3adaa19bdfe20c7a54b2085efglennrp /* ping_exclude_EXIF=mng_info->ping_exclude_EXIF; */ 75820e8ea19baa0666ccfe869d19116372f60fe9230fglennrp ping_exclude_gAMA=mng_info->ping_exclude_gAMA; 75830e8ea19baa0666ccfe869d19116372f60fe9230fglennrp ping_exclude_iCCP=mng_info->ping_exclude_iCCP; 75840e8ea19baa0666ccfe869d19116372f60fe9230fglennrp /* ping_exclude_iTXt=mng_info->ping_exclude_iTXt; */ 75850e8ea19baa0666ccfe869d19116372f60fe9230fglennrp ping_exclude_oFFs=mng_info->ping_exclude_oFFs; 75860e8ea19baa0666ccfe869d19116372f60fe9230fglennrp ping_exclude_pHYs=mng_info->ping_exclude_pHYs; 75870e8ea19baa0666ccfe869d19116372f60fe9230fglennrp ping_exclude_sRGB=mng_info->ping_exclude_sRGB; 75880e8ea19baa0666ccfe869d19116372f60fe9230fglennrp ping_exclude_tEXt=mng_info->ping_exclude_tEXt; 7589dde35db6e37a8fd3adaa19bdfe20c7a54b2085efglennrp /* ping_exclude_tRNS=mng_info->ping_exclude_tRNS; */ 75900e8ea19baa0666ccfe869d19116372f60fe9230fglennrp ping_exclude_vpAg=mng_info->ping_exclude_vpAg; 75910e8ea19baa0666ccfe869d19116372f60fe9230fglennrp ping_exclude_zCCP=mng_info->ping_exclude_zCCP; /* hex-encoded iCCP in zTXt */ 75920e8ea19baa0666ccfe869d19116372f60fe9230fglennrp ping_exclude_zTXt=mng_info->ping_exclude_zTXt; 75930e8ea19baa0666ccfe869d19116372f60fe9230fglennrp 75948d3d6e584829223ac5f6e6653c3caa38a2562a74glennrp ping_preserve_colormap = mng_info->ping_preserve_colormap; 75950e8ea19baa0666ccfe869d19116372f60fe9230fglennrp ping_need_colortype_warning = MagickFalse; 75960e8ea19baa0666ccfe869d19116372f60fe9230fglennrp 75978bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp number_opaque = 0; 75988bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp number_semitransparent = 0; 75998bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp number_transparent = 0; 76008bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp 7601fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp if (logging != MagickFalse) 7602fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp { 7603fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp if (image->storage_class == UndefinedClass) 7604fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7605fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp " storage_class=UndefinedClass"); 7606fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp if (image->storage_class == DirectClass) 7607fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7608fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp " storage_class=DirectClass"); 7609fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp if (image->storage_class == PseudoClass) 7610fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7611fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp " storage_class=PseudoClass"); 7612fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp } 761328af3713c9111a471cc868c787760de89236fa3cglennrp 7614c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp if (ping_preserve_colormap == MagickFalse) 761528af3713c9111a471cc868c787760de89236fa3cglennrp { 7616c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp if (image->storage_class != PseudoClass && image->colormap != NULL) 7617c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp { 7618c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp /* Free the bogus colormap; it can cause trouble later */ 7619c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp if (logging != MagickFalse) 7620c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7621c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp " Freeing bogus colormap"); 7622c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp (void *) RelinquishMagickMemory(image->colormap); 7623c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp image->colormap=NULL; 7624c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp } 762528af3713c9111a471cc868c787760de89236fa3cglennrp } 7626bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp 76273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->colorspace != RGBColorspace) 76283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) TransformImageColorspace(image,RGBColorspace); 76290fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 76303241bd0c43e56612fc7aa006a0d30333dacbb51aglennrp /* 76313241bd0c43e56612fc7aa006a0d30333dacbb51aglennrp Sometimes we get PseudoClass images whose RGB values don't match 76323241bd0c43e56612fc7aa006a0d30333dacbb51aglennrp the colors in the colormap. This code syncs the RGB values. 76333241bd0c43e56612fc7aa006a0d30333dacbb51aglennrp */ 76343241bd0c43e56612fc7aa006a0d30333dacbb51aglennrp if (image->depth <= 8 && image->taint && image->storage_class == PseudoClass) 76353241bd0c43e56612fc7aa006a0d30333dacbb51aglennrp (void) SyncImage(image); 76363241bd0c43e56612fc7aa006a0d30333dacbb51aglennrp 7637a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp#if (MAGICKCORE_QUANTUM_DEPTH == 8) 7638a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp if (image->depth > 8) 7639a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp { 7640a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp if (logging != MagickFalse) 7641a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7642a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp " Reducing PNG bit depth to 8 since this is a Q8 build."); 7643a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp 7644a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp image->depth=8; 7645a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp } 7646a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp#endif 7647a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp 76488e58efdecda887b08ef730d68290a61081ef2566glennrp /* Respect the -depth option */ 764967b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp if (image->depth < MAGICKCORE_QUANTUM_DEPTH) 765067b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp { 76514c08aed51c5899665ade97263692328eea4af106cristy register Quantum 76528e58efdecda887b08ef730d68290a61081ef2566glennrp *r; 76538e58efdecda887b08ef730d68290a61081ef2566glennrp 76548e58efdecda887b08ef730d68290a61081ef2566glennrp ExceptionInfo 76558e58efdecda887b08ef730d68290a61081ef2566glennrp *exception; 76568e58efdecda887b08ef730d68290a61081ef2566glennrp 76578e58efdecda887b08ef730d68290a61081ef2566glennrp exception=(&image->exception); 76588e58efdecda887b08ef730d68290a61081ef2566glennrp 76598e58efdecda887b08ef730d68290a61081ef2566glennrp if (image->depth > 8) 76608e58efdecda887b08ef730d68290a61081ef2566glennrp { 76618e58efdecda887b08ef730d68290a61081ef2566glennrp#if MAGICKCORE_QUANTUM_DEPTH > 16 76628e58efdecda887b08ef730d68290a61081ef2566glennrp /* Scale to 16-bit */ 766391d99255dd77083750426ba5463e002a586bc9a6glennrp LBR16PacketRGBO(image->background_color); 76648e58efdecda887b08ef730d68290a61081ef2566glennrp 76658e58efdecda887b08ef730d68290a61081ef2566glennrp for (y=0; y < (ssize_t) image->rows; y++) 76668e58efdecda887b08ef730d68290a61081ef2566glennrp { 76678e58efdecda887b08ef730d68290a61081ef2566glennrp r=GetAuthenticPixels(image,0,y,image->columns,1, 76688e58efdecda887b08ef730d68290a61081ef2566glennrp exception); 76698e58efdecda887b08ef730d68290a61081ef2566glennrp 76704c08aed51c5899665ade97263692328eea4af106cristy if (r == (Quantum *) NULL) 76718e58efdecda887b08ef730d68290a61081ef2566glennrp break; 76728e58efdecda887b08ef730d68290a61081ef2566glennrp 76738e58efdecda887b08ef730d68290a61081ef2566glennrp for (x=0; x < (ssize_t) image->columns; x++) 76748e58efdecda887b08ef730d68290a61081ef2566glennrp { 76754c08aed51c5899665ade97263692328eea4af106cristy LBR16RGBA(r); 76768e58efdecda887b08ef730d68290a61081ef2566glennrp r++; 76778e58efdecda887b08ef730d68290a61081ef2566glennrp } 7678bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp 76798e58efdecda887b08ef730d68290a61081ef2566glennrp if (SyncAuthenticPixels(image,exception) == MagickFalse) 76808e58efdecda887b08ef730d68290a61081ef2566glennrp break; 76818e58efdecda887b08ef730d68290a61081ef2566glennrp } 76828e58efdecda887b08ef730d68290a61081ef2566glennrp 76838e58efdecda887b08ef730d68290a61081ef2566glennrp if (image->storage_class == PseudoClass && image->colormap != NULL) 76848e58efdecda887b08ef730d68290a61081ef2566glennrp { 76853e08f1130848df134cab76223cc758607d25efa7cristy for (i=0; i < (ssize_t) image->colors; i++) 76868e58efdecda887b08ef730d68290a61081ef2566glennrp { 768791d99255dd77083750426ba5463e002a586bc9a6glennrp LBR16PacketRGBO(image->colormap[i]); 76888e58efdecda887b08ef730d68290a61081ef2566glennrp } 76898e58efdecda887b08ef730d68290a61081ef2566glennrp } 76908e58efdecda887b08ef730d68290a61081ef2566glennrp#endif /* MAGICKCORE_QUANTUM_DEPTH > 16 */ 76918e58efdecda887b08ef730d68290a61081ef2566glennrp } 76928e58efdecda887b08ef730d68290a61081ef2566glennrp 76938e58efdecda887b08ef730d68290a61081ef2566glennrp else if (image->depth > 4) 76948e58efdecda887b08ef730d68290a61081ef2566glennrp { 76958e58efdecda887b08ef730d68290a61081ef2566glennrp#if MAGICKCORE_QUANTUM_DEPTH > 8 76968e58efdecda887b08ef730d68290a61081ef2566glennrp /* Scale to 8-bit */ 769791d99255dd77083750426ba5463e002a586bc9a6glennrp LBR08PacketRGBO(image->background_color); 76988e58efdecda887b08ef730d68290a61081ef2566glennrp 76998e58efdecda887b08ef730d68290a61081ef2566glennrp for (y=0; y < (ssize_t) image->rows; y++) 77008e58efdecda887b08ef730d68290a61081ef2566glennrp { 77018e58efdecda887b08ef730d68290a61081ef2566glennrp r=GetAuthenticPixels(image,0,y,image->columns,1, 77028e58efdecda887b08ef730d68290a61081ef2566glennrp exception); 77038e58efdecda887b08ef730d68290a61081ef2566glennrp 77044c08aed51c5899665ade97263692328eea4af106cristy if (r == (Quantum *) NULL) 77058e58efdecda887b08ef730d68290a61081ef2566glennrp break; 77068e58efdecda887b08ef730d68290a61081ef2566glennrp 77078e58efdecda887b08ef730d68290a61081ef2566glennrp for (x=0; x < (ssize_t) image->columns; x++) 77088e58efdecda887b08ef730d68290a61081ef2566glennrp { 77094c08aed51c5899665ade97263692328eea4af106cristy LBR08RGBA(r); 77108e58efdecda887b08ef730d68290a61081ef2566glennrp r++; 77118e58efdecda887b08ef730d68290a61081ef2566glennrp } 7712bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp 77138e58efdecda887b08ef730d68290a61081ef2566glennrp if (SyncAuthenticPixels(image,exception) == MagickFalse) 77148e58efdecda887b08ef730d68290a61081ef2566glennrp break; 77158e58efdecda887b08ef730d68290a61081ef2566glennrp } 77168e58efdecda887b08ef730d68290a61081ef2566glennrp 77178e58efdecda887b08ef730d68290a61081ef2566glennrp if (image->storage_class == PseudoClass && image->colormap != NULL) 77188e58efdecda887b08ef730d68290a61081ef2566glennrp { 77193e08f1130848df134cab76223cc758607d25efa7cristy for (i=0; i < (ssize_t) image->colors; i++) 77208e58efdecda887b08ef730d68290a61081ef2566glennrp { 772191d99255dd77083750426ba5463e002a586bc9a6glennrp LBR08PacketRGBO(image->colormap[i]); 77228e58efdecda887b08ef730d68290a61081ef2566glennrp } 77238e58efdecda887b08ef730d68290a61081ef2566glennrp } 77248e58efdecda887b08ef730d68290a61081ef2566glennrp#endif /* MAGICKCORE_QUANTUM_DEPTH > 8 */ 77258e58efdecda887b08ef730d68290a61081ef2566glennrp } 77268e58efdecda887b08ef730d68290a61081ef2566glennrp else 77278e58efdecda887b08ef730d68290a61081ef2566glennrp if (image->depth > 2) 77288e58efdecda887b08ef730d68290a61081ef2566glennrp { 77298e58efdecda887b08ef730d68290a61081ef2566glennrp /* Scale to 4-bit */ 773091d99255dd77083750426ba5463e002a586bc9a6glennrp LBR04PacketRGBO(image->background_color); 77318e58efdecda887b08ef730d68290a61081ef2566glennrp 77328e58efdecda887b08ef730d68290a61081ef2566glennrp for (y=0; y < (ssize_t) image->rows; y++) 77338e58efdecda887b08ef730d68290a61081ef2566glennrp { 77348e58efdecda887b08ef730d68290a61081ef2566glennrp r=GetAuthenticPixels(image,0,y,image->columns,1, 77358e58efdecda887b08ef730d68290a61081ef2566glennrp exception); 77368e58efdecda887b08ef730d68290a61081ef2566glennrp 77374c08aed51c5899665ade97263692328eea4af106cristy if (r == (Quantum *) NULL) 77388e58efdecda887b08ef730d68290a61081ef2566glennrp break; 77398e58efdecda887b08ef730d68290a61081ef2566glennrp 77408e58efdecda887b08ef730d68290a61081ef2566glennrp for (x=0; x < (ssize_t) image->columns; x++) 77418e58efdecda887b08ef730d68290a61081ef2566glennrp { 77424c08aed51c5899665ade97263692328eea4af106cristy LBR04RGBA(r); 77438e58efdecda887b08ef730d68290a61081ef2566glennrp r++; 77448e58efdecda887b08ef730d68290a61081ef2566glennrp } 7745bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp 77468e58efdecda887b08ef730d68290a61081ef2566glennrp if (SyncAuthenticPixels(image,exception) == MagickFalse) 77478e58efdecda887b08ef730d68290a61081ef2566glennrp break; 77488e58efdecda887b08ef730d68290a61081ef2566glennrp } 77498e58efdecda887b08ef730d68290a61081ef2566glennrp 77508e58efdecda887b08ef730d68290a61081ef2566glennrp if (image->storage_class == PseudoClass && image->colormap != NULL) 77518e58efdecda887b08ef730d68290a61081ef2566glennrp { 77523e08f1130848df134cab76223cc758607d25efa7cristy for (i=0; i < (ssize_t) image->colors; i++) 77538e58efdecda887b08ef730d68290a61081ef2566glennrp { 775491d99255dd77083750426ba5463e002a586bc9a6glennrp LBR04PacketRGBO(image->colormap[i]); 77558e58efdecda887b08ef730d68290a61081ef2566glennrp } 77568e58efdecda887b08ef730d68290a61081ef2566glennrp } 77578e58efdecda887b08ef730d68290a61081ef2566glennrp } 77588e58efdecda887b08ef730d68290a61081ef2566glennrp 77598e58efdecda887b08ef730d68290a61081ef2566glennrp else if (image->depth > 1) 77608e58efdecda887b08ef730d68290a61081ef2566glennrp { 77618e58efdecda887b08ef730d68290a61081ef2566glennrp /* Scale to 2-bit */ 776291d99255dd77083750426ba5463e002a586bc9a6glennrp LBR02PacketRGBO(image->background_color); 77638e58efdecda887b08ef730d68290a61081ef2566glennrp 77648e58efdecda887b08ef730d68290a61081ef2566glennrp for (y=0; y < (ssize_t) image->rows; y++) 77658e58efdecda887b08ef730d68290a61081ef2566glennrp { 77668e58efdecda887b08ef730d68290a61081ef2566glennrp r=GetAuthenticPixels(image,0,y,image->columns,1, 77678e58efdecda887b08ef730d68290a61081ef2566glennrp exception); 77688e58efdecda887b08ef730d68290a61081ef2566glennrp 77694c08aed51c5899665ade97263692328eea4af106cristy if (r == (Quantum *) NULL) 77708e58efdecda887b08ef730d68290a61081ef2566glennrp break; 77718e58efdecda887b08ef730d68290a61081ef2566glennrp 77728e58efdecda887b08ef730d68290a61081ef2566glennrp for (x=0; x < (ssize_t) image->columns; x++) 77738e58efdecda887b08ef730d68290a61081ef2566glennrp { 77744c08aed51c5899665ade97263692328eea4af106cristy LBR02RGBA(r); 77758e58efdecda887b08ef730d68290a61081ef2566glennrp r++; 77768e58efdecda887b08ef730d68290a61081ef2566glennrp } 7777bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp 77788e58efdecda887b08ef730d68290a61081ef2566glennrp if (SyncAuthenticPixels(image,exception) == MagickFalse) 77798e58efdecda887b08ef730d68290a61081ef2566glennrp break; 77808e58efdecda887b08ef730d68290a61081ef2566glennrp } 77818e58efdecda887b08ef730d68290a61081ef2566glennrp 77828e58efdecda887b08ef730d68290a61081ef2566glennrp if (image->storage_class == PseudoClass && image->colormap != NULL) 77838e58efdecda887b08ef730d68290a61081ef2566glennrp { 77843e08f1130848df134cab76223cc758607d25efa7cristy for (i=0; i < (ssize_t) image->colors; i++) 77858e58efdecda887b08ef730d68290a61081ef2566glennrp { 778691d99255dd77083750426ba5463e002a586bc9a6glennrp LBR02PacketRGBO(image->colormap[i]); 77878e58efdecda887b08ef730d68290a61081ef2566glennrp } 77888e58efdecda887b08ef730d68290a61081ef2566glennrp } 77898e58efdecda887b08ef730d68290a61081ef2566glennrp } 77908e58efdecda887b08ef730d68290a61081ef2566glennrp else 77918e58efdecda887b08ef730d68290a61081ef2566glennrp { 77928e58efdecda887b08ef730d68290a61081ef2566glennrp /* Scale to 1-bit */ 779391d99255dd77083750426ba5463e002a586bc9a6glennrp LBR01PacketRGBO(image->background_color); 77948e58efdecda887b08ef730d68290a61081ef2566glennrp 77958e58efdecda887b08ef730d68290a61081ef2566glennrp for (y=0; y < (ssize_t) image->rows; y++) 77968e58efdecda887b08ef730d68290a61081ef2566glennrp { 77978e58efdecda887b08ef730d68290a61081ef2566glennrp r=GetAuthenticPixels(image,0,y,image->columns,1, 77988e58efdecda887b08ef730d68290a61081ef2566glennrp exception); 77998e58efdecda887b08ef730d68290a61081ef2566glennrp 78004c08aed51c5899665ade97263692328eea4af106cristy if (r == (Quantum *) NULL) 78018e58efdecda887b08ef730d68290a61081ef2566glennrp break; 78028e58efdecda887b08ef730d68290a61081ef2566glennrp 78038e58efdecda887b08ef730d68290a61081ef2566glennrp for (x=0; x < (ssize_t) image->columns; x++) 78048e58efdecda887b08ef730d68290a61081ef2566glennrp { 78054c08aed51c5899665ade97263692328eea4af106cristy LBR01RGBA(r); 78068e58efdecda887b08ef730d68290a61081ef2566glennrp r++; 78078e58efdecda887b08ef730d68290a61081ef2566glennrp } 7808bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp 78098e58efdecda887b08ef730d68290a61081ef2566glennrp if (SyncAuthenticPixels(image,exception) == MagickFalse) 78108e58efdecda887b08ef730d68290a61081ef2566glennrp break; 78118e58efdecda887b08ef730d68290a61081ef2566glennrp } 78128e58efdecda887b08ef730d68290a61081ef2566glennrp 78138e58efdecda887b08ef730d68290a61081ef2566glennrp if (image->storage_class == PseudoClass && image->colormap != NULL) 78148e58efdecda887b08ef730d68290a61081ef2566glennrp { 78153e08f1130848df134cab76223cc758607d25efa7cristy for (i=0; i < (ssize_t) image->colors; i++) 78168e58efdecda887b08ef730d68290a61081ef2566glennrp { 781791d99255dd77083750426ba5463e002a586bc9a6glennrp LBR01PacketRGBO(image->colormap[i]); 78188e58efdecda887b08ef730d68290a61081ef2566glennrp } 78198e58efdecda887b08ef730d68290a61081ef2566glennrp } 78208e58efdecda887b08ef730d68290a61081ef2566glennrp } 7821cc95c3f37f025a52b71d927cba8009c4f8bc83a5glennrp } 7822cc95c3f37f025a52b71d927cba8009c4f8bc83a5glennrp 782367b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp /* To do: set to next higher multiple of 8 */ 782467b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp if (image->depth < 8) 782570e68a844517efda3094dc170a8f54affc9c82bcglennrp image->depth=8; 7826a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp 78272b013e4b9b602533eff410e61c3683fb2a3ab913glennrp#if (MAGICKCORE_QUANTUM_DEPTH > 16) 78282b013e4b9b602533eff410e61c3683fb2a3ab913glennrp /* PNG does not handle depths greater than 16 so reduce it even 78292b013e4b9b602533eff410e61c3683fb2a3ab913glennrp * if lossy 78302b013e4b9b602533eff410e61c3683fb2a3ab913glennrp */ 78318e58efdecda887b08ef730d68290a61081ef2566glennrp if (image->depth > 8) 78322b013e4b9b602533eff410e61c3683fb2a3ab913glennrp image->depth=16; 78332b013e4b9b602533eff410e61c3683fb2a3ab913glennrp#endif 78342b013e4b9b602533eff410e61c3683fb2a3ab913glennrp 78353faa9a3fb01696daaf976d595f492cb530bffb21glennrp#if (MAGICKCORE_QUANTUM_DEPTH > 8) 7836c722dd852e8abe407c2846d39662f7ade9c234deglennrp if (image->depth == 16 && mng_info->write_png_depth != 16) 78378bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp if (mng_info->write_png8 || LosslessReduceDepthOK(image) != MagickFalse) 78388640fb5e9b1094f35f8beab436f81661b8a99448glennrp image->depth = 8; 78398640fb5e9b1094f35f8beab436f81661b8a99448glennrp#endif 78408640fb5e9b1094f35f8beab436f81661b8a99448glennrp 7841c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp /* Normally we run this just once, but in the case of writing PNG8 7842e9637cb863ebc78027c145832eaf0b3a62bf2a56glennrp * we reduce the transparency to binary and run again, then if there 7843e9637cb863ebc78027c145832eaf0b3a62bf2a56glennrp * are still too many colors we reduce to a simple 4-4-4-1, then 3-3-3-1 78448ca51ad2da164dabc55b192ed7884b745fde0e26glennrp * RGBA palette and run again, and then to a simple 3-3-2-1 RGBA 78458ca51ad2da164dabc55b192ed7884b745fde0e26glennrp * palette. Then (To do) we take care of a final reduction that is only 78468ca51ad2da164dabc55b192ed7884b745fde0e26glennrp * needed if there are still 256 colors present and one of them has both 78478ca51ad2da164dabc55b192ed7884b745fde0e26glennrp * transparent and opaque instances. 7848c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp */ 784982b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp 78508ca51ad2da164dabc55b192ed7884b745fde0e26glennrp tried_332 = MagickFalse; 785182b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp tried_333 = MagickFalse; 7852d337164012450d70d62e71cf4a308a29004f7d57glennrp tried_444 = MagickFalse; 785382b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp 78548ca51ad2da164dabc55b192ed7884b745fde0e26glennrp for (j=0; j<6; j++) 7855d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 7856d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp /* BUILD_PALETTE 7857d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp * 7858d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp * Sometimes we get DirectClass images that have 256 colors or fewer. 7859d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp * This code will build a colormap. 7860d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp * 7861d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp * Also, sometimes we get PseudoClass images with an out-of-date 7862d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp * colormap. This code will replace the colormap with a new one. 7863d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp * Sometimes we get PseudoClass images that have more than 256 colors. 7864d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp * This code will delete the colormap and change the image to 7865d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp * DirectClass. 7866d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp * 78674c08aed51c5899665ade97263692328eea4af106cristy * If image->matte is MagickFalse, we ignore the alpha channel 7868d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp * even though it sometimes contains left-over non-opaque values. 7869d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp * 7870d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp * Also we gather some information (number of opaque, transparent, 7871d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp * and semitransparent pixels, and whether the image has any non-gray 7872d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp * pixels or only black-and-white pixels) that we might need later. 7873d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp * 7874d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp * Even if the user wants to force GrayAlpha or RGBA (colortype 4 or 6) 7875d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp * we need to check for bogus non-opaque values, at least. 7876d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp */ 78773c21811cab8a3b168295e3f0da1909c4e2a7da15glennrp 7878d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp ExceptionInfo 7879d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp *exception; 78808bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp 7881d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp int 7882d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp n; 78838bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp 7884d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp PixelPacket 7885d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp opaque[260], 7886d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp semitransparent[260], 7887d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp transparent[260]; 78888bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp 78894c08aed51c5899665ade97263692328eea4af106cristy register const Quantum 78904c08aed51c5899665ade97263692328eea4af106cristy *s; 7891d6bf1617e99df0272b231855a933a74e99b6578fglennrp 78924c08aed51c5899665ade97263692328eea4af106cristy register Quantum 78934c08aed51c5899665ade97263692328eea4af106cristy *q, 7894fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp *r; 7895fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp 7896d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (logging != MagickFalse) 7897d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7898d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp " Enter BUILD_PALETTE:"); 7899d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp 7900d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (logging != MagickFalse) 7901d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 7902d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7903d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp " image->columns=%.20g",(double) image->columns); 7904d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7905d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp " image->rows=%.20g",(double) image->rows); 7906d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7907d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp " image->matte=%.20g",(double) image->matte); 790803812ae402fb53d548f0e1d7d14720768f803c2dglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7909d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp " image->depth=%.20g",(double) image->depth); 79103c21811cab8a3b168295e3f0da1909c4e2a7da15glennrp 7911fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp if (image->storage_class == PseudoClass && image->colormap != NULL) 79127ddcc22478e0199aa11e9aeab088874b3b2cef63glennrp { 79137ddcc22478e0199aa11e9aeab088874b3b2cef63glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7914d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp " Original colormap:"); 79158bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 79164c08aed51c5899665ade97263692328eea4af106cristy " i (red,green,blue,alpha)"); 79172cc891a179d622dde7bbb8854138851e828bc6eaglennrp 7918d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp for (i=0; i < 256; i++) 79197ddcc22478e0199aa11e9aeab088874b3b2cef63glennrp { 7920d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7921d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp " %d (%d,%d,%d,%d)", 7922d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (int) i, 7923d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (int) image->colormap[i].red, 7924d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (int) image->colormap[i].green, 7925d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (int) image->colormap[i].blue, 79264c08aed51c5899665ade97263692328eea4af106cristy (int) image->colormap[i].alpha); 79277ddcc22478e0199aa11e9aeab088874b3b2cef63glennrp } 79282cc891a179d622dde7bbb8854138851e828bc6eaglennrp 7929d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp for (i=image->colors - 10; i < (ssize_t) image->colors; i++) 7930d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 7931d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (i > 255) 7932d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 7933d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7934d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp " %d (%d,%d,%d,%d)", 7935d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (int) i, 7936d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (int) image->colormap[i].red, 7937d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (int) image->colormap[i].green, 7938d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (int) image->colormap[i].blue, 79394c08aed51c5899665ade97263692328eea4af106cristy (int) image->colormap[i].alpha); 7940d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 7941d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 7942d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 79432cc891a179d622dde7bbb8854138851e828bc6eaglennrp 7944d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7945d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp " image->colors=%d",(int) image->colors); 794683c2de583a59e41b57be8036d1cf7392c01d03d7glennrp 7947d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (image->colors == 0) 7948d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7949d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp " (zero means unknown)"); 79507ddcc22478e0199aa11e9aeab088874b3b2cef63glennrp 79518d3d6e584829223ac5f6e6653c3caa38a2562a74glennrp if (ping_preserve_colormap == MagickFalse) 79528d3d6e584829223ac5f6e6653c3caa38a2562a74glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 79538d3d6e584829223ac5f6e6653c3caa38a2562a74glennrp " Regenerate the colormap"); 7954d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 79557ddcc22478e0199aa11e9aeab088874b3b2cef63glennrp 7956d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp exception=(&image->exception); 7957d6bf1617e99df0272b231855a933a74e99b6578fglennrp 7958d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp image_colors=0; 7959fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp number_opaque = 0; 7960fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp number_semitransparent = 0; 7961fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp number_transparent = 0; 79622cc891a179d622dde7bbb8854138851e828bc6eaglennrp 7963d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp for (y=0; y < (ssize_t) image->rows; y++) 7964d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 7965d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp q=GetAuthenticPixels(image,0,y,image->columns,1,exception); 79667ddcc22478e0199aa11e9aeab088874b3b2cef63glennrp 79674c08aed51c5899665ade97263692328eea4af106cristy if (q == (const Quantum *) NULL) 7968d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp break; 796997fd3d052fbd2e629d5d2387f26de9e250dd3e32glennrp 7970d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp for (x=0; x < (ssize_t) image->columns; x++) 7971d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 79724737d521d1d9e5d9a7c55375027ba4befc711046glennrp if (image->matte == MagickFalse || 79734c08aed51c5899665ade97263692328eea4af106cristy GetPixelAlpha(image,q) == OpaqueAlpha) 79748d579660c9b96b7a3f3292fc6c518f8b6ca44d50glennrp { 7975d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (number_opaque < 259) 79768d579660c9b96b7a3f3292fc6c518f8b6ca44d50glennrp { 7977d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (number_opaque == 0) 7978d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 79794c08aed51c5899665ade97263692328eea4af106cristy GetPixelPacket(image, q, opaque); 79804c08aed51c5899665ade97263692328eea4af106cristy opaque[0].alpha=OpaqueAlpha; 7981d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp number_opaque=1; 7982d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 7983d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp 7984d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp for (i=0; i< (ssize_t) number_opaque; i++) 7985d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 79864c08aed51c5899665ade97263692328eea4af106cristy if (IsPixelEquivalent(image,q, opaque+i)) 7987d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp break; 7988d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 7989d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp 7990d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (i == (ssize_t) number_opaque && 7991d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp number_opaque < 259) 7992d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 7993d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp number_opaque++; 79944c08aed51c5899665ade97263692328eea4af106cristy GetPixelPacket(image, q, opaque+i); 79954c08aed51c5899665ade97263692328eea4af106cristy opaque[i].alpha=OpaqueAlpha; 7996d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 79978d579660c9b96b7a3f3292fc6c518f8b6ca44d50glennrp } 79988d579660c9b96b7a3f3292fc6c518f8b6ca44d50glennrp } 79994c08aed51c5899665ade97263692328eea4af106cristy else if (GetPixelAlpha(image,q) == TransparentAlpha) 80008d579660c9b96b7a3f3292fc6c518f8b6ca44d50glennrp { 8001d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (number_transparent < 259) 80028d579660c9b96b7a3f3292fc6c518f8b6ca44d50glennrp { 8003d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (number_transparent == 0) 8004d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 80054c08aed51c5899665ade97263692328eea4af106cristy GetPixelPacket(image, q, transparent); 80064c08aed51c5899665ade97263692328eea4af106cristy ping_trans_color.red=(unsigned short) 80074c08aed51c5899665ade97263692328eea4af106cristy GetPixelRed(image,q); 80084c08aed51c5899665ade97263692328eea4af106cristy ping_trans_color.green=(unsigned short) 80094c08aed51c5899665ade97263692328eea4af106cristy GetPixelGreen(image,q); 80104c08aed51c5899665ade97263692328eea4af106cristy ping_trans_color.blue=(unsigned short) 80114c08aed51c5899665ade97263692328eea4af106cristy GetPixelBlue(image,q); 80124c08aed51c5899665ade97263692328eea4af106cristy ping_trans_color.gray=(unsigned short) 80134c08aed51c5899665ade97263692328eea4af106cristy GetPixelRed(image,q); 8014d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp number_transparent = 1; 8015d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 8016d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp 8017d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp for (i=0; i< (ssize_t) number_transparent; i++) 8018d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 80194c08aed51c5899665ade97263692328eea4af106cristy if (IsPixelEquivalent(image,q, transparent+i)) 8020d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp break; 8021d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 8022d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp 8023d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (i == (ssize_t) number_transparent && 8024d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp number_transparent < 259) 8025d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 8026d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp number_transparent++; 80274c08aed51c5899665ade97263692328eea4af106cristy GetPixelPacket(image,q,transparent+i); 8028d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 80298d579660c9b96b7a3f3292fc6c518f8b6ca44d50glennrp } 80308d579660c9b96b7a3f3292fc6c518f8b6ca44d50glennrp } 8031d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp else 8032d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 8033d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (number_semitransparent < 259) 8034d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 8035d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (number_semitransparent == 0) 8036d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 80374c08aed51c5899665ade97263692328eea4af106cristy GetPixelPacket(image,q,semitransparent); 8038d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp number_semitransparent = 1; 8039d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 80408d579660c9b96b7a3f3292fc6c518f8b6ca44d50glennrp 8041d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp for (i=0; i< (ssize_t) number_semitransparent; i++) 8042d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 80434c08aed51c5899665ade97263692328eea4af106cristy if (IsPixelEquivalent(image,q, semitransparent+i) 80444c08aed51c5899665ade97263692328eea4af106cristy && GetPixelAlpha(image,q) == 80454c08aed51c5899665ade97263692328eea4af106cristy semitransparent[i].alpha) 8046d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp break; 8047d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 8048d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp 8049d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (i == (ssize_t) number_semitransparent && 8050d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp number_semitransparent < 259) 8051d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 8052d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp number_semitransparent++; 80534c08aed51c5899665ade97263692328eea4af106cristy GetPixelPacket(image, q, semitransparent+i); 8054d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 8055d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 80568bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp } 80574c08aed51c5899665ade97263692328eea4af106cristy q+=GetPixelChannels(image); 8058d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 8059d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 80603c21811cab8a3b168295e3f0da1909c4e2a7da15glennrp 8061d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (ping_exclude_bKGD == MagickFalse) 8062d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 8063d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp /* Add the background color to the palette, if it 8064d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp * isn't already there. 8065d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp */ 8066c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp if (logging != MagickFalse) 8067c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp { 8068c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8069c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp " Check colormap for background (%d,%d,%d)", 8070c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp (int) image->background_color.red, 8071c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp (int) image->background_color.green, 8072c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp (int) image->background_color.blue); 8073c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp } 8074d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp for (i=0; i<number_opaque; i++) 8075d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 8076ca7ad3a4c4d394b32265e215c857b485fb57296fglennrp if (opaque[i].red == image->background_color.red && 8077ca7ad3a4c4d394b32265e215c857b485fb57296fglennrp opaque[i].green == image->background_color.green && 8078ca7ad3a4c4d394b32265e215c857b485fb57296fglennrp opaque[i].blue == image->background_color.blue) 8079ca7ad3a4c4d394b32265e215c857b485fb57296fglennrp break; 8080d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 8081d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (number_opaque < 259 && i == number_opaque) 808203812ae402fb53d548f0e1d7d14720768f803c2dglennrp { 80838e045c8f9e00ec89df5b20bf07c059d60e7aaa77glennrp opaque[i] = image->background_color; 8084c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp ping_background.index = i; 8085c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp if (logging != MagickFalse) 8086c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp { 8087c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8088c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp " background_color index is %d",(int) i); 8089c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp } 8090c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp 809103812ae402fb53d548f0e1d7d14720768f803c2dglennrp } 8092a080bc32a4a8b2ffec83fd836a28753959175363glennrp else if (logging != MagickFalse) 8093a080bc32a4a8b2ffec83fd836a28753959175363glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8094a080bc32a4a8b2ffec83fd836a28753959175363glennrp " No room in the colormap to add background color"); 8095d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 80962cc891a179d622dde7bbb8854138851e828bc6eaglennrp 8097d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp image_colors=number_opaque+number_transparent+number_semitransparent; 80983241bd0c43e56612fc7aa006a0d30333dacbb51aglennrp 8099a080bc32a4a8b2ffec83fd836a28753959175363glennrp if (mng_info->write_png8 != MagickFalse && image_colors > 256) 8100a080bc32a4a8b2ffec83fd836a28753959175363glennrp { 8101a080bc32a4a8b2ffec83fd836a28753959175363glennrp /* No room for the background color; remove it. */ 8102a080bc32a4a8b2ffec83fd836a28753959175363glennrp number_opaque--; 8103a080bc32a4a8b2ffec83fd836a28753959175363glennrp image_colors--; 8104a080bc32a4a8b2ffec83fd836a28753959175363glennrp } 8105a080bc32a4a8b2ffec83fd836a28753959175363glennrp 8106d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (logging != MagickFalse) 8107d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 8108d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (image_colors > 256) 8109d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8110d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp " image has more than 256 colors"); 81113241bd0c43e56612fc7aa006a0d30333dacbb51aglennrp 8112d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp else 8113d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8114d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp " image has %d colors",image_colors); 8115d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 81163241bd0c43e56612fc7aa006a0d30333dacbb51aglennrp 81178d3d6e584829223ac5f6e6653c3caa38a2562a74glennrp if (ping_preserve_colormap != MagickFalse) 81188d3d6e584829223ac5f6e6653c3caa38a2562a74glennrp break; 81198d3d6e584829223ac5f6e6653c3caa38a2562a74glennrp 8120fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp if (mng_info->write_png_colortype != 7) /* We won't need this info */ 8121d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 8122d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp ping_have_color=MagickFalse; 8123d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp ping_have_non_bw=MagickFalse; 81243241bd0c43e56612fc7aa006a0d30333dacbb51aglennrp 8125d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if(image_colors > 256) 8126d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 8127d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp for (y=0; y < (ssize_t) image->rows; y++) 8128d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 8129d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp q=GetAuthenticPixels(image,0,y,image->columns,1,exception); 81306185c5395ac23a4c51586d671ec3e0ba9c126349glennrp 81314c08aed51c5899665ade97263692328eea4af106cristy if (q == (const Quantum *) NULL) 8132d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp break; 81336185c5395ac23a4c51586d671ec3e0ba9c126349glennrp 8134d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp /* Worst case is black-and-white; we are looking at every 8135d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp * pixel twice. 8136d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp */ 81376185c5395ac23a4c51586d671ec3e0ba9c126349glennrp 8138d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (ping_have_color == MagickFalse) 8139d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 8140d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp s=q; 8141d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp for (x=0; x < (ssize_t) image->columns; x++) 8142d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 81434c08aed51c5899665ade97263692328eea4af106cristy if (GetPixelRed(image,s) != GetPixelGreen(image,s) || 81444c08aed51c5899665ade97263692328eea4af106cristy GetPixelRed(image,s) != GetPixelBlue(image,s)) 8145d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 8146d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp ping_have_color=MagickTrue; 8147d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp ping_have_non_bw=MagickTrue; 8148d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp break; 8149d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 81504c08aed51c5899665ade97263692328eea4af106cristy s+=GetPixelChannels(image); 8151d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 8152d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 81533241bd0c43e56612fc7aa006a0d30333dacbb51aglennrp 8154d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (ping_have_non_bw == MagickFalse) 8155d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 8156d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp s=q; 8157d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp for (x=0; x < (ssize_t) image->columns; x++) 81586185c5395ac23a4c51586d671ec3e0ba9c126349glennrp { 81594c08aed51c5899665ade97263692328eea4af106cristy if (GetPixelRed(image,s) != 0 && 81604c08aed51c5899665ade97263692328eea4af106cristy GetPixelRed(image,s) != QuantumRange) 8161d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 8162d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp ping_have_non_bw=MagickTrue; 8163d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 81644c08aed51c5899665ade97263692328eea4af106cristy s+=GetPixelChannels(image); 8165d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 8166d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 8167d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 8168bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp } 8169bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp } 81704f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp 8171d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (image_colors < 257) 8172d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 8173d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp PixelPacket 8174d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp colormap[260]; 8175bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp 8176d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp /* 8177d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp * Initialize image colormap. 8178d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp */ 8179d6bf1617e99df0272b231855a933a74e99b6578fglennrp 8180d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (logging != MagickFalse) 8181d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8182d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp " Sort the new colormap"); 8183d6bf1617e99df0272b231855a933a74e99b6578fglennrp 8184d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp /* Sort palette, transparent first */; 8185d6bf1617e99df0272b231855a933a74e99b6578fglennrp 8186d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp n = 0; 81873241bd0c43e56612fc7aa006a0d30333dacbb51aglennrp 8188d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp for (i=0; i<number_transparent; i++) 8189d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp colormap[n++] = transparent[i]; 81903241bd0c43e56612fc7aa006a0d30333dacbb51aglennrp 8191d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp for (i=0; i<number_semitransparent; i++) 8192d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp colormap[n++] = semitransparent[i]; 8193d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp 8194d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp for (i=0; i<number_opaque; i++) 8195d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp colormap[n++] = opaque[i]; 8196d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp 8197c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp ping_background.index += 8198c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp (number_transparent + number_semitransparent); 8199bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp 8200d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp /* image_colors < 257; search the colormap instead of the pixels 8201d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp * to get ping_have_color and ping_have_non_bw 8202d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp */ 8203d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp for (i=0; i<n; i++) 8204d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 8205d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (ping_have_color == MagickFalse) 8206d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 8207d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (colormap[i].red != colormap[i].green || 8208d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp colormap[i].red != colormap[i].blue) 8209d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 8210d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp ping_have_color=MagickTrue; 8211d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp ping_have_non_bw=MagickTrue; 8212d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp break; 8213d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 8214d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 8215d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp 8216d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (ping_have_non_bw == MagickFalse) 8217d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 8218d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (colormap[i].red != 0 && colormap[i].red != QuantumRange) 8219d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp ping_have_non_bw=MagickTrue; 8220d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 8221d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 82223241bd0c43e56612fc7aa006a0d30333dacbb51aglennrp 8223d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if ((mng_info->ping_exclude_tRNS == MagickFalse || 8224d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (number_transparent == 0 && number_semitransparent == 0)) && 8225d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (((mng_info->write_png_colortype-1) == 8226d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp PNG_COLOR_TYPE_PALETTE) || 8227d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (mng_info->write_png_colortype == 0))) 8228d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 8229d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (logging != MagickFalse) 82306185c5395ac23a4c51586d671ec3e0ba9c126349glennrp { 8231d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (n != (ssize_t) image_colors) 8232d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8233d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp " image_colors (%d) and n (%d) don't match", 8234d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp image_colors, n); 82352cc891a179d622dde7bbb8854138851e828bc6eaglennrp 8236d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8237d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp " AcquireImageColormap"); 8238d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 8239d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp 8240d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp image->colors = image_colors; 8241d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp 8242d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (AcquireImageColormap(image,image_colors) == 8243d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp MagickFalse) 82443faa9a3fb01696daaf976d595f492cb530bffb21glennrp ThrowWriterException(ResourceLimitError, 82453faa9a3fb01696daaf976d595f492cb530bffb21glennrp "MemoryAllocationFailed"); 8246d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp 8247d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp for (i=0; i< (ssize_t) image_colors; i++) 8248d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp image->colormap[i] = colormap[i]; 8249d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp 8250d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (logging != MagickFalse) 8251d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 8252d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8253d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp " image->colors=%d (%d)", 8254d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (int) image->colors, image_colors); 8255bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp 8256d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8257d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp " Update the pixel indexes"); 8258d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 8259d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp 8260fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp /* Sync the pixel indices with the new colormap */ 8261fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp 8262d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp for (y=0; y < (ssize_t) image->rows; y++) 8263d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 8264d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp q=GetAuthenticPixels(image,0,y,image->columns,1, 8265d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp exception); 82663c21811cab8a3b168295e3f0da1909c4e2a7da15glennrp 82674c08aed51c5899665ade97263692328eea4af106cristy if (q == (const Quantum *) NULL) 8268d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp break; 82693c21811cab8a3b168295e3f0da1909c4e2a7da15glennrp 8270bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp 8271d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp for (x=0; x < (ssize_t) image->columns; x++) 8272d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 8273d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp for (i=0; i< (ssize_t) image_colors; i++) 827403812ae402fb53d548f0e1d7d14720768f803c2dglennrp { 8275d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if ((image->matte == MagickFalse || 82764c08aed51c5899665ade97263692328eea4af106cristy image->colormap[i].alpha == GetPixelAlpha(image,q)) && 82774c08aed51c5899665ade97263692328eea4af106cristy image->colormap[i].red == GetPixelRed(image,q) && 82784c08aed51c5899665ade97263692328eea4af106cristy image->colormap[i].green == GetPixelGreen(image,q) && 82794c08aed51c5899665ade97263692328eea4af106cristy image->colormap[i].blue == GetPixelBlue(image,q)) 82806185c5395ac23a4c51586d671ec3e0ba9c126349glennrp { 82814c08aed51c5899665ade97263692328eea4af106cristy SetPixelIndex(image,i,q); 8282d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp break; 82836185c5395ac23a4c51586d671ec3e0ba9c126349glennrp } 828403812ae402fb53d548f0e1d7d14720768f803c2dglennrp } 82854c08aed51c5899665ade97263692328eea4af106cristy q+=GetPixelChannels(image); 8286d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 8287d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp 8288d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (SyncAuthenticPixels(image,exception) == MagickFalse) 8289d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp break; 8290d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 8291d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 8292d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 8293d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp 8294d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (logging != MagickFalse) 8295d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 8296d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8297d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp " image->colors=%d", (int) image->colors); 8298d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp 8299d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (image->colormap != NULL) 8300d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 8301d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 83024c08aed51c5899665ade97263692328eea4af106cristy " i (red,green,blue,alpha)"); 830383c2de583a59e41b57be8036d1cf7392c01d03d7glennrp 8304d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp for (i=0; i < (ssize_t) image->colors; i++) 8305d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 830672988485e53441bbc7e5e7fbcb8e81012212efb6cristy if (i < 300 || i >= (ssize_t) image->colors - 10) 8307d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp { 8308d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8309d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp " %d (%d,%d,%d,%d)", 8310d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (int) i, 8311d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (int) image->colormap[i].red, 8312d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (int) image->colormap[i].green, 8313d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (int) image->colormap[i].blue, 83144c08aed51c5899665ade97263692328eea4af106cristy (int) image->colormap[i].alpha); 8315d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 83166185c5395ac23a4c51586d671ec3e0ba9c126349glennrp } 83176185c5395ac23a4c51586d671ec3e0ba9c126349glennrp } 83183c21811cab8a3b168295e3f0da1909c4e2a7da15glennrp 8319d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (number_transparent < 257) 8320d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8321d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp " number_transparent = %d", 8322d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp number_transparent); 8323d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp else 83243c21811cab8a3b168295e3f0da1909c4e2a7da15glennrp 8325d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8326d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp " number_transparent > 256"); 83273c21811cab8a3b168295e3f0da1909c4e2a7da15glennrp 8328d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (number_opaque < 257) 8329d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8330d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp " number_opaque = %d", 8331d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp number_opaque); 833203812ae402fb53d548f0e1d7d14720768f803c2dglennrp 8333d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp else 8334d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8335d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp " number_opaque > 256"); 83366185c5395ac23a4c51586d671ec3e0ba9c126349glennrp 8337d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (number_semitransparent < 257) 8338d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8339d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp " number_semitransparent = %d", 8340d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp number_semitransparent); 83416185c5395ac23a4c51586d671ec3e0ba9c126349glennrp 8342d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp else 8343d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8344d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp " number_semitransparent > 256"); 8345a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp 8346d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (ping_have_non_bw == MagickFalse) 8347d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8348d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp " All pixels and the background are black or white"); 8349a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp 8350d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp else if (ping_have_color == MagickFalse) 8351d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8352d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp " All pixels and the background are gray"); 8353d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp 8354d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp else 8355d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8356d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp " At least one pixel or the background is non-gray"); 83576185c5395ac23a4c51586d671ec3e0ba9c126349glennrp 835803812ae402fb53d548f0e1d7d14720768f803c2dglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 835903812ae402fb53d548f0e1d7d14720768f803c2dglennrp " Exit BUILD_PALETTE:"); 8360d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp } 83613c21811cab8a3b168295e3f0da1909c4e2a7da15glennrp 8362c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp if (mng_info->write_png8 == MagickFalse) 8363c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp break; 8364fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp 8365c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp /* Make any reductions necessary for the PNG8 format */ 8366c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp if (image_colors <= 256 && 8367c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp image_colors != 0 && image->colormap != NULL && 8368c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp number_semitransparent == 0 && 8369c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp number_transparent <= 1) 8370c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp break; 8371fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp 8372c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp /* PNG8 can't have semitransparent colors so we threshold the 83734c08aed51c5899665ade97263692328eea4af106cristy * alpha to 0 or OpaqueAlpha 8374c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp */ 8375c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp if (number_semitransparent != 0) 8376c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp { 8377c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8378c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp " Thresholding the alpha channel to binary"); 8379fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp 8380c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp for (y=0; y < (ssize_t) image->rows; y++) 8381c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp { 8382c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp r=GetAuthenticPixels(image,0,y,image->columns,1, 8383c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp exception); 8384fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp 83854c08aed51c5899665ade97263692328eea4af106cristy if (r == (Quantum *) NULL) 8386c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp break; 8387fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp 8388c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp for (x=0; x < (ssize_t) image->columns; x++) 8389c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp { 83904c08aed51c5899665ade97263692328eea4af106cristy if (GetPixelAlpha(image,r) > TransparentAlpha/2) 83918ca51ad2da164dabc55b192ed7884b745fde0e26glennrp { 83924c08aed51c5899665ade97263692328eea4af106cristy SetPixelPacket(image,&image->background_color,r); 83934c08aed51c5899665ade97263692328eea4af106cristy SetPixelAlpha(image,TransparentAlpha,r); 83948ca51ad2da164dabc55b192ed7884b745fde0e26glennrp } 83958ca51ad2da164dabc55b192ed7884b745fde0e26glennrp else 83964c08aed51c5899665ade97263692328eea4af106cristy SetPixelAlpha(image,OpaqueAlpha,r); 83974c08aed51c5899665ade97263692328eea4af106cristy r+=GetPixelChannels(image); 8398c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp } 8399bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp 8400c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp if (SyncAuthenticPixels(image,exception) == MagickFalse) 8401c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp break; 8402fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp 8403c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp if (image_colors != 0 && image_colors <= 256 && 8404c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp image->colormap != NULL) 8405c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp for (i=0; i<image_colors; i++) 84064c08aed51c5899665ade97263692328eea4af106cristy image->colormap[i].alpha = 84074c08aed51c5899665ade97263692328eea4af106cristy (image->colormap[i].alpha > TransparentAlpha/2 ? 84084c08aed51c5899665ade97263692328eea4af106cristy TransparentAlpha : OpaqueAlpha); 8409c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp } 8410c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp continue; 8411c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp } 8412c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp 8413c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp /* PNG8 can't have more than 256 colors so we quantize the pixels and 8414e9637cb863ebc78027c145832eaf0b3a62bf2a56glennrp * background color to the 4-4-4-1, 3-3-3-1 or 3-3-2-1 palette. If the 8415e9637cb863ebc78027c145832eaf0b3a62bf2a56glennrp * image is mostly gray, the 4-4-4-1 palette is likely to end up with 256 8416e9637cb863ebc78027c145832eaf0b3a62bf2a56glennrp * colors or less. 8417c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp */ 8418d337164012450d70d62e71cf4a308a29004f7d57glennrp if (tried_444 == MagickFalse && (image_colors == 0 || image_colors > 256)) 8419d337164012450d70d62e71cf4a308a29004f7d57glennrp { 8420d337164012450d70d62e71cf4a308a29004f7d57glennrp if (logging != MagickFalse) 8421d337164012450d70d62e71cf4a308a29004f7d57glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8422d337164012450d70d62e71cf4a308a29004f7d57glennrp " Quantizing the background color to 4-4-4"); 8423d337164012450d70d62e71cf4a308a29004f7d57glennrp 8424d337164012450d70d62e71cf4a308a29004f7d57glennrp tried_444 = MagickTrue; 8425d337164012450d70d62e71cf4a308a29004f7d57glennrp 842691d99255dd77083750426ba5463e002a586bc9a6glennrp LBR04PacketRGB(image->background_color); 8427d337164012450d70d62e71cf4a308a29004f7d57glennrp 8428d337164012450d70d62e71cf4a308a29004f7d57glennrp if (logging != MagickFalse) 8429d337164012450d70d62e71cf4a308a29004f7d57glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8430d337164012450d70d62e71cf4a308a29004f7d57glennrp " Quantizing the pixel colors to 4-4-4"); 8431d337164012450d70d62e71cf4a308a29004f7d57glennrp 8432d337164012450d70d62e71cf4a308a29004f7d57glennrp if (image->colormap == NULL) 8433d337164012450d70d62e71cf4a308a29004f7d57glennrp { 8434d337164012450d70d62e71cf4a308a29004f7d57glennrp for (y=0; y < (ssize_t) image->rows; y++) 8435d337164012450d70d62e71cf4a308a29004f7d57glennrp { 8436d337164012450d70d62e71cf4a308a29004f7d57glennrp r=GetAuthenticPixels(image,0,y,image->columns,1, 8437d337164012450d70d62e71cf4a308a29004f7d57glennrp exception); 8438d337164012450d70d62e71cf4a308a29004f7d57glennrp 84394c08aed51c5899665ade97263692328eea4af106cristy if (r == (Quantum *) NULL) 8440d337164012450d70d62e71cf4a308a29004f7d57glennrp break; 8441d337164012450d70d62e71cf4a308a29004f7d57glennrp 8442d337164012450d70d62e71cf4a308a29004f7d57glennrp for (x=0; x < (ssize_t) image->columns; x++) 8443d337164012450d70d62e71cf4a308a29004f7d57glennrp { 84444c08aed51c5899665ade97263692328eea4af106cristy if (GetPixelAlpha(image,r) == OpaqueAlpha) 84454c08aed51c5899665ade97263692328eea4af106cristy LBR04RGB(r); 8446d337164012450d70d62e71cf4a308a29004f7d57glennrp r++; 8447d337164012450d70d62e71cf4a308a29004f7d57glennrp } 8448bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp 8449d337164012450d70d62e71cf4a308a29004f7d57glennrp if (SyncAuthenticPixels(image,exception) == MagickFalse) 8450d337164012450d70d62e71cf4a308a29004f7d57glennrp break; 8451d337164012450d70d62e71cf4a308a29004f7d57glennrp } 8452d337164012450d70d62e71cf4a308a29004f7d57glennrp } 8453d337164012450d70d62e71cf4a308a29004f7d57glennrp 8454d337164012450d70d62e71cf4a308a29004f7d57glennrp else /* Should not reach this; colormap already exists and 8455d337164012450d70d62e71cf4a308a29004f7d57glennrp must be <= 256 */ 8456d337164012450d70d62e71cf4a308a29004f7d57glennrp { 8457d337164012450d70d62e71cf4a308a29004f7d57glennrp if (logging != MagickFalse) 8458d337164012450d70d62e71cf4a308a29004f7d57glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8459d337164012450d70d62e71cf4a308a29004f7d57glennrp " Quantizing the colormap to 4-4-4"); 84608e58efdecda887b08ef730d68290a61081ef2566glennrp 8461d337164012450d70d62e71cf4a308a29004f7d57glennrp for (i=0; i<image_colors; i++) 8462d337164012450d70d62e71cf4a308a29004f7d57glennrp { 846391d99255dd77083750426ba5463e002a586bc9a6glennrp LBR04PacketRGB(image->colormap[i]); 8464d337164012450d70d62e71cf4a308a29004f7d57glennrp } 8465d337164012450d70d62e71cf4a308a29004f7d57glennrp } 8466d337164012450d70d62e71cf4a308a29004f7d57glennrp continue; 8467d337164012450d70d62e71cf4a308a29004f7d57glennrp } 8468d337164012450d70d62e71cf4a308a29004f7d57glennrp 846982b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp if (tried_333 == MagickFalse && (image_colors == 0 || image_colors > 256)) 847082b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp { 847182b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp if (logging != MagickFalse) 847282b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 847382b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp " Quantizing the background color to 3-3-3"); 847482b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp 847582b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp tried_333 = MagickTrue; 847682b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp 847791d99255dd77083750426ba5463e002a586bc9a6glennrp LBR03PacketRGB(image->background_color); 847882b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp 847982b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp if (logging != MagickFalse) 848082b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8481e9637cb863ebc78027c145832eaf0b3a62bf2a56glennrp " Quantizing the pixel colors to 3-3-3-1"); 848282b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp 848382b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp if (image->colormap == NULL) 848482b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp { 848582b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp for (y=0; y < (ssize_t) image->rows; y++) 848682b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp { 848782b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp r=GetAuthenticPixels(image,0,y,image->columns,1, 848882b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp exception); 848982b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp 84904c08aed51c5899665ade97263692328eea4af106cristy if (r == (Quantum *) NULL) 849182b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp break; 849282b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp 849382b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp for (x=0; x < (ssize_t) image->columns; x++) 849482b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp { 84954c08aed51c5899665ade97263692328eea4af106cristy if (GetPixelAlpha(image,r) == OpaqueAlpha) 84964c08aed51c5899665ade97263692328eea4af106cristy LBR03RGB(r); 849782b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp r++; 849882b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp } 8499bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp 850082b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp if (SyncAuthenticPixels(image,exception) == MagickFalse) 850182b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp break; 850282b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp } 850382b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp } 850482b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp 850582b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp else /* Should not reach this; colormap already exists and 850682b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp must be <= 256 */ 850782b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp { 850882b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp if (logging != MagickFalse) 850982b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8510e9637cb863ebc78027c145832eaf0b3a62bf2a56glennrp " Quantizing the colormap to 3-3-3-1"); 851182b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp for (i=0; i<image_colors; i++) 851282b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp { 851391d99255dd77083750426ba5463e002a586bc9a6glennrp LBR03PacketRGB(image->colormap[i]); 851482b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp } 8515d337164012450d70d62e71cf4a308a29004f7d57glennrp } 8516d337164012450d70d62e71cf4a308a29004f7d57glennrp continue; 851782b3c538ac5cfab10ee4ce71e69605dda09195a3glennrp } 8518c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp 85198ca51ad2da164dabc55b192ed7884b745fde0e26glennrp if (tried_332 == MagickFalse && (image_colors == 0 || image_colors > 256)) 8520c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp { 8521c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp if (logging != MagickFalse) 8522c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8523c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp " Quantizing the background color to 3-3-2"); 8524c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp 85258ca51ad2da164dabc55b192ed7884b745fde0e26glennrp tried_332 = MagickTrue; 85268ca51ad2da164dabc55b192ed7884b745fde0e26glennrp 85273faa9a3fb01696daaf976d595f492cb530bffb21glennrp /* Red and green were already done so we only quantize the blue 85283faa9a3fb01696daaf976d595f492cb530bffb21glennrp * channel 85293faa9a3fb01696daaf976d595f492cb530bffb21glennrp */ 85303faa9a3fb01696daaf976d595f492cb530bffb21glennrp 853191d99255dd77083750426ba5463e002a586bc9a6glennrp LBR02PacketBlue(image->background_color); 8532fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp 8533c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp if (logging != MagickFalse) 8534c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8535e9637cb863ebc78027c145832eaf0b3a62bf2a56glennrp " Quantizing the pixel colors to 3-3-2-1"); 8536fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp 8537c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp if (image->colormap == NULL) 8538c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp { 8539c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp for (y=0; y < (ssize_t) image->rows; y++) 8540c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp { 8541c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp r=GetAuthenticPixels(image,0,y,image->columns,1, 8542c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp exception); 85438d579660c9b96b7a3f3292fc6c518f8b6ca44d50glennrp 85444c08aed51c5899665ade97263692328eea4af106cristy if (r == (Quantum *) NULL) 8545c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp break; 8546c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp 8547c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp for (x=0; x < (ssize_t) image->columns; x++) 8548c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp { 85494c08aed51c5899665ade97263692328eea4af106cristy if (GetPixelAlpha(image,r) == OpaqueAlpha) 85504c08aed51c5899665ade97263692328eea4af106cristy LBR02Blue(r); 855152a479ca718756af72f96e127f8256499ab68f76glennrp r++; 8552c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp } 8553bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp 8554c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp if (SyncAuthenticPixels(image,exception) == MagickFalse) 8555c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp break; 8556c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp } 8557c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp } 8558c722dd852e8abe407c2846d39662f7ade9c234deglennrp 8559c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp else /* Should not reach this; colormap already exists and 8560c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp must be <= 256 */ 8561c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp { 8562c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp if (logging != MagickFalse) 8563c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8564e9637cb863ebc78027c145832eaf0b3a62bf2a56glennrp " Quantizing the colormap to 3-3-2-1"); 8565c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp for (i=0; i<image_colors; i++) 8566c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp { 856791d99255dd77083750426ba5463e002a586bc9a6glennrp LBR02PacketBlue(image->colormap[i]); 8568c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp } 8569c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp } 8570c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp continue; 8571c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp } 8572c8c2f066877e87b2d3ece7f92a80287177717d9fglennrp break; 85738ca51ad2da164dabc55b192ed7884b745fde0e26glennrp 85748ca51ad2da164dabc55b192ed7884b745fde0e26glennrp if (image_colors == 0 || image_colors > 256) 85758ca51ad2da164dabc55b192ed7884b745fde0e26glennrp { 85768ca51ad2da164dabc55b192ed7884b745fde0e26glennrp /* Take care of special case with 256 colors + 1 transparent 85778ca51ad2da164dabc55b192ed7884b745fde0e26glennrp * color. We don't need to quantize to 2-3-2-1; we only need to 85788ca51ad2da164dabc55b192ed7884b745fde0e26glennrp * eliminate one color, so we'll merge the two darkest red 85798ca51ad2da164dabc55b192ed7884b745fde0e26glennrp * colors (0x49, 0, 0) -> (0x24, 0, 0). 85808ca51ad2da164dabc55b192ed7884b745fde0e26glennrp */ 85818ca51ad2da164dabc55b192ed7884b745fde0e26glennrp if (ScaleQuantumToChar(image->background_color.red) == 0x49 && 85828ca51ad2da164dabc55b192ed7884b745fde0e26glennrp ScaleQuantumToChar(image->background_color.green) == 0x00 && 85838ca51ad2da164dabc55b192ed7884b745fde0e26glennrp ScaleQuantumToChar(image->background_color.blue) == 0x00) 85848ca51ad2da164dabc55b192ed7884b745fde0e26glennrp { 85858ca51ad2da164dabc55b192ed7884b745fde0e26glennrp image->background_color.red=ScaleCharToQuantum(0x24); 85868ca51ad2da164dabc55b192ed7884b745fde0e26glennrp } 8587bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp 85888ca51ad2da164dabc55b192ed7884b745fde0e26glennrp if (image->colormap == NULL) 85898ca51ad2da164dabc55b192ed7884b745fde0e26glennrp { 85908ca51ad2da164dabc55b192ed7884b745fde0e26glennrp for (y=0; y < (ssize_t) image->rows; y++) 85918ca51ad2da164dabc55b192ed7884b745fde0e26glennrp { 85928ca51ad2da164dabc55b192ed7884b745fde0e26glennrp r=GetAuthenticPixels(image,0,y,image->columns,1, 85938ca51ad2da164dabc55b192ed7884b745fde0e26glennrp exception); 8594bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp 85954c08aed51c5899665ade97263692328eea4af106cristy if (r == (Quantum *) NULL) 85968ca51ad2da164dabc55b192ed7884b745fde0e26glennrp break; 8597bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp 85988ca51ad2da164dabc55b192ed7884b745fde0e26glennrp for (x=0; x < (ssize_t) image->columns; x++) 85998ca51ad2da164dabc55b192ed7884b745fde0e26glennrp { 86004c08aed51c5899665ade97263692328eea4af106cristy if (ScaleQuantumToChar(GetPixelRed(image,r)) == 0x49 && 86014c08aed51c5899665ade97263692328eea4af106cristy ScaleQuantumToChar(GetPixelGreen(image,r)) == 0x00 && 86024c08aed51c5899665ade97263692328eea4af106cristy ScaleQuantumToChar(GetPixelBlue(image,r)) == 0x00 && 86034c08aed51c5899665ade97263692328eea4af106cristy GetPixelAlpha(image,r) == OpaqueAlpha) 86048ca51ad2da164dabc55b192ed7884b745fde0e26glennrp { 86054c08aed51c5899665ade97263692328eea4af106cristy SetPixelRed(image,ScaleCharToQuantum(0x24),r); 86068ca51ad2da164dabc55b192ed7884b745fde0e26glennrp } 86074c08aed51c5899665ade97263692328eea4af106cristy r+=GetPixelChannels(image); 86088ca51ad2da164dabc55b192ed7884b745fde0e26glennrp } 8609bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp 86108ca51ad2da164dabc55b192ed7884b745fde0e26glennrp if (SyncAuthenticPixels(image,exception) == MagickFalse) 86118ca51ad2da164dabc55b192ed7884b745fde0e26glennrp break; 8612bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp 86138ca51ad2da164dabc55b192ed7884b745fde0e26glennrp } 86148ca51ad2da164dabc55b192ed7884b745fde0e26glennrp } 86158ca51ad2da164dabc55b192ed7884b745fde0e26glennrp 86168ca51ad2da164dabc55b192ed7884b745fde0e26glennrp else 86178ca51ad2da164dabc55b192ed7884b745fde0e26glennrp { 86188ca51ad2da164dabc55b192ed7884b745fde0e26glennrp for (i=0; i<image_colors; i++) 86198ca51ad2da164dabc55b192ed7884b745fde0e26glennrp { 86208ca51ad2da164dabc55b192ed7884b745fde0e26glennrp if (ScaleQuantumToChar(image->colormap[i].red) == 0x49 && 86218ca51ad2da164dabc55b192ed7884b745fde0e26glennrp ScaleQuantumToChar(image->colormap[i].green) == 0x00 && 86228ca51ad2da164dabc55b192ed7884b745fde0e26glennrp ScaleQuantumToChar(image->colormap[i].blue) == 0x00) 86238ca51ad2da164dabc55b192ed7884b745fde0e26glennrp { 86248ca51ad2da164dabc55b192ed7884b745fde0e26glennrp image->colormap[i].red=ScaleCharToQuantum(0x24); 86258ca51ad2da164dabc55b192ed7884b745fde0e26glennrp } 86268ca51ad2da164dabc55b192ed7884b745fde0e26glennrp } 86278ca51ad2da164dabc55b192ed7884b745fde0e26glennrp } 86288ca51ad2da164dabc55b192ed7884b745fde0e26glennrp } 8629fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp } 8630fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp /* END OF BUILD_PALETTE */ 8631fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp 8632fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp /* If we are excluding the tRNS chunk and there is transparency, 8633fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp * then we must write a Gray-Alpha (color-type 4) or RGBA (color-type 6) 8634fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp * PNG. 8635fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp */ 86360e8ea19baa0666ccfe869d19116372f60fe9230fglennrp if (mng_info->ping_exclude_tRNS != MagickFalse && 86370e8ea19baa0666ccfe869d19116372f60fe9230fglennrp (number_transparent != 0 || number_semitransparent != 0)) 86380e8ea19baa0666ccfe869d19116372f60fe9230fglennrp { 8639d17915c2c5a29b7f778217765f0f2d354c829e9eglennrp unsigned int colortype=mng_info->write_png_colortype; 86400e8ea19baa0666ccfe869d19116372f60fe9230fglennrp 86410e8ea19baa0666ccfe869d19116372f60fe9230fglennrp if (ping_have_color == MagickFalse) 86420e8ea19baa0666ccfe869d19116372f60fe9230fglennrp mng_info->write_png_colortype = 5; 86430e8ea19baa0666ccfe869d19116372f60fe9230fglennrp 86440e8ea19baa0666ccfe869d19116372f60fe9230fglennrp else 86450e8ea19baa0666ccfe869d19116372f60fe9230fglennrp mng_info->write_png_colortype = 7; 86460e8ea19baa0666ccfe869d19116372f60fe9230fglennrp 86478d579660c9b96b7a3f3292fc6c518f8b6ca44d50glennrp if (colortype != 0 && 8648d17915c2c5a29b7f778217765f0f2d354c829e9eglennrp mng_info->write_png_colortype != colortype) 86490e8ea19baa0666ccfe869d19116372f60fe9230fglennrp ping_need_colortype_warning=MagickTrue; 86500b206f5daa453dc1035db5890cabc899736dc2d0glennrp 86510e8ea19baa0666ccfe869d19116372f60fe9230fglennrp } 86520e8ea19baa0666ccfe869d19116372f60fe9230fglennrp 8653fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp /* See if cheap transparency is possible. It is only possible 8654fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp * when there is a single transparent color, no semitransparent 8655fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp * color, and no opaque color that has the same RGB components 86565a39f3714559b4d9c08beb391ce4326354bb0f0cglennrp * as the transparent color. We only need this information if 86575a39f3714559b4d9c08beb391ce4326354bb0f0cglennrp * we are writing a PNG with colortype 0 or 2, and we have not 86585a39f3714559b4d9c08beb391ce4326354bb0f0cglennrp * excluded the tRNS chunk. 8659fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp */ 86605a39f3714559b4d9c08beb391ce4326354bb0f0cglennrp if (number_transparent == 1 && 86615a39f3714559b4d9c08beb391ce4326354bb0f0cglennrp mng_info->write_png_colortype < 4) 8662fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp { 8663fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp ping_have_cheap_transparency = MagickTrue; 8664fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp 8665fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp if (number_semitransparent != 0) 8666fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp ping_have_cheap_transparency = MagickFalse; 8667fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp 8668fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp else if (image_colors == 0 || image_colors > 256 || 8669fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp image->colormap == NULL) 8670fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp { 8671fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp ExceptionInfo 8672fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp *exception; 8673fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp 86744c08aed51c5899665ade97263692328eea4af106cristy register const Quantum 8675fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp *q; 8676fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp 8677fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp exception=(&image->exception); 8678fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp 8679fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp for (y=0; y < (ssize_t) image->rows; y++) 8680fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp { 8681fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp q=GetVirtualPixels(image,0,y,image->columns,1, exception); 8682fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp 86834c08aed51c5899665ade97263692328eea4af106cristy if (q == (const Quantum *) NULL) 8684fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp break; 8685fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp 8686fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp for (x=0; x < (ssize_t) image->columns; x++) 8687fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp { 86884c08aed51c5899665ade97263692328eea4af106cristy if (GetPixelAlpha(image,q) != TransparentAlpha && 8689847370c32c6b67817205f49897c43c540fd670c4glennrp (unsigned short) GetPixelRed(image,q) == 8690847370c32c6b67817205f49897c43c540fd670c4glennrp ping_trans_color.red && 8691847370c32c6b67817205f49897c43c540fd670c4glennrp (unsigned short) GetPixelGreen(image,q) == 8692847370c32c6b67817205f49897c43c540fd670c4glennrp ping_trans_color.green && 8693847370c32c6b67817205f49897c43c540fd670c4glennrp (unsigned short) GetPixelBlue(image,q) == 8694847370c32c6b67817205f49897c43c540fd670c4glennrp ping_trans_color.blue) 8695fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp { 8696fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp ping_have_cheap_transparency = MagickFalse; 8697fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp break; 8698fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp } 8699fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp 87004c08aed51c5899665ade97263692328eea4af106cristy q+=GetPixelChannels(image); 8701fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp } 8702bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp 8703fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp if (ping_have_cheap_transparency == MagickFalse) 8704fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp break; 8705fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp } 8706fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp } 8707fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp else 8708fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp { 870967b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp /* Assuming that image->colormap[0] is the one transparent color 871067b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp * and that all others are opaque. 871167b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp */ 8712fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp if (image_colors > 1) 871367b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp for (i=1; i<image_colors; i++) 871467b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp if (image->colormap[i].red == image->colormap[0].red && 871567b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp image->colormap[i].green == image->colormap[0].green && 871667b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp image->colormap[i].blue == image->colormap[0].blue) 8717fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp { 871867b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp ping_have_cheap_transparency = MagickFalse; 871967b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp break; 8720fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp } 8721fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp } 8722bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp 8723fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp if (logging != MagickFalse) 8724fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp { 8725fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp if (ping_have_cheap_transparency == MagickFalse) 8726fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8727fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp " Cheap transparency is not possible."); 8728fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp 8729fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp else 8730fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8731fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp " Cheap transparency is possible."); 8732fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp } 8733fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp } 8734fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp else 8735fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp ping_have_cheap_transparency = MagickFalse; 8736fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp 87373c21811cab8a3b168295e3f0da1909c4e2a7da15glennrp image_depth=image->depth; 87383c21811cab8a3b168295e3f0da1909c4e2a7da15glennrp 87393c21811cab8a3b168295e3f0da1909c4e2a7da15glennrp quantum_info = (QuantumInfo *) NULL; 87403c21811cab8a3b168295e3f0da1909c4e2a7da15glennrp number_colors=0; 8741f09bdedccf9ca10bc002a946227df3367cb58d14glennrp image_colors=(int) image->colors; 87423c21811cab8a3b168295e3f0da1909c4e2a7da15glennrp image_matte=image->matte; 874383c2de583a59e41b57be8036d1cf7392c01d03d7glennrp 87440fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp mng_info->IsPalette=image->storage_class == PseudoClass && 87451273f7b031edcb07e2ee4835455712ebdd0b2f60glennrp image_colors <= 256 && image->colormap != NULL; 87463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 874752a479ca718756af72f96e127f8256499ab68f76glennrp if ((mng_info->write_png_colortype == 4 || mng_info->write_png8) && 874852a479ca718756af72f96e127f8256499ab68f76glennrp (image->colors == 0 || image->colormap == NULL)) 874952a479ca718756af72f96e127f8256499ab68f76glennrp { 875052a479ca718756af72f96e127f8256499ab68f76glennrp image_info=DestroyImageInfo(image_info); 875152a479ca718756af72f96e127f8256499ab68f76glennrp image=DestroyImage(image); 875215e0155e1d2502703b937a3454bd7907e6fd8dc7glennrp (void) ThrowMagickException(&IMimage->exception, 875315e0155e1d2502703b937a3454bd7907e6fd8dc7glennrp GetMagickModule(),CoderError, 875415e0155e1d2502703b937a3454bd7907e6fd8dc7glennrp "Cannot write PNG8 or color-type 3; colormap is NULL", 875515e0155e1d2502703b937a3454bd7907e6fd8dc7glennrp "`%s'",IMimage->filename); 875652a479ca718756af72f96e127f8256499ab68f76glennrp#if defined(PNG_SETJMP_NOT_THREAD_SAFE) 875752a479ca718756af72f96e127f8256499ab68f76glennrp UnlockSemaphoreInfo(ping_semaphore); 875852a479ca718756af72f96e127f8256499ab68f76glennrp#endif 875952a479ca718756af72f96e127f8256499ab68f76glennrp return(MagickFalse); 876052a479ca718756af72f96e127f8256499ab68f76glennrp } 876152a479ca718756af72f96e127f8256499ab68f76glennrp 87623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 87633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Allocate the PNG structures 87643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 87653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#ifdef PNG_USER_MEM_SUPPORTED 87663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ping=png_create_write_struct_2(PNG_LIBPNG_VER_STRING,image, 8767cf002022280cc4dedb2748ad6f415aac1d44f530glennrp MagickPNGErrorHandler,MagickPNGWarningHandler,(void *) NULL, 8768cf002022280cc4dedb2748ad6f415aac1d44f530glennrp (png_malloc_ptr) Magick_png_malloc,(png_free_ptr) Magick_png_free); 87690fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 87703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#else 87713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ping=png_create_write_struct(PNG_LIBPNG_VER_STRING,image, 8772cf002022280cc4dedb2748ad6f415aac1d44f530glennrp MagickPNGErrorHandler,MagickPNGWarningHandler); 87730fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 87743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 87753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (ping == (png_struct *) NULL) 87763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); 87770fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 87783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ping_info=png_create_info_struct(ping); 87790fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 87803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (ping_info == (png_info *) NULL) 87813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 87823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_destroy_write_struct(&ping,(png_info **) NULL); 87833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); 87843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 87850fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 87863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_set_write_fn(ping,image,png_put_data,png_flush_data); 8787cf002022280cc4dedb2748ad6f415aac1d44f530glennrp ping_pixels=(unsigned char *) NULL; 87883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 87895af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp if (setjmp(png_jmpbuf(ping))) 87903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 87913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 87923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNG write failed. 87933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 87943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#ifdef PNG_DEBUG 87953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image_info->verbose) 87963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) printf("PNG write has failed.\n"); 87973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 87983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_destroy_write_struct(&ping,&ping_info); 87993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(PNG_SETJMP_NOT_THREAD_SAFE) 8800cf002022280cc4dedb2748ad6f415aac1d44f530glennrp UnlockSemaphoreInfo(ping_semaphore); 88013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 8802da8f3a7bfddac2680a3069a490db541e7944edafglennrp if (ping_have_blob != MagickFalse) 8803b9cfe27bef51dbbd1f05aef89c767749d7e37864glennrp (void) CloseBlob(image); 8804b9cfe27bef51dbbd1f05aef89c767749d7e37864glennrp image_info=DestroyImageInfo(image_info); 8805b9cfe27bef51dbbd1f05aef89c767749d7e37864glennrp image=DestroyImage(image); 88063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(MagickFalse); 88073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 88083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 88093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Prepare PNG for writing. 88103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 88113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(PNG_MNG_FEATURES_SUPPORTED) 88123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->write_mng) 88133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) png_permit_mng_features(ping,PNG_ALL_MNG_FEATURES); 88142b013e4b9b602533eff410e61c3683fb2a3ab913glennrp 88153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#else 88163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy# ifdef PNG_WRITE_EMPTY_PLTE_SUPPORTED 88173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->write_mng) 88183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_permit_empty_plte(ping,MagickTrue); 88192b013e4b9b602533eff410e61c3683fb2a3ab913glennrp 88203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy# endif 88213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 88222b013e4b9b602533eff410e61c3683fb2a3ab913glennrp 88233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy x=0; 88242b013e4b9b602533eff410e61c3683fb2a3ab913glennrp 88254e5bc84ff8bf274c4d9206d5e6ffd1a5e5d75335cristy ping_width=(png_uint_32) image->columns; 88264e5bc84ff8bf274c4d9206d5e6ffd1a5e5d75335cristy ping_height=(png_uint_32) image->rows; 88272b013e4b9b602533eff410e61c3683fb2a3ab913glennrp 88283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->write_png8 || mng_info->write_png24 || mng_info->write_png32) 88293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image_depth=8; 88300fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 88313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->write_png_depth != 0) 88323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image_depth=mng_info->write_png_depth; 88330fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 88343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Adjust requested depth to next higher valid depth if necessary */ 88353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image_depth > 8) 88363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image_depth=16; 88370fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 88383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((image_depth > 4) && (image_depth < 8)) 88393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image_depth=8; 88400fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 88413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image_depth == 3) 88423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image_depth=4; 88430fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 88443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 88453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 88463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8847e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " width=%.20g",(double) ping_width); 88483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8849e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " height=%.20g",(double) ping_height); 88503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8851e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " image_matte=%.20g",(double) image->matte); 88523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 88538640fb5e9b1094f35f8beab436f81661b8a99448glennrp " image->depth=%.20g",(double) image->depth); 88543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 88558640fb5e9b1094f35f8beab436f81661b8a99448glennrp " Tentative ping_bit_depth=%.20g",(double) image_depth); 88563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 88578640fb5e9b1094f35f8beab436f81661b8a99448glennrp 88583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy save_image_depth=image_depth; 88595af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_bit_depth=(png_byte) save_image_depth; 8860dfd7080ae717c8ddb013b59958f2d0790f5e3145glennrp 886126f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp 88623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(PNG_pHYs_SUPPORTED) 886326f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp if (ping_exclude_pHYs == MagickFalse) 886426f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp { 88653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((image->x_resolution != 0) && (image->y_resolution != 0) && 88663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (!mng_info->write_mng || !mng_info->equal_physs)) 88673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 88680fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp if (logging != MagickFalse) 8869dfd7080ae717c8ddb013b59958f2d0790f5e3145glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8870dfd7080ae717c8ddb013b59958f2d0790f5e3145glennrp " Setting up pHYs chunk"); 88713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 88723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->units == PixelsPerInchResolution) 88733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 8874dfd7080ae717c8ddb013b59958f2d0790f5e3145glennrp ping_pHYs_unit_type=PNG_RESOLUTION_METER; 8875823b55c200d7fc1818ab539b036a9c24feaecda8glennrp ping_pHYs_x_resolution= 8876823b55c200d7fc1818ab539b036a9c24feaecda8glennrp (png_uint_32) ((100.0*image->x_resolution+0.5)/2.54); 8877823b55c200d7fc1818ab539b036a9c24feaecda8glennrp ping_pHYs_y_resolution= 8878823b55c200d7fc1818ab539b036a9c24feaecda8glennrp (png_uint_32) ((100.0*image->y_resolution+0.5)/2.54); 88793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 8880dfd7080ae717c8ddb013b59958f2d0790f5e3145glennrp 88813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else if (image->units == PixelsPerCentimeterResolution) 88823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 8883dfd7080ae717c8ddb013b59958f2d0790f5e3145glennrp ping_pHYs_unit_type=PNG_RESOLUTION_METER; 8884823b55c200d7fc1818ab539b036a9c24feaecda8glennrp ping_pHYs_x_resolution=(png_uint_32) (100.0*image->x_resolution+0.5); 8885823b55c200d7fc1818ab539b036a9c24feaecda8glennrp ping_pHYs_y_resolution=(png_uint_32) (100.0*image->y_resolution+0.5); 88863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 8887991d11dd9c33e65872778b81aff1347cd2878154glennrp 88883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 88893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 8890dfd7080ae717c8ddb013b59958f2d0790f5e3145glennrp ping_pHYs_unit_type=PNG_RESOLUTION_UNKNOWN; 8891dfd7080ae717c8ddb013b59958f2d0790f5e3145glennrp ping_pHYs_x_resolution=(png_uint_32) image->x_resolution; 8892dfd7080ae717c8ddb013b59958f2d0790f5e3145glennrp ping_pHYs_y_resolution=(png_uint_32) image->y_resolution; 88933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 8894991d11dd9c33e65872778b81aff1347cd2878154glennrp 8895823b55c200d7fc1818ab539b036a9c24feaecda8glennrp if (logging != MagickFalse) 8896823b55c200d7fc1818ab539b036a9c24feaecda8glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8897823b55c200d7fc1818ab539b036a9c24feaecda8glennrp " Set up PNG pHYs chunk: xres: %.20g, yres: %.20g, units: %d.", 8898823b55c200d7fc1818ab539b036a9c24feaecda8glennrp (double) ping_pHYs_x_resolution,(double) ping_pHYs_y_resolution, 8899823b55c200d7fc1818ab539b036a9c24feaecda8glennrp (int) ping_pHYs_unit_type); 8900991d11dd9c33e65872778b81aff1347cd2878154glennrp ping_have_pHYs = MagickTrue; 89013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 890226f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp } 89033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 8904a521b2fe1f4c8b8ab9412bd6ef23b6736b90e43dglennrp 890526f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp if (ping_exclude_bKGD == MagickFalse) 890626f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp { 8907a521b2fe1f4c8b8ab9412bd6ef23b6736b90e43dglennrp if ((!mng_info->adjoin || !mng_info->equal_backgrounds)) 89083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 8909a521b2fe1f4c8b8ab9412bd6ef23b6736b90e43dglennrp unsigned int 8910a521b2fe1f4c8b8ab9412bd6ef23b6736b90e43dglennrp mask; 8911a521b2fe1f4c8b8ab9412bd6ef23b6736b90e43dglennrp 8912a521b2fe1f4c8b8ab9412bd6ef23b6736b90e43dglennrp mask=0xffff; 8913a521b2fe1f4c8b8ab9412bd6ef23b6736b90e43dglennrp if (ping_bit_depth == 8) 8914a521b2fe1f4c8b8ab9412bd6ef23b6736b90e43dglennrp mask=0x00ff; 89150fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 8916a521b2fe1f4c8b8ab9412bd6ef23b6736b90e43dglennrp if (ping_bit_depth == 4) 8917a521b2fe1f4c8b8ab9412bd6ef23b6736b90e43dglennrp mask=0x000f; 89180fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 8919a521b2fe1f4c8b8ab9412bd6ef23b6736b90e43dglennrp if (ping_bit_depth == 2) 8920a521b2fe1f4c8b8ab9412bd6ef23b6736b90e43dglennrp mask=0x0003; 89210fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 8922a521b2fe1f4c8b8ab9412bd6ef23b6736b90e43dglennrp if (ping_bit_depth == 1) 8923a521b2fe1f4c8b8ab9412bd6ef23b6736b90e43dglennrp mask=0x0001; 89240fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 8925a521b2fe1f4c8b8ab9412bd6ef23b6736b90e43dglennrp ping_background.red=(png_uint_16) 8926a521b2fe1f4c8b8ab9412bd6ef23b6736b90e43dglennrp (ScaleQuantumToShort(image->background_color.red) & mask); 89270fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 8928a521b2fe1f4c8b8ab9412bd6ef23b6736b90e43dglennrp ping_background.green=(png_uint_16) 8929a521b2fe1f4c8b8ab9412bd6ef23b6736b90e43dglennrp (ScaleQuantumToShort(image->background_color.green) & mask); 89300fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 8931a521b2fe1f4c8b8ab9412bd6ef23b6736b90e43dglennrp ping_background.blue=(png_uint_16) 8932a521b2fe1f4c8b8ab9412bd6ef23b6736b90e43dglennrp (ScaleQuantumToShort(image->background_color.blue) & mask); 8933c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp 8934c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp ping_background.gray=(png_uint_16) ping_background.green; 89350fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp } 89360fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 89370fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp if (logging != MagickFalse) 89383b51f0e7f4f7cce3e7466784c8b4e5dac9f55741glennrp { 89393b51f0e7f4f7cce3e7466784c8b4e5dac9f55741glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 89403b51f0e7f4f7cce3e7466784c8b4e5dac9f55741glennrp " Setting up bKGD chunk (1)"); 8941c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8942c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp " background_color index is %d", 8943c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp (int) ping_background.index); 89443b51f0e7f4f7cce3e7466784c8b4e5dac9f55741glennrp 89453b51f0e7f4f7cce3e7466784c8b4e5dac9f55741glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 89463b51f0e7f4f7cce3e7466784c8b4e5dac9f55741glennrp " ping_bit_depth=%d",ping_bit_depth); 89473b51f0e7f4f7cce3e7466784c8b4e5dac9f55741glennrp } 89480fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 89490fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp ping_have_bKGD = MagickTrue; 895026f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp } 89513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 89523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 89533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Select the color type. 89543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 89553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy matte=image_matte; 89563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy old_bit_depth=0; 89570fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 89581273f7b031edcb07e2ee4835455712ebdd0b2f60glennrp if (mng_info->IsPalette && mng_info->write_png8) 89593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 89600fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 8961fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp /* To do: make this a function cause it's used twice, except 89620fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp for reducing the sample depth from 8. */ 89630fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 89640fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp number_colors=image_colors; 89658bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp 89668bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp ping_have_tRNS=MagickFalse; 89670fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 89680fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp /* 89690fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp Set image palette. 89700fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp */ 89710fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp ping_color_type=(png_byte) PNG_COLOR_TYPE_PALETTE; 89720fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 89730fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp if (logging != MagickFalse) 89740fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 89750fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp " Setting up PLTE chunk with %d colors (%d)", 8976f09bdedccf9ca10bc002a946227df3367cb58d14glennrp number_colors, image_colors); 89770fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 89780fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp for (i=0; i < (ssize_t) number_colors; i++) 89790fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp { 89800fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp palette[i].red=ScaleQuantumToChar(image->colormap[i].red); 89810fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp palette[i].green=ScaleQuantumToChar(image->colormap[i].green); 89820fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp palette[i].blue=ScaleQuantumToChar(image->colormap[i].blue); 89830fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp if (logging != MagickFalse) 89840fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 898567b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp#if MAGICKCORE_QUANTUM_DEPTH == 8 89860fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp " %3ld (%3d,%3d,%3d)", 898767b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp#else 898867b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp " %5ld (%5d,%5d,%5d)", 898967b9c1a76a0be5ad88b138c4f46dd860b272e1bcglennrp#endif 89900fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp (long) i,palette[i].red,palette[i].green,palette[i].blue); 89913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 89920fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp } 89932b013e4b9b602533eff410e61c3683fb2a3ab913glennrp 89948bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp ping_have_PLTE=MagickTrue; 89958bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp image_depth=ping_bit_depth; 89968bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp ping_num_trans=0; 89975af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp 899858e017631f66141a6e36ddbe03a54f6e3ee3a253glennrp if (matte != MagickFalse) 89998bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp { 90000fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp /* 90010fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp Identify which colormap entry is transparent. 90020fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp */ 90030fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp assert(number_colors <= 256); 90048bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp assert(image->colormap != NULL); 90053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 90068bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp for (i=0; i < (ssize_t) number_transparent; i++) 90078bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp ping_trans_alpha[i]=0; 90080fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 90090fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 90102cc891a179d622dde7bbb8854138851e828bc6eaglennrp ping_num_trans=(unsigned short) (number_transparent + 90118bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp number_semitransparent); 90120fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 90130fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp if (ping_num_trans == 0) 90140fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp ping_have_tRNS=MagickFalse; 90150fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 90168bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp else 90178bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp ping_have_tRNS=MagickTrue; 90188bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp } 90190fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 90201273f7b031edcb07e2ee4835455712ebdd0b2f60glennrp if (ping_exclude_bKGD == MagickFalse) 90214f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp { 90221273f7b031edcb07e2ee4835455712ebdd0b2f60glennrp /* 90231273f7b031edcb07e2ee4835455712ebdd0b2f60glennrp * Identify which colormap entry is the background color. 90241273f7b031edcb07e2ee4835455712ebdd0b2f60glennrp */ 90251273f7b031edcb07e2ee4835455712ebdd0b2f60glennrp 90264f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp for (i=0; i < (ssize_t) MagickMax(1L*number_colors-1L,1L); i++) 90274f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp if (IsPNGColorEqual(ping_background,image->colormap[i])) 90284f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp break; 90290fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 90304f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp ping_background.index=(png_byte) i; 9031c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp 9032c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp if (logging != MagickFalse) 9033c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp { 9034c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 9035c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp " background_color index is %d", 9036c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp (int) ping_background.index); 9037c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp } 90384f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp } 90393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } /* end of write_png8 */ 90400fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 90413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else if (mng_info->write_png24) 90423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 90433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image_matte=MagickFalse; 90445af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_color_type=(png_byte) PNG_COLOR_TYPE_RGB; 90453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 90460fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 90473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else if (mng_info->write_png32) 90483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 90493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image_matte=MagickTrue; 90505af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_color_type=(png_byte) PNG_COLOR_TYPE_RGB_ALPHA; 90513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 90520fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 90538bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp else /* mng_info->write_pngNN not specified */ 90543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 90555af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp image_depth=ping_bit_depth; 90560fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 90578bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp if (mng_info->write_png_colortype != 0) 90583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 90595af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_color_type=(png_byte) mng_info->write_png_colortype-1; 90600fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 90615af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp if (ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA || 90625af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_color_type == PNG_COLOR_TYPE_RGB_ALPHA) 90633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image_matte=MagickTrue; 90642cc891a179d622dde7bbb8854138851e828bc6eaglennrp 90658bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp else 90668bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp image_matte=MagickFalse; 90677c4c9e67499f5a8e5cfd4148a3424bacd8fc635bglennrp 90687c4c9e67499f5a8e5cfd4148a3424bacd8fc635bglennrp if (logging != MagickFalse) 90697c4c9e67499f5a8e5cfd4148a3424bacd8fc635bglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 90707c4c9e67499f5a8e5cfd4148a3424bacd8fc635bglennrp " PNG colortype %d was specified:",(int) ping_color_type); 90713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 90720fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 90737c4c9e67499f5a8e5cfd4148a3424bacd8fc635bglennrp else /* write_png_colortype not specified */ 90743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 90753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 90763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 90773c21811cab8a3b168295e3f0da1909c4e2a7da15glennrp " Selecting PNG colortype:"); 90780fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 9079d6bf1617e99df0272b231855a933a74e99b6578fglennrp ping_color_type=(png_byte) ((matte != MagickFalse)? 90808bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp PNG_COLOR_TYPE_RGB_ALPHA:PNG_COLOR_TYPE_RGB); 90810fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 9082d6bf1617e99df0272b231855a933a74e99b6578fglennrp if (image_info->type == TrueColorType) 90833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 90845af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_color_type=(png_byte) PNG_COLOR_TYPE_RGB; 90853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image_matte=MagickFalse; 90863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 90870fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 9088d6bf1617e99df0272b231855a933a74e99b6578fglennrp if (image_info->type == TrueColorMatteType) 90893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 90905af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_color_type=(png_byte) PNG_COLOR_TYPE_RGB_ALPHA; 90913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image_matte=MagickTrue; 90923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 90930fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 90945aa37f69df93407ddf94afdfd2504f708d8b3242glennrp if (image_info->type == PaletteType || 90955aa37f69df93407ddf94afdfd2504f708d8b3242glennrp image_info->type == PaletteMatteType) 90965aa37f69df93407ddf94afdfd2504f708d8b3242glennrp ping_color_type=(png_byte) PNG_COLOR_TYPE_PALETTE; 90975aa37f69df93407ddf94afdfd2504f708d8b3242glennrp 90987c4c9e67499f5a8e5cfd4148a3424bacd8fc635bglennrp if (mng_info->write_png_colortype == 0 && 90997c4c9e67499f5a8e5cfd4148a3424bacd8fc635bglennrp (image_info->type == UndefinedType || 91007c4c9e67499f5a8e5cfd4148a3424bacd8fc635bglennrp image_info->type == OptimizeType)) 91013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 91025aa37f69df93407ddf94afdfd2504f708d8b3242glennrp if (ping_have_color == MagickFalse) 91038bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp { 91045aa37f69df93407ddf94afdfd2504f708d8b3242glennrp if (image_matte == MagickFalse) 91055aa37f69df93407ddf94afdfd2504f708d8b3242glennrp { 91065aa37f69df93407ddf94afdfd2504f708d8b3242glennrp ping_color_type=(png_byte) PNG_COLOR_TYPE_GRAY; 91075aa37f69df93407ddf94afdfd2504f708d8b3242glennrp image_matte=MagickFalse; 91085aa37f69df93407ddf94afdfd2504f708d8b3242glennrp } 91090fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 91100b206f5daa453dc1035db5890cabc899736dc2d0glennrp else 91115aa37f69df93407ddf94afdfd2504f708d8b3242glennrp { 91125aa37f69df93407ddf94afdfd2504f708d8b3242glennrp ping_color_type=(png_byte) PNG_COLOR_TYPE_GRAY_ALPHA; 91135aa37f69df93407ddf94afdfd2504f708d8b3242glennrp image_matte=MagickTrue; 91145aa37f69df93407ddf94afdfd2504f708d8b3242glennrp } 91158bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp } 91165aa37f69df93407ddf94afdfd2504f708d8b3242glennrp else 91175aa37f69df93407ddf94afdfd2504f708d8b3242glennrp { 91185aa37f69df93407ddf94afdfd2504f708d8b3242glennrp if (image_matte == MagickFalse) 91195aa37f69df93407ddf94afdfd2504f708d8b3242glennrp { 91205aa37f69df93407ddf94afdfd2504f708d8b3242glennrp ping_color_type=(png_byte) PNG_COLOR_TYPE_RGB; 91215aa37f69df93407ddf94afdfd2504f708d8b3242glennrp image_matte=MagickFalse; 91225aa37f69df93407ddf94afdfd2504f708d8b3242glennrp } 91238bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp 91240b206f5daa453dc1035db5890cabc899736dc2d0glennrp else 91255aa37f69df93407ddf94afdfd2504f708d8b3242glennrp { 91265aa37f69df93407ddf94afdfd2504f708d8b3242glennrp ping_color_type=(png_byte) PNG_COLOR_TYPE_RGBA; 91275aa37f69df93407ddf94afdfd2504f708d8b3242glennrp image_matte=MagickTrue; 91285aa37f69df93407ddf94afdfd2504f708d8b3242glennrp } 91295aa37f69df93407ddf94afdfd2504f708d8b3242glennrp } 91300fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp } 91315aa37f69df93407ddf94afdfd2504f708d8b3242glennrp 91323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 91330fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 91343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 913526c990a974947ce90bfb1d08bcd8794bf85f7a65glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 91368640fb5e9b1094f35f8beab436f81661b8a99448glennrp " Selected PNG colortype=%d",ping_color_type); 913726c990a974947ce90bfb1d08bcd8794bf85f7a65glennrp 91385af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp if (ping_bit_depth < 8) 91390fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp { 91400fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp if (ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA || 91410fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp ping_color_type == PNG_COLOR_TYPE_RGB || 91420fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp ping_color_type == PNG_COLOR_TYPE_RGB_ALPHA) 91430fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp ping_bit_depth=8; 91440fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp } 91453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 9146d6bf1617e99df0272b231855a933a74e99b6578fglennrp old_bit_depth=ping_bit_depth; 9147d6bf1617e99df0272b231855a933a74e99b6578fglennrp 91485af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp if (ping_color_type == PNG_COLOR_TYPE_GRAY) 91493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 91508d579660c9b96b7a3f3292fc6c518f8b6ca44d50glennrp if (image->matte == MagickFalse && ping_have_non_bw == MagickFalse) 91518d579660c9b96b7a3f3292fc6c518f8b6ca44d50glennrp ping_bit_depth=1; 91523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 91538640fb5e9b1094f35f8beab436f81661b8a99448glennrp 91545af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp if (ping_color_type == PNG_COLOR_TYPE_PALETTE) 91553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 915635ef824baa82511126ff0072ae30eee0da9c05a3cristy size_t one = 1; 91575af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_bit_depth=1; 91580f111984738842d27d04aed2a3f823d82a943506glennrp 91590f111984738842d27d04aed2a3f823d82a943506glennrp if (image->colors == 0) 91600f111984738842d27d04aed2a3f823d82a943506glennrp { 91610fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp /* DO SOMETHING */ 9162c70af4ac292f8db9a1ab488318912894d412cb8cglennrp (void) ThrowMagickException(&image->exception, 91630f111984738842d27d04aed2a3f823d82a943506glennrp GetMagickModule(),CoderError, 9164c70af4ac292f8db9a1ab488318912894d412cb8cglennrp "image has 0 colors", "`%s'",""); 91650f111984738842d27d04aed2a3f823d82a943506glennrp } 91660f111984738842d27d04aed2a3f823d82a943506glennrp 916735ef824baa82511126ff0072ae30eee0da9c05a3cristy while ((int) (one << ping_bit_depth) < (ssize_t) image_colors) 91685af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_bit_depth <<= 1; 9169d6bf1617e99df0272b231855a933a74e99b6578fglennrp } 91703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 9171d6bf1617e99df0272b231855a933a74e99b6578fglennrp if (logging != MagickFalse) 9172d6bf1617e99df0272b231855a933a74e99b6578fglennrp { 9173d6bf1617e99df0272b231855a933a74e99b6578fglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 9174d6bf1617e99df0272b231855a933a74e99b6578fglennrp " Number of colors: %.20g",(double) image_colors); 91750fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 9176d6bf1617e99df0272b231855a933a74e99b6578fglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 9177d6bf1617e99df0272b231855a933a74e99b6578fglennrp " Tentative PNG bit depth: %d",ping_bit_depth); 9178d6bf1617e99df0272b231855a933a74e99b6578fglennrp } 91790fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 9180d6bf1617e99df0272b231855a933a74e99b6578fglennrp if (ping_bit_depth < (int) mng_info->write_png_depth) 9181d6bf1617e99df0272b231855a933a74e99b6578fglennrp ping_bit_depth = mng_info->write_png_depth; 91823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 91832cc891a179d622dde7bbb8854138851e828bc6eaglennrp 91845af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp image_depth=ping_bit_depth; 91852b013e4b9b602533eff410e61c3683fb2a3ab913glennrp 91863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 91873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 91883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 9189e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " Tentative PNG color type: %.20g",(double) ping_color_type); 91900fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 91913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 9192e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " image_info->type: %.20g",(double) image_info->type); 91930fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 91943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 9195e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " image_depth: %.20g",(double) image_depth); 91960fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 91973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 91983c21811cab8a3b168295e3f0da1909c4e2a7da15glennrp 91998640fb5e9b1094f35f8beab436f81661b8a99448glennrp " image->depth: %.20g",(double) image->depth); 92008640fb5e9b1094f35f8beab436f81661b8a99448glennrp 92018640fb5e9b1094f35f8beab436f81661b8a99448glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 9202e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " ping_bit_depth: %.20g",(double) ping_bit_depth); 92033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 92043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 920558e017631f66141a6e36ddbe03a54f6e3ee3a253glennrp if (matte != MagickFalse) 92063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 92074f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp if (mng_info->IsPalette) 92084f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp { 92097c4c9e67499f5a8e5cfd4148a3424bacd8fc635bglennrp if (mng_info->write_png_colortype == 0) 92107c4c9e67499f5a8e5cfd4148a3424bacd8fc635bglennrp { 92117c4c9e67499f5a8e5cfd4148a3424bacd8fc635bglennrp ping_color_type=PNG_COLOR_TYPE_GRAY_ALPHA; 92122b013e4b9b602533eff410e61c3683fb2a3ab913glennrp 92137c4c9e67499f5a8e5cfd4148a3424bacd8fc635bglennrp if (ping_have_color != MagickFalse) 92147c4c9e67499f5a8e5cfd4148a3424bacd8fc635bglennrp ping_color_type=PNG_COLOR_TYPE_RGBA; 92157c4c9e67499f5a8e5cfd4148a3424bacd8fc635bglennrp } 92162b013e4b9b602533eff410e61c3683fb2a3ab913glennrp 92173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 92184f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp * Determine if there is any transparent color. 92193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 92204f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp if (number_transparent + number_semitransparent == 0) 92214f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp { 92224f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp /* 92234f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp No transparent pixels are present. Change 4 or 6 to 0 or 2. 92244f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp */ 9225a6a0663bea94c73cf424f0b49076e7c037d084d4glennrp 92264f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp image_matte=MagickFalse; 92277c4c9e67499f5a8e5cfd4148a3424bacd8fc635bglennrp 92287c4c9e67499f5a8e5cfd4148a3424bacd8fc635bglennrp if (mng_info->write_png_colortype == 0) 92297c4c9e67499f5a8e5cfd4148a3424bacd8fc635bglennrp ping_color_type&=0x03; 92304f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp } 92310fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 92324f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp else 92334f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp { 92344f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp unsigned int 9235bb4f99d3d6ed6a8eee38324baf473c45e4f644e4glennrp mask; 92363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 92374f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp mask=0xffff; 92380fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 92394f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp if (ping_bit_depth == 8) 92404f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp mask=0x00ff; 92410fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 92424f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp if (ping_bit_depth == 4) 92434f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp mask=0x000f; 92440fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 92454f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp if (ping_bit_depth == 2) 92464f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp mask=0x0003; 92470fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 92484f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp if (ping_bit_depth == 1) 92494f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp mask=0x0001; 92500fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 92514f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp ping_trans_color.red=(png_uint_16) 92524f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp (ScaleQuantumToShort(image->colormap[0].red) & mask); 92530fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 92544f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp ping_trans_color.green=(png_uint_16) 92554f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp (ScaleQuantumToShort(image->colormap[0].green) & mask); 92560fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 92574f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp ping_trans_color.blue=(png_uint_16) 92584f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp (ScaleQuantumToShort(image->colormap[0].blue) & mask); 92590fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 92604f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp ping_trans_color.gray=(png_uint_16) 92614c08aed51c5899665ade97263692328eea4af106cristy (ScaleQuantumToShort(GetPixelPacketIntensity( 92624f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp image->colormap)) & mask); 92630fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 92644f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp ping_trans_color.index=(png_byte) 0; 92650fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 92664f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp ping_have_tRNS=MagickTrue; 92674f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp } 92680fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 92694f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp if (ping_have_tRNS != MagickFalse) 92704f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp { 92714f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp /* 9272fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp * Determine if there is one and only one transparent color 9273fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp * and if so if it is fully transparent. 9274fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp */ 9275fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp if (ping_have_cheap_transparency == MagickFalse) 9276fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp ping_have_tRNS=MagickFalse; 92774f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp } 92782b013e4b9b602533eff410e61c3683fb2a3ab913glennrp 92794f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp if (ping_have_tRNS != MagickFalse) 92804f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp { 92817c4c9e67499f5a8e5cfd4148a3424bacd8fc635bglennrp if (mng_info->write_png_colortype == 0) 92827c4c9e67499f5a8e5cfd4148a3424bacd8fc635bglennrp ping_color_type &= 0x03; /* changes 4 or 6 to 0 or 2 */ 92830fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 92844f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp if (image_depth == 8) 92854f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp { 92864f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp ping_trans_color.red&=0xff; 92874f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp ping_trans_color.green&=0xff; 92884f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp ping_trans_color.blue&=0xff; 92894f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp ping_trans_color.gray&=0xff; 92904f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp } 92914f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp } 92924f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp } 92934f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp else 92944f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp { 92953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image_depth == 8) 92963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 92975af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_trans_color.red&=0xff; 92985af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_trans_color.green&=0xff; 92995af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_trans_color.blue&=0xff; 93005af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_trans_color.gray&=0xff; 93013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 93023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 93033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 93048640fb5e9b1094f35f8beab436f81661b8a99448glennrp 93053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy matte=image_matte; 93060fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 93072e09f55407bbe197cbaf4f88b1d7265f62d7f6c7glennrp if (ping_have_tRNS != MagickFalse) 93083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image_matte=MagickFalse; 93090fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 931039992b4dd9b12ef752d55b8e402c069698851f72glennrp if ((mng_info->IsPalette) && 93113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->write_png_colortype-1 != PNG_COLOR_TYPE_PALETTE && 93128d579660c9b96b7a3f3292fc6c518f8b6ca44d50glennrp ping_have_color == MagickFalse && 93138d579660c9b96b7a3f3292fc6c518f8b6ca44d50glennrp (image_matte == MagickFalse || image_depth >= 8)) 93143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 931535ef824baa82511126ff0072ae30eee0da9c05a3cristy size_t one=1; 93160fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 93173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image_matte != MagickFalse) 93189c1eb0729653219b9da9037e044501a6dce79d10glennrp ping_color_type=PNG_COLOR_TYPE_GRAY_ALPHA; 93190fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 93207c4c9e67499f5a8e5cfd4148a3424bacd8fc635bglennrp else if (mng_info->write_png_colortype-1 != PNG_COLOR_TYPE_GRAY_ALPHA) 93213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 93225af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_color_type=PNG_COLOR_TYPE_GRAY; 93234f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp 93243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (save_image_depth == 16 && image_depth == 8) 93254f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp { 93264f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp if (logging != MagickFalse) 93274f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp { 93284f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 93294f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp " Scaling ping_trans_color (0)"); 93304f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp } 93314f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp ping_trans_color.gray*=0x0101; 93324f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp } 93333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 93340fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 93353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image_depth > MAGICKCORE_QUANTUM_DEPTH) 93363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image_depth=MAGICKCORE_QUANTUM_DEPTH; 93370fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 9338136ee3aa5987c7418c835f7ee741e1af1dadb113glennrp if ((image_colors == 0) || 9339d17915c2c5a29b7f778217765f0f2d354c829e9eglennrp ((ssize_t) (image_colors-1) > (ssize_t) MaxColormapSize)) 9340f09bdedccf9ca10bc002a946227df3367cb58d14glennrp image_colors=(int) (one << image_depth); 93410fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 93423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image_depth > 8) 93435af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_bit_depth=16; 93440fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 93453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 93463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 93475af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_bit_depth=8; 93485af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp if ((int) ping_color_type == PNG_COLOR_TYPE_PALETTE) 93493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 93503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if(!mng_info->write_png_depth) 93513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 93525af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_bit_depth=1; 93530fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 935435ef824baa82511126ff0072ae30eee0da9c05a3cristy while ((int) (one << ping_bit_depth) 9355bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy < (ssize_t) image_colors) 93565af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_bit_depth <<= 1; 93573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 93583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 93592b013e4b9b602533eff410e61c3683fb2a3ab913glennrp 93600fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp else if (ping_color_type == 93610fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp PNG_COLOR_TYPE_GRAY && image_colors < 17 && 93623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->IsPalette) 93633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 93643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Check if grayscale is reducible */ 93651a0aaa639fb2360f2db93f9b0ed2b42ef6d2106dglennrp 93663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy int 93673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy depth_4_ok=MagickTrue, 93683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy depth_2_ok=MagickTrue, 93693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy depth_1_ok=MagickTrue; 93703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 9371bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (i=0; i < (ssize_t) image_colors; i++) 93723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 93733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy unsigned char 93743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy intensity; 93753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 93763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy intensity=ScaleQuantumToChar(image->colormap[i].red); 93773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 93783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((intensity & 0x0f) != ((intensity & 0xf0) >> 4)) 93793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy depth_4_ok=depth_2_ok=depth_1_ok=MagickFalse; 93803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else if ((intensity & 0x03) != ((intensity & 0x0c) >> 2)) 93813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy depth_2_ok=depth_1_ok=MagickFalse; 93824bf89731a90c6e03598950223e19e7be7b95d630glennrp else if ((intensity & 0x01) != ((intensity & 0x02) >> 1)) 93833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy depth_1_ok=MagickFalse; 93843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 93852b013e4b9b602533eff410e61c3683fb2a3ab913glennrp 93863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (depth_1_ok && mng_info->write_png_depth <= 1) 93879c1eb0729653219b9da9037e044501a6dce79d10glennrp ping_bit_depth=1; 93880fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 93893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else if (depth_2_ok && mng_info->write_png_depth <= 2) 93909c1eb0729653219b9da9037e044501a6dce79d10glennrp ping_bit_depth=2; 93910fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 93923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else if (depth_4_ok && mng_info->write_png_depth <= 4) 93939c1eb0729653219b9da9037e044501a6dce79d10glennrp ping_bit_depth=4; 93943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 93953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 93962b013e4b9b602533eff410e61c3683fb2a3ab913glennrp 93975af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp image_depth=ping_bit_depth; 93983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 93990fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 94003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 94010fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 94023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->IsPalette) 94033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 940417a1485544c62993fc7a94e343c87fed5f3e6407glennrp number_colors=image_colors; 940517a1485544c62993fc7a94e343c87fed5f3e6407glennrp 94063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image_depth <= 8) 94073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 94083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 94093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Set image palette. 94103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 94115af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_color_type=(png_byte) PNG_COLOR_TYPE_PALETTE; 94120fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 941358e017631f66141a6e36ddbe03a54f6e3ee3a253glennrp if (mng_info->have_write_global_plte && matte == MagickFalse) 94143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 94159c1eb0729653219b9da9037e044501a6dce79d10glennrp png_set_PLTE(ping,ping_info,NULL,0); 94160fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 94173b51f0e7f4f7cce3e7466784c8b4e5dac9f55741glennrp if (logging != MagickFalse) 94189c1eb0729653219b9da9037e044501a6dce79d10glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 94199c1eb0729653219b9da9037e044501a6dce79d10glennrp " Setting up empty PLTE chunk"); 94203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 94210fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 94223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 94233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 9424bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (i=0; i < (ssize_t) number_colors; i++) 94253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 94263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy palette[i].red=ScaleQuantumToChar(image->colormap[i].red); 94273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy palette[i].green=ScaleQuantumToChar(image->colormap[i].green); 94283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy palette[i].blue=ScaleQuantumToChar(image->colormap[i].blue); 94293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 94300fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 94313b51f0e7f4f7cce3e7466784c8b4e5dac9f55741glennrp if (logging != MagickFalse) 94323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 943398156a3a465a004545e39434c63052b955a74d1cglennrp " Setting up PLTE chunk with %d colors", 9434f09bdedccf9ca10bc002a946227df3367cb58d14glennrp number_colors); 94350fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 943639992b4dd9b12ef752d55b8e402c069698851f72glennrp ping_have_PLTE=MagickTrue; 94373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 94380fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 94393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* color_type is PNG_COLOR_TYPE_PALETTE */ 9440d6bf1617e99df0272b231855a933a74e99b6578fglennrp if (mng_info->write_png_depth == 0) 94413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 9442befe4d21bf21c8f8fb5c8cc01fe60fe4accac47fcristy size_t 9443befe4d21bf21c8f8fb5c8cc01fe60fe4accac47fcristy one; 9444befe4d21bf21c8f8fb5c8cc01fe60fe4accac47fcristy 94455af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_bit_depth=1; 9446befe4d21bf21c8f8fb5c8cc01fe60fe4accac47fcristy one=1; 94470fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 9448d17915c2c5a29b7f778217765f0f2d354c829e9eglennrp while ((one << ping_bit_depth) < (ssize_t) number_colors) 94495af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_bit_depth <<= 1; 94503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 94510fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 94525af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_num_trans=0; 94530fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 945458e017631f66141a6e36ddbe03a54f6e3ee3a253glennrp if (matte != MagickFalse) 94550fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp { 94560fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp /* 9457d6bf1617e99df0272b231855a933a74e99b6578fglennrp * Set up trans_colors array. 9458d6bf1617e99df0272b231855a933a74e99b6578fglennrp */ 94590fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp assert(number_colors <= 256); 94603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 9461d6bf1617e99df0272b231855a933a74e99b6578fglennrp ping_num_trans=(unsigned short) (number_transparent + 9462d6bf1617e99df0272b231855a933a74e99b6578fglennrp number_semitransparent); 94633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 94640fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp if (ping_num_trans == 0) 94650fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp ping_have_tRNS=MagickFalse; 94660fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 9467d6bf1617e99df0272b231855a933a74e99b6578fglennrp else 94680fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp { 9469c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp if (logging != MagickFalse) 9470c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp { 9471c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 9472c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp " Scaling ping_trans_color (1)"); 9473c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp } 9474d6bf1617e99df0272b231855a933a74e99b6578fglennrp ping_have_tRNS=MagickTrue; 9475d6bf1617e99df0272b231855a933a74e99b6578fglennrp 9476d6bf1617e99df0272b231855a933a74e99b6578fglennrp for (i=0; i < ping_num_trans; i++) 9477d6bf1617e99df0272b231855a933a74e99b6578fglennrp { 94784c08aed51c5899665ade97263692328eea4af106cristy ping_trans_alpha[i]= (png_byte) 94794c08aed51c5899665ade97263692328eea4af106cristy ScaleQuantumToChar(image->colormap[i].alpha); 9480d6bf1617e99df0272b231855a933a74e99b6578fglennrp } 94810fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp } 94820fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp } 94833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 94843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 94850fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 94863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 94873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 9488c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp 94893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image_depth < 8) 94903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image_depth=8; 94910fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 94923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((save_image_depth == 16) && (image_depth == 8)) 94933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 94944f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp if (logging != MagickFalse) 94954f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp { 94964f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 94974f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp " Scaling ping_trans_color from (%d,%d,%d)", 94984f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp (int) ping_trans_color.red, 94994f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp (int) ping_trans_color.green, 95004f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp (int) ping_trans_color.blue); 95014f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp } 95024f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp 95035af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_trans_color.red*=0x0101; 95045af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_trans_color.green*=0x0101; 95055af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_trans_color.blue*=0x0101; 95065af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_trans_color.gray*=0x0101; 95074f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp 95084f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp if (logging != MagickFalse) 95094f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp { 95104f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 95114f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp " to (%d,%d,%d)", 95124f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp (int) ping_trans_color.red, 95134f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp (int) ping_trans_color.green, 95144f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp (int) ping_trans_color.blue); 95154f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp } 95163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 95173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 95183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 95194383ec8c3c8811128f5a8a034d67c47db5e7e75acristy if (ping_bit_depth < (ssize_t) mng_info->write_png_depth) 95204383ec8c3c8811128f5a8a034d67c47db5e7e75acristy ping_bit_depth = (ssize_t) mng_info->write_png_depth; 95212cc891a179d622dde7bbb8854138851e828bc6eaglennrp 95223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 95233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Adjust background and transparency samples in sub-8-bit grayscale files. 95243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 95255af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp if (ping_bit_depth < 8 && ping_color_type == 95263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNG_COLOR_TYPE_GRAY) 95273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 95283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_uint_16 95293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy maxval; 95303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 953135ef824baa82511126ff0072ae30eee0da9c05a3cristy size_t 953235ef824baa82511126ff0072ae30eee0da9c05a3cristy one=1; 953335ef824baa82511126ff0072ae30eee0da9c05a3cristy 953422ffd97a7a54140ebcfe886af90cbdb7bfe41e89cristy maxval=(png_uint_16) ((one << ping_bit_depth)-1); 95353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 95364f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp if (ping_exclude_bKGD == MagickFalse) 953726f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp { 95383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 9539a521b2fe1f4c8b8ab9412bd6ef23b6736b90e43dglennrp ping_background.gray=(png_uint_16) 9540847370c32c6b67817205f49897c43c540fd670c4glennrp ((maxval/255.)*((GetPixelPacketIntensity(&image->background_color))) 9541847370c32c6b67817205f49897c43c540fd670c4glennrp +.5); 95423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 95433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 95443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 95453c21811cab8a3b168295e3f0da1909c4e2a7da15glennrp " Setting up bKGD chunk (2)"); 9546c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 9547c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp " background_color index is %d", 9548c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp (int) ping_background.index); 95493b51f0e7f4f7cce3e7466784c8b4e5dac9f55741glennrp 9550991d11dd9c33e65872778b81aff1347cd2878154glennrp ping_have_bKGD = MagickTrue; 955126f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp } 95523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 95533e3e20f27f74686a93873f25b015e0e8e40f451dglennrp if (logging != MagickFalse) 95543e3e20f27f74686a93873f25b015e0e8e40f451dglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 95553e3e20f27f74686a93873f25b015e0e8e40f451dglennrp " Scaling ping_trans_color.gray from %d", 95563e3e20f27f74686a93873f25b015e0e8e40f451dglennrp (int)ping_trans_color.gray); 95573e3e20f27f74686a93873f25b015e0e8e40f451dglennrp 95589be9b1cfe4c5ead507b2ad633cced4321db3c806glennrp ping_trans_color.gray=(png_uint_16) ((maxval/255.)*( 95593e3e20f27f74686a93873f25b015e0e8e40f451dglennrp ping_trans_color.gray)+.5); 95603e3e20f27f74686a93873f25b015e0e8e40f451dglennrp 95613e3e20f27f74686a93873f25b015e0e8e40f451dglennrp if (logging != MagickFalse) 95623e3e20f27f74686a93873f25b015e0e8e40f451dglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 95633e3e20f27f74686a93873f25b015e0e8e40f451dglennrp " to %d", (int)ping_trans_color.gray); 95643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 956517a1485544c62993fc7a94e343c87fed5f3e6407glennrp 956626f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp if (ping_exclude_bKGD == MagickFalse) 956726f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp { 95681273f7b031edcb07e2ee4835455712ebdd0b2f60glennrp if (mng_info->IsPalette && (int) ping_color_type == PNG_COLOR_TYPE_PALETTE) 956917a1485544c62993fc7a94e343c87fed5f3e6407glennrp { 957017a1485544c62993fc7a94e343c87fed5f3e6407glennrp /* 957117a1485544c62993fc7a94e343c87fed5f3e6407glennrp Identify which colormap entry is the background color. 957217a1485544c62993fc7a94e343c87fed5f3e6407glennrp */ 957317a1485544c62993fc7a94e343c87fed5f3e6407glennrp 957417a1485544c62993fc7a94e343c87fed5f3e6407glennrp number_colors=image_colors; 957517a1485544c62993fc7a94e343c87fed5f3e6407glennrp 9576a521b2fe1f4c8b8ab9412bd6ef23b6736b90e43dglennrp for (i=0; i < (ssize_t) MagickMax(1L*number_colors,1L); i++) 9577a521b2fe1f4c8b8ab9412bd6ef23b6736b90e43dglennrp if (IsPNGColorEqual(image->background_color,image->colormap[i])) 957817a1485544c62993fc7a94e343c87fed5f3e6407glennrp break; 957917a1485544c62993fc7a94e343c87fed5f3e6407glennrp 958017a1485544c62993fc7a94e343c87fed5f3e6407glennrp ping_background.index=(png_byte) i; 958117a1485544c62993fc7a94e343c87fed5f3e6407glennrp 95823b51f0e7f4f7cce3e7466784c8b4e5dac9f55741glennrp if (logging != MagickFalse) 95830fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp { 95840fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 95850fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp " Setting up bKGD chunk with index=%d",(int) i); 95860fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp } 9587a521b2fe1f4c8b8ab9412bd6ef23b6736b90e43dglennrp 958813d07043243e0c8c151aad7db5240b75e76ca281cristy if (i < (ssize_t) number_colors) 9589a521b2fe1f4c8b8ab9412bd6ef23b6736b90e43dglennrp { 95900fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp ping_have_bKGD = MagickTrue; 95913b51f0e7f4f7cce3e7466784c8b4e5dac9f55741glennrp 95923b51f0e7f4f7cce3e7466784c8b4e5dac9f55741glennrp if (logging != MagickFalse) 95930fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp { 95940fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 95950fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp " background =(%d,%d,%d)", 95960fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp (int) ping_background.red, 95970fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp (int) ping_background.green, 95980fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp (int) ping_background.blue); 95990fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp } 9600a521b2fe1f4c8b8ab9412bd6ef23b6736b90e43dglennrp } 960117a1485544c62993fc7a94e343c87fed5f3e6407glennrp 9602d6bf1617e99df0272b231855a933a74e99b6578fglennrp else /* Can't happen */ 96033c21811cab8a3b168295e3f0da1909c4e2a7da15glennrp { 96043b51f0e7f4f7cce3e7466784c8b4e5dac9f55741glennrp if (logging != MagickFalse) 96053b51f0e7f4f7cce3e7466784c8b4e5dac9f55741glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 96063b51f0e7f4f7cce3e7466784c8b4e5dac9f55741glennrp " No room in PLTE to add bKGD color"); 96073c21811cab8a3b168295e3f0da1909c4e2a7da15glennrp ping_have_bKGD = MagickFalse; 96083c21811cab8a3b168295e3f0da1909c4e2a7da15glennrp } 960917a1485544c62993fc7a94e343c87fed5f3e6407glennrp } 961026f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp } 961117a1485544c62993fc7a94e343c87fed5f3e6407glennrp 96123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 96133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 96145af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp " PNG color type: %d",ping_color_type); 96153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 96163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Initialize compression level and filtering. 96173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 96183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 96190fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp { 96200fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 96210fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp " Setting up deflate compression"); 96220fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 96230fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 96240fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp " Compression buffer size: 32768"); 96250fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp } 96260fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 96273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_set_compression_buffer_size(ping,32768L); 96280fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 96293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 96303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 96313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Compression mem level: 9"); 96320fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 963310d739ef54404090a55cb8977fc51f85cafa81a5glennrp /* Untangle the "-quality" setting: 963410d739ef54404090a55cb8977fc51f85cafa81a5glennrp 963510d739ef54404090a55cb8977fc51f85cafa81a5glennrp Undefined is 0; the default is used. 963610d739ef54404090a55cb8977fc51f85cafa81a5glennrp Default is 75 963710d739ef54404090a55cb8977fc51f85cafa81a5glennrp 963810d739ef54404090a55cb8977fc51f85cafa81a5glennrp 10's digit: 963910d739ef54404090a55cb8977fc51f85cafa81a5glennrp 964010d739ef54404090a55cb8977fc51f85cafa81a5glennrp 0: Use Z_HUFFMAN_ONLY strategy with the 964110d739ef54404090a55cb8977fc51f85cafa81a5glennrp zlib default compression level 964210d739ef54404090a55cb8977fc51f85cafa81a5glennrp 964310d739ef54404090a55cb8977fc51f85cafa81a5glennrp 1-9: the zlib compression level 964410d739ef54404090a55cb8977fc51f85cafa81a5glennrp 964510d739ef54404090a55cb8977fc51f85cafa81a5glennrp 1's digit: 964610d739ef54404090a55cb8977fc51f85cafa81a5glennrp 964710d739ef54404090a55cb8977fc51f85cafa81a5glennrp 0-4: the PNG filter method 964810d739ef54404090a55cb8977fc51f85cafa81a5glennrp 964910d739ef54404090a55cb8977fc51f85cafa81a5glennrp 5: libpng adaptive filtering if compression level > 5 965010d739ef54404090a55cb8977fc51f85cafa81a5glennrp libpng filter type "none" if compression level <= 5 965110d739ef54404090a55cb8977fc51f85cafa81a5glennrp or if image is grayscale or palette 965210d739ef54404090a55cb8977fc51f85cafa81a5glennrp 965310d739ef54404090a55cb8977fc51f85cafa81a5glennrp 6: libpng adaptive filtering 965410d739ef54404090a55cb8977fc51f85cafa81a5glennrp 965510d739ef54404090a55cb8977fc51f85cafa81a5glennrp 7: "LOCO" filtering (intrapixel differing) if writing 965610d739ef54404090a55cb8977fc51f85cafa81a5glennrp a MNG, othewise "none". Did not work in IM-6.7.0-9 965710d739ef54404090a55cb8977fc51f85cafa81a5glennrp and earlier because of a missing "else". 965810d739ef54404090a55cb8977fc51f85cafa81a5glennrp 965910d739ef54404090a55cb8977fc51f85cafa81a5glennrp 8: Z_RLE strategy, all filters 96601868258559ddf946fa73ef72dd43507b32623705glennrp Unused prior to IM-6.7.0-10, was same as 6 966110d739ef54404090a55cb8977fc51f85cafa81a5glennrp 966210d739ef54404090a55cb8977fc51f85cafa81a5glennrp 9: Z_RLE strategy, no PNG filters 96631868258559ddf946fa73ef72dd43507b32623705glennrp Unused prior to IM-6.7.0-10, was same as 6 966410d739ef54404090a55cb8977fc51f85cafa81a5glennrp 966510d739ef54404090a55cb8977fc51f85cafa81a5glennrp Note that using the -quality option, not all combinations of 966610d739ef54404090a55cb8977fc51f85cafa81a5glennrp PNG filter type, zlib compression level, and zlib compression 966710d739ef54404090a55cb8977fc51f85cafa81a5glennrp strategy are possible. This will be addressed soon in a 966810d739ef54404090a55cb8977fc51f85cafa81a5glennrp release that accomodates "-define PNG:compression-strategy", 966910d739ef54404090a55cb8977fc51f85cafa81a5glennrp etc. 967010d739ef54404090a55cb8977fc51f85cafa81a5glennrp 967110d739ef54404090a55cb8977fc51f85cafa81a5glennrp */ 967210d739ef54404090a55cb8977fc51f85cafa81a5glennrp 96733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy quality=image->quality == UndefinedCompressionQuality ? 75UL : 96743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->quality; 96750fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 96761868258559ddf946fa73ef72dd43507b32623705glennrp if (quality <= 9) 96771868258559ddf946fa73ef72dd43507b32623705glennrp { 96781868258559ddf946fa73ef72dd43507b32623705glennrp if (mng_info->write_png_compression_strategy == 0) 96791868258559ddf946fa73ef72dd43507b32623705glennrp mng_info->write_png_compression_strategy = Z_HUFFMAN_ONLY+1; 96801868258559ddf946fa73ef72dd43507b32623705glennrp } 96811868258559ddf946fa73ef72dd43507b32623705glennrp 96821868258559ddf946fa73ef72dd43507b32623705glennrp else if (mng_info->write_png_compression_level == 0) 96833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 96843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy int 96853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy level; 96863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 9687bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy level=(int) MagickMin((ssize_t) quality/10,9); 96880fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 96891868258559ddf946fa73ef72dd43507b32623705glennrp mng_info->write_png_compression_level = level+1; 96901868258559ddf946fa73ef72dd43507b32623705glennrp } 96910fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 96921868258559ddf946fa73ef72dd43507b32623705glennrp if (mng_info->write_png_compression_strategy == 0) 96931868258559ddf946fa73ef72dd43507b32623705glennrp { 96941868258559ddf946fa73ef72dd43507b32623705glennrp if ((quality %10) == 8 || (quality %10) == 9) 96951868258559ddf946fa73ef72dd43507b32623705glennrp mng_info->write_png_compression_strategy=Z_RLE; 96963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 96970fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 96981868258559ddf946fa73ef72dd43507b32623705glennrp if (mng_info->write_png_compression_filter == 0) 96991868258559ddf946fa73ef72dd43507b32623705glennrp mng_info->write_png_compression_filter=((int) quality % 10) + 1; 97001868258559ddf946fa73ef72dd43507b32623705glennrp 97011868258559ddf946fa73ef72dd43507b32623705glennrp if (logging != MagickFalse) 97023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 97031868258559ddf946fa73ef72dd43507b32623705glennrp if (mng_info->write_png_compression_level) 97043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 97051868258559ddf946fa73ef72dd43507b32623705glennrp " Compression level: %d", 97061868258559ddf946fa73ef72dd43507b32623705glennrp (int) mng_info->write_png_compression_level-1); 97070fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 97081868258559ddf946fa73ef72dd43507b32623705glennrp if (mng_info->write_png_compression_strategy) 97091868258559ddf946fa73ef72dd43507b32623705glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 97101868258559ddf946fa73ef72dd43507b32623705glennrp " Compression strategy: %d", 97111868258559ddf946fa73ef72dd43507b32623705glennrp (int) mng_info->write_png_compression_strategy-1); 97120fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 97131868258559ddf946fa73ef72dd43507b32623705glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 97141868258559ddf946fa73ef72dd43507b32623705glennrp " Setting up filtering"); 97153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 97161868258559ddf946fa73ef72dd43507b32623705glennrp if (mng_info->write_png_compression_filter == PNG_ALL_FILTERS+1) 971710d739ef54404090a55cb8977fc51f85cafa81a5glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 97181868258559ddf946fa73ef72dd43507b32623705glennrp " Base filter method: ADAPTIVE"); 97191868258559ddf946fa73ef72dd43507b32623705glennrp else if (mng_info->write_png_compression_filter == PNG_NO_FILTERS+1) 97201868258559ddf946fa73ef72dd43507b32623705glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 97211868258559ddf946fa73ef72dd43507b32623705glennrp " Base filter method: NONE"); 97221868258559ddf946fa73ef72dd43507b32623705glennrp else 97231868258559ddf946fa73ef72dd43507b32623705glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 97241868258559ddf946fa73ef72dd43507b32623705glennrp " Base filter method: %d", 97251868258559ddf946fa73ef72dd43507b32623705glennrp (int) mng_info->write_png_compression_filter-1); 97263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 97270fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 97281868258559ddf946fa73ef72dd43507b32623705glennrp if (mng_info->write_png_compression_level != 0) 97291868258559ddf946fa73ef72dd43507b32623705glennrp png_set_compression_level(ping,mng_info->write_png_compression_level-1); 97300fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 97311868258559ddf946fa73ef72dd43507b32623705glennrp if (mng_info->write_png_compression_filter == 6) 97321868258559ddf946fa73ef72dd43507b32623705glennrp { 97331868258559ddf946fa73ef72dd43507b32623705glennrp if (((int) ping_color_type == PNG_COLOR_TYPE_GRAY) || 97341868258559ddf946fa73ef72dd43507b32623705glennrp ((int) ping_color_type == PNG_COLOR_TYPE_PALETTE) || 97351868258559ddf946fa73ef72dd43507b32623705glennrp (quality < 50)) 97361868258559ddf946fa73ef72dd43507b32623705glennrp png_set_filter(ping,PNG_FILTER_TYPE_BASE,PNG_NO_FILTERS); 97371868258559ddf946fa73ef72dd43507b32623705glennrp else 97381868258559ddf946fa73ef72dd43507b32623705glennrp png_set_filter(ping,PNG_FILTER_TYPE_BASE,PNG_ALL_FILTERS); 97391868258559ddf946fa73ef72dd43507b32623705glennrp } 974010d739ef54404090a55cb8977fc51f85cafa81a5glennrp 97411868258559ddf946fa73ef72dd43507b32623705glennrp if (mng_info->write_png_compression_filter == 7 || 97421868258559ddf946fa73ef72dd43507b32623705glennrp mng_info->write_png_compression_filter == 10) 97431868258559ddf946fa73ef72dd43507b32623705glennrp png_set_filter(ping,PNG_FILTER_TYPE_BASE,PNG_ALL_FILTERS); 974410d739ef54404090a55cb8977fc51f85cafa81a5glennrp 97451868258559ddf946fa73ef72dd43507b32623705glennrp else if (mng_info->write_png_compression_filter == 8) 97461868258559ddf946fa73ef72dd43507b32623705glennrp { 97471868258559ddf946fa73ef72dd43507b32623705glennrp#if defined(PNG_MNG_FEATURES_SUPPORTED) && defined(PNG_INTRAPIXEL_DIFFERENCING) 97481868258559ddf946fa73ef72dd43507b32623705glennrp if (mng_info->write_mng) 97491868258559ddf946fa73ef72dd43507b32623705glennrp { 97501868258559ddf946fa73ef72dd43507b32623705glennrp if (((int) ping_color_type == PNG_COLOR_TYPE_RGB) || 97511868258559ddf946fa73ef72dd43507b32623705glennrp ((int) ping_color_type == PNG_COLOR_TYPE_RGBA)) 97521868258559ddf946fa73ef72dd43507b32623705glennrp ping_filter_method=PNG_INTRAPIXEL_DIFFERENCING; 97531868258559ddf946fa73ef72dd43507b32623705glennrp } 97541868258559ddf946fa73ef72dd43507b32623705glennrp#endif 97551868258559ddf946fa73ef72dd43507b32623705glennrp png_set_filter(ping,PNG_FILTER_TYPE_BASE,0); 97561868258559ddf946fa73ef72dd43507b32623705glennrp } 97570fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 97581868258559ddf946fa73ef72dd43507b32623705glennrp else if (mng_info->write_png_compression_filter == 9) 97591868258559ddf946fa73ef72dd43507b32623705glennrp png_set_filter(ping,PNG_FILTER_TYPE_BASE,PNG_NO_FILTERS); 97600fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 97611868258559ddf946fa73ef72dd43507b32623705glennrp else if (mng_info->write_png_compression_filter != 0) 97621868258559ddf946fa73ef72dd43507b32623705glennrp png_set_filter(ping,PNG_FILTER_TYPE_BASE, 97631868258559ddf946fa73ef72dd43507b32623705glennrp mng_info->write_png_compression_filter-1); 97640fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 97651868258559ddf946fa73ef72dd43507b32623705glennrp if (mng_info->write_png_compression_strategy != 0) 97661868258559ddf946fa73ef72dd43507b32623705glennrp png_set_compression_strategy(ping, 97671868258559ddf946fa73ef72dd43507b32623705glennrp mng_info->write_png_compression_strategy-1); 97682b013e4b9b602533eff410e61c3683fb2a3ab913glennrp 97693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 9770823b55c200d7fc1818ab539b036a9c24feaecda8glennrp if ((ping_exclude_tEXt == MagickFalse || ping_exclude_zTXt == MagickFalse) && 9771823b55c200d7fc1818ab539b036a9c24feaecda8glennrp (ping_exclude_iCCP == MagickFalse || ping_exclude_zCCP == MagickFalse)) 9772c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp { 9773c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp ResetImageProfileIterator(image); 9774c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp for (name=GetNextImageProfile(image); name != (const char *) NULL; ) 97753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 9776c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp profile=GetImageProfile(image,name); 97770fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 9778c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp if (profile != (StringInfo *) NULL) 9779c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp { 9780c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp#ifdef PNG_WRITE_iCCP_SUPPORTED 9781c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp if ((LocaleCompare(name,"ICC") == 0) || 9782c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp (LocaleCompare(name,"ICM") == 0)) 978326f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp { 9784c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp 9785c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp if (ping_exclude_iCCP == MagickFalse) 9786c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp { 9787c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp png_set_iCCP(ping,ping_info,(const png_charp) name,0, 9788e4017e34baec05ee0a45800ed8efb2ff6d5c9f5aglennrp#if (PNG_LIBPNG_VER < 10500) 9789c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp (png_charp) GetStringInfoDatum(profile), 9790e4017e34baec05ee0a45800ed8efb2ff6d5c9f5aglennrp#else 9791e4017e34baec05ee0a45800ed8efb2ff6d5c9f5aglennrp (png_const_bytep) GetStringInfoDatum(profile), 9792e4017e34baec05ee0a45800ed8efb2ff6d5c9f5aglennrp#endif 9793c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp (png_uint_32) GetStringInfoLength(profile)); 9794c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp } 979526f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp } 97960fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 9797c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp else 97983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 9799c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp if (ping_exclude_zCCP == MagickFalse) 9800c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp { 9801cf002022280cc4dedb2748ad6f415aac1d44f530glennrp Magick_png_write_raw_profile(image_info,ping,ping_info, 9802c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp (unsigned char *) name,(unsigned char *) name, 9803c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp GetStringInfoDatum(profile), 9804c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp (png_uint_32) GetStringInfoLength(profile)); 9805c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp } 9806c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp } 98070b206f5daa453dc1035db5890cabc899736dc2d0glennrp 9808c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp if (logging != MagickFalse) 9809c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 9810c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp " Setting up text chunk with %s profile",name); 98110fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 9812c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp name=GetNextImageProfile(image); 9813c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp } 98143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 98153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 98163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(PNG_WRITE_sRGB_SUPPORTED) 98173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((mng_info->have_write_global_srgb == 0) && 98183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ((image->rendering_intent != UndefinedIntent) || 98193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (image->colorspace == sRGBColorspace))) 98203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 982126f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp if (ping_exclude_sRGB == MagickFalse) 982226f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp { 982326f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp /* 982426f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp Note image rendering intent. 982526f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp */ 982626f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp if (logging != MagickFalse) 982726f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 982826f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp " Setting up sRGB chunk"); 98290fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 983026f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp (void) png_set_sRGB(ping,ping_info,( 9831cf002022280cc4dedb2748ad6f415aac1d44f530glennrp Magick_RenderingIntent_to_PNG_RenderingIntent( 9832cf002022280cc4dedb2748ad6f415aac1d44f530glennrp image->rendering_intent))); 98330fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 983426f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp if (ping_exclude_gAMA == MagickFalse) 983526f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp png_set_gAMA(ping,ping_info,0.45455); 983626f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp } 98373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 983826f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp 98395af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp if ((!mng_info->write_mng) || (!png_get_valid(ping,ping_info,PNG_INFO_sRGB))) 98403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 98413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 98422cc891a179d622dde7bbb8854138851e828bc6eaglennrp if (ping_exclude_gAMA == MagickFalse && 98432cc891a179d622dde7bbb8854138851e828bc6eaglennrp (ping_exclude_sRGB == MagickFalse || 984426f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp (image->gamma < .45 || image->gamma > .46))) 984526f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp { 98463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((mng_info->have_write_global_gama == 0) && (image->gamma != 0.0)) 98473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 98483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 98493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Note image gamma. 98503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy To do: check for cHRM+gAMA == sRGB, and write sRGB instead. 98513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 98523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 98533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 98543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Setting up gAMA chunk"); 98553b51f0e7f4f7cce3e7466784c8b4e5dac9f55741glennrp 98563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_set_gAMA(ping,ping_info,image->gamma); 98573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 985826f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp } 98592b013e4b9b602533eff410e61c3683fb2a3ab913glennrp 986026f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp if (ping_exclude_cHRM == MagickFalse) 98613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 986226f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp if ((mng_info->have_write_global_chrm == 0) && 986326f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp (image->chromaticity.red_primary.x != 0.0)) 986426f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp { 986526f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp /* 986626f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp Note image chromaticity. 986726f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp To do: check for cHRM+gAMA == sRGB, and write sRGB instead. 986826f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp */ 986926f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp PrimaryInfo 987026f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp bp, 987126f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp gp, 987226f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp rp, 987326f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp wp; 987426f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp 987526f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp wp=image->chromaticity.white_point; 987626f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp rp=image->chromaticity.red_primary; 987726f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp gp=image->chromaticity.green_primary; 987826f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp bp=image->chromaticity.blue_primary; 987926f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp 988026f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp if (logging != MagickFalse) 988126f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 988226f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp " Setting up cHRM chunk"); 988326f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp 988426f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp png_set_cHRM(ping,ping_info,wp.x,wp.y,rp.x,rp.y,gp.x,gp.y, 988526f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp bp.x,bp.y); 988626f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp } 988726f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp } 98883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 9889dfd7080ae717c8ddb013b59958f2d0790f5e3145glennrp 98905af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_interlace_method=image_info->interlace != NoInterlace; 98913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 98923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->write_mng) 98933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_set_sig_bytes(ping,8); 98943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 98953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Bail out if cannot meet defined PNG:bit-depth or PNG:color-type */ 98963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 9897d6bf1617e99df0272b231855a933a74e99b6578fglennrp if (mng_info->write_png_colortype != 0) 98983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 98993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->write_png_colortype-1 == PNG_COLOR_TYPE_GRAY) 99008d579660c9b96b7a3f3292fc6c518f8b6ca44d50glennrp if (ping_have_color != MagickFalse) 99013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 99025af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_color_type = PNG_COLOR_TYPE_RGB; 99032b013e4b9b602533eff410e61c3683fb2a3ab913glennrp 99045af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp if (ping_bit_depth < 8) 99055af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_bit_depth=8; 99063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 99070fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 99083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->write_png_colortype-1 == PNG_COLOR_TYPE_GRAY_ALPHA) 99098d579660c9b96b7a3f3292fc6c518f8b6ca44d50glennrp if (ping_have_color != MagickFalse) 99105af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_color_type = PNG_COLOR_TYPE_RGB_ALPHA; 99113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 99123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 99130e8ea19baa0666ccfe869d19116372f60fe9230fglennrp if (ping_need_colortype_warning != MagickFalse || 99140e8ea19baa0666ccfe869d19116372f60fe9230fglennrp ((mng_info->write_png_depth && 99155af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp (int) mng_info->write_png_depth != ping_bit_depth) || 99163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (mng_info->write_png_colortype && 99175af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ((int) mng_info->write_png_colortype-1 != ping_color_type && 9918991e92a91acb9e432cd6c05843e4f6a57643e29dglennrp mng_info->write_png_colortype != 7 && 99190e8ea19baa0666ccfe869d19116372f60fe9230fglennrp !(mng_info->write_png_colortype == 5 && ping_color_type == 0))))) 99203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 99213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 99223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 99230e8ea19baa0666ccfe869d19116372f60fe9230fglennrp if (ping_need_colortype_warning != MagickFalse) 99240e8ea19baa0666ccfe869d19116372f60fe9230fglennrp { 99250e8ea19baa0666ccfe869d19116372f60fe9230fglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 99260e8ea19baa0666ccfe869d19116372f60fe9230fglennrp " Image has transparency but tRNS chunk was excluded"); 99270e8ea19baa0666ccfe869d19116372f60fe9230fglennrp } 99280e8ea19baa0666ccfe869d19116372f60fe9230fglennrp 99293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->write_png_depth) 99303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 99313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 99323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Defined PNG:bit-depth=%u, Computed depth=%u", 99333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->write_png_depth, 99345af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_bit_depth); 99353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 99360e8ea19baa0666ccfe869d19116372f60fe9230fglennrp 99373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->write_png_colortype) 99383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 99393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 99403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Defined PNG:color-type=%u, Computed color type=%u", 99413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->write_png_colortype-1, 99425af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_color_type); 99433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 99443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 99450e8ea19baa0666ccfe869d19116372f60fe9230fglennrp 99463bd2e411d0f07c705a40c2c73ce7eda3f1f03e0cglennrp png_warning(ping, 99473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy "Cannot write image with defined PNG:bit-depth or PNG:color-type."); 99483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 99493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 995058e017631f66141a6e36ddbe03a54f6e3ee3a253glennrp if (image_matte != MagickFalse && image->matte == MagickFalse) 99513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 99523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Add an opaque matte channel */ 99533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->matte = MagickTrue; 99543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) SetImageOpacity(image,0); 99550fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 9956b4a1341a4d06abe5f603ad9052b6ddc1a667dcd5glennrp if (logging != MagickFalse) 9957b4a1341a4d06abe5f603ad9052b6ddc1a667dcd5glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 9958b4a1341a4d06abe5f603ad9052b6ddc1a667dcd5glennrp " Added an opaque matte channel"); 99593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 99603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 99610e319739731741c52a6303723e0c8678a0df5579glennrp if (number_transparent != 0 || number_semitransparent != 0) 9962e9c26dc68fb7cff87adcf2677968737acc9d3d2cglennrp { 9963991d11dd9c33e65872778b81aff1347cd2878154glennrp if (ping_color_type < 4) 9964c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp { 9965991d11dd9c33e65872778b81aff1347cd2878154glennrp ping_have_tRNS=MagickTrue; 9966c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp if (logging != MagickFalse) 9967c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 9968c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp " Setting ping_have_tRNS=MagickTrue."); 9969c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp } 9970e9c26dc68fb7cff87adcf2677968737acc9d3d2cglennrp } 9971e9c26dc68fb7cff87adcf2677968737acc9d3d2cglennrp 99723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 99733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 99743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Writing PNG header chunks"); 99753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 99765af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp png_set_IHDR(ping,ping_info,ping_width,ping_height, 99775af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_bit_depth,ping_color_type, 99785af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_interlace_method,ping_compression_method, 99795af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp ping_filter_method); 99805af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp 998139992b4dd9b12ef752d55b8e402c069698851f72glennrp if (ping_color_type == 3 && ping_have_PLTE != MagickFalse) 998239992b4dd9b12ef752d55b8e402c069698851f72glennrp { 9983f09bdedccf9ca10bc002a946227df3367cb58d14glennrp png_set_PLTE(ping,ping_info,palette,number_colors); 99840fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 99853b51f0e7f4f7cce3e7466784c8b4e5dac9f55741glennrp if (logging != MagickFalse) 998639992b4dd9b12ef752d55b8e402c069698851f72glennrp { 99878640fb5e9b1094f35f8beab436f81661b8a99448glennrp for (i=0; i< (ssize_t) number_colors; i++) 99880fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp { 9989d6bf1617e99df0272b231855a933a74e99b6578fglennrp if (i < ping_num_trans) 99900fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 9991d6bf1617e99df0272b231855a933a74e99b6578fglennrp " PLTE[%d] = (%d,%d,%d), tRNS[%d] = (%d)", 9992d6bf1617e99df0272b231855a933a74e99b6578fglennrp (int) i, 99930fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp (int) palette[i].red, 99940fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp (int) palette[i].green, 99950fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp (int) palette[i].blue, 9996d6bf1617e99df0272b231855a933a74e99b6578fglennrp (int) i, 99970fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp (int) ping_trans_alpha[i]); 99980fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp else 99990fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 10000d6bf1617e99df0272b231855a933a74e99b6578fglennrp " PLTE[%d] = (%d,%d,%d)", 100010fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp (int) i, 100020fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp (int) palette[i].red, 100030fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp (int) palette[i].green, 100040fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp (int) palette[i].blue); 100050fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp } 1000639992b4dd9b12ef752d55b8e402c069698851f72glennrp } 1000739992b4dd9b12ef752d55b8e402c069698851f72glennrp } 1000839992b4dd9b12ef752d55b8e402c069698851f72glennrp 1000926f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp if (ping_exclude_bKGD == MagickFalse) 1001026f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp { 1001126f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp if (ping_have_bKGD != MagickFalse) 10012c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp { 1001326f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp png_set_bKGD(ping,ping_info,&ping_background); 10014c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp if (logging) 10015c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp { 10016c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 10017c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp " Setting up bKGD chunk"); 10018c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 10019c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp " background color = (%d,%d,%d)", 10020c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp (int) ping_background.red, 10021c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp (int) ping_background.green, 10022c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp (int) ping_background.blue); 10023c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 10024c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp " index = %d, gray=%d", 10025c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp (int) ping_background.index, 10026c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp (int) ping_background.gray); 10027c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp } 10028c6c391a2036b6e500b986d1635c50b9a89ea331dglennrp } 1002926f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp } 10030991d11dd9c33e65872778b81aff1347cd2878154glennrp 1003126f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp if (ping_exclude_pHYs == MagickFalse) 10032dfd7080ae717c8ddb013b59958f2d0790f5e3145glennrp { 1003326f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp if (ping_have_pHYs != MagickFalse) 1003426f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp { 1003526f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp png_set_pHYs(ping,ping_info, 1003626f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp ping_pHYs_x_resolution, 1003726f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp ping_pHYs_y_resolution, 1003826f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp ping_pHYs_unit_type); 10039823b55c200d7fc1818ab539b036a9c24feaecda8glennrp 10040823b55c200d7fc1818ab539b036a9c24feaecda8glennrp if (logging) 10041823b55c200d7fc1818ab539b036a9c24feaecda8glennrp { 10042823b55c200d7fc1818ab539b036a9c24feaecda8glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 10043823b55c200d7fc1818ab539b036a9c24feaecda8glennrp " Setting up pHYs chunk"); 10044823b55c200d7fc1818ab539b036a9c24feaecda8glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 10045823b55c200d7fc1818ab539b036a9c24feaecda8glennrp " x_resolution=%lu", 10046823b55c200d7fc1818ab539b036a9c24feaecda8glennrp (unsigned long) ping_pHYs_x_resolution); 10047823b55c200d7fc1818ab539b036a9c24feaecda8glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 10048823b55c200d7fc1818ab539b036a9c24feaecda8glennrp " y_resolution=%lu", 10049823b55c200d7fc1818ab539b036a9c24feaecda8glennrp (unsigned long) ping_pHYs_y_resolution); 10050823b55c200d7fc1818ab539b036a9c24feaecda8glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 10051823b55c200d7fc1818ab539b036a9c24feaecda8glennrp " unit_type=%lu", 10052823b55c200d7fc1818ab539b036a9c24feaecda8glennrp (unsigned long) ping_pHYs_unit_type); 10053823b55c200d7fc1818ab539b036a9c24feaecda8glennrp } 1005426f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp } 10055dfd7080ae717c8ddb013b59958f2d0790f5e3145glennrp } 10056dfd7080ae717c8ddb013b59958f2d0790f5e3145glennrp 10057dfd7080ae717c8ddb013b59958f2d0790f5e3145glennrp#if defined(PNG_oFFs_SUPPORTED) 100584f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp if (ping_exclude_oFFs == MagickFalse) 10059dfd7080ae717c8ddb013b59958f2d0790f5e3145glennrp { 1006026f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp if (image->page.x || image->page.y) 1006126f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp { 1006226f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp png_set_oFFs(ping,ping_info,(png_int_32) image->page.x, 1006326f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp (png_int_32) image->page.y, 0); 10064dfd7080ae717c8ddb013b59958f2d0790f5e3145glennrp 1006526f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp if (logging != MagickFalse) 1006626f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 1006726f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp " Setting up oFFs chunk with x=%d, y=%d, units=0", 1006826f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp (int) image->page.x, (int) image->page.y); 1006926f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp } 10070dfd7080ae717c8ddb013b59958f2d0790f5e3145glennrp } 10071dfd7080ae717c8ddb013b59958f2d0790f5e3145glennrp#endif 10072dfd7080ae717c8ddb013b59958f2d0790f5e3145glennrp 10073da8f3a7bfddac2680a3069a490db541e7944edafglennrp if (mng_info->need_blob != MagickFalse) 10074da8f3a7bfddac2680a3069a490db541e7944edafglennrp { 10075da8f3a7bfddac2680a3069a490db541e7944edafglennrp if (OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception) == 10076da8f3a7bfddac2680a3069a490db541e7944edafglennrp MagickFalse) 10077da8f3a7bfddac2680a3069a490db541e7944edafglennrp png_error(ping,"WriteBlob Failed"); 10078da8f3a7bfddac2680a3069a490db541e7944edafglennrp 10079da8f3a7bfddac2680a3069a490db541e7944edafglennrp ping_have_blob=MagickTrue; 10080da8f3a7bfddac2680a3069a490db541e7944edafglennrp } 10081da8f3a7bfddac2680a3069a490db541e7944edafglennrp 100823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_write_info_before_PLTE(ping, ping_info); 10083991d11dd9c33e65872778b81aff1347cd2878154glennrp 1008439992b4dd9b12ef752d55b8e402c069698851f72glennrp if (ping_have_tRNS != MagickFalse && ping_color_type < 4) 10085991d11dd9c33e65872778b81aff1347cd2878154glennrp { 100863b51f0e7f4f7cce3e7466784c8b4e5dac9f55741glennrp if (logging != MagickFalse) 100870fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp { 100880fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 100890fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp " Calling png_set_tRNS with num_trans=%d",ping_num_trans); 100900fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp } 10091991d11dd9c33e65872778b81aff1347cd2878154glennrp 100920fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp if (ping_color_type == 3) 100930fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp (void) png_set_tRNS(ping, ping_info, 100940fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp ping_trans_alpha, 100950fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp ping_num_trans, 100960fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp NULL); 10097991d11dd9c33e65872778b81aff1347cd2878154glennrp 100980fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp else 100990fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp { 101000fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp (void) png_set_tRNS(ping, ping_info, 101010fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp NULL, 101020fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 0, 101030fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp &ping_trans_color); 101040fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 101053b51f0e7f4f7cce3e7466784c8b4e5dac9f55741glennrp if (logging != MagickFalse) 101060fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp { 101070fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 10108c8cbc5d89664c67b8a8f3f4619fc7ce19ea654bcglennrp " tRNS color =(%d,%d,%d)", 101090fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp (int) ping_trans_color.red, 101100fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp (int) ping_trans_color.green, 101110fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp (int) ping_trans_color.blue); 101120fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp } 101130fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp } 101140fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp } 10115991d11dd9c33e65872778b81aff1347cd2878154glennrp 101163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* write any png-chunk-b profiles */ 10117cf002022280cc4dedb2748ad6f415aac1d44f530glennrp (void) Magick_png_write_chunk_from_profile(image,"PNG-chunk-b",logging); 10118da8f3a7bfddac2680a3069a490db541e7944edafglennrp 101193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_write_info(ping,ping_info); 10120991d11dd9c33e65872778b81aff1347cd2878154glennrp 101213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* write any PNG-chunk-m profiles */ 10122cf002022280cc4dedb2748ad6f415aac1d44f530glennrp (void) Magick_png_write_chunk_from_profile(image,"PNG-chunk-m",logging); 101233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1012426f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp if (ping_exclude_vpAg == MagickFalse) 101253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 101264f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp if ((image->page.width != 0 && image->page.width != image->columns) || 101274f25bd0f2f7f8673457c20de30664b5982b57b7cglennrp (image->page.height != 0 && image->page.height != image->rows)) 1012826f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp { 1012926f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp unsigned char 1013026f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp chunk[14]; 1013126f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp 1013226f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp (void) WriteBlobMSBULong(image,9L); /* data length=8 */ 1013326f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp PNGType(chunk,mng_vpAg); 1013403812ae402fb53d548f0e1d7d14720768f803c2dglennrp LogPNGChunk(logging,mng_vpAg,9L); 1013526f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp PNGLong(chunk+4,(png_uint_32) image->page.width); 1013626f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp PNGLong(chunk+8,(png_uint_32) image->page.height); 1013726f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp chunk[12]=0; /* unit = pixels */ 1013826f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp (void) WriteBlob(image,13,chunk); 1013926f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp (void) WriteBlobMSBULong(image,crc32(0,chunk,13)); 1014026f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp } 101413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 101423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 101433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if (PNG_LIBPNG_VER == 10206) 101449c1eb0729653219b9da9037e044501a6dce79d10glennrp /* avoid libpng-1.2.6 bug by setting PNG_HAVE_IDAT flag */ 101453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define PNG_HAVE_IDAT 0x04 101469c1eb0729653219b9da9037e044501a6dce79d10glennrp ping->mode |= PNG_HAVE_IDAT; 101473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#undef PNG_HAVE_IDAT 101483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 101493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 101503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_set_packing(ping); 101513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 101523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Allocate memory. 101533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 101543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy rowbytes=image->columns; 10155b4a1341a4d06abe5f603ad9052b6ddc1a667dcd5glennrp if (image_depth > 8) 10156b4a1341a4d06abe5f603ad9052b6ddc1a667dcd5glennrp rowbytes*=2; 101577202c101b42be63076be56386f79429bb2f39784cristy switch (ping_color_type) 101583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 10159b4a1341a4d06abe5f603ad9052b6ddc1a667dcd5glennrp case PNG_COLOR_TYPE_RGB: 101603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy rowbytes*=3; 10161b4a1341a4d06abe5f603ad9052b6ddc1a667dcd5glennrp break; 101620fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 10163b4a1341a4d06abe5f603ad9052b6ddc1a667dcd5glennrp case PNG_COLOR_TYPE_GRAY_ALPHA: 10164b4a1341a4d06abe5f603ad9052b6ddc1a667dcd5glennrp rowbytes*=2; 10165b4a1341a4d06abe5f603ad9052b6ddc1a667dcd5glennrp break; 101660fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 10167b4a1341a4d06abe5f603ad9052b6ddc1a667dcd5glennrp case PNG_COLOR_TYPE_RGBA: 101683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy rowbytes*=4; 10169b4a1341a4d06abe5f603ad9052b6ddc1a667dcd5glennrp break; 101700fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 10171b4a1341a4d06abe5f603ad9052b6ddc1a667dcd5glennrp default: 10172b4a1341a4d06abe5f603ad9052b6ddc1a667dcd5glennrp break; 101733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 101743b51f0e7f4f7cce3e7466784c8b4e5dac9f55741glennrp 101753b51f0e7f4f7cce3e7466784c8b4e5dac9f55741glennrp if (logging != MagickFalse) 101763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 10177b4a1341a4d06abe5f603ad9052b6ddc1a667dcd5glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 10178b4a1341a4d06abe5f603ad9052b6ddc1a667dcd5glennrp " Writing PNG image data"); 101790fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 10180b4a1341a4d06abe5f603ad9052b6ddc1a667dcd5glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 10181e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " Allocating %.20g bytes of memory for pixels",(double) rowbytes); 101823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 10183cf002022280cc4dedb2748ad6f415aac1d44f530glennrp ping_pixels=(unsigned char *) AcquireQuantumMemory(rowbytes, 10184cf002022280cc4dedb2748ad6f415aac1d44f530glennrp sizeof(*ping_pixels)); 101850fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 10186cf002022280cc4dedb2748ad6f415aac1d44f530glennrp if (ping_pixels == (unsigned char *) NULL) 101873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); 101880fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 101893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 101903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Initialize image scanlines. 101913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 101925af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp if (setjmp(png_jmpbuf(ping))) 101933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 101943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 101953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNG write failed. 101963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 101973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#ifdef PNG_DEBUG 101983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image_info->verbose) 101993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) printf("PNG write has failed.\n"); 102003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 102013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_destroy_write_struct(&ping,&ping_info); 102023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (quantum_info != (QuantumInfo *) NULL) 102033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy quantum_info=DestroyQuantumInfo(quantum_info); 10204cf002022280cc4dedb2748ad6f415aac1d44f530glennrp if (ping_pixels != (unsigned char *) NULL) 10205cf002022280cc4dedb2748ad6f415aac1d44f530glennrp ping_pixels=(unsigned char *) RelinquishMagickMemory(ping_pixels); 102063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(PNG_SETJMP_NOT_THREAD_SAFE) 10207cf002022280cc4dedb2748ad6f415aac1d44f530glennrp UnlockSemaphoreInfo(ping_semaphore); 102083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 10209da8f3a7bfddac2680a3069a490db541e7944edafglennrp if (ping_have_blob != MagickFalse) 10210b9cfe27bef51dbbd1f05aef89c767749d7e37864glennrp (void) CloseBlob(image); 10211b9cfe27bef51dbbd1f05aef89c767749d7e37864glennrp image_info=DestroyImageInfo(image_info); 10212b9cfe27bef51dbbd1f05aef89c767749d7e37864glennrp image=DestroyImage(image); 102133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(MagickFalse); 102143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 10215ed5525230af20461366cdc5b8bbe0f7f9b166c44cristy quantum_info=AcquireQuantumInfo(image_info,image); 10216ed5525230af20461366cdc5b8bbe0f7f9b166c44cristy if (quantum_info == (QuantumInfo *) NULL) 10217ed5525230af20461366cdc5b8bbe0f7f9b166c44cristy ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); 102183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy quantum_info->format=UndefinedQuantumFormat; 102193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy quantum_info->depth=image_depth; 102203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy num_passes=png_set_interlace_handling(ping); 102218bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp 102223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((!mng_info->write_png8 && !mng_info->write_png24 && 102238bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp !mng_info->write_png32) && 102248bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp (mng_info->IsPalette || 102253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (image_info->type == BilevelType)) && 102268d579660c9b96b7a3f3292fc6c518f8b6ca44d50glennrp image_matte == MagickFalse && 102278d579660c9b96b7a3f3292fc6c518f8b6ca44d50glennrp ping_have_non_bw == MagickFalse) 102283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 102298bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp /* Palette, Bilevel, or Opaque Monochrome */ 102304c08aed51c5899665ade97263692328eea4af106cristy register const Quantum 102313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *p; 102320fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 102333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy quantum_info->depth=8; 102343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy for (pass=0; pass < num_passes; pass++) 102353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 102363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 102373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Convert PseudoClass image to a PNG monochrome image. 102383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 10239bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (y=0; y < (ssize_t) image->rows; y++) 102403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 10241d71e86a4e57997f1aad16e85b542612b1d2f9b6eglennrp if (logging != MagickFalse && y == 0) 102423b51f0e7f4f7cce3e7466784c8b4e5dac9f55741glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 102433b51f0e7f4f7cce3e7466784c8b4e5dac9f55741glennrp " Writing row of pixels (0)"); 10244a521b2fe1f4c8b8ab9412bd6ef23b6736b90e43dglennrp 102453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception); 102460fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 102474c08aed51c5899665ade97263692328eea4af106cristy if (p == (const Quantum *) NULL) 102483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 102490fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 102503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->IsPalette) 102513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 102524c08aed51c5899665ade97263692328eea4af106cristy (void) ExportQuantumPixels(image,(CacheView *) NULL, 10253cf002022280cc4dedb2748ad6f415aac1d44f530glennrp quantum_info,GrayQuantum,ping_pixels,&image->exception); 102543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->write_png_colortype-1 == PNG_COLOR_TYPE_PALETTE && 102553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->write_png_depth && 102563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->write_png_depth != old_bit_depth) 102573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 102583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Undo pixel scaling */ 10259bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (i=0; i < (ssize_t) image->columns; i++) 10260cf002022280cc4dedb2748ad6f415aac1d44f530glennrp *(ping_pixels+i)=(unsigned char) (*(ping_pixels+i) 102613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy >> (8-old_bit_depth)); 102623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 102633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 102640fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 102653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 102663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 102674c08aed51c5899665ade97263692328eea4af106cristy (void) ExportQuantumPixels(image,(CacheView *) NULL, 10268cf002022280cc4dedb2748ad6f415aac1d44f530glennrp quantum_info,RedQuantum,ping_pixels,&image->exception); 102693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 102700fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 102713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->write_png_colortype-1 != PNG_COLOR_TYPE_PALETTE) 10272bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (i=0; i < (ssize_t) image->columns; i++) 10273cf002022280cc4dedb2748ad6f415aac1d44f530glennrp *(ping_pixels+i)=(unsigned char) ((*(ping_pixels+i) > 127) ? 102743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 255 : 0); 102750fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 102763b51f0e7f4f7cce3e7466784c8b4e5dac9f55741glennrp if (logging != MagickFalse && y == 0) 10277b4a1341a4d06abe5f603ad9052b6ddc1a667dcd5glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 10278b4a1341a4d06abe5f603ad9052b6ddc1a667dcd5glennrp " Writing row of pixels (1)"); 102790fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 10280cf002022280cc4dedb2748ad6f415aac1d44f530glennrp png_write_row(ping,ping_pixels); 102813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 102823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->previous == (Image *) NULL) 102833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 102843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status=SetImageProgress(image,LoadImageTag,pass,num_passes); 102853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (status == MagickFalse) 102863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 102873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 102883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 102893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 102900fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 102918bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp else /* Not Palette, Bilevel, or Opaque Monochrome */ 102923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 102930fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp if ((!mng_info->write_png8 && !mng_info->write_png24 && 102943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy !mng_info->write_png32) && 1029558e017631f66141a6e36ddbe03a54f6e3ee3a253glennrp (image_matte != MagickFalse || 102965af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp (ping_bit_depth >= MAGICKCORE_QUANTUM_DEPTH)) && 102978d579660c9b96b7a3f3292fc6c518f8b6ca44d50glennrp (mng_info->IsPalette) && ping_have_color == MagickFalse) 102983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 102994c08aed51c5899665ade97263692328eea4af106cristy register const Quantum 103008bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp *p; 103010fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 103028bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp for (pass=0; pass < num_passes; pass++) 103033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 103048bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp 10305bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (y=0; y < (ssize_t) image->rows; y++) 103063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 103073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception); 103082cc891a179d622dde7bbb8854138851e828bc6eaglennrp 103094c08aed51c5899665ade97263692328eea4af106cristy if (p == (const Quantum *) NULL) 103103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 103112cc891a179d622dde7bbb8854138851e828bc6eaglennrp 103125af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp if (ping_color_type == PNG_COLOR_TYPE_GRAY) 103133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 103148bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp if (mng_info->IsPalette) 103154c08aed51c5899665ade97263692328eea4af106cristy (void) ExportQuantumPixels(image,(CacheView *) NULL, 10316cf002022280cc4dedb2748ad6f415aac1d44f530glennrp quantum_info,GrayQuantum,ping_pixels,&image->exception); 103172cc891a179d622dde7bbb8854138851e828bc6eaglennrp 103183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 103194c08aed51c5899665ade97263692328eea4af106cristy (void) ExportQuantumPixels(image,(CacheView *) NULL, 10320cf002022280cc4dedb2748ad6f415aac1d44f530glennrp quantum_info,RedQuantum,ping_pixels,&image->exception); 103212cc891a179d622dde7bbb8854138851e828bc6eaglennrp 103228bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp if (logging != MagickFalse && y == 0) 103238bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 103248bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp " Writing GRAY PNG pixels (2)"); 103253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 103262cc891a179d622dde7bbb8854138851e828bc6eaglennrp 103278bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp else /* PNG_COLOR_TYPE_GRAY_ALPHA */ 10328b4a1341a4d06abe5f603ad9052b6ddc1a667dcd5glennrp { 103293b51f0e7f4f7cce3e7466784c8b4e5dac9f55741glennrp if (logging != MagickFalse && y == 0) 10330b4a1341a4d06abe5f603ad9052b6ddc1a667dcd5glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 103318bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp " Writing GRAY_ALPHA PNG pixels (2)"); 103322cc891a179d622dde7bbb8854138851e828bc6eaglennrp 103334c08aed51c5899665ade97263692328eea4af106cristy (void) ExportQuantumPixels(image,(CacheView *) NULL, 10334cf002022280cc4dedb2748ad6f415aac1d44f530glennrp quantum_info,GrayAlphaQuantum,ping_pixels,&image->exception); 10335b4a1341a4d06abe5f603ad9052b6ddc1a667dcd5glennrp } 103362cc891a179d622dde7bbb8854138851e828bc6eaglennrp 103373b51f0e7f4f7cce3e7466784c8b4e5dac9f55741glennrp if (logging != MagickFalse && y == 0) 10338b4a1341a4d06abe5f603ad9052b6ddc1a667dcd5glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 103398bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp " Writing row of pixels (2)"); 103402cc891a179d622dde7bbb8854138851e828bc6eaglennrp 10341cf002022280cc4dedb2748ad6f415aac1d44f530glennrp png_write_row(ping,ping_pixels); 103423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 103432cc891a179d622dde7bbb8854138851e828bc6eaglennrp 103448bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp if (image->previous == (Image *) NULL) 103458bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp { 103468bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp status=SetImageProgress(image,LoadImageTag,pass,num_passes); 103478bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp if (status == MagickFalse) 103488bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp break; 103498bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp } 103508bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp } 103518bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp } 103520fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 103533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 103543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 103554c08aed51c5899665ade97263692328eea4af106cristy register const Quantum 103568bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp *p; 103570fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 103588bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp for (pass=0; pass < num_passes; pass++) 103593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 103608bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp if ((image_depth > 8) || (mng_info->write_png24 || 103618bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp mng_info->write_png32 || 103628bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp (!mng_info->write_png8 && !mng_info->IsPalette))) 103638bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp { 103648bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp for (y=0; y < (ssize_t) image->rows; y++) 10365b4a1341a4d06abe5f603ad9052b6ddc1a667dcd5glennrp { 103668bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp p=GetVirtualPixels(image,0,y,image->columns,1, 103678bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp &image->exception); 103682cc891a179d622dde7bbb8854138851e828bc6eaglennrp 103694c08aed51c5899665ade97263692328eea4af106cristy if (p == (const Quantum *) NULL) 103708bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp break; 103712cc891a179d622dde7bbb8854138851e828bc6eaglennrp 103728bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp if (ping_color_type == PNG_COLOR_TYPE_GRAY) 103738bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp { 103748bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp if (image->storage_class == DirectClass) 103754c08aed51c5899665ade97263692328eea4af106cristy (void) ExportQuantumPixels(image,(CacheView *) NULL, 10376cf002022280cc4dedb2748ad6f415aac1d44f530glennrp quantum_info,RedQuantum,ping_pixels,&image->exception); 103772cc891a179d622dde7bbb8854138851e828bc6eaglennrp 103788bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp else 103794c08aed51c5899665ade97263692328eea4af106cristy (void) ExportQuantumPixels(image,(CacheView *) NULL, 10380cf002022280cc4dedb2748ad6f415aac1d44f530glennrp quantum_info,GrayQuantum,ping_pixels,&image->exception); 103818bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp } 103822cc891a179d622dde7bbb8854138851e828bc6eaglennrp 103838bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp else if (ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA) 103848bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp { 103854c08aed51c5899665ade97263692328eea4af106cristy (void) ExportQuantumPixels(image,(CacheView *) NULL, 10386cf002022280cc4dedb2748ad6f415aac1d44f530glennrp quantum_info,GrayAlphaQuantum,ping_pixels, 103878bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp &image->exception); 103882cc891a179d622dde7bbb8854138851e828bc6eaglennrp 103898bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp if (logging != MagickFalse && y == 0) 103908bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 103918bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp " Writing GRAY_ALPHA PNG pixels (3)"); 103928bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp } 103932cc891a179d622dde7bbb8854138851e828bc6eaglennrp 103948bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp else if (image_matte != MagickFalse) 103954c08aed51c5899665ade97263692328eea4af106cristy (void) ExportQuantumPixels(image,(CacheView *) NULL, 10396cf002022280cc4dedb2748ad6f415aac1d44f530glennrp quantum_info,RGBAQuantum,ping_pixels,&image->exception); 103972cc891a179d622dde7bbb8854138851e828bc6eaglennrp 103988bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp else 103994c08aed51c5899665ade97263692328eea4af106cristy (void) ExportQuantumPixels(image,(CacheView *) NULL, 10400cf002022280cc4dedb2748ad6f415aac1d44f530glennrp quantum_info,RGBQuantum,ping_pixels,&image->exception); 104012cc891a179d622dde7bbb8854138851e828bc6eaglennrp 104023b51f0e7f4f7cce3e7466784c8b4e5dac9f55741glennrp if (logging != MagickFalse && y == 0) 10403b4a1341a4d06abe5f603ad9052b6ddc1a667dcd5glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 104048bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp " Writing row of pixels (3)"); 104052cc891a179d622dde7bbb8854138851e828bc6eaglennrp 10406cf002022280cc4dedb2748ad6f415aac1d44f530glennrp png_write_row(ping,ping_pixels); 10407b4a1341a4d06abe5f603ad9052b6ddc1a667dcd5glennrp } 104088bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp } 104092cc891a179d622dde7bbb8854138851e828bc6eaglennrp 104108bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp else 104118bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp /* not ((image_depth > 8) || (mng_info->write_png24 || 104128bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp mng_info->write_png32 || 104138bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp (!mng_info->write_png8 && !mng_info->IsPalette))) */ 104148bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp { 104158bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp if ((ping_color_type != PNG_COLOR_TYPE_GRAY) && 104168bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp (ping_color_type != PNG_COLOR_TYPE_GRAY_ALPHA)) 104178bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp { 104188bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp if (logging != MagickFalse) 104198bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 104208bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp " pass %d, Image Is not GRAY or GRAY_ALPHA",pass); 104212cc891a179d622dde7bbb8854138851e828bc6eaglennrp 104228bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp quantum_info->depth=8; 104238bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp image_depth=8; 104248bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp } 104252cc891a179d622dde7bbb8854138851e828bc6eaglennrp 104268bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp for (y=0; y < (ssize_t) image->rows; y++) 104278640fb5e9b1094f35f8beab436f81661b8a99448glennrp { 104288bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp if (logging != MagickFalse && y == 0) 104298bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 104308bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp " pass %d, Image Is RGB, 16-bit GRAY, or GRAY_ALPHA",pass); 104312cc891a179d622dde7bbb8854138851e828bc6eaglennrp 10432770d193edfaf07ccf8d1947f6c3c6ee45fa65971glennrp p=GetVirtualPixels(image,0,y,image->columns,1, 10433770d193edfaf07ccf8d1947f6c3c6ee45fa65971glennrp &image->exception); 104342cc891a179d622dde7bbb8854138851e828bc6eaglennrp 104354c08aed51c5899665ade97263692328eea4af106cristy if (p == (const Quantum *) NULL) 104368bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp break; 104372cc891a179d622dde7bbb8854138851e828bc6eaglennrp 104388bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp if (ping_color_type == PNG_COLOR_TYPE_GRAY) 1043944757ab033a4bc1f272fb26c9a46325ca01a5482glennrp { 104404bf89731a90c6e03598950223e19e7be7b95d630glennrp quantum_info->depth=image->depth; 104414bf89731a90c6e03598950223e19e7be7b95d630glennrp 104424c08aed51c5899665ade97263692328eea4af106cristy (void) ExportQuantumPixels(image,(CacheView *) NULL, 10443cf002022280cc4dedb2748ad6f415aac1d44f530glennrp quantum_info,GrayQuantum,ping_pixels,&image->exception); 1044444757ab033a4bc1f272fb26c9a46325ca01a5482glennrp } 104452cc891a179d622dde7bbb8854138851e828bc6eaglennrp 104468bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp else if (ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA) 104478bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp { 104488bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp if (logging != MagickFalse && y == 0) 104498bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 104508bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp " Writing GRAY_ALPHA PNG pixels (4)"); 104512cc891a179d622dde7bbb8854138851e828bc6eaglennrp 104524c08aed51c5899665ade97263692328eea4af106cristy (void) ExportQuantumPixels(image,(CacheView *) NULL, 10453cf002022280cc4dedb2748ad6f415aac1d44f530glennrp quantum_info,GrayAlphaQuantum,ping_pixels, 10454d6bf1617e99df0272b231855a933a74e99b6578fglennrp &image->exception); 104558bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp } 104562cc891a179d622dde7bbb8854138851e828bc6eaglennrp 104578bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp else 104588bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp { 104594c08aed51c5899665ade97263692328eea4af106cristy (void) ExportQuantumPixels(image,(CacheView *) NULL, 104605eae76090b1e30c1e546508dd1d17711ddd3fcc0glennrp quantum_info,IndexQuantum,ping_pixels,&image->exception); 104612cc891a179d622dde7bbb8854138851e828bc6eaglennrp 104625eae76090b1e30c1e546508dd1d17711ddd3fcc0glennrp if (logging != MagickFalse && y <= 2) 104635eae76090b1e30c1e546508dd1d17711ddd3fcc0glennrp { 104645eae76090b1e30c1e546508dd1d17711ddd3fcc0glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 104651a7d6dbd296698a7cddbc625896987bf674c0cc4glennrp " Writing row of non-gray pixels (4)"); 104665eae76090b1e30c1e546508dd1d17711ddd3fcc0glennrp 104675eae76090b1e30c1e546508dd1d17711ddd3fcc0glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 104685eae76090b1e30c1e546508dd1d17711ddd3fcc0glennrp " ping_pixels[0]=%d,ping_pixels[1]=%d", 104695eae76090b1e30c1e546508dd1d17711ddd3fcc0glennrp (int)ping_pixels[0],(int)ping_pixels[1]); 104705eae76090b1e30c1e546508dd1d17711ddd3fcc0glennrp } 104718bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp } 10472cf002022280cc4dedb2748ad6f415aac1d44f530glennrp png_write_row(ping,ping_pixels); 104738bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp } 104748bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp } 104752cc891a179d622dde7bbb8854138851e828bc6eaglennrp 104768bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp if (image->previous == (Image *) NULL) 104778bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp { 104788bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp status=SetImageProgress(image,LoadImageTag,pass,num_passes); 104798bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp if (status == MagickFalse) 104808bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp break; 104818640fb5e9b1094f35f8beab436f81661b8a99448glennrp } 104823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 104833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 104848bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp } 104858bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp 10486b32b90a7e1ee2275333589072c496b5f69e17feccristy if (quantum_info != (QuantumInfo *) NULL) 10487b32b90a7e1ee2275333589072c496b5f69e17feccristy quantum_info=DestroyQuantumInfo(quantum_info); 104883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 104893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 104903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 104913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 10492b4a1341a4d06abe5f603ad9052b6ddc1a667dcd5glennrp " Wrote PNG image data"); 104930fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 104943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 10495e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " Width: %.20g",(double) ping_width); 104960fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 104973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 10498e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " Height: %.20g",(double) ping_height); 104990fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 105003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->write_png_depth) 105013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 105023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 105033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Defined PNG:bit-depth: %d",mng_info->write_png_depth); 105043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 105050fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 105063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 105075af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp " PNG bit-depth written: %d",ping_bit_depth); 105080fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 105093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->write_png_colortype) 105103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 105113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 105123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Defined PNG:color-type: %d",mng_info->write_png_colortype-1); 105133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 105140fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 105153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 105165af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp " PNG color-type written: %d",ping_color_type); 105170fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 105183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 105195af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp " PNG Interlace method: %d",ping_interlace_method); 105203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 105213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 10522a0ed009a1e9480ac6f3f4520e9ef29d6d37e27dcglennrp Generate text chunks after IDAT. 105233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 10524823b55c200d7fc1818ab539b036a9c24feaecda8glennrp if (ping_exclude_tEXt == MagickFalse || ping_exclude_zTXt == MagickFalse) 105253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 1052626f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp ResetImagePropertyIterator(image); 1052726f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp property=GetNextImageProperty(image); 1052826f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp while (property != (const char *) NULL) 1052926f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp { 1053026f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp png_textp 1053126f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp text; 105322cc891a179d622dde7bbb8854138851e828bc6eaglennrp 1053326f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp value=GetImageProperty(image,property); 10534a0ed009a1e9480ac6f3f4520e9ef29d6d37e27dcglennrp 10535a0ed009a1e9480ac6f3f4520e9ef29d6d37e27dcglennrp /* Don't write any "png:" properties; those are just for "identify" */ 10536a0ed009a1e9480ac6f3f4520e9ef29d6d37e27dcglennrp if (LocaleNCompare(property,"png:",4) != 0 && 10537a0ed009a1e9480ac6f3f4520e9ef29d6d37e27dcglennrp 10538a0ed009a1e9480ac6f3f4520e9ef29d6d37e27dcglennrp /* Suppress density and units if we wrote a pHYs chunk */ 10539a0ed009a1e9480ac6f3f4520e9ef29d6d37e27dcglennrp (ping_exclude_pHYs != MagickFalse || 10540823b55c200d7fc1818ab539b036a9c24feaecda8glennrp LocaleCompare(property,"density") != 0 || 10541a0ed009a1e9480ac6f3f4520e9ef29d6d37e27dcglennrp LocaleCompare(property,"units") != 0) && 10542a0ed009a1e9480ac6f3f4520e9ef29d6d37e27dcglennrp 10543a0ed009a1e9480ac6f3f4520e9ef29d6d37e27dcglennrp /* Suppress the IM-generated Date:create and Date:modify */ 10544a0ed009a1e9480ac6f3f4520e9ef29d6d37e27dcglennrp (ping_exclude_date == MagickFalse || 10545a0ed009a1e9480ac6f3f4520e9ef29d6d37e27dcglennrp LocaleNCompare(property, "Date:",5) != 0)) 1054626f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp { 10547c70af4ac292f8db9a1ab488318912894d412cb8cglennrp if (value != (const char *) NULL) 10548c70af4ac292f8db9a1ab488318912894d412cb8cglennrp { 10549c70af4ac292f8db9a1ab488318912894d412cb8cglennrp text=(png_textp) png_malloc(ping,(png_uint_32) sizeof(png_text)); 10550c70af4ac292f8db9a1ab488318912894d412cb8cglennrp text[0].key=(char *) property; 10551c70af4ac292f8db9a1ab488318912894d412cb8cglennrp text[0].text=(char *) value; 10552c70af4ac292f8db9a1ab488318912894d412cb8cglennrp text[0].text_length=strlen(value); 105532cc891a179d622dde7bbb8854138851e828bc6eaglennrp 10554c70af4ac292f8db9a1ab488318912894d412cb8cglennrp if (ping_exclude_tEXt != MagickFalse) 10555c70af4ac292f8db9a1ab488318912894d412cb8cglennrp text[0].compression=PNG_TEXT_COMPRESSION_zTXt; 105562cc891a179d622dde7bbb8854138851e828bc6eaglennrp 10557c70af4ac292f8db9a1ab488318912894d412cb8cglennrp else if (ping_exclude_zTXt != MagickFalse) 10558c70af4ac292f8db9a1ab488318912894d412cb8cglennrp text[0].compression=PNG_TEXT_COMPRESSION_NONE; 105592cc891a179d622dde7bbb8854138851e828bc6eaglennrp 10560c70af4ac292f8db9a1ab488318912894d412cb8cglennrp else 1056126f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp { 10562c70af4ac292f8db9a1ab488318912894d412cb8cglennrp text[0].compression=image_info->compression == NoCompression || 10563c70af4ac292f8db9a1ab488318912894d412cb8cglennrp (image_info->compression == UndefinedCompression && 10564c70af4ac292f8db9a1ab488318912894d412cb8cglennrp text[0].text_length < 128) ? PNG_TEXT_COMPRESSION_NONE : 10565c70af4ac292f8db9a1ab488318912894d412cb8cglennrp PNG_TEXT_COMPRESSION_zTXt ; 1056626f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp } 105672cc891a179d622dde7bbb8854138851e828bc6eaglennrp 10568c70af4ac292f8db9a1ab488318912894d412cb8cglennrp if (logging != MagickFalse) 10569c70af4ac292f8db9a1ab488318912894d412cb8cglennrp { 10570c70af4ac292f8db9a1ab488318912894d412cb8cglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 10571c70af4ac292f8db9a1ab488318912894d412cb8cglennrp " Setting up text chunk"); 10572c70af4ac292f8db9a1ab488318912894d412cb8cglennrp 10573c70af4ac292f8db9a1ab488318912894d412cb8cglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 10574c70af4ac292f8db9a1ab488318912894d412cb8cglennrp " keyword: %s",text[0].key); 10575c70af4ac292f8db9a1ab488318912894d412cb8cglennrp } 10576c70af4ac292f8db9a1ab488318912894d412cb8cglennrp 10577c70af4ac292f8db9a1ab488318912894d412cb8cglennrp png_set_text(ping,ping_info,text,1); 10578c70af4ac292f8db9a1ab488318912894d412cb8cglennrp png_free(ping,text); 10579c70af4ac292f8db9a1ab488318912894d412cb8cglennrp } 1058026f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp } 1058126f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp property=GetNextImageProperty(image); 1058226f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp } 105833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 105843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 105853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* write any PNG-chunk-e profiles */ 10586cf002022280cc4dedb2748ad6f415aac1d44f530glennrp (void) Magick_png_write_chunk_from_profile(image,"PNG-chunk-e",logging); 105873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 105883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 105893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 105903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Writing PNG end info"); 105910fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 105923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_write_end(ping,ping_info); 105930fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 105943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->need_fram && (int) image->dispose == BackgroundDispose) 105953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 105963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->page.x || mng_info->page.y || 105975af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp (ping_width != mng_info->page.width) || 105985af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp (ping_height != mng_info->page.height)) 105993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 106003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy unsigned char 106013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[32]; 106023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 106033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 106043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Write FRAM 4 with clipping boundaries followed by FRAM 1. 106053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 106063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,27L); /* data length=27 */ 106073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGType(chunk,mng_FRAM); 1060803812ae402fb53d548f0e1d7d14720768f803c2dglennrp LogPNGChunk(logging,mng_FRAM,27L); 106093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[4]=4; 106103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[5]=0; /* frame name separator (no name) */ 106113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[6]=1; /* flag for changing delay, for next frame only */ 106123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[7]=0; /* flag for changing frame timeout */ 106133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[8]=1; /* flag for changing frame clipping for next frame */ 106143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[9]=0; /* flag for changing frame sync_id */ 106153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGLong(chunk+10,(png_uint_32) (0L)); /* temporary 0 delay */ 106163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[14]=0; /* clipping boundaries delta type */ 106173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGLong(chunk+15,(png_uint_32) (mng_info->page.x)); /* left cb */ 106183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGLong(chunk+19, 106195af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp (png_uint_32) (mng_info->page.x + ping_width)); 106203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGLong(chunk+23,(png_uint_32) (mng_info->page.y)); /* top cb */ 106213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGLong(chunk+27, 106225af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp (png_uint_32) (mng_info->page.y + ping_height)); 106233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(image,31,chunk); 106243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,crc32(0,chunk,31)); 106253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->old_framing_mode=4; 106263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->framing_mode=1; 106273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 106280fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 106293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 106303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->framing_mode=3; 106313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 106323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->write_mng && !mng_info->need_fram && 106333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ((int) image->dispose == 3)) 10634c70af4ac292f8db9a1ab488318912894d412cb8cglennrp (void) ThrowMagickException(&image->exception,GetMagickModule(), 106353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy CoderError,"Cannot convert GIF with disposal method 3 to MNG-LC", 10636c70af4ac292f8db9a1ab488318912894d412cb8cglennrp "`%s'",image->filename); 106370fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 106383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 106393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Free PNG resources. 106403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 106415af765f10ae9ac5aae02c0b7c213e22a43c0672dglennrp 106423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy png_destroy_write_struct(&ping,&ping_info); 106433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 10644cf002022280cc4dedb2748ad6f415aac1d44f530glennrp ping_pixels=(unsigned char *) RelinquishMagickMemory(ping_pixels); 106453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 106463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(PNG_SETJMP_NOT_THREAD_SAFE) 10647cf002022280cc4dedb2748ad6f415aac1d44f530glennrp UnlockSemaphoreInfo(ping_semaphore); 106483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 106493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 10650da8f3a7bfddac2680a3069a490db541e7944edafglennrp if (ping_have_blob != MagickFalse) 10651b9cfe27bef51dbbd1f05aef89c767749d7e37864glennrp (void) CloseBlob(image); 10652b9cfe27bef51dbbd1f05aef89c767749d7e37864glennrp 10653b9cfe27bef51dbbd1f05aef89c767749d7e37864glennrp image_info=DestroyImageInfo(image_info); 10654b9cfe27bef51dbbd1f05aef89c767749d7e37864glennrp image=DestroyImage(image); 10655b9cfe27bef51dbbd1f05aef89c767749d7e37864glennrp 10656b9cfe27bef51dbbd1f05aef89c767749d7e37864glennrp /* Store bit depth actually written */ 10657b9cfe27bef51dbbd1f05aef89c767749d7e37864glennrp s[0]=(char) ping_bit_depth; 10658b9cfe27bef51dbbd1f05aef89c767749d7e37864glennrp s[1]='\0'; 10659b9cfe27bef51dbbd1f05aef89c767749d7e37864glennrp 10660b9cfe27bef51dbbd1f05aef89c767749d7e37864glennrp (void) SetImageProperty(IMimage,"png:bit-depth-written",s); 10661b9cfe27bef51dbbd1f05aef89c767749d7e37864glennrp 106623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 106633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 106643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " exit WriteOnePNGImage()"); 106650fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 106663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(MagickTrue); 106673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* End write one PNG image */ 106683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 106693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 106703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 106713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 106723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 106733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 106743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 106753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% W r i t e P N G I m a g e % 106763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 106773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 106783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 106793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 106803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 106813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% WritePNGImage() writes a Portable Network Graphics (PNG) or 106823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Multiple-image Network Graphics (MNG) image file. 106833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 106843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% MNG support written by Glenn Randers-Pehrson, glennrp@image... 106853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 106863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% The format of the WritePNGImage method is: 106873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 106883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% MagickBooleanType WritePNGImage(const ImageInfo *image_info,Image *image) 106893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 106903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% A description of each parameter follows: 106913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 106923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o image_info: the image info. 106933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 106943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o image: The image. 106953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 106963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Returns MagickTrue on success, MagickFalse on failure. 106973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 106983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Communicating with the PNG encoder: 106993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 107003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% While the datastream written is always in PNG format and normally would 107013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% be given the "png" file extension, this method also writes the following 107023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% pseudo-formats which are subsets of PNG: 107033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 107045a39f3714559b4d9c08beb391ce4326354bb0f0cglennrp% o PNG8: An 8-bit indexed PNG datastream is written. If the image has 107055a39f3714559b4d9c08beb391ce4326354bb0f0cglennrp% a depth greater than 8, the depth is reduced. If transparency 107063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% is present, the tRNS chunk must only have values 0 and 255 107073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% (i.e., transparency is binary: fully opaque or fully 107085a39f3714559b4d9c08beb391ce4326354bb0f0cglennrp% transparent). If other values are present they will be 107095a39f3714559b4d9c08beb391ce4326354bb0f0cglennrp% 50%-thresholded to binary transparency. If more than 256 10710e9637cb863ebc78027c145832eaf0b3a62bf2a56glennrp% colors are present, they will be quantized to the 4-4-4-1, 10711e9637cb863ebc78027c145832eaf0b3a62bf2a56glennrp% 3-3-3-1, or 3-3-2-1 palette. 10712e9637cb863ebc78027c145832eaf0b3a62bf2a56glennrp% 10713e9637cb863ebc78027c145832eaf0b3a62bf2a56glennrp% If you want better quantization or dithering of the colors 10714e9637cb863ebc78027c145832eaf0b3a62bf2a56glennrp% or alpha than that, you need to do it before calling the 107155a39f3714559b4d9c08beb391ce4326354bb0f0cglennrp% PNG encoder. The pixels contain 8-bit indices even if 107165a39f3714559b4d9c08beb391ce4326354bb0f0cglennrp% they could be represented with 1, 2, or 4 bits. Grayscale 107173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% images will be written as indexed PNG files even though the 107185a39f3714559b4d9c08beb391ce4326354bb0f0cglennrp% PNG grayscale type might be slightly more efficient. Please 107195a39f3714559b4d9c08beb391ce4326354bb0f0cglennrp% note that writing to the PNG8 format may result in loss 107205a39f3714559b4d9c08beb391ce4326354bb0f0cglennrp% of color and alpha data. 107213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 107223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o PNG24: An 8-bit per sample RGB PNG datastream is written. The tRNS 107233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% chunk can be present to convey binary transparency by naming 107245a39f3714559b4d9c08beb391ce4326354bb0f0cglennrp% one of the colors as transparent. The only loss incurred 107255a39f3714559b4d9c08beb391ce4326354bb0f0cglennrp% is reduction of sample depth to 8. If the image has more 107265a39f3714559b4d9c08beb391ce4326354bb0f0cglennrp% than one transparent color, has semitransparent pixels, or 107275a39f3714559b4d9c08beb391ce4326354bb0f0cglennrp% has an opaque pixel with the same RGB components as the 107285a39f3714559b4d9c08beb391ce4326354bb0f0cglennrp% transparent color, an image is not written. 107293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 107303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o PNG32: An 8-bit per sample RGBA PNG is written. Partial 107313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% transparency is permitted, i.e., the alpha sample for 107323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% each pixel can have any value from 0 to 255. The alpha 107330fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp% channel is present even if the image is fully opaque. 107345a39f3714559b4d9c08beb391ce4326354bb0f0cglennrp% The only loss in data is the reduction of the sample depth 107355a39f3714559b4d9c08beb391ce4326354bb0f0cglennrp% to 8. 107363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 107373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o -define: For more precise control of the PNG output, you can use the 107383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Image options "png:bit-depth" and "png:color-type". These 107393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% can be set from the commandline with "-define" and also 10740bb8a733a352d1143bf6e823471ccce72aee8189fglennrp% from the application programming interfaces. The options 10741bb8a733a352d1143bf6e823471ccce72aee8189fglennrp% are case-independent and are converted to lowercase before 10742bb8a733a352d1143bf6e823471ccce72aee8189fglennrp% being passed to this encoder. 107433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 107443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% png:color-type can be 0, 2, 3, 4, or 6. 107453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 107463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% When png:color-type is 0 (Grayscale), png:bit-depth can 107473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% be 1, 2, 4, 8, or 16. 107483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 107493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% When png:color-type is 2 (RGB), png:bit-depth can 107503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% be 8 or 16. 107513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 107523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% When png:color-type is 3 (Indexed), png:bit-depth can 107533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% be 1, 2, 4, or 8. This refers to the number of bits 107543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% used to store the index. The color samples always have 107553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% bit-depth 8 in indexed PNG files. 107563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 107573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% When png:color-type is 4 (Gray-Matte) or 6 (RGB-Matte), 107583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% png:bit-depth can be 8 or 16. 107593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 107605a39f3714559b4d9c08beb391ce4326354bb0f0cglennrp% If the image cannot be written without loss with the requested bit-depth 107615a39f3714559b4d9c08beb391ce4326354bb0f0cglennrp% and color-type, a PNG file will not be written, and the encoder will 107625a39f3714559b4d9c08beb391ce4326354bb0f0cglennrp% return MagickFalse. 107635a39f3714559b4d9c08beb391ce4326354bb0f0cglennrp% 107643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Since image encoders should not be responsible for the "heavy lifting", 107653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% the user should make sure that ImageMagick has already reduced the 107663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% image depth and number of colors and limit transparency to binary 107675a39f3714559b4d9c08beb391ce4326354bb0f0cglennrp% transparency prior to attempting to write the image with depth, color, 1076854dc0694601d2c51ec50c76e3fd90d9ff704df9bglennrp% or transparency limitations. 107693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 107703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Note that another definition, "png:bit-depth-written" exists, but it 107713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% is not intended for external use. It is only used internally by the 107723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% PNG encoder to inform the JNG encoder of the depth of the alpha channel. 107733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 107743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% It is possible to request that the PNG encoder write previously-formatted 107753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% ancillary chunks in the output PNG file, using the "-profile" commandline 107763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% option as shown below or by setting the profile via a programming 107773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% interface: 107783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 107793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% -profile PNG-chunk-x:<file> 107803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 107813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% where x is a location flag and <file> is a file containing the chunk 107823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% name in the first 4 bytes, then a colon (":"), followed by the chunk data. 10783bb8a733a352d1143bf6e823471ccce72aee8189fglennrp% This encoder will compute the chunk length and CRC, so those must not 10784bb8a733a352d1143bf6e823471ccce72aee8189fglennrp% be included in the file. 107853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 107863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% "x" can be "b" (before PLTE), "m" (middle, i.e., between PLTE and IDAT), 107873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% or "e" (end, i.e., after IDAT). If you want to write multiple chunks 107883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% of the same type, then add a short unique string after the "x" to prevent 10789bb8a733a352d1143bf6e823471ccce72aee8189fglennrp% subsequent profiles from overwriting the preceding ones, e.g., 107903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 10791bb8a733a352d1143bf6e823471ccce72aee8189fglennrp% -profile PNG-chunk-b01:file01 -profile PNG-chunk-b02:file02 107923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 107933241bd0c43e56612fc7aa006a0d30333dacbb51aglennrp% As of version 6.6.6 the following optimizations are always done: 107940fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp% 10795d6afd54fac7c96376ea623fb7ab6c3e398cb7064glennrp% o 32-bit depth is reduced to 16. 107960fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp% o 16-bit depth is reduced to 8 if all pixels contain samples whose 107970fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp% high byte and low byte are identical. 107980fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp% o Palette is sorted to remove unused entries and to put a 10799cf002022280cc4dedb2748ad6f415aac1d44f530glennrp% transparent color first, if BUILD_PNG_PALETTE is defined. 108000fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp% o Opaque matte channel is removed when writing an indexed PNG. 10801d6afd54fac7c96376ea623fb7ab6c3e398cb7064glennrp% o Grayscale images are reduced to 1, 2, or 4 bit depth if 10802d6afd54fac7c96376ea623fb7ab6c3e398cb7064glennrp% this can be done without loss and a larger bit depth N was not 10803d6afd54fac7c96376ea623fb7ab6c3e398cb7064glennrp% requested via the "-define PNG:bit-depth=N" option. 10804d6afd54fac7c96376ea623fb7ab6c3e398cb7064glennrp% o If matte channel is present but only one transparent color is 10805d6afd54fac7c96376ea623fb7ab6c3e398cb7064glennrp% present, RGB+tRNS is written instead of RGBA 10806d6afd54fac7c96376ea623fb7ab6c3e398cb7064glennrp% o Opaque matte channel is removed (or added, if color-type 4 or 6 10807d6afd54fac7c96376ea623fb7ab6c3e398cb7064glennrp% was requested when converting an opaque image). 108080fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp% 108093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 108103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 108113ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic MagickBooleanType WritePNGImage(const ImageInfo *image_info, 108123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Image *image) 108133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 108143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MagickBooleanType 1081521f0e6211a440c0f96134ea25a1bfe7c5f91c29cglennrp excluding, 1081621f0e6211a440c0f96134ea25a1bfe7c5f91c29cglennrp logging, 1081721f0e6211a440c0f96134ea25a1bfe7c5f91c29cglennrp have_mng_structure, 108183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status; 108193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 108203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngInfo 108213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *mng_info; 108223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 108233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy const char 108243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *value; 108253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 108263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy int 1082721f0e6211a440c0f96134ea25a1bfe7c5f91c29cglennrp i, 108285c7cf4e469a4dad7e277783749155932252c52dfglennrp source; 108295c7cf4e469a4dad7e277783749155932252c52dfglennrp 108303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 108313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Open image file. 108323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 108333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(image_info != (const ImageInfo *) NULL); 108343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(image_info->signature == MagickSignature); 108353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(image != (Image *) NULL); 108363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(image->signature == MagickSignature); 108373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); 10838fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp logging=LogMagickEvent(CoderEvent,GetMagickModule(),"Enter WritePNGImage()"); 108393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 108403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Allocate a MngInfo structure. 108413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 108423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy have_mng_structure=MagickFalse; 1084373bd4a51b419e914565bdf204bf1540dc4c8ee26cristy mng_info=(MngInfo *) AcquireMagickMemory(sizeof(MngInfo)); 108440fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 108453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info == (MngInfo *) NULL) 108463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); 108470fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 108483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 108493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Initialize members of the MngInfo structure. 108503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 108513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ResetMagickMemory(mng_info,0,sizeof(MngInfo)); 108523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->image=image; 10853a521b2fe1f4c8b8ab9412bd6ef23b6736b90e43dglennrp mng_info->equal_backgrounds=MagickTrue; 108543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy have_mng_structure=MagickTrue; 108553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 108563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* See if user has requested a specific PNG subformat */ 108573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 108583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->write_png8=LocaleCompare(image_info->magick,"PNG8") == 0; 108593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->write_png24=LocaleCompare(image_info->magick,"PNG24") == 0; 108603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->write_png32=LocaleCompare(image_info->magick,"PNG32") == 0; 108613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 108623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->write_png8) 108633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 108649c1eb0729653219b9da9037e044501a6dce79d10glennrp mng_info->write_png_colortype = /* 3 */ 4; 108659c1eb0729653219b9da9037e044501a6dce79d10glennrp mng_info->write_png_depth = 8; 108669c1eb0729653219b9da9037e044501a6dce79d10glennrp image->depth = 8; 108673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 108683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 108693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->write_png24) 108703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 108719c1eb0729653219b9da9037e044501a6dce79d10glennrp mng_info->write_png_colortype = /* 2 */ 3; 108729c1eb0729653219b9da9037e044501a6dce79d10glennrp mng_info->write_png_depth = 8; 108739c1eb0729653219b9da9037e044501a6dce79d10glennrp image->depth = 8; 108740fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 108759c1eb0729653219b9da9037e044501a6dce79d10glennrp if (image->matte == MagickTrue) 108769c1eb0729653219b9da9037e044501a6dce79d10glennrp (void) SetImageType(image,TrueColorMatteType); 108770fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 108789c1eb0729653219b9da9037e044501a6dce79d10glennrp else 108799c1eb0729653219b9da9037e044501a6dce79d10glennrp (void) SetImageType(image,TrueColorType); 108800fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 108819c1eb0729653219b9da9037e044501a6dce79d10glennrp (void) SyncImage(image); 108823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 108833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 108843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->write_png32) 108853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 108869c1eb0729653219b9da9037e044501a6dce79d10glennrp mng_info->write_png_colortype = /* 6 */ 7; 108879c1eb0729653219b9da9037e044501a6dce79d10glennrp mng_info->write_png_depth = 8; 108889c1eb0729653219b9da9037e044501a6dce79d10glennrp image->depth = 8; 108890fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 108909c1eb0729653219b9da9037e044501a6dce79d10glennrp if (image->matte == MagickTrue) 108919c1eb0729653219b9da9037e044501a6dce79d10glennrp (void) SetImageType(image,TrueColorMatteType); 108920fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 108939c1eb0729653219b9da9037e044501a6dce79d10glennrp else 108949c1eb0729653219b9da9037e044501a6dce79d10glennrp (void) SetImageType(image,TrueColorType); 108950fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 108969c1eb0729653219b9da9037e044501a6dce79d10glennrp (void) SyncImage(image); 108973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 108983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 108993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy value=GetImageOption(image_info,"png:bit-depth"); 109008bb3a02a0021145f36ed1057d3153c74abdcabaeglennrp 109013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (value != (char *) NULL) 109023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 109033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (LocaleCompare(value,"1") == 0) 109049c1eb0729653219b9da9037e044501a6dce79d10glennrp mng_info->write_png_depth = 1; 109050fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 109063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else if (LocaleCompare(value,"2") == 0) 109079c1eb0729653219b9da9037e044501a6dce79d10glennrp mng_info->write_png_depth = 2; 109080fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 109093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else if (LocaleCompare(value,"4") == 0) 109109c1eb0729653219b9da9037e044501a6dce79d10glennrp mng_info->write_png_depth = 4; 109110fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 109123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else if (LocaleCompare(value,"8") == 0) 109139c1eb0729653219b9da9037e044501a6dce79d10glennrp mng_info->write_png_depth = 8; 109140fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 109153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else if (LocaleCompare(value,"16") == 0) 109169c1eb0729653219b9da9037e044501a6dce79d10glennrp mng_info->write_png_depth = 16; 109170fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 10918bb8a733a352d1143bf6e823471ccce72aee8189fglennrp else 10919bb8a733a352d1143bf6e823471ccce72aee8189fglennrp (void) ThrowMagickException(&image->exception, 10920bb8a733a352d1143bf6e823471ccce72aee8189fglennrp GetMagickModule(),CoderWarning, 10921bb8a733a352d1143bf6e823471ccce72aee8189fglennrp "ignoring invalid defined png:bit-depth", 10922bb8a733a352d1143bf6e823471ccce72aee8189fglennrp "=%s",value); 10923bb8a733a352d1143bf6e823471ccce72aee8189fglennrp 109243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 109259c1eb0729653219b9da9037e044501a6dce79d10glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 10926bb8a733a352d1143bf6e823471ccce72aee8189fglennrp " png:bit-depth=%d was defined.\n",mng_info->write_png_depth); 109273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 109280fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 109293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy value=GetImageOption(image_info,"png:color-type"); 109300fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 109313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (value != (char *) NULL) 109323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 109333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* We must store colortype+1 because 0 is a valid colortype */ 109343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (LocaleCompare(value,"0") == 0) 109359c1eb0729653219b9da9037e044501a6dce79d10glennrp mng_info->write_png_colortype = 1; 109360fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 109373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else if (LocaleCompare(value,"2") == 0) 109389c1eb0729653219b9da9037e044501a6dce79d10glennrp mng_info->write_png_colortype = 3; 109390fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 109403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else if (LocaleCompare(value,"3") == 0) 109419c1eb0729653219b9da9037e044501a6dce79d10glennrp mng_info->write_png_colortype = 4; 109420fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 109433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else if (LocaleCompare(value,"4") == 0) 109449c1eb0729653219b9da9037e044501a6dce79d10glennrp mng_info->write_png_colortype = 5; 109450fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 109463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else if (LocaleCompare(value,"6") == 0) 109479c1eb0729653219b9da9037e044501a6dce79d10glennrp mng_info->write_png_colortype = 7; 109480fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 10949bb8a733a352d1143bf6e823471ccce72aee8189fglennrp else 10950bb8a733a352d1143bf6e823471ccce72aee8189fglennrp (void) ThrowMagickException(&image->exception, 10951bb8a733a352d1143bf6e823471ccce72aee8189fglennrp GetMagickModule(),CoderWarning, 10952bb8a733a352d1143bf6e823471ccce72aee8189fglennrp "ignoring invalid defined png:color-type", 10953bb8a733a352d1143bf6e823471ccce72aee8189fglennrp "=%s",value); 10954bb8a733a352d1143bf6e823471ccce72aee8189fglennrp 109553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 109569c1eb0729653219b9da9037e044501a6dce79d10glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 10957d6bf1617e99df0272b231855a933a74e99b6578fglennrp " png:color-type=%d was defined.\n",mng_info->write_png_colortype-1); 109583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 109593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 109600e8ea19baa0666ccfe869d19116372f60fe9230fglennrp /* Check for chunks to be excluded: 109610e8ea19baa0666ccfe869d19116372f60fe9230fglennrp * 109620dff56c31fb2f5daa9744018ca533e387c246afcglennrp * The default is to not exclude any known chunks except for any 109630e8ea19baa0666ccfe869d19116372f60fe9230fglennrp * listed in the "unused_chunks" array, above. 109640e8ea19baa0666ccfe869d19116372f60fe9230fglennrp * 109650e8ea19baa0666ccfe869d19116372f60fe9230fglennrp * Chunks can be listed for exclusion via a "PNG:exclude-chunk" 109660e8ea19baa0666ccfe869d19116372f60fe9230fglennrp * define (in the image properties or in the image artifacts) 109670e8ea19baa0666ccfe869d19116372f60fe9230fglennrp * or via a mng_info member. For convenience, in addition 109680e8ea19baa0666ccfe869d19116372f60fe9230fglennrp * to or instead of a comma-separated list of chunks, the 109690e8ea19baa0666ccfe869d19116372f60fe9230fglennrp * "exclude-chunk" string can be simply "all" or "none". 109700e8ea19baa0666ccfe869d19116372f60fe9230fglennrp * 109710e8ea19baa0666ccfe869d19116372f60fe9230fglennrp * The exclude-chunk define takes priority over the mng_info. 109720e8ea19baa0666ccfe869d19116372f60fe9230fglennrp * 109730e8ea19baa0666ccfe869d19116372f60fe9230fglennrp * A "PNG:include-chunk" define takes priority over both the 109740e8ea19baa0666ccfe869d19116372f60fe9230fglennrp * mng_info and the "PNG:exclude-chunk" define. Like the 109750e8ea19baa0666ccfe869d19116372f60fe9230fglennrp * "exclude-chunk" string, it can define "all" or "none" as 109760dff56c31fb2f5daa9744018ca533e387c246afcglennrp * well as a comma-separated list. Chunks that are unknown to 109770dff56c31fb2f5daa9744018ca533e387c246afcglennrp * ImageMagick are always excluded, regardless of their "copy-safe" 109780dff56c31fb2f5daa9744018ca533e387c246afcglennrp * status according to the PNG specification, and even if they 109790dff56c31fb2f5daa9744018ca533e387c246afcglennrp * appear in the "include-chunk" list. 109800e8ea19baa0666ccfe869d19116372f60fe9230fglennrp * 109810e8ea19baa0666ccfe869d19116372f60fe9230fglennrp * Finally, all chunks listed in the "unused_chunks" array are 109820e8ea19baa0666ccfe869d19116372f60fe9230fglennrp * automatically excluded, regardless of the other instructions 109830e8ea19baa0666ccfe869d19116372f60fe9230fglennrp * or lack thereof. 109840e8ea19baa0666ccfe869d19116372f60fe9230fglennrp * 109850e8ea19baa0666ccfe869d19116372f60fe9230fglennrp * if you exclude sRGB but not gAMA (recommended), then sRGB chunk 109860e8ea19baa0666ccfe869d19116372f60fe9230fglennrp * will not be written and the gAMA chunk will only be written if it 109870e8ea19baa0666ccfe869d19116372f60fe9230fglennrp * is not between .45 and .46, or approximately (1.0/2.2). 109880e8ea19baa0666ccfe869d19116372f60fe9230fglennrp * 109890e8ea19baa0666ccfe869d19116372f60fe9230fglennrp * If you exclude tRNS and the image has transparency, the colortype 109900e8ea19baa0666ccfe869d19116372f60fe9230fglennrp * is forced to be 4 or 6 (GRAY_ALPHA or RGB_ALPHA). 109910e8ea19baa0666ccfe869d19116372f60fe9230fglennrp * 109920e8ea19baa0666ccfe869d19116372f60fe9230fglennrp * The -strip option causes StripImage() to set the png:include-chunk 109930e8ea19baa0666ccfe869d19116372f60fe9230fglennrp * artifact to "none,gama". 109940e8ea19baa0666ccfe869d19116372f60fe9230fglennrp */ 109950e8ea19baa0666ccfe869d19116372f60fe9230fglennrp 1099626f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp mng_info->ping_exclude_bKGD=MagickFalse; 1099726f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp mng_info->ping_exclude_cHRM=MagickFalse; 10998a0ed009a1e9480ac6f3f4520e9ef29d6d37e27dcglennrp mng_info->ping_exclude_date=MagickFalse; 1099926f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp mng_info->ping_exclude_EXIF=MagickFalse; /* hex-encoded EXIF in zTXt */ 1100026f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp mng_info->ping_exclude_gAMA=MagickFalse; 1100126f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp mng_info->ping_exclude_iCCP=MagickFalse; 1100226f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp /* mng_info->ping_exclude_iTXt=MagickFalse; */ 1100326f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp mng_info->ping_exclude_oFFs=MagickFalse; 1100426f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp mng_info->ping_exclude_pHYs=MagickFalse; 1100526f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp mng_info->ping_exclude_sRGB=MagickFalse; 1100626f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp mng_info->ping_exclude_tEXt=MagickFalse; 11007a1e3b7b4887860a199d00bddbf4b12e0a93ee1e5glennrp mng_info->ping_exclude_tRNS=MagickFalse; 1100826f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp mng_info->ping_exclude_vpAg=MagickFalse; 1100926f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp mng_info->ping_exclude_zCCP=MagickFalse; /* hex-encoded iCCP in zTXt */ 1101026f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp mng_info->ping_exclude_zTXt=MagickFalse; 1101126f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp 110128d3d6e584829223ac5f6e6653c3caa38a2562a74glennrp mng_info->ping_preserve_colormap=MagickFalse; 110138d3d6e584829223ac5f6e6653c3caa38a2562a74glennrp 110148d3d6e584829223ac5f6e6653c3caa38a2562a74glennrp value=GetImageArtifact(image,"png:preserve-colormap"); 110158d3d6e584829223ac5f6e6653c3caa38a2562a74glennrp if (value == NULL) 110168d3d6e584829223ac5f6e6653c3caa38a2562a74glennrp value=GetImageOption(image_info,"png:preserve-colormap"); 110178d3d6e584829223ac5f6e6653c3caa38a2562a74glennrp if (value != NULL) 110188d3d6e584829223ac5f6e6653c3caa38a2562a74glennrp mng_info->ping_preserve_colormap=MagickTrue; 110198d3d6e584829223ac5f6e6653c3caa38a2562a74glennrp 110201868258559ddf946fa73ef72dd43507b32623705glennrp /* Thes compression-level, compression-strategy, and compression-filter 110211868258559ddf946fa73ef72dd43507b32623705glennrp * defines take precedence over values from the -quality option. 110221868258559ddf946fa73ef72dd43507b32623705glennrp */ 110231868258559ddf946fa73ef72dd43507b32623705glennrp value=GetImageArtifact(image,"png:compression-level"); 110241868258559ddf946fa73ef72dd43507b32623705glennrp if (value == NULL) 110251868258559ddf946fa73ef72dd43507b32623705glennrp value=GetImageOption(image_info,"png:compression-level"); 110261868258559ddf946fa73ef72dd43507b32623705glennrp if (value != NULL) 110271868258559ddf946fa73ef72dd43507b32623705glennrp { 110281868258559ddf946fa73ef72dd43507b32623705glennrp /* We have to add 1 to everything because 0 is a valid input, 110291868258559ddf946fa73ef72dd43507b32623705glennrp * and we want to use 0 (the default) to mean undefined. 110301868258559ddf946fa73ef72dd43507b32623705glennrp */ 110311868258559ddf946fa73ef72dd43507b32623705glennrp if (LocaleCompare(value,"0") == 0) 110321868258559ddf946fa73ef72dd43507b32623705glennrp mng_info->write_png_compression_level = 1; 110331868258559ddf946fa73ef72dd43507b32623705glennrp 110341868258559ddf946fa73ef72dd43507b32623705glennrp if (LocaleCompare(value,"1") == 0) 110351868258559ddf946fa73ef72dd43507b32623705glennrp mng_info->write_png_compression_level = 2; 110361868258559ddf946fa73ef72dd43507b32623705glennrp 110371868258559ddf946fa73ef72dd43507b32623705glennrp else if (LocaleCompare(value,"2") == 0) 110381868258559ddf946fa73ef72dd43507b32623705glennrp mng_info->write_png_compression_level = 3; 110391868258559ddf946fa73ef72dd43507b32623705glennrp 110401868258559ddf946fa73ef72dd43507b32623705glennrp else if (LocaleCompare(value,"3") == 0) 110411868258559ddf946fa73ef72dd43507b32623705glennrp mng_info->write_png_compression_level = 4; 110421868258559ddf946fa73ef72dd43507b32623705glennrp 110431868258559ddf946fa73ef72dd43507b32623705glennrp else if (LocaleCompare(value,"4") == 0) 110441868258559ddf946fa73ef72dd43507b32623705glennrp mng_info->write_png_compression_level = 5; 110451868258559ddf946fa73ef72dd43507b32623705glennrp 110461868258559ddf946fa73ef72dd43507b32623705glennrp else if (LocaleCompare(value,"5") == 0) 110471868258559ddf946fa73ef72dd43507b32623705glennrp mng_info->write_png_compression_level = 6; 110481868258559ddf946fa73ef72dd43507b32623705glennrp 110491868258559ddf946fa73ef72dd43507b32623705glennrp else if (LocaleCompare(value,"6") == 0) 110501868258559ddf946fa73ef72dd43507b32623705glennrp mng_info->write_png_compression_level = 7; 110511868258559ddf946fa73ef72dd43507b32623705glennrp 110521868258559ddf946fa73ef72dd43507b32623705glennrp else if (LocaleCompare(value,"7") == 0) 110531868258559ddf946fa73ef72dd43507b32623705glennrp mng_info->write_png_compression_level = 8; 110541868258559ddf946fa73ef72dd43507b32623705glennrp 110551868258559ddf946fa73ef72dd43507b32623705glennrp else if (LocaleCompare(value,"8") == 0) 110561868258559ddf946fa73ef72dd43507b32623705glennrp mng_info->write_png_compression_level = 9; 110571868258559ddf946fa73ef72dd43507b32623705glennrp 110581868258559ddf946fa73ef72dd43507b32623705glennrp else if (LocaleCompare(value,"9") == 0) 110591868258559ddf946fa73ef72dd43507b32623705glennrp mng_info->write_png_compression_level = 10; 110601868258559ddf946fa73ef72dd43507b32623705glennrp 110611868258559ddf946fa73ef72dd43507b32623705glennrp else 110621868258559ddf946fa73ef72dd43507b32623705glennrp (void) ThrowMagickException(&image->exception, 110631868258559ddf946fa73ef72dd43507b32623705glennrp GetMagickModule(),CoderWarning, 110641868258559ddf946fa73ef72dd43507b32623705glennrp "ignoring invalid defined png:compression-level", 110651868258559ddf946fa73ef72dd43507b32623705glennrp "=%s",value); 110661868258559ddf946fa73ef72dd43507b32623705glennrp } 110671868258559ddf946fa73ef72dd43507b32623705glennrp 110681868258559ddf946fa73ef72dd43507b32623705glennrp value=GetImageArtifact(image,"png:compression-strategy"); 110691868258559ddf946fa73ef72dd43507b32623705glennrp if (value == NULL) 110701868258559ddf946fa73ef72dd43507b32623705glennrp value=GetImageOption(image_info,"png:compression-strategy"); 110711868258559ddf946fa73ef72dd43507b32623705glennrp if (value != NULL) 110721868258559ddf946fa73ef72dd43507b32623705glennrp { 110731868258559ddf946fa73ef72dd43507b32623705glennrp 110741868258559ddf946fa73ef72dd43507b32623705glennrp if (LocaleCompare(value,"0") == 0) 110751868258559ddf946fa73ef72dd43507b32623705glennrp mng_info->write_png_compression_strategy = Z_DEFAULT_STRATEGY+1; 110761868258559ddf946fa73ef72dd43507b32623705glennrp 110771868258559ddf946fa73ef72dd43507b32623705glennrp else if (LocaleCompare(value,"1") == 0) 110781868258559ddf946fa73ef72dd43507b32623705glennrp mng_info->write_png_compression_strategy = Z_FILTERED+1; 110791868258559ddf946fa73ef72dd43507b32623705glennrp 110801868258559ddf946fa73ef72dd43507b32623705glennrp else if (LocaleCompare(value,"2") == 0) 110811868258559ddf946fa73ef72dd43507b32623705glennrp mng_info->write_png_compression_strategy = Z_HUFFMAN_ONLY+1; 110821868258559ddf946fa73ef72dd43507b32623705glennrp 110831868258559ddf946fa73ef72dd43507b32623705glennrp else if (LocaleCompare(value,"3") == 0) 1108498c07ad97d2b2c4571ec3b58241df30d43ba51d0glennrp#ifdef Z_RLE /* Z_RLE was added to zlib-1.2.0 */ 110851868258559ddf946fa73ef72dd43507b32623705glennrp mng_info->write_png_compression_strategy = Z_RLE+1; 1108698c07ad97d2b2c4571ec3b58241df30d43ba51d0glennrp#else 1108798c07ad97d2b2c4571ec3b58241df30d43ba51d0glennrp mng_info->write_png_compression_strategy = Z_DEFAULT_STRATEGY+1; 1108898c07ad97d2b2c4571ec3b58241df30d43ba51d0glennrp#endif 110891868258559ddf946fa73ef72dd43507b32623705glennrp 110901868258559ddf946fa73ef72dd43507b32623705glennrp else if (LocaleCompare(value,"4") == 0) 1109198c07ad97d2b2c4571ec3b58241df30d43ba51d0glennrp#ifdef Z_FIXED /* Z_FIXED was added to zlib-1.2.2.2 */ 110921868258559ddf946fa73ef72dd43507b32623705glennrp mng_info->write_png_compression_strategy = Z_FIXED+1; 1109398c07ad97d2b2c4571ec3b58241df30d43ba51d0glennrp#else 1109498c07ad97d2b2c4571ec3b58241df30d43ba51d0glennrp mng_info->write_png_compression_strategy = Z_DEFAULT_STRATEGY+1; 1109598c07ad97d2b2c4571ec3b58241df30d43ba51d0glennrp#endif 110961868258559ddf946fa73ef72dd43507b32623705glennrp 110971868258559ddf946fa73ef72dd43507b32623705glennrp else 110981868258559ddf946fa73ef72dd43507b32623705glennrp (void) ThrowMagickException(&image->exception, 110991868258559ddf946fa73ef72dd43507b32623705glennrp GetMagickModule(),CoderWarning, 111001868258559ddf946fa73ef72dd43507b32623705glennrp "ignoring invalid defined png:compression-strategy", 111011868258559ddf946fa73ef72dd43507b32623705glennrp "=%s",value); 111021868258559ddf946fa73ef72dd43507b32623705glennrp } 111031868258559ddf946fa73ef72dd43507b32623705glennrp 111041868258559ddf946fa73ef72dd43507b32623705glennrp value=GetImageArtifact(image,"png:compression-filter"); 111051868258559ddf946fa73ef72dd43507b32623705glennrp if (value == NULL) 111061868258559ddf946fa73ef72dd43507b32623705glennrp value=GetImageOption(image_info,"png:compression-filter"); 111071868258559ddf946fa73ef72dd43507b32623705glennrp if (value != NULL) 111081868258559ddf946fa73ef72dd43507b32623705glennrp { 111091868258559ddf946fa73ef72dd43507b32623705glennrp 111101868258559ddf946fa73ef72dd43507b32623705glennrp /* To do: combinations of filters allowed by libpng 111111868258559ddf946fa73ef72dd43507b32623705glennrp * masks 0x08 through 0xf8 111121868258559ddf946fa73ef72dd43507b32623705glennrp * 111131868258559ddf946fa73ef72dd43507b32623705glennrp * Implement this as a comma-separated list of 0,1,2,3,4,5 111141868258559ddf946fa73ef72dd43507b32623705glennrp * where 5 is a special case meaning PNG_ALL_FILTERS. 111151868258559ddf946fa73ef72dd43507b32623705glennrp */ 111161868258559ddf946fa73ef72dd43507b32623705glennrp 111171868258559ddf946fa73ef72dd43507b32623705glennrp if (LocaleCompare(value,"0") == 0) 111181868258559ddf946fa73ef72dd43507b32623705glennrp mng_info->write_png_compression_filter = 1; 111191868258559ddf946fa73ef72dd43507b32623705glennrp 111201868258559ddf946fa73ef72dd43507b32623705glennrp if (LocaleCompare(value,"1") == 0) 111211868258559ddf946fa73ef72dd43507b32623705glennrp mng_info->write_png_compression_filter = 2; 111221868258559ddf946fa73ef72dd43507b32623705glennrp 111231868258559ddf946fa73ef72dd43507b32623705glennrp else if (LocaleCompare(value,"2") == 0) 111241868258559ddf946fa73ef72dd43507b32623705glennrp mng_info->write_png_compression_filter = 3; 111251868258559ddf946fa73ef72dd43507b32623705glennrp 111261868258559ddf946fa73ef72dd43507b32623705glennrp else if (LocaleCompare(value,"3") == 0) 111271868258559ddf946fa73ef72dd43507b32623705glennrp mng_info->write_png_compression_filter = 4; 111281868258559ddf946fa73ef72dd43507b32623705glennrp 111291868258559ddf946fa73ef72dd43507b32623705glennrp else if (LocaleCompare(value,"4") == 0) 111301868258559ddf946fa73ef72dd43507b32623705glennrp mng_info->write_png_compression_filter = 5; 111311868258559ddf946fa73ef72dd43507b32623705glennrp 111321868258559ddf946fa73ef72dd43507b32623705glennrp else if (LocaleCompare(value,"5") == 0) 111331868258559ddf946fa73ef72dd43507b32623705glennrp mng_info->write_png_compression_filter = 6; 111341868258559ddf946fa73ef72dd43507b32623705glennrp 1113554dc0694601d2c51ec50c76e3fd90d9ff704df9bglennrp else if (LocaleCompare(value,"6") == 0) 1113654dc0694601d2c51ec50c76e3fd90d9ff704df9bglennrp mng_info->write_png_compression_filter = 7; 1113754dc0694601d2c51ec50c76e3fd90d9ff704df9bglennrp 1113854dc0694601d2c51ec50c76e3fd90d9ff704df9bglennrp else if (LocaleCompare(value,"7") == 0) 1113954dc0694601d2c51ec50c76e3fd90d9ff704df9bglennrp mng_info->write_png_compression_filter = 8; 1114054dc0694601d2c51ec50c76e3fd90d9ff704df9bglennrp 1114154dc0694601d2c51ec50c76e3fd90d9ff704df9bglennrp else if (LocaleCompare(value,"8") == 0) 1114254dc0694601d2c51ec50c76e3fd90d9ff704df9bglennrp mng_info->write_png_compression_filter = 9; 1114354dc0694601d2c51ec50c76e3fd90d9ff704df9bglennrp 1114454dc0694601d2c51ec50c76e3fd90d9ff704df9bglennrp else if (LocaleCompare(value,"9") == 0) 1114554dc0694601d2c51ec50c76e3fd90d9ff704df9bglennrp mng_info->write_png_compression_filter = 10; 111461868258559ddf946fa73ef72dd43507b32623705glennrp 111471868258559ddf946fa73ef72dd43507b32623705glennrp else 111481868258559ddf946fa73ef72dd43507b32623705glennrp (void) ThrowMagickException(&image->exception, 111491868258559ddf946fa73ef72dd43507b32623705glennrp GetMagickModule(),CoderWarning, 111501868258559ddf946fa73ef72dd43507b32623705glennrp "ignoring invalid defined png:compression-filter", 111511868258559ddf946fa73ef72dd43507b32623705glennrp "=%s",value); 111521868258559ddf946fa73ef72dd43507b32623705glennrp } 111531868258559ddf946fa73ef72dd43507b32623705glennrp 1115403812ae402fb53d548f0e1d7d14720768f803c2dglennrp excluding=MagickFalse; 1115503812ae402fb53d548f0e1d7d14720768f803c2dglennrp 111565c7cf4e469a4dad7e277783749155932252c52dfglennrp for (source=0; source<1; source++) 111575c7cf4e469a4dad7e277783749155932252c52dfglennrp { 111585c7cf4e469a4dad7e277783749155932252c52dfglennrp if (source==0) 11159acba004f7fac1660554dfefd2a078ead5ac8ee14glennrp { 111605c7cf4e469a4dad7e277783749155932252c52dfglennrp value=GetImageArtifact(image,"png:exclude-chunk"); 11161acba004f7fac1660554dfefd2a078ead5ac8ee14glennrp 11162acba004f7fac1660554dfefd2a078ead5ac8ee14glennrp if (value == NULL) 11163acba004f7fac1660554dfefd2a078ead5ac8ee14glennrp value=GetImageArtifact(image,"png:exclude-chunks"); 11164acba004f7fac1660554dfefd2a078ead5ac8ee14glennrp } 111655c7cf4e469a4dad7e277783749155932252c52dfglennrp else 11166acba004f7fac1660554dfefd2a078ead5ac8ee14glennrp { 111675c7cf4e469a4dad7e277783749155932252c52dfglennrp value=GetImageOption(image_info,"png:exclude-chunk"); 1116826f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp 11169acba004f7fac1660554dfefd2a078ead5ac8ee14glennrp if (value == NULL) 11170acba004f7fac1660554dfefd2a078ead5ac8ee14glennrp value=GetImageOption(image_info,"png:exclude-chunks"); 11171acba004f7fac1660554dfefd2a078ead5ac8ee14glennrp } 11172acba004f7fac1660554dfefd2a078ead5ac8ee14glennrp 1117303812ae402fb53d548f0e1d7d14720768f803c2dglennrp if (value != NULL) 1117403812ae402fb53d548f0e1d7d14720768f803c2dglennrp { 1117526f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp 1117603812ae402fb53d548f0e1d7d14720768f803c2dglennrp size_t 1117703812ae402fb53d548f0e1d7d14720768f803c2dglennrp last; 1117826f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp 1117903812ae402fb53d548f0e1d7d14720768f803c2dglennrp excluding=MagickTrue; 1118026f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp 1118103812ae402fb53d548f0e1d7d14720768f803c2dglennrp if (logging != MagickFalse) 111822cc891a179d622dde7bbb8854138851e828bc6eaglennrp { 111832cc891a179d622dde7bbb8854138851e828bc6eaglennrp if (source == 0) 111842cc891a179d622dde7bbb8854138851e828bc6eaglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 111852cc891a179d622dde7bbb8854138851e828bc6eaglennrp " png:exclude-chunk=%s found in image artifacts.\n", value); 111862cc891a179d622dde7bbb8854138851e828bc6eaglennrp else 111872cc891a179d622dde7bbb8854138851e828bc6eaglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 111882cc891a179d622dde7bbb8854138851e828bc6eaglennrp " png:exclude-chunk=%s found in image properties.\n", value); 111892cc891a179d622dde7bbb8854138851e828bc6eaglennrp } 1119003812ae402fb53d548f0e1d7d14720768f803c2dglennrp 1119103812ae402fb53d548f0e1d7d14720768f803c2dglennrp last=strlen(value); 1119203812ae402fb53d548f0e1d7d14720768f803c2dglennrp 1119303812ae402fb53d548f0e1d7d14720768f803c2dglennrp for (i=0; i<(int) last; i+=5) 1119403812ae402fb53d548f0e1d7d14720768f803c2dglennrp { 1119503812ae402fb53d548f0e1d7d14720768f803c2dglennrp 1119603812ae402fb53d548f0e1d7d14720768f803c2dglennrp if (LocaleNCompare(value+i,"all",3) == 0) 1119703812ae402fb53d548f0e1d7d14720768f803c2dglennrp { 1119803812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_bKGD=MagickTrue; 1119903812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_cHRM=MagickTrue; 11200a0ed009a1e9480ac6f3f4520e9ef29d6d37e27dcglennrp mng_info->ping_exclude_date=MagickTrue; 1120103812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_EXIF=MagickTrue; 1120203812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_gAMA=MagickTrue; 1120303812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_iCCP=MagickTrue; 1120403812ae402fb53d548f0e1d7d14720768f803c2dglennrp /* mng_info->ping_exclude_iTXt=MagickTrue; */ 1120503812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_oFFs=MagickTrue; 1120603812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_pHYs=MagickTrue; 1120703812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_sRGB=MagickTrue; 1120803812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_tEXt=MagickTrue; 11209a1e3b7b4887860a199d00bddbf4b12e0a93ee1e5glennrp mng_info->ping_exclude_tRNS=MagickTrue; 1121003812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_vpAg=MagickTrue; 1121103812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_zCCP=MagickTrue; 1121203812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_zTXt=MagickTrue; 1121303812ae402fb53d548f0e1d7d14720768f803c2dglennrp i--; 1121403812ae402fb53d548f0e1d7d14720768f803c2dglennrp } 112152cc891a179d622dde7bbb8854138851e828bc6eaglennrp 1121603812ae402fb53d548f0e1d7d14720768f803c2dglennrp if (LocaleNCompare(value+i,"none",4) == 0) 1121703812ae402fb53d548f0e1d7d14720768f803c2dglennrp { 1121803812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_bKGD=MagickFalse; 1121903812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_cHRM=MagickFalse; 11220a0ed009a1e9480ac6f3f4520e9ef29d6d37e27dcglennrp mng_info->ping_exclude_date=MagickFalse; 1122103812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_EXIF=MagickFalse; 1122203812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_gAMA=MagickFalse; 1122303812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_iCCP=MagickFalse; 1122403812ae402fb53d548f0e1d7d14720768f803c2dglennrp /* mng_info->ping_exclude_iTXt=MagickFalse; */ 1122503812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_oFFs=MagickFalse; 1122603812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_pHYs=MagickFalse; 1122703812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_sRGB=MagickFalse; 1122803812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_tEXt=MagickFalse; 11229a1e3b7b4887860a199d00bddbf4b12e0a93ee1e5glennrp mng_info->ping_exclude_tRNS=MagickFalse; 1123003812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_vpAg=MagickFalse; 1123103812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_zCCP=MagickFalse; 1123203812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_zTXt=MagickFalse; 1123303812ae402fb53d548f0e1d7d14720768f803c2dglennrp } 112342cc891a179d622dde7bbb8854138851e828bc6eaglennrp 1123503812ae402fb53d548f0e1d7d14720768f803c2dglennrp if (LocaleNCompare(value+i,"bkgd",4) == 0) 1123603812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_bKGD=MagickTrue; 112372cc891a179d622dde7bbb8854138851e828bc6eaglennrp 1123803812ae402fb53d548f0e1d7d14720768f803c2dglennrp if (LocaleNCompare(value+i,"chrm",4) == 0) 1123903812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_cHRM=MagickTrue; 112402cc891a179d622dde7bbb8854138851e828bc6eaglennrp 11241a0ed009a1e9480ac6f3f4520e9ef29d6d37e27dcglennrp if (LocaleNCompare(value+i,"date",4) == 0) 11242a0ed009a1e9480ac6f3f4520e9ef29d6d37e27dcglennrp mng_info->ping_exclude_date=MagickTrue; 11243a0ed009a1e9480ac6f3f4520e9ef29d6d37e27dcglennrp 1124403812ae402fb53d548f0e1d7d14720768f803c2dglennrp if (LocaleNCompare(value+i,"exif",4) == 0) 1124503812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_EXIF=MagickTrue; 112462cc891a179d622dde7bbb8854138851e828bc6eaglennrp 1124703812ae402fb53d548f0e1d7d14720768f803c2dglennrp if (LocaleNCompare(value+i,"gama",4) == 0) 1124803812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_gAMA=MagickTrue; 112492cc891a179d622dde7bbb8854138851e828bc6eaglennrp 1125003812ae402fb53d548f0e1d7d14720768f803c2dglennrp if (LocaleNCompare(value+i,"iccp",4) == 0) 1125103812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_iCCP=MagickTrue; 112522cc891a179d622dde7bbb8854138851e828bc6eaglennrp 1125303812ae402fb53d548f0e1d7d14720768f803c2dglennrp /* 1125403812ae402fb53d548f0e1d7d14720768f803c2dglennrp if (LocaleNCompare(value+i,"itxt",4) == 0) 1125503812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_iTXt=MagickTrue; 1125603812ae402fb53d548f0e1d7d14720768f803c2dglennrp */ 112572cc891a179d622dde7bbb8854138851e828bc6eaglennrp 1125803812ae402fb53d548f0e1d7d14720768f803c2dglennrp if (LocaleNCompare(value+i,"gama",4) == 0) 1125903812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_gAMA=MagickTrue; 112602cc891a179d622dde7bbb8854138851e828bc6eaglennrp 1126103812ae402fb53d548f0e1d7d14720768f803c2dglennrp if (LocaleNCompare(value+i,"offs",4) == 0) 1126203812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_oFFs=MagickTrue; 112632cc891a179d622dde7bbb8854138851e828bc6eaglennrp 1126403812ae402fb53d548f0e1d7d14720768f803c2dglennrp if (LocaleNCompare(value+i,"phys",4) == 0) 1126503812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_pHYs=MagickTrue; 112662cc891a179d622dde7bbb8854138851e828bc6eaglennrp 11267a1e3b7b4887860a199d00bddbf4b12e0a93ee1e5glennrp if (LocaleNCompare(value+i,"srgb",4) == 0) 11268a1e3b7b4887860a199d00bddbf4b12e0a93ee1e5glennrp mng_info->ping_exclude_sRGB=MagickTrue; 112692cc891a179d622dde7bbb8854138851e828bc6eaglennrp 1127003812ae402fb53d548f0e1d7d14720768f803c2dglennrp if (LocaleNCompare(value+i,"text",4) == 0) 1127103812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_tEXt=MagickTrue; 112722cc891a179d622dde7bbb8854138851e828bc6eaglennrp 11273a1e3b7b4887860a199d00bddbf4b12e0a93ee1e5glennrp if (LocaleNCompare(value+i,"trns",4) == 0) 11274a1e3b7b4887860a199d00bddbf4b12e0a93ee1e5glennrp mng_info->ping_exclude_tRNS=MagickTrue; 11275a1e3b7b4887860a199d00bddbf4b12e0a93ee1e5glennrp 1127603812ae402fb53d548f0e1d7d14720768f803c2dglennrp if (LocaleNCompare(value+i,"vpag",4) == 0) 1127703812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_vpAg=MagickTrue; 112782cc891a179d622dde7bbb8854138851e828bc6eaglennrp 1127903812ae402fb53d548f0e1d7d14720768f803c2dglennrp if (LocaleNCompare(value+i,"zccp",4) == 0) 1128003812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_zCCP=MagickTrue; 112812cc891a179d622dde7bbb8854138851e828bc6eaglennrp 1128203812ae402fb53d548f0e1d7d14720768f803c2dglennrp if (LocaleNCompare(value+i,"ztxt",4) == 0) 1128303812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_zTXt=MagickTrue; 112842cc891a179d622dde7bbb8854138851e828bc6eaglennrp 1128503812ae402fb53d548f0e1d7d14720768f803c2dglennrp } 11286ce91ed5de546373b90d60e2efd118e76692dc416glennrp } 1128726f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp } 1128826f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp 112895c7cf4e469a4dad7e277783749155932252c52dfglennrp for (source=0; source<1; source++) 112905c7cf4e469a4dad7e277783749155932252c52dfglennrp { 112915c7cf4e469a4dad7e277783749155932252c52dfglennrp if (source==0) 11292acba004f7fac1660554dfefd2a078ead5ac8ee14glennrp { 112935c7cf4e469a4dad7e277783749155932252c52dfglennrp value=GetImageArtifact(image,"png:include-chunk"); 11294acba004f7fac1660554dfefd2a078ead5ac8ee14glennrp 11295acba004f7fac1660554dfefd2a078ead5ac8ee14glennrp if (value == NULL) 11296acba004f7fac1660554dfefd2a078ead5ac8ee14glennrp value=GetImageArtifact(image,"png:include-chunks"); 11297acba004f7fac1660554dfefd2a078ead5ac8ee14glennrp } 112985c7cf4e469a4dad7e277783749155932252c52dfglennrp else 11299acba004f7fac1660554dfefd2a078ead5ac8ee14glennrp { 113005c7cf4e469a4dad7e277783749155932252c52dfglennrp value=GetImageOption(image_info,"png:include-chunk"); 1130126f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp 11302acba004f7fac1660554dfefd2a078ead5ac8ee14glennrp if (value == NULL) 11303acba004f7fac1660554dfefd2a078ead5ac8ee14glennrp value=GetImageOption(image_info,"png:include-chunks"); 11304acba004f7fac1660554dfefd2a078ead5ac8ee14glennrp } 11305acba004f7fac1660554dfefd2a078ead5ac8ee14glennrp 1130603812ae402fb53d548f0e1d7d14720768f803c2dglennrp if (value != NULL) 1130703812ae402fb53d548f0e1d7d14720768f803c2dglennrp { 1130803812ae402fb53d548f0e1d7d14720768f803c2dglennrp size_t 1130903812ae402fb53d548f0e1d7d14720768f803c2dglennrp last; 1131026f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp 1131103812ae402fb53d548f0e1d7d14720768f803c2dglennrp excluding=MagickTrue; 1131226f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp 1131303812ae402fb53d548f0e1d7d14720768f803c2dglennrp if (logging != MagickFalse) 113142cc891a179d622dde7bbb8854138851e828bc6eaglennrp { 113152cc891a179d622dde7bbb8854138851e828bc6eaglennrp if (source == 0) 113162cc891a179d622dde7bbb8854138851e828bc6eaglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 113172cc891a179d622dde7bbb8854138851e828bc6eaglennrp " png:include-chunk=%s found in image artifacts.\n", value); 113182cc891a179d622dde7bbb8854138851e828bc6eaglennrp else 113192cc891a179d622dde7bbb8854138851e828bc6eaglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 113202cc891a179d622dde7bbb8854138851e828bc6eaglennrp " png:include-chunk=%s found in image properties.\n", value); 113212cc891a179d622dde7bbb8854138851e828bc6eaglennrp } 1132203812ae402fb53d548f0e1d7d14720768f803c2dglennrp 1132303812ae402fb53d548f0e1d7d14720768f803c2dglennrp last=strlen(value); 1132403812ae402fb53d548f0e1d7d14720768f803c2dglennrp 1132503812ae402fb53d548f0e1d7d14720768f803c2dglennrp for (i=0; i<(int) last; i+=5) 1132603812ae402fb53d548f0e1d7d14720768f803c2dglennrp { 1132703812ae402fb53d548f0e1d7d14720768f803c2dglennrp if (LocaleNCompare(value+i,"all",3) == 0) 1132803812ae402fb53d548f0e1d7d14720768f803c2dglennrp { 1132903812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_bKGD=MagickFalse; 1133003812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_cHRM=MagickFalse; 11331a0ed009a1e9480ac6f3f4520e9ef29d6d37e27dcglennrp mng_info->ping_exclude_date=MagickFalse; 1133203812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_EXIF=MagickFalse; 1133303812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_gAMA=MagickFalse; 1133403812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_iCCP=MagickFalse; 1133503812ae402fb53d548f0e1d7d14720768f803c2dglennrp /* mng_info->ping_exclude_iTXt=MagickFalse; */ 1133603812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_oFFs=MagickFalse; 1133703812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_pHYs=MagickFalse; 1133803812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_sRGB=MagickFalse; 1133903812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_tEXt=MagickFalse; 11340a1e3b7b4887860a199d00bddbf4b12e0a93ee1e5glennrp mng_info->ping_exclude_tRNS=MagickFalse; 1134103812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_vpAg=MagickFalse; 1134203812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_zCCP=MagickFalse; 1134303812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_zTXt=MagickFalse; 1134403812ae402fb53d548f0e1d7d14720768f803c2dglennrp i--; 1134503812ae402fb53d548f0e1d7d14720768f803c2dglennrp } 113462cc891a179d622dde7bbb8854138851e828bc6eaglennrp 1134703812ae402fb53d548f0e1d7d14720768f803c2dglennrp if (LocaleNCompare(value+i,"none",4) == 0) 1134803812ae402fb53d548f0e1d7d14720768f803c2dglennrp { 1134903812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_bKGD=MagickTrue; 1135003812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_cHRM=MagickTrue; 11351a0ed009a1e9480ac6f3f4520e9ef29d6d37e27dcglennrp mng_info->ping_exclude_date=MagickTrue; 1135203812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_EXIF=MagickTrue; 1135303812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_gAMA=MagickTrue; 1135403812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_iCCP=MagickTrue; 1135503812ae402fb53d548f0e1d7d14720768f803c2dglennrp /* mng_info->ping_exclude_iTXt=MagickTrue; */ 1135603812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_oFFs=MagickTrue; 1135703812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_pHYs=MagickTrue; 1135803812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_sRGB=MagickTrue; 1135903812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_tEXt=MagickTrue; 11360a1e3b7b4887860a199d00bddbf4b12e0a93ee1e5glennrp mng_info->ping_exclude_tRNS=MagickTrue; 1136103812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_vpAg=MagickTrue; 1136203812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_zCCP=MagickTrue; 1136303812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_zTXt=MagickTrue; 1136403812ae402fb53d548f0e1d7d14720768f803c2dglennrp } 113652cc891a179d622dde7bbb8854138851e828bc6eaglennrp 1136603812ae402fb53d548f0e1d7d14720768f803c2dglennrp if (LocaleNCompare(value+i,"bkgd",4) == 0) 1136703812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_bKGD=MagickFalse; 113682cc891a179d622dde7bbb8854138851e828bc6eaglennrp 1136903812ae402fb53d548f0e1d7d14720768f803c2dglennrp if (LocaleNCompare(value+i,"chrm",4) == 0) 1137003812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_cHRM=MagickFalse; 113712cc891a179d622dde7bbb8854138851e828bc6eaglennrp 11372a0ed009a1e9480ac6f3f4520e9ef29d6d37e27dcglennrp if (LocaleNCompare(value+i,"date",4) == 0) 11373a0ed009a1e9480ac6f3f4520e9ef29d6d37e27dcglennrp mng_info->ping_exclude_date=MagickFalse; 11374a0ed009a1e9480ac6f3f4520e9ef29d6d37e27dcglennrp 1137503812ae402fb53d548f0e1d7d14720768f803c2dglennrp if (LocaleNCompare(value+i,"exif",4) == 0) 1137603812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_EXIF=MagickFalse; 113772cc891a179d622dde7bbb8854138851e828bc6eaglennrp 1137803812ae402fb53d548f0e1d7d14720768f803c2dglennrp if (LocaleNCompare(value+i,"gama",4) == 0) 1137903812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_gAMA=MagickFalse; 113802cc891a179d622dde7bbb8854138851e828bc6eaglennrp 1138103812ae402fb53d548f0e1d7d14720768f803c2dglennrp if (LocaleNCompare(value+i,"iccp",4) == 0) 1138203812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_iCCP=MagickFalse; 113832cc891a179d622dde7bbb8854138851e828bc6eaglennrp 1138403812ae402fb53d548f0e1d7d14720768f803c2dglennrp /* 1138503812ae402fb53d548f0e1d7d14720768f803c2dglennrp if (LocaleNCompare(value+i,"itxt",4) == 0) 1138603812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_iTXt=MagickFalse; 1138703812ae402fb53d548f0e1d7d14720768f803c2dglennrp */ 113882cc891a179d622dde7bbb8854138851e828bc6eaglennrp 1138903812ae402fb53d548f0e1d7d14720768f803c2dglennrp if (LocaleNCompare(value+i,"gama",4) == 0) 1139003812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_gAMA=MagickFalse; 113912cc891a179d622dde7bbb8854138851e828bc6eaglennrp 1139203812ae402fb53d548f0e1d7d14720768f803c2dglennrp if (LocaleNCompare(value+i,"offs",4) == 0) 1139303812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_oFFs=MagickFalse; 113942cc891a179d622dde7bbb8854138851e828bc6eaglennrp 1139503812ae402fb53d548f0e1d7d14720768f803c2dglennrp if (LocaleNCompare(value+i,"phys",4) == 0) 1139603812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_pHYs=MagickFalse; 113972cc891a179d622dde7bbb8854138851e828bc6eaglennrp 11398a1e3b7b4887860a199d00bddbf4b12e0a93ee1e5glennrp if (LocaleNCompare(value+i,"srgb",4) == 0) 11399a1e3b7b4887860a199d00bddbf4b12e0a93ee1e5glennrp mng_info->ping_exclude_sRGB=MagickFalse; 114002cc891a179d622dde7bbb8854138851e828bc6eaglennrp 1140103812ae402fb53d548f0e1d7d14720768f803c2dglennrp if (LocaleNCompare(value+i,"text",4) == 0) 1140203812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_tEXt=MagickFalse; 114032cc891a179d622dde7bbb8854138851e828bc6eaglennrp 11404a1e3b7b4887860a199d00bddbf4b12e0a93ee1e5glennrp if (LocaleNCompare(value+i,"trns",4) == 0) 11405a1e3b7b4887860a199d00bddbf4b12e0a93ee1e5glennrp mng_info->ping_exclude_tRNS=MagickFalse; 11406a1e3b7b4887860a199d00bddbf4b12e0a93ee1e5glennrp 1140703812ae402fb53d548f0e1d7d14720768f803c2dglennrp if (LocaleNCompare(value+i,"vpag",4) == 0) 1140803812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_vpAg=MagickFalse; 114092cc891a179d622dde7bbb8854138851e828bc6eaglennrp 1141003812ae402fb53d548f0e1d7d14720768f803c2dglennrp if (LocaleNCompare(value+i,"zccp",4) == 0) 1141103812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_zCCP=MagickFalse; 114122cc891a179d622dde7bbb8854138851e828bc6eaglennrp 1141303812ae402fb53d548f0e1d7d14720768f803c2dglennrp if (LocaleNCompare(value+i,"ztxt",4) == 0) 1141403812ae402fb53d548f0e1d7d14720768f803c2dglennrp mng_info->ping_exclude_zTXt=MagickFalse; 114152cc891a179d622dde7bbb8854138851e828bc6eaglennrp 1141603812ae402fb53d548f0e1d7d14720768f803c2dglennrp } 11417ce91ed5de546373b90d60e2efd118e76692dc416glennrp } 1141826f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp } 1141926f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp 1142003812ae402fb53d548f0e1d7d14720768f803c2dglennrp if (excluding != MagickFalse && logging != MagickFalse) 1142126f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp { 1142226f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 1142326f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp " Chunks to be excluded from the output PNG:"); 1142426f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp if (mng_info->ping_exclude_bKGD != MagickFalse) 1142526f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 1142626f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp " bKGD"); 1142726f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp if (mng_info->ping_exclude_cHRM != MagickFalse) 1142826f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 1142926f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp " cHRM"); 11430a0ed009a1e9480ac6f3f4520e9ef29d6d37e27dcglennrp if (mng_info->ping_exclude_date != MagickFalse) 11431a0ed009a1e9480ac6f3f4520e9ef29d6d37e27dcglennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 11432a0ed009a1e9480ac6f3f4520e9ef29d6d37e27dcglennrp " date"); 1143326f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp if (mng_info->ping_exclude_EXIF != MagickFalse) 1143426f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 1143526f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp " EXIF"); 1143626f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp if (mng_info->ping_exclude_gAMA != MagickFalse) 1143726f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 1143826f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp " gAMA"); 1143926f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp if (mng_info->ping_exclude_iCCP != MagickFalse) 1144026f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 1144126f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp " iCCP"); 1144226f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp/* 1144326f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp if (mng_info->ping_exclude_iTXt != MagickFalse) 1144426f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 1144526f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp " iTXt"); 1144626f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp*/ 1144726f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp if (mng_info->ping_exclude_oFFs != MagickFalse) 1144826f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 1144926f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp " oFFs"); 1145026f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp if (mng_info->ping_exclude_pHYs != MagickFalse) 1145126f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 1145226f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp " pHYs"); 1145326f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp if (mng_info->ping_exclude_sRGB != MagickFalse) 1145426f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 1145526f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp " sRGB"); 1145626f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp if (mng_info->ping_exclude_tEXt != MagickFalse) 1145726f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 1145826f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp " tEXt"); 11459a1e3b7b4887860a199d00bddbf4b12e0a93ee1e5glennrp if (mng_info->ping_exclude_tRNS != MagickFalse) 11460a1e3b7b4887860a199d00bddbf4b12e0a93ee1e5glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 11461a1e3b7b4887860a199d00bddbf4b12e0a93ee1e5glennrp " tRNS"); 1146226f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp if (mng_info->ping_exclude_vpAg != MagickFalse) 1146326f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 1146426f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp " vpAg"); 1146526f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp if (mng_info->ping_exclude_zCCP != MagickFalse) 1146626f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 1146726f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp " zCCP"); 1146826f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp if (mng_info->ping_exclude_zTXt != MagickFalse) 1146926f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp (void) LogMagickEvent(CoderEvent,GetMagickModule(), 1147026f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp " zTXt"); 1147126f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp } 1147226f379198a1c94db76f302873c7f1f2e8d5ec6a0glennrp 11473b9cfe27bef51dbbd1f05aef89c767749d7e37864glennrp mng_info->need_blob = MagickTrue; 114743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 11475b9cfe27bef51dbbd1f05aef89c767749d7e37864glennrp status=WriteOnePNGImage(mng_info,image_info,image); 114763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 114773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngInfoFreeStruct(mng_info,&have_mng_structure); 114780fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 114793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 114803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(),"exit WritePNGImage()"); 114810fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 114823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(status); 114833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 114843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 114853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(JNG_SUPPORTED) 114863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 114873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* Write one JNG image */ 114883ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic MagickBooleanType WriteOneJNGImage(MngInfo *mng_info, 114893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy const ImageInfo *image_info,Image *image) 114903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 114913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Image 114923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *jpeg_image; 114933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 114943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ImageInfo 114953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *jpeg_image_info; 114963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 114973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MagickBooleanType 1149803812ae402fb53d548f0e1d7d14720768f803c2dglennrp logging, 114993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status; 115003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 115013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy size_t 115023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy length; 115033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 115043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy unsigned char 115053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *blob, 115063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[80], 115073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *p; 115083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 115093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy unsigned int 115103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_alpha_compression_method, 115113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_alpha_sample_depth, 115123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_color_type, 115133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy transparent; 115143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 11515bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy size_t 115163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_quality; 115173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 115183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy logging=LogMagickEvent(CoderEvent,GetMagickModule(), 11519fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp " Enter WriteOneJNGImage()"); 115203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 115213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy blob=(unsigned char *) NULL; 115223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jpeg_image=(Image *) NULL; 115233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jpeg_image_info=(ImageInfo *) NULL; 115243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 115253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status=MagickTrue; 115263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy transparent=image_info->type==GrayscaleMatteType || 115273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image_info->type==TrueColorMatteType; 115283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_color_type=10; 115293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_alpha_sample_depth=0; 115303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_quality=image_info->quality == 0UL ? 75UL : image_info->quality; 115313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_alpha_compression_method=0; 115323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 115333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->matte != MagickFalse) 115343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 115353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* if any pixels are transparent */ 115363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy transparent=MagickTrue; 115373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image_info->compression==JPEGCompression) 115383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_alpha_compression_method=8; 115393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 115403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 115413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (transparent) 115423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 115433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_color_type=14; 115440fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 115453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Create JPEG blob, image, and image_info */ 115463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 115473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 115484c08aed51c5899665ade97263692328eea4af106cristy " Creating jpeg_image_info for alpha."); 115490fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 115503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jpeg_image_info=(ImageInfo *) CloneImageInfo(image_info); 115510fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 115523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (jpeg_image_info == (ImageInfo *) NULL) 115533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); 115540fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 115553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 115563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 115573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Creating jpeg_image."); 115580fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 115593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jpeg_image=CloneImage(image,0,0,MagickTrue,&image->exception); 115600fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 115613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (jpeg_image == (Image *) NULL) 115623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); 115630fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 115643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) CopyMagickString(jpeg_image->magick,"JPEG",MaxTextExtent); 115654c08aed51c5899665ade97263692328eea4af106cristy status=SeparateImageChannel(jpeg_image,AlphaChannel); 115663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jpeg_image->matte=MagickFalse; 115670fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 115683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (jng_quality >= 1000) 115693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jpeg_image_info->quality=jng_quality/1000; 115700fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 115713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 115723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jpeg_image_info->quality=jng_quality; 115730fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 115743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jpeg_image_info->type=GrayscaleType; 115753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) SetImageType(jpeg_image,GrayscaleType); 115763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) AcquireUniqueFilename(jpeg_image->filename); 115773b6fd2ec2d9f69f9404445dba0aff5bac02e685ccristy (void) FormatLocaleString(jpeg_image_info->filename,MaxTextExtent, 115783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy "%s",jpeg_image->filename); 115793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 115803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 115813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* To do: check bit depth of PNG alpha channel */ 115823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 115833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Check if image is grayscale. */ 115843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image_info->type != TrueColorMatteType && image_info->type != 115853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy TrueColorType && ImageIsGray(image)) 115863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_color_type-=2; 115873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 115883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (transparent) 115893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 115903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (jng_alpha_compression_method==0) 115913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 115923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy const char 115933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *value; 115943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 115954c08aed51c5899665ade97263692328eea4af106cristy /* Encode alpha as a grayscale PNG blob */ 115963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status=OpenBlob(jpeg_image_info,jpeg_image,WriteBinaryBlobMode, 115973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy &image->exception); 115983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 115993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 116003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Creating PNG blob."); 116013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy length=0; 116023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 116033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) CopyMagickString(jpeg_image_info->magick,"PNG",MaxTextExtent); 116043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) CopyMagickString(jpeg_image->magick,"PNG",MaxTextExtent); 116053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jpeg_image_info->interlace=NoInterlace; 116063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 116073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy blob=ImageToBlob(jpeg_image_info,jpeg_image,&length, 116083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy &image->exception); 116093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 116103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Retrieve sample depth used */ 116113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy value=GetImageProperty(jpeg_image,"png:bit-depth-written"); 116123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (value != (char *) NULL) 116133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_alpha_sample_depth= (unsigned int) value[0]; 116143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 116153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 116163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 116174c08aed51c5899665ade97263692328eea4af106cristy /* Encode alpha as a grayscale JPEG blob */ 116183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 116193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status=OpenBlob(jpeg_image_info,jpeg_image,WriteBinaryBlobMode, 116203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy &image->exception); 116213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 116223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) CopyMagickString(jpeg_image_info->magick,"JPEG",MaxTextExtent); 116233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) CopyMagickString(jpeg_image->magick,"JPEG",MaxTextExtent); 116243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jpeg_image_info->interlace=NoInterlace; 116253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 116263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 116273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Creating blob."); 116283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy blob=ImageToBlob(jpeg_image_info,jpeg_image,&length, 11629f2faecf9facdbbb14fcba373365f9f691a9658e0cristy &image->exception); 116303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jng_alpha_sample_depth=8; 116310fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 116323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 116333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 11634e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " Successfully read jpeg_image into a blob, length=%.20g.", 11635e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy (double) length); 116363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 116373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 116383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Destroy JPEG image and image_info */ 116393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jpeg_image=DestroyImage(jpeg_image); 116403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) RelinquishUniqueFileResource(jpeg_image_info->filename); 116413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jpeg_image_info=DestroyImageInfo(jpeg_image_info); 116423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 116433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 116443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Write JHDR chunk */ 116453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,16L); /* chunk data length=16 */ 116463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGType(chunk,mng_JHDR); 1164703812ae402fb53d548f0e1d7d14720768f803c2dglennrp LogPNGChunk(logging,mng_JHDR,16L); 116484e5bc84ff8bf274c4d9206d5e6ffd1a5e5d75335cristy PNGLong(chunk+4,(png_uint_32) image->columns); 116494e5bc84ff8bf274c4d9206d5e6ffd1a5e5d75335cristy PNGLong(chunk+8,(png_uint_32) image->rows); 116503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[12]=jng_color_type; 116513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[13]=8; /* sample depth */ 116523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[14]=8; /*jng_image_compression_method */ 116533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[15]=(unsigned char) (image_info->interlace == NoInterlace ? 0 : 8); 116543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[16]=jng_alpha_sample_depth; 116553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[17]=jng_alpha_compression_method; 116563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[18]=0; /*jng_alpha_filter_method */ 116573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[19]=0; /*jng_alpha_interlace_method */ 116583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(image,20,chunk); 116593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,crc32(0,chunk,20)); 116603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 116613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 116623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 11663f2faecf9facdbbb14fcba373365f9f691a9658e0cristy " JNG width:%15lu",(unsigned long) image->columns); 116640fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 116653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 11666f2faecf9facdbbb14fcba373365f9f691a9658e0cristy " JNG height:%14lu",(unsigned long) image->rows); 116670fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 116683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 116693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " JNG color type:%10d",jng_color_type); 116700fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 116713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 116723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " JNG sample depth:%8d",8); 116730fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 116743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 116753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " JNG compression:%9d",8); 116760fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 116773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 116783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " JNG interlace:%11d",0); 116790fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 116803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 116813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " JNG alpha depth:%9d",jng_alpha_sample_depth); 116820fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 116833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 116843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " JNG alpha compression:%3d",jng_alpha_compression_method); 116850fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 116863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 116873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " JNG alpha filter:%8d",0); 116880fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 116893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 116903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " JNG alpha interlace:%5d",0); 116913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 116923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 116930fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp /* Write any JNG-chunk-b profiles */ 11694cf002022280cc4dedb2748ad6f415aac1d44f530glennrp (void) Magick_png_write_chunk_from_profile(image,"JNG-chunk-b",logging); 116953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 116963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 116973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Write leading ancillary chunks 116983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 116993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 117003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (transparent) 117013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 117023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 117033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Write JNG bKGD chunk 117043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 117053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 117063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy unsigned char 117073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy blue, 117083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy green, 117093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy red; 117103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 11711bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy ssize_t 117123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy num_bytes; 117133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 117143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (jng_color_type == 8 || jng_color_type == 12) 117153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy num_bytes=6L; 117163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 117173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy num_bytes=10L; 11718bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy (void) WriteBlobMSBULong(image,(size_t) (num_bytes-4L)); 117193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGType(chunk,mng_bKGD); 1172003812ae402fb53d548f0e1d7d14720768f803c2dglennrp LogPNGChunk(logging,mng_bKGD,(size_t) (num_bytes-4L)); 117213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy red=ScaleQuantumToChar(image->background_color.red); 117223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy green=ScaleQuantumToChar(image->background_color.green); 117233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy blue=ScaleQuantumToChar(image->background_color.blue); 117243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *(chunk+4)=0; 117253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *(chunk+5)=red; 117263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *(chunk+6)=0; 117273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *(chunk+7)=green; 117283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *(chunk+8)=0; 117293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *(chunk+9)=blue; 117303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(image,(size_t) num_bytes,chunk); 117313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,crc32(0,chunk,(uInt) num_bytes)); 117323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 117333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 117343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((image->colorspace == sRGBColorspace || image->rendering_intent)) 117353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 117363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 117373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Write JNG sRGB chunk 117383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 117393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,1L); 117403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGType(chunk,mng_sRGB); 1174103812ae402fb53d548f0e1d7d14720768f803c2dglennrp LogPNGChunk(logging,mng_sRGB,1L); 117420fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 117433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->rendering_intent != UndefinedIntent) 11744e610a071534e448c46460a5aa39ede33bf56b329glennrp chunk[4]=(unsigned char) 11745cf002022280cc4dedb2748ad6f415aac1d44f530glennrp Magick_RenderingIntent_to_PNG_RenderingIntent( 11746e610a071534e448c46460a5aa39ede33bf56b329glennrp (image->rendering_intent)); 117470fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 117483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 11749e610a071534e448c46460a5aa39ede33bf56b329glennrp chunk[4]=(unsigned char) 11750cf002022280cc4dedb2748ad6f415aac1d44f530glennrp Magick_RenderingIntent_to_PNG_RenderingIntent( 11751e610a071534e448c46460a5aa39ede33bf56b329glennrp (PerceptualIntent)); 117520fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 117533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(image,5,chunk); 117543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,crc32(0,chunk,5)); 117553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 117563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 117573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 117583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->gamma != 0.0) 117593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 117603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 117613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Write JNG gAMA chunk 117623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 117633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,4L); 117643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGType(chunk,mng_gAMA); 1176503812ae402fb53d548f0e1d7d14720768f803c2dglennrp LogPNGChunk(logging,mng_gAMA,4L); 1176635ef824baa82511126ff0072ae30eee0da9c05a3cristy PNGLong(chunk+4,(png_uint_32) (100000*image->gamma+0.5)); 117673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(image,8,chunk); 117683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,crc32(0,chunk,8)); 117693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 117700fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 117713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((mng_info->equal_chrms == MagickFalse) && 117723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (image->chromaticity.red_primary.x != 0.0)) 117733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 117743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PrimaryInfo 117753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy primary; 117763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 117773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 117783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Write JNG cHRM chunk 117793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 117803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,32L); 117813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGType(chunk,mng_cHRM); 1178203812ae402fb53d548f0e1d7d14720768f803c2dglennrp LogPNGChunk(logging,mng_cHRM,32L); 117833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy primary=image->chromaticity.white_point; 1178435ef824baa82511126ff0072ae30eee0da9c05a3cristy PNGLong(chunk+4,(png_uint_32) (100000*primary.x+0.5)); 1178535ef824baa82511126ff0072ae30eee0da9c05a3cristy PNGLong(chunk+8,(png_uint_32) (100000*primary.y+0.5)); 117863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy primary=image->chromaticity.red_primary; 1178735ef824baa82511126ff0072ae30eee0da9c05a3cristy PNGLong(chunk+12,(png_uint_32) (100000*primary.x+0.5)); 1178835ef824baa82511126ff0072ae30eee0da9c05a3cristy PNGLong(chunk+16,(png_uint_32) (100000*primary.y+0.5)); 117893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy primary=image->chromaticity.green_primary; 1179035ef824baa82511126ff0072ae30eee0da9c05a3cristy PNGLong(chunk+20,(png_uint_32) (100000*primary.x+0.5)); 1179135ef824baa82511126ff0072ae30eee0da9c05a3cristy PNGLong(chunk+24,(png_uint_32) (100000*primary.y+0.5)); 117923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy primary=image->chromaticity.blue_primary; 1179335ef824baa82511126ff0072ae30eee0da9c05a3cristy PNGLong(chunk+28,(png_uint_32) (100000*primary.x+0.5)); 1179435ef824baa82511126ff0072ae30eee0da9c05a3cristy PNGLong(chunk+32,(png_uint_32) (100000*primary.y+0.5)); 117953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(image,36,chunk); 117963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,crc32(0,chunk,36)); 117973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 117983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 117990fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 118003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->x_resolution && image->y_resolution && !mng_info->equal_physs) 118013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 118023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 118033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Write JNG pHYs chunk 118043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 118053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,9L); 118063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGType(chunk,mng_pHYs); 1180703812ae402fb53d548f0e1d7d14720768f803c2dglennrp LogPNGChunk(logging,mng_pHYs,9L); 118083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->units == PixelsPerInchResolution) 118093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 1181035ef824baa82511126ff0072ae30eee0da9c05a3cristy PNGLong(chunk+4,(png_uint_32) 118113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (image->x_resolution*100.0/2.54+0.5)); 118120fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 1181335ef824baa82511126ff0072ae30eee0da9c05a3cristy PNGLong(chunk+8,(png_uint_32) 118143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (image->y_resolution*100.0/2.54+0.5)); 118150fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 118163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[12]=1; 118173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 118180fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 118193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 118203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 118213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->units == PixelsPerCentimeterResolution) 118223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 1182335ef824baa82511126ff0072ae30eee0da9c05a3cristy PNGLong(chunk+4,(png_uint_32) 118243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (image->x_resolution*100.0+0.5)); 118250fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 1182635ef824baa82511126ff0072ae30eee0da9c05a3cristy PNGLong(chunk+8,(png_uint_32) 118273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (image->y_resolution*100.0+0.5)); 118280fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 118293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[12]=1; 118303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 118310fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 118323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 118333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 1183435ef824baa82511126ff0072ae30eee0da9c05a3cristy PNGLong(chunk+4,(png_uint_32) (image->x_resolution+0.5)); 1183535ef824baa82511126ff0072ae30eee0da9c05a3cristy PNGLong(chunk+8,(png_uint_32) (image->y_resolution+0.5)); 118363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[12]=0; 118373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 118383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 118393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(image,13,chunk); 118403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,crc32(0,chunk,13)); 118413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 118423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 118433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->write_mng == 0 && (image->page.x || image->page.y)) 118443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 118453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 118463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Write JNG oFFs chunk 118473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 118483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,9L); 118493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGType(chunk,mng_oFFs); 1185003812ae402fb53d548f0e1d7d14720768f803c2dglennrp LogPNGChunk(logging,mng_oFFs,9L); 11851bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy PNGsLong(chunk+4,(ssize_t) (image->page.x)); 11852bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy PNGsLong(chunk+8,(ssize_t) (image->page.y)); 118533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[12]=0; 118543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(image,13,chunk); 118553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,crc32(0,chunk,13)); 118563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 118573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->write_mng == 0 && (image->page.width || image->page.height)) 118583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 118593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,9L); /* data length=8 */ 118603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGType(chunk,mng_vpAg); 1186103812ae402fb53d548f0e1d7d14720768f803c2dglennrp LogPNGChunk(logging,mng_vpAg,9L); 118623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGLong(chunk+4,(png_uint_32) image->page.width); 118633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGLong(chunk+8,(png_uint_32) image->page.height); 118643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[12]=0; /* unit = pixels */ 118653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(image,13,chunk); 118663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,crc32(0,chunk,13)); 118673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 118683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 118693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 118703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (transparent) 118713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 118723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (jng_alpha_compression_method==0) 118733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 11874bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy register ssize_t 118753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy i; 118763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 11877bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy ssize_t 118783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy len; 118793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 118803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Write IDAT chunk header */ 118813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 118823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 11883e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " Write IDAT chunks from blob, length=%.20g.",(double) 11884f2faecf9facdbbb14fcba373365f9f691a9658e0cristy length); 118853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 118863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Copy IDAT chunks */ 118873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy len=0; 118883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy p=blob+8; 11889bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (i=8; i<(ssize_t) length; i+=len+12) 118903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 118913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy len=(*p<<24)|((*(p+1))<<16)|((*(p+2))<<8)|(*(p+3)); 118923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy p+=4; 118930fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 118943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (*(p)==73 && *(p+1)==68 && *(p+2)==65 && *(p+3)==84) /* IDAT */ 118953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 118963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Found an IDAT chunk. */ 11897bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy (void) WriteBlobMSBULong(image,(size_t) len); 1189803812ae402fb53d548f0e1d7d14720768f803c2dglennrp LogPNGChunk(logging,mng_IDAT,(size_t) len); 118993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(image,(size_t) len+4,p); 119003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image, 119013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy crc32(0,p,(uInt) len+4)); 119023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 119030fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 119043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 119053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 119063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 119073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 11908e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " Skipping %c%c%c%c chunk, length=%.20g.", 11909e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy *(p),*(p+1),*(p+2),*(p+3),(double) len); 119103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 119113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy p+=(8+len); 119123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 119133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 119143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 119153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 119163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Write JDAA chunk header */ 119173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 119183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 11919e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " Write JDAA chunk, length=%.20g.",(double) length); 11920bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy (void) WriteBlobMSBULong(image,(size_t) length); 119213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGType(chunk,mng_JDAA); 1192203812ae402fb53d548f0e1d7d14720768f803c2dglennrp LogPNGChunk(logging,mng_JDAA,length); 119233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Write JDAT chunk(s) data */ 119243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(image,4,chunk); 119253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(image,length,blob); 119263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,crc32(crc32(0,chunk,4),blob, 119273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (uInt) length)); 119283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 119293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy blob=(unsigned char *) RelinquishMagickMemory(blob); 119303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 119313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 119323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Encode image as a JPEG blob */ 119333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 119343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 119353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Creating jpeg_image_info."); 119363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jpeg_image_info=(ImageInfo *) CloneImageInfo(image_info); 119373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (jpeg_image_info == (ImageInfo *) NULL) 119383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); 119393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 119403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 119413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 119423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Creating jpeg_image."); 119433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 119443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jpeg_image=CloneImage(image,0,0,MagickTrue,&image->exception); 119453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (jpeg_image == (Image *) NULL) 119463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); 119473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) CopyMagickString(jpeg_image->magick,"JPEG",MaxTextExtent); 119483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 119493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) AcquireUniqueFilename(jpeg_image->filename); 119503b6fd2ec2d9f69f9404445dba0aff5bac02e685ccristy (void) FormatLocaleString(jpeg_image_info->filename,MaxTextExtent,"%s", 119513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jpeg_image->filename); 119523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 119533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status=OpenBlob(jpeg_image_info,jpeg_image,WriteBinaryBlobMode, 119543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy &image->exception); 119553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 119563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 119573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 11958e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " Created jpeg_image, %.20g x %.20g.",(double) jpeg_image->columns, 11959e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy (double) jpeg_image->rows); 119603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 119613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (jng_color_type == 8 || jng_color_type == 12) 119623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jpeg_image_info->type=GrayscaleType; 119630fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 119643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jpeg_image_info->quality=jng_quality % 1000; 119653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) CopyMagickString(jpeg_image_info->magick,"JPEG",MaxTextExtent); 119663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) CopyMagickString(jpeg_image->magick,"JPEG",MaxTextExtent); 119670fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 119683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 119693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 119703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Creating blob."); 119710fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 119723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy blob=ImageToBlob(jpeg_image_info,jpeg_image,&length,&image->exception); 119730fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 119743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 119753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 119763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 11977e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " Successfully read jpeg_image into a blob, length=%.20g.", 11978e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy (double) length); 119793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 119803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 11981e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " Write JDAT chunk, length=%.20g.",(double) length); 119823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 119830fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 119843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Write JDAT chunk(s) */ 11985bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy (void) WriteBlobMSBULong(image,(size_t) length); 119863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGType(chunk,mng_JDAT); 1198703812ae402fb53d548f0e1d7d14720768f803c2dglennrp LogPNGChunk(logging,mng_JDAT,length); 119883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(image,4,chunk); 119893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(image,length,blob); 119903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,crc32(crc32(0,chunk,4),blob,(uInt) length)); 119913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 119923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jpeg_image=DestroyImage(jpeg_image); 119933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) RelinquishUniqueFileResource(jpeg_image_info->filename); 119943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy jpeg_image_info=DestroyImageInfo(jpeg_image_info); 119953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy blob=(unsigned char *) RelinquishMagickMemory(blob); 119963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 119973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Write any JNG-chunk-e profiles */ 11998cf002022280cc4dedb2748ad6f415aac1d44f530glennrp (void) Magick_png_write_chunk_from_profile(image,"JNG-chunk-e",logging); 119993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 120003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Write IEND chunk */ 120013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,0L); 120023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGType(chunk,mng_IEND); 1200303812ae402fb53d548f0e1d7d14720768f803c2dglennrp LogPNGChunk(logging,mng_IEND,0); 120043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(image,4,chunk); 120053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,crc32(0,chunk,4)); 120063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 120073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 120083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 120093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " exit WriteOneJNGImage()"); 120100fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 120113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(status); 120123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 120133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 120143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 120153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 120163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 120173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 120183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 120193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 120203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% W r i t e J N G I m a g e % 120213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 120223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 120233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 120243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 120253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 120263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% WriteJNGImage() writes a JPEG Network Graphics (JNG) image file. 120273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 120283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% JNG support written by Glenn Randers-Pehrson, glennrp@image... 120293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 120303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% The format of the WriteJNGImage method is: 120313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 120323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% MagickBooleanType WriteJNGImage(const ImageInfo *image_info,Image *image) 120333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 120343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% A description of each parameter follows: 120353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 120363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o image_info: the image info. 120373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 120383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o image: The image. 120393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 120403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 120413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 120423ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic MagickBooleanType WriteJNGImage(const ImageInfo *image_info,Image *image) 120433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 120443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MagickBooleanType 1204521f0e6211a440c0f96134ea25a1bfe7c5f91c29cglennrp have_mng_structure, 1204603812ae402fb53d548f0e1d7d14720768f803c2dglennrp logging, 120473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status; 120483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 120493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngInfo 120503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *mng_info; 120513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 120523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 120533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Open image file. 120543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 120553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(image_info != (const ImageInfo *) NULL); 120563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(image_info->signature == MagickSignature); 120573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(image != (Image *) NULL); 120583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(image->signature == MagickSignature); 120593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); 12060fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp logging=LogMagickEvent(CoderEvent,GetMagickModule(),"Enter WriteJNGImage()"); 120613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception); 120623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (status == MagickFalse) 120633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(status); 120643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 120653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 120663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Allocate a MngInfo structure. 120673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 120683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy have_mng_structure=MagickFalse; 1206973bd4a51b419e914565bdf204bf1540dc4c8ee26cristy mng_info=(MngInfo *) AcquireMagickMemory(sizeof(MngInfo)); 120703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info == (MngInfo *) NULL) 120713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); 120723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 120733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Initialize members of the MngInfo structure. 120743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 120753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ResetMagickMemory(mng_info,0,sizeof(MngInfo)); 120763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->image=image; 120773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy have_mng_structure=MagickTrue; 120783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 120793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(image,8,(const unsigned char *) "\213JNG\r\n\032\n"); 120803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 120813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status=WriteOneJNGImage(mng_info,image_info,image); 120823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) CloseBlob(image); 120833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 120843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) CatchImageException(image); 120853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngInfoFreeStruct(mng_info,&have_mng_structure); 120863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 120873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(),"exit WriteJNGImage()"); 120883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(status); 120893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 120903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 120913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 120923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 120933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 120943ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic MagickBooleanType WriteMNGImage(const ImageInfo *image_info,Image *image) 120953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 120963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy const char 120973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *option; 120983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 120993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Image 121003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *next_image; 121013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 121023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MagickBooleanType 1210321f0e6211a440c0f96134ea25a1bfe7c5f91c29cglennrp have_mng_structure, 121043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status; 121053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1210603812ae402fb53d548f0e1d7d14720768f803c2dglennrp volatile MagickBooleanType 1210703812ae402fb53d548f0e1d7d14720768f803c2dglennrp logging; 1210803812ae402fb53d548f0e1d7d14720768f803c2dglennrp 121093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngInfo 121103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *mng_info; 121113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 121123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy int 121133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image_count, 121143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy need_iterations, 121153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy need_matte; 121163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 121173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy volatile int 121183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED) || \ 121193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy defined(PNG_MNG_FEATURES_SUPPORTED) 121203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy need_local_plte, 121213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 121223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy all_images_are_gray, 121233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy need_defi, 121243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy use_global_plte; 121253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 12126bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy register ssize_t 121273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy i; 121283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 121293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy unsigned char 121303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[800]; 121313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 121323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy volatile unsigned int 121333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy write_jng, 121343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy write_mng; 121353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 12136bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy volatile size_t 121373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy scene; 121383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 12139bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy size_t 121403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy final_delay=0, 121413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy initial_delay; 121423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 12143d5045b44ae266ec7d6d2fca5e7c8a69a28938ec4glennrp#if (PNG_LIBPNG_VER < 10200) 121443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image_info->verbose) 121453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy printf("Your PNG library (libpng-%s) is rather old.\n", 121463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNG_LIBPNG_VER_STRING); 121473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 121483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 121493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 121503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Open image file. 121513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 121523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(image_info != (const ImageInfo *) NULL); 121533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(image_info->signature == MagickSignature); 121543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(image != (Image *) NULL); 121553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(image->signature == MagickSignature); 121563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); 12157fd05d626fbb7efa0aeff3755d902b5bcdb89b152glennrp logging=LogMagickEvent(CoderEvent,GetMagickModule(),"Enter WriteMNGImage()"); 121583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception); 121593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (status == MagickFalse) 121603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(status); 121613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 121623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 121633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Allocate a MngInfo structure. 121643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 121653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy have_mng_structure=MagickFalse; 1216673bd4a51b419e914565bdf204bf1540dc4c8ee26cristy mng_info=(MngInfo *) AcquireMagickMemory(sizeof(MngInfo)); 121673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info == (MngInfo *) NULL) 121683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); 121693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 121703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Initialize members of the MngInfo structure. 121713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 121723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ResetMagickMemory(mng_info,0,sizeof(MngInfo)); 121733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->image=image; 121743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy have_mng_structure=MagickTrue; 121753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy write_mng=LocaleCompare(image_info->magick,"MNG") == 0; 121763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 121773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 121783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy * See if user has requested a specific PNG subformat to be used 121793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy * for all of the PNGs in the MNG being written, e.g., 121803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy * 121813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy * convert *.png png8:animation.mng 121823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy * 121833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy * To do: check -define png:bit_depth and png:color_type as well, 121843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy * or perhaps use mng:bit_depth and mng:color_type instead for 121853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy * global settings. 121863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 121873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 121883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->write_png8=LocaleCompare(image_info->magick,"PNG8") == 0; 121893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->write_png24=LocaleCompare(image_info->magick,"PNG24") == 0; 121903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->write_png32=LocaleCompare(image_info->magick,"PNG32") == 0; 121913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 121923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy write_jng=MagickFalse; 121933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image_info->compression == JPEGCompression) 121943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy write_jng=MagickTrue; 121953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 121963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->adjoin=image_info->adjoin && 121973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (GetNextImageInList(image) != (Image *) NULL) && write_mng; 121983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 121993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 122003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 122013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Log some info about the input */ 122023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Image 122033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *p; 122043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 122053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 122063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Checking input image(s)"); 122070fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 122083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 12209e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " Image_info depth: %.20g",(double) image_info->depth); 122100fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 122113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 122123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Type: %d",image_info->type); 122133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 122143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy scene=0; 122153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy for (p=image; p != (Image *) NULL; p=GetNextImageInList(p)) 122163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 122173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 12218e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " Scene: %.20g",(double) scene++); 122190fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 122203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 12221e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " Image depth: %.20g",(double) p->depth); 122220fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 122233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (p->matte) 122243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 122253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Matte: True"); 122260fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 122273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 122283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 122293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Matte: False"); 122300fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 122313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (p->storage_class == PseudoClass) 122323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 122333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Storage class: PseudoClass"); 122340fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 122353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 122363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 122373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Storage class: DirectClass"); 122380fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 122393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (p->colors) 122403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 12241e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " Number of colors: %.20g",(double) p->colors); 122420fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 122433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 122443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 122453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Number of colors: unspecified"); 122460fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 122473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->adjoin == MagickFalse) 122483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 122493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 122503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 122513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 122523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy use_global_plte=MagickFalse; 122533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy all_images_are_gray=MagickFalse; 122543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#ifdef PNG_WRITE_EMPTY_PLTE_SUPPORTED 122553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy need_local_plte=MagickTrue; 122563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 122573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy need_defi=MagickFalse; 122583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy need_matte=MagickFalse; 122593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->framing_mode=1; 122603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->old_framing_mode=1; 122613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 122623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (write_mng) 122633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image_info->page != (char *) NULL) 122643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 122653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 122663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Determine image bounding box. 122673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 122683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy SetGeometry(image,&mng_info->page); 122693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ParseMetaGeometry(image_info->page,&mng_info->page.x, 122703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy &mng_info->page.y,&mng_info->page.width,&mng_info->page.height); 122713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 122723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (write_mng) 122733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 122743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy unsigned int 122753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy need_geom; 122763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 122773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy unsigned short 122783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy red, 122793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy green, 122803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy blue; 122813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 122823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->page=image->page; 122833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy need_geom=MagickTrue; 122843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->page.width || mng_info->page.height) 122853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy need_geom=MagickFalse; 122863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 122873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Check all the scenes. 122883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 122893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy initial_delay=image->delay; 122903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy need_iterations=MagickFalse; 122913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->equal_chrms=image->chromaticity.red_primary.x != 0.0; 122923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->equal_physs=MagickTrue, 122933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->equal_gammas=MagickTrue; 122943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->equal_srgbs=MagickTrue; 122953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->equal_backgrounds=MagickTrue; 122963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image_count=0; 122973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED) || \ 122983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy defined(PNG_MNG_FEATURES_SUPPORTED) 122993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy all_images_are_gray=MagickTrue; 123003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->equal_palettes=MagickFalse; 123013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy need_local_plte=MagickFalse; 123023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 123033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy for (next_image=image; next_image != (Image *) NULL; ) 123043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 123053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (need_geom) 123063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 123073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((next_image->columns+next_image->page.x) > mng_info->page.width) 123083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->page.width=next_image->columns+next_image->page.x; 123090fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 123103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((next_image->rows+next_image->page.y) > mng_info->page.height) 123113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->page.height=next_image->rows+next_image->page.y; 123123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 123130fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 123143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (next_image->page.x || next_image->page.y) 123153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy need_defi=MagickTrue; 123160fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 123173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (next_image->matte) 123183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy need_matte=MagickTrue; 123190fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 123203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((int) next_image->dispose >= BackgroundDispose) 123213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (next_image->matte || next_image->page.x || next_image->page.y || 123223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ((next_image->columns < mng_info->page.width) && 123233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (next_image->rows < mng_info->page.height))) 123243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->need_fram=MagickTrue; 123250fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 123263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (next_image->iterations) 123273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy need_iterations=MagickTrue; 123280fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 123293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy final_delay=next_image->delay; 123300fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 123313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (final_delay != initial_delay || final_delay > 1UL* 123323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy next_image->ticks_per_second) 123333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->need_fram=1; 123340fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 123353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED) || \ 123363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy defined(PNG_MNG_FEATURES_SUPPORTED) 123373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 123383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy check for global palette possibility. 123393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 123403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->matte != MagickFalse) 123413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy need_local_plte=MagickTrue; 123420fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 123433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (need_local_plte == 0) 123443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 123453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (ImageIsGray(image) == MagickFalse) 123463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy all_images_are_gray=MagickFalse; 123473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->equal_palettes=PalettesAreEqual(image,next_image); 123483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (use_global_plte == 0) 123493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy use_global_plte=mng_info->equal_palettes; 123503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy need_local_plte=!mng_info->equal_palettes; 123513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 123523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 123533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (GetNextImageInList(next_image) != (Image *) NULL) 123543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 123553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (next_image->background_color.red != 123563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy next_image->next->background_color.red || 123573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy next_image->background_color.green != 123583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy next_image->next->background_color.green || 123593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy next_image->background_color.blue != 123603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy next_image->next->background_color.blue) 123613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->equal_backgrounds=MagickFalse; 123620fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 123633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (next_image->gamma != next_image->next->gamma) 123643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->equal_gammas=MagickFalse; 123650fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 123663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (next_image->rendering_intent != 123673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy next_image->next->rendering_intent) 123683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->equal_srgbs=MagickFalse; 123690fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 123703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((next_image->units != next_image->next->units) || 123713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (next_image->x_resolution != next_image->next->x_resolution) || 123723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (next_image->y_resolution != next_image->next->y_resolution)) 123733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->equal_physs=MagickFalse; 123740fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 123753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->equal_chrms) 123763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 123773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (next_image->chromaticity.red_primary.x != 123783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy next_image->next->chromaticity.red_primary.x || 123793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy next_image->chromaticity.red_primary.y != 123803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy next_image->next->chromaticity.red_primary.y || 123813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy next_image->chromaticity.green_primary.x != 123823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy next_image->next->chromaticity.green_primary.x || 123833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy next_image->chromaticity.green_primary.y != 123843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy next_image->next->chromaticity.green_primary.y || 123853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy next_image->chromaticity.blue_primary.x != 123863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy next_image->next->chromaticity.blue_primary.x || 123873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy next_image->chromaticity.blue_primary.y != 123883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy next_image->next->chromaticity.blue_primary.y || 123893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy next_image->chromaticity.white_point.x != 123903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy next_image->next->chromaticity.white_point.x || 123913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy next_image->chromaticity.white_point.y != 123923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy next_image->next->chromaticity.white_point.y) 123933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->equal_chrms=MagickFalse; 123943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 123953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 123963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image_count++; 123973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy next_image=GetNextImageInList(next_image); 123983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 123993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image_count < 2) 124003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 124013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->equal_backgrounds=MagickFalse; 124023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->equal_chrms=MagickFalse; 124033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->equal_gammas=MagickFalse; 124043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->equal_srgbs=MagickFalse; 124053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->equal_physs=MagickFalse; 124063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy use_global_plte=MagickFalse; 124073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#ifdef PNG_WRITE_EMPTY_PLTE_SUPPORTED 124083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy need_local_plte=MagickTrue; 124093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 124103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy need_iterations=MagickFalse; 124113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 124120fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 124133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->need_fram == MagickFalse) 124143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 124153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 124163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Only certain framing rates 100/n are exactly representable without 124173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy the FRAM chunk but we'll allow some slop in VLC files 124183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 124193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (final_delay == 0) 124203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 124213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (need_iterations != MagickFalse) 124223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 124233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 124243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy It's probably a GIF with loop; don't run it *too* fast. 124253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 124260261712cdc8fb4765add50146936e3ba2cb9fefaglennrp if (mng_info->adjoin) 12427d908de4208e47f6b6ddb7c288b50d8f6d8845bb2glennrp { 12428d908de4208e47f6b6ddb7c288b50d8f6d8845bb2glennrp final_delay=10; 12429d908de4208e47f6b6ddb7c288b50d8f6d8845bb2glennrp (void) ThrowMagickException(&image->exception, 12430d908de4208e47f6b6ddb7c288b50d8f6d8845bb2glennrp GetMagickModule(),CoderWarning, 12431d908de4208e47f6b6ddb7c288b50d8f6d8845bb2glennrp "input has zero delay between all frames; assuming", 12432d908de4208e47f6b6ddb7c288b50d8f6d8845bb2glennrp " 10 cs `%s'",""); 12433d908de4208e47f6b6ddb7c288b50d8f6d8845bb2glennrp } 124343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 124353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 124363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->ticks_per_second=0; 124373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 124383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (final_delay != 0) 12439cf002022280cc4dedb2748ad6f415aac1d44f530glennrp mng_info->ticks_per_second=(png_uint_32) 12440cf002022280cc4dedb2748ad6f415aac1d44f530glennrp (image->ticks_per_second/final_delay); 124413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (final_delay > 50) 124423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->ticks_per_second=2; 124430fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 124443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (final_delay > 75) 124453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->ticks_per_second=1; 124460fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 124473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (final_delay > 125) 124483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->need_fram=MagickTrue; 124490fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 124503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (need_defi && final_delay > 2 && (final_delay != 4) && 124513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (final_delay != 5) && (final_delay != 10) && (final_delay != 20) && 124523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (final_delay != 25) && (final_delay != 50) && (final_delay != 124533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1UL*image->ticks_per_second)) 124543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->need_fram=MagickTrue; /* make it exact; cannot be VLC */ 124553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 124560fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 124573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->need_fram != MagickFalse) 124583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->ticks_per_second=1UL*image->ticks_per_second; 124593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 124603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy If pseudocolor, we should also check to see if all the 124613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy palettes are identical and write a global PLTE if they are. 124623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ../glennrp Feb 99. 124633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 124643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 124653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Write the MNG version 1.0 signature and MHDR chunk. 124663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 124673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(image,8,(const unsigned char *) "\212MNG\r\n\032\n"); 124683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,28L); /* chunk data length=28 */ 124693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGType(chunk,mng_MHDR); 1247003812ae402fb53d548f0e1d7d14720768f803c2dglennrp LogPNGChunk(logging,mng_MHDR,28L); 124714e5bc84ff8bf274c4d9206d5e6ffd1a5e5d75335cristy PNGLong(chunk+4,(png_uint_32) mng_info->page.width); 124724e5bc84ff8bf274c4d9206d5e6ffd1a5e5d75335cristy PNGLong(chunk+8,(png_uint_32) mng_info->page.height); 124733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGLong(chunk+12,mng_info->ticks_per_second); 124743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGLong(chunk+16,0L); /* layer count=unknown */ 124753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGLong(chunk+20,0L); /* frame count=unknown */ 124763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGLong(chunk+24,0L); /* play time=unknown */ 124773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (write_jng) 124783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 124793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (need_matte) 124803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 124813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (need_defi || mng_info->need_fram || use_global_plte) 124823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGLong(chunk+28,27L); /* simplicity=LC+JNG */ 124830fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 124843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 124853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGLong(chunk+28,25L); /* simplicity=VLC+JNG */ 124863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 124870fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 124883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 124893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 124903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (need_defi || mng_info->need_fram || use_global_plte) 124913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGLong(chunk+28,19L); /* simplicity=LC+JNG, no transparency */ 124920fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 124933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 124943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGLong(chunk+28,17L); /* simplicity=VLC+JNG, no transparency */ 124953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 124963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 124970fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 124983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 124993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 125003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (need_matte) 125013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 125023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (need_defi || mng_info->need_fram || use_global_plte) 125033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGLong(chunk+28,11L); /* simplicity=LC */ 125040fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 125053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 125063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGLong(chunk+28,9L); /* simplicity=VLC */ 125073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 125080fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 125093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 125103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 125113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (need_defi || mng_info->need_fram || use_global_plte) 125123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGLong(chunk+28,3L); /* simplicity=LC, no transparency */ 125130fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 125143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 125153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGLong(chunk+28,1L); /* simplicity=VLC, no transparency */ 125163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 125173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 125183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(image,32,chunk); 125193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,crc32(0,chunk,32)); 125203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy option=GetImageOption(image_info,"mng:need-cacheoff"); 125213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (option != (const char *) NULL) 125223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 125233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy size_t 125243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy length; 125253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 125263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 125273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Write "nEED CACHEOFF" to turn playback caching off for streaming MNG. 125283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 125293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGType(chunk,mng_nEED); 125303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy length=CopyMagickString((char *) chunk+4,"CACHEOFF",20); 12531bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy (void) WriteBlobMSBULong(image,(size_t) length); 1253203812ae402fb53d548f0e1d7d14720768f803c2dglennrp LogPNGChunk(logging,mng_nEED,(size_t) length); 125333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy length+=4; 125343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(image,length,chunk); 125353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,crc32(0,chunk,(uInt) length)); 125363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 125373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((GetPreviousImageInList(image) == (Image *) NULL) && 125383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (GetNextImageInList(image) != (Image *) NULL) && 125393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (image->iterations != 1)) 125403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 125413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 125423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Write MNG TERM chunk 125433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 125443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,10L); /* data length=10 */ 125453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGType(chunk,mng_TERM); 1254603812ae402fb53d548f0e1d7d14720768f803c2dglennrp LogPNGChunk(logging,mng_TERM,10L); 125473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[4]=3; /* repeat animation */ 125483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[5]=0; /* show last frame when done */ 125493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGLong(chunk+6,(png_uint_32) (mng_info->ticks_per_second* 125503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy final_delay/MagickMax(image->ticks_per_second,1))); 125510fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 125523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->iterations == 0) 125533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGLong(chunk+10,PNG_UINT_31_MAX); 125540fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 125553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 125563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGLong(chunk+10,(png_uint_32) image->iterations); 125570fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 125583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 125593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 125603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 12561e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " TERM delay: %.20g",(double) (mng_info->ticks_per_second* 12562e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy final_delay/MagickMax(image->ticks_per_second,1))); 125630fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 125643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->iterations == 0) 125653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 12566e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " TERM iterations: %.20g",(double) PNG_UINT_31_MAX); 125670fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 125683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 125693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 12570e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy " Image iterations: %.20g",(double) image->iterations); 125713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 125723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(image,14,chunk); 125733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,crc32(0,chunk,14)); 125743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 125753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 125763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy To do: check for cHRM+gAMA == sRGB, and write sRGB instead. 125773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 125783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((image->colorspace == sRGBColorspace || image->rendering_intent) && 125793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->equal_srgbs) 125803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 125813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 125823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Write MNG sRGB chunk 125833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 125843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,1L); 125853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGType(chunk,mng_sRGB); 1258603812ae402fb53d548f0e1d7d14720768f803c2dglennrp LogPNGChunk(logging,mng_sRGB,1L); 125870fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 125883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->rendering_intent != UndefinedIntent) 12589e610a071534e448c46460a5aa39ede33bf56b329glennrp chunk[4]=(unsigned char) 12590cf002022280cc4dedb2748ad6f415aac1d44f530glennrp Magick_RenderingIntent_to_PNG_RenderingIntent( 12591e610a071534e448c46460a5aa39ede33bf56b329glennrp (image->rendering_intent)); 125920fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 125933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 12594e610a071534e448c46460a5aa39ede33bf56b329glennrp chunk[4]=(unsigned char) 12595cf002022280cc4dedb2748ad6f415aac1d44f530glennrp Magick_RenderingIntent_to_PNG_RenderingIntent( 12596cf002022280cc4dedb2748ad6f415aac1d44f530glennrp (PerceptualIntent)); 125970fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 125983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(image,5,chunk); 125993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,crc32(0,chunk,5)); 126003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->have_write_global_srgb=MagickTrue; 126013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 126020fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 126033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 126043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 126053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->gamma && mng_info->equal_gammas) 126063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 126073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 126083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Write MNG gAMA chunk 126093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 126103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,4L); 126113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGType(chunk,mng_gAMA); 1261203812ae402fb53d548f0e1d7d14720768f803c2dglennrp LogPNGChunk(logging,mng_gAMA,4L); 1261335ef824baa82511126ff0072ae30eee0da9c05a3cristy PNGLong(chunk+4,(png_uint_32) (100000*image->gamma+0.5)); 126143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(image,8,chunk); 126153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,crc32(0,chunk,8)); 126163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->have_write_global_gama=MagickTrue; 126173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 126183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->equal_chrms) 126193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 126203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PrimaryInfo 126213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy primary; 126223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 126233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 126243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Write MNG cHRM chunk 126253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 126263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,32L); 126273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGType(chunk,mng_cHRM); 1262803812ae402fb53d548f0e1d7d14720768f803c2dglennrp LogPNGChunk(logging,mng_cHRM,32L); 126293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy primary=image->chromaticity.white_point; 1263035ef824baa82511126ff0072ae30eee0da9c05a3cristy PNGLong(chunk+4,(png_uint_32) (100000*primary.x+0.5)); 1263135ef824baa82511126ff0072ae30eee0da9c05a3cristy PNGLong(chunk+8,(png_uint_32) (100000*primary.y+0.5)); 126323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy primary=image->chromaticity.red_primary; 1263335ef824baa82511126ff0072ae30eee0da9c05a3cristy PNGLong(chunk+12,(png_uint_32) (100000*primary.x+0.5)); 1263435ef824baa82511126ff0072ae30eee0da9c05a3cristy PNGLong(chunk+16,(png_uint_32) (100000*primary.y+0.5)); 126353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy primary=image->chromaticity.green_primary; 1263635ef824baa82511126ff0072ae30eee0da9c05a3cristy PNGLong(chunk+20,(png_uint_32) (100000*primary.x+0.5)); 1263735ef824baa82511126ff0072ae30eee0da9c05a3cristy PNGLong(chunk+24,(png_uint_32) (100000*primary.y+0.5)); 126383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy primary=image->chromaticity.blue_primary; 1263935ef824baa82511126ff0072ae30eee0da9c05a3cristy PNGLong(chunk+28,(png_uint_32) (100000*primary.x+0.5)); 1264035ef824baa82511126ff0072ae30eee0da9c05a3cristy PNGLong(chunk+32,(png_uint_32) (100000*primary.y+0.5)); 126413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(image,36,chunk); 126423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,crc32(0,chunk,36)); 126433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->have_write_global_chrm=MagickTrue; 126443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 126453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 126463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->x_resolution && image->y_resolution && mng_info->equal_physs) 126473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 126483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 126493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Write MNG pHYs chunk 126503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 126513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,9L); 126523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGType(chunk,mng_pHYs); 1265303812ae402fb53d548f0e1d7d14720768f803c2dglennrp LogPNGChunk(logging,mng_pHYs,9L); 126540fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 126553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->units == PixelsPerInchResolution) 126563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 1265735ef824baa82511126ff0072ae30eee0da9c05a3cristy PNGLong(chunk+4,(png_uint_32) 126583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (image->x_resolution*100.0/2.54+0.5)); 126590fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 1266035ef824baa82511126ff0072ae30eee0da9c05a3cristy PNGLong(chunk+8,(png_uint_32) 126613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (image->y_resolution*100.0/2.54+0.5)); 126620fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 126633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[12]=1; 126643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 126650fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 126663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 126673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 126683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->units == PixelsPerCentimeterResolution) 126693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 1267035ef824baa82511126ff0072ae30eee0da9c05a3cristy PNGLong(chunk+4,(png_uint_32) 126713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (image->x_resolution*100.0+0.5)); 126720fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 1267335ef824baa82511126ff0072ae30eee0da9c05a3cristy PNGLong(chunk+8,(png_uint_32) 126743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (image->y_resolution*100.0+0.5)); 126750fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 126763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[12]=1; 126773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 126780fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 126793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 126803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 1268135ef824baa82511126ff0072ae30eee0da9c05a3cristy PNGLong(chunk+4,(png_uint_32) (image->x_resolution+0.5)); 1268235ef824baa82511126ff0072ae30eee0da9c05a3cristy PNGLong(chunk+8,(png_uint_32) (image->y_resolution+0.5)); 126833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[12]=0; 126843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 126853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 126863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(image,13,chunk); 126873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,crc32(0,chunk,13)); 126883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 126893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 126903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Write MNG BACK chunk and global bKGD chunk, if the image is transparent 126913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy or does not cover the entire frame. 126923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 126933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (write_mng && (image->matte || image->page.x > 0 || 126943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->page.y > 0 || (image->page.width && 126953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (image->page.width+image->page.x < mng_info->page.width)) 126963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy || (image->page.height && (image->page.height+image->page.y 126973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy < mng_info->page.height)))) 126983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 126993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,6L); 127003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGType(chunk,mng_BACK); 1270103812ae402fb53d548f0e1d7d14720768f803c2dglennrp LogPNGChunk(logging,mng_BACK,6L); 127023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy red=ScaleQuantumToShort(image->background_color.red); 127033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy green=ScaleQuantumToShort(image->background_color.green); 127043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy blue=ScaleQuantumToShort(image->background_color.blue); 127053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGShort(chunk+4,red); 127063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGShort(chunk+6,green); 127073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGShort(chunk+8,blue); 127083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(image,10,chunk); 127093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,crc32(0,chunk,10)); 127103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->equal_backgrounds) 127113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 127123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,6L); 127133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGType(chunk,mng_bKGD); 1271403812ae402fb53d548f0e1d7d14720768f803c2dglennrp LogPNGChunk(logging,mng_bKGD,6L); 127153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(image,10,chunk); 127163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,crc32(0,chunk,10)); 127173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 127183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 127193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 127203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#ifdef PNG_WRITE_EMPTY_PLTE_SUPPORTED 127213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((need_local_plte == MagickFalse) && 127223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (image->storage_class == PseudoClass) && 127233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (all_images_are_gray == MagickFalse)) 127243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 12725bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy size_t 127263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy data_length; 127273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 127283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 127293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Write MNG PLTE chunk 127303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 127313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy data_length=3*image->colors; 127323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,data_length); 127333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGType(chunk,mng_PLTE); 1273403812ae402fb53d548f0e1d7d14720768f803c2dglennrp LogPNGChunk(logging,mng_PLTE,data_length); 127350fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 12736bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (i=0; i < (ssize_t) image->colors; i++) 127373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 127383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[4+i*3]=ScaleQuantumToChar(image->colormap[i].red) & 0xff; 127393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[5+i*3]=ScaleQuantumToChar(image->colormap[i].green) & 0xff; 127403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[6+i*3]=ScaleQuantumToChar(image->colormap[i].blue) & 0xff; 127413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 127420fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 127433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(image,data_length+4,chunk); 127443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,crc32(0,chunk,(uInt) (data_length+4))); 127453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->have_write_global_plte=MagickTrue; 127463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 127473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 127483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 127493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy scene=0; 127503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->delay=0; 127513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED) || \ 127523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy defined(PNG_MNG_FEATURES_SUPPORTED) 127533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->equal_palettes=MagickFalse; 127543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 127553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy do 127563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 127573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->adjoin) 127583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 127593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED) || \ 127603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy defined(PNG_MNG_FEATURES_SUPPORTED) 127613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 127623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy If we aren't using a global palette for the entire MNG, check to 127633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy see if we can use one for two or more consecutive images. 127643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 127653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (need_local_plte && use_global_plte && !all_images_are_gray) 127663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 127673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->IsPalette) 127683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 127693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 127703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy When equal_palettes is true, this image has the same palette 127713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy as the previous PseudoClass image 127723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 127733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->have_write_global_plte=mng_info->equal_palettes; 127743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->equal_palettes=PalettesAreEqual(image,image->next); 127753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->equal_palettes && !mng_info->have_write_global_plte) 127763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 127773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 127783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Write MNG PLTE chunk 127793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 12780bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy size_t 127813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy data_length; 127823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 127833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy data_length=3*image->colors; 127843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,data_length); 127853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGType(chunk,mng_PLTE); 1278603812ae402fb53d548f0e1d7d14720768f803c2dglennrp LogPNGChunk(logging,mng_PLTE,data_length); 127870fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 12788bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy for (i=0; i < (ssize_t) image->colors; i++) 127893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 127903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[4+i*3]=ScaleQuantumToChar(image->colormap[i].red); 127913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[5+i*3]=ScaleQuantumToChar(image->colormap[i].green); 127923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[6+i*3]=ScaleQuantumToChar(image->colormap[i].blue); 127933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 127940fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 127953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(image,data_length+4,chunk); 127963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,crc32(0,chunk, 127973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (uInt) (data_length+4))); 127983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->have_write_global_plte=MagickTrue; 127993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 128003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 128013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 128023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->have_write_global_plte=MagickFalse; 128033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 128043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 128053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (need_defi) 128063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 12807bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy ssize_t 128083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy previous_x, 128093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy previous_y; 128103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 128113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (scene) 128123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 128133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy previous_x=mng_info->page.x; 128143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy previous_y=mng_info->page.y; 128153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 128163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 128173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 128183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy previous_x=0; 128193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy previous_y=0; 128203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 128213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->page=image->page; 128223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((mng_info->page.x != previous_x) || 128233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (mng_info->page.y != previous_y)) 128243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 128253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,12L); /* data length=12 */ 128263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGType(chunk,mng_DEFI); 1282703812ae402fb53d548f0e1d7d14720768f803c2dglennrp LogPNGChunk(logging,mng_DEFI,12L); 128283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[4]=0; /* object 0 MSB */ 128293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[5]=0; /* object 0 LSB */ 128303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[6]=0; /* visible */ 128313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[7]=0; /* abstract */ 128323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGLong(chunk+8,(png_uint_32) mng_info->page.x); 128333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGLong(chunk+12,(png_uint_32) mng_info->page.y); 128343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(image,16,chunk); 128353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,crc32(0,chunk,16)); 128363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 128373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 128383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 128393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 128403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->write_mng=write_mng; 128413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 128423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ((int) image->dispose >= 3) 128433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->framing_mode=3; 128443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 128453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (mng_info->need_fram && mng_info->adjoin && 128463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ((image->delay != mng_info->delay) || 128473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (mng_info->framing_mode != mng_info->old_framing_mode))) 128483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 128493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->delay == mng_info->delay) 128503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 128513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 128523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Write a MNG FRAM chunk with the new framing mode. 128533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 128543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,1L); /* data length=1 */ 128553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGType(chunk,mng_FRAM); 1285603812ae402fb53d548f0e1d7d14720768f803c2dglennrp LogPNGChunk(logging,mng_FRAM,1L); 128573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[4]=(unsigned char) mng_info->framing_mode; 128583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(image,5,chunk); 128593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,crc32(0,chunk,5)); 128603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 128613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 128623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 128633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 128643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Write a MNG FRAM chunk with the delay. 128653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 128663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,10L); /* data length=10 */ 128673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGType(chunk,mng_FRAM); 1286803812ae402fb53d548f0e1d7d14720768f803c2dglennrp LogPNGChunk(logging,mng_FRAM,10L); 128693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[4]=(unsigned char) mng_info->framing_mode; 128703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[5]=0; /* frame name separator (no name) */ 128713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[6]=2; /* flag for changing default delay */ 128723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[7]=0; /* flag for changing frame timeout */ 128733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[8]=0; /* flag for changing frame clipping */ 128743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy chunk[9]=0; /* flag for changing frame sync_id */ 128753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGLong(chunk+10,(png_uint_32) 128763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ((mng_info->ticks_per_second* 128773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image->delay)/MagickMax(image->ticks_per_second,1))); 128783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(image,14,chunk); 128793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,crc32(0,chunk,14)); 128804e5bc84ff8bf274c4d9206d5e6ffd1a5e5d75335cristy mng_info->delay=(png_uint_32) image->delay; 128813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 128823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy mng_info->old_framing_mode=mng_info->framing_mode; 128833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 128843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 128853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(JNG_SUPPORTED) 128863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image_info->compression == JPEGCompression) 128873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 128883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ImageInfo 128893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *write_info; 128903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 128913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 128923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 128933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Writing JNG object."); 128943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* To do: specify the desired alpha compression method. */ 128953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy write_info=CloneImageInfo(image_info); 128963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy write_info->compression=UndefinedCompression; 128973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status=WriteOneJNGImage(mng_info,write_info,image); 128983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy write_info=DestroyImageInfo(write_info); 128993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 129003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 129013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 129023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 129033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 129043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(), 129053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy " Writing PNG object."); 129062f2e514554975d510c88df54de98c6cdc1080f1cglennrp 12907b9cfe27bef51dbbd1f05aef89c767749d7e37864glennrp mng_info->need_blob = MagickFalse; 129088d3d6e584829223ac5f6e6653c3caa38a2562a74glennrp mng_info->ping_preserve_colormap = MagickFalse; 129092f2e514554975d510c88df54de98c6cdc1080f1cglennrp 129102f2e514554975d510c88df54de98c6cdc1080f1cglennrp /* We don't want any ancillary chunks written */ 129112f2e514554975d510c88df54de98c6cdc1080f1cglennrp mng_info->ping_exclude_bKGD=MagickTrue; 129122f2e514554975d510c88df54de98c6cdc1080f1cglennrp mng_info->ping_exclude_cHRM=MagickTrue; 12913a0ed009a1e9480ac6f3f4520e9ef29d6d37e27dcglennrp mng_info->ping_exclude_date=MagickTrue; 129142f2e514554975d510c88df54de98c6cdc1080f1cglennrp mng_info->ping_exclude_EXIF=MagickTrue; 129152f2e514554975d510c88df54de98c6cdc1080f1cglennrp mng_info->ping_exclude_gAMA=MagickTrue; 129162f2e514554975d510c88df54de98c6cdc1080f1cglennrp mng_info->ping_exclude_iCCP=MagickTrue; 129172f2e514554975d510c88df54de98c6cdc1080f1cglennrp /* mng_info->ping_exclude_iTXt=MagickTrue; */ 129182f2e514554975d510c88df54de98c6cdc1080f1cglennrp mng_info->ping_exclude_oFFs=MagickTrue; 129192f2e514554975d510c88df54de98c6cdc1080f1cglennrp mng_info->ping_exclude_pHYs=MagickTrue; 129202f2e514554975d510c88df54de98c6cdc1080f1cglennrp mng_info->ping_exclude_sRGB=MagickTrue; 129212f2e514554975d510c88df54de98c6cdc1080f1cglennrp mng_info->ping_exclude_tEXt=MagickTrue; 12922a1e3b7b4887860a199d00bddbf4b12e0a93ee1e5glennrp mng_info->ping_exclude_tRNS=MagickTrue; 129232f2e514554975d510c88df54de98c6cdc1080f1cglennrp mng_info->ping_exclude_vpAg=MagickTrue; 129242f2e514554975d510c88df54de98c6cdc1080f1cglennrp mng_info->ping_exclude_zCCP=MagickTrue; 129252f2e514554975d510c88df54de98c6cdc1080f1cglennrp mng_info->ping_exclude_zTXt=MagickTrue; 129262f2e514554975d510c88df54de98c6cdc1080f1cglennrp 129273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status=WriteOnePNGImage(mng_info,image_info,image); 129283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 129293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 129303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (status == MagickFalse) 129313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 129323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngInfoFreeStruct(mng_info,&have_mng_structure); 129333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) CloseBlob(image); 129343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(MagickFalse); 129353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 129363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) CatchImageException(image); 129373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (GetNextImageInList(image) == (Image *) NULL) 129383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 129393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=SyncNextImageInList(image); 129403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status=SetImageProgress(image,SaveImagesTag,scene++, 129413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy GetImageListLength(image)); 129420fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 129433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (status == MagickFalse) 129443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 129450fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 129463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } while (mng_info->adjoin); 129470fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 129483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (write_mng) 129493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 129503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy while (GetPreviousImageInList(image) != (Image *) NULL) 129513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=GetPreviousImageInList(image); 129523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 129533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Write the MEND chunk. 129543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 129553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,0x00000000L); 129563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNGType(chunk,mng_MEND); 1295703812ae402fb53d548f0e1d7d14720768f803c2dglennrp LogPNGChunk(logging,mng_MEND,0L); 129583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlob(image,4,chunk); 129593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) WriteBlobMSBULong(image,crc32(0,chunk,4)); 129603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 129613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 129623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Relinquish resources. 129633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 129643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) CloseBlob(image); 129653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MngInfoFreeStruct(mng_info,&have_mng_structure); 129660fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 129673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (logging != MagickFalse) 129683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(CoderEvent,GetMagickModule(),"exit WriteMNGImage()"); 129690fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 129703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(MagickTrue); 129713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 12972d5045b44ae266ec7d6d2fca5e7c8a69a28938ec4glennrp#else /* PNG_LIBPNG_VER > 10011 */ 1297339992b4dd9b12ef752d55b8e402c069698851f72glennrp 129743ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic MagickBooleanType WritePNGImage(const ImageInfo *image_info,Image *image) 129753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 129763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image=image; 129773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy printf("Your PNG library is too old: You have libpng-%s\n", 129783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PNG_LIBPNG_VER_STRING); 129790fe50b47f88ea0fc74b8bdb0e552fc7c58e2b5a0glennrp 129803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowBinaryException(CoderError,"PNG library is too old", 129813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image_info->filename); 129823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 1298339992b4dd9b12ef752d55b8e402c069698851f72glennrp 129843ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic MagickBooleanType WriteMNGImage(const ImageInfo *image_info,Image *image) 129853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 129863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(WritePNGImage(image_info,image)); 129873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 12988d5045b44ae266ec7d6d2fca5e7c8a69a28938ec4glennrp#endif /* PNG_LIBPNG_VER > 10011 */ 129893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 12990