2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12 % Read/Write Cisco IP Phone Image Format %
19 % Copyright 1999-2011 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 *);
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=SetMagickInfo("CIP");
102 entry->encoder=(EncodeImageHandler *) WriteCIPImage;
103 entry->adjoin=MagickFalse;
104 entry->description=ConstantString("Cisco IP phone image format");
105 entry->module=ConstantString("CIP");
106 (void) RegisterMagickInfo(entry);
107 return(MagickImageCoderSignature);
111 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115 % U n r e g i s t e r C I P I m a g e %
119 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
121 % UnregisterCIPImage() removes format registrations made by the
122 % CIP module from the list of supported formats.
124 % The format of the UnregisterCIPImage method is:
126 % UnregisterCIPImage(void)
129 ModuleExport void UnregisterCIPImage(void)
131 (void) UnregisterMagickInfo("CIP");
135 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
139 % W r i t e C I P I m a g e %
143 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
145 % Procedure WriteCIPImage() writes an image to a file in the Cisco IP phone
148 % The format of the WriteCIPImage method is:
150 % MagickBooleanType WriteCIPImage(const ImageInfo *image_info,Image *image)
152 % A description of each parameter follows.
154 % o image_info: the image info.
156 % o image: The image.
160 static inline ssize_t MagickMin(const ssize_t x,const ssize_t y)
167 static MagickBooleanType WriteCIPImage(const ImageInfo *image_info,Image *image)
170 buffer[MaxTextExtent];
178 register const Quantum
192 Open output image file.
194 assert(image_info != (const ImageInfo *) NULL);
195 assert(image_info->signature == MagickSignature);
196 assert(image != (Image *) NULL);
197 assert(image->signature == MagickSignature);
198 if (image->debug != MagickFalse)
199 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
200 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
201 if (status == MagickFalse)
203 (void) WriteBlobString(image,"<CiscoIPPhoneImage>\n");
204 value=GetImageProperty(image,"label");
205 if (value != (const char *) NULL)
206 (void) FormatLocaleString(buffer,MaxTextExtent,"<Title>%s</Title>\n",value);
210 basename[MaxTextExtent];
212 GetPathComponent(image->filename,BasePath,basename);
213 (void) FormatLocaleString(buffer,MaxTextExtent,"<Title>%s</Title>\n",
216 (void) WriteBlobString(image,buffer);
217 (void) FormatLocaleString(buffer,MaxTextExtent,
218 "<LocationX>%.20g</LocationX>\n",(double) image->page.x);
219 (void) WriteBlobString(image,buffer);
220 (void) FormatLocaleString(buffer,MaxTextExtent,
221 "<LocationY>%.20g</LocationY>\n",(double) image->page.y);
222 (void) WriteBlobString(image,buffer);
223 (void) FormatLocaleString(buffer,MaxTextExtent,"<Width>%.20g</Width>\n",
224 (double) (image->columns+(image->columns % 2)));
225 (void) WriteBlobString(image,buffer);
226 (void) FormatLocaleString(buffer,MaxTextExtent,"<Height>%.20g</Height>\n",
227 (double) image->rows);
228 (void) WriteBlobString(image,buffer);
229 (void) FormatLocaleString(buffer,MaxTextExtent,"<Depth>2</Depth>\n");
230 (void) WriteBlobString(image,buffer);
231 (void) WriteBlobString(image,"<Data>");
232 if (IsRGBColorspace(image->colorspace) == MagickFalse)
233 (void) TransformImageColorspace(image,RGBColorspace);
234 for (y=0; y < (ssize_t) image->rows; y++)
236 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
237 if (p == (const Quantum *) NULL)
239 for (x=0; x < ((ssize_t) image->columns-3); x+=4)
242 ((((size_t) (4*GetPixelIntensity(image,p+3)/QuantumRange) & 0x03) << 6) |
243 (((size_t) (4*GetPixelIntensity(image,p+2)/QuantumRange) & 0x03) << 4) |
244 (((size_t) (4*GetPixelIntensity(image,p+1)/QuantumRange) & 0x03) << 2) |
245 (((size_t) (4*GetPixelIntensity(image,p+0)/QuantumRange) & 0x03) << 0));
246 (void) FormatLocaleString(buffer,MaxTextExtent,"%02x",byte);
247 (void) WriteBlobString(image,buffer);
250 if ((image->columns % 4) != 0)
252 i=(ssize_t) image->columns % 4;
254 ((((size_t) (4*GetPixelIntensity(image,p+MagickMin(i,3))/QuantumRange) & 0x03) << 6) |
255 (((size_t) (4*GetPixelIntensity(image,p+MagickMin(i,2))/QuantumRange) & 0x03) << 4) |
256 (((size_t) (4*GetPixelIntensity(image,p+MagickMin(i,1))/QuantumRange) & 0x03) << 2) |
257 (((size_t) (4*GetPixelIntensity(image,p+MagickMin(i,0))/QuantumRange) & 0x03) << 0));
258 (void) FormatLocaleString(buffer,MaxTextExtent,"%02x",~byte);
259 (void) WriteBlobString(image,buffer);
261 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
263 if (status == MagickFalse)
266 (void) WriteBlobString(image,"</Data>\n");
267 (void) WriteBlobString(image,"</CiscoIPPhoneImage>\n");
268 (void) CloseBlob(image);