size_t
file_size;
- ExceptionInfo
- *exception;
+ size_t
+ number_layers;
} XCFDocInfo;
typedef struct
image->filename);
for (y=0; y < (ssize_t) tile_image->rows; y++)
{
- q=QueueAuthenticPixels(tile_image,0,y,tile_image->columns,1,exception);
+ q=GetAuthenticPixels(tile_image,0,y,tile_image->columns,1,exception);
if (q == (Quantum *) NULL)
break;
if (inDocInfo->image_type == GIMP_GRAY)
SetPixelRed(tile_image,ScaleCharToQuantum(xcfdata->red),q);
SetPixelGreen(tile_image,ScaleCharToQuantum(xcfdata->green),q);
SetPixelBlue(tile_image,ScaleCharToQuantum(xcfdata->blue),q);
- SetPixelAlpha(tile_image,xcfdata->alpha == 0U ? OpaqueAlpha :
+ SetPixelAlpha(tile_image,xcfdata->alpha == 255U ? TransparentAlpha :
ScaleCharToQuantum((unsigned char) inLayerInfo->alpha),q);
xcfdata++;
q+=GetPixelChannels(tile_image);
MagickOffsetType
size;
+ Quantum
+ alpha;
+
register Quantum
*q;
xcfodata=xcfdata;
count=ReadBlob(image, (size_t) data_length, xcfdata);
xcfdatalimit = xcfodata+count-1;
- exception=(exception);
+ 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,
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 == 0 ? OpaqueAlpha :
- 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 == 0 ? OpaqueAlpha :
- 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);
/* composite the tile onto the layer's image, and then destroy it */
(void) CompositeImage(inLayerInfo->image,tile_image,CopyCompositeOp,
- MagickTrue,destLeft*TILE_WIDTH,destTop*TILE_HEIGHT,exception);
+ MagickTrue,destLeft * TILE_WIDTH,destTop*TILE_HEIGHT,exception);
tile_image=DestroyImage(tile_image);
/* adjust tile position */
}
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);
+ if (outLayer->image == (Image *) NULL)
+ return(MagickFalse);
+ outLayer->image->page.x=outLayer->offset_x;
+ outLayer->image->page.y=outLayer->offset_y;
+ outLayer->image->page.width=outLayer->width;
+ outLayer->image->page.height=outLayer->height;
+ 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) (255-outLayer->alpha));
+ ScaleCharToQuantum((unsigned char) outLayer->alpha);
(void) SetImageBackgroundColor(outLayer->image,exception);
+ outLayer->image->page.x=outLayer->offset_x;
+ outLayer->image->page.y=outLayer->offset_y;
+ outLayer->image->page.width=outLayer->width;
+ outLayer->image->page.height=outLayer->height;
/* set the compositing mode */
outLayer->image->compose = GIMPBlendModeToCompositeOperator( outLayer->mode );
if ( outLayer->visible == MagickFalse )
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 */
return MagickTrue;
}
-
+\f
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
%
% 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))
else
if (image_type == GIMP_INDEXED)
ThrowReaderException(CoderError,"ColormapTypeNotSupported");
+ (void) SetImageBackgroundColor(image,exception);
image->matte=MagickTrue;
/*
Read properties.
/*BOGUS: ignored for now */
/*float factor = (float) */ (void) ReadBlobMSBLong(image);
/* size_t digits = */ (void) ReadBlobMSBLong(image);
- for (i=0; i < 5; i++)
- (void) ReadBlobStringWithLongSize(image,unit_string,
+ for (i=0; i<5; i++)
+ (void) ReadBlobStringWithLongSize(image, unit_string,
sizeof(unit_string),exception);
}
break;
else
{
int
- number_layers = 0,
- num_layers = 0,
current_layer = 0,
- first_layer = 0,
- last_layer = 0,
- last = 0,
- foundAllLayers = MagickFalse;
+ foundAllLayers = MagickFalse,
+ number_layers = 0;
MagickOffsetType
- oldPos;
+ oldPos=TellBlob(image);
XCFLayerInfo
*layer_info;
/*
the read pointer
*/
- oldPos=TellBlob(image);
do
{
ssize_t offset = (int) ReadBlobMSBLong(image);
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");
- first_layer=image_info->scene;
- num_layers=number_layers;
- /* number_scenes==0 means read all the images */
- if ((image_info->number_scenes > 0) &&
- (image_info->number_scenes < number_layers))
- num_layers=image_info->scene;
- last_layer=first_layer+num_layers-1;
-
- /* XCF has layers backwards. */
- last=last_layer;
- last_layer=number_layers-first_layer - 1;
- first_layer=number_layers-last-1;
- number_layers=num_layers;
-
/* allocate our array of layer info blocks */
length=(size_t) number_layers;
layer_info=(XCFLayerInfo *) AcquireQuantumMemory(length,
* next layer offset is stored.
*/
saved_pos=TellBlob(image);
- if ((first_layer <= current_layer) && (current_layer <= last_layer))
+ /* seek to the layer offset */
+ offset=SeekBlob(image,offset,SEEK_SET);
+ /* read in the layer */
+ layer_ok=ReadOneLayer(image_info,image,&doc_info,
+ &layer_info[current_layer],current_layer,exception);
+ if (layer_ok == MagickFalse)
{
- /* 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);
- if (layer_ok == MagickFalse)
- {
- int j;
-
- for (j=0; j < current_layer; j++)
- layer_info[j].image=DestroyImage(layer_info[j].image);
- layer_info=(XCFLayerInfo *) RelinquishMagickMemory(layer_info);
- ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
- }
- /* restore the saved position so we'll be ready to
- * read the next offset.
- */
- offset=SeekBlob(image, saved_pos, SEEK_SET);
+ int j;
+
+ for (j=0; j < current_layer; j++)
+ layer_info[j].image=DestroyImage(layer_info[j].image);
+ layer_info=(XCFLayerInfo *) RelinquishMagickMemory(layer_info);
+ ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
}
- current_layer++;
- }
+ /* restore the saved position so we'll be ready to
+ * read the next offset.
+ */
+ offset=SeekBlob(image, saved_pos, SEEK_SET);
+ current_layer++;
+ }
if (number_layers == 1)
{
/*
*/
(void) CompositeImage(image,layer_info[0].image,OverCompositeOp,
MagickTrue,layer_info[0].offset_x,layer_info[0].offset_y,exception);
- layer_info[0].image=DestroyImage( layer_info[0].image);
+ layer_info[0].image =DestroyImage( layer_info[0].image);
}
else
{
/* BOGUS: need to consider layer blending modes!! */
if ( layer_info[j].visible ) { /* only visible ones, please! */
- CompositeImage(image, layer_info[j].image, OverCompositeOp,
- MagickTrue, layer_info[j].offset_x, layer_info[j].offset_y );
+ CompositeImage(image, OverCompositeOp, layer_info[j].image,
+ layer_info[j].offset_x, layer_info[j].offset_y );
layer_info[j].image =DestroyImage( layer_info[j].image );
- /* If we do this, we'll get REAL gray images! */
+ /* If we do this, we'll get REAL gray images! */
if ( image_type == GIMP_GRAY ) {
QuantizeInfo qi;
GetQuantizeInfo(&qi);
#else
{
/* NOTE: XCF layers are REVERSED from composite order! */
- signed int j;
+ ssize_t j;
/* first we copy the last layer on top of the main image */
(void) CompositeImage(image,layer_info[number_layers-1].image,
CopyCompositeOp,MagickTrue,layer_info[number_layers-1].offset_x,
layer_info[number_layers-1].offset_y,exception);
- layer_info[number_layers-1].image=DestroyImage(
- layer_info[number_layers-1].image);
+ layer_info[number_layers-1].image=DestroyImage(
+ layer_info[number_layers-1].image);
/* now reverse the order of the layers as they are put
into subimages
*/
- image->next=layer_info[number_layers-2].image;
- layer_info[number_layers-2].image->previous=image;
- for (j=number_layers-2; j>=0; j--)
- {
- if (j > 0)
- layer_info[j].image->next=layer_info[j-1].image;
- if (j < (number_layers-1))
- layer_info[j].image->previous=layer_info[j+1].image;
- layer_info[j].image->page.x = layer_info[j].offset_x;
- layer_info[j].image->page.y = layer_info[j].offset_y;
- layer_info[j].image->page.width = layer_info[j].width;
- layer_info[j].image->page.height = layer_info[j].height;
- }
+ for (j=(ssize_t) number_layers-2; j >= 0; j--)
+ AppendImageToList(&image,layer_info[j].image);
}
#endif
}