% You may not use this file except in compliance with the License. You may %
% obtain a copy of the License at %
% %
-% http://www.imagemagick.org/script/license.php %
+% https://www.imagemagick.org/script/license.php %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
Process warning message.
*/
(jpeg_info->err->format_message)(jpeg_info,message);
- if (jpeg_info->err->num_warnings++ > JPEGExcessiveWarnings)
- JPEGErrorHandler(jpeg_info);
- ThrowBinaryException(CorruptImageWarning,(char *) message,
- image->filename);
+ if (jpeg_info->err->num_warnings++ < JPEGExcessiveWarnings)
+ ThrowBinaryException(CorruptImageWarning,(char *) message,
+ image->filename);
}
else
if ((image->debug != MagickFalse) &&
if (previous_profile != (const StringInfo *) NULL)
{
size_t
- length;
+ profile_length;
- length=GetStringInfoLength(profile);
+ profile_length=GetStringInfoLength(profile);
SetStringInfoLength(profile,GetStringInfoLength(profile)+
GetStringInfoLength(previous_profile));
(void) memmove(GetStringInfoDatum(profile)+
GetStringInfoLength(previous_profile),GetStringInfoDatum(profile),
- length);
+ profile_length);
(void) memcpy(GetStringInfoDatum(profile),
GetStringInfoDatum(previous_profile),
GetStringInfoLength(previous_profile));
}
static void JPEGSetImageQuality(struct jpeg_decompress_struct *jpeg_info,
- Image *image, ExceptionInfo *exception)
+ Image *image)
{
image->quality=UndefinedCompressionQuality;
#if defined(D_PROGRESSIVE_SUPPORTED)
image=DestroyImageList(image);
return((Image *) NULL);
}
+ /*
+ Verify that file size large enough to contain a JPEG datastream.
+ */
+ if (GetBlobSize(image) < 107)
+ ThrowReaderException(CorruptImageError,"InsufficientImageDataInFile");
/*
Initialize JPEG parameters.
*/
if (AcquireImageColormap(image,StringToUnsignedLong(option),exception)
== MagickFalse)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
- if ((jpeg_info.output_components == 1) &&
- (jpeg_info.quantize_colors == MagickFalse))
+ if ((jpeg_info.output_components == 1) && (jpeg_info.quantize_colors == 0))
{
size_t
colors;
(void) LogMagickEvent(CoderEvent,GetMagickModule(),"Geometry: %dx%d",
(int) jpeg_info.output_width,(int) jpeg_info.output_height);
}
- JPEGSetImageQuality(&jpeg_info,image,exception);
+ JPEGSetImageQuality(&jpeg_info,image);
JPEGSetImageSamplingFactor(&jpeg_info,image,exception);
(void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
jpeg_info.out_color_space);
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
}
jpeg_pixels=(JSAMPLE *) GetVirtualMemoryBlob(memory_info);
+ (void) ResetMagickMemory(jpeg_pixels,0,image->columns*
+ jpeg_info.output_components*sizeof(*jpeg_pixels));
/*
Convert JPEG pixels to pixel packets.
*/
return(GetFirstImageInList(image));
return(DestroyImage(image));
}
- if (jpeg_info.quantize_colors != MagickFalse)
+ if (jpeg_info.quantize_colors != 0)
{
image->colors=(size_t) jpeg_info.actual_number_of_colors;
if (jpeg_info.out_color_space == JCS_GRAYSCALE)
jpeg_info.colormap[0][i]);
image->colormap[i].green=image->colormap[i].red;
image->colormap[i].blue=image->colormap[i].red;
- image->colormap[i].alpha=OpaqueAlpha;
+ image->colormap[i].alpha=(MagickRealType) OpaqueAlpha;
}
else
for (i=0; i < (ssize_t) image->colors; i++)
jpeg_info.colormap[1][i]);
image->colormap[i].blue=(double) ScaleCharToQuantum(
jpeg_info.colormap[2][i]);
- image->colormap[i].alpha=OpaqueAlpha;
+ image->colormap[i].alpha=(MagickRealType) OpaqueAlpha;
}
}
scanline[0]=(JSAMPROW) jpeg_pixels;
x;
register Quantum
- *restrict q;
+ *magick_restrict q;
if (jpeg_read_scanlines(&jpeg_info,scanline,1) != 1)
{
unsigned short
scale;
- scale=65535U/GetQuantumRange(jpeg_info.data_precision);
+ scale=65535/(unsigned short) GetQuantumRange((size_t)
+ jpeg_info.data_precision);
if (jpeg_info.output_components == 1)
for (x=0; x < (ssize_t) image->columns; x++)
{
- size_t
+ ssize_t
pixel;
- pixel=(size_t) (scale*GETJSAMPLE(*p));
- index=ConstrainColormapIndex(image,pixel,exception);
+ pixel=(ssize_t) (scale*GETJSAMPLE(*p));
+ index=(Quantum) ConstrainColormapIndex(image,pixel,exception);
SetPixelIndex(image,index,q);
SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q);
p++;
if (image->colorspace != CMYKColorspace)
for (x=0; x < (ssize_t) image->columns; x++)
{
- SetPixelRed(image,ScaleShortToQuantum(scale*GETJSAMPLE(*p++)),
- q);
- SetPixelGreen(image,ScaleShortToQuantum(scale*GETJSAMPLE(*p++)),
- q);
- SetPixelBlue(image,ScaleShortToQuantum(scale*GETJSAMPLE(*p++)),
- q);
+ SetPixelRed(image,ScaleShortToQuantum(
+ (unsigned short) (scale*GETJSAMPLE(*p++))),q);
+ SetPixelGreen(image,ScaleShortToQuantum(
+ (unsigned short) (scale*GETJSAMPLE(*p++))),q);
+ SetPixelBlue(image,ScaleShortToQuantum(
+ (unsigned short) (scale*GETJSAMPLE(*p++))),q);
SetPixelAlpha(image,OpaqueAlpha,q);
q+=GetPixelChannels(image);
}
else
for (x=0; x < (ssize_t) image->columns; x++)
{
- SetPixelCyan(image,QuantumRange-ScaleShortToQuantum(scale*
- GETJSAMPLE(*p++)),q);
- SetPixelMagenta(image,QuantumRange-ScaleShortToQuantum(scale*
- GETJSAMPLE(*p++)),q);
- SetPixelYellow(image,QuantumRange-ScaleShortToQuantum(scale*
- GETJSAMPLE(*p++)),q);
- SetPixelBlack(image,QuantumRange-ScaleShortToQuantum(scale*
- GETJSAMPLE(*p++)),q);
+ SetPixelCyan(image,QuantumRange-ScaleShortToQuantum(
+ (unsigned short) (scale*GETJSAMPLE(*p++))),q);
+ SetPixelMagenta(image,QuantumRange-ScaleShortToQuantum(
+ (unsigned short) (scale*GETJSAMPLE(*p++))),q);
+ SetPixelYellow(image,QuantumRange-ScaleShortToQuantum(
+ (unsigned short) (scale*GETJSAMPLE(*p++))),q);
+ SetPixelBlack(image,QuantumRange-ScaleShortToQuantum(
+ (unsigned short) (scale*GETJSAMPLE(*p++))),q);
SetPixelAlpha(image,OpaqueAlpha,q);
q+=GetPixelChannels(image);
}
if (jpeg_info.output_components == 1)
for (x=0; x < (ssize_t) image->columns; x++)
{
- index=ConstrainColormapIndex(image,(size_t) GETJSAMPLE(*p),exception);
+ index=(Quantum) ConstrainColormapIndex(image,(ssize_t) GETJSAMPLE(*p),
+ exception);
SetPixelIndex(image,index,q);
SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q);
p++;
#endif
entry=AcquireMagickInfo("JPEG","JPE",JPEGDescription);
#if (JPEG_LIB_VERSION < 80) && !defined(LIBJPEG_TURBO_VERSION)
- entry->thread_support=NoThreadSupport;
+ entry->flags^=CoderDecoderThreadSupportFlag;
#endif
#if defined(MAGICKCORE_JPEG_DELEGATE)
entry->decoder=(DecodeImageHandler *) ReadJPEGImage;
entry->encoder=(EncodeImageHandler *) WriteJPEGImage;
#endif
entry->magick=(IsImageFormatHandler *) IsJPEG;
+ entry->flags|=CoderDecoderSeekableStreamFlag;
entry->flags^=CoderAdjoinFlag;
entry->flags^=CoderUseExtensionFlag;
if (*version != '\0')
(void) RegisterMagickInfo(entry);
entry=AcquireMagickInfo("JPEG","JPEG",JPEGDescription);
#if (JPEG_LIB_VERSION < 80) && !defined(LIBJPEG_TURBO_VERSION)
- entry->thread_support=NoThreadSupport;
+ entry->flags^=CoderDecoderThreadSupportFlag;
#endif
#if defined(MAGICKCORE_JPEG_DELEGATE)
entry->decoder=(DecodeImageHandler *) ReadJPEGImage;
entry->encoder=(EncodeImageHandler *) WriteJPEGImage;
#endif
entry->magick=(IsImageFormatHandler *) IsJPEG;
+ entry->flags|=CoderDecoderSeekableStreamFlag;
entry->flags^=CoderAdjoinFlag;
if (*version != '\0')
entry->version=ConstantString(version);
(void) RegisterMagickInfo(entry);
entry=AcquireMagickInfo("JPEG","JPG",JPEGDescription);
#if (JPEG_LIB_VERSION < 80) && !defined(LIBJPEG_TURBO_VERSION)
- entry->thread_support=NoThreadSupport;
+ entry->flags^=CoderDecoderThreadSupportFlag;
#endif
#if defined(MAGICKCORE_JPEG_DELEGATE)
entry->decoder=(DecodeImageHandler *) ReadJPEGImage;
entry->encoder=(EncodeImageHandler *) WriteJPEGImage;
#endif
+ entry->flags|=CoderDecoderSeekableStreamFlag;
entry->flags^=CoderAdjoinFlag;
entry->flags^=CoderUseExtensionFlag;
if (*version != '\0')
(void) RegisterMagickInfo(entry);
entry=AcquireMagickInfo("JPEG","JPS",JPEGDescription);
#if (JPEG_LIB_VERSION < 80) && !defined(LIBJPEG_TURBO_VERSION)
- entry->thread_support=NoThreadSupport;
+ entry->flags^=CoderDecoderThreadSupportFlag;
#endif
#if defined(MAGICKCORE_JPEG_DELEGATE)
entry->decoder=(DecodeImageHandler *) ReadJPEGImage;
entry->encoder=(EncodeImageHandler *) WriteJPEGImage;
#endif
+ entry->flags|=CoderDecoderSeekableStreamFlag;
entry->flags^=CoderAdjoinFlag;
entry->flags^=CoderUseExtensionFlag;
if (*version != '\0')
(void) RegisterMagickInfo(entry);
entry=AcquireMagickInfo("JPEG","PJPEG",JPEGDescription);
#if (JPEG_LIB_VERSION < 80) && !defined(LIBJPEG_TURBO_VERSION)
- entry->thread_support=NoThreadSupport;
+ entry->flags^=CoderDecoderThreadSupportFlag;
#endif
#if defined(MAGICKCORE_JPEG_DELEGATE)
entry->decoder=(DecodeImageHandler *) ReadJPEGImage;
entry->encoder=(EncodeImageHandler *) WriteJPEGImage;
#endif
+ entry->flags|=CoderDecoderSeekableStreamFlag;
entry->flags^=CoderAdjoinFlag;
entry->flags^=CoderUseExtensionFlag;
if (*version != '\0')
if (description == (XMLTreeInfo *) NULL)
{
(void) ThrowMagickException(exception,GetMagickModule(),OptionError,
- "XmlMissingElement", "<description>, slot \"%s\"",slot);
+ "XmlMissingElement","<description>, slot \"%s\"",slot);
quantization_tables=DestroyXMLTree(quantization_tables);
xml=DestroyString(xml);
return(table);
if (levels == (XMLTreeInfo *) NULL)
{
(void) ThrowMagickException(exception,GetMagickModule(),OptionError,
- "XmlMissingElement", "<levels>, slot \"%s\"", slot);
+ "XmlMissingElement","<levels>, slot \"%s\"",slot);
quantization_tables=DestroyXMLTree(quantization_tables);
xml=DestroyString(xml);
return(table);
if (attribute == (char *) NULL)
{
(void) ThrowMagickException(exception,GetMagickModule(),OptionError,
- "XmlMissingAttribute", "<levels width>, slot \"%s\"",slot);
+ "XmlMissingAttribute","<levels width>, slot \"%s\"",slot);
quantization_tables=DestroyXMLTree(quantization_tables);
table=DestroyQuantizationTable(table);
xml=DestroyString(xml);
if (table->width == 0)
{
(void) ThrowMagickException(exception,GetMagickModule(),OptionError,
- "XmlInvalidAttribute", "<levels width>, table \"%s\"",slot);
+ "XmlInvalidAttribute","<levels width>, table \"%s\"",slot);
quantization_tables=DestroyXMLTree(quantization_tables);
table=DestroyQuantizationTable(table);
xml=DestroyString(xml);
if (attribute == (char *) NULL)
{
(void) ThrowMagickException(exception,GetMagickModule(),OptionError,
- "XmlMissingAttribute", "<levels height>, table \"%s\"",slot);
+ "XmlMissingAttribute","<levels height>, table \"%s\"",slot);
quantization_tables=DestroyXMLTree(quantization_tables);
table=DestroyQuantizationTable(table);
xml=DestroyString(xml);
if (table->height == 0)
{
(void) ThrowMagickException(exception,GetMagickModule(),OptionError,
- "XmlInvalidAttribute", "<levels height>, table \"%s\"",slot);
+ "XmlInvalidAttribute","<levels height>, table \"%s\"",slot);
quantization_tables=DestroyXMLTree(quantization_tables);
table=DestroyQuantizationTable(table);
xml=DestroyString(xml);
if (attribute == (char *) NULL)
{
(void) ThrowMagickException(exception,GetMagickModule(),OptionError,
- "XmlMissingAttribute", "<levels divisor>, table \"%s\"",slot);
+ "XmlMissingAttribute","<levels divisor>, table \"%s\"",slot);
quantization_tables=DestroyXMLTree(quantization_tables);
table=DestroyQuantizationTable(table);
xml=DestroyString(xml);
if (table->divisor == 0.0)
{
(void) ThrowMagickException(exception,GetMagickModule(),OptionError,
- "XmlInvalidAttribute", "<levels divisor>, table \"%s\"",slot);
+ "XmlInvalidAttribute","<levels divisor>, table \"%s\"",slot);
quantization_tables=DestroyXMLTree(quantization_tables);
table=DestroyQuantizationTable(table);
xml=DestroyString(xml);
if (content == (char *) NULL)
{
(void) ThrowMagickException(exception,GetMagickModule(),OptionError,
- "XmlMissingContent", "<levels>, table \"%s\"",slot);
+ "XmlMissingContent","<levels>, table \"%s\"",slot);
quantization_tables=DestroyXMLTree(quantization_tables);
table=DestroyQuantizationTable(table);
xml=DestroyString(xml);
if (p != content)
{
(void) ThrowMagickException(exception,GetMagickModule(),OptionError,
- "XmlInvalidContent", "<level> too many values, table \"%s\"",slot);
+ "XmlInvalidContent","<level> too many values, table \"%s\"",slot);
quantization_tables=DestroyXMLTree(quantization_tables);
table=DestroyQuantizationTable(table);
xml=DestroyString(xml);
}
}
-static void WriteProfile(j_compress_ptr jpeg_info,Image *image)
+static void WriteProfile(j_compress_ptr jpeg_info,Image *image,
+ ExceptionInfo *exception)
{
const char
*name;
ResetImageProfileIterator(image);
for (name=GetNextImageProfile(image); name != (const char *) NULL; )
{
- register unsigned char
- *p;
-
profile=GetImageProfile(image,name);
- p=GetStringInfoDatum(custom_profile);
if (LocaleCompare(name,"EXIF") == 0)
- for (i=0; i < (ssize_t) GetStringInfoLength(profile); i+=65533L)
{
- length=MagickMin(GetStringInfoLength(profile)-i,65533L);
- jpeg_write_marker(jpeg_info,XML_MARKER,GetStringInfoDatum(profile)+i,
+ length=GetStringInfoLength(profile);
+ if (length > 65533L)
+ {
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ CoderWarning,"ExifProfileSizeExceedsLimit","`%s'",
+ image->filename);
+ length=65533L;
+ }
+ jpeg_write_marker(jpeg_info,XML_MARKER,GetStringInfoDatum(profile),
(unsigned int) length);
}
if (LocaleCompare(name,"ICC") == 0)
if (((LocaleCompare(name,"IPTC") == 0) ||
(LocaleCompare(name,"8BIM") == 0)) && (iptc == MagickFalse))
{
+ register unsigned char
+ *p;
+
size_t
roundup;
iptc=MagickTrue;
+ p=GetStringInfoDatum(custom_profile);
for (i=0; i < (ssize_t) GetStringInfoLength(profile); i+=65500L)
{
length=MagickMin(GetStringInfoLength(profile)-i,65500L);
register ssize_t
i;
- size_t
- lines;
-
if (text == (char *) NULL)
return((char **) NULL);
/*
Convert string to an ASCII list.
*/
- lines=1;
- for (p=text; *p != '\0'; p++)
- if (*p == ',')
- lines++;
- textlist=(char **) AcquireQuantumMemory((size_t) lines+MagickPathExtent,
+ textlist=(char **) AcquireQuantumMemory((size_t) MAX_COMPONENTS,
sizeof(*textlist));
if (textlist == (char **) NULL)
ThrowFatalException(ResourceLimitFatalError,"UnableToConvertText");
p=text;
- for (i=0; i < (ssize_t) lines; i++)
+ for (i=0; i < (ssize_t) MAX_COMPONENTS; i++)
{
for (q=(char *) p; *q != '\0'; q++)
if (*q == ',')
(void) CopyMagickString(textlist[i],p,(size_t) (q-p+1));
if (*q == '\r')
q++;
+ if (*q == '\0')
+ break;
p=q+1;
}
- textlist[i]=(char *) NULL;
+ for (i++; i < (ssize_t) MAX_COMPONENTS; i++)
+ textlist[i]=ConstantString("1x1");
return(textlist);
}
jpeg_info.data_precision=BITS_IN_JSAMPLE;
if (image->debug != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- "Image resolution: %.20g,%.20g",floor(image->resolution.x+0.5),
- floor(image->resolution.y+0.5));
+ "Image resolution: %.20g,%.20g",image->resolution.x,image->resolution.y);
if ((image->resolution.x != 0.0) && (image->resolution.y != 0.0))
{
/*
Set image resolution.
*/
jpeg_info.write_JFIF_header=TRUE;
- jpeg_info.X_density=(UINT16) floor(image->resolution.x+0.5);
- jpeg_info.Y_density=(UINT16) floor(image->resolution.y+0.5);
+ jpeg_info.X_density=(UINT16) image->resolution.x;
+ jpeg_info.Y_density=(UINT16) image->resolution.y;
/*
Set image resolution units.
*/
#else
if (image->quality < 100)
(void) ThrowMagickException(exception,GetMagickModule(),CoderWarning,
- "LosslessToLossyJPEGConversion",image->filename);
+ "LosslessToLossyJPEGConversion","`%s'",image->filename);
else
{
int
*jpeg_image;
ImageInfo
- *jpeg_info;
+ *extent_info;
- jpeg_info=CloneImageInfo(image_info);
- jpeg_info->blob=NULL;
+ extent_info=CloneImageInfo(image_info);
+ extent_info->blob=NULL;
jpeg_image=CloneImage(image,0,0,MagickTrue,exception);
if (jpeg_image != (Image *) NULL)
{
/*
Search for compression quality that does not exceed image extent.
*/
- jpeg_info->quality=0;
+ extent_info->quality=0;
extent=(MagickSizeType) SiPrefixToDoubleInterval(option,100.0);
- (void) DeleteImageOption(jpeg_info,"jpeg:extent");
+ (void) DeleteImageOption(extent_info,"jpeg:extent");
(void) DeleteImageArtifact(jpeg_image,"jpeg:extent");
- maximum=image->quality;
+ maximum=image_info->quality;
if (maximum < 2)
- maximum=2;
+ maximum=101;
for (minimum=2; minimum < maximum; )
{
(void) AcquireUniqueFilename(jpeg_image->filename);
jpeg_image->quality=minimum+(maximum-minimum+1)/2;
- status=WriteJPEGImage(jpeg_info,jpeg_image,exception);
+ status=WriteJPEGImage(extent_info,jpeg_image,exception);
if (GetBlobSize(jpeg_image) <= extent)
minimum=jpeg_image->quality+1;
else
quality=(int) minimum-1;
jpeg_image=DestroyImage(jpeg_image);
}
- jpeg_info=DestroyImageInfo(jpeg_info);
+ extent_info=DestroyImageInfo(extent_info);
}
jpeg_set_quality(&jpeg_info,quality,TRUE);
#if (JPEG_LIB_VERSION >= 70)
jpeg_write_marker(&jpeg_info,JPEG_COM,(unsigned char *) value+i,
(unsigned int) MagickMin((size_t) strlen(value+i),65533L));
if (image->profiles != (void *) NULL)
- WriteProfile(&jpeg_info,image);
+ WriteProfile(&jpeg_info,image,exception);
/*
Convert MIFF to JPEG raster pixels.
*/
return(MagickFalse);
}
scanline[0]=(JSAMPROW) jpeg_pixels;
- scale=65535U/GetQuantumRange(jpeg_info.data_precision);
+ scale=65535/(unsigned short) GetQuantumRange((size_t)
+ jpeg_info.data_precision);
if (scale == 0)
- scale=1;
+ scale=1;
if (jpeg_info.data_precision <= 8)
{
if ((jpeg_info.in_color_space == JCS_RGB) ||