diff options
Diffstat (limited to 'coders/png.c')
-rw-r--r-- | coders/png.c | 106 |
1 files changed, 81 insertions, 25 deletions
diff --git a/coders/png.c b/coders/png.c index 60ce8dc..9895a68 100644 --- a/coders/png.c +++ b/coders/png.c @@ -3047,12 +3047,12 @@ DestroyJNG(unsigned char *chunk,Image **color_image, } if (*color_image) { - DestroyImage(*color_image); + DestroyImageList(*color_image); *color_image = (Image *)NULL; } if (*alpha_image) { - DestroyImage(*alpha_image); + DestroyImageList(*alpha_image); *alpha_image = (Image *)NULL; } } @@ -3433,6 +3433,20 @@ static Image *ReadOneJNGImage(MngInfo *mng_info, if (!image_info->ping && jng_color_type >= 12) { + if ((jng_alpha_compression_method != 0) && + (jng_alpha_compression_method != 8)) + { + if (logging) + (void) LogMagickEvent(CoderEvent,GetMagickModule(), + "Unsupported Alpha_compression_method: %u", + jng_alpha_compression_method); + DestroyJNG(chunk,&color_image,&color_image_info, + &alpha_image,&alpha_image_info); + ThrowException(exception,CorruptImageError,ImproperImageHeader, + image->filename); + return ((Image *)NULL); + } + alpha_image_info=MagickAllocateMemory(ImageInfo *, sizeof(ImageInfo)); if (alpha_image_info == (ImageInfo *) NULL) @@ -3743,7 +3757,7 @@ static Image *ReadOneJNGImage(MngInfo *mng_info, ThrowException(exception,CorruptImageError, ImageFileDoesNotContainAnyImageData,image->filename); } - DestroyImage(color_image); + DestroyImageList(color_image); color_image=(Image *) NULL; return (Image *) NULL; } @@ -3758,6 +3772,9 @@ static Image *ReadOneJNGImage(MngInfo *mng_info, FormatString(color_image_info->filename,"JPEG:%.1024s",color_image->filename); color_image_info->ping=MagickFalse; /* To do: avoid this */ + color_image_info->subimage=0; + color_image_info->subrange=1; + jng_image=ReadImage(color_image_info,exception); (void) LiberateUniqueFileResource(color_image->filename); DestroyImage(color_image); @@ -3842,6 +3859,17 @@ static Image *ReadOneJNGImage(MngInfo *mng_info, { if (jng_color_type >= 12) { + /* + Alpha is stored in PNG or JPEG format: + Alpha_compression_method: + 1 byte. + 0: PNG grayscale IDAT format. + 8: JNG 8-bit grayscale JDAA format + */ + const char *jng_alpha_magick= + (jng_alpha_compression_method == 0 ? "PNG" : + (jng_alpha_compression_method == 8 ? "JPEG" : + "UNKNOWN")); if (jng_alpha_compression_method == 0) { png_byte @@ -3855,10 +3883,12 @@ static Image *ReadOneJNGImage(MngInfo *mng_info, CloseBlob(alpha_image); if (logging) (void) LogMagickEvent(CoderEvent,GetMagickModule(), - " Reading opacity from alpha_blob."); - - FormatString(alpha_image_info->filename,"%.1024s", - alpha_image->filename); + " Reading opacity from %s alpha_blob.", + jng_alpha_magick); + FormatString(alpha_image_info->filename,"%s:%.1024s", + jng_alpha_magick, alpha_image->filename); + alpha_image_info->subimage=0; + alpha_image_info->subrange=1; jng_image=ReadImage(alpha_image_info,exception); @@ -3875,7 +3905,7 @@ static Image *ReadOneJNGImage(MngInfo *mng_info, if (logging) { (void) LogMagickEvent(CoderEvent,GetMagickModule(), - " Read jng_image."); + " Read jng_image (%s)",image->magick); (void) LogMagickEvent(CoderEvent,GetMagickModule(), " jng_image->width=%lu, jng_image->height=%lu", (unsigned long)jng_width,(unsigned long)jng_height); @@ -3919,7 +3949,7 @@ static Image *ReadOneJNGImage(MngInfo *mng_info, &alpha_image,&alpha_image_info); (void) LogMagickEvent(CoderEvent,GetMagickModule(), " Destroy the JNG image"); - DestroyImage(jng_image); + DestroyImageList(jng_image); jng_image = (Image *)NULL; } } @@ -5679,6 +5709,8 @@ static Image *ReadMNGImage(const ImageInfo *image_info, /* If magnifying and a supported method is requested then magnify the image. + + http://www.libpng.org/pub/mng/spec/mng-1.0-20010209-pdg.html#mng-MAGN */ if (((mng_info->magn_methx > 0) && (mng_info->magn_methx <= 5)) && ((mng_info->magn_methy > 0) && (mng_info->magn_methy <= 5))) @@ -5689,7 +5721,28 @@ static Image *ReadMNGImage(const ImageInfo *image_info, if (logging) (void) LogMagickEvent(CoderEvent,GetMagickModule(), - " Processing MNG MAGN chunk"); + " Processing MNG MAGN chunk: MB=%u, ML=%u," + " MR=%u, MT=%u, MX=%u, MY=%u," + " X_method=%u, Y_method=%u", + mng_info->magn_mb,mng_info->magn_ml, + mng_info->magn_mr,mng_info->magn_mt, + mng_info->magn_mx,mng_info->magn_my, + mng_info->magn_methx, + mng_info->magn_methy); + + /* + If the image width is 1, then X magnification is done + by simple pixel replication. + */ + if (image->columns == 1) + mng_info->magn_methx = 1; + + /* + If the image height is 1, then Y magnification is done + by simple pixel replication. + */ + if (image->rows == 1) + mng_info->magn_methy = 1; if (mng_info->magn_methx == 1) { @@ -5734,12 +5787,10 @@ static Image *ReadMNGImage(const ImageInfo *image_info, Image *large_image; - int - yy; - long m, - y; + y, + yy; register long x; @@ -6955,14 +7006,14 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_info, /* Define these outside of the following "if logging()" block so they will * show in debuggers. */ - gm_vers=MagickLibVersionText; + gm_vers=MagickLibVersionText; #ifdef HasLCMS - (void) sprintf(lcms_vers,"%.4d",LCMS_VERSION); + (void) sprintf(lcms_vers,"%.4d",LCMS_VERSION); #endif - libpng_runv=png_get_libpng_ver(NULL); - libpng_vers=PNG_LIBPNG_VER_STRING; - zlib_runv=zlib_version; - zlib_vers=ZLIB_VERSION; + libpng_runv=png_get_libpng_ver(NULL); + libpng_vers=PNG_LIBPNG_VER_STRING; + zlib_runv=zlib_version; + zlib_vers=ZLIB_VERSION; if (logging != MagickFalse) { @@ -8536,17 +8587,22 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_info, PNGType(chunk,mng_eXIf); if (length < 7) - break; /* othewise crashes */ + break; /* otherwise crashes */ - /* skip the "Exif\0\0" JFIF Exif Header ID */ - length -= 6; + if (data[0] == 'E' && data[1] == 'x' && data[2] == 'i' && + data[3] == 'f' && data[4] == '\0' && data[5] == '\0') + { + /* skip the optional Exif identifier code ("Exif\0\0") */ + length -= 6; + data += 6; + } LogPNGChunk(logging,chunk,length); (void) WriteBlobMSBULong(image,length); (void) WriteBlob(image,4,chunk); - (void) WriteBlob(image,length,data+6); + (void) WriteBlob(image,length,data); (void) WriteBlobMSBULong(image,crc32(crc32(0,chunk,4), - data+6, (uInt) length)); + data, (uInt) length)); break; } } |