From: Dirk Lemstra Date: Sat, 23 Sep 2017 10:57:11 +0000 (+0200) Subject: Corrected fix for writing multiple layers from the tiff writer. X-Git-Tag: 7.0.7-4~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1d0e549c1202828b10805ec47cb86b63d9ac5004;p=imagemagick Corrected fix for writing multiple layers from the tiff writer. --- diff --git a/coders/psd.c b/coders/psd.c index 12924ec22..a7f09b23b 100644 --- a/coders/psd.c +++ b/coders/psd.c @@ -3116,6 +3116,7 @@ static MagickBooleanType WritePSDLayersInternal(Image *image, *info; Image + *base_image, *next_image; MagickBooleanType @@ -3137,11 +3138,14 @@ static MagickBooleanType WritePSDLayersInternal(Image *image, size; status=MagickTrue; + base_image=GetNextImageInList(image); + if (base_image == (Image *) NULL) + base_image=image; size=0; size_offset=TellBlob(image); SetPSDSize(psd_info,image,0); layer_count=0; - for (next_image=image; next_image != NULL; ) + for (next_image=base_image; next_image != NULL; ) { layer_count++; next_image=GetNextImageInList(next_image); @@ -3155,7 +3159,7 @@ static MagickBooleanType WritePSDLayersInternal(Image *image, if (layer_size_offsets == (MagickOffsetType *) NULL) ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); layer_index=0; - for (next_image=image; next_image != NULL; ) + for (next_image=base_image; next_image != NULL; ) { Image *mask; @@ -3263,7 +3267,7 @@ static MagickBooleanType WritePSDLayersInternal(Image *image, /* Now the image data! */ - next_image=image; + next_image=base_image; layer_index=0; while (next_image != NULL) { @@ -3292,7 +3296,7 @@ static MagickBooleanType WritePSDLayersInternal(Image *image, /* Remove the opacity mask from the registry */ - next_image=image; + next_image=base_image; while (next_image != (Image *) NULL) { property=GetImageArtifact(next_image,"psd:opacity-mask"); @@ -3486,9 +3490,6 @@ static MagickBooleanType WritePSDImage(const ImageInfo *image_info, } if (status != MagickFalse) { - Image - *base_image; - MagickOffsetType size_offset; @@ -3497,10 +3498,7 @@ static MagickBooleanType WritePSDImage(const ImageInfo *image_info, size_offset=TellBlob(image); SetPSDSize(&psd_info,image,0); - base_image=GetNextImageInList(image); - if (base_image == (Image *) NULL) - base_image=image; - status=WritePSDLayersInternal(base_image,image_info,&psd_info,&size, + status=WritePSDLayersInternal(image,image_info,&psd_info,&size, exception); size_offset+=WritePSDSize(&psd_info,image,size+ (psd_info.version == 1 ? 8 : 16),size_offset); diff --git a/coders/tiff.c b/coders/tiff.c index edef96741..ea4cdde6c 100644 --- a/coders/tiff.c +++ b/coders/tiff.c @@ -3092,6 +3092,7 @@ static MagickBooleanType TIFFWritePhotoshopLayers(Image* image, *custom_stream; Image + *base_image, *next; ImageInfo @@ -3109,8 +3110,8 @@ static MagickBooleanType TIFFWritePhotoshopLayers(Image* image, StringInfo *layers; - next=image->next; - if (next == (Image *) NULL) + base_image=CloneImage(image,0,0,MagickFalse,exception); + if (base_image == (Image *) NULL) return(MagickTrue); clone_info=CloneImageInfo(image_info); if (clone_info == (ImageInfo *) NULL) @@ -3144,24 +3145,25 @@ static MagickBooleanType TIFFWritePhotoshopLayers(Image* image, ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed", image->filename); } - DestroyBlob(next); - next->blob=blob; + DestroyBlob(base_image); + base_image->blob=blob; + next=base_image; while (next != (Image *) NULL) next=SyncNextImageInList(next); - next=image->next; - AttachCustomStream(next->blob,custom_stream); + AttachCustomStream(base_image->blob,custom_stream); InitPSDInfo(image,&info); - if (next->endian == UndefinedEndian) - next->endian=(HOST_FILLORDER == FILLORDER_LSB2MSB) ? LSBEndian : MSBEndian; + if (base_image->endian == UndefinedEndian) + base_image->endian=(HOST_FILLORDER == FILLORDER_LSB2MSB) ? LSBEndian : MSBEndian; WriteBlobString(next,"Adobe Photoshop Document Data Block"); - WriteBlobByte(next,0); - WriteBlobString(next,next->endian == LSBEndian ? "MIB8ryaL" : "8BIMLayr"); - status=WritePSDLayers(next,clone_info,&info,exception); + WriteBlobByte(base_image,0); + WriteBlobString(base_image,base_image->endian == LSBEndian ? "MIB8ryaL" : "8BIMLayr"); + status=WritePSDLayers(base_image,clone_info,&info,exception); if (status != MagickFalse) { SetStringInfoLength(layers,(size_t) profile.offset); status=SetImageProfile(image,"tiff:37724",layers,exception); } + next=base_image; while (next != (Image *) NULL) { CloseBlob(next);