]> granicus.if.org Git - imagemagick/blobdiff - coders/cip.c
...
[imagemagick] / coders / cip.c
index e9d729c1a2c12d3e4cf3afa04d7a43183507578f..2d45ac8540deaf1c37e079c85d4ca0ce7f758e87 100644 (file)
 %                  Read/Write Cisco IP Phone Image Format                     %
 %                                                                             %
 %                              Software Design                                %
-%                                John Cristy                                  %
+%                                   Cristy                                    %
 %                                April 2004                                   %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2014 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://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,          %
@@ -98,11 +98,9 @@ ModuleExport size_t RegisterCIPImage(void)
   MagickInfo
     *entry;
 
-  entry=SetMagickInfo("CIP");
+  entry=AcquireMagickInfo("CIP","CIP","Cisco IP phone image format");
   entry->encoder=(EncodeImageHandler *) WriteCIPImage;
-  entry->adjoin=MagickFalse;
-  entry->description=ConstantString("Cisco IP phone image format");
-  entry->module=ConstantString("CIP");
+  entry->flags^=CoderAdjoinFlag;
   (void) RegisterMagickInfo(entry);
   return(MagickImageCoderSignature);
 }
@@ -159,19 +157,11 @@ ModuleExport void UnregisterCIPImage(void)
 %    o exception: return any errors or warnings in this structure.
 %
 */
-
-static inline ssize_t MagickMin(const ssize_t x,const ssize_t y)
-{
-  if (x < y)
-    return(x);
-  return(y);
-}
-
 static MagickBooleanType WriteCIPImage(const ImageInfo *image_info,Image *image,
   ExceptionInfo *exception)
 {
   char
-    buffer[MaxTextExtent];
+    buffer[MagickPathExtent];
 
   const char
     *value;
@@ -196,47 +186,47 @@ static MagickBooleanType WriteCIPImage(const ImageInfo *image_info,Image *image,
     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);
   assert(exception != (ExceptionInfo *) NULL);
-  assert(exception->signature == MagickSignature);
+  assert(exception->signature == MagickCoreSignature);
   status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
   if (status == MagickFalse)
     return(status);
   (void) WriteBlobString(image,"<CiscoIPPhoneImage>\n");
   value=GetImageProperty(image,"label",exception);
   if (value != (const char *) NULL)
-    (void) FormatLocaleString(buffer,MaxTextExtent,"<Title>%s</Title>\n",value);
+    (void) FormatLocaleString(buffer,MagickPathExtent,"<Title>%s</Title>\n",
+      value);
   else
     {
       char
-        basename[MaxTextExtent];
+        basename[MagickPathExtent];
 
       GetPathComponent(image->filename,BasePath,basename);
-      (void) FormatLocaleString(buffer,MaxTextExtent,"<Title>%s</Title>\n",
+      (void) FormatLocaleString(buffer,MagickPathExtent,"<Title>%s</Title>\n",
         basename);
     }
   (void) WriteBlobString(image,buffer);
-  (void) FormatLocaleString(buffer,MaxTextExtent,
+  (void) FormatLocaleString(buffer,MagickPathExtent,
     "<LocationX>%.20g</LocationX>\n",(double) image->page.x);
   (void) WriteBlobString(image,buffer);
-  (void) FormatLocaleString(buffer,MaxTextExtent,
+  (void) FormatLocaleString(buffer,MagickPathExtent,
     "<LocationY>%.20g</LocationY>\n",(double) image->page.y);
   (void) WriteBlobString(image,buffer);
-  (void) FormatLocaleString(buffer,MaxTextExtent,"<Width>%.20g</Width>\n",
+  (void) FormatLocaleString(buffer,MagickPathExtent,"<Width>%.20g</Width>\n",
     (double) (image->columns+(image->columns % 2)));
   (void) WriteBlobString(image,buffer);
-  (void) FormatLocaleString(buffer,MaxTextExtent,"<Height>%.20g</Height>\n",
+  (void) FormatLocaleString(buffer,MagickPathExtent,"<Height>%.20g</Height>\n",
     (double) image->rows);
   (void) WriteBlobString(image,buffer);
-  (void) FormatLocaleString(buffer,MaxTextExtent,"<Depth>2</Depth>\n");
+  (void) FormatLocaleString(buffer,MagickPathExtent,"<Depth>2</Depth>\n");
   (void) WriteBlobString(image,buffer);
   (void) WriteBlobString(image,"<Data>");
-  if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
-    (void) TransformImageColorspace(image,sRGBColorspace,exception);
+  (void) TransformImageColorspace(image,sRGBColorspace,exception);
   for (y=0; y < (ssize_t) image->rows; y++)
   {
     p=GetVirtualPixels(image,0,y,image->columns,1,exception);
@@ -245,23 +235,53 @@ static MagickBooleanType WriteCIPImage(const ImageInfo *image_info,Image *image,
     for (x=0; x < ((ssize_t) image->columns-3); x+=4)
     {
       byte=(unsigned char)
-        ((((size_t) (3*ClampToQuantum(GetPixelLuma(image,p+3))/QuantumRange) & 0x03) << 6) |
-         (((size_t) (3*ClampToQuantum(GetPixelLuma(image,p+2))/QuantumRange) & 0x03) << 4) |
-         (((size_t) (3*ClampToQuantum(GetPixelLuma(image,p+1))/QuantumRange) & 0x03) << 2) |
-         (((size_t) (3*ClampToQuantum(GetPixelLuma(image,p+0))/QuantumRange) & 0x03) << 0));
-      (void) FormatLocaleString(buffer,MaxTextExtent,"%02x",byte);
+        ((((size_t) (3*ClampToQuantum(GetPixelLuma(image,p+3*GetPixelChannels(image)))/QuantumRange) & 0x03) << 6) |
+         (((size_t) (3*ClampToQuantum(GetPixelLuma(image,p+2*GetPixelChannels(image)))/QuantumRange) & 0x03) << 4) |
+         (((size_t) (3*ClampToQuantum(GetPixelLuma(image,p+1*GetPixelChannels(image)))/QuantumRange) & 0x03) << 2) |
+         (((size_t) (3*ClampToQuantum(GetPixelLuma(image,p+0*GetPixelChannels(image)))/QuantumRange) & 0x03) << 0));
+      (void) FormatLocaleString(buffer,MagickPathExtent,"%02x",byte);
       (void) WriteBlobString(image,buffer);
-      p+=4;
+      p+=GetPixelChannels(image);
     }
     if ((image->columns % 4) != 0)
       {
-        i=(ssize_t) image->columns % 4;
-        byte=(unsigned char)
-          ((((size_t) (3*ClampToQuantum(GetPixelLuma(image,p+MagickMin(i,3)))/QuantumRange) & 0x03) << 6) |
-           (((size_t) (3*ClampToQuantum(GetPixelLuma(image,p+MagickMin(i,2)))/QuantumRange) & 0x03) << 4) |
-           (((size_t) (3*ClampToQuantum(GetPixelLuma(image,p+MagickMin(i,1)))/QuantumRange) & 0x03) << 2) |
-           (((size_t) (3*ClampToQuantum(GetPixelLuma(image,p+MagickMin(i,0)))/QuantumRange) & 0x03) << 0));
-        (void) FormatLocaleString(buffer,MaxTextExtent,"%02x",~byte);
+        byte=0;
+        for ( ; x < (ssize_t) image->columns; x++)
+        {
+          i=x % 4;
+          switch (i)
+          {
+            case 0:
+            {
+              byte|=(unsigned char) (((size_t) (3*ClampToQuantum(GetPixelLuma(
+                image,p+MagickMin(i,3)*GetPixelChannels(image)))/
+                QuantumRange) & 0x03) << 6);
+              break;
+            }
+            case 1:
+            {
+              byte|=(unsigned char) (((size_t) (3*ClampToQuantum(GetPixelLuma(
+                image,p+MagickMin(i,2)*GetPixelChannels(image)))/
+                QuantumRange) & 0x03) << 4);
+              break;
+            }
+            case 2:
+            {
+              byte|=(unsigned char) (((size_t) (3*ClampToQuantum(GetPixelLuma(
+                image,p+MagickMin(i,1)*GetPixelChannels(image)))/
+                QuantumRange) & 0x03) << 2);
+              break;
+            }
+            case 3:
+            {
+              byte|=(unsigned char) (((size_t) (3*ClampToQuantum(GetPixelLuma(
+                image,p+MagickMin(i,0)*GetPixelChannels(image)))/
+                QuantumRange) & 0x03) << 0);
+              break;
+            }
+          }
+        }
+        (void) FormatLocaleString(buffer,MagickPathExtent,"%02x",~byte);
         (void) WriteBlobString(image,buffer);
       }
     status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,