| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 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" |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | static MagickBooleanType |
|---|
| 69 | WriteCIPImage(const ImageInfo *,Image *); |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | |
|---|
| 94 | ModuleExport unsigned long RegisterCIPImage(void) |
|---|
| 95 | { |
|---|
| 96 | MagickInfo |
|---|
| 97 | *entry; |
|---|
| 98 | |
|---|
| 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); |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | |
|---|
| 126 | |
|---|
| 127 | ModuleExport void UnregisterCIPImage(void) |
|---|
| 128 | { |
|---|
| 129 | (void) UnregisterMagickInfo("CIP"); |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | |
|---|
| 151 | |
|---|
| 152 | |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | |
|---|
| 157 | |
|---|
| 158 | static inline long MagickMin(const long x,const long y) |
|---|
| 159 | { |
|---|
| 160 | if (x < y) |
|---|
| 161 | return(x); |
|---|
| 162 | return(y); |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | static MagickBooleanType WriteCIPImage(const ImageInfo *image_info,Image *image) |
|---|
| 166 | { |
|---|
| 167 | char |
|---|
| 168 | buffer[MaxTextExtent]; |
|---|
| 169 | |
|---|
| 170 | const char |
|---|
| 171 | *value; |
|---|
| 172 | |
|---|
| 173 | long |
|---|
| 174 | y; |
|---|
| 175 | |
|---|
| 176 | MagickBooleanType |
|---|
| 177 | status; |
|---|
| 178 | |
|---|
| 179 | register const PixelPacket |
|---|
| 180 | *p; |
|---|
| 181 | |
|---|
| 182 | register long |
|---|
| 183 | i, |
|---|
| 184 | x; |
|---|
| 185 | |
|---|
| 186 | unsigned char |
|---|
| 187 | byte; |
|---|
| 188 | |
|---|
| 189 | |
|---|
| 190 | |
|---|
| 191 | |
|---|
| 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) |
|---|
| 200 | return(status); |
|---|
| 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); |
|---|
| 205 | else |
|---|
| 206 | { |
|---|
| 207 | char |
|---|
| 208 | basename[MaxTextExtent]; |
|---|
| 209 | |
|---|
| 210 | GetPathComponent(image->filename,BasePath,basename); |
|---|
| 211 | (void) FormatMagickString(buffer,MaxTextExtent,"<Title>%s</Title>\n", |
|---|
| 212 | basename); |
|---|
| 213 | } |
|---|
| 214 | (void) WriteBlobString(image,buffer); |
|---|
| 215 | (void) FormatMagickString(buffer,MaxTextExtent,"<LocationX>%ld</LocationX>\n", |
|---|
| 216 | image->page.x); |
|---|
| 217 | (void) WriteBlobString(image,buffer); |
|---|
| 218 | (void) FormatMagickString(buffer,MaxTextExtent,"<LocationY>%ld</LocationY>\n", |
|---|
| 219 | image->page.y); |
|---|
| 220 | (void) WriteBlobString(image,buffer); |
|---|
| 221 | (void) FormatMagickString(buffer,MaxTextExtent,"<Width>%lu</Width>\n", |
|---|
| 222 | image->columns+(image->columns % 2)); |
|---|
| 223 | (void) WriteBlobString(image,buffer); |
|---|
| 224 | (void) FormatMagickString(buffer,MaxTextExtent,"<Height>%lu</Height>\n", |
|---|
| 225 | 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 < (long) image->rows; y++) |
|---|
| 233 | { |
|---|
| 234 | p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception); |
|---|
| 235 | if (p == (const PixelPacket *) NULL) |
|---|
| 236 | break; |
|---|
| 237 | for (x=0; x < ((long) image->columns-3); x+=4) |
|---|
| 238 | { |
|---|
| 239 | byte=(unsigned char) |
|---|
| 240 | ((((unsigned long) (4*PixelIntensityToQuantum(p+3)/QuantumRange) & 0x03) << 6) | |
|---|
| 241 | (((unsigned long) (4*PixelIntensityToQuantum(p+2)/QuantumRange) & 0x03) << 4) | |
|---|
| 242 | (((unsigned long) (4*PixelIntensityToQuantum(p+1)/QuantumRange) & 0x03) << 2) | |
|---|
| 243 | (((unsigned long) (4*PixelIntensityToQuantum(p+0)/QuantumRange) & 0x03) << 0)); |
|---|
| 244 | (void) FormatMagickString(buffer,MaxTextExtent,"%02x",byte); |
|---|
| 245 | (void) WriteBlobString(image,buffer); |
|---|
| 246 | p+=4; |
|---|
| 247 | } |
|---|
| 248 | if ((image->columns % 4) != 0) |
|---|
| 249 | { |
|---|
| 250 | i=(long) image->columns % 4; |
|---|
| 251 | byte=(unsigned char) |
|---|
| 252 | ((((unsigned long) (4*PixelIntensityToQuantum(p+MagickMin(i,3))/QuantumRange) & 0x03) << 6) | |
|---|
| 253 | (((unsigned long) (4*PixelIntensityToQuantum(p+MagickMin(i,2))/QuantumRange) & 0x03) << 4) | |
|---|
| 254 | (((unsigned long) (4*PixelIntensityToQuantum(p+MagickMin(i,1))/QuantumRange) & 0x03) << 2) | |
|---|
| 255 | (((unsigned long) (4*PixelIntensityToQuantum(p+MagickMin(i,0))/QuantumRange) & 0x03) << 0)); |
|---|
| 256 | (void) FormatMagickString(buffer,MaxTextExtent,"%02x",~byte); |
|---|
| 257 | (void) WriteBlobString(image,buffer); |
|---|
| 258 | } |
|---|
| 259 | status=SetImageProgress(image,SaveImageTag,y,image->rows); |
|---|
| 260 | if (status == MagickFalse) |
|---|
| 261 | break; |
|---|
| 262 | } |
|---|
| 263 | (void) WriteBlobString(image,"</Data>\n"); |
|---|
| 264 | (void) WriteBlobString(image,"</CiscoIPPhoneImage>\n"); |
|---|
| 265 | (void) CloseBlob(image); |
|---|
| 266 | return(MagickTrue); |
|---|
| 267 | } |
|---|