2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12 % Read/Write Cisco IP Phone Image Format %
19 % Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization %
20 % dedicated to making software imaging solutions freely available. %
22 % You may not use this file except in compliance with the License. You may %
23 % obtain a copy of the License at %
25 % http://www.imagemagick.org/script/license.php %
27 % Unless required by applicable law or agreed to in writing, software %
28 % distributed under the License is distributed on an "AS IS" BASIS, %
29 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
30 % See the License for the specific language governing permissions and %
31 % limitations under the License. %
33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 #include "MagickCore/studio.h"
42 #include "MagickCore/blob.h"
43 #include "MagickCore/blob-private.h"
44 #include "MagickCore/cache.h"
45 #include "MagickCore/color-private.h"
46 #include "MagickCore/colorspace.h"
47 #include "MagickCore/colorspace-private.h"
48 #include "MagickCore/constitute.h"
49 #include "MagickCore/exception.h"
50 #include "MagickCore/exception-private.h"
51 #include "MagickCore/image.h"
52 #include "MagickCore/image-private.h"
53 #include "MagickCore/list.h"
54 #include "MagickCore/magick.h"
55 #include "MagickCore/memory_.h"
56 #include "MagickCore/monitor.h"
57 #include "MagickCore/monitor-private.h"
58 #include "MagickCore/pixel-accessor.h"
59 #include "MagickCore/property.h"
60 #include "MagickCore/quantize.h"
61 #include "MagickCore/quantum-private.h"
62 #include "MagickCore/static.h"
63 #include "MagickCore/string_.h"
64 #include "MagickCore/module.h"
65 #include "MagickCore/utility.h"
70 static MagickBooleanType
71 WriteCIPImage(const ImageInfo *,Image *,ExceptionInfo *);
74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78 % R e g i s t e r C I P I m a g e %
82 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84 % RegisterCIPImage() adds properties for the CIP IP phone image format to
85 % the list of supported formats. The properties include the image format
86 % tag, a method to read and/or write the format, whether the format
87 % supports the saving of more than one frame to the same file or blob,
88 % whether the format supports native in-memory I/O, and a brief
89 % description of the format.
91 % The format of the RegisterCIPImage method is:
93 % size_t RegisterCIPImage(void)
96 ModuleExport size_t RegisterCIPImage(void)
101 entry=AcquireMagickInfo("CIP","CIP","Cisco IP phone image format");
102 entry->encoder=(EncodeImageHandler *) WriteCIPImage;
103 entry->flags^=CoderAdjoinFlag;
104 (void) RegisterMagickInfo(entry);
105 return(MagickImageCoderSignature);
109 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113 % U n r e g i s t e r C I P I m a g e %
117 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
119 % UnregisterCIPImage() removes format registrations made by the
120 % CIP module from the list of supported formats.
122 % The format of the UnregisterCIPImage method is:
124 % UnregisterCIPImage(void)
127 ModuleExport void UnregisterCIPImage(void)
129 (void) UnregisterMagickInfo("CIP");
133 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
137 % W r i t e C I P I m a g e %
141 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
143 % Procedure WriteCIPImage() writes an image to a file in the Cisco IP phone
146 % The format of the WriteCIPImage method is:
148 % MagickBooleanType WriteCIPImage(const ImageInfo *image_info,
149 % Image *image,ExceptionInfo *exception)
151 % A description of each parameter follows.
153 % o image_info: the image info.
155 % o image: The image.
157 % o exception: return any errors or warnings in this structure.
160 static MagickBooleanType WriteCIPImage(const ImageInfo *image_info,Image *image,
161 ExceptionInfo *exception)
164 buffer[MaxTextExtent];
172 register const Quantum
186 Open output image file.
188 assert(image_info != (const ImageInfo *) NULL);
189 assert(image_info->signature == MagickSignature);
190 assert(image != (Image *) NULL);
191 assert(image->signature == MagickSignature);
192 if (image->debug != MagickFalse)
193 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
194 assert(exception != (ExceptionInfo *) NULL);
195 assert(exception->signature == MagickSignature);
196 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
197 if (status == MagickFalse)
199 (void) WriteBlobString(image,"<CiscoIPPhoneImage>\n");
200 value=GetImageProperty(image,"label",exception);
201 if (value != (const char *) NULL)
202 (void) FormatLocaleString(buffer,MaxTextExtent,"<Title>%s</Title>\n",value);
206 basename[MaxTextExtent];
208 GetPathComponent(image->filename,BasePath,basename);
209 (void) FormatLocaleString(buffer,MaxTextExtent,"<Title>%s</Title>\n",
212 (void) WriteBlobString(image,buffer);
213 (void) FormatLocaleString(buffer,MaxTextExtent,
214 "<LocationX>%.20g</LocationX>\n",(double) image->page.x);
215 (void) WriteBlobString(image,buffer);
216 (void) FormatLocaleString(buffer,MaxTextExtent,
217 "<LocationY>%.20g</LocationY>\n",(double) image->page.y);
218 (void) WriteBlobString(image,buffer);
219 (void) FormatLocaleString(buffer,MaxTextExtent,"<Width>%.20g</Width>\n",
220 (double) (image->columns+(image->columns % 2)));
221 (void) WriteBlobString(image,buffer);
222 (void) FormatLocaleString(buffer,MaxTextExtent,"<Height>%.20g</Height>\n",
223 (double) image->rows);
224 (void) WriteBlobString(image,buffer);
225 (void) FormatLocaleString(buffer,MaxTextExtent,"<Depth>2</Depth>\n");
226 (void) WriteBlobString(image,buffer);
227 (void) WriteBlobString(image,"<Data>");
228 (void) TransformImageColorspace(image,sRGBColorspace,exception);
229 for (y=0; y < (ssize_t) image->rows; y++)
231 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
232 if (p == (const Quantum *) NULL)
234 for (x=0; x < ((ssize_t) image->columns-3); x+=4)
237 ((((size_t) (3*ClampToQuantum(GetPixelLuma(image,p+3))/QuantumRange) & 0x03) << 6) |
238 (((size_t) (3*ClampToQuantum(GetPixelLuma(image,p+2))/QuantumRange) & 0x03) << 4) |
239 (((size_t) (3*ClampToQuantum(GetPixelLuma(image,p+1))/QuantumRange) & 0x03) << 2) |
240 (((size_t) (3*ClampToQuantum(GetPixelLuma(image,p+0))/QuantumRange) & 0x03) << 0));
241 (void) FormatLocaleString(buffer,MaxTextExtent,"%02x",byte);
242 (void) WriteBlobString(image,buffer);
245 if ((image->columns % 4) != 0)
247 i=(ssize_t) image->columns % 4;
249 ((((size_t) (3*ClampToQuantum(GetPixelLuma(image,p+MagickMin(i,3)))/QuantumRange) & 0x03) << 6) |
250 (((size_t) (3*ClampToQuantum(GetPixelLuma(image,p+MagickMin(i,2)))/QuantumRange) & 0x03) << 4) |
251 (((size_t) (3*ClampToQuantum(GetPixelLuma(image,p+MagickMin(i,1)))/QuantumRange) & 0x03) << 2) |
252 (((size_t) (3*ClampToQuantum(GetPixelLuma(image,p+MagickMin(i,0)))/QuantumRange) & 0x03) << 0));
253 (void) FormatLocaleString(buffer,MaxTextExtent,"%02x",~byte);
254 (void) WriteBlobString(image,buffer);
256 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
258 if (status == MagickFalse)
261 (void) WriteBlobString(image,"</Data>\n");
262 (void) WriteBlobString(image,"</CiscoIPPhoneImage>\n");
263 (void) CloseBlob(image);