]> granicus.if.org Git - imagemagick/blobdiff - coders/wbmp.c
...
[imagemagick] / coders / wbmp.c
index 8a3055994f35c59795f2770e3a2d6df90e71d534..7a0882f4a15b9c845b519ae04b25b84d436eb3a2 100644 (file)
 %               Read/Write Wireless Bitmap (level 0) Image Format             %
 %                                                                             %
 %                              Software Design                                %
-%                                John Cristy                                  %
+%                                   Cristy                                    %
 %                               January 2000                                  %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2018 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  %
 %  obtain a copy of the License at                                            %
 %                                                                             %
-%    http://www.imagemagick.org/script/license.php                            %
+%    https://www.imagemagick.org/script/license.php                           %
 %                                                                             %
 %  Unless required by applicable law or agreed to in writing, software        %
 %  distributed under the License is distributed on an "AS IS" BASIS,          %
   Include declarations.
 */
 #include "MagickCore/studio.h"
+#include "MagickCore/attribute.h"
 #include "MagickCore/blob.h"
 #include "MagickCore/blob-private.h"
 #include "MagickCore/cache.h"
 #include "MagickCore/color-private.h"
 #include "MagickCore/colormap.h"
 #include "MagickCore/colorspace.h"
+#include "MagickCore/colorspace-private.h"
 #include "MagickCore/exception.h"
 #include "MagickCore/exception-private.h"
 #include "MagickCore/image.h"
@@ -64,7 +66,7 @@
   Forward declarations.
 */
 static MagickBooleanType
-  WriteWBMPImage(const ImageInfo *,Image *);
+  WriteWBMPImage(const ImageInfo *,Image *,ExceptionInfo *);
 \f
 /*
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -144,20 +146,21 @@ static Image *ReadWBMPImage(const ImageInfo *image_info,
     Open image file.
   */
   assert(image_info != (const ImageInfo *) NULL);
-  assert(image_info->signature == MagickSignature);
+  assert(image_info->signature == MagickCoreSignature);
   if (image_info->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
       image_info->filename);
   assert(exception != (ExceptionInfo *) NULL);
-  assert(exception->signature == MagickSignature);
-  image=AcquireImage(image_info);
+  assert(exception->signature == MagickCoreSignature);
+  image=AcquireImage(image_info,exception);
   status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
   if (status == MagickFalse)
     {
       image=DestroyImageList(image);
       return((Image *) NULL);
     }
-  if (ReadBlob(image,2,(unsigned char *) &header) == 0)
+  header=0;
+  if (ReadBlob(image,2,(unsigned char *) &header) != 2)
     ThrowReaderException(CorruptImageError,"ImproperImageHeader");
   if (header != 0)
     ThrowReaderException(CoderError,"OnlyLevelZerofilesSupported");
@@ -173,20 +176,24 @@ static Image *ReadWBMPImage(const ImageInfo *image_info,
   if (DiscardBlobBytes(image,image->offset) == MagickFalse)
     ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
       image->filename);
-  if (AcquireImageColormap(image,2) == MagickFalse)
-    ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
   if (image_info->ping != MagickFalse)
     {
       (void) CloseBlob(image);
       return(GetFirstImageInList(image));
     }
+  status=SetImageExtent(image,image->columns,image->rows,exception);
+  if (status == MagickFalse)
+    return(DestroyImageList(image));
+  (void) SetImageBackgroundColor(image,exception);
+  if (AcquireImageColormap(image,2,exception) == MagickFalse)
+    ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
   /*
     Convert bi-level image to pixel packets.
   */
   for (y=0; y < (ssize_t) image->rows; y++)
   {
     q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
-    if (q == (const Quantum *) NULL)
+    if (q == (Quantum *) NULL)
       break;
     bit=0;
     byte=0;
@@ -211,7 +218,7 @@ static Image *ReadWBMPImage(const ImageInfo *image_info,
     if (status == MagickFalse)
       break;
   }
-  (void) SyncImage(image);
+  (void) SyncImage(image,exception);
   if (EOFBlob(image) != MagickFalse)
     ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
       image->filename);
@@ -247,12 +254,10 @@ ModuleExport size_t RegisterWBMPImage(void)
   MagickInfo
     *entry;
 
-  entry=SetMagickInfo("WBMP");
+  entry=AcquireMagickInfo("WBMP","WBMP","Wireless Bitmap (level 0) image");
   entry->decoder=(DecodeImageHandler *) ReadWBMPImage;
   entry->encoder=(EncodeImageHandler *) WriteWBMPImage;
-  entry->adjoin=MagickFalse;
-  entry->description=ConstantString("Wireless Bitmap (level 0) image");
-  entry->module=ConstantString("WBMP");
+  entry->flags^=CoderAdjoinFlag;
   (void) RegisterMagickInfo(entry);
   return(MagickImageCoderSignature);
 }
@@ -300,7 +305,7 @@ ModuleExport void UnregisterWBMPImage(void)
 %  The format of the WriteWBMPImage method is:
 %
 %      MagickBooleanType WriteWBMPImage(const ImageInfo *image_info,
-%        Image *image)
+%        Image *image,ExceptionInfo *exception)
 %
 %  A description of each parameter follows.
 %
@@ -308,6 +313,7 @@ ModuleExport void UnregisterWBMPImage(void)
 %
 %    o image:  The image.
 %
+%    o exception: return any errors or warnings in this structure.
 %
 */
 
@@ -343,7 +349,7 @@ static void WBMPWriteInteger(Image *image,const size_t value)
 }
 
 static MagickBooleanType WriteWBMPImage(const ImageInfo *image_info,
-  Image *image)
+  Image *image,ExceptionInfo *exception)
 {
   MagickBooleanType
     status;
@@ -365,33 +371,34 @@ static MagickBooleanType WriteWBMPImage(const ImageInfo *image_info,
     Open output image file.
   */
   assert(image_info != (const ImageInfo *) NULL);
-  assert(image_info->signature == MagickSignature);
+  assert(image_info->signature == MagickCoreSignature);
   assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
-  status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
+  assert(exception != (ExceptionInfo *) NULL);
+  assert(exception->signature == MagickCoreSignature);
+  status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
   if (status == MagickFalse)
     return(status);
-  if (image->colorspace != RGBColorspace)
-    (void) TransformImageColorspace(image,RGBColorspace);
+  (void) TransformImageColorspace(image,sRGBColorspace,exception);
   /*
     Convert image to a bi-level image.
   */
-  (void) SetImageType(image,BilevelType);
+  (void) SetImageType(image,BilevelType,exception);
   (void) WriteBlobMSBShort(image,0);
   WBMPWriteInteger(image,image->columns);
   WBMPWriteInteger(image,image->rows);
   for (y=0; y < (ssize_t) image->rows; y++)
   {
-    p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
+    p=GetVirtualPixels(image,0,y,image->columns,1,exception);
     if (p == (const Quantum *) NULL)
       break;
     bit=0;
     byte=0;
     for (x=0; x < (ssize_t) image->columns; x++)
     {
-      if (GetPixelIntensity(image,p) >= ((MagickRealType) QuantumRange/2.0))
+      if (GetPixelLuma(image,p) >= (QuantumRange/2.0))
         byte|=0x1 << (7-bit);
       bit++;
       if (bit == 8)