From: cristy Date: Sun, 14 Mar 2010 18:21:29 +0000 (+0000) Subject: (no commit message) X-Git-Tag: 7.0.1-0~9803 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e90d740a0e791918560f0f1124d8ec96d8d5d8d8;p=imagemagick --- diff --git a/coders/jpeg.c b/coders/jpeg.c index d28d45838..f311b7055 100644 --- a/coders/jpeg.c +++ b/coders/jpeg.c @@ -851,8 +851,8 @@ static void JPEGSetImageSamplingFactor(struct jpeg_decompress_struct *jpeg_info, } } (void) SetImageProperty(image,"jpeg:sampling-factor",sampling_factor); - (void) LogMagickEvent(CoderEvent,GetMagickModule(), - "Sampling Factors: %s",sampling_factor); + (void) LogMagickEvent(CoderEvent,GetMagickModule(),"Sampling Factors: %s", + sampling_factor); } static Image *ReadJPEGImage(const ImageInfo *image_info, @@ -2157,9 +2157,10 @@ static MagickBooleanType WriteJPEGImage(const ImageInfo *image_info, return(MagickFalse); } scanline[0]=(JSAMPROW) jpeg_pixels; - if (jpeg_info.data_precision > 8) + if (jpeg_info.data_precision <= 8) { - if (jpeg_info.in_color_space == JCS_GRAYSCALE) + if ((jpeg_info.in_color_space == JCS_RGB) || + (jpeg_info.in_color_space == JCS_YCbCr)) for (y=0; y < (long) image->rows; y++) { register const PixelPacket @@ -2174,8 +2175,9 @@ static MagickBooleanType WriteJPEGImage(const ImageInfo *image_info, q=jpeg_pixels; for (x=0; x < (long) image->columns; x++) { - *q++=(JSAMPLE) (ScaleQuantumToShort(PixelIntensityToQuantum(p)) >> - 4); + *q++=(JSAMPLE) ScaleQuantumToChar(GetRedPixelComponent(p)); + *q++=(JSAMPLE) ScaleQuantumToChar(GetGreenPixelComponent(p)); + *q++=(JSAMPLE) ScaleQuantumToChar(GetBluePixelComponent(p)); p++; } (void) jpeg_write_scanlines(&jpeg_info,scanline,1); @@ -2183,8 +2185,7 @@ static MagickBooleanType WriteJPEGImage(const ImageInfo *image_info, break; } else - if ((jpeg_info.in_color_space == JCS_RGB) || - (jpeg_info.in_color_space == JCS_YCbCr)) + if (jpeg_info.in_color_space == JCS_GRAYSCALE) for (y=0; y < (long) image->rows; y++) { register const PixelPacket @@ -2199,14 +2200,11 @@ static MagickBooleanType WriteJPEGImage(const ImageInfo *image_info, q=jpeg_pixels; for (x=0; x < (long) image->columns; x++) { - *q++=(JSAMPLE) (ScaleQuantumToShort(GetRedPixelComponent(p)) >> 4); - *q++=(JSAMPLE) (ScaleQuantumToShort(GetGreenPixelComponent(p)) >> 4); - *q++=(JSAMPLE) (ScaleQuantumToShort(GetBluePixelComponent(p)) >> 4); + *q++=(JSAMPLE) ScaleQuantumToChar(PixelIntensityToQuantum(p)); p++; } (void) jpeg_write_scanlines(&jpeg_info,scanline,1); - status=SetImageProgress(image,SaveImageTag,y,image->rows); - if (status == MagickFalse) + if (SetImageProgress(image,SaveImageTag,y,image->rows) == MagickFalse) break; } else @@ -2231,15 +2229,18 @@ static MagickBooleanType WriteJPEGImage(const ImageInfo *image_info, /* Convert DirectClass packets to contiguous CMYK scanlines. */ - *q++=(JSAMPLE) (4095-(ScaleQuantumToShort(GetRedPixelComponent(p)) >> 4)); - *q++=(JSAMPLE) (4095-(ScaleQuantumToShort(GetGreenPixelComponent(p)) >> 4)); - *q++=(JSAMPLE) (4095-(ScaleQuantumToShort(GetBluePixelComponent(p)) >> 4)); - *q++=(JSAMPLE) (4095-(ScaleQuantumToShort(indexes[x]) >> 4)); + *q++=(JSAMPLE) (ScaleQuantumToChar((Quantum) (QuantumRange- + GetRedPixelComponent(p)))); + *q++=(JSAMPLE) (ScaleQuantumToChar((Quantum) (QuantumRange- + GetGreenPixelComponent(p)))); + *q++=(JSAMPLE) (ScaleQuantumToChar((Quantum) (QuantumRange- + GetBluePixelComponent(p)))); + *q++=(JSAMPLE) (ScaleQuantumToChar((Quantum) (QuantumRange- + indexes[x]))); p++; } (void) jpeg_write_scanlines(&jpeg_info,scanline,1); - status=SetImageProgress(image,SaveImageTag,y,image->rows); - if (status == MagickFalse) + if (SetImageProgress(image,SaveImageTag,y,image->rows) == MagickFalse) break; } } @@ -2259,7 +2260,8 @@ static MagickBooleanType WriteJPEGImage(const ImageInfo *image_info, q=jpeg_pixels; for (x=0; x < (long) image->columns; x++) { - *q++=(JSAMPLE) ScaleQuantumToChar(PixelIntensityToQuantum(p)); + *q++=(JSAMPLE) (ScaleQuantumToShort(PixelIntensityToQuantum(p)) >> + 4); p++; } (void) jpeg_write_scanlines(&jpeg_info,scanline,1); @@ -2283,13 +2285,17 @@ static MagickBooleanType WriteJPEGImage(const ImageInfo *image_info, q=jpeg_pixels; for (x=0; x < (long) image->columns; x++) { - *q++=(JSAMPLE) ScaleQuantumToChar(GetRedPixelComponent(p)); - *q++=(JSAMPLE) ScaleQuantumToChar(GetGreenPixelComponent(p)); - *q++=(JSAMPLE) ScaleQuantumToChar(GetBluePixelComponent(p)); + *q++=(JSAMPLE) (ScaleQuantumToShort(GetRedPixelComponent(p)) >> + 4); + *q++=(JSAMPLE) (ScaleQuantumToShort(GetGreenPixelComponent(p)) >> + 4); + *q++=(JSAMPLE) (ScaleQuantumToShort(GetBluePixelComponent(p)) >> + 4); p++; } (void) jpeg_write_scanlines(&jpeg_info,scanline,1); - if (SetImageProgress(image,SaveImageTag,y,image->rows) == MagickFalse) + status=SetImageProgress(image,SaveImageTag,y,image->rows); + if (status == MagickFalse) break; } else @@ -2314,18 +2320,18 @@ static MagickBooleanType WriteJPEGImage(const ImageInfo *image_info, /* Convert DirectClass packets to contiguous CMYK scanlines. */ - *q++=(JSAMPLE) (ScaleQuantumToChar((Quantum) (QuantumRange- - GetRedPixelComponent(p)))); - *q++=(JSAMPLE) (ScaleQuantumToChar((Quantum) (QuantumRange- - GetGreenPixelComponent(p)))); - *q++=(JSAMPLE) (ScaleQuantumToChar((Quantum) (QuantumRange- - GetBluePixelComponent(p)))); - *q++=(JSAMPLE) (ScaleQuantumToChar((Quantum) (QuantumRange- - indexes[x]))); + *q++=(JSAMPLE) (4095-(ScaleQuantumToShort( + GetRedPixelComponent(p)) >> 4)); + *q++=(JSAMPLE) (4095-(ScaleQuantumToShort( + GetGreenPixelComponent(p)) >> 4)); + *q++=(JSAMPLE) (4095-(ScaleQuantumToShort( + GetBluePixelComponent(p)) >> 4)); + *q++=(JSAMPLE) (4095-(ScaleQuantumToShort(indexes[x]) >> 4)); p++; } (void) jpeg_write_scanlines(&jpeg_info,scanline,1); - if (SetImageProgress(image,SaveImageTag,y,image->rows) == MagickFalse) + status=SetImageProgress(image,SaveImageTag,y,image->rows); + if (status == MagickFalse) break; } if (y == (long) image->rows) diff --git a/coders/pnm.c b/coders/pnm.c index 8b976f10e..6471e0ef3 100644 --- a/coders/pnm.c +++ b/coders/pnm.c @@ -817,9 +817,6 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) ssize_t count; - size_t - length; - unsigned char *pixels; @@ -853,66 +850,84 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) continue; } p=pixels; - if ((image->depth == 8) || (image->depth == 16)) + if (image->depth == 8) + for (x=0; x < (long) image->columns; x++) { - length=ImportQuantumPixels(image,image_view,quantum_info, - quantum_type,pixels,exception); - if (length != extent) - status=MagickFalse; + q->red=ScaleCharToQuantum(*p++); + q->green=ScaleCharToQuantum(*p++); + q->blue=ScaleCharToQuantum(*p++); + q->opacity=OpaqueOpacity; + q++; } else - if (image->depth <= 8) - { - unsigned char - pixel; - - register PixelPacket - *restrict r; - - r=q; - for (x=0; x < (long) image->columns; x++) - { - p=PushCharPixel(p,&pixel); - r->red=ScaleAnyToQuantum(pixel,range); - p=PushCharPixel(p,&pixel); - r->green=ScaleAnyToQuantum(pixel,range); - p=PushCharPixel(p,&pixel); - r->blue=ScaleAnyToQuantum(pixel,range); - r++; - } - } - else + if (image->depth == 16) { unsigned short pixel; - register PixelPacket - *restrict r; - - r=q; for (x=0; x < (long) image->columns; x++) { p=PushShortPixel(MSBEndian,p,&pixel); - r->red=ScaleAnyToQuantum(pixel,range); + q->red=ScaleShortToQuantum(pixel); p=PushShortPixel(MSBEndian,p,&pixel); - r->green=ScaleAnyToQuantum(pixel,range); + q->green=ScaleShortToQuantum(pixel); p=PushShortPixel(MSBEndian,p,&pixel); - r->blue=ScaleAnyToQuantum(pixel,range); - r++; + q->blue=ScaleShortToQuantum(pixel); + q->opacity=OpaqueOpacity; + q++; } } + else + if (image->depth <= 8) + { + unsigned char + pixel; + + for (x=0; x < (long) image->columns; x++) + { + p=PushCharPixel(p,&pixel); + q->red=ScaleAnyToQuantum(pixel,range); + p=PushCharPixel(p,&pixel); + q->green=ScaleAnyToQuantum(pixel,range); + p=PushCharPixel(p,&pixel); + q->blue=ScaleAnyToQuantum(pixel,range); + q->opacity=OpaqueOpacity; + q++; + } + } + else + { + unsigned short + pixel; + + for (x=0; x < (long) image->columns; x++) + { + p=PushShortPixel(MSBEndian,p,&pixel); + q->red=ScaleAnyToQuantum(pixel,range); + p=PushShortPixel(MSBEndian,p,&pixel); + q->green=ScaleAnyToQuantum(pixel,range); + p=PushShortPixel(MSBEndian,p,&pixel); + q->blue=ScaleAnyToQuantum(pixel,range); + q->opacity=OpaqueOpacity; + q++; + } + } if ((type == BilevelType) || (type == GrayscaleType)) - for (x=0; x < (long) image->columns; x++) { - if ((type == BilevelType) && - (IsMonochromePixel(q) == MagickFalse)) - type=IsGrayPixel(q) == MagickFalse ? UndefinedType : - GrayscaleType; - if ((type == GrayscaleType) && (IsGrayPixel(q) == MagickFalse)) - type=UndefinedType; - if ((type != BilevelType) && (type != GrayscaleType)) - break; - q++; + q=QueueCacheViewAuthenticPixels(image_view,0,offset, + image->columns,1,exception); + for (x=0; x < (long) image->columns; x++) + { + if ((type == BilevelType) && + (IsMonochromePixel(q) == MagickFalse)) + type=IsGrayPixel(q) == MagickFalse ? UndefinedType : + GrayscaleType; + if ((type == GrayscaleType) && (IsGrayPixel(q) == MagickFalse)) + type=UndefinedType; + if ((type != BilevelType) && (type != GrayscaleType)) + break; + q++; + } } sync=SyncCacheViewAuthenticPixels(image_view,exception); if (sync == MagickFalse) diff --git a/coders/psd.c b/coders/psd.c index 8d2996506..b6e6a6b29 100644 --- a/coders/psd.c +++ b/coders/psd.c @@ -1864,63 +1864,6 @@ static MagickBooleanType WriteImageChannels(const PSDInfo *psd_info, return(MagickTrue); } -/* Write white background, RLE-compressed */ - -static void WriteWhiteBackground(const PSDInfo *psd_info,Image *image ) -{ - long w8, w; - char *d, scanline[256]; - - int numChannels = 3, dim = (int) (image->rows*numChannels); - - register long - i; - - size_t - length; - - unsigned short - bytecount; - - (void) WriteBlobMSBShort(image,1); /* RLE compressed */ - w8 = (long) image->columns; - d = scanline; - /* Set up scanline */ - for (w=w8; w > 128; w-=128) - { - *d++=(-127); - *d++=(char) 255; - } - switch (w) - { - case 0: - break; - case 1: - *d++=0; - *d++=(char) 255; - break; - default: - *d++=(char) (1-w); - *d++=(char) 255; - break; - } - bytecount = d - scanline; - - /* Scanline counts (rows*channels) */ - for (i=0; i < dim; i++) - { - (void) SetPSDOffset(psd_info,image,bytecount); - } - - /* RLE compressed data */ - length = bytecount; - for (i=0; i < dim; i++) - { - (void) WriteBlob( image, length, (unsigned char *) scanline ); - } - -} - static void WritePascalString(Image* inImage,const char *inString,int inPad) { size_t diff --git a/magick/quantum-private.h b/magick/quantum-private.h index a5bda70eb..79fa18055 100644 --- a/magick/quantum-private.h +++ b/magick/quantum-private.h @@ -376,7 +376,7 @@ static inline unsigned short ScaleQuantumToShort(const Quantum quantum) static inline Quantum ScaleShortToQuantum(const unsigned short value) { #if !defined(MAGICKCORE_HDRI_SUPPORT) - return((Quantum) ((value+128UL)/257UL)); + return((Quantum) ((value+128U)/257U)); #else return((Quantum) (value/257.0)); #endif @@ -385,7 +385,7 @@ static inline Quantum ScaleShortToQuantum(const unsigned short value) static inline Quantum ScaleCharToQuantum(const unsigned char value) { #if !defined(MAGICKCORE_HDRI_SUPPORT) - return((Quantum) (257UL*value)); + return((Quantum) (257U*value)); #else return((Quantum) (257.0*value)); #endif diff --git a/magick/quantum.h b/magick/quantum.h index 12488b18c..2c65bc9d0 100644 --- a/magick/quantum.h +++ b/magick/quantum.h @@ -111,7 +111,7 @@ static inline unsigned char ScaleQuantumToChar(const Quantum quantum) static inline unsigned char ScaleQuantumToChar(const Quantum quantum) { #if !defined(MAGICKCORE_HDRI_SUPPORT) - return((unsigned char) (((quantum+128UL)-((quantum+128UL) >> 8)) >> 8)); + return((unsigned char) (quantum/257U)); #else if (quantum <= 0.0) return(0);