]> granicus.if.org Git - imagemagick/commitdiff
(no commit message)
authorcristy <urban-warrior@git.imagemagick.org>
Sun, 14 Mar 2010 18:21:29 +0000 (18:21 +0000)
committercristy <urban-warrior@git.imagemagick.org>
Sun, 14 Mar 2010 18:21:29 +0000 (18:21 +0000)
coders/jpeg.c
coders/pnm.c
coders/psd.c
magick/quantum-private.h
magick/quantum.h

index d28d4583874daeac25de165241f37092b2e29227..f311b70556f5115c710adb53c1b2c8ab0c38b787 100644 (file)
@@ -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)
index 8b976f10e038005395f8c29e4fa6161b805bc296..6471e0ef33d159aa97f32686fe3375be23d488b4 100644 (file)
@@ -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)
index 8d29965062b02174e07dc96a33bc362e6195237a..b6e6a6b29fbab1c613203ceb293e8387c08594e4 100644 (file)
@@ -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
index a5bda70eb3fbb4869e98258478855beddc353149..79fa1805516d3ded9760396b9a6c2cdc8c7e490f 100644 (file)
@@ -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
index 12488b18cce5bf428b97084c48b55348a04954f8..2c65bc9d02577dbc30c99bb17a0dad6b1abdfc39 100644 (file)
@@ -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);