2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12 % Read/Write Cisco IP Phone Image Format %
19 % Copyright 1999-2010 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 "magick/studio.h"
42 #include "magick/blob.h"
43 #include "magick/blob-private.h"
44 #include "magick/cache.h"
45 #include "magick/color-private.h"
46 #include "magick/colorspace.h"
47 #include "magick/constitute.h"
48 #include "magick/exception.h"
49 #include "magick/exception-private.h"
50 #include "magick/image.h"
51 #include "magick/image-private.h"
52 #include "magick/list.h"
53 #include "magick/magick.h"
54 #include "magick/memory_.h"
55 #include "magick/monitor.h"
56 #include "magick/monitor-private.h"
57 #include "magick/property.h"
58 #include "magick/quantize.h"
59 #include "magick/quantum-private.h"
60 #include "magick/static.h"
61 #include "magick/string_.h"
62 #include "magick/module.h"
63 #include "magick/utility.h"
68 static MagickBooleanType
69 WriteCIPImage(const ImageInfo *,Image *);
72 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76 % R e g i s t e r C I P I m a g e %
80 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82 % RegisterCIPImage() adds properties for the CIP IP phone image format to
83 % the list of supported formats. The properties include the image format
84 % tag, a method to read and/or write the format, whether the format
85 % supports the saving of more than one frame to the same file or blob,
86 % whether the format supports native in-memory I/O, and a brief
87 % description of the format.
89 % The format of the RegisterCIPImage method is:
91 % size_t RegisterCIPImage(void)
94 ModuleExport size_t RegisterCIPImage(void)
99 entry=SetMagickInfo("CIP");
100 entry->encoder=(EncodeImageHandler *) WriteCIPImage;
101 entry->adjoin=MagickFalse;
102 entry->description=ConstantString("Cisco IP phone image format");
103 entry->module=ConstantString("CIP");
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,Image *image)
150 % A description of each parameter follows.
152 % o image_info: the image info.
154 % o image: The image.
158 static inline ssize_t MagickMin(const ssize_t x,const ssize_t y)
165 static MagickBooleanType WriteCIPImage(const ImageInfo *image_info,Image *image)
168 buffer[MaxTextExtent];
179 register const PixelPacket
190 Open output image file.
192 assert(image_info != (const ImageInfo *) NULL);
193 assert(image_info->signature == MagickSignature);
194 assert(image != (Image *) NULL);
195 assert(image->signature == MagickSignature);
196 if (image->debug != MagickFalse)
197 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
198 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
199 if (status == MagickFalse)
201 (void) WriteBlobString(image,"<CiscoIPPhoneImage>\n");
202 value=GetImageProperty(image,"label");
203 if (value != (const char *) NULL)
204 (void) FormatMagickString(buffer,MaxTextExtent,"<Title>%s</Title>\n",value);
208 basename[MaxTextExtent];
210 GetPathComponent(image->filename,BasePath,basename);
211 (void) FormatMagickString(buffer,MaxTextExtent,"<Title>%s</Title>\n",
214 (void) WriteBlobString(image,buffer);
215 (void) FormatMagickString(buffer,MaxTextExtent,
216 "<LocationX>%.20g</LocationX>\n",(double) image->page.x);
217 (void) WriteBlobString(image,buffer);
218 (void) FormatMagickString(buffer,MaxTextExtent,
219 "<LocationY>%.20g</LocationY>\n",(double) image->page.y);
220 (void) WriteBlobString(image,buffer);
221 (void) FormatMagickString(buffer,MaxTextExtent,"<Width>%.20g</Width>\n",
222 (double) (image->columns+(image->columns % 2)));
223 (void) WriteBlobString(image,buffer);
224 (void) FormatMagickString(buffer,MaxTextExtent,"<Height>%.20g</Height>\n",
225 (double) image->rows);
226 (void) WriteBlobString(image,buffer);
227 (void) FormatMagickString(buffer,MaxTextExtent,"<Depth>2</Depth>\n");
228 (void) WriteBlobString(image,buffer);
229 (void) WriteBlobString(image,"<Data>");
230 if (image->colorspace != RGBColorspace)
231 (void) TransformImageColorspace(image,RGBColorspace);
232 for (y=0; y < (ssize_t) image->rows; y++)
234 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
235 if (p == (const PixelPacket *) NULL)
237 for (x=0; x < ((ssize_t) image->columns-3); x+=4)
240 ((((size_t) (4*PixelIntensityToQuantum(p+3)/QuantumRange) & 0x03) << 6) |
241 (((size_t) (4*PixelIntensityToQuantum(p+2)/QuantumRange) & 0x03) << 4) |
242 (((size_t) (4*PixelIntensityToQuantum(p+1)/QuantumRange) & 0x03) << 2) |
243 (((size_t) (4*PixelIntensityToQuantum(p+0)/QuantumRange) & 0x03) << 0));
244 (void) FormatMagickString(buffer,MaxTextExtent,"%02x",byte);
245 (void) WriteBlobString(image,buffer);
248 if ((image->columns % 4) != 0)
250 i=(ssize_t) image->columns % 4;
252 ((((size_t) (4*PixelIntensityToQuantum(p+MagickMin(i,3))/QuantumRange) & 0x03) << 6) |
253 (((size_t) (4*PixelIntensityToQuantum(p+MagickMin(i,2))/QuantumRange) & 0x03) << 4) |
254 (((size_t) (4*PixelIntensityToQuantum(p+MagickMin(i,1))/QuantumRange) & 0x03) << 2) |
255 (((size_t) (4*PixelIntensityToQuantum(p+MagickMin(i,0))/QuantumRange) & 0x03) << 0));
256 (void) FormatMagickString(buffer,MaxTextExtent,"%02x",~byte);
257 (void) WriteBlobString(image,buffer);
259 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
261 if (status == MagickFalse)
264 (void) WriteBlobString(image,"</Data>\n");
265 (void) WriteBlobString(image,"</CiscoIPPhoneImage>\n");
266 (void) CloseBlob(image);