% July 1992 %
% %
% %
-% Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2011 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 %
#if defined(__MINGW32__)
# define XMD_H 1 /* Avoid conflicting typedef for INT32 */
typedef unsigned char boolean;
+#define HAVE_BOOLEAN
#endif
#undef HAVE_STDLIB_H
#include "jpeglib.h"
*source;
source=(SourceManager *) cinfo->src;
- source->manager.bytes_in_buffer=(size_t)
- ReadBlob(source->image,MaxBufferExtent,source->buffer);
+ source->manager.bytes_in_buffer=(size_t) ReadBlob(source->image,
+ MaxBufferExtent,source->buffer);
if (source->manager.bytes_in_buffer == 0)
{
if (source->start_of_blob != 0)
}
if (image->debug != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- "Profile: ICC, %lu bytes",(size_t) length);
+ "Profile: ICC, %.20g bytes",(double) length);
return(MagickTrue);
}
ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
image->filename);
p=GetStringInfoDatum(profile);
- for (i=(ssize_t) GetStringInfoLength(profile)-1; i >= 0; i--)
+ for (i=0; i < (ssize_t) GetStringInfoLength(profile); i++)
*p++=(unsigned char) GetCharacter(jpeg_info);
iptc_profile=(StringInfo *) GetImageProfile(image,"8bim");
if (iptc_profile != (StringInfo *) NULL)
}
if (image->debug != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- "Profile: iptc, %lu bytes",(size_t) length);
+ "Profile: iptc, %.20g bytes",(double) length);
return(MagickTrue);
}
image->filename);
if (image->debug != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- "Profile: %s, %lu bytes",name,(size_t) length);
+ "Profile: %s, %.20g bytes",name,(double) length);
return(MagickTrue);
}
-static void SkipInputData(j_decompress_ptr cinfo,ssize_t number_bytes)
+static void SkipInputData(j_decompress_ptr cinfo,long number_bytes)
{
SourceManager
*source;
if (number_bytes <= 0)
return;
source=(SourceManager *) cinfo->src;
- while (number_bytes > (ssize_t) source->manager.bytes_in_buffer)
+ while (number_bytes > (long) source->manager.bytes_in_buffer)
{
- number_bytes-=(ssize_t) source->manager.bytes_in_buffer;
+ number_bytes-=(long) source->manager.bytes_in_buffer;
(void) FillInputBuffer(cinfo);
}
- source->manager.next_input_byte+=(size_t) number_bytes;
- source->manager.bytes_in_buffer-=(size_t) number_bytes;
+ source->manager.next_input_byte+=number_bytes;
+ source->manager.bytes_in_buffer-=number_bytes;
}
static void TerminateSource(j_decompress_ptr cinfo)
image->quality=(size_t) i+1;
if (image->debug != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- "Quality: %ld (%s)",i+1,(qvalue <= hash[i]) &&
+ "Quality: %.20g (%s)",(double) i+1,(qvalue <= hash[i]) &&
(sum <= sums[i]) ? "exact" : "approximate");
break;
}
image->quality=(size_t) i+1;
if (image->debug != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- "Quality: %ld (%s)",i+1,(qvalue <= hash[i]) &&
+ "Quality: %.20g (%s)",(double) i+1,(qvalue <= hash[i]) &&
(sum <= sums[i]) ? "exact" : "approximate");
break;
}
IndexPacket
index;
- ssize_t
- y;
-
JSAMPLE
*jpeg_pixels;
precision,
units;
+ ssize_t
+ y;
+
/*
Open image file.
*/
assert(exception != (ExceptionInfo *) NULL);
assert(exception->signature == MagickSignature);
debug=IsEventLogging();
+ (void) debug;
image=AcquireImage(image_info);
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
if (status == MagickFalse)
/*
Initialize JPEG parameters.
*/
+ (void) ResetMagickMemory(&error_manager,0,sizeof(error_manager));
(void) ResetMagickMemory(&jpeg_info,0,sizeof(jpeg_info));
(void) ResetMagickMemory(&jpeg_error,0,sizeof(jpeg_error));
jpeg_info.err=jpeg_std_error(&jpeg_error);
for (i=1; i < 16; i++)
if ((i != 2) && (i != 13) && (i != 14))
jpeg_set_marker_processor(&jpeg_info,(int) (JPEG_APP0+i),ReadProfile);
- i=jpeg_read_header(&jpeg_info,MagickTrue);
+ i=(ssize_t) jpeg_read_header(&jpeg_info,MagickTrue);
if ((image_info->colorspace == YCbCrColorspace) ||
(image_info->colorspace == Rec601YCbCrColorspace) ||
(image_info->colorspace == Rec709YCbCrColorspace))
jpeg_info.scale_denom=(unsigned int) scale_factor;
jpeg_calc_output_dimensions(&jpeg_info);
if (image->debug != MagickFalse)
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),"Scale factor: %ld",
- (ssize_t) scale_factor);
+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+ "Scale factor: %.20g",(double) scale_factor);
}
precision=(size_t) jpeg_info.data_precision;
#if (JPEG_LIB_VERSION >= 61) && defined(D_PROGRESSIVE_SUPPORTED)
}
JPEGSetImageQuality(&jpeg_info,image);
JPEGSetImageSamplingFactor(&jpeg_info,image);
- (void) FormatMagickString(value,MaxTextExtent,"%ld",(ssize_t)
+ (void) FormatMagickString(value,MaxTextExtent,"%.20g",(double)
jpeg_info.out_color_space);
(void) SetImageProperty(image,"jpeg:colorspace",value);
if (image_info->ping != MagickFalse)
else
pixel=(size_t) ((GETJSAMPLE(*p) ^ 0x80) << 4);
index=ConstrainColormapIndex(image,pixel);
- indexes[x]=index;
- *q++=image->colormap[(int) index];
+ SetIndexPixelComponent(indexes+x,index);
+ SetRedPixelComponent(q,image->colormap[(int) index].red);
+ SetGreenPixelComponent(q,image->colormap[(int) index].green);
+ SetBluePixelComponent(q,image->colormap[(int) index].blue);
p++;
+ q++;
}
else
if (image->colorspace != CMYKColorspace)
for (x=0; x < (ssize_t) image->columns; x++)
{
- q->red=ScaleShortToQuantum((unsigned char)
- (GETJSAMPLE(*p++) << 4));
- q->green=ScaleShortToQuantum((unsigned char)
- (GETJSAMPLE(*p++) << 4));
- q->blue=ScaleShortToQuantum((unsigned char)
- (GETJSAMPLE(*p++) << 4));
+ SetRedPixelComponent(q,ScaleShortToQuantum((unsigned char)
+ (GETJSAMPLE(*p++) << 4)));
+ SetGreenPixelComponent(q,ScaleShortToQuantum((unsigned char)
+ (GETJSAMPLE(*p++) << 4)));
+ SetBluePixelComponent(q,ScaleShortToQuantum((unsigned char)
+ (GETJSAMPLE(*p++) << 4)));
SetOpacityPixelComponent(q,OpaqueOpacity);
q++;
}
else
for (x=0; x < (ssize_t) image->columns; x++)
{
- q->red=(Quantum) QuantumRange-ScaleShortToQuantum((unsigned char)
- (GETJSAMPLE(*p++) << 4));
- q->green=(Quantum) QuantumRange-ScaleShortToQuantum(
- (unsigned char) (GETJSAMPLE(*p++) << 4));
- q->blue=(Quantum) QuantumRange-ScaleShortToQuantum((unsigned char)
- (GETJSAMPLE(*p++) << 4));
+ SetCyanPixelComponent(q,QuantumRange-ScaleShortToQuantum(
+ (unsigned char) (GETJSAMPLE(*p++) << 4)));
+ SetMagentaPixelComponent(q,QuantumRange-ScaleShortToQuantum(
+ (unsigned char) (GETJSAMPLE(*p++) << 4)));
+ SetYellowPixelComponent(q,QuantumRange-ScaleShortToQuantum(
+ (unsigned char) (GETJSAMPLE(*p++) << 4)));
+ SetBlackPixelComponent(indexes+x,QuantumRange-ScaleShortToQuantum(
+ (unsigned char) (GETJSAMPLE(*p++) << 4)));
SetOpacityPixelComponent(q,OpaqueOpacity);
- indexes[x]=(IndexPacket) QuantumRange-ScaleShortToQuantum(
- (unsigned char) (GETJSAMPLE(*p++) << 4));
q++;
}
}
for (x=0; x < (ssize_t) image->columns; x++)
{
index=ConstrainColormapIndex(image,(size_t) GETJSAMPLE(*p));
- indexes[x]=(IndexPacket) index;
- *q++=image->colormap[(int) index];
+ SetIndexPixelComponent(indexes+x,index);
+ SetRedPixelComponent(q,image->colormap[(int) index].red);
+ SetGreenPixelComponent(q,image->colormap[(int) index].green);
+ SetBluePixelComponent(q,image->colormap[(int) index].blue);
p++;
+ q++;
}
else
if (image->colorspace != CMYKColorspace)
for (x=0; x < (ssize_t) image->columns; x++)
{
- q->red=ScaleCharToQuantum((unsigned char) GETJSAMPLE(*p++));
- q->green=ScaleCharToQuantum((unsigned char) GETJSAMPLE(*p++));
- q->blue=ScaleCharToQuantum((unsigned char) GETJSAMPLE(*p++));
+ SetRedPixelComponent(q,ScaleCharToQuantum((unsigned char)
+ GETJSAMPLE(*p++)));
+ SetGreenPixelComponent(q,ScaleCharToQuantum((unsigned char)
+ GETJSAMPLE(*p++)));
+ SetBluePixelComponent(q,ScaleCharToQuantum((unsigned char)
+ GETJSAMPLE(*p++)));
SetOpacityPixelComponent(q,OpaqueOpacity);
q++;
}
else
for (x=0; x < (ssize_t) image->columns; x++)
{
- q->red=(Quantum) QuantumRange-ScaleCharToQuantum((unsigned char)
- GETJSAMPLE(*p++));
- q->green=(Quantum) QuantumRange-ScaleCharToQuantum((unsigned char)
- GETJSAMPLE(*p++));
- q->blue=(Quantum) QuantumRange-ScaleCharToQuantum((unsigned char)
- GETJSAMPLE(*p++));
+ SetCyanPixelComponent(q,QuantumRange-ScaleCharToQuantum(
+ (unsigned char) GETJSAMPLE(*p++)));
+ SetMagentaPixelComponent(q,QuantumRange-ScaleCharToQuantum(
+ (unsigned char) GETJSAMPLE(*p++)));
+ SetYellowPixelComponent(q,QuantumRange-ScaleCharToQuantum(
+ (unsigned char) GETJSAMPLE(*p++)));
+ SetBlackPixelComponent(indexes+x,QuantumRange-ScaleCharToQuantum(
+ (unsigned char) GETJSAMPLE(*p++)));
SetOpacityPixelComponent(q,OpaqueOpacity);
- indexes[x]=(IndexPacket) QuantumRange-ScaleCharToQuantum(
- (unsigned char) GETJSAMPLE(*p++));
q++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
- if (SetImageProgress(image,LoadImageTag,y,image->rows) == MagickFalse)
+ status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
+ image->rows);
+ if (status == MagickFalse)
break;
}
/*
%
% The format of the WriteJPEGImage method is:
%
-% MagickBooleanType WriteJPEGImage(const ImageInfo *image_info,Image *image)
+% MagickBooleanType WriteJPEGImage(const ImageInfo *image_info,
+% Image *image)
%
% A description of each parameter follows:
%
i;
size_t
- length;
+ length,
+ tag_length;
StringInfo
*custom_profile;
- size_t
- tag_length;
-
/*
Save image profile as a APP marker.
*/
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)
{
for (i=0; i < (ssize_t) GetStringInfoLength(profile); i+=65519L)
{
length=MagickMin(GetStringInfoLength(profile)-i,65519L);
- p=GetStringInfoDatum(custom_profile);
p[12]=(unsigned char) ((i/65519L)+1);
p[13]=(unsigned char) (GetStringInfoLength(profile)/65519L+1);
(void) CopyMagickMemory(p+tag_length,GetStringInfoDatum(profile)+i,
if (((LocaleCompare(name,"IPTC") == 0) ||
(LocaleCompare(name,"8BIM") == 0)) && (iptc == MagickFalse))
{
- register unsigned char
- *p;
-
size_t
roundup;
iptc=MagickTrue;
- p=GetStringInfoDatum(custom_profile);
- if (LocaleNCompare((char *) GetStringInfoDatum(profile),"8BIM",4) == 0)
- {
- (void) CopyMagickMemory(p,"Photoshop 3.0\0",14);
- tag_length=14;
- }
- else
- {
- (void) CopyMagickMemory(p,"Photoshop 3.0\08BIM\04\04\0\0\0\0",24);
- p[13]=0x00;
- p[24]=(unsigned char) (GetStringInfoLength(profile) >> 8);
- p[25]=(unsigned char) (GetStringInfoLength(profile) & 0xff);
- tag_length=26;
- }
for (i=0; i < (ssize_t) GetStringInfoLength(profile); i+=65500L)
{
length=MagickMin(GetStringInfoLength(profile)-i,65500L);
roundup=(size_t) (length & 0x01);
- (void) CopyMagickMemory(p+tag_length,GetStringInfoDatum(profile)+i,
- length);
+ if (LocaleNCompare((char *) GetStringInfoDatum(profile),"8BIM",4) == 0)
+ {
+ (void) memcpy(p,"Photoshop 3.0 ",14);
+ tag_length=14;
+ }
+ else
+ {
+ (void) CopyMagickMemory(p,"Photoshop 3.0 8BIM\04\04\0\0\0\0",24);
+ tag_length=26;
+ p[24]=(unsigned char) (length >> 8);
+ p[25]=(unsigned char) (length & 0xff);
+ }
+ p[13]=0x00;
+ (void) memcpy(p+tag_length,GetStringInfoDatum(profile)+i,length);
if (roundup != 0)
p[length+tag_length]='\0';
jpeg_write_marker(jpeg_info,IPTC_MARKER,GetStringInfoDatum(
}
xmp_profile=DestroyStringInfo(xmp_profile);
}
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),"%s profile: %lu bytes",
- name,(size_t) GetStringInfoLength(profile));
+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+ "%s profile: %.20g bytes",name,(double) GetStringInfoLength(profile));
name=GetNextImageProfile(image);
}
custom_profile=DestroyStringInfo(custom_profile);
JSAMPROW
scanline[1];
- ssize_t
- y;
-
MagickBooleanType
status;
register ssize_t
i;
+ ssize_t
+ y;
+
struct jpeg_compress_struct
jpeg_info;
/*
Initialize JPEG parameters.
*/
+ (void) ResetMagickMemory(&error_manager,0,sizeof(error_manager));
(void) ResetMagickMemory(&jpeg_info,0,sizeof(jpeg_info));
(void) ResetMagickMemory(&jpeg_error,0,sizeof(jpeg_error));
jpeg_info.client_data=(void *) image;
jpeg_info.density_unit=(UINT8) 1;
if (image->debug != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- "Image resolution: %ld,%ld",(ssize_t) floor(image->x_resolution+0.5),
- (ssize_t) floor(image->y_resolution+0.5));
+ "Image resolution: %.20g,%.20g",floor(image->x_resolution+0.5),
+ floor(image->y_resolution+0.5));
if ((image->x_resolution != 0.0) && (image->y_resolution != 0.0))
{
/*
else
jpeg_set_quality(&jpeg_info,(int) image->quality,MagickTrue);
if (image->debug != MagickFalse)
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),"Quality: %lu",
- image->quality);
+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),"Quality: %.20g",
+ (double) image->quality);
}
else
{
else
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
"Storage class: DirectClass");
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),"Depth: %lu",
- image->depth);
+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),"Depth: %.20g",
+ (double) image->depth);
if (image->colors != 0)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- "Number of colors: %lu",image->colors);
+ "Number of colors: %.20g",(double) image->colors);
else
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
"Number of colors: unspecified");
p++;
}
(void) jpeg_write_scanlines(&jpeg_info,scanline,1);
- if (SetImageProgress(image,SaveImageTag,y,image->rows) == MagickFalse)
+ status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
+ image->rows);
+ if (status == MagickFalse)
break;
}
else
p++;
}
(void) jpeg_write_scanlines(&jpeg_info,scanline,1);
- if (SetImageProgress(image,SaveImageTag,y,image->rows) == MagickFalse)
+ status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
+ image->rows);
+ if (status == MagickFalse)
break;
}
else
*q++=(JSAMPLE) (ScaleQuantumToChar((Quantum) (QuantumRange-
GetBluePixelComponent(p))));
*q++=(JSAMPLE) (ScaleQuantumToChar((Quantum) (QuantumRange-
- indexes[x])));
+ GetIndexPixelComponent(indexes+x))));
p++;
}
(void) jpeg_write_scanlines(&jpeg_info,scanline,1);
- if (SetImageProgress(image,SaveImageTag,y,image->rows) == MagickFalse)
+ status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
+ image->rows);
+ if (status == MagickFalse)
break;
}
}
p++;
}
(void) jpeg_write_scanlines(&jpeg_info,scanline,1);
- if (SetImageProgress(image,SaveImageTag,y,image->rows) == MagickFalse)
+ status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
+ image->rows);
+ if (status == MagickFalse)
break;
}
else
p++;
}
(void) jpeg_write_scanlines(&jpeg_info,scanline,1);
- status=SetImageProgress(image,SaveImageTag,y,image->rows);
+ status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
+ image->rows);
if (status == MagickFalse)
break;
}
GetGreenPixelComponent(p)) >> 4));
*q++=(JSAMPLE) (4095-(ScaleQuantumToShort(
GetBluePixelComponent(p)) >> 4));
- *q++=(JSAMPLE) (4095-(ScaleQuantumToShort(indexes[x]) >> 4));
+ *q++=(JSAMPLE) (4095-(ScaleQuantumToShort(
+ GetIndexPixelComponent(indexes+x)) >> 4));
p++;
}
(void) jpeg_write_scanlines(&jpeg_info,scanline,1);
- status=SetImageProgress(image,SaveImageTag,y,image->rows);
+ status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
+ image->rows);
if (status == MagickFalse)
break;
}