]> granicus.if.org Git - imagemagick/blobdiff - coders/bgr.c
(no commit message)
[imagemagick] / coders / bgr.c
index 188ba166c9219581bcb0b74c372cdad761d24330..e64ba72d9612587bbc589d84a7cb2b7802192a12 100644 (file)
@@ -100,6 +100,9 @@ static MagickBooleanType
 static Image *ReadBGRImage(const ImageInfo *image_info,
   ExceptionInfo *exception)
 {
+  const void
+    *pixels;
+
   Image
     *canvas_image,
     *image;
@@ -126,9 +129,6 @@ static Image *ReadBGRImage(const ImageInfo *image_info,
     count,
     y;
 
-  unsigned char
-    *pixels;
-
   /*
     Open image file.
   */
@@ -164,13 +164,20 @@ static Image *ReadBGRImage(const ImageInfo *image_info,
   quantum_info=AcquireQuantumInfo(image_info,canvas_image);
   if (quantum_info == (QuantumInfo *) NULL)
     ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
-  pixels=GetQuantumPixels(quantum_info);
   quantum_type=BGRQuantum;
   if (LocaleCompare(image_info->magick,"BGRA") == 0)
     {
       quantum_type=BGRAQuantum;
       image->alpha_trait=BlendPixelTrait;
+      canvas_image->alpha_trait=BlendPixelTrait;
     }
+  if (LocaleCompare(image_info->magick,"BGRO") == 0)
+    {
+      quantum_type=BGROQuantum;
+      image->alpha_trait=BlendPixelTrait;
+      canvas_image->alpha_trait=BlendPixelTrait;
+    }
+  pixels=(const void *) NULL;
   if (image_info->number_scenes != 0)
     while (image->scene < image_info->scene)
     {
@@ -181,7 +188,8 @@ static Image *ReadBGRImage(const ImageInfo *image_info,
       length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
       for (y=0; y < (ssize_t) image->rows; y++)
       {
-        count=ReadBlob(image,length,pixels);
+        pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
+          &count);
         if (count != (ssize_t) length)
           break;
       }
@@ -211,7 +219,8 @@ static Image *ReadBGRImage(const ImageInfo *image_info,
         if (scene == 0)
           {
             length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
-            count=ReadBlob(image,length,pixels);
+            pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
+              &count);
           }
         for (y=0; y < (ssize_t) image->extract_info.height; y++)
         {
@@ -269,7 +278,8 @@ static Image *ReadBGRImage(const ImageInfo *image_info,
               if (status == MagickFalse)
                 break;
             }
-          count=ReadBlob(image,length,pixels);
+          pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
+            &count);
         }
         break;
       }
@@ -290,7 +300,8 @@ static Image *ReadBGRImage(const ImageInfo *image_info,
         if (scene == 0)
           {
             length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
-            count=ReadBlob(image,length,pixels);
+            pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
+              &count);
           }
         for (y=0; y < (ssize_t) image->extract_info.height; y++)
         {
@@ -368,7 +379,8 @@ static Image *ReadBGRImage(const ImageInfo *image_info,
                 if (SyncAuthenticPixels(image,exception) == MagickFalse)
                   break;
               }
-            count=ReadBlob(image,length,pixels);
+            pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
+              &count);
           }
           if (image->previous == (Image *) NULL)
             {
@@ -388,7 +400,8 @@ static Image *ReadBGRImage(const ImageInfo *image_info,
         if (scene == 0)
           {
             length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
-            count=ReadBlob(image,length,pixels);
+            pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
+              &count);
           }
         for (y=0; y < (ssize_t) image->extract_info.height; y++)
         {
@@ -434,7 +447,8 @@ static Image *ReadBGRImage(const ImageInfo *image_info,
               if (SyncAuthenticPixels(image,exception) == MagickFalse)
                 break;
             }
-          count=ReadBlob(image,length,pixels);
+          pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
+            &count);
         }
         if (image->previous == (Image *) NULL)
           {
@@ -486,7 +500,8 @@ static Image *ReadBGRImage(const ImageInfo *image_info,
               if (SyncAuthenticPixels(image,exception) == MagickFalse)
                 break;
            }
-          count=ReadBlob(image,length,pixels);
+          pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
+            &count);
         }
         if (image->previous == (Image *) NULL)
           {
@@ -538,7 +553,8 @@ static Image *ReadBGRImage(const ImageInfo *image_info,
               if (SyncAuthenticPixels(image,exception) == MagickFalse)
                 break;
             }
-          count=ReadBlob(image,length,pixels);
+          pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
+            &count);
         }
         if (image->previous == (Image *) NULL)
           {
@@ -599,7 +615,8 @@ static Image *ReadBGRImage(const ImageInfo *image_info,
                   if (SyncAuthenticPixels(image,exception) == MagickFalse)
                     break;
                 }
-              count=ReadBlob(image,length,pixels);
+              pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
+                &count);
             }
             if (image->previous == (Image *) NULL)
               {
@@ -635,13 +652,18 @@ static Image *ReadBGRImage(const ImageInfo *image_info,
         length=GetQuantumExtent(canvas_image,quantum_info,BlueQuantum);
         for (i=0; i < (ssize_t) scene; i++)
           for (y=0; y < (ssize_t) image->extract_info.height; y++)
-            if (ReadBlob(image,length,pixels) != (ssize_t) length)
+          {
+            pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
+              &count);
+            if (count != (ssize_t) length)
               {
                 ThrowFileException(exception,CorruptImageError,
                   "UnexpectedEndOfFile",image->filename);
                 break;
               }
-        count=ReadBlob(image,length,pixels);
+          }
+        pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
+          &count);
         for (y=0; y < (ssize_t) image->extract_info.height; y++)
         {
           register const Quantum
@@ -686,7 +708,8 @@ static Image *ReadBGRImage(const ImageInfo *image_info,
               if (SyncAuthenticPixels(image,exception) == MagickFalse)
                 break;
             }
-          count=ReadBlob(image,length,pixels);
+          pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
+            &count);
         }
         if (image->previous == (Image *) NULL)
           {
@@ -706,13 +729,18 @@ static Image *ReadBGRImage(const ImageInfo *image_info,
         length=GetQuantumExtent(canvas_image,quantum_info,GreenQuantum);
         for (i=0; i < (ssize_t) scene; i++)
           for (y=0; y < (ssize_t) image->extract_info.height; y++)
-            if (ReadBlob(image,length,pixels) != (ssize_t) length)
+          {
+            pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
+              &count);
+            if (count != (ssize_t) length)
               {
                 ThrowFileException(exception,CorruptImageError,
                   "UnexpectedEndOfFile",image->filename);
                 break;
               }
-        count=ReadBlob(image,length,pixels);
+          }
+        pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
+          &count);
         for (y=0; y < (ssize_t) image->extract_info.height; y++)
         {
           register const Quantum
@@ -757,7 +785,8 @@ static Image *ReadBGRImage(const ImageInfo *image_info,
               if (SyncAuthenticPixels(image,exception) == MagickFalse)
                 break;
            }
-          count=ReadBlob(image,length,pixels);
+          pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
+            &count);
         }
         if (image->previous == (Image *) NULL)
           {
@@ -777,13 +806,18 @@ static Image *ReadBGRImage(const ImageInfo *image_info,
         length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
         for (i=0; i < (ssize_t) scene; i++)
           for (y=0; y < (ssize_t) image->extract_info.height; y++)
-            if (ReadBlob(image,length,pixels) != (ssize_t) length)
+          {
+            pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
+              &count);
+            if (count != (ssize_t) length)
               {
                 ThrowFileException(exception,CorruptImageError,
                   "UnexpectedEndOfFile",image->filename);
                 break;
               }
-        count=ReadBlob(image,length,pixels);
+          }
+        pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
+          &count);
         for (y=0; y < (ssize_t) image->extract_info.height; y++)
         {
           register const Quantum
@@ -828,7 +862,8 @@ static Image *ReadBGRImage(const ImageInfo *image_info,
               if (SyncAuthenticPixels(image,exception) == MagickFalse)
                 break;
            }
-          count=ReadBlob(image,length,pixels);
+          pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
+            &count);
         }
         if (image->previous == (Image *) NULL)
           {
@@ -850,13 +885,18 @@ static Image *ReadBGRImage(const ImageInfo *image_info,
             length=GetQuantumExtent(canvas_image,quantum_info,AlphaQuantum);
             for (i=0; i < (ssize_t) scene; i++)
               for (y=0; y < (ssize_t) image->extract_info.height; y++)
-                if (ReadBlob(image,length,pixels) != (ssize_t) length)
+              {
+                pixels=ReadBlobStream(image,length,
+                  GetQuantumPixels(quantum_info),&count);
+                if (count != (ssize_t) length)
                   {
                     ThrowFileException(exception,CorruptImageError,
                       "UnexpectedEndOfFile",image->filename);
                     break;
                   }
-            count=ReadBlob(image,length,pixels);
+              }
+            pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
+              &count);
             for (y=0; y < (ssize_t) image->extract_info.height; y++)
             {
               register const Quantum
@@ -901,7 +941,8 @@ static Image *ReadBGRImage(const ImageInfo *image_info,
                   if (SyncAuthenticPixels(image,exception) == MagickFalse)
                     break;
                }
-              count=ReadBlob(image,length,pixels);
+              pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
+                &count);
             }
             if (image->previous == (Image *) NULL)
               {
@@ -983,19 +1024,27 @@ ModuleExport size_t RegisterBGRImage(void)
   entry=SetMagickInfo("BGR");
   entry->decoder=(DecodeImageHandler *) ReadBGRImage;
   entry->encoder=(EncodeImageHandler *) WriteBGRImage;
-  entry->raw=MagickTrue;
-  entry->endian_support=MagickTrue;
+  entry->flags|=CoderRawSupportFlag;
+  entry->flags|=CoderEndianSupportFlag;
   entry->description=ConstantString("Raw blue, green, and red samples");
   entry->module=ConstantString("BGR");
   (void) RegisterMagickInfo(entry);
   entry=SetMagickInfo("BGRA");
   entry->decoder=(DecodeImageHandler *) ReadBGRImage;
   entry->encoder=(EncodeImageHandler *) WriteBGRImage;
-  entry->raw=MagickTrue;
-  entry->endian_support=MagickTrue;
+  entry->flags|=CoderRawSupportFlag;
+  entry->flags|=CoderEndianSupportFlag;
   entry->description=ConstantString("Raw blue, green, red, and alpha samples");
   entry->module=ConstantString("BGR");
   (void) RegisterMagickInfo(entry);
+  entry=SetMagickInfo("BGRO");
+  entry->decoder=(DecodeImageHandler *) ReadBGRImage;
+  entry->encoder=(EncodeImageHandler *) WriteBGRImage;
+  entry->flags|=CoderRawSupportFlag;
+  entry->flags|=CoderEndianSupportFlag;
+  entry->description=ConstantString("Raw blue, green, red, and opacity samples");
+  entry->module=ConstantString("BGR");
+  (void) RegisterMagickInfo(entry);
   return(MagickImageCoderSignature);
 }
 \f