break;
}
+
case 2:
{
for (x=(ssize_t) image->columns-3; x > 0; x-=4)
break;
}
+
case 4:
{
for (x=(ssize_t) image->columns-1; x > 0; x-=2)
break;
}
+
case 8:
{
if (ping_color_type == 4)
break;
}
+
case 16:
{
for (x=(ssize_t) image->columns-1; x >= 0; x--)
quantum|=(*p++);
*r=(Quantum) quantum;
r++;
+
if (ping_color_type == 4)
{
quantum=((*p++) << 8);
p+=2;
q++;
}
+
#else /* MAGICKCORE_QUANTUM_DEPTH == 8 */
*r++=(*p++);
p++; /* strip low byte */
+
if (ping_color_type == 4)
{
q->opacity=(Quantum) (QuantumRange-(*p++));
#endif
#endif
}
+
break;
}
+
default:
break;
}
{
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
image->rows);
+
if (status == MagickFalse)
break;
}
if ((image->previous == (Image *) NULL) && (num_passes != 1))
{
status=SetImageProgress(image,LoadImageTag,pass,num_passes);
+
if (status == MagickFalse)
break;
}
(void) SyncImage(image);
image->matte=matte;
}
+
png_read_end(ping,ping_info);
if (image_info->number_scenes != 0 && mng_info->scenes_found-1 <
" exit ReadOnePNGImage() early.");
return(image);
}
+
if (png_get_valid(ping,ping_info,PNG_INFO_tRNS))
{
ClassType
ScaleCharToQuantum((unsigned char)(255-ping_trans_alpha[x]));
}
}
+
else if (ping_color_type == PNG_COLOR_TYPE_GRAY)
{
for (x=0; x < (int) image->colors; x++)
}
(void) SyncImage(image);
}
+
else
{
for (y=0; y < (ssize_t) image->rows; y++)
q++;
}
+
else if (ping_color_type == PNG_COLOR_TYPE_GRAY)
for (x=0; x < (ssize_t) image->columns; x++)
{
q++;
}
+
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
if ((ping_color_type == PNG_COLOR_TYPE_GRAY) ||
(ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
image->colorspace=GRAYColorspace;
+
if (png_get_text(ping,ping_info,&text,&num_text) != 0)
for (i=0; i < (ssize_t) num_text; i++)
{
mng_info->ob[object_id]->reference_count=1;
}
}
+
if ((mng_info->ob[object_id] == (MngBuffer *) NULL) ||
mng_info->ob[object_id]->frozen)
{
mng_info->ob[object_id]->plte[i]=plte[i];
}
}
+
else
mng_info->ob[object_id]->plte_length=0;
}
*/
assert(image_info != (const ImageInfo *) NULL);
assert(image_info->signature == MagickSignature);
+
if (image_info->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
image_info->filename);
+
assert(exception != (ExceptionInfo *) NULL);
assert(exception->signature == MagickSignature);
logging=LogMagickEvent(CoderEvent,GetMagickModule(),"enter ReadPNGImage()");
image=AcquireImage(image_info);
mng_info=(MngInfo *) NULL;
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
+
if (status == MagickFalse)
ThrowReaderException(FileOpenError,"UnableToOpenFile");
+
/*
Verify PNG signature.
*/
count=ReadBlob(image,8,(unsigned char *) magic_number);
+
if (memcmp(magic_number,"\211PNG\r\n\032\n",8) != 0)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
+
/*
Allocate a MngInfo structure.
*/
have_mng_structure=MagickFalse;
mng_info=(MngInfo *) AcquireMagickMemory(sizeof(MngInfo));
+
if (mng_info == (MngInfo *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+
/*
Initialize members of the MngInfo structure.
*/
previous=image;
image=ReadOnePNGImage(mng_info,image_info,exception);
MngInfoFreeStruct(mng_info,&have_mng_structure);
+
if (image == (Image *) NULL)
{
if (previous != (Image *) NULL)
return((Image *) NULL);
}
+
(void) CloseBlob(image);
+
if ((image->columns == 0) || (image->rows == 0))
{
if (logging != MagickFalse)
ThrowReaderException(CorruptImageError,"CorruptImage");
}
+
if (LocaleCompare(image_info->magick,"PNG8") == 0)
{
(void) SetImageType(image,PaletteType);
/* To do: Reduce to binary transparency */
}
}
+
if (LocaleCompare(image_info->magick,"PNG24") == 0)
{
(void) SetImageType(image,TrueColorType);
p=NULL;
chunk=(unsigned char *) NULL;
+
if (length)
{
chunk=(unsigned char *) AcquireQuantumMemory(length,sizeof(*chunk));
p=chunk;
}
+
(void) ReadBlobMSBLong(image); /* read crc word */
if (skip_to_iend)
{
if (length)
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
+
continue;
}
jng_image_sample_depth=p[9];
jng_image_compression_method=p[10];
jng_image_interlace_method=p[11];
+
image->interlace=jng_image_interlace_method != 0 ? PNGInterlace :
NoInterlace;
+
jng_alpha_sample_depth=p[12];
jng_alpha_compression_method=p[13];
jng_alpha_filter_method=p[14];
jng_alpha_interlace_method=p[15];
+
if (logging != MagickFalse)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" jng_width: %16lu",(unsigned long) jng_width);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" jng_width: %16lu",(unsigned long) jng_height);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" jng_color_type: %16d",jng_color_type);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" jng_image_sample_depth: %3d",
jng_image_sample_depth);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" jng_image_compression_method:%3d",
jng_image_compression_method);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" jng_image_interlace_method: %3d",
jng_image_interlace_method);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" jng_alpha_sample_depth: %3d",
jng_alpha_sample_depth);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" jng_alpha_compression_method:%3d",
jng_alpha_compression_method);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" jng_alpha_filter_method: %3d",
jng_alpha_filter_method);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" jng_alpha_interlace_method: %3d",
jng_alpha_interlace_method);
}
}
+
if (length)
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
+
continue;
}
*/
color_image_info=(ImageInfo *)AcquireMagickMemory(sizeof(ImageInfo));
+
if (color_image_info == (ImageInfo *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+
GetImageInfo(color_image_info);
color_image=AcquireImage(color_image_info);
if (memcmp(type,mng_JDAT,4) == 0)
{
- /*
- Copy chunk to color_image->blob
- */
+ /* Copy chunk to color_image->blob */
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Copying JDAT chunk data to color_blob.");
(void) WriteBlob(color_image,length,chunk);
+
if (length)
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
+
continue;
}
png_byte
data[5];
- /*
- Copy IDAT header and chunk data to alpha_image->blob
- */
+ /* Copy IDAT header and chunk data to alpha_image->blob */
if (image_info->ping == MagickFalse)
{
if ((memcmp(type,mng_JDAA,4) == 0) || (memcmp(type,mng_JdAA,4) == 0))
{
- /*
- Copy chunk data to alpha_image->blob
- */
+ /* Copy chunk data to alpha_image->blob */
if (image_info->ping == MagickFalse)
{
image->chromaticity.blue_primary.x=0.00001*mng_get_long(&p[24]);
image->chromaticity.blue_primary.y=0.00001*mng_get_long(&p[28]);
}
+
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
continue;
}
image->chromaticity.white_point.x=0.3127f;
image->chromaticity.white_point.y=0.3290f;
}
+
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
continue;
}
image->page.y/=10000;
}
}
+
if (length)
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
*/
(void) CloseBlob(color_image);
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Reading jng_image from color_blob.");
s=GetVirtualPixels(jng_image,0,y,image->columns,1,&image->exception);
q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
(void) CopyMagickMemory(q,s,length);
+
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
s=GetVirtualPixels(jng_image,0,y,image->columns,1,
&image->exception);
q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
+
if (image->matte != MagickFalse)
for (x=(ssize_t) image->columns; x != 0; x--,q++,s++)
q->opacity=(Quantum) QuantumRange-s->red;
}
}
- /*
- Read the JNG image.
- */
+ /* Read the JNG image. */
+
if (mng_info->mng_type == 0)
{
mng_info->mng_width=jng_width;
if (LocaleCompare(image_info->magick,"JNG") != 0)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
- /*
- Verify JNG signature.
- */
+ /* Verify JNG signature. */
+
count=(size_t) ReadBlob(image,8,(unsigned char *) magic_number);
+
if (memcmp(magic_number,"\213JNG\r\n\032\n",8) != 0)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
- /*
- Allocate a MngInfo structure.
- */
+ /* Allocate a MngInfo structure. */
+
have_mng_structure=MagickFalse;
mng_info=(MngInfo *) AcquireMagickMemory(sizeof(*mng_info));
if (mng_info == (MngInfo *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
- /*
- Initialize members of the MngInfo structure.
- */
+ /* Initialize members of the MngInfo structure. */
+
(void) ResetMagickMemory(mng_info,0,sizeof(MngInfo));
have_mng_structure=MagickTrue;
return((Image *) NULL);
}
(void) CloseBlob(image);
+
if (image->columns == 0 || image->rows == 0)
{
if (logging != MagickFalse)
default_fb.left=0;
default_fb.right=0;
- /*
- Open image file.
- */
+ /* Open image file. */
+
assert(image_info != (const ImageInfo *) NULL);
assert(image_info->signature == MagickSignature);
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image_info->filename);
first_mng_object=MagickFalse;
skipping_loop=(-1);
have_mng_structure=MagickFalse;
- /*
- Allocate a MngInfo structure.
- */
+
+ /* Allocate a MngInfo structure. */
+
mng_info=(MngInfo *) AcquireMagickMemory(sizeof(MngInfo));
if (mng_info == (MngInfo *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
- /*
- Initialize members of the MngInfo structure.
- */
+ /* Initialize members of the MngInfo structure. */
+
(void) ResetMagickMemory(mng_info,0,sizeof(MngInfo));
mng_info->image=image;
have_mng_structure=MagickTrue;
char
magic_number[MaxTextExtent];
- /*
- Verify MNG signature.
- */
+ /* Verify MNG signature. */
count=(size_t) ReadBlob(image,8,(unsigned char *) magic_number);
if (memcmp(magic_number,"\212MNG\r\n\032\n",8) != 0)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
- /*
- Initialize some nonzero members of the MngInfo structure.
- */
+
+ /* Initialize some nonzero members of the MngInfo structure. */
for (i=0; i < MNG_MAX_OBJECTS; i++)
{
mng_info->object_clip[i].right=(ssize_t) PNG_UINT_31_MAX;
}
mng_info->exists[0]=MagickTrue;
}
+
first_mng_object=MagickTrue;
mng_type=0;
#if defined(MNG_INSERT_LAYERS)
if (length)
{
chunk=(unsigned char *) AcquireQuantumMemory(length,sizeof(*chunk));
+
if (chunk == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+
for (i=0; i < (ssize_t) length; i++)
chunk[i]=(unsigned char) ReadBlobByte(image);
+
p=chunk;
}
}
if (memcmp(type,mng_MEND,4) == 0)
break;
+
if (skip_to_iend)
{
if (memcmp(type,mng_IEND,4) == 0)
#endif
if (GetAuthenticPixelQueue(image) != (PixelPacket *) NULL)
{
- /*
- Allocate next image structure.
- */
+ /* Allocate next image structure. */
AcquireNextImage(image_info,image);
if (GetNextImageInList(image) == (Image *) NULL)
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
continue;
}
+
if (memcmp(type,mng_PLTE,4) == 0)
{
- /*
- Read global PLTE.
- */
+ /* Read global PLTE. */
+
if (length && (length < 769))
{
if (mng_info->global_plte == (png_colorp) NULL)
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
continue;
}
+
if (memcmp(type,mng_tRNS,4) == 0)
{
/* read global tRNS */
if (memcmp(type,mng_cHRM,4) == 0)
{
- /*
- Read global cHRM
- */
+ /* Read global cHRM */
+
if (length == 32)
{
mng_info->global_chrm.white_point.x=0.00001*mng_get_long(p);
}
else
mng_info->have_global_chrm=MagickFalse;
+
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
continue;
}
+
if (memcmp(type,mng_sRGB,4) == 0)
{
/*
}
else
mng_info->have_global_srgb=MagickFalse;
+
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
continue;
}
+
if (memcmp(type,mng_iCCP,4) == 0)
{
/* To do. */
*/
if (length)
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
+
continue;
}
+
if (memcmp(type,mng_FRAM,4) == 0)
{
if (mng_type == 3)
frame_delay=default_frame_delay;
frame_timeout=default_frame_timeout;
fb=default_fb;
+
if (length)
if (p[0])
mng_info->framing_mode=p[0];
if (length > 6)
{
- /*
- Note the delay and frame clipping boundaries.
- */
+ /* Note the delay and frame clipping boundaries. */
+
p++; /* framing mode */
+
while (*p && ((p-chunk) < (ssize_t) length))
p++; /* frame name */
+
p++; /* frame name terminator */
+
if ((p-chunk) < (ssize_t) (length-4))
{
int
change_timeout=(*p++);
change_clipping=(*p++);
p++; /* change_sync */
+
if (change_delay)
{
frame_delay=1UL*image->ticks_per_second*
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Framing_delay=%.20g",(double) frame_delay);
}
+
if (change_timeout)
{
frame_timeout=1UL*image->ticks_per_second*
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Framing_timeout=%.20g",(double) frame_timeout);
}
+
if (change_clipping)
{
fb=mng_read_box(previous_fb,(char) p[0],&p[1]);
" Frame_clip: L=%.20g R=%.20g T=%.20g B=%.20g",
(double) fb.left,(double) fb.right,(double) fb.top,
(double) fb.bottom);
+
if (change_clipping == 2)
default_fb=fb;
}
if (insert_layers && (mng_info->framing_mode == 4) &&
(subframe_width) && (subframe_height))
{
- /*
- Allocate next image structure.
- */
+ /* Allocate next image structure. */
if (GetAuthenticPixelQueue(image) != (PixelPacket *) NULL)
{
AcquireNextImage(image_info,image);
+
if (GetNextImageInList(image) == (Image *) NULL)
{
image=DestroyImageList(image);
MngInfoFreeStruct(mng_info,&have_mng_structure);
return((Image *) NULL);
}
+
image=SyncNextImageInList(image);
}
*/
first_object=(p[0] << 8) | p[1];
last_object=(p[2] << 8) | p[3];
+
for (i=(int) first_object; i <= (int) last_object; i++)
{
if (mng_info->exists[i] && !mng_info->frozen[i])
mng_info->object_clip[i]=mng_read_box(box,(char) p[4],&p[5]);
}
}
+
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
continue;
}
if ((memcmp(type,mng_DISC,4) == 0) || (memcmp(type,mng_SEEK,4) == 0))
{
- /*
- Read DISC or SEEK.
- */
+ /* Read DISC or SEEK. */
+
if ((length == 0) || !memcmp(type,mng_SEEK,4))
{
for (i=1; i < MNG_MAX_OBJECTS; i++)
continue;
}
+
if (memcmp(type,mng_MOVE,4) == 0)
{
size_t
first_object,
last_object;
- /*
- read MOVE
- */
+ /* read MOVE */
+
first_object=(p[0] << 8) | p[1];
last_object=(p[2] << 8) | p[3];
for (i=(ssize_t) first_object; i <= (ssize_t) last_object; i++)
mng_info->y_off[i]=new_pair.b;
}
}
+
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
continue;
}
ssize_t loop_iters=1;
loop_level=chunk[0];
mng_info->loop_active[loop_level]=1; /* mark loop active */
- /*
- Record starting point.
- */
+
+ /* Record starting point. */
loop_iters=mng_get_long(&chunk[1]);
if (logging != MagickFalse)
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
continue;
}
+
if (memcmp(type,mng_ENDL,4) == 0)
{
loop_level=chunk[0];
+
if (skipping_loop > 0)
{
if (skipping_loop == loop_level)
mng_info->loop_active[loop_level]=0;
}
}
+
else
{
if (mng_info->loop_active[loop_level] == 1)
" ENDL: LOOP level %.20g has %.20g remaining iters ",
(double) loop_level,(double)
mng_info->loop_count[loop_level]);
+
if (mng_info->loop_count[loop_level] != 0)
{
offset=SeekBlob(image,mng_info->loop_jump[loop_level],
ThrowReaderException(CorruptImageError,
"ImproperImageHeader");
}
+
else
{
short
}
}
}
+
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
continue;
}
+
if (memcmp(type,mng_CLON,4) == 0)
{
if (mng_info->clon_warning == 0)
(void) ThrowMagickException(&image->exception,GetMagickModule(),
CoderError,"CLON is not implemented yet","`%s'",
image->filename);
+
mng_info->clon_warning++;
}
+
if (memcmp(type,mng_MAGN,4) == 0)
{
png_uint_16
GetMagickModule(),CoderError,
"MAGN is not implemented yet for nonzero objects",
"`%s'",image->filename);
+
mng_info->magn_warning++;
}
#endif
if (length > 4)
magn_methx=p[4];
+
else
magn_methx=0;
if (length > 6)
magn_mx=(p[5] << 8) | p[6];
+
else
magn_mx=1;
+
if (magn_mx == 0)
magn_mx=1;
if (length > 8)
magn_my=(p[7] << 8) | p[8];
+
else
magn_my=magn_mx;
+
if (magn_my == 0)
magn_my=1;
if (length > 10)
magn_ml=(p[9] << 8) | p[10];
+
else
magn_ml=magn_mx;
+
if (magn_ml == 0)
magn_ml=1;
if (length > 12)
magn_mr=(p[11] << 8) | p[12];
+
else
magn_mr=magn_mx;
+
if (magn_mr == 0)
magn_mr=1;
if (length > 14)
magn_mt=(p[13] << 8) | p[14];
+
else
magn_mt=magn_my;
+
if (magn_mt == 0)
magn_mt=1;
if (length > 16)
magn_mb=(p[15] << 8) | p[16];
+
else
magn_mb=magn_my;
+
if (magn_mb == 0)
magn_mb=1;
if (length > 17)
magn_methy=p[17];
+
else
magn_methy=magn_methx;
+
if (magn_methx > 5 || magn_methy > 5)
if (mng_info->magn_warning == 0)
{
GetMagickModule(),CoderError,
"Unknown MAGN method in MNG datastream","`%s'",
image->filename);
+
mng_info->magn_warning++;
}
#ifdef MNG_OBJECT_BUFFERS
mng_info->magn_methy=magn_methy;
}
}
+
if (memcmp(type,mng_PAST,4) == 0)
{
if (mng_info->past_warning == 0)
(void) ThrowMagickException(&image->exception,GetMagickModule(),
CoderError,"PAST is not implemented yet","`%s'",
image->filename);
+
mng_info->past_warning++;
}
+
if (memcmp(type,mng_SHOW,4) == 0)
{
if (mng_info->show_warning == 0)
(void) ThrowMagickException(&image->exception,GetMagickModule(),
CoderError,"SHOW is not implemented yet","`%s'",
image->filename);
+
mng_info->show_warning++;
}
+
if (memcmp(type,mng_sBIT,4) == 0)
{
if (length < 4)
mng_info->have_global_sbit=MagickFalse;
+
else
{
mng_info->global_sbit.gray=p[0];
mng_info->global_phys_unit_type=p[8];
mng_info->have_global_phys=MagickTrue;
}
+
else
mng_info->have_global_phys=MagickFalse;
}
if (mng_info->phyg_warning == 0)
(void) ThrowMagickException(&image->exception,GetMagickModule(),
CoderError,"pHYg is not implemented.","`%s'",image->filename);
+
mng_info->phyg_warning++;
}
if (memcmp(type,mng_BASI,4) == 0)
{
skip_to_iend=MagickTrue;
+
if (mng_info->basi_warning == 0)
(void) ThrowMagickException(&image->exception,GetMagickModule(),
CoderError,"BASI is not implemented yet","`%s'",
image->filename);
+
mng_info->basi_warning++;
#ifdef MNG_BASI_SUPPORTED
basi_width=(size_t) ((p[0] << 24) | (p[1] << 16) |
basi_interlace_method=p[11];
if (length > 11)
basi_red=(p[12] << 8) & p[13];
+
else
basi_red=0;
+
if (length > 13)
basi_green=(p[14] << 8) & p[15];
+
else
basi_green=0;
+
if (length > 15)
basi_blue=(p[16] << 8) & p[17];
+
else
basi_blue=0;
+
if (length > 17)
basi_alpha=(p[18] << 8) & p[19];
+
else
{
if (basi_sample_depth == 16)
else
basi_alpha=255;
}
+
if (length > 19)
basi_viewable=p[20];
+
else
basi_viewable=0;
+
#endif
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
continue;
}
+
if (memcmp(type,mng_IHDR,4)
#if defined(JNG_SUPPORTED)
&& memcmp(type,mng_JHDR,4)
/* Not an IHDR or JHDR chunk */
if (length)
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
+
continue;
}
/* Process IHDR */
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Processing %c%c%c%c chunk",type[0],type[1],type[2],type[3]);
+
mng_info->exists[object_id]=MagickTrue;
mng_info->viewable[object_id]=MagickTrue;
+
if (mng_info->invisible[object_id])
{
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Skipping invisible object");
+
skip_to_iend=MagickTrue;
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
continue;
#if defined(MNG_INSERT_LAYERS)
if (length < 8)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
+
image_width=(size_t) mng_get_long(p);
image_height=(size_t) mng_get_long(&p[4]);
#endif
Allocate next image structure.
*/
AcquireNextImage(image_info,image);
+
if (GetNextImageInList(image) == (Image *) NULL)
{
image=DestroyImageList(image);
MngInfoFreeStruct(mng_info,&have_mng_structure);
return((Image *) NULL);
}
+
image=SyncNextImageInList(image);
}
mng_info->image=image;
+
if (term_chunk_found)
{
image->start_loop=MagickTrue;
image->iterations=mng_iterations;
term_chunk_found=MagickFalse;
}
+
else
image->start_loop=MagickFalse;
- /*
- Make a background rectangle.
- */
+
+ /* Make a background rectangle. */
+
image->delay=0;
image->columns=mng_info->mng_width;
image->rows=mng_info->mng_height;
Allocate next image structure.
*/
AcquireNextImage(image_info,image);
+
if (GetNextImageInList(image) == (Image *) NULL)
{
image=DestroyImageList(image);
MngInfoFreeStruct(mng_info,&have_mng_structure);
return((Image *) NULL);
}
+
image=SyncNextImageInList(image);
}
else
image->start_loop=MagickFalse;
+
image->delay=0;
image->columns=subframe_width;
image->rows=subframe_height;
}
#endif /* MNG_INSERT_LAYERS */
first_mng_object=MagickFalse;
+
if (GetAuthenticPixelQueue(image) != (PixelPacket *) NULL)
{
/*
Allocate next image structure.
*/
AcquireNextImage(image_info,image);
+
if (GetNextImageInList(image) == (Image *) NULL)
{
image=DestroyImageList(image);
MngInfoFreeStruct(mng_info,&have_mng_structure);
return((Image *) NULL);
}
+
image=SyncNextImageInList(image);
}
mng_info->image=image;
image->page.x=mng_info->x_off[object_id];
image->page.y=mng_info->y_off[object_id];
image->iterations=mng_iterations;
+
/*
Seek back to the beginning of the IHDR or JHDR chunk's length field.
*/
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Seeking back to beginning of %c%c%c%c chunk",type[0],type[1],
type[2],type[3]);
+
offset=SeekBlob(image,-((ssize_t) length+12),SEEK_CUR);
+
if (offset < 0)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
}
if (memcmp(type,mng_IHDR,4) == 0)
image=ReadOnePNGImage(mng_info,image_info,exception);
+
#if defined(JNG_SUPPORTED)
else
image=ReadOneJNGImage(mng_info,image_info,exception);
(void) DestroyImageList(previous);
(void) CloseBlob(previous);
}
+
MngInfoFreeStruct(mng_info,&have_mng_structure);
return((Image *) NULL);
}
if (mng_info->magn_methx == 1)
{
magnified_width=mng_info->magn_ml;
+
if (image->columns > 1)
magnified_width += mng_info->magn_mr;
+
if (image->columns > 2)
- magnified_width += (png_uint_32) ((image->columns-2)*(mng_info->magn_mx));
+ magnified_width += (png_uint_32)
+ ((image->columns-2)*(mng_info->magn_mx));
}
+
else
{
magnified_width=(png_uint_32) image->columns;
+
if (image->columns > 1)
magnified_width += mng_info->magn_ml-1;
+
if (image->columns > 2)
magnified_width += mng_info->magn_mr-1;
+
if (image->columns > 3)
- magnified_width += (png_uint_32) ((image->columns-3)*(mng_info->magn_mx-1));
+ magnified_width += (png_uint_32)
+ ((image->columns-3)*(mng_info->magn_mx-1));
}
+
if (mng_info->magn_methy == 1)
{
magnified_height=mng_info->magn_mt;
+
if (image->rows > 1)
magnified_height += mng_info->magn_mb;
+
if (image->rows > 2)
- magnified_height += (png_uint_32) ((image->rows-2)*(mng_info->magn_my));
+ magnified_height += (png_uint_32)
+ ((image->rows-2)*(mng_info->magn_my));
}
+
else
{
magnified_height=(png_uint_32) image->rows;
+
if (image->rows > 1)
magnified_height += mng_info->magn_mt-1;
+
if (image->rows > 2)
magnified_height += mng_info->magn_mb-1;
+
if (image->rows > 3)
- magnified_height += (png_uint_32) ((image->rows-3)*(mng_info->magn_my-1));
+ magnified_height += (png_uint_32)
+ ((image->rows-3)*(mng_info->magn_my-1));
}
+
if (magnified_height > image->rows ||
magnified_width > image->columns)
{
magn_methx,
magn_methy;
- /*
- Allocate next image structure.
- */
+ /* Allocate next image structure. */
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Allocate magnified image");
+
AcquireNextImage(image_info,image);
+
if (GetNextImageInList(image) == (Image *) NULL)
{
image=DestroyImageList(image);
{
q=GetAuthenticPixels(image,0,y,image->columns,1,
exception);
+
for (x=(ssize_t) image->columns-1; x >= 0; x--)
{
q->red=ScaleQuantumToShort(q->red);
q->opacity=ScaleQuantumToShort(q->opacity);
q++;
}
+
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
if (image->matte != MagickFalse)
(void) SetImageBackgroundColor(large_image);
+
else
{
large_image->background_color.opacity=OpaqueOpacity;
(void) SetImageBackgroundColor(large_image);
+
if (magn_methx == 4)
magn_methx=2;
+
if (magn_methx == 5)
magn_methx=3;
+
if (magn_methy == 4)
magn_methy=2;
+
if (magn_methy == 5)
magn_methy=3;
}
length=(size_t) image->columns;
next=(PixelPacket *) AcquireQuantumMemory(length,sizeof(*next));
prev=(PixelPacket *) AcquireQuantumMemory(length,sizeof(*prev));
+
if ((prev == (PixelPacket *) NULL) ||
(next == (PixelPacket *) NULL))
{
ThrowReaderException(ResourceLimitError,
"MemoryAllocationFailed");
}
+
n=GetAuthenticPixels(image,0,0,image->columns,1,exception);
(void) CopyMagickMemory(next,n,length);
+
for (y=0; y < (ssize_t) image->rows; y++)
{
if (y == 0)
m=(ssize_t) mng_info->magn_mt;
+
else if (magn_methy > 1 && y == (ssize_t) image->rows-2)
m=(ssize_t) mng_info->magn_mb;
+
else if (magn_methy <= 1 && y == (ssize_t) image->rows-1)
m=(ssize_t) mng_info->magn_mb;
+
else if (magn_methy > 1 && y == (ssize_t) image->rows-1)
m=1;
+
else
m=(ssize_t) mng_info->magn_my;
+
n=prev;
prev=next;
next=n;
+
if (y < (ssize_t) image->rows-1)
{
n=GetAuthenticPixels(image,0,y+1,image->columns,1,
exception);
(void) CopyMagickMemory(next,n,length);
}
+
for (i=0; i < m; i++, yy++)
{
register PixelPacket
q=GetAuthenticPixels(large_image,0,yy,large_image->columns,
1,exception);
q+=(large_image->columns-image->columns);
+
for (x=(ssize_t) image->columns-1; x >= 0; x--)
{
/* TO DO: get color as function of indexes[x] */
{
*q=(*pixels); /* replicate previous */
}
+
else if (magn_methy == 2 || magn_methy == 4)
{
if (i == 0)
*q=(*pixels);
+
else
{
/* Interpolate */
(*q).blue=(QM) (((ssize_t) (2*i*((*n).blue
-(*pixels).blue)+m))/((ssize_t) (m*2))
+(*pixels).blue);
+
if (image->matte != MagickFalse)
(*q).opacity=(QM) (((ssize_t)
(2*i*((*n).opacity
-(*pixels).opacity)+m))
/((ssize_t) (m*2))+(*pixels).opacity);
}
+
if (magn_methy == 4)
{
/* Replicate nearest */
(*q).opacity=(*n).opacity+0;
}
}
+
else /* if (magn_methy == 3 || magn_methy == 5) */
{
/* Replicate nearest */
if (i <= ((m+1) << 1))
*q=(*pixels);
+
else
*q=(*n);
+
if (magn_methy == 5)
{
(*q).opacity=(QM) (((ssize_t) (2*i*((*n).opacity
q++;
pixels++;
} /* x */
+
if (SyncAuthenticPixels(large_image,exception) == 0)
break;
+
} /* i */
} /* y */
+
prev=(PixelPacket *) RelinquishMagickMemory(prev);
next=(PixelPacket *) RelinquishMagickMemory(next);
q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
pixels=q+(image->columns-length);
n=pixels+1;
+
for (x=(ssize_t) (image->columns-length);
x < (ssize_t) image->columns; x++)
{
if (x == (ssize_t) (image->columns-length))
m=(ssize_t) mng_info->magn_ml;
+
else if (magn_methx > 1 && x == (ssize_t) image->columns-2)
m=(ssize_t) mng_info->magn_mr;
+
else if (magn_methx <= 1 && x == (ssize_t) image->columns-1)
m=(ssize_t) mng_info->magn_mr;
+
else if (magn_methx > 1 && x == (ssize_t) image->columns-1)
m=1;
+
else
m=(ssize_t) mng_info->magn_mx;
+
for (i=0; i < m; i++)
{
if (magn_methx <= 1)
/* replicate previous */
*q=(*pixels);
}
+
else if (magn_methx == 2 || magn_methx == 4)
{
if (i == 0)
*q=(*pixels);
+
else
{
/* Interpolate */
-(*pixels).opacity)+m)/((ssize_t) (m*2))
+(*pixels).opacity);
}
+
if (magn_methx == 4)
{
/* Replicate nearest */
(*q).opacity=(*n).opacity+0;
}
}
+
else /* if (magn_methx == 3 || magn_methx == 5) */
{
/* Replicate nearest */
if (i <= ((m+1) << 1))
*q=(*pixels);
+
else
*q=(*n);
+
if (magn_methx == 5)
{
/* Interpolate */
n++;
p++;
}
+
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
for (y=0; y < (ssize_t) image->rows; y++)
{
q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
+
for (x=(ssize_t) image->columns-1; x >= 0; x--)
{
q->red=ScaleShortToQuantum(q->red);
q->opacity=ScaleShortToQuantum(q->opacity);
q++;
}
+
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Crop the PNG image");
+
if ((crop_box.left < crop_box.right) &&
(crop_box.top < crop_box.bottom))
{
image->page.x=0;
image->page.y=0;
im=CropImage(image,&crop_info,exception);
+
if (im != (Image *) NULL)
{
image->columns=im->columns;
image->page.y=crop_box.top;
}
}
+
else
{
/*
#endif
GetImageException(image,exception);
+
if (image_info->number_scenes != 0)
{
if (mng_info->scenes_found >
" Finished reading image datastream.");
} while (LocaleCompare(image_info->magick,"MNG") == 0);
+
(void) CloseBlob(image);
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Finished reading all image datastreams.");
+
#if defined(MNG_INSERT_LAYERS)
if (insert_layers && !mng_info->image_found && (mng_info->mng_width) &&
(mng_info->mng_height))
{
image=DestroyImageList(image);
MngInfoFreeStruct(mng_info,&have_mng_structure);
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Allocation failed, returning NULL.");
+
return((Image *) NULL);
}
image=SyncNextImageInList(image);
{
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule()," No beginning");
+
(void) ThrowMagickException(&image->exception,GetMagickModule(),
CoderError,"Linked list is corrupted, beginning of list not found",
"`%s'",image_info->filename);
+
return((Image *) NULL);
}
{
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule()," Corrupt list");
+
(void) ThrowMagickException(&image->exception,GetMagickModule(),
CoderError,"Linked list is corrupted; next_image is NULL","`%s'",
image_info->filename);
}
}
+
if (mng_info->ticks_per_second && mng_info->image_found > 1 &&
GetNextImageInList(image) ==
(Image *) NULL)
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" First image null");
+
(void) ThrowMagickException(&image->exception,GetMagickModule(),
CoderError,"image->next for first image is NULL but shouldn't be.",
"`%s'",image_info->filename);
}
+
if (mng_info->image_found == 0)
{
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" No visible images found.");
+
(void) ThrowMagickException(&image->exception,GetMagickModule(),
CoderError,"No visible images in file","`%s'",image_info->filename);
+
if (image != (Image *) NULL)
image=DestroyImageList(image);
+
MngInfoFreeStruct(mng_info,&have_mng_structure);
return((Image *) NULL);
}
{
if (image->delay)
final_image_delay=image->delay;
+
image=GetNextImageInList(image);
}
scene=0;
image=GetFirstImageInList(image);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Before coalesce:");
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" scene 0 delay=%.20g",(double) image->delay);
+
while (GetNextImageInList(image) != (Image *) NULL)
{
image=GetNextImageInList(image);
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule()," Coalesce Images");
+
scene=image->scene;
next_image=CoalesceImages(image,&image->exception);
+
if (next_image == (Image *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+
image=DestroyImageList(image);
image=next_image;
+
for (next=image; next != (Image *) NULL; next=next_image)
{
next->page.width=mng_info->mng_width;
next->page.y=0;
next->scene=scene++;
next_image=GetNextImageInList(next);
+
if (next_image == (Image *) NULL)
break;
+
if (next->delay == 0)
{
scene--;
while (GetNextImageInList(image) != (Image *) NULL)
image=GetNextImageInList(image);
+
image->dispose=BackgroundDispose;
if (logging != MagickFalse)
scene=0;
image=GetFirstImageInList(image);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" After coalesce:");
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" scene 0 delay=%.20g dispose=%.20g",(double) image->delay,
(double) image->dispose);
+
while (GetNextImageInList(image) != (Image *) NULL)
{
image=GetNextImageInList(image);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" scene %.20g delay=%.20g dispose=%.20g",(double) scene++,
(double) image->delay,(double) image->dispose);
}
}
+
image=GetFirstImageInList(image);
MngInfoFreeStruct(mng_info,&have_mng_structure);
have_mng_structure=MagickFalse;
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),"exit ReadMNGImage()");
+
return(GetFirstImageInList(image));
}
#else /* PNG_LIBPNG_VER > 10011 */
{
printf("Your PNG library is too old: You have libpng-%s\n",
PNG_LIBPNG_VER_STRING);
+
(void) ThrowMagickException(exception,GetMagickModule(),CoderError,
"PNG library is too old","`%s'",image_info->filename);
+
return(Image *) NULL;
}
+
static Image *ReadMNGImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
return(ReadPNGImage(image_info,exception));
{
"See http://www.libpng.org/ for details about the PNG format."
},
+
*JNGNote=
{
"See http://www.libpng.org/pub/mng/ for details about the JNG\n"
"format."
},
+
*MNGNote=
{
"See http://www.libpng.org/pub/mng/ for details about the MNG\n"
};
*version='\0';
+
#if defined(PNG_LIBPNG_VER_STRING)
(void) ConcatenateMagickString(version,"libpng ",MaxTextExtent);
(void) ConcatenateMagickString(version,PNG_LIBPNG_VER_STRING,MaxTextExtent);
+
if (LocaleCompare(PNG_LIBPNG_VER_STRING,png_get_header_ver(NULL)) != 0)
{
(void) ConcatenateMagickString(version,",",MaxTextExtent);
MaxTextExtent);
}
#endif
+
entry=SetMagickInfo("MNG");
entry->seekable_stream=MagickTrue; /* To do: eliminate this. */
+
#if defined(MAGICKCORE_PNG_DELEGATE)
entry->decoder=(DecodeImageHandler *) ReadMNGImage;
entry->encoder=(EncodeImageHandler *) WriteMNGImage;
#endif
+
entry->magick=(IsImageFormatHandler *) IsMNG;
entry->description=ConstantString("Multiple-image Network Graphics");
+
if (*version != '\0')
entry->version=ConstantString(version);
+
entry->module=ConstantString("PNG");
entry->note=ConstantString(MNGNote);
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("PNG");
+
#if defined(MAGICKCORE_PNG_DELEGATE)
entry->decoder=(DecodeImageHandler *) ReadPNGImage;
entry->encoder=(EncodeImageHandler *) WritePNGImage;
#endif
+
entry->magick=(IsImageFormatHandler *) IsPNG;
entry->adjoin=MagickFalse;
entry->description=ConstantString("Portable Network Graphics");
entry->module=ConstantString("PNG");
+
if (*version != '\0')
entry->version=ConstantString(version);
+
entry->note=ConstantString(PNGNote);
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("PNG8");
+
#if defined(MAGICKCORE_PNG_DELEGATE)
entry->decoder=(DecodeImageHandler *) ReadPNGImage;
entry->encoder=(EncodeImageHandler *) WritePNGImage;
#endif
+
entry->magick=(IsImageFormatHandler *) IsPNG;
entry->adjoin=MagickFalse;
entry->description=ConstantString(
entry=SetMagickInfo("PNG24");
*version='\0';
+
#if defined(ZLIB_VERSION)
(void) ConcatenateMagickString(version,"zlib ",MaxTextExtent);
(void) ConcatenateMagickString(version,ZLIB_VERSION,MaxTextExtent);
+
if (LocaleCompare(ZLIB_VERSION,zlib_version) != 0)
{
(void) ConcatenateMagickString(version,",",MaxTextExtent);
(void) ConcatenateMagickString(version,zlib_version,MaxTextExtent);
}
#endif
+
if (*version != '\0')
entry->version=ConstantString(version);
+
#if defined(MAGICKCORE_PNG_DELEGATE)
entry->decoder=(DecodeImageHandler *) ReadPNGImage;
entry->encoder=(EncodeImageHandler *) WritePNGImage;
#endif
+
entry->magick=(IsImageFormatHandler *) IsPNG;
entry->adjoin=MagickFalse;
entry->description=ConstantString("opaque 24-bit RGB");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("PNG32");
+
#if defined(MAGICKCORE_PNG_DELEGATE)
entry->decoder=(DecodeImageHandler *) ReadPNGImage;
entry->encoder=(EncodeImageHandler *) WritePNGImage;
#endif
+
entry->magick=(IsImageFormatHandler *) IsPNG;
entry->adjoin=MagickFalse;
entry->description=ConstantString("opaque or transparent 32-bit RGBA");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("JNG");
+
#if defined(JNG_SUPPORTED)
#if defined(MAGICKCORE_PNG_DELEGATE)
entry->decoder=(DecodeImageHandler *) ReadJNGImage;
entry->encoder=(EncodeImageHandler *) WriteJNGImage;
#endif
#endif
+
entry->magick=(IsImageFormatHandler *) IsJNG;
entry->adjoin=MagickFalse;
entry->description=ConstantString("JPEG Network Graphics");
entry->module=ConstantString("PNG");
entry->note=ConstantString(JNGNote);
(void) RegisterMagickInfo(entry);
+
#if defined(PNG_SETJMP_NOT_THREAD_SAFE)
png_semaphore=AllocateSemaphoreInfo();
#endif
+
return(MagickImageCoderSignature);
}
\f
(void) UnregisterMagickInfo("PNG24");
(void) UnregisterMagickInfo("PNG32");
(void) UnregisterMagickInfo("JNG");
+
#if defined(PNG_SETJMP_NOT_THREAD_SAFE)
if (png_semaphore != (SemaphoreInfo *) NULL)
DestroySemaphoreInfo(&png_semaphore);
(void) FormatMagickString(dp,allocated_length-
(png_size_t) (dp-text[0].text),"%8lu ",(unsigned long) length);
dp+=8;
+
for (i=0; i < (ssize_t) length; i++)
{
if (i%36 == 0)
*(dp++)=(char) hex[((*sp >> 4) & 0x0f)];
*(dp++)=(char) hex[((*sp++ ) & 0x0f)];
}
+
*dp++='\n';
*dp='\0';
text[0].text_length=(png_size_t) (dp-text[0].text);
text[0].compression=image_info->compression == NoCompression ||
(image_info->compression == UndefinedCompression &&
text[0].text_length < 128) ? -1 : 0;
+
if (text[0].text_length <= allocated_length)
png_set_text(ping,ping_info,text,1);
+
png_free(ping,text[0].text);
png_free(ping,text[0].key);
png_free(ping,text);
png_uint_32 length;
ResetImageProfileIterator(image);
- for (name=GetNextImageProfile(image); name != (const char *) NULL; ){
+
+ for (name=GetNextImageProfile(image); name != (const char *) NULL; )
+ {
profile=GetImageProfile(image,name);
+
if (profile != (const StringInfo *) NULL)
{
StringInfo
*png_profile;
- if (LocaleNCompare(name,string,11) == 0) {
- if (logging != MagickFalse)
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " Found %s profile",name);
-
- png_profile=CloneStringInfo(profile);
- data=GetStringInfoDatum(png_profile),
- length=(png_uint_32) GetStringInfoLength(png_profile);
- data[4]=data[3];
- data[3]=data[2];
- data[2]=data[1];
- data[1]=data[0];
- (void) WriteBlobMSBULong(image,length-5); /* data length */
- (void) WriteBlob(image,length-1,data+1);
- (void) WriteBlobMSBULong(image,crc32(0,data+1,(uInt) length-1));
- png_profile=DestroyStringInfo(png_profile);
- }
+ if (LocaleNCompare(name,string,11) == 0)
+ {
+ if (logging != MagickFalse)
+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+ " Found %s profile",name);
+
+ png_profile=CloneStringInfo(profile);
+ data=GetStringInfoDatum(png_profile),
+ length=(png_uint_32) GetStringInfoLength(png_profile);
+ data[4]=data[3];
+ data[3]=data[2];
+ data[2]=data[1];
+ data[1]=data[0];
+ (void) WriteBlobMSBULong(image,length-5); /* data length */
+ (void) WriteBlob(image,length-1,data+1);
+ (void) WriteBlobMSBULong(image,crc32(0,data+1,(uInt) length-1));
+ png_profile=DestroyStringInfo(png_profile);
+ }
}
+
name=GetNextImageProfile(image);
}
+
return(MagickTrue);
}