% July 1992 %
% %
% %
-% Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization %
% dedicated to making software imaging solutions freely available. %
% %
% You may not use this file except in compliance with the License. You may %
#include <setjmp.h>
#if defined(MAGICKCORE_JPEG_DELEGATE)
#define JPEG_INTERNAL_OPTIONS
-#if defined(__MINGW32__)
+#if defined(__MINGW32__) || defined(__MINGW64__)
# define XMD_H 1 /* Avoid conflicting typedef for INT32 */
-typedef unsigned char boolean;
-#define HAVE_BOOLEAN
#endif
#undef HAVE_STDLIB_H
#include "jpeglib.h"
MagickBooleanType
finished;
+ StringInfo
+ *profile;
+
jmp_buf
error_recovery;
} ErrorManager;
static boolean ReadComment(j_decompress_ptr jpeg_info)
{
- char
- *comment;
-
ErrorManager
*error_manager;
Image
*image;
- register char
+ register unsigned char
*p;
register ssize_t
size_t
length;
+ StringInfo
+ *comment;
+
/*
Determine length of comment.
*/
length-=2;
if (length <= 0)
return(MagickTrue);
- comment=(char *) NULL;
- if (~length >= (MaxTextExtent-1))
- comment=(char *) AcquireQuantumMemory(length+MaxTextExtent,
- sizeof(*comment));
- if (comment == (char *) NULL)
+ comment=BlobToStringInfo((const void *) NULL,length);
+ if (comment == (StringInfo *) NULL)
ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
image->filename);
/*
Read comment.
*/
- i=(ssize_t) length-1;
- for (p=comment; i-- >= 0; p++)
- *p=(char) GetCharacter(jpeg_info);
+ error_manager->profile=comment;
+ p=GetStringInfoDatum(comment);
+ for (i=0; i < (ssize_t) GetStringInfoLength(comment); i++)
+ *p++=(unsigned char) GetCharacter(jpeg_info);
*p='\0';
- (void) SetImageProperty(image,"comment",comment,exception);
- comment=DestroyString(comment);
+ error_manager->profile=NULL;
+ p=GetStringInfoDatum(comment);
+ (void) SetImageProperty(image,"comment",(const char *) p,exception);
+ comment=DestroyStringInfo(comment);
return(MagickTrue);
}
if (profile == (StringInfo *) NULL)
ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
image->filename);
+ error_manager->profile=profile;
p=GetStringInfoDatum(profile);
for (i=(ssize_t) GetStringInfoLength(profile)-1; i >= 0; i--)
*p++=(unsigned char) GetCharacter(jpeg_info);
+ error_manager->profile=NULL;
icc_profile=(StringInfo *) GetImageProfile(image,"icc");
if (icc_profile != (StringInfo *) NULL)
{
if (profile == (StringInfo *) NULL)
ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
image->filename);
+ error_manager->profile=profile;
p=GetStringInfoDatum(profile);
for (i=0; i < (ssize_t) GetStringInfoLength(profile); i++)
*p++=(unsigned char) GetCharacter(jpeg_info);
+ error_manager->profile=NULL;
iptc_profile=(StringInfo *) GetImageProfile(image,"8bim");
if (iptc_profile != (StringInfo *) NULL)
{
if (profile == (StringInfo *) NULL)
ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
image->filename);
+ error_manager->profile=profile;
p=GetStringInfoDatum(profile);
for (i=0; i < (ssize_t) GetStringInfoLength(profile); i++)
*p++=(unsigned char) GetCharacter(jpeg_info);
+ error_manager->profile=NULL;
if (marker == 1)
{
p=GetStringInfoDatum(profile);
*image;
JSAMPLE
- *jpeg_pixels;
+ *volatile jpeg_pixels;
JSAMPROW
scanline[1];
if (setjmp(error_manager.error_recovery) != 0)
{
jpeg_destroy_decompress(&jpeg_info);
+ if (error_manager.profile != (StringInfo *) NULL)
+ error_manager.profile=DestroyStringInfo(error_manager.profile);
(void) CloseBlob(image);
number_pixels=(MagickSizeType) image->columns*image->rows;
if (number_pixels != 0)
case JCS_RGB:
default:
{
- SetImageColorspace(image,sRGBColorspace,exception);
+ (void) SetImageColorspace(image,sRGBColorspace,exception);
break;
}
case JCS_GRAYSCALE:
{
- SetImageColorspace(image,GRAYColorspace,exception);
+ (void) SetImageColorspace(image,GRAYColorspace,exception);
break;
}
case JCS_YCbCr:
{
- SetImageColorspace(image,YCbCrColorspace,exception);
+ (void) SetImageColorspace(image,YCbCrColorspace,exception);
break;
}
case JCS_CMYK:
{
- SetImageColorspace(image,CMYKColorspace,exception);
+ (void) SetImageColorspace(image,CMYKColorspace,exception);
break;
}
}
if (IsITUFaxImage(image) != MagickFalse)
{
- SetImageColorspace(image,LabColorspace,exception);
+ (void) SetImageColorspace(image,LabColorspace,exception);
jpeg_info.out_color_space=JCS_YCbCr;
}
option=GetImageOption(image_info,"jpeg:colors");
*/
if (setjmp(error_manager.error_recovery) != 0)
{
- if (jpeg_pixels != (unsigned char *) NULL)
- jpeg_pixels=(unsigned char *) RelinquishMagickMemory(jpeg_pixels);
+ if (jpeg_pixels != (JSAMPLE *) NULL)
+ jpeg_pixels=(JSAMPLE *) RelinquishMagickMemory(jpeg_pixels);
jpeg_destroy_decompress(&jpeg_info);
(void) CloseBlob(image);
number_pixels=(MagickSizeType) image->columns*image->rows;
Free jpeg resources.
*/
jpeg_destroy_decompress(&jpeg_info);
- jpeg_pixels=(unsigned char *) RelinquishMagickMemory(jpeg_pixels);
+ jpeg_pixels=(JSAMPLE *) RelinquishMagickMemory(jpeg_pixels);
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
quality;
JSAMPLE
- *jpeg_pixels;
+ *volatile jpeg_pixels;
JSAMPROW
scanline[1];
break;
}
case GRAYColorspace:
- case Rec601LumaColorspace:
- case Rec709LumaColorspace:
{
jpeg_info.input_components=1;
jpeg_info.in_color_space=JCS_GRAYSCALE;
jpeg_info.in_color_space=JCS_GRAYSCALE;
}
jpeg_set_defaults(&jpeg_info);
+ if (jpeg_info.in_color_space == JCS_CMYK)
+ jpeg_set_colorspace(&jpeg_info,JCS_YCCK);
if ((jpeg_info.data_precision != 12) && (image->depth <= 8))
jpeg_info.data_precision=8;
else
}
#endif
sampling_factor=(const char *) NULL;
- value=GetImageProperty(image,"jpeg:sampling-factor",exception);
+ value=GetImageOption(image_info,"jpeg:sampling-factor");
+ if (value == (char *) NULL)
+ value=GetImageProperty(image,"jpeg:sampling-factor",exception);
if (value != (char *) NULL)
{
sampling_factor=value;
break;
}
case GRAYColorspace:
- case Rec601LumaColorspace:
- case Rec709LumaColorspace:
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
"Colorspace: GRAY");
if (setjmp(error_manager.error_recovery) != 0)
{
jpeg_destroy_compress(&jpeg_info);
- if (jpeg_pixels != (unsigned char *) NULL)
- jpeg_pixels=(unsigned char *) RelinquishMagickMemory(jpeg_pixels);
+ if (jpeg_pixels != (JSAMPLE *) NULL)
+ jpeg_pixels=(JSAMPLE *) RelinquishMagickMemory(jpeg_pixels);
(void) CloseBlob(image);
return(MagickFalse);
}
Convert DirectClass packets to contiguous CMYK scanlines.
*/
*q++=(JSAMPLE) (ScaleQuantumToChar((Quantum) (QuantumRange-
- GetPixelRed(image,p))));
+ GetPixelCyan(image,p))));
*q++=(JSAMPLE) (ScaleQuantumToChar((Quantum) (QuantumRange-
- GetPixelGreen(image,p))));
+ GetPixelMagenta(image,p))));
*q++=(JSAMPLE) (ScaleQuantumToChar((Quantum) (QuantumRange-
- GetPixelBlue(image,p))));
+ GetPixelYellow(image,p))));
*q++=(JSAMPLE) (ScaleQuantumToChar((Quantum) (QuantumRange-
GetPixelBlack(image,p))));
p+=GetPixelChannels(image);
Relinquish resources.
*/
jpeg_destroy_compress(&jpeg_info);
- jpeg_pixels=(unsigned char *) RelinquishMagickMemory(jpeg_pixels);
+ jpeg_pixels=(JSAMPLE *) RelinquishMagickMemory(jpeg_pixels);
(void) CloseBlob(image);
return(MagickTrue);
}