Powered by Pair ImageMagick logo
Image Magick
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages

ImageMagick-6.1.1/coders/cip.c

Go to the documentation of this file.
00001 /* 00002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00003 % % 00004 % % 00005 % CCCC IIIII PPPP % 00006 % C I P P % 00007 % C I PPPP % 00008 % C I P % 00009 % CCCC IIIII P % 00010 % % 00011 % % 00012 % Read/Write Cisco IP Phone Image Format. % 00013 % % 00014 % Software Design % 00015 % John Cristy % 00016 % April 2004 % 00017 % % 00018 % % 00019 % Copyright 1999-2004 ImageMagick Studio LLC, a non-profit organization % 00020 % dedicated to making software imaging solutions freely available. % 00021 % % 00022 % You may not use this file except in compliance with the License. You may % 00023 % obtain a copy of the License at % 00024 % % 00025 % http://www.imagemagick.org/www/Copyright.html % 00026 % % 00027 % Unless required by applicable law or agreed to in writing, software % 00028 % distributed under the License is distributed on an "AS IS" BASIS, % 00029 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % 00030 % See the License for the specific language governing permissions and % 00031 % limitations under the License. % 00032 % % 00033 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00034 % 00035 % 00036 */ 00037 00038 /* 00039 Include declarations. 00040 */ 00041 #include "magick/studio.h" 00042 #include "magick/attribute.h" 00043 #include "magick/blob.h" 00044 #include "magick/blob_private.h" 00045 #include "magick/colorspace.h" 00046 #include "magick/constitute.h" 00047 #include "magick/error.h" 00048 #include "magick/error_private.h" 00049 #include "magick/image.h" 00050 #include "magick/image_private.h" 00051 #include "magick/list.h" 00052 #include "magick/magick.h" 00053 #include "magick/memory_.h" 00054 #include "magick/monitor.h" 00055 #include "magick/quantize.h" 00056 #include "magick/static.h" 00057 #include "magick/string_.h" 00058 #include "magick/utility.h" 00059 00060 /* 00061 Forward declarations. 00062 */ 00063 static MagickBooleanType 00064 WriteCIPImage(const ImageInfo *,Image *); 00065 00066 /* 00067 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00068 % % 00069 % % 00070 % % 00071 % R e g i s t e r C I P I m a g e % 00072 % % 00073 % % 00074 % % 00075 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00076 % 00077 % RegisterCIPImage() adds attributes for the CIP IP phone image format to 00078 % the list of supported formats. The attributes include the image format 00079 % tag, a method to read and/or write the format, whether the format 00080 % supports the saving of more than one frame to the same file or blob, 00081 % whether the format supports native in-memory I/O, and a brief 00082 % description of the format. 00083 % 00084 % The format of the RegisterCIPImage method is: 00085 % 00086 % RegisterCIPImage(void) 00087 % 00088 */ 00089 ModuleExport void RegisterCIPImage(void) 00090 { 00091 MagickInfo 00092 *entry; 00093 00094 entry=SetMagickInfo("CIP"); 00095 entry->encoder=(EncoderHandler *) WriteCIPImage; 00096 entry->adjoin=MagickFalse; 00097 entry->description=AcquireString("Cisco IP phone image format"); 00098 entry->module=AcquireString("CIP"); 00099 (void) RegisterMagickInfo(entry); 00100 } 00101 00102 /* 00103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00104 % % 00105 % % 00106 % % 00107 % U n r e g i s t e r C I P I m a g e % 00108 % % 00109 % % 00110 % % 00111 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00112 % 00113 % UnregisterCIPImage() removes format registrations made by the 00114 % CIP module from the list of supported formats. 00115 % 00116 % The format of the UnregisterCIPImage method is: 00117 % 00118 % UnregisterCIPImage(void) 00119 % 00120 */ 00121 ModuleExport void UnregisterCIPImage(void) 00122 { 00123 (void) UnregisterMagickInfo("CIP"); 00124 } 00125 00126 /* 00127 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00128 % % 00129 % % 00130 % % 00131 % W r i t e C I P I m a g e % 00132 % % 00133 % % 00134 % % 00135 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00136 % 00137 % Procedure WriteCIPImage() writes an image to a file in the Cisco IP phone 00138 % image format. 00139 % 00140 % The format of the WriteCIPImage method is: 00141 % 00142 % MagickBooleanType WriteCIPImage(const ImageInfo *image_info,Image *image) 00143 % 00144 % A description of each parameter follows. 00145 % 00146 % o image_info: The image info. 00147 % 00148 % o image: The image. 00149 % 00150 % 00151 */ 00152 static MagickBooleanType WriteCIPImage(const ImageInfo *image_info,Image *image) 00153 { 00154 char 00155 buffer[MaxTextExtent]; 00156 00157 const ImageAttribute 00158 *attribute; 00159 00160 long 00161 y; 00162 00163 MagickBooleanType 00164 status; 00165 00166 register const PixelPacket 00167 *p; 00168 00169 register long 00170 i, 00171 x; 00172 00173 unsigned char 00174 byte; 00175 00176 /* 00177 Open output image file. 00178 */ 00179 assert(image_info != (const ImageInfo *) NULL); 00180 assert(image_info->signature == MagickSignature); 00181 assert(image != (Image *) NULL); 00182 assert(image->signature == MagickSignature); 00183 if (image->debug != MagickFalse) 00184 (void) LogMagickEvent(TraceEvent,GetMagickModule(),image->filename); 00185 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception); 00186 if (status == MagickFalse) 00187 return(status); 00188 (void) WriteBlobString(image,"<CiscoIPPhoneImage>\n"); 00189 attribute=GetImageAttribute(image,"label"); 00190 if (attribute != (const ImageAttribute *) NULL) 00191 (void) FormatMagickString(buffer,MaxTextExtent,"<Title>%s</Title>\n", 00192 attribute->value); 00193 else 00194 { 00195 char 00196 basename[MaxTextExtent]; 00197 00198 GetPathComponent(image->filename,BasePath,basename); 00199 (void) FormatMagickString(buffer,MaxTextExtent,"<Title>%s</Title>\n", 00200 basename); 00201 } 00202 (void) WriteBlobString(image,buffer); 00203 (void) FormatMagickString(buffer,MaxTextExtent,"<LocationX>%ld</LocationX>\n", 00204 image->page.x); 00205 (void) WriteBlobString(image,buffer); 00206 (void) FormatMagickString(buffer,MaxTextExtent,"<LocationY>%ld</LocationY>\n", 00207 image->page.y); 00208 (void) WriteBlobString(image,buffer); 00209 (void) FormatMagickString(buffer,MaxTextExtent,"<Width>%lu</Width>\n", 00210 image->columns+(image->columns % 2)); 00211 (void) WriteBlobString(image,buffer); 00212 (void) FormatMagickString(buffer,MaxTextExtent,"<Height>%lu</Height>\n", 00213 image->rows); 00214 (void) WriteBlobString(image,buffer); 00215 (void) FormatMagickString(buffer,MaxTextExtent,"<Depth>2</Depth>\n"); 00216 (void) WriteBlobString(image,buffer); 00217 (void) WriteBlobString(image,"<Data>"); 00218 (void) SetImageColorspace(image,RGBColorspace); 00219 for (y=0; y < (long) image->rows; y++) 00220 { 00221 p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception); 00222 if (p == (const PixelPacket *) NULL) 00223 break; 00224 for (x=0; x < ((long) image->columns-3); x+=4) 00225 { 00226 byte=(unsigned char) 00227 (((4*PixelIntensityToQuantum(p+3)/MaxRGB) & 0x03) << 6) | 00228 (((4*PixelIntensityToQuantum(p+2)/MaxRGB) & 0x03) << 4) | 00229 (((4*PixelIntensityToQuantum(p+1)/MaxRGB) & 0x03) << 2) | 00230 (((4*PixelIntensityToQuantum(p+0)/MaxRGB) & 0x03) << 0); 00231 (void) FormatMagickString(buffer,MaxTextExtent,"%02x",byte); 00232 (void) WriteBlobString(image,buffer); 00233 p+=4; 00234 } 00235 if ((image->columns % 4) != 0) 00236 { 00237 i=(long) image->columns % 4; 00238 byte=(unsigned char) 00239 ((((4*PixelIntensityToQuantum(p+Min(i,3))/MaxRGB) & 0x03) << 6) | 00240 (((4*PixelIntensityToQuantum(p+Min(i,2))/MaxRGB) & 0x03) << 4) | 00241 (((4*PixelIntensityToQuantum(p+Min(i,1))/MaxRGB) & 0x03) << 2) | 00242 (((4*PixelIntensityToQuantum(p+Min(i,0))/MaxRGB) & 0x03) << 0)); 00243 (void) FormatMagickString(buffer,MaxTextExtent,"%02x",~byte); 00244 (void) WriteBlobString(image,buffer); 00245 } 00246 if ((image->progress_monitor != (MagickProgressMonitor) NULL) && 00247 (QuantumTick(y,image->rows) != MagickFalse)) 00248 { 00249 status=image->progress_monitor(SaveImageTag,y,image->rows, 00250 image->client_data); 00251 if (status == MagickFalse) 00252 break; 00253 } 00254 } 00255 (void) WriteBlobString(image,"</Data>\n"); 00256 (void) WriteBlobString(image,"</CiscoIPPhoneImage>\n"); 00257 CloseBlob(image); 00258 return(MagickTrue); 00259 }

Generated on Mon Oct 25 13:40:35 2004 for ImageMagick by doxygen 1.3.7
ImageMagick Copyright © 2004, ImageMagick Studio LLC