size_t
file_size;
- ExceptionInfo
- *exception;
+ size_t
+ number_layers;
} XCFDocInfo;
typedef struct
MagickOffsetType
size;
+ Quantum
+ alpha;
+
register Quantum
*q;
xcfodata=xcfdata;
count=ReadBlob(image, (size_t) data_length, xcfdata);
xcfdatalimit = xcfodata+count-1;
+ alpha=ScaleCharToQuantum((unsigned char) inLayerInfo->alpha);
for (i=0; i < (ssize_t) bytes_per_pixel; i++)
{
- q=GetAuthenticPixels(tile_image,0,0,tile_image->columns,tile_image->rows,
+ q=QueueAuthenticPixels(tile_image,0,0,tile_image->columns,tile_image->rows,
exception);
+ if (q == (Quantum *) NULL)
+ continue;
size=(MagickOffsetType) tile_image->rows*tile_image->columns;
while (size > 0)
{
SetPixelRed(tile_image,ScaleCharToQuantum(data),q);
SetPixelGreen(tile_image,ScaleCharToQuantum(data),q);
SetPixelBlue(tile_image,ScaleCharToQuantum(data),q);
- SetPixelAlpha(tile_image,ScaleCharToQuantum(
- (unsigned char) inLayerInfo->alpha),q);
+ SetPixelAlpha(tile_image,data == 255U ? alpha :
+ ScaleCharToQuantum(data),q);
}
else
{
SetPixelGray(tile_image,ScaleCharToQuantum(data),q);
- SetPixelAlpha(tile_image,ScaleCharToQuantum(
- (unsigned char) inLayerInfo->alpha),q);
+ SetPixelAlpha(tile_image,data == 255U ? alpha :
+ ScaleCharToQuantum(data),q);
}
break;
}
}
case 3:
{
- SetPixelAlpha(tile_image,data == 0U ? TransparentAlpha :
- ScaleCharToQuantum((unsigned char) inLayerInfo->alpha),q);
+ SetPixelAlpha(tile_image,data == 255U ? alpha :
+ ScaleCharToQuantum(data),q);
break;
}
}
if (xcfdata > xcfdatalimit)
goto bogus_rle;
pixel=(*xcfdata++);
- for (j= 0; j < (ssize_t) length; j++)
+ for (j=0; j < (ssize_t) length; j++)
{
data=pixel;
switch (i)
SetPixelRed(tile_image,ScaleCharToQuantum(data),q);
SetPixelGreen(tile_image,ScaleCharToQuantum(data),q);
SetPixelBlue(tile_image,ScaleCharToQuantum(data),q);
- SetPixelAlpha(tile_image,ScaleCharToQuantum(
- (unsigned char) inLayerInfo->alpha),q);
+ SetPixelAlpha(tile_image,data == 255U ? alpha :
+ ScaleCharToQuantum(data),q);
}
else
{
SetPixelGray(tile_image,ScaleCharToQuantum(data),q);
- SetPixelAlpha(tile_image,ScaleCharToQuantum(
- (unsigned char) inLayerInfo->alpha),q);
+ SetPixelAlpha(tile_image,data == 255U ? alpha :
+ ScaleCharToQuantum(data),q);
}
break;
}
}
case 3:
{
- SetPixelAlpha(tile_image,data == 0U ? TransparentAlpha :
- ScaleCharToQuantum((unsigned char) inLayerInfo->alpha),q);
+ SetPixelAlpha(tile_image,data == 255U ? alpha :
+ ScaleCharToQuantum(data),q);
break;
}
}
}
static MagickBooleanType load_level(Image *image,XCFDocInfo *inDocInfo,
- XCFLayerInfo *inLayerInfo)
+ XCFLayerInfo *inLayerInfo,ExceptionInfo *exception)
{
- ExceptionInfo
- *exception;
-
int
destLeft = 0,
destTop = 0;
tile_image_height;
/* start reading the data */
- exception=inDocInfo->exception;
width=ReadBlobMSBLong(image);
height=ReadBlobMSBLong(image);
}
static MagickBooleanType load_hierarchy(Image *image,XCFDocInfo *inDocInfo,
- XCFLayerInfo *inLayer)
+ XCFLayerInfo *inLayer, ExceptionInfo *exception)
{
MagickOffsetType
saved_pos,
offset=SeekBlob(image, offset, SEEK_SET);
/* read in the level */
- if (load_level (image, inDocInfo, inLayer) == 0)
+ if (load_level (image, inDocInfo, inLayer, exception) == 0)
return(MagickFalse);
/* restore the saved position so we'll be ready to
* read the next offset.
return(MagickTrue);
}
-static MagickBooleanType ReadOneLayer(Image* image,XCFDocInfo* inDocInfo,
- XCFLayerInfo *outLayer, ExceptionInfo *exception )
+static MagickBooleanType ReadOneLayer(const ImageInfo *image_info,Image* image,
+ XCFDocInfo* inDocInfo,XCFLayerInfo *outLayer,const ssize_t layer,
+ ExceptionInfo *exception )
{
MagickOffsetType
offset;
outLayer->type = ReadBlobMSBLong(image);
(void) ReadBlobStringWithLongSize(image, outLayer->name,
sizeof(outLayer->name),exception);
- /* allocate the image for this layer */
- outLayer->image=CloneImage(image,outLayer->width, outLayer->height,MagickTrue,
- exception);
- if (outLayer->image == (Image *) NULL)
- return MagickFalse;
/* read the layer properties! */
foundPropEnd = 0;
while ( (foundPropEnd == MagickFalse) && (EOFBlob(image) == MagickFalse) ) {
if (foundPropEnd == MagickFalse)
return(MagickFalse);
+ /* allocate the image for this layer */
+ if (image_info->number_scenes != 0)
+ {
+ ssize_t
+ scene;
+
+ scene=inDocInfo->number_layers-layer-1;
+ if (scene > (image_info->scene+image_info->number_scenes-1))
+ {
+ outLayer->image=CloneImage(image,0,0,MagickTrue,exception);
+ return(MagickTrue);
+ }
+ }
+ outLayer->image=CloneImage(image,outLayer->width, outLayer->height,MagickTrue,
+ exception);
+ if (outLayer->image == (Image *) NULL)
+ return MagickFalse;
/* clear the image based on the layer opacity */
outLayer->image->background_color.alpha=
ScaleCharToQuantum((unsigned char) outLayer->alpha);
if (offset < 0)
(void) ThrowMagickException(exception,GetMagickModule(),
CorruptImageError,"InvalidImageHeader","`%s'",image->filename);
- if (load_hierarchy (image, inDocInfo, outLayer) == 0)
+ if (load_hierarchy (image, inDocInfo, outLayer, exception) == 0)
return(MagickFalse);
/* read in the layer mask */
%
% o exception: return any errors or warnings in this structure.
%
-%
*/
static Image *ReadXCFImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
(LocaleNCompare((char *) magick,"gimp xcf",8) != 0))
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
(void) ResetMagickMemory(&doc_info,0,sizeof(XCFDocInfo));
- doc_info.exception=exception;
doc_info.width=ReadBlobMSBLong(image);
doc_info.height=ReadBlobMSBLong(image);
if ((doc_info.width > 262144) || (doc_info.height > 262144))
break;
}
} while (foundAllLayers == MagickFalse);
+ doc_info.number_layers=number_layers;
offset=SeekBlob(image,oldPos,SEEK_SET); /* restore the position! */
if (offset < 0)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
/* seek to the layer offset */
offset=SeekBlob(image,offset,SEEK_SET);
/* read in the layer */
- layer_ok=ReadOneLayer(image,&doc_info,&layer_info[current_layer],
- exception);
+ layer_ok=ReadOneLayer(image_info,image,&doc_info,
+ &layer_info[current_layer],current_layer,exception);
if (layer_ok == MagickFalse)
{
int j;
for (j=0; j < current_layer; j++)
layer_info[j].image=DestroyImage(layer_info[j].image);
- ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
- }
+ layer_info=(XCFLayerInfo *) RelinquishMagickMemory(layer_info);
+ ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+ }
/* restore the saved position so we'll be ready to
* read the next offset.
*/