static int
PNG_RenderingIntent_from_Magick_RenderingIntent(const RenderingIntent intent)
-{
+{
switch (intent)
{
case PerceptualIntent:
return 0;
+
case RelativeIntent:
return 1;
+
case SaturationIntent:
return 2;
+
case AbsoluteIntent:
return 3;
+
default:
return -1;
}
static RenderingIntent
PNG_RenderingIntent_to_Magick_RenderingIntent(const int png_intent)
-{
+{
switch (png_intent)
{
case 0:
return PerceptualIntent;
+
case 1:
return RelativeIntent;
+
case 2:
return SaturationIntent;
+
case 3:
return AbsoluteIntent;
+
default:
return UndefinedIntent;
}
{
if (x > y)
return(x);
+
return(y);
}
static inline ssize_t MagickMin(const ssize_t x,const ssize_t y)
{
if (x < y)
return(x);
+
return(y);
}
\f
{
if ((p->red != 0) && (p->red != (Quantum) QuantumRange))
return(MagickFalse);
+
if (IsGray(p) == MagickFalse)
return(MagickFalse);
+
if ((p->opacity != OpaqueOpacity) &&
(p->opacity != (Quantum) TransparentOpacity))
return(MagickFalse);
+
p++;
}
}
{
if (length < 8)
return(MagickFalse);
+
if (memcmp(magick,"\212MNG\r\n\032\n",8) == 0)
return(MagickTrue);
+
return(MagickFalse);
}
\f
{
if (length < 8)
return(MagickFalse);
+
if (memcmp(magick,"\213JNG\r\n\032\n",8) == 0)
return(MagickTrue);
+
return(MagickFalse);
}
\f
{
if (length < 8)
return(MagickFalse);
+
if (memcmp(magick,"\211PNG\r\n\032\n",8) == 0)
return(MagickTrue);
+
return(MagickFalse);
}
\f
if (length)
{
check=(png_size_t) ReadBlob(image,(size_t) length,(char *) data);
+
if (check != length)
png_error(png_ptr,"Read Exception");
+
if (length == 4)
{
if ((data[0] == 0) && (data[1] == 0) && (data[2] == 0) &&
mng_info->have_saved_bkgd_index=MagickFalse;
}
}
+
if ((data[0] == 0) && (data[1] == 0) && (data[2] == 0) &&
(data[3] == 1))
{
check;
check=(png_size_t) WriteBlob(image,(size_t) length,data);
+
if (check != length)
png_error(png_ptr,"WriteBlob Failed");
}
if ((a == (Image *) NULL) || (b == (Image *) NULL))
return((int) MagickFalse);
+
if (a->storage_class != PseudoClass || b->storage_class != PseudoClass)
return((int) MagickFalse);
+
if (a->colors != b->colors)
return((int) MagickFalse);
+
for (i=0; i < (ssize_t) a->colors; i++)
{
if ((a->colormap[i].red != b->colormap[i].red) ||
(a->colormap[i].blue != b->colormap[i].blue))
return((int) MagickFalse);
}
+
return((int) MagickTrue);
}
#endif
{
if (mng_info->ob[i]->reference_count > 0)
mng_info->ob[i]->reference_count--;
+
if (mng_info->ob[i]->reference_count == 0)
{
if (mng_info->ob[i]->image != (Image *) NULL)
mng_info->ob[i]->image=DestroyImage(mng_info->ob[i]->image);
+
mng_info->ob[i]=DestroyString(mng_info->ob[i]);
}
}
for (i=1; i < MNG_MAX_OBJECTS; i++)
MngInfoDiscardObject(mng_info,i);
+
if (mng_info->global_plte != (png_colorp) NULL)
mng_info->global_plte=(png_colorp)
RelinquishMagickMemory(mng_info->global_plte);
+
mng_info=(MngInfo *) RelinquishMagickMemory(mng_info);
*have_mng_structure=MagickFalse;
}
box=box1;
if (box.left < box2.left)
box.left=box2.left;
+
if (box.top < box2.top)
box.top=box2.top;
+
if (box.right > box2.right)
box.right=box2.right;
+
if (box.bottom > box2.bottom)
box.bottom=box2.bottom;
+
return box;
}
box.top+=previous_box.top;
box.bottom+=previous_box.bottom;
}
+
return(box);
}
*/
pair.a=(long) ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
pair.b=(long) ((p[4] << 24) | (p[5] << 16) | (p[6] << 8) | p[7]);
+
if (delta_type != 0)
{
pair.a+=previous_pair.a;
pair.b+=previous_pair.b;
}
+
return(pair);
}
*image;
image=(Image *) png_get_error_ptr(ping);
+
if (image->debug != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" libpng-%s error: %s", PNG_LIBPNG_VER_STRING,message);
+
(void) ThrowMagickException(&image->exception,GetMagickModule(),CoderError,
message,"`%s'",image->filename);
+
#if PNG_LIBPNG_VER < 10500
longjmp(ping->jmpbuf,1);
#else
if (LocaleCompare(message, "Missing PLTE before tRNS") == 0)
png_error(ping, message);
+
image=(Image *) png_get_error_ptr(ping);
if (image->debug != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" libpng-%s warning: %s", PNG_LIBPNG_VER_STRING,message);
+
(void) ThrowMagickException(&image->exception,GetMagickModule(),CoderWarning,
message,"`%s'",image->filename);
}
png_ptr=png_ptr;
ret=((png_voidp) AcquireMagickMemory((size_t) size));
+
if (ret == NULL)
png_error("Insufficient memory.");
+
return(ret);
#else
png_ptr=png_ptr;
/* look for newline */
while (*sp != '\n')
sp++;
+
/* look for length */
while (*sp == '\0' || *sp == ' ' || *sp == '\n')
sp++;
+
length=(png_uint_32) StringToLong(sp);
+
while (*sp != ' ' && *sp != '\n')
sp++;
+
/* allocate space */
if (length == 0)
{
CoderWarning,"UnableToCopyProfile","`%s'","invalid profile length");
return(MagickFalse);
}
+
profile=AcquireStringInfo(length);
+
if (profile == (StringInfo *) NULL)
{
(void) ThrowMagickException(&image->exception,GetMagickModule(),
"unable to copy profile");
return(MagickFalse);
}
+
/* copy profile, skipping white space and column 1 "=" signs */
dp=GetStringInfoDatum(profile);
nibbles=length*2;
+
for (i=0; i < (ssize_t) nibbles; i++)
{
while (*sp < '0' || (*sp > '9' && *sp < 'a') || *sp > 'f')
}
sp++;
}
+
if (i%2 == 0)
*dp=(unsigned char) (16*unhex[(int) *sp++]);
+
else
(*dp++)+=unhex[(int) *sp++];
}
*/
(void) SetImageProfile(image,&text[ii].key[17],profile);
profile=DestroyStringInfo(profile);
+
if (image_info->verbose)
(void) printf(" Found a generic profile, type %s\n",&text[ii].key[17]);
+
return MagickTrue;
}
image->page.width=(size_t) ((chunk->data[0] << 24) |
(chunk->data[1] << 16) | (chunk->data[2] << 8) | chunk->data[3]);
+
image->page.height=(size_t) ((chunk->data[4] << 24) |
(chunk->data[5] << 16) | (chunk->data[6] << 8) | chunk->data[7]);
#endif
if (ping == (png_struct *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+
ping_info=png_create_info_struct(ping);
+
if (ping_info == (png_info *) NULL)
{
png_destroy_read_struct(&ping,(png_info **) NULL,(png_info **) NULL);
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
}
+
end_info=png_create_info_struct(ping);
+
if (end_info == (png_info *) NULL)
{
png_destroy_read_struct(&ping,&ping_info,(png_info **) NULL);
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
}
+
png_pixels=(unsigned char *) NULL;
+
if (setjmp(png_jmpbuf(ping)))
{
/*
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" exit ReadOnePNGImage() with error.");
+
if (image != (Image *) NULL)
{
InheritException(exception,&image->exception);
image->columns=0;
}
+
return(GetFirstImageInList(image));
}
/*
mng_info->image_found++;
png_set_sig_bytes(ping,8);
+
if (LocaleCompare(image_info->magick,"MNG") == 0)
{
#if defined(PNG_MNG_FEATURES_SUPPORTED)
#endif
#endif
}
+
else
png_set_read_fn(ping,image,png_get_data);
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" PNG width: %.20g, height: %.20g",
(double) ping_width, (double) ping_height);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" PNG color_type: %d, bit_depth: %d",
ping_color_type, ping_bit_depth);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" PNG compression_method: %d",
ping_compression_method);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" PNG interlace_method: %d, filter_method: %d",
ping_interlace_method,ping_filter_method);
(void) png_get_iCCP(ping,ping_info,&name,(int *) &compression,&info,
&profile_length);
+
if (profile_length != 0)
{
StringInfo
if (mng_info->have_global_srgb)
image->rendering_intent=PNG_RenderingIntent_to_Magick_RenderingIntent(
mng_info->global_srgb_intent);
+
if (png_get_sRGB(ping,ping_info,&intent))
{
image->rendering_intent=PNG_RenderingIntent_to_Magick_RenderingIntent(
intent);
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Reading PNG sRGB chunk: rendering_intent: %d",intent);
if (!png_get_gAMA(ping,ping_info,&file_gamma))
if (mng_info->have_global_gama)
png_set_gAMA(ping,ping_info,mng_info->global_gamma);
+
if (png_get_gAMA(ping,ping_info,&file_gamma))
{
image->gamma=(float) file_gamma;
mng_info->global_chrm.blue_primary.y);
}
}
+
if (png_get_valid(ping,ping_info,PNG_INFO_cHRM))
{
(void) png_get_cHRM(ping,ping_info,
&image->chromaticity.green_primary.y,
&image->chromaticity.blue_primary.x,
&image->chromaticity.blue_primary.y);
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Reading PNG cHRM chunk.");
}
+
if (image->rendering_intent != UndefinedIntent)
{
png_set_sRGB(ping,ping_info,
{
image->page.x=png_get_x_offset_pixels(ping, ping_info);
image->page.y=png_get_y_offset_pixels(ping, ping_info);
+
if (logging != MagickFalse)
if (image->page.x || image->page.y)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
&unit_type);
image->x_resolution=(double) x_resolution;
image->y_resolution=(double) y_resolution;
+
if (unit_type == PNG_RESOLUTION_METER)
{
image->units=PixelsPerCentimeterResolution;
image->x_resolution=(double) x_resolution/100.0;
image->y_resolution=(double) y_resolution/100.0;
}
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Reading PNG pHYs chunk: xres: %.20g, yres: %.20g, units: %d.",
palette;
(void) png_get_PLTE(ping,ping_info,&palette,&number_colors);
+
if ((number_colors == 0) &&
((int) ping_color_type == PNG_COLOR_TYPE_PALETTE))
{
{
png_set_PLTE(ping,ping_info,mng_info->global_plte,
(int) mng_info->global_plte_length);
+
if (!png_get_valid(ping,ping_info,PNG_INFO_tRNS))
if (mng_info->global_trns_length)
{
#endif
if (png_get_valid(ping, ping_info, PNG_INFO_bKGD))
background.index=ping_background->index;
+
background.red=(png_uint_16)
mng_info->global_plte[background.index].red;
+
background.green=(png_uint_16)
mng_info->global_plte[background.index].green;
+
background.blue=(png_uint_16)
mng_info->global_plte[background.index].blue;
+
png_set_bKGD(ping,ping_info,&background);
}
#endif
if (mng_info->have_global_bkgd &&
(!png_get_valid(ping,ping_info,PNG_INFO_bKGD)))
image->background_color=mng_info->mng_global_bkgd;
+
if (png_get_valid(ping,ping_info,PNG_INFO_bKGD))
{
/*
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Reading PNG bKGD chunk.");
+
if (ping_bit_depth == MAGICKCORE_QUANTUM_DEPTH)
{
image->background_color.red=ping_background->red;
image->background_color.green=ping_background->green;
image->background_color.blue=ping_background->blue;
}
+
else /* Scale background components to 16-bit */
{
unsigned int
ping_background->green,ping_background->blue);
bkgd_scale = 1;
+
if (ping_bit_depth == 1)
bkgd_scale = 255;
+
else if (ping_bit_depth == 2)
bkgd_scale = 85;
+
else if (ping_bit_depth == 4)
bkgd_scale = 17;
+
if (ping_bit_depth <= 8)
bkgd_scale *= 257;
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" bkgd_scale=%d.",bkgd_scale);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" ping_background=(%d,%d,%d).",ping_background->red,
ping_background->green,ping_background->blue);
image->background_color.red=
ScaleShortToQuantum(ping_background->red);
+
image->background_color.green=
ScaleShortToQuantum(ping_background->green);
+
image->background_color.blue=
ScaleShortToQuantum(ping_background->blue);
+
image->background_color.opacity=OpaqueOpacity;
if (logging != MagickFalse)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Raw tRNS graylevel is %d.",ping_trans_color->gray);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" scaled graylevel is %d.",transparent_color.opacity);
}
mng_info->frame=mng_info->image_box;
mng_info->clip=mng_info->image_box;
}
+
else
{
image->page.y=mng_info->y_off[mng_info->object_id];
}
+
image->compression=ZipCompression;
image->columns=ping_width;
image->rows=ping_height;
(void) png_get_PLTE(ping,ping_info,&palette,&number_colors);
image->colors=(size_t) number_colors;
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Reading PNG PLTE chunk: number_colors: %d.",number_colors);
*/
if (AcquireImageColormap(image,image->colors) == MagickFalse)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+
if ((int) ping_color_type == PNG_COLOR_TYPE_PALETTE)
{
int
palette;
(void) png_get_PLTE(ping,ping_info,&palette,&number_colors);
+
for (i=0; i < (ssize_t) image->colors; i++)
{
image->colormap[i].red=ScaleCharToQuantum(palette[i].red);
image->colormap[i].blue=ScaleCharToQuantum(palette[i].blue);
}
}
+
else
{
size_t
scale;
scale=(QuantumRange/((1UL << ping_bit_depth)-1));
+
if (scale < 1)
scale=1;
+
for (i=0; i < (ssize_t) image->colors; i++)
{
image->colormap[i].red=(Quantum) (i*scale);
*/
if (image->delay != 0)
mng_info->scenes_found++;
+
if ((mng_info->mng_type == 0 && (image->ping != MagickFalse)) || (
(image_info->number_scenes != 0) && (mng_info->scenes_found > (ssize_t)
(image_info->first_scene+image_info->number_scenes))))
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" exit ReadOnePNGImage().");
+
return(image);
}
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Reading PNG IDAT chunk(s)");
+
if (num_passes > 1)
png_pixels=(unsigned char *) AcquireQuantumMemory(image->rows,
ping_rowbytes*sizeof(*png_pixels));
+
else
png_pixels=(unsigned char *) AcquireQuantumMemory(ping_rowbytes,
sizeof(*png_pixels));
+
if (png_pixels == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Converting PNG pixels to pixel packets");
#endif
if (quantum_info != (QuantumInfo *) NULL)
quantum_info = DestroyQuantumInfo(quantum_info);
+
if (png_pixels != (unsigned char *) NULL)
png_pixels=(unsigned char *) RelinquishMagickMemory(png_pixels);
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" exit ReadOnePNGImage() with error.");
+
if (image != (Image *) NULL)
{
InheritException(exception,&image->exception);
image->columns=0;
}
+
return(GetFirstImageInList(image));
}
+
quantum_info=AcquireQuantumInfo(image_info,image);
+
if (quantum_info == (QuantumInfo *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+
if (image->storage_class == DirectClass)
for (pass=0; pass < num_passes; pass++)
{
{
if (num_passes > 1)
row_offset=ping_rowbytes*y;
+
else
row_offset=0;
+
png_read_row(ping,png_pixels+row_offset,NULL);
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
+
if (q == (PixelPacket *) NULL)
break;
#if (0 && (MAGICKCORE_QUANTUM_DEPTH == 8) && !defined(MAGICKCORE_HDRI_SUPPORT))
*r++=OpaqueOpacity;
}
}
+
else if (ping_color_type == PNG_COLOR_TYPE_RGB_ALPHA)
for (x=(ssize_t) (4*image->columns); x != 0; x--)
{
*r++=*p++;
p++;
}
+
else if (ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
for (x=(ssize_t) (2*image->columns); x != 0; x--)
{
if (depth == 8 && ping_color_type == PNG_COLOR_TYPE_GRAY)
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
GrayQuantum,png_pixels+row_offset);
+
if (ping_color_type == PNG_COLOR_TYPE_GRAY ||
ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
{
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
GrayAlphaQuantum,png_pixels+row_offset);
}
+
else if (depth == 8 && ping_color_type == PNG_COLOR_TYPE_RGB)
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
RGBQuantum,png_pixels+row_offset);
+
else if (ping_color_type == PNG_COLOR_TYPE_RGB ||
ping_color_type == PNG_COLOR_TYPE_RGB_ALPHA)
{
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
RGBAQuantum,png_pixels+row_offset);
}
+
else if (ping_color_type == PNG_COLOR_TYPE_PALETTE)
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
IndexQuantum,png_pixels+row_offset);
#else /* (MAGICKCORE_QUANTUM_DEPTH != 8) */
+
if ((int) ping_color_type == PNG_COLOR_TYPE_GRAY)
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
GrayQuantum,png_pixels+row_offset,exception);
+
else if ((int) ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
GrayAlphaQuantum,png_pixels+row_offset,exception);
+
else if ((int) ping_color_type == PNG_COLOR_TYPE_RGB_ALPHA)
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
RGBAQuantum,png_pixels+row_offset,exception);
+
else if ((int) ping_color_type == PNG_COLOR_TYPE_PALETTE)
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
IndexQuantum,png_pixels+row_offset,exception);
+
else
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
RGBQuantum,png_pixels+row_offset,exception);
{
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
image->rows);
+
if (status == MagickFalse)
break;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
+
if ((image->previous == (Image *) NULL) && (num_passes != 1))
{
status=SetImageProgress(image,LoadImageTag,pass,num_passes);
break;
}
}
+
else /* image->storage_class != DirectClass */
for (pass=0; pass < num_passes; pass++)
{
*/
image->matte=ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA ?
MagickTrue : MagickFalse;
+
quantum_scanline=(Quantum *) AcquireQuantumMemory(image->columns,
(image->matte ? 2 : 1)*sizeof(*quantum_scanline));
+
if (quantum_scanline == (Quantum *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+
for (y=0; y < (ssize_t) image->rows; y++)
{
if (num_passes > 1)
row_offset=0;
png_read_row(ping,png_pixels+row_offset,NULL);
q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
+
if (q == (PixelPacket *) NULL)
break;
+
indexes=GetAuthenticIndexQueue(image);
p=png_pixels+row_offset;
r=quantum_scanline;
*r++=(Quantum) ((*p) & (0x01 << bit) ? 0x01 : 0x00);
p++;
}
+
if ((image->columns % 8) != 0)
{
for (bit=7; bit >= (ssize_t) (8-(image->columns % 8)); bit--)
*r++=(Quantum) ((*p) & (0x01 << bit) ? 0x01 : 0x00);
}
+
break;
}
case 2:
*r++=(*p >> 2) & 0x03;
*r++=(*p++) & 0x03;
}
+
if ((image->columns % 4) != 0)
{
for (i=3; i >= (ssize_t) (4-(image->columns % 4)); i--)
*r++=(Quantum) ((*p >> (i*2)) & 0x03);
}
+
break;
}
case 4:
*r++=(*p >> 4) & 0x0f;
*r++=(*p++) & 0x0f;
}
+
if ((image->columns % 2) != 0)
*r++=(*p++ >> 4) & 0x0f;
+
break;
}
case 8:
q->opacity=ScaleCharToQuantum((unsigned char) (255-(*p++)));
q++;
}
+
else
for (x=(ssize_t) image->columns-1; x >= 0; x--)
*r++=*p++;
+
break;
}
case 16:
if (image->colors > 256)
*r=((*p++) << 8);
+
else
*r=0;
+
quantum=(*r);
quantum|=(*p++);
*r=(Quantum) quantum;
if (image->colors > 256)
*r=((*p++) << 8);
+
else
*r=0;
+
quantum=(*r);
quantum|=(*p++);
*r=quantum;
r++;
+
if (ping_color_type == 4)
{
q->opacity=(*p << 8) | *(p+1);
Transfer image scanline.
*/
r=quantum_scanline;
+
for (x=0; x < (ssize_t) image->columns; x++)
indexes[x]=(IndexPacket) (*r++);
+
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
+
if ((image->previous == (Image *) NULL) && (num_passes == 1))
{
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
}
if (quantum_info != (QuantumInfo *) NULL)
quantum_info=DestroyQuantumInfo(quantum_info);
+
if (image->storage_class == PseudoClass)
{
MagickBooleanType
#if 1 /* balfour fix */
/* From imagemagick discourse server, 5 Feb 2010 */
- if (storage_class == PseudoClass)
- {
- if ((int) ping_color_type == PNG_COLOR_TYPE_PALETTE)
- {
- for (x=0; x < ping_num_trans; x++)
- {
- image->colormap[x].opacity =
- 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++)
- {
- if (ScaleQuantumToShort(image->colormap[x].red) ==
- transparent_color.opacity)
+ if (storage_class == PseudoClass)
+ {
+ if ((int) ping_color_type == PNG_COLOR_TYPE_PALETTE)
{
- image->colormap[x].opacity = (Quantum) TransparentOpacity;
+ for (x=0; x < ping_num_trans; x++)
+ {
+ image->colormap[x].opacity =
+ ScaleCharToQuantum((unsigned char)(255-ping_trans_alpha[x]));
+ }
}
- }
- }
- (void) SyncImage(image);
- }
- else
- {
+ else if (ping_color_type == PNG_COLOR_TYPE_GRAY)
+ {
+ for (x=0; x < (int) image->colors; x++)
+ {
+ if (ScaleQuantumToShort(image->colormap[x].red) ==
+ transparent_color.opacity)
+ {
+ image->colormap[x].opacity = (Quantum) TransparentOpacity;
+ }
+ }
+ }
+ (void) SyncImage(image);
+ }
+ else
+ {
+ for (y=0; y < (ssize_t) image->rows; y++)
+ {
+ image->storage_class=storage_class;
+ q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
- for (y=0; y < (ssize_t) image->rows; y++)
- {
- image->storage_class=storage_class;
- q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
- if (q == (PixelPacket *) NULL)
- break;
- indexes=GetAuthenticIndexQueue(image);
+ if (q == (PixelPacket *) NULL)
+ break;
- for (x=(ssize_t) image->columns-1; x >= 0; x--)
- {
- if (ScaleQuantumToShort(q->red) == transparent_color.red &&
- ScaleQuantumToShort(q->green) == transparent_color.green &&
- ScaleQuantumToShort(q->blue) == transparent_color.blue)
- q->opacity=(Quantum) TransparentOpacity;
- else
- SetOpacityPixelComponent(q,OpaqueOpacity);
- q++;
+ indexes=GetAuthenticIndexQueue(image);
+
+ for (x=(ssize_t) image->columns-1; x >= 0; x--)
+ {
+ if (ScaleQuantumToShort(q->red) == transparent_color.red &&
+ ScaleQuantumToShort(q->green) == transparent_color.green &&
+ ScaleQuantumToShort(q->blue) == transparent_color.blue)
+ q->opacity=(Quantum) TransparentOpacity;
+
+ else
+ SetOpacityPixelComponent(q,OpaqueOpacity);
+
+ q++;
+ }
+
+ if (SyncAuthenticPixels(image,exception) == MagickFalse)
+ break;
}
- if (SyncAuthenticPixels(image,exception) == MagickFalse)
- break;
- }
- }
+ }
#else /* not balfour */
-
for (y=0; y < (ssize_t) image->rows; y++)
{
image->storage_class=storage_class;
q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
+
if (q == (PixelPacket *) NULL)
break;
+
indexes=GetAuthenticIndexQueue(image);
if (storage_class == PseudoClass)
for (x=0; x < (ssize_t) image->columns; x++)
{
indexpacket=indexes[x];
+
if (indexpacket < ping_num_trans)
q->opacity=ScaleCharToQuantum((unsigned char)
(255-ping_trans_alpha[(ssize_t) indexpacket]));
+
else
SetOpacityPixelComponent(q,OpaqueOpacity);
+
q++;
}
else if (ping_color_type == PNG_COLOR_TYPE_GRAY)
q->red=image->colormap[(ssize_t) indexpacket].red;
q->green=q->red;
q->blue=q->red;
+
if (ScaleQuantomToShort(q->red) == transparent_color.opacity)
q->opacity=(Quantum) TransparentOpacity;
+
else
SetOpacityPixelComponent(q,OpaqueOpacity);
+
q++;
}
}
ScaleQuantumToShort(q->green) == transparent_color.green &&
ScaleQuantumToShort(q->blue) == transparent_color.blue)
q->opacity=(Quantum) TransparentOpacity;
+
else
SetOpacityPixelComponent(q,OpaqueOpacity);
+
q++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Reading PNG text chunk");
+
if (memcmp(text[i].key, "Raw profile type ",17) == 0)
(void) png_read_raw_profile(image,image_info,text,(int) i);
+
else
{
char
*value='\0';
(void) ConcatenateMagickString(value,text[i].text,length+2);
(void) SetImageProperty(image,text[i].key,value);
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Keyword: %s",text[i].key);
+
value=DestroyString(value);
}
}
*/
mng_info->ob[object_id]=(MngBuffer *)
AcquireMagickMemory(sizeof(MngBuffer));
+
if (mng_info->ob[object_id] != (MngBuffer *) NULL)
{
mng_info->ob[object_id]->image=(Image *) NULL;
(void) ThrowMagickException(&image->exception,GetMagickModule(),
ResourceLimitError,"MemoryAllocationFailed","`%s'",
image->filename);
+
if (mng_info->ob[object_id]->frozen)
(void) ThrowMagickException(&image->exception,GetMagickModule(),
ResourceLimitError,"Cannot overwrite frozen MNG object buffer",
"`%s'",image->filename);
}
+
else
{
if (mng_info->ob[object_id]->image != (Image *) NULL)
mng_info->ob[object_id]->image=DestroyImage
(mng_info->ob[object_id]->image);
+
mng_info->ob[object_id]->image=CloneImage(image,0,0,MagickTrue,
&image->exception);
+
if (mng_info->ob[object_id]->image != (Image *) NULL)
mng_info->ob[object_id]->image->file=(FILE *) NULL;
+
else
(void) ThrowMagickException(&image->exception,GetMagickModule(),
ResourceLimitError,"Cloning image for object buffer failed",
"`%s'",image->filename);
+
if (ping_width > 250000L || ping_height > 250000L)
png_error(ping,"PNG Image dimensions are too large.");
+
mng_info->ob[object_id]->width=ping_width;
mng_info->ob[object_id]->height=ping_height;
mng_info->ob[object_id]->color_type=ping_color_type;
mng_info->ob[object_id]->compression_method=
ping_compression_method;
mng_info->ob[object_id]->filter_method=ping_filter_method;
+
if (png_get_valid(ping,ping_info,PNG_INFO_PLTE))
{
int
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" exit ReadOnePNGImage()");
+
return(image);
/* end of reading one PNG image */
{
if (previous->signature != MagickSignature)
ThrowReaderException(CorruptImageError,"CorruptImage");
+
(void) CloseBlob(previous);
(void) DestroyImageList(previous);
}
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
"exit ReadPNGImage() with error");
+
return((Image *) NULL);
}
(void) CloseBlob(image);
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
"exit ReadPNGImage() with error.");
+
ThrowReaderException(CorruptImageError,"CorruptImage");
}
if (LocaleCompare(image_info->magick,"PNG8") == 0)
{
(void) SetImageType(image,PaletteType);
+
if (image->matte != MagickFalse)
{
/* To do: Reduce to binary transparency */
(void) SetImageType(image,TrueColorType);
image->matte=MagickFalse;
}
+
if (LocaleCompare(image_info->magick,"PNG32") == 0)
(void) SetImageType(image,TrueColorMatteType);
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),"exit ReadPNGImage()");
+
return(image);
}
" enter ReadOneJNGImage()");
image=mng_info->image;
+
if (GetAuthenticPixelQueue(image) != (PixelPacket *) NULL)
{
/*
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" AcquireNextImage()");
+
AcquireNextImage(image_info,image);
+
if (GetNextImageInList(image) == (Image *) NULL)
return((Image *) NULL);
+
image=SyncNextImageInList(image);
}
mng_info->image=image;
*/
status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
2*GetBlobSize(image));
+
if (status == MagickFalse)
break;
+
type[0]='\0';
(void) ConcatenateMagickString(type,"errr",MaxTextExtent);
length=ReadBlobMSBLong(image);
if (length > PNG_UINT_31_MAX || count == 0)
ThrowReaderException(CorruptImageError,"CorruptImage");
+
p=NULL;
chunk=(unsigned char *) NULL;
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;
}
(void) ReadBlobMSBLong(image); /* read crc word */
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
GetImageInfo(color_image_info);
color_image=AcquireImage(color_image_info);
+
if (color_image == (Image *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Creating color_blob.");
+
(void) AcquireUniqueFilename(color_image->filename);
status=OpenBlob(color_image_info,color_image,WriteBinaryBlobMode,
exception);
+
if (status == MagickFalse)
return((Image *) NULL);
{
alpha_image_info=(ImageInfo *)
AcquireMagickMemory(sizeof(ImageInfo));
+
if (alpha_image_info == (ImageInfo *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+
GetImageInfo(alpha_image_info);
alpha_image=AcquireImage(alpha_image_info);
+
if (alpha_image == (Image *) NULL)
{
alpha_image=DestroyImage(alpha_image);
ThrowReaderException(ResourceLimitError,
"MemoryAllocationFailed");
}
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Creating alpha_blob.");
+
(void) AcquireUniqueFilename(alpha_image->filename);
status=OpenBlob(alpha_image_info,alpha_image,WriteBinaryBlobMode,
exception);
+
if (status == MagickFalse)
return((Image *) NULL);
+
if (jng_alpha_compression_method == 0)
{
unsigned char
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Writing IHDR chunk to alpha_blob.");
+
(void) WriteBlob(alpha_image,8,(const unsigned char *)
"\211PNG\r\n\032\n");
+
(void) WriteBlobMSBULong(alpha_image,13L);
PNGType(data,mng_IHDR);
LogPNGChunk((int) logging,mng_IHDR,13L);
(void) WriteBlobMSBULong(alpha_image,
crc32(crc32(0,data,4),chunk,(uInt) length));
}
+
if (length)
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
+
continue;
}
(void) WriteBlob(alpha_image,length,chunk);
}
+
if (length)
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
+
continue;
}
if (memcmp(type,mng_JSEP,4) == 0)
{
read_JSEP=MagickTrue;
+
if (length)
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
+
continue;
}
image->background_color.green=image->background_color.red;
image->background_color.blue=image->background_color.red;
}
+
if (length == 6)
{
image->background_color.red=ScaleCharToQuantum(p[1]);
image->background_color.green=ScaleCharToQuantum(p[3]);
image->background_color.blue=ScaleCharToQuantum(p[5]);
}
+
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
continue;
}
{
if (length == 4)
image->gamma=((float) mng_get_long(p))*0.00001;
+
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
continue;
}
{
image->page.x=mng_get_long(p);
image->page.y=mng_get_long(&p[4]);
+
if ((int) p[8] != 0)
{
image->page.x/=10000;
}
if (length)
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
+
continue;
}
image->y_resolution=image->y_resolution/100.0f;
}
}
+
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
continue;
}
/* To do. */
if (length)
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
+
continue;
}
#endif
if (memcmp(type,mng_IEND,4))
continue;
+
break;
}
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Reading jng_image from color_blob.");
+
(void) FormatMagickString(color_image_info->filename,MaxTextExtent,"%s",
color_image->filename);
+
color_image_info->ping=MagickFalse; /* To do: avoid this */
jng_image=ReadImage(color_image_info,exception);
+
if (jng_image == (Image *) NULL)
return((Image *) NULL);
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Copying jng_image pixels to main image.");
+
image->rows=jng_height;
image->columns=jng_width;
length=image->columns*sizeof(PixelPacket);
+
for (y=0; y < (ssize_t) image->rows; y++)
{
s=GetVirtualPixels(jng_image,0,y,image->columns,1,&image->exception);
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
+
jng_image=DestroyImage(jng_image);
+
if (image_info->ping == MagickFalse)
{
if (jng_color_type >= 12)
(void) WriteBlob(alpha_image,4,data);
(void) WriteBlobMSBULong(alpha_image,crc32(0,data,4));
}
+
(void) CloseBlob(alpha_image);
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Reading opacity from alpha_blob.");
"%s",alpha_image->filename);
jng_image=ReadImage(alpha_image_info,exception);
+
if (jng_image != (Image *) NULL)
for (y=0; y < (ssize_t) image->rows; y++)
{
if (image->matte != MagickFalse)
for (x=(ssize_t) image->columns; x != 0; x--,q++,s++)
q->opacity=(Quantum) QuantumRange-s->red;
+
else
for (x=(ssize_t) image->columns; x != 0; x--,q++,s++)
{
if (q->opacity != OpaqueOpacity)
image->matte=MagickTrue;
}
+
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
mng_info->mng_width=jng_width;
mng_info->mng_height=jng_height;
}
+
if (image->page.width == 0 && image->page.height == 0)
- {
- image->page.width=jng_width;
- image->page.height=jng_height;
- }
+ {
+ image->page.width=jng_width;
+ image->page.height=jng_height;
+ }
+
if (image->page.x == 0 && image->page.y == 0)
- {
- image->page.x=mng_info->x_off[mng_info->object_id];
- image->page.y=mng_info->y_off[mng_info->object_id];
- }
+ {
+ image->page.x=mng_info->x_off[mng_info->object_id];
+ image->page.y=mng_info->y_off[mng_info->object_id];
+ }
+
else
- {
- image->page.y=mng_info->y_off[mng_info->object_id];
- }
+ {
+ image->page.y=mng_info->y_off[mng_info->object_id];
+ }
+
mng_info->image_found++;
status=SetImageProgress(image,LoadImagesTag,2*TellBlob(image),
2*GetBlobSize(image));
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" exit ReadOneJNGImage()");
+
return(image);
}
image=AcquireImage(image_info);
mng_info=(MngInfo *) NULL;
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
+
if (status == MagickFalse)
return((Image *) NULL);
+
if (LocaleCompare(image_info->magick,"JNG") != 0)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
+
/*
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.
*/
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.
*/
previous=image;
image=ReadOneJNGImage(mng_info,image_info,exception);
MngInfoFreeStruct(mng_info,&have_mng_structure);
+
if (image == (Image *) NULL)
{
if (IsImageObject(previous) != MagickFalse)
(void) CloseBlob(previous);
(void) DestroyImageList(previous);
}
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
"exit ReadJNGImage() with error");
+
return((Image *) NULL);
}
(void) CloseBlob(image);
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
"exit ReadJNGImage() with error");
+
ThrowReaderException(CorruptImageError,"CorruptImage");
}
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),"exit ReadJNGImage()");
+
return(image);
}
#endif
default_fb.left=0;
default_fb.right=0;
- /*
- Set image_info->type=OptimizeType (new in version 5.4.0) to get the
- following optimizations:
-
- o 16-bit depth is reduced to 8 if all pixels contain samples whose
- high byte and low byte are identical.
- o Opaque matte channel is removed.
- o If matte channel is present but only one transparent color is
- present, RGB+tRNS is written instead of RGBA
- o Grayscale images are reduced to 1, 2, or 4 bit depth if
- this can be done without loss.
- o Palette is sorted to remove unused entries and to put a
- transparent color first, if PNG_SORT_PALETTE is also defined.
- */
-
/*
Open image file.
*/
image=AcquireImage(image_info);
mng_info=(MngInfo *) NULL;
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
+
if (status == MagickFalse)
return((Image *) NULL);
+
first_mng_object=MagickFalse;
skipping_loop=(-1);
have_mng_structure=MagickFalse;
Allocate a MngInfo structure.
*/
mng_info=(MngInfo *) AcquireMagickMemory(sizeof(MngInfo));
+
if (mng_info == (MngInfo *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+
/*
Initialize members of the MngInfo structure.
*/
if (length > PNG_UINT_31_MAX)
status=MagickFalse;
+
if (count == 0)
ThrowReaderException(CorruptImageError,"CorruptImage");
+
p=NULL;
chunk=(unsigned char *) NULL;
+
if (length)
{
chunk=(unsigned char *) AcquireQuantumMemory(length,sizeof(*chunk));
chunk[i]=(unsigned char) ReadBlobByte(image);
p=chunk;
}
+
(void) ReadBlobMSBLong(image); /* read crc word */
#if !defined(JNG_SUPPORTED)
if (memcmp(type,mng_JHDR,4) == 0)
{
skip_to_iend=MagickTrue;
+
if (mng_info->jhdr_warning == 0)
(void) ThrowMagickException(&image->exception,GetMagickModule(),
CoderError,"JNGCompressNotSupported","`%s'",image->filename);
+
mng_info->jhdr_warning++;
}
#endif
if (memcmp(type,mng_DHDR,4) == 0)
{
skip_to_iend=MagickTrue;
+
if (mng_info->dhdr_warning == 0)
(void) ThrowMagickException(&image->exception,GetMagickModule(),
CoderError,"DeltaPNGNotSupported","`%s'",image->filename);
+
mng_info->dhdr_warning++;
}
if (memcmp(type,mng_MEND,4) == 0)
{
if (memcmp(type,mng_IEND,4) == 0)
skip_to_iend=MagickFalse;
+
if (length)
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Skip to IEND.");
+
continue;
}
+
if (memcmp(type,mng_MHDR,4) == 0)
{
mng_info->mng_width=(size_t) ((p[0] << 24) | (p[1] << 16) |
(p[2] << 8) | p[3]);
+
mng_info->mng_height=(size_t) ((p[4] << 24) | (p[5] << 16) |
(p[6] << 8) | p[7]);
+
if (logging != MagickFalse)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" MNG height: %.20g",(double) mng_info->mng_height);
}
+
p+=8;
mng_info->ticks_per_second=(size_t) mng_get_long(p);
+
if (mng_info->ticks_per_second == 0)
default_frame_delay=0;
+
else
default_frame_delay=1UL*image->ticks_per_second/
mng_info->ticks_per_second;
+
frame_delay=default_frame_delay;
simplicity=0;
+
if (length > 16)
{
p+=16;
simplicity=(size_t) mng_get_long(p);
}
+
mng_type=1; /* Full MNG */
+
if ((simplicity != 0) && ((simplicity | 11) == 11))
mng_type=2; /* LC */
+
if ((simplicity != 0) && ((simplicity | 9) == 9))
mng_type=3; /* VLC */
+
#if defined(MNG_INSERT_LAYERS)
if (mng_type != 3)
insert_layers=MagickTrue;
Allocate next image structure.
*/
AcquireNextImage(image_info,image);
+
if (GetNextImageInList(image) == (Image *) NULL)
return((Image *) NULL);
+
image=SyncNextImageInList(image);
mng_info->image=image;
}
if ((mng_info->mng_width > 65535L) ||
(mng_info->mng_height > 65535L))
ThrowReaderException(ImageError,"WidthOrHeightExceedsLimit");
+
(void) FormatMagickString(page_geometry,MaxTextExtent,
"%.20gx%.20g+0+0",(double) mng_info->mng_width,(double)
mng_info->mng_height);
+
mng_info->frame.left=0;
mng_info->frame.right=(ssize_t) mng_info->mng_width;
mng_info->frame.top=0;
mng_info->frame.bottom=(ssize_t) mng_info->mng_height;
mng_info->clip=default_fb=previous_fb=mng_info->frame;
+
for (i=0; i < MNG_MAX_OBJECTS; i++)
mng_info->object_clip[i]=mng_info->frame;
+
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
continue;
}
if (length)
repeat=p[0];
+
if (repeat == 3)
{
final_delay=(png_uint_32) mng_get_long(&p[2]);
mng_iterations=(png_uint_32) mng_get_long(&p[6]);
+
if (mng_iterations == PNG_UINT_31_MAX)
mng_iterations=0;
+
image->iterations=mng_iterations;
term_chunk_found=MagickTrue;
}
+
if (logging != MagickFalse)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" repeat=%d",repeat);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" final_delay=%.20g",(double) final_delay);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" image->iterations=%.20g",(double) image->iterations);
}
+
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
continue;
}
(void) ThrowMagickException(&image->exception,GetMagickModule(),
CoderError,"DEFI chunk found in MNG-VLC datastream","`%s'",
image->filename);
+
object_id=(p[0] << 8) | p[1];
+
if (mng_type == 2 && object_id != 0)
(void) ThrowMagickException(&image->exception,GetMagickModule(),
CoderError,"Nonzero object_id in MNG-LC datastream","`%s'",
image->filename);
+
if (object_id > MNG_MAX_OBJECTS)
{
/*
CoderError,"object id too large","`%s'",image->filename);
object_id=MNG_MAX_OBJECTS;
}
+
if (mng_info->exists[object_id])
if (mng_info->frozen[object_id])
{
image->filename);
continue;
}
+
mng_info->exists[object_id]=MagickTrue;
+
if (length > 2)
mng_info->invisible[object_id]=p[2];
+
/*
Extract object offset info.
*/
if (length > 11)
{
- mng_info->x_off[object_id]=(ssize_t) ((p[4] << 24) | (p[5] << 16) |
- (p[6] << 8) | p[7]);
- mng_info->y_off[object_id]=(ssize_t) ((p[8] << 24) | (p[9] << 16) |
- (p[10] << 8) | p[11]);
+ mng_info->x_off[object_id]=(ssize_t) ((p[4] << 24) |
+ (p[5] << 16) | (p[6] << 8) | p[7]);
+
+ mng_info->y_off[object_id]=(ssize_t) ((p[8] << 24) |
+ (p[9] << 16) | (p[10] << 8) | p[11]);
+
if (logging != MagickFalse)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" x_off[%d]: %.20g",object_id,(double)
mng_info->x_off[object_id]);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" y_off[%d]: %.20g",object_id,(double)
mng_info->y_off[object_id]);
}
}
+
/*
Extract object clipping info.
*/
if (length > 27)
mng_info->object_clip[object_id]=mng_read_box(mng_info->frame,0,
&p[12]);
+
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
continue;
}
if (memcmp(type,mng_bKGD,4) == 0)
{
mng_info->have_global_bkgd=MagickFalse;
+
if (length > 5)
{
mng_info->mng_global_bkgd.red=
ScaleShortToQuantum((unsigned short) ((p[0] << 8) | p[1]));
+
mng_info->mng_global_bkgd.green=
ScaleShortToQuantum((unsigned short) ((p[2] << 8) | p[3]));
+
mng_info->mng_global_bkgd.blue=
ScaleShortToQuantum((unsigned short) ((p[4] << 8) | p[5]));
+
mng_info->have_global_bkgd=MagickTrue;
}
+
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
continue;
}
#if defined(MNG_INSERT_LAYERS)
if (length > 6)
mandatory_back=p[6];
+
else
mandatory_back=0;
+
if (mandatory_back && length > 5)
{
mng_background_color.red=
ScaleShortToQuantum((unsigned short) ((p[0] << 8) | p[1]));
+
mng_background_color.green=
ScaleShortToQuantum((unsigned short) ((p[2] << 8) | p[3]));
+
mng_background_color.blue=
ScaleShortToQuantum((unsigned short) ((p[4] << 8) | p[5]));
+
mng_background_color.opacity=OpaqueOpacity;
}
+
#ifdef MNG_OBJECT_BUFFERS
if (length > 8)
mng_background_object=(p[7] << 8) | p[8];
if (mng_info->global_plte == (png_colorp) NULL)
mng_info->global_plte=(png_colorp) AcquireQuantumMemory(256,
sizeof(*mng_info->global_plte));
+
for (i=0; i < (ssize_t) (length/3); i++)
{
mng_info->global_plte[i].red=p[3*i];
mng_info->global_plte[i].green=p[3*i+1];
mng_info->global_plte[i].blue=p[3*i+2];
}
+
mng_info->global_plte_length=(unsigned int) (length/3);
}
#ifdef MNG_LOOSE
mng_info->global_plte[i].green=i;
mng_info->global_plte[i].blue=i;
}
+
if (length)
mng_info->global_plte_length=256;
#endif
else
mng_info->global_plte_length=0;
+
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
continue;
}
mng_info->global_gamma=((float) igamma)*0.00001;
mng_info->have_global_gama=MagickTrue;
}
+
else
mng_info->have_global_gama=MagickFalse;
+
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
continue;
}
(void) ThrowMagickException(&image->exception,GetMagickModule(),
CoderError,"FRAM chunk found in MNG-VLC datastream","`%s'",
image->filename);
+
if ((mng_info->framing_mode == 2) || (mng_info->framing_mode == 4))
image->delay=frame_delay;
+
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 (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Framing_mode=%d",mng_info->framing_mode);
+
if (length > 6)
{
/*
{
frame_delay=1UL*image->ticks_per_second*
mng_get_long(p);
+
if (mng_info->ticks_per_second != 0)
frame_delay/=mng_info->ticks_per_second;
+
else
frame_delay=PNG_UINT_31_MAX;
+
if (change_delay == 2)
default_frame_delay=frame_delay;
+
p+=4;
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Framing_delay=%.20g",(double) frame_delay);
{
frame_timeout=1UL*image->ticks_per_second*
mng_get_long(p);
+
if (mng_info->ticks_per_second != 0)
frame_timeout/=mng_info->ticks_per_second;
+
else
frame_timeout=PNG_UINT_31_MAX;
+
if (change_delay == 2)
default_frame_timeout=frame_timeout;
+
p+=4;
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Framing_timeout=%.20g",(double) frame_timeout);
fb=mng_read_box(previous_fb,(char) p[0],&p[1]);
p+=17;
previous_fb=fb;
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " Frame_clipping: L=%.20g R=%.20g T=%.20g B=%.20g",
+ " 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)
}
mng_info->clip=fb;
mng_info->clip=mng_minimum_box(fb,mng_info->frame);
+
subframe_width=(size_t) (mng_info->clip.right
-mng_info->clip.left);
+
subframe_height=(size_t) (mng_info->clip.bottom
-mng_info->clip.top);
/*
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" subframe_width=%.20g, subframe_height=%.20g",(double)
subframe_width,(double) subframe_height);
+
if (insert_layers && (mng_info->framing_mode == 4) &&
(subframe_width) && (subframe_height))
{
}
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;
+
image->columns=subframe_width;
image->rows=subframe_height;
image->page.width=subframe_width;
image->matte=MagickFalse;
image->delay=0;
(void) SetImageBackgroundColor(image);
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " Inserted background layer, L=%.20g, R=%.20g T=%.20g, B=%.20g",
+ " Insert backgd layer, L=%.20g, R=%.20g T=%.20g, B=%.20g",
(double) mng_info->clip.left,(double) mng_info->clip.right,
(double) mng_info->clip.top,(double) mng_info->clip.bottom);
}
mng_info->ob[i]->frozen=MagickTrue;
#endif
}
+
if (length)
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
+
continue;
}
for (i=1; i < MNG_MAX_OBJECTS; i++)
MngInfoDiscardObject(mng_info,i);
}
+
else
{
register ssize_t
MngInfoDiscardObject(mng_info,i);
}
}
+
if (length)
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
+
continue;
}
if (memcmp(type,mng_MOVE,4) == 0)
Record starting point.
*/
loop_iters=mng_get_long(&chunk[1]);
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" LOOP level %.20g has %.20g iterations ",(double) loop_level,
(double) loop_iters);
+
if (loop_iters == 0)
skipping_loop=loop_level;
+
else
{
mng_info->loop_jump[loop_level]=TellBlob(image);
mng_info->loop_count[loop_level]=loop_iters;
}
+
mng_info->loop_iteration[loop_level]=0;
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
continue;
{
mng_info->loop_count[loop_level]--;
mng_info->loop_iteration[loop_level]++;
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " ENDL: LOOP level %.20g has %.20g remaining iterations ",
+ " 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],
SEEK_SET);
+
if (offset < 0)
ThrowReaderException(CorruptImageError,
"ImproperImageHeader");
if (length > 1)
magn_first=(p[0] << 8) | p[1];
+
else
magn_first=0;
+
if (length > 3)
magn_last=(p[2] << 8) | p[3];
+
else
magn_last=magn_first;
#ifndef MNG_OBJECT_BUFFERS
}
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;
image->delay=0;
image->background_color=mng_background_color;
image->matte=MagickFalse;
(void) SetImageBackgroundColor(image);
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " Inserted background layer, L=%.20g, R=%.20g T=%.20g, B=%.20g",
+ " Insert background layer, L=%.20g, R=%.20g T=%.20g, B=%.20g",
(double) mng_info->clip.left,(double) mng_info->clip.right,
(double) mng_info->clip.top,(double) mng_info->clip.bottom);
}
mng_info->image=image;
status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
GetBlobSize(image));
+
if (status == MagickFalse)
break;
+
if (term_chunk_found)
{
image->start_loop=MagickTrue;
term_chunk_found=MagickFalse;
}
+
else
image->start_loop=MagickFalse;
+
if (mng_info->framing_mode == 1 || mng_info->framing_mode == 3)
{
image->delay=frame_delay;
frame_delay=default_frame_delay;
}
+
else
image->delay=0;
+
image->page.width=mng_info->mng_width;
image->page.height=mng_info->mng_height;
image->page.x=mng_info->x_off[object_id];
MngInfoFreeStruct(mng_info,&have_mng_structure);
return((Image *) NULL);
}
+
if (image->columns == 0 || image->rows == 0)
{
(void) CloseBlob(image);
MngInfoFreeStruct(mng_info,&have_mng_structure);
return((Image *) NULL);
}
+
mng_info->image=image;
if (mng_type)
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" No images found. Inserting a background layer.");
+
if (GetAuthenticPixelQueue(image) != (PixelPacket *) NULL)
{
/*
image->page.y=0;
image->background_color=mng_background_color;
image->matte=MagickFalse;
+
if (image_info->ping == MagickFalse)
(void) SetImageBackgroundColor(image);
+
mng_info->image_found++;
}
#endif
image->iterations=mng_iterations;
+
if (mng_iterations == 1)
image->start_loop=MagickTrue;
+
while (GetPreviousImageInList(image) != (Image *) NULL)
{
image_count++;
"`%s'",image_info->filename);
return((Image *) NULL);
}
+
image=GetPreviousImageInList(image);
+
if (GetNextImageInList(image) == (Image *) NULL)
{
if (logging != MagickFalse)
if (mng_info->ticks_per_second)
final_delay=1UL*MagickMax(image->ticks_per_second,1L)*
final_delay/mng_info->ticks_per_second;
+
else
image->start_loop=MagickTrue;
+
/* Find final nonzero image delay */
final_image_delay=0;
+
while (GetNextImageInList(image) != (Image *) NULL)
{
if (image->delay)
final_image_delay=image->delay;
image=GetNextImageInList(image);
}
+
if (final_delay < final_image_delay)
final_delay=final_image_delay;
+
image->delay=final_delay;
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" image->delay=%.20g, final_delay=%.20g",(double) image->delay,
(double) final_delay);
+
if (logging != MagickFalse)
{
int
if (image_info->verbose)
{
- (void) printf("writing raw profile: type=%s, length=%.20g\n",
- (char *) profile_type, (double) length);
+ (void) printf("writing raw profile: type=%s, length=%.20g\n",
+ (char *) profile_type, (double) length);
}
+
text=(png_textp) png_malloc(ping,(png_uint_32) sizeof(png_text));
description_length=(png_uint_32) strlen((const char *) profile_description);
allocated_length=(png_uint_32) (length*2 + (length >> 5) + 20
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" new_number_colors in OptimizePNGColormap=%d",
(int) new_number_colors);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" In OptimizePNGColormap:");
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" i plte_map (red,green,blue,opacity)");
+
for (i=0; i < image->colors; i++)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
Eliminate unused colormap entries.
*/
for (i=0; i < number_colors; i++)
- ping_plte_map[i]=i;
+ ping_plte_map[i]=i;
k=0;
for (i=0; i < number_colors; i++)
{
if (marker[i])
{
- ping_plte_map[i]=(IndexPacket) k;
+ ping_plte_map[i]=(IndexPacket) k;
for (j=i+1; j < number_colors; j++)
{
if ((image->colormap[i].opacity == image->colormap[j].opacity) &&
}
}
- if (have_transparency && (image->colormap[0].opacity !=
+ if (have_transparency && (image->colormap[0].opacity !=
(Quantum) TransparentOpacity))
{
/*
colormap[ping_plte_map[i]] = image->colormap[i];
if (ping_plte_map[i] != i)
- remap_needed = MagickTrue;
+ remap_needed = MagickTrue;
if (ping_plte_map[i] >= ping_number_colors)
ping_number_colors=ping_plte_map[i]+1;
for (y=0; y < (ssize_t) image->rows; y++)
{
q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
+
if (q == (PixelPacket *) NULL)
break;
+
pixels=GetAuthenticIndexQueue(image);
+
for (x=0; x < (ssize_t) image->columns; x++)
{
j=(int) pixels[x];
pixels[x]=(IndexPacket) ping_plte_map[j];
}
+
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" After OptimizePNGColormap:");
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" i plte_map (red,green,blue,opacity)");
+
for (i=0; i < image->colors; i++)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
matte;
volatile int
- ping_bit_depth,
+ ping_bit_depth,
ping_color_type,
ping_interlace_method,
ping_compression_method,
#endif
/* Initialize some stuff */
- ping_bit_depth=0,
+ ping_bit_depth=0,
ping_color_type=0,
ping_interlace_method=0,
ping_compression_method=0,
if (image->colorspace != RGBColorspace)
(void) TransformImageColorspace(image,RGBColorspace);
- mng_info->IsPalette=image->storage_class == PseudoClass &&
+
+ mng_info->IsPalette=image->storage_class == PseudoClass &&
image_colors <= 256 && !IsOpaqueImage(image,&image->exception);
/*
ping=png_create_write_struct_2(PNG_LIBPNG_VER_STRING,image,
PNGErrorHandler,PNGWarningHandler,(void *) NULL,
(png_malloc_ptr) png_IM_malloc,(png_free_ptr) png_IM_free);
+
#else
ping=png_create_write_struct(PNG_LIBPNG_VER_STRING,image,
PNGErrorHandler,PNGWarningHandler);
+
#endif
if (ping == (png_struct *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
+
ping_info=png_create_info_struct(ping);
+
if (ping_info == (png_info *) NULL)
{
png_destroy_write_struct(&ping,(png_info **) NULL);
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
}
+
png_set_write_fn(ping,image,png_put_data,png_flush_data);
png_pixels=(unsigned char *) NULL;
ping_height=(png_uint_32) image->rows;
if (mng_info->write_png8 || mng_info->write_png24 || mng_info->write_png32)
image_depth=8;
+
if (mng_info->write_png_depth != 0)
image_depth=mng_info->write_png_depth;
+
/* Adjust requested depth to next higher valid depth if necessary */
if (image_depth > 8)
image_depth=16;
+
if ((image_depth > 4) && (image_depth < 8))
image_depth=8;
+
if (image_depth == 3)
image_depth=4;
+
if (logging != MagickFalse)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
if ((image->x_resolution != 0) && (image->y_resolution != 0) &&
(!mng_info->write_mng || !mng_info->equal_physs))
{
- if (logging != MagickFalse)
+ if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Setting up pHYs chunk");
mask=0xffff;
if (ping_bit_depth == 8)
mask=0x00ff;
+
if (ping_bit_depth == 4)
mask=0x000f;
+
if (ping_bit_depth == 2)
mask=0x0003;
+
if (ping_bit_depth == 1)
mask=0x0001;
+
ping_background.red=(png_uint_16)
(ScaleQuantumToShort(image->background_color.red) & mask);
+
ping_background.green=(png_uint_16)
(ScaleQuantumToShort(image->background_color.green) & mask);
+
ping_background.blue=(png_uint_16)
(ScaleQuantumToShort(image->background_color.blue) & mask);
- }
+ }
+
+ if (logging != MagickFalse)
+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+ " Setting up bKGd chunk");
+
+ ping_have_bKGD = MagickTrue;
- if (logging != MagickFalse)
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " Setting up bKGd chunk");
- ping_have_bKGD = MagickTrue;
/*
Select the color type.
*/
matte=image_matte;
old_bit_depth=0;
+
if ((mng_info->write_png_colortype-1) == PNG_COLOR_TYPE_PALETTE)
mng_info->write_png8=MagickTrue;
+
if (mng_info->write_png8)
{
- ping_color_type=(png_byte) PNG_COLOR_TYPE_PALETTE;
+ QuantizeInfo
+ quantize_info;
+
+ /* TO DO: make this a function cause it's used twice, except
+ for reducing the sample depth from 8. */
+
+ ping_color_type=(png_byte) PNG_COLOR_TYPE_PALETTE;
ping_bit_depth=8;
image_depth=ping_bit_depth;
- {
- /* TO DO: make this a function cause it's used twice, except
- for reducing the sample depth from 8. */
-
- QuantizeInfo
- quantize_info;
+ number_colors=image_colors;
+ if ((image->storage_class == DirectClass) || (number_colors > 256))
+ {
+ GetQuantizeInfo(&quantize_info);
+ quantize_info.dither=IsPaletteImage(image,&image->exception) ==
+ MagickFalse ? MagickTrue : MagickFalse;
+ quantize_info.number_colors= (matte != MagickFalse ? 255UL :
+ 256UL);
+ (void) QuantizeImage(&quantize_info,image);
number_colors=image_colors;
- if ((image->storage_class == DirectClass) || (number_colors > 256))
- {
- GetQuantizeInfo(&quantize_info);
- quantize_info.dither=IsPaletteImage(image,&image->exception) ==
- MagickFalse ? MagickTrue : MagickFalse;
- quantize_info.number_colors= (matte != MagickFalse ? 255UL :
- 256UL);
- (void) QuantizeImage(&quantize_info,image);
- number_colors=image_colors;
- (void) SyncImage(image);
- if (logging != MagickFalse)
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " Colors quantized to %.20g",(double) number_colors);
- }
- if (matte)
- ping_have_tRNS=MagickFalse;
- /*
- Set image palette.
- */
- ping_color_type=(png_byte) PNG_COLOR_TYPE_PALETTE;
- if (CompressColormapTransFirst(image) == MagickFalse)
- ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
- number_colors=image->colors;
- image_colors=number_colors;
+ (void) SyncImage(image);
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " Setting up PLTE chunk with %d colors (%d)",
- (int) number_colors, (int) image_colors);
- for (i=0; i < (ssize_t) number_colors; i++)
- {
- palette[i].red=ScaleQuantumToChar(image->colormap[i].red);
- palette[i].green=ScaleQuantumToChar(image->colormap[i].green);
- palette[i].blue=ScaleQuantumToChar(image->colormap[i].blue);
- if (logging != MagickFalse)
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+ " Colors quantized to %.20g",(double) number_colors);
+ }
+
+ if (matte)
+ ping_have_tRNS=MagickFalse;
+
+ /*
+ Set image palette.
+ */
+ ping_color_type=(png_byte) PNG_COLOR_TYPE_PALETTE;
+
+ if (CompressColormapTransFirst(image) == MagickFalse)
+ ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
+
+ number_colors=image->colors;
+ image_colors=number_colors;
+
+ if (logging != MagickFalse)
+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+ " Setting up PLTE chunk with %d colors (%d)",
+ (int) number_colors, (int) image_colors);
+
+ for (i=0; i < (ssize_t) number_colors; i++)
+ {
+ palette[i].red=ScaleQuantumToChar(image->colormap[i].red);
+ palette[i].green=ScaleQuantumToChar(image->colormap[i].green);
+ palette[i].blue=ScaleQuantumToChar(image->colormap[i].blue);
+ if (logging != MagickFalse)
+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
#if MAGICKCORE_QUANTUM_DEPTH == 8
- " %3ld (%3d,%3d,%3d)",
+ " %3ld (%3d,%3d,%3d)",
#else
- " %5ld (%5d,%5d,%5d)",
+ " %5ld (%5d,%5d,%5d)",
#endif
- (long) i,palette[i].red,palette[i].green,palette[i].blue);
+ (long) i,palette[i].red,palette[i].green,palette[i].blue);
- }
- if (matte)
- {
- number_colors++;
- palette[i].red=ScaleQuantumToChar((Quantum) QuantumRange);
- palette[i].green=ScaleQuantumToChar((Quantum) QuantumRange);
- palette[i].blue=ScaleQuantumToChar((Quantum) QuantumRange);
- }
- ping_have_PLTE=MagickTrue;
- image_depth=ping_bit_depth;
- ping_num_trans=0;
- if (matte)
- {
- ExceptionInfo
- *exception;
+ }
+ if (matte)
+ {
+ number_colors++;
+ palette[i].red=ScaleQuantumToChar((Quantum) QuantumRange);
+ palette[i].green=ScaleQuantumToChar((Quantum) QuantumRange);
+ palette[i].blue=ScaleQuantumToChar((Quantum) QuantumRange);
+ }
+ ping_have_PLTE=MagickTrue;
+ image_depth=ping_bit_depth;
+ ping_num_trans=0;
+ if (matte)
+ {
+ ExceptionInfo
+ *exception;
- int
- trans_alpha[256];
+ int
+ trans_alpha[256];
- /*
- Identify which colormap entry is transparent.
- */
- assert(number_colors <= 256);
- for (i=0; i < (ssize_t) number_colors; i++)
- trans_alpha[i]=255;
- exception=(&image->exception);
- for (y=0; y < (ssize_t) image->rows; y++)
- {
- register const PixelPacket
- *p;
+ /*
+ Identify which colormap entry is transparent.
+ */
+ assert(number_colors <= 256);
- p=GetVirtualPixels(image,0,y,image->columns,1,exception);
- if (p == (PixelPacket *) NULL)
- break;
- for (x=0; x < (ssize_t) image->columns; x++)
- {
- if (p->opacity != OpaqueOpacity)
- {
- trans_alpha[(ssize_t) number_colors-1]=(png_byte) (255-
- ScaleQuantumToChar(GetOpacityPixelComponent(p)));
- }
- p++;
- }
- }
- for (i=0; i < (ssize_t) number_colors; i++)
- if (trans_alpha[i] != 255)
- ping_num_trans=(unsigned short) (i+1);
-
- if (ping_num_trans == 0)
- ping_have_tRNS=MagickFalse;
- if (ping_have_tRNS==MagickFalse)
- ping_num_trans=0;
- if (ping_num_trans != 0)
+ for (i=0; i < (ssize_t) number_colors; i++)
+ trans_alpha[i]=255;
+
+ exception=(&image->exception);
+
+ for (y=0; y < (ssize_t) image->rows; y++)
+ {
+ register const PixelPacket
+ *p;
+
+ p=GetVirtualPixels(image,0,y,image->columns,1,exception);
+
+ if (p == (PixelPacket *) NULL)
+ break;
+
+ for (x=0; x < (ssize_t) image->columns; x++)
+ {
+ if (p->opacity != OpaqueOpacity)
{
- for (i=0; i<256; i++)
- ping_trans_alpha[i]=(png_byte) trans_alpha[i];
+ trans_alpha[(ssize_t) number_colors-1]=(png_byte) (255-
+ ScaleQuantumToChar(GetOpacityPixelComponent(p)));
}
+ p++;
+ }
+ }
+ for (i=0; i < (ssize_t) number_colors; i++)
+ if (trans_alpha[i] != 255)
+ ping_num_trans=(unsigned short) (i+1);
+
+ if (ping_num_trans == 0)
+ ping_have_tRNS=MagickFalse;
+
+ if (ping_have_tRNS==MagickFalse)
+ ping_num_trans=0;
- ping_have_tRNS=MagickTrue;
+ if (ping_num_trans != 0)
+ {
+ for (i=0; i<256; i++)
+ ping_trans_alpha[i]=(png_byte) trans_alpha[i];
}
- /*
- Identify which colormap entry is the background color.
- */
- for (i=0; i < (ssize_t) MagickMax(1L*number_colors-1L,1L); i++)
- if (IsPNGColorEqual(ping_background,image->colormap[i]))
- break;
- ping_background.index=(png_byte) i;
+
+ ping_have_tRNS=MagickTrue;
}
+
+ /*
+ Identify which colormap entry is the background color.
+ */
+ for (i=0; i < (ssize_t) MagickMax(1L*number_colors-1L,1L); i++)
+ if (IsPNGColorEqual(ping_background,image->colormap[i]))
+ break;
+
+ ping_background.index=(png_byte) i;
+
if (image_matte != MagickFalse)
{
/* TO DO: reduce to binary transparency */
}
} /* end of write_png8 */
+
else if (mng_info->write_png24)
{
image_matte=MagickFalse;
ping_color_type=(png_byte) PNG_COLOR_TYPE_RGB;
}
+
else if (mng_info->write_png32)
{
image_matte=MagickTrue;
ping_color_type=(png_byte) PNG_COLOR_TYPE_RGB_ALPHA;
}
+
else
{
image_depth=ping_bit_depth;
+
if (mng_info->write_png_colortype)
{
ping_color_type=(png_byte) mng_info->write_png_colortype-1;
image_matte=MagickFalse;
+
if (ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
ping_color_type == PNG_COLOR_TYPE_RGB_ALPHA)
image_matte=MagickTrue;
}
+
else
{
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
"Selecting PNG colortype");
+
ping_color_type=(png_byte) ((matte == MagickTrue)?
PNG_COLOR_TYPE_RGB_ALPHA:PNG_COLOR_TYPE_RGB);
+
if(image_info->type == TrueColorType)
{
ping_color_type=(png_byte) PNG_COLOR_TYPE_RGB;
image_matte=MagickFalse;
}
+
if(image_info->type == TrueColorMatteType)
{
ping_color_type=(png_byte) PNG_COLOR_TYPE_RGB_ALPHA;
image_matte=MagickTrue;
}
- if ((image_info->type == UndefinedType ||
- image_info->type == OptimizeType ||
+
+ if ((image_info->type == UndefinedType ||
+ image_info->type == OptimizeType ||
image_info->type == GrayscaleType) &&
image_matte == MagickFalse && ImageIsGray(image))
{
ping_color_type=(png_byte) PNG_COLOR_TYPE_GRAY;
image_matte=MagickFalse;
}
+
if ((image_info->type == UndefinedType ||
- image_info->type == OptimizeType ||
+ image_info->type == OptimizeType ||
image_info->type == GrayscaleMatteType) &&
image_matte == MagickTrue && ImageIsGray(image))
{
ping_color_type=(png_byte) PNG_COLOR_TYPE_GRAY_ALPHA;
image_matte=MagickTrue;
- }
+ }
}
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
"Selected PNG colortype=%d",ping_color_type);
if (ping_bit_depth < 8)
- {
- if (ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
- ping_color_type == PNG_COLOR_TYPE_RGB ||
- ping_color_type == PNG_COLOR_TYPE_RGB_ALPHA)
- ping_bit_depth=8;
- }
+ {
+ if (ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
+ ping_color_type == PNG_COLOR_TYPE_RGB ||
+ ping_color_type == PNG_COLOR_TYPE_RGB_ALPHA)
+ ping_bit_depth=8;
+ }
if (ping_color_type == PNG_COLOR_TYPE_GRAY)
{
if (ImageIsMonochrome(image))
{
ping_bit_depth=1;
+
if (ping_bit_depth < (int)mng_info->write_png_depth)
ping_bit_depth = mng_info->write_png_depth;
}
if (image->colors == 0)
{
- /* DO SOMETHING */
+ /* DO SOMETHING */
(void) ThrowMagickException(&image->exception,
GetMagickModule(),CoderError,
"image has 0 colors", "`%s'","");
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" SyncImage.2.");
+
while ((int) (one << ping_bit_depth) < (ssize_t) image_colors)
ping_bit_depth <<= 1;
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Number of colors: %.20g",(double) image_colors);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Tentative PNG bit depth: %d",ping_bit_depth);
}
+
if (mng_info->write_png_depth)
{
old_bit_depth=ping_bit_depth;
if (ping_bit_depth < (int)mng_info->write_png_depth)
{
ping_bit_depth = mng_info->write_png_depth;
+
if (ping_bit_depth > 8)
ping_bit_depth = 8;
+
if (ping_bit_depth != (int) old_bit_depth)
{
if (logging != MagickFalse)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Tentative PNG color type: %.20g",(double) ping_color_type);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" image_info->type: %.20g",(double) image_info->type);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" image_depth: %.20g",(double) image_depth);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" ping_bit_depth: %.20g",(double) ping_bit_depth);
}
p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
if (p == (const PixelPacket *) NULL)
break;
+
for (x=(ssize_t) image->columns-1; x >= 0; x--)
{
if (IsGray(p) == MagickFalse)
for (y=0; y < (ssize_t) image->rows; y++)
{
p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
+
if (p == (const PixelPacket *) NULL)
break;
+
for (x=(ssize_t) image->columns-1; x >= 0; x--)
{
if (p->opacity != OpaqueOpacity)
break;
p++;
}
+
if (x != 0)
break;
}
+
if ((y == (ssize_t) image->rows) && (x == (ssize_t) image->columns))
{
/*
image_matte=MagickFalse;
ping_color_type&=0x03;
}
+
else
{
unsigned int
mask;
mask=0xffff;
+
if (ping_bit_depth == 8)
mask=0x00ff;
+
if (ping_bit_depth == 4)
mask=0x000f;
+
if (ping_bit_depth == 2)
mask=0x0003;
+
if (ping_bit_depth == 1)
mask=0x0001;
+
ping_trans_color.red=(png_uint_16)
(ScaleQuantumToShort(GetRedPixelComponent(p)) & mask);
+
ping_trans_color.green=(png_uint_16)
(ScaleQuantumToShort(GetGreenPixelComponent(p)) & mask);
+
ping_trans_color.blue=(png_uint_16)
(ScaleQuantumToShort(GetBluePixelComponent(p)) & mask);
+
ping_trans_color.gray=(png_uint_16)
(ScaleQuantumToShort(PixelIntensityToQuantum(p)) & mask);
+
ping_trans_color.index=(png_byte)
(ScaleQuantumToChar((Quantum) (GetAlphaPixelComponent(p))));
+
ping_have_tRNS=MagickTrue;
}
+
if (ping_have_tRNS != MagickFalse)
{
/*
p=GetVirtualPixels(image,0,y,image->columns,1,
&image->exception);
x=0;
+
if (p == (const PixelPacket *) NULL)
break;
+
for (x=(ssize_t) image->columns-1; x >= 0; x--)
{
if (p->opacity != OpaqueOpacity)
{
if (IsPNGColorEqual(ping_trans_color,*p) == 0)
- {
- break; /* Can't use RGB + tRNS for multiple
- transparent colors. */
- }
+ {
+ break; /* Can't use RGB + tRNS for multiple
+ transparent colors. */
+ }
+
if (p->opacity != (Quantum) TransparentOpacity)
- {
- break; /* Can't use RGB + tRNS for
- semitransparency. */
- }
+ {
+ break; /* Can't use RGB + tRNS for
+ semitransparency. */
+ }
}
+
else
{
if (IsPNGColorEqual(ping_trans_color,*p))
if (ping_have_tRNS != MagickFalse)
{
ping_color_type &= 0x03; /* changes 4 or 6 to 0 or 2 */
+
if (image_depth == 8)
{
ping_trans_color.red&=0xff;
}
}
matte=image_matte;
+
if (ping_have_tRNS != MagickFalse)
image_matte=MagickFalse;
+
if ((mng_info->IsPalette) &&
mng_info->write_png_colortype-1 != PNG_COLOR_TYPE_PALETTE &&
ImageIsGray(image) && (!image_matte || image_depth >= 8))
{
size_t one=1;
+
if (image_matte != MagickFalse)
ping_color_type=PNG_COLOR_TYPE_GRAY_ALPHA;
+
else
{
ping_color_type=PNG_COLOR_TYPE_GRAY;
if (save_image_depth == 16 && image_depth == 8)
ping_trans_color.gray*=0x0101;
}
+
if (image_depth > MAGICKCORE_QUANTUM_DEPTH)
image_depth=MAGICKCORE_QUANTUM_DEPTH;
+
if (image_colors == 0 || image_colors-1 > MaxColormapSize)
image_colors=one << image_depth;
+
if (image_depth > 8)
ping_bit_depth=16;
+
else
{
ping_bit_depth=8;
if(!mng_info->write_png_depth)
{
ping_bit_depth=1;
+
while ((int) (one << ping_bit_depth)
< (ssize_t) image_colors)
ping_bit_depth <<= 1;
}
}
- else if (ping_color_type ==
- PNG_COLOR_TYPE_GRAY && image_colors < 17 &&
+ else if (ping_color_type ==
+ PNG_COLOR_TYPE_GRAY && image_colors < 17 &&
mng_info->IsPalette)
{
if ((intensity & 0x0f) != ((intensity & 0xf0) >> 4))
depth_4_ok=depth_2_ok=depth_1_ok=MagickFalse;
+
else if ((intensity & 0x03) != ((intensity & 0x0c) >> 2))
depth_2_ok=depth_1_ok=MagickFalse;
+
else if ((intensity & 0x01) != ((intensity & 0x02) >> 1))
depth_1_ok=MagickFalse;
}
if (depth_1_ok && mng_info->write_png_depth <= 1)
ping_bit_depth=1;
+
else if (depth_2_ok && mng_info->write_png_depth <= 2)
ping_bit_depth=2;
+
else if (depth_4_ok && mng_info->write_png_depth <= 4)
ping_bit_depth=4;
}
}
image_depth=ping_bit_depth;
}
+
else
+
if (mng_info->IsPalette)
{
number_colors=image_colors;
Set image palette.
*/
ping_color_type=(png_byte) PNG_COLOR_TYPE_PALETTE;
+
if (mng_info->have_write_global_plte && !matte)
{
png_set_PLTE(ping,ping_info,NULL,0);
+
if (logging)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Setting up empty PLTE chunk");
}
+
else
{
if (CompressColormapTransFirst(image) == MagickFalse)
"MemoryAllocationFailed");
number_colors=image->colors;
image_colors=number_colors;
+
for (i=0; i < (ssize_t) number_colors; i++)
{
palette[i].red=ScaleQuantumToChar(image->colormap[i].red);
palette[i].green=ScaleQuantumToChar(image->colormap[i].green);
palette[i].blue=ScaleQuantumToChar(image->colormap[i].blue);
}
+
if (logging)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Setting up PLTE chunk with %d colors",
(int) number_colors);
+
ping_have_PLTE=MagickTrue;
}
+
/* color_type is PNG_COLOR_TYPE_PALETTE */
if (!mng_info->write_png_depth)
{
ping_bit_depth=1;
one=1;
+
while ((one << ping_bit_depth) < number_colors)
ping_bit_depth <<= 1;
}
+
ping_num_trans=0;
+
if (matte)
- {
- ExceptionInfo
- *exception;
+ {
+ ExceptionInfo
+ *exception;
- register const PixelPacket
- *p;
+ register const PixelPacket
+ *p;
- int
- trans[256];
+ int
+ trans[256];
- register const IndexPacket
- *packet_indexes;
+ register const IndexPacket
+ *packet_indexes;
+
+ /*
+ Identify which colormap entry is transparent.
+ */
+ assert(number_colors <= 256);
- /*
- Identify which colormap entry is transparent.
- */
- assert(number_colors <= 256);
- for (i=0; i < (ssize_t) number_colors; i++)
- trans[i]=256;
- exception=(&image->exception);
- for (y=0; y < (ssize_t) image->rows; y++)
- {
- p=GetVirtualPixels(image,0,y,image->columns,1,exception);
- if (p == (const PixelPacket *) NULL)
- break;
- packet_indexes=GetVirtualIndexQueue(image);
- for (x=0; x < (ssize_t) image->columns; x++)
- {
- if (p->opacity != OpaqueOpacity)
- {
- IndexPacket
- packet_index;
-
- packet_index=packet_indexes[x];
- if((size_t) packet_index >= number_colors)
- (void) LogMagickEvent(CoderEvent, GetMagickModule(),
- "packet_index=%d, number_colors=%d",
- (int) packet_index, (int) number_colors);
- assert((size_t) packet_index < number_colors);
- if (trans[(ssize_t) packet_index] != 256)
- {
- if (trans[(ssize_t) packet_index] != (png_byte) (255-
- ScaleQuantumToChar(GetOpacityPixelComponent(p))))
- {
- ping_color_type=(png_byte)
- PNG_COLOR_TYPE_RGB_ALPHA;
- break;
- }
- }
- trans[(ssize_t) packet_index]=(png_byte) (255-
- ScaleQuantumToChar(GetOpacityPixelComponent(p)));
- }
- p++;
- }
- if ((int) ping_color_type == PNG_COLOR_TYPE_RGB_ALPHA)
- {
- ping_num_trans=0;
- ping_have_tRNS=MagickFalse;
- ping_have_PLTE=MagickFalse;
- mng_info->IsPalette=MagickFalse;
- (void) SyncImage(image);
- if (logging)
- (void) LogMagickEvent(CoderEvent, GetMagickModule(),
- " Cannot write image as indexed PNG, writing RGBA.");
- break;
- }
- }
- if (ping_have_tRNS != MagickFalse)
- {
for (i=0; i < (ssize_t) number_colors; i++)
+ trans[i]=256;
+
+ exception=(&image->exception);
+
+ for (y=0; y < (ssize_t) image->rows; y++)
{
- if (trans[i] == 256)
- trans[i]=255;
- if (trans[i] != 255)
- ping_num_trans=(unsigned short) (i+1);
+ p=GetVirtualPixels(image,0,y,image->columns,1,exception);
+
+ if (p == (const PixelPacket *) NULL)
+ break;
+
+ packet_indexes=GetVirtualIndexQueue(image);
+
+ for (x=0; x < (ssize_t) image->columns; x++)
+ {
+ if (p->opacity != OpaqueOpacity)
+ {
+ IndexPacket
+ packet_index;
+
+ packet_index=packet_indexes[x];
+
+ if((size_t) packet_index >= number_colors)
+ (void) LogMagickEvent(CoderEvent, GetMagickModule(),
+ "packet_index=%d, number_colors=%d",
+ (int) packet_index, (int) number_colors);
+
+ assert((size_t) packet_index < number_colors);
+
+ if (trans[(ssize_t) packet_index] != 256)
+ {
+ if (trans[(ssize_t) packet_index] != (png_byte) (255-
+ ScaleQuantumToChar(GetOpacityPixelComponent(p))))
+ {
+ ping_color_type=(png_byte)
+ PNG_COLOR_TYPE_RGB_ALPHA;
+ break;
+ }
+ }
+
+ trans[(ssize_t) packet_index]=(png_byte) (255-
+ ScaleQuantumToChar(GetOpacityPixelComponent(p)));
+ }
+ p++;
+ }
+
+ if ((int) ping_color_type == PNG_COLOR_TYPE_RGB_ALPHA)
+ {
+ ping_num_trans=0;
+ ping_have_tRNS=MagickFalse;
+ ping_have_PLTE=MagickFalse;
+ mng_info->IsPalette=MagickFalse;
+ (void) SyncImage(image);
+
+ if (logging)
+ (void) LogMagickEvent(CoderEvent, GetMagickModule(),
+ " Cannot write image as indexed PNG, writing RGBA.");
+ break;
+ }
}
- }
- if (ping_num_trans == 0)
- ping_have_tRNS=MagickFalse;
- if (ping_have_tRNS == MagickFalse)
- ping_num_trans=0;
- if (ping_num_trans != 0)
+
+ if (ping_have_tRNS != MagickFalse)
{
for (i=0; i < (ssize_t) number_colors; i++)
- ping_trans_alpha[i]=(png_byte) trans[i];
+ {
+ if (trans[i] == 256)
+ trans[i]=255;
+
+ if (trans[i] != 255)
+ ping_num_trans=(unsigned short) (i+1);
+ }
}
- }
+ if (ping_num_trans == 0)
+ ping_have_tRNS=MagickFalse;
+
+ if (ping_have_tRNS == MagickFalse)
+ ping_num_trans=0;
+
+ if (ping_num_trans != 0)
+ {
+ for (i=0; i < (ssize_t) number_colors; i++)
+ ping_trans_alpha[i]=(png_byte) trans[i];
+ }
+ }
}
}
+
else
{
if (image_depth < 8)
image_depth=8;
+
if ((save_image_depth == 16) && (image_depth == 8))
{
ping_trans_color.red*=0x0101;
ping_background.index=(png_byte) i;
if (logging)
- {
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " Setting up bKGD chunk with index=%d",(int) i);
- }
+ {
+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+ " Setting up bKGD chunk with index=%d",(int) i);
+ }
if (i < number_colors)
- {
- ping_have_bKGD = MagickTrue;
- if (logging)
{
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " background =(%d,%d,%d)",
- (int) ping_background.red,
- (int) ping_background.green,
- (int) ping_background.blue);
+ ping_have_bKGD = MagickTrue;
+ if (logging)
+ {
+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+ " background =(%d,%d,%d)",
+ (int) ping_background.red,
+ (int) ping_background.green,
+ (int) ping_background.blue);
+ }
}
- }
else
ping_have_bKGD = MagickFalse;
Initialize compression level and filtering.
*/
if (logging != MagickFalse)
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " Setting up deflate compression");
- if (logging != MagickFalse)
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " Compression buffer size: 32768");
+ {
+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+ " Setting up deflate compression");
+
+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+ " Compression buffer size: 32768");
+ }
+
png_set_compression_buffer_size(ping,32768L);
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Compression mem level: 9");
+
png_set_compression_mem_level(ping, 9);
+
quality=image->quality == UndefinedCompressionQuality ? 75UL :
image->quality;
+
if (quality > 9)
{
int
level;
level=(int) MagickMin((ssize_t) quality/10,9);
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Compression level: %d",level);
+
png_set_compression_level(ping,level);
}
+
else
{
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Compression strategy: Z_HUFFMAN_ONLY");
+
png_set_compression_strategy(ping, Z_HUFFMAN_ONLY);
}
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Setting up filtering");
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Filter_type: PNG_INTRAPIXEL_DIFFERENCING");
+
ping_filter_method=PNG_INTRAPIXEL_DIFFERENCING;
}
+
else
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
if ((quality % 10) > 5)
base_filter=PNG_ALL_FILTERS;
+
else
if ((quality % 10) != 5)
base_filter=(int) quality % 10;
+
else
if (((int) ping_color_type == PNG_COLOR_TYPE_GRAY) ||
((int) ping_color_type == PNG_COLOR_TYPE_PALETTE) ||
(quality < 50))
base_filter=PNG_NO_FILTERS;
+
else
base_filter=PNG_ALL_FILTERS;
+
if (logging != MagickFalse)
{
if (base_filter == PNG_ALL_FILTERS)
#ifdef PNG_WRITE_iCCP_SUPPORTED
if ((LocaleCompare(name,"ICC") == 0) ||
(LocaleCompare(name,"ICM") == 0))
+
png_set_iCCP(ping,ping_info,(const png_charp) name,0,(png_charp)
GetStringInfoDatum(profile),
(png_uint_32) GetStringInfoLength(profile));
+
else
#endif
png_write_raw_profile(image_info,ping,ping_info,(unsigned char *)
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Setting up text chunk with %s profile",name);
+
name=GetNextImageProfile(image);
}
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Setting up sRGB chunk");
+
(void) png_set_sRGB(ping,ping_info,(
PNG_RenderingIntent_from_Magick_RenderingIntent(
image->rendering_intent)));
+
png_set_gAMA(ping,ping_info,0.45455);
}
if ((!mng_info->write_mng) || (!png_get_valid(ping,ping_info,PNG_INFO_sRGB)))
if (ping_bit_depth < 8)
ping_bit_depth=8;
}
-
+
if (mng_info->write_png_colortype-1 == PNG_COLOR_TYPE_GRAY_ALPHA)
if (ImageIsGray(image) == MagickFalse)
ping_color_type = PNG_COLOR_TYPE_RGB_ALPHA;
/* Add an opaque matte channel */
image->matte = MagickTrue;
(void) SetImageOpacity(image,0);
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Added an opaque matte channel");
if (ping_color_type == 3 && ping_have_PLTE != MagickFalse)
{
png_set_PLTE(ping,ping_info,palette,(int) number_colors);
+
if (logging)
- {
- for (i=0; i< number_colors; i++)
{
- if (ping_num_trans != 0)
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " PLTE[%d] + tRNS[%d] =(%d,%d,%d,%d)",
- (int) i,(int) i,
- (int) palette[i].red,
- (int) palette[i].green,
- (int) palette[i].blue,
- (int) ping_trans_alpha[i]);
- else
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " PLTE[%d] =(%d,%d,%d)",
- (int) i,
- (int) palette[i].red,
- (int) palette[i].green,
- (int) palette[i].blue);
+ for (i=0; i< number_colors; i++)
+ {
+ if (ping_num_trans != 0)
+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+ " PLTE[%d] + tRNS[%d] =(%d,%d,%d,%d)",
+ (int) i,(int) i,
+ (int) palette[i].red,
+ (int) palette[i].green,
+ (int) palette[i].blue,
+ (int) ping_trans_alpha[i]);
+ else
+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+ " PLTE[%d] =(%d,%d,%d)",
+ (int) i,
+ (int) palette[i].red,
+ (int) palette[i].green,
+ (int) palette[i].blue);
+ }
}
- }
}
if (ping_have_bKGD != MagickFalse)
png_write_info_before_PLTE(ping, ping_info);
if (ping_have_tRNS != MagickFalse && ping_color_type < 4)
- {
- if (logging)
{
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " Calling png_set_tRNS with num_trans=%d",ping_num_trans);
- }
+ if (logging)
+ {
+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+ " Calling png_set_tRNS with num_trans=%d",ping_num_trans);
+ }
- if (ping_color_type == 3)
- (void) png_set_tRNS(ping, ping_info,
- ping_trans_alpha,
- ping_num_trans,
- NULL);
+ if (ping_color_type == 3)
+ (void) png_set_tRNS(ping, ping_info,
+ ping_trans_alpha,
+ ping_num_trans,
+ NULL);
- else
- {
- (void) png_set_tRNS(ping, ping_info,
- NULL,
- 0,
- &ping_trans_color);
- if (logging)
- {
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " background =(%d,%d,%d)",
- (int) ping_trans_color.red,
- (int) ping_trans_color.green,
- (int) ping_trans_color.blue);
- }
- }
- }
+ else
+ {
+ (void) png_set_tRNS(ping, ping_info,
+ NULL,
+ 0,
+ &ping_trans_color);
+
+ if (logging)
+ {
+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+ " background =(%d,%d,%d)",
+ (int) ping_trans_color.red,
+ (int) ping_trans_color.green,
+ (int) ping_trans_color.blue);
+ }
+ }
+ }
/* write any png-chunk-b profiles */
(void) png_write_chunk_from_profile(image,"PNG-chunk-b",(int) logging);
case PNG_COLOR_TYPE_RGB:
rowbytes*=3;
break;
+
case PNG_COLOR_TYPE_GRAY_ALPHA:
rowbytes*=2;
break;
+
case PNG_COLOR_TYPE_RGBA:
rowbytes*=4;
break;
+
default:
break;
}
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Writing PNG image data");
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Allocating %.20g bytes of memory for pixels",(double) rowbytes);
}
png_pixels=(unsigned char *) AcquireQuantumMemory(rowbytes,
sizeof(*png_pixels));
+
if (png_pixels == (unsigned char *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
+
/*
Initialize image scanlines.
*/
{
register const PixelPacket
*p;
-
+
quantum_info->depth=8;
for (pass=0; pass < num_passes; pass++)
{
" Writing row of pixels (0)");
p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
+
if (p == (const PixelPacket *) NULL)
break;
+
if (mng_info->IsPalette)
{
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
>> (8-old_bit_depth));
}
}
+
else
{
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
quantum_info,RedQuantum,png_pixels,&image->exception);
}
+
if (mng_info->write_png_colortype-1 != PNG_COLOR_TYPE_PALETTE)
for (i=0; i < (ssize_t) image->columns; i++)
*(png_pixels+i)=(unsigned char) ((*(png_pixels+i) > 127) ?
255 : 0);
+
if (logging && y == 0)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Writing row of pixels (1)");
+
png_write_row(ping,png_pixels);
}
if (image->previous == (Image *) NULL)
}
}
}
+
else
for (pass=0; pass < num_passes; pass++)
{
register const PixelPacket
*p;
- if ((!mng_info->write_png8 && !mng_info->write_png24 &&
+ if ((!mng_info->write_png8 && !mng_info->write_png24 &&
!mng_info->write_png32) &&
(image_matte ||
(ping_bit_depth >= MAGICKCORE_QUANTUM_DEPTH)) &&
for (y=0; y < (ssize_t) image->rows; y++)
{
p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
+
if (p == (const PixelPacket *) NULL)
break;
+
if (ping_color_type == PNG_COLOR_TYPE_GRAY)
{
if (mng_info->IsPalette)
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
quantum_info,GrayQuantum,png_pixels,&image->exception);
+
else
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
quantum_info,RedQuantum,png_pixels,&image->exception);
+
if (logging && y == 0)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Writing GRAY PNG pixels (2)");
}
+
else /* PNG_COLOR_TYPE_GRAY_ALPHA */
{
if (logging && y == 0)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Writing GRAY_ALPHA PNG pixels (2)");
+
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
quantum_info,GrayAlphaQuantum,png_pixels,&image->exception);
}
if (logging && y == 0)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Writing row of pixels (2)");
+
png_write_row(ping,png_pixels);
}
+
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,LoadImageTag,pass,num_passes);
for (y=0; y < (ssize_t) image->rows; y++)
{
p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
+
if (p == (const PixelPacket *) NULL)
break;
+
if (ping_color_type == PNG_COLOR_TYPE_GRAY)
{
if (image->storage_class == DirectClass)
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
quantum_info,RedQuantum,png_pixels,&image->exception);
+
else
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
quantum_info,GrayQuantum,png_pixels,&image->exception);
}
+
else if (ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
{
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
quantum_info,GrayAlphaQuantum,png_pixels,&image->exception);
+
if (logging && y == 0)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Writing GRAY_ALPHA PNG pixels (3)");
}
+
else if (image_matte != MagickFalse)
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
quantum_info,RGBAQuantum,png_pixels,&image->exception);
+
else
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
quantum_info,RGBQuantum,png_pixels,&image->exception);
+
if (logging && y == 0)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Writing row of pixels (3)");
+
png_write_row(ping,png_pixels);
}
+
else
/* not ((image_depth > 8) || (mng_info->write_png24 ||
mng_info->write_png32 ||
if (logging)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" pass %d, Image Is not GRAY or GRAY_ALPHA",pass);
+
quantum_info->depth=8;
image_depth=8;
}
if (logging && y == 0)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" pass %d, Image Is RGB, 16-bit GRAY, or GRAY_ALPHA",pass);
+
p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
+
if (p == (const PixelPacket *) NULL)
break;
+
if (ping_color_type == PNG_COLOR_TYPE_GRAY)
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
quantum_info,GrayQuantum,png_pixels,&image->exception);
+
else if (ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
{
if (logging && y == 0)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Writing GRAY_ALPHA PNG pixels (4)");
+
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
quantum_info,GrayAlphaQuantum,png_pixels,&image->exception);
}
+
else
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
quantum_info,IndexQuantum,png_pixels,&image->exception);
+
if (logging && y <= 2)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Writing row of pixels (4)");
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" png_pixels[0]=%d,png_pixels[1]=%d",
(int)png_pixels[0],(int)png_pixels[1]);
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Wrote PNG image data");
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Width: %.20g",(double) ping_width);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Height: %.20g",(double) ping_height);
+
if (mng_info->write_png_depth)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Defined PNG:bit-depth: %d",mng_info->write_png_depth);
}
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" PNG bit-depth written: %d",ping_bit_depth);
+
if (mng_info->write_png_colortype)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Defined PNG:color-type: %d",mng_info->write_png_colortype-1);
}
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" PNG color-type written: %d",ping_color_type);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" PNG Interlace method: %d",ping_interlace_method);
}
text[0].compression=image_info->compression == NoCompression ||
(image_info->compression == UndefinedCompression &&
text[0].text_length < 128) ? -1 : 0;
+
if (logging != MagickFalse)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Setting up text chunk");
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" keyword: %s",text[0].key);
}
+
png_set_text(ping,ping_info,text,1);
png_free(ping,text);
}
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Writing PNG end info");
+
png_write_end(ping,ping_info);
+
if (mng_info->need_fram && (int) image->dispose == BackgroundDispose)
{
if (mng_info->page.x || mng_info->page.y ||
mng_info->old_framing_mode=4;
mng_info->framing_mode=1;
}
+
else
mng_info->framing_mode=3;
}
(void) ThrowMagickException(&image->exception,GetMagickModule(),
CoderError,"Cannot convert GIF with disposal method 3 to MNG-LC",
"`%s'",image->filename);
+
image_depth=save_image_depth;
/* Save depth actually written */
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" exit WriteOnePNGImage()");
+
return(MagickTrue);
/* End write one PNG image */
}
% o PNG32: An 8-bit per sample RGBA PNG is written. Partial
% transparency is permitted, i.e., the alpha sample for
% each pixel can have any value from 0 to 255. The alpha
-% channel is present even if the image is fully opaque.
+% channel is present even if the image is fully opaque.
%
% o -define: For more precise control of the PNG output, you can use the
% Image options "png:bit-depth" and "png:color-type". These
%
% -profile PNG-chunk-b01:file01 -profile PNG-chunk-b02:file02
%
+% Set image_info->type=OptimizeType (new in version 5.4.0) to get the
+% following optimizations:
+%
+% o 16-bit depth is reduced to 8 if all pixels contain samples whose
+% high byte and low byte are identical.
+% o Opaque matte channel is removed.
+% o If matte channel is present but only one transparent color is
+% present, RGB+tRNS is written instead of RGBA
+% o Grayscale images are reduced to 1, 2, or 4 bit depth if
+% this can be done without loss.
+%
+% TO DO: Always do the above.
+%
+% As of version 6.6.5 the following optimizations are always done:
+%
+% o Palette is sorted to remove unused entries and to put a
+% transparent color first, if PNG_SORT_PALETTE is defined.
+% o Opaque matte channel is removed when writing an indexed PNG.
+%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
static MagickBooleanType WritePNGImage(const ImageInfo *image_info,
*/
have_mng_structure=MagickFalse;
mng_info=(MngInfo *) AcquireMagickMemory(sizeof(MngInfo));
+
if (mng_info == (MngInfo *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
+
/*
Initialize members of the MngInfo structure.
*/
#if 0 /* this does not work */
if (image->matte == MagickTrue)
(void) SetImageType(image,PaletteMatteType);
+
else
(void) SetImageType(image,PaletteType);
+
(void) SyncImage(image);
#endif
}
mng_info->write_png_colortype = /* 2 */ 3;
mng_info->write_png_depth = 8;
image->depth = 8;
+
if (image->matte == MagickTrue)
(void) SetImageType(image,TrueColorMatteType);
+
else
(void) SetImageType(image,TrueColorType);
+
(void) SyncImage(image);
}
mng_info->write_png_colortype = /* 6 */ 7;
mng_info->write_png_depth = 8;
image->depth = 8;
+
if (image->matte == MagickTrue)
(void) SetImageType(image,TrueColorMatteType);
+
else
(void) SetImageType(image,TrueColorType);
+
(void) SyncImage(image);
}
{
if (LocaleCompare(value,"1") == 0)
mng_info->write_png_depth = 1;
+
else if (LocaleCompare(value,"2") == 0)
mng_info->write_png_depth = 2;
+
else if (LocaleCompare(value,"4") == 0)
mng_info->write_png_depth = 4;
+
else if (LocaleCompare(value,"8") == 0)
mng_info->write_png_depth = 8;
+
else if (LocaleCompare(value,"16") == 0)
mng_info->write_png_depth = 16;
+
else
(void) ThrowMagickException(&image->exception,
GetMagickModule(),CoderWarning,
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" png:bit-depth=%d was defined.\n",mng_info->write_png_depth);
}
+
value=GetImageOption(image_info,"png:color-type");
+
if (value != (char *) NULL)
{
/* We must store colortype+1 because 0 is a valid colortype */
if (LocaleCompare(value,"0") == 0)
mng_info->write_png_colortype = 1;
+
else if (LocaleCompare(value,"2") == 0)
mng_info->write_png_colortype = 3;
+
else if (LocaleCompare(value,"3") == 0)
mng_info->write_png_colortype = 4;
+
else if (LocaleCompare(value,"4") == 0)
mng_info->write_png_colortype = 5;
+
else if (LocaleCompare(value,"6") == 0)
mng_info->write_png_colortype = 7;
+
else
(void) ThrowMagickException(&image->exception,
GetMagickModule(),CoderWarning,
(void) CloseBlob(image);
MngInfoFreeStruct(mng_info,&have_mng_structure);
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),"exit WritePNGImage()");
+
return(status);
}
if (transparent)
{
jng_color_type=14;
+
/* Create JPEG blob, image, and image_info */
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Creating jpeg_image_info for opacity.");
+
jpeg_image_info=(ImageInfo *) CloneImageInfo(image_info);
+
if (jpeg_image_info == (ImageInfo *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Creating jpeg_image.");
+
jpeg_image=CloneImage(image,0,0,MagickTrue,&image->exception);
+
if (jpeg_image == (Image *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
+
(void) CopyMagickString(jpeg_image->magick,"JPEG",MaxTextExtent);
status=SeparateImageChannel(jpeg_image,OpacityChannel);
status=NegateImage(jpeg_image,MagickFalse);
jpeg_image->matte=MagickFalse;
+
if (jng_quality >= 1000)
jpeg_image_info->quality=jng_quality/1000;
+
else
jpeg_image_info->quality=jng_quality;
+
jpeg_image_info->type=GrayscaleType;
(void) SetImageType(jpeg_image,GrayscaleType);
(void) AcquireUniqueFilename(jpeg_image->filename);
blob=ImageToBlob(jpeg_image_info,jpeg_image,&length,
&image->exception);
jng_alpha_sample_depth=8;
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Successfully read jpeg_image into a blob, length=%.20g.",
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" JNG width:%15lu",(unsigned long) image->columns);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" JNG height:%14lu",(unsigned long) image->rows);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" JNG color type:%10d",jng_color_type);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" JNG sample depth:%8d",8);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" JNG compression:%9d",8);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" JNG interlace:%11d",0);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" JNG alpha depth:%9d",jng_alpha_sample_depth);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" JNG alpha compression:%3d",jng_alpha_compression_method);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" JNG alpha filter:%8d",0);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" JNG alpha interlace:%5d",0);
}
- /* Write any JNG-chunk-b profiles */
+ /* Write any JNG-chunk-b profiles */
(void) png_write_chunk_from_profile(image,"JNG-chunk-b",(int) logging);
/*
(void) WriteBlobMSBULong(image,1L);
PNGType(chunk,mng_sRGB);
LogPNGChunk((int) logging,mng_sRGB,1L);
+
if (image->rendering_intent != UndefinedIntent)
chunk[4]=(unsigned char)
PNG_RenderingIntent_from_Magick_RenderingIntent(
(image->rendering_intent));
+
else
chunk[4]=(unsigned char)
PNG_RenderingIntent_from_Magick_RenderingIntent(
(PerceptualIntent));
+
(void) WriteBlob(image,5,chunk);
(void) WriteBlobMSBULong(image,crc32(0,chunk,5));
}
(void) WriteBlob(image,8,chunk);
(void) WriteBlobMSBULong(image,crc32(0,chunk,8));
}
+
if ((mng_info->equal_chrms == MagickFalse) &&
(image->chromaticity.red_primary.x != 0.0))
{
(void) WriteBlobMSBULong(image,crc32(0,chunk,36));
}
}
+
if (image->x_resolution && image->y_resolution && !mng_info->equal_physs)
{
/*
{
PNGLong(chunk+4,(png_uint_32)
(image->x_resolution*100.0/2.54+0.5));
+
PNGLong(chunk+8,(png_uint_32)
(image->y_resolution*100.0/2.54+0.5));
+
chunk[12]=1;
}
+
else
{
if (image->units == PixelsPerCentimeterResolution)
{
PNGLong(chunk+4,(png_uint_32)
(image->x_resolution*100.0+0.5));
+
PNGLong(chunk+8,(png_uint_32)
(image->y_resolution*100.0+0.5));
+
chunk[12]=1;
}
+
else
{
PNGLong(chunk+4,(png_uint_32) (image->x_resolution+0.5));
{
len=(*p<<24)|((*(p+1))<<16)|((*(p+2))<<8)|(*(p+3));
p+=4;
+
if (*(p)==73 && *(p+1)==68 && *(p+2)==65 && *(p+3)==84) /* IDAT */
{
/* Found an IDAT chunk. */
(void) WriteBlobMSBULong(image,
crc32(0,p,(uInt) len+4));
}
+
else
{
if (logging != MagickFalse)
if (jng_color_type == 8 || jng_color_type == 12)
jpeg_image_info->type=GrayscaleType;
+
jpeg_image_info->quality=jng_quality % 1000;
(void) CopyMagickString(jpeg_image_info->magick,"JPEG",MaxTextExtent);
(void) CopyMagickString(jpeg_image->magick,"JPEG",MaxTextExtent);
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Creating blob.");
+
blob=ImageToBlob(jpeg_image_info,jpeg_image,&length,&image->exception);
+
if (logging != MagickFalse)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Write JDAT chunk, length=%.20g.",(double) length);
}
+
/* Write JDAT chunk(s) */
(void) WriteBlobMSBULong(image,(size_t) length);
PNGType(chunk,mng_JDAT);
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" exit WriteOneJNGImage()");
+
return(status);
}
if (mng_info->write_png8 || mng_info->write_png24 || mng_info->write_png32)
optimize=MagickFalse;
+
else
optimize=(image_info->type == OptimizeType || image_info->type ==
UndefinedType);
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Checking input image(s)");
+
if (optimize)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Optimize: TRUE");
+
else
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Optimize: FALSE");
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Image_info depth: %.20g",(double) image_info->depth);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Type: %d",image_info->type);
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Scene: %.20g",(double) scene++);
+
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Image depth: %.20g",(double) p->depth);
+
if (p->matte)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Matte: True");
+
else
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Matte: False");
+
if (p->storage_class == PseudoClass)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Storage class: PseudoClass");
+
else
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Storage class: DirectClass");
+
if (p->colors)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Number of colors: %.20g",(double) p->colors);
+
else
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Number of colors: unspecified");
+
if (mng_info->adjoin == MagickFalse)
break;
}
{
if (p->taint && p->storage_class == PseudoClass)
(void) SyncImage(p);
+
if (mng_info->adjoin == MagickFalse)
break;
}
if (p->colors <= 256)
{
p->colors=0;
+
if (p->matte != MagickFalse)
(void) SetImageType(p,PaletteMatteType);
+
else
(void) SetImageType(p,PaletteType);
}
{
if ((next_image->columns+next_image->page.x) > mng_info->page.width)
mng_info->page.width=next_image->columns+next_image->page.x;
+
if ((next_image->rows+next_image->page.y) > mng_info->page.height)
mng_info->page.height=next_image->rows+next_image->page.y;
}
+
if (next_image->page.x || next_image->page.y)
need_defi=MagickTrue;
+
if (next_image->matte)
need_matte=MagickTrue;
+
if ((int) next_image->dispose >= BackgroundDispose)
if (next_image->matte || next_image->page.x || next_image->page.y ||
((next_image->columns < mng_info->page.width) &&
(next_image->rows < mng_info->page.height)))
mng_info->need_fram=MagickTrue;
+
if (next_image->iterations)
need_iterations=MagickTrue;
+
final_delay=next_image->delay;
+
if (final_delay != initial_delay || final_delay > 1UL*
next_image->ticks_per_second)
mng_info->need_fram=1;
+
#if defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED) || \
defined(PNG_MNG_FEATURES_SUPPORTED)
/*
*/
if (image->matte != MagickFalse)
need_local_plte=MagickTrue;
+
if (need_local_plte == 0)
{
if (ImageIsGray(image) == MagickFalse)
next_image->background_color.blue !=
next_image->next->background_color.blue)
mng_info->equal_backgrounds=MagickFalse;
+
if (next_image->gamma != next_image->next->gamma)
mng_info->equal_gammas=MagickFalse;
+
if (next_image->rendering_intent !=
next_image->next->rendering_intent)
mng_info->equal_srgbs=MagickFalse;
+
if ((next_image->units != next_image->next->units) ||
(next_image->x_resolution != next_image->next->x_resolution) ||
(next_image->y_resolution != next_image->next->y_resolution))
mng_info->equal_physs=MagickFalse;
+
if (mng_info->equal_chrms)
{
if (next_image->chromaticity.red_primary.x !=
#endif
need_iterations=MagickFalse;
}
+
if (mng_info->need_fram == MagickFalse)
{
/*
mng_info->ticks_per_second=(png_uint_32) (image->ticks_per_second/final_delay);
if (final_delay > 50)
mng_info->ticks_per_second=2;
+
if (final_delay > 75)
mng_info->ticks_per_second=1;
+
if (final_delay > 125)
mng_info->need_fram=MagickTrue;
+
if (need_defi && final_delay > 2 && (final_delay != 4) &&
(final_delay != 5) && (final_delay != 10) && (final_delay != 20) &&
(final_delay != 25) && (final_delay != 50) && (final_delay !=
1UL*image->ticks_per_second))
mng_info->need_fram=MagickTrue; /* make it exact; cannot be VLC */
}
+
if (mng_info->need_fram != MagickFalse)
mng_info->ticks_per_second=1UL*image->ticks_per_second;
/*
{
if (need_defi || mng_info->need_fram || use_global_plte)
PNGLong(chunk+28,27L); /* simplicity=LC+JNG */
+
else
PNGLong(chunk+28,25L); /* simplicity=VLC+JNG */
}
+
else
{
if (need_defi || mng_info->need_fram || use_global_plte)
PNGLong(chunk+28,19L); /* simplicity=LC+JNG, no transparency */
+
else
PNGLong(chunk+28,17L); /* simplicity=VLC+JNG, no transparency */
}
}
+
else
{
if (need_matte)
{
if (need_defi || mng_info->need_fram || use_global_plte)
PNGLong(chunk+28,11L); /* simplicity=LC */
+
else
PNGLong(chunk+28,9L); /* simplicity=VLC */
}
+
else
{
if (need_defi || mng_info->need_fram || use_global_plte)
PNGLong(chunk+28,3L); /* simplicity=LC, no transparency */
+
else
PNGLong(chunk+28,1L); /* simplicity=VLC, no transparency */
}
chunk[5]=0; /* show last frame when done */
PNGLong(chunk+6,(png_uint_32) (mng_info->ticks_per_second*
final_delay/MagickMax(image->ticks_per_second,1)));
+
if (image->iterations == 0)
PNGLong(chunk+10,PNG_UINT_31_MAX);
+
else
PNGLong(chunk+10,(png_uint_32) image->iterations);
+
if (logging != MagickFalse)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" TERM delay: %.20g",(double) (mng_info->ticks_per_second*
final_delay/MagickMax(image->ticks_per_second,1)));
+
if (image->iterations == 0)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" TERM iterations: %.20g",(double) PNG_UINT_31_MAX);
+
else
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Image iterations: %.20g",(double) image->iterations);
(void) WriteBlobMSBULong(image,1L);
PNGType(chunk,mng_sRGB);
LogPNGChunk((int) logging,mng_sRGB,1L);
+
if (image->rendering_intent != UndefinedIntent)
chunk[4]=(unsigned char)
PNG_RenderingIntent_from_Magick_RenderingIntent(
(image->rendering_intent));
+
else
chunk[4]=(unsigned char)
PNG_RenderingIntent_from_Magick_RenderingIntent(
(PerceptualIntent));
+
(void) WriteBlob(image,5,chunk);
(void) WriteBlobMSBULong(image,crc32(0,chunk,5));
mng_info->have_write_global_srgb=MagickTrue;
}
+
else
{
if (image->gamma && mng_info->equal_gammas)
(void) WriteBlobMSBULong(image,9L);
PNGType(chunk,mng_pHYs);
LogPNGChunk((int) logging,mng_pHYs,9L);
+
if (image->units == PixelsPerInchResolution)
{
PNGLong(chunk+4,(png_uint_32)
(image->x_resolution*100.0/2.54+0.5));
+
PNGLong(chunk+8,(png_uint_32)
(image->y_resolution*100.0/2.54+0.5));
+
chunk[12]=1;
}
+
else
{
if (image->units == PixelsPerCentimeterResolution)
{
PNGLong(chunk+4,(png_uint_32)
(image->x_resolution*100.0+0.5));
+
PNGLong(chunk+8,(png_uint_32)
(image->y_resolution*100.0+0.5));
+
chunk[12]=1;
}
+
else
{
PNGLong(chunk+4,(png_uint_32) (image->x_resolution+0.5));
(void) WriteBlobMSBULong(image,data_length);
PNGType(chunk,mng_PLTE);
LogPNGChunk((int) logging,mng_PLTE,data_length);
+
for (i=0; i < (ssize_t) image->colors; i++)
{
chunk[4+i*3]=ScaleQuantumToChar(image->colormap[i].red) & 0xff;
chunk[5+i*3]=ScaleQuantumToChar(image->colormap[i].green) & 0xff;
chunk[6+i*3]=ScaleQuantumToChar(image->colormap[i].blue) & 0xff;
}
+
(void) WriteBlob(image,data_length+4,chunk);
(void) WriteBlobMSBULong(image,crc32(0,chunk,(uInt) (data_length+4)));
mng_info->have_write_global_plte=MagickTrue;
(void) WriteBlobMSBULong(image,data_length);
PNGType(chunk,mng_PLTE);
LogPNGChunk((int) logging,mng_PLTE,data_length);
+
for (i=0; i < (ssize_t) image->colors; i++)
{
chunk[4+i*3]=ScaleQuantumToChar(image->colormap[i].red);
chunk[5+i*3]=ScaleQuantumToChar(image->colormap[i].green);
chunk[6+i*3]=ScaleQuantumToChar(image->colormap[i].blue);
}
+
(void) WriteBlob(image,data_length+4,chunk);
(void) WriteBlobMSBULong(image,crc32(0,chunk,
(uInt) (data_length+4)));
image=SyncNextImageInList(image);
status=SetImageProgress(image,SaveImagesTag,scene++,
GetImageListLength(image));
+
if (status == MagickFalse)
break;
+
} while (mng_info->adjoin);
+
if (write_mng)
{
while (GetPreviousImageInList(image) != (Image *) NULL)
*/
(void) CloseBlob(image);
MngInfoFreeStruct(mng_info,&have_mng_structure);
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),"exit WriteMNGImage()");
+
return(MagickTrue);
}
#else /* PNG_LIBPNG_VER > 10011 */
image=image;
printf("Your PNG library is too old: You have libpng-%s\n",
PNG_LIBPNG_VER_STRING);
+
ThrowBinaryException(CoderError,"PNG library is too old",
image_info->filename);
}