cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % IIIII CCCC OOO N N % |
| 7 | % I C O O NN N % |
| 8 | % I C O O N N N % |
| 9 | % I C O O N NN % |
| 10 | % IIIII CCCC OOO N N % |
| 11 | % % |
| 12 | % % |
| 13 | % Read Microsoft Windows Icon Format % |
| 14 | % % |
| 15 | % Software Design % |
| 16 | % John Cristy % |
| 17 | % July 1992 % |
| 18 | % % |
| 19 | % % |
cristy | 7e41fe8 | 2010-12-04 23:12:08 +0000 | [diff] [blame] | 20 | % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 21 | % dedicated to making software imaging solutions freely available. % |
| 22 | % % |
| 23 | % You may not use this file except in compliance with the License. You may % |
| 24 | % obtain a copy of the License at % |
| 25 | % % |
| 26 | % http://www.imagemagick.org/script/license.php % |
| 27 | % % |
| 28 | % Unless required by applicable law or agreed to in writing, software % |
| 29 | % distributed under the License is distributed on an "AS IS" BASIS, % |
| 30 | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
| 31 | % See the License for the specific language governing permissions and % |
| 32 | % limitations under the License. % |
| 33 | % % |
| 34 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 35 | % |
| 36 | % |
| 37 | */ |
| 38 | |
| 39 | /* |
| 40 | Include declarations. |
| 41 | */ |
| 42 | #include "magick/studio.h" |
| 43 | #include "magick/blob.h" |
| 44 | #include "magick/blob-private.h" |
| 45 | #include "magick/cache.h" |
cristy | e7e4055 | 2010-04-24 21:34:22 +0000 | [diff] [blame] | 46 | #include "magick/colormap.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 47 | #include "magick/colorspace.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/log.h" |
| 54 | #include "magick/magick.h" |
| 55 | #include "magick/memory_.h" |
| 56 | #include "magick/monitor.h" |
| 57 | #include "magick/monitor-private.h" |
| 58 | #include "magick/nt-feature.h" |
| 59 | #include "magick/quantize.h" |
| 60 | #include "magick/quantum-private.h" |
| 61 | #include "magick/static.h" |
| 62 | #include "magick/string_.h" |
| 63 | #include "magick/module.h" |
| 64 | |
| 65 | /* |
| 66 | Define declarations. |
| 67 | */ |
cristy | 0157aea | 2010-04-24 21:12:18 +0000 | [diff] [blame] | 68 | #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__MINGW32__) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 69 | #define BI_RGB 0 |
| 70 | #define BI_RLE8 1 |
| 71 | #define BI_BITFIELDS 3 |
| 72 | #endif |
| 73 | #define MaxIcons 1024 |
| 74 | |
| 75 | /* |
| 76 | Typedef declarations. |
| 77 | */ |
| 78 | typedef struct _IconEntry |
| 79 | { |
| 80 | unsigned char |
| 81 | width, |
| 82 | height, |
| 83 | colors, |
| 84 | reserved; |
| 85 | |
| 86 | unsigned short int |
| 87 | planes, |
| 88 | bits_per_pixel; |
| 89 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 90 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 91 | size, |
| 92 | offset; |
| 93 | } IconEntry; |
| 94 | |
| 95 | typedef struct _IconFile |
| 96 | { |
| 97 | short |
| 98 | reserved, |
| 99 | resource_type, |
| 100 | count; |
| 101 | |
| 102 | IconEntry |
| 103 | directory[MaxIcons]; |
| 104 | } IconFile; |
| 105 | |
| 106 | typedef struct _IconInfo |
| 107 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 108 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 109 | file_size, |
| 110 | ba_offset, |
| 111 | offset_bits, |
| 112 | size; |
| 113 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 114 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 115 | width, |
| 116 | height; |
| 117 | |
| 118 | unsigned short |
| 119 | planes, |
| 120 | bits_per_pixel; |
| 121 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 122 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 123 | compression, |
| 124 | image_size, |
| 125 | x_pixels, |
| 126 | y_pixels, |
| 127 | number_colors, |
| 128 | red_mask, |
| 129 | green_mask, |
| 130 | blue_mask, |
| 131 | alpha_mask, |
| 132 | colors_important; |
| 133 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 134 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 135 | colorspace; |
| 136 | } IconInfo; |
| 137 | |
| 138 | /* |
| 139 | Forward declaractions. |
| 140 | */ |
| 141 | static MagickBooleanType |
| 142 | WriteICONImage(const ImageInfo *,Image *); |
| 143 | |
| 144 | /* |
| 145 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 146 | % % |
| 147 | % % |
| 148 | % % |
| 149 | % R e a d I C O N I m a g e % |
| 150 | % % |
| 151 | % % |
| 152 | % % |
| 153 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 154 | % |
| 155 | % ReadICONImage() reads a Microsoft icon image file and returns it. It |
| 156 | % allocates the memory necessary for the new Image structure and returns a |
| 157 | % pointer to the new image. |
| 158 | % |
| 159 | % The format of the ReadICONImage method is: |
| 160 | % |
| 161 | % Image *ReadICONImage(const ImageInfo *image_info, |
| 162 | % ExceptionInfo *exception) |
| 163 | % |
| 164 | % A description of each parameter follows: |
| 165 | % |
| 166 | % o image_info: the image info. |
| 167 | % |
| 168 | % o exception: return any errors or warnings in this structure. |
| 169 | % |
| 170 | */ |
| 171 | static Image *ReadICONImage(const ImageInfo *image_info, |
| 172 | ExceptionInfo *exception) |
| 173 | { |
| 174 | IconFile |
| 175 | icon_file; |
| 176 | |
| 177 | IconInfo |
| 178 | icon_info; |
| 179 | |
| 180 | Image |
| 181 | *image; |
| 182 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 183 | MagickBooleanType |
| 184 | status; |
| 185 | |
| 186 | register IndexPacket |
| 187 | *indexes; |
| 188 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 189 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 190 | i, |
| 191 | x; |
| 192 | |
| 193 | register PixelPacket |
| 194 | *q; |
| 195 | |
| 196 | register unsigned char |
| 197 | *p; |
| 198 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 199 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 200 | bit, |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 201 | byte, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 202 | bytes_per_line, |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 203 | one, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 204 | scanline_pad; |
| 205 | |
cristy | ebc891a | 2011-04-24 23:04:16 +0000 | [diff] [blame^] | 206 | ssize_t |
| 207 | count, |
| 208 | offset, |
| 209 | y; |
| 210 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 211 | /* |
| 212 | Open image file. |
| 213 | */ |
| 214 | assert(image_info != (const ImageInfo *) NULL); |
| 215 | assert(image_info->signature == MagickSignature); |
| 216 | (void) LogMagickEvent(CoderEvent,GetMagickModule(),"%s",image_info->filename); |
| 217 | assert(exception != (ExceptionInfo *) NULL); |
| 218 | assert(exception->signature == MagickSignature); |
| 219 | image=AcquireImage(image_info); |
| 220 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 221 | if (status == MagickFalse) |
| 222 | { |
| 223 | image=DestroyImageList(image); |
| 224 | return((Image *) NULL); |
| 225 | } |
| 226 | icon_file.reserved=(short) ReadBlobLSBShort(image); |
| 227 | icon_file.resource_type=(short) ReadBlobLSBShort(image); |
| 228 | icon_file.count=(short) ReadBlobLSBShort(image); |
| 229 | if ((icon_file.reserved != 0) || |
| 230 | ((icon_file.resource_type != 1) && (icon_file.resource_type != 2)) || |
| 231 | (icon_file.count > MaxIcons)) |
| 232 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
| 233 | for (i=0; i < icon_file.count; i++) |
| 234 | { |
| 235 | icon_file.directory[i].width=(unsigned char) ReadBlobByte(image); |
| 236 | icon_file.directory[i].height=(unsigned char) ReadBlobByte(image); |
| 237 | icon_file.directory[i].colors=(unsigned char) ReadBlobByte(image); |
| 238 | icon_file.directory[i].reserved=(unsigned char) ReadBlobByte(image); |
| 239 | icon_file.directory[i].planes=(unsigned short) ReadBlobLSBShort(image); |
| 240 | icon_file.directory[i].bits_per_pixel=(unsigned short) |
| 241 | ReadBlobLSBShort(image); |
| 242 | icon_file.directory[i].size=ReadBlobLSBLong(image); |
| 243 | icon_file.directory[i].offset=ReadBlobLSBLong(image); |
| 244 | } |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 245 | one=1; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 246 | for (i=0; i < icon_file.count; i++) |
| 247 | { |
| 248 | /* |
| 249 | Verify Icon identifier. |
| 250 | */ |
| 251 | offset=(ssize_t) SeekBlob(image,(MagickOffsetType) |
| 252 | icon_file.directory[i].offset,SEEK_SET); |
| 253 | if (offset < 0) |
| 254 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
| 255 | icon_info.size=ReadBlobLSBLong(image); |
cristy | d63c050 | 2011-01-03 15:45:11 +0000 | [diff] [blame] | 256 | icon_info.width=(unsigned char) ((int) ReadBlobLSBLong(image)); |
| 257 | icon_info.height=(unsigned char) ((int) ReadBlobLSBLong(image)/2); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 258 | if ((icon_file.directory[i].width == 0) && |
| 259 | (icon_file.directory[i].height == 0)) |
| 260 | { |
| 261 | Image |
| 262 | *icon_image; |
| 263 | |
| 264 | ImageInfo |
| 265 | *read_info; |
| 266 | |
| 267 | size_t |
| 268 | length; |
| 269 | |
| 270 | unsigned char |
| 271 | *png; |
| 272 | |
| 273 | /* |
| 274 | Icon image encoded as a compressed PNG image. |
| 275 | */ |
| 276 | length=icon_file.directory[i].size; |
| 277 | png=(unsigned char *) AcquireQuantumMemory(length+12,sizeof(*png)); |
| 278 | if (png == (unsigned char *) NULL) |
| 279 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
| 280 | (void) CopyMagickMemory(png,"\211PNG\r\n\032\n\000\000\000\015",12); |
cristy | c8817fe | 2010-08-01 13:43:59 +0000 | [diff] [blame] | 281 | count=ReadBlob(image,length-12,png+12); |
| 282 | if (count != (ssize_t) (length-12)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 283 | { |
| 284 | png=(unsigned char *) RelinquishMagickMemory(png); |
| 285 | ThrowReaderException(CorruptImageError, |
| 286 | "InsufficientImageDataInFile"); |
| 287 | } |
| 288 | read_info=CloneImageInfo(image_info); |
| 289 | (void) CopyMagickString(read_info->magick,"PNG",MaxTextExtent); |
| 290 | icon_image=BlobToImage(read_info,png,length+12,exception); |
| 291 | read_info=DestroyImageInfo(read_info); |
| 292 | png=(unsigned char *) RelinquishMagickMemory(png); |
| 293 | if (icon_image == (Image *) NULL) |
| 294 | { |
| 295 | image=DestroyImageList(image); |
| 296 | return((Image *) NULL); |
| 297 | } |
| 298 | DestroyBlob(icon_image); |
| 299 | icon_image->blob=ReferenceBlob(image->blob); |
| 300 | ReplaceImageInList(&image,icon_image); |
| 301 | } |
| 302 | else |
| 303 | { |
| 304 | icon_info.planes=ReadBlobLSBShort(image); |
| 305 | icon_info.bits_per_pixel=ReadBlobLSBShort(image); |
| 306 | if (icon_info.bits_per_pixel > 32) |
| 307 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
| 308 | icon_info.compression=ReadBlobLSBLong(image); |
| 309 | icon_info.image_size=ReadBlobLSBLong(image); |
| 310 | icon_info.x_pixels=ReadBlobLSBLong(image); |
| 311 | icon_info.y_pixels=ReadBlobLSBLong(image); |
| 312 | icon_info.number_colors=ReadBlobLSBLong(image); |
| 313 | icon_info.colors_important=ReadBlobLSBLong(image); |
| 314 | image->matte=MagickTrue; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 315 | image->columns=(size_t) icon_file.directory[i].width; |
| 316 | if ((ssize_t) image->columns > icon_info.width) |
| 317 | image->columns=(size_t) icon_info.width; |
| 318 | image->rows=(size_t) icon_file.directory[i].height; |
| 319 | if ((ssize_t) image->rows > icon_info.height) |
| 320 | image->rows=(size_t) icon_info.height; |
cristy | c8817fe | 2010-08-01 13:43:59 +0000 | [diff] [blame] | 321 | image->depth=icon_info.bits_per_pixel; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 322 | if (image->debug != MagickFalse) |
| 323 | { |
| 324 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 325 | " scene = %.20g",(double) i); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 326 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 327 | " size = %.20g",(double) icon_info.size); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 328 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 329 | " width = %.20g",(double) icon_file.directory[i].width); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 330 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 331 | " height = %.20g",(double) icon_file.directory[i].height); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 332 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 333 | " colors = %.20g",(double ) icon_info.number_colors); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 334 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 335 | " planes = %.20g",(double) icon_info.planes); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 336 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 337 | " bpp = %.20g",(double) icon_info.bits_per_pixel); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 338 | } |
| 339 | if ((icon_info.number_colors != 0) || (icon_info.bits_per_pixel <= 16)) |
| 340 | { |
| 341 | image->storage_class=PseudoClass; |
| 342 | image->colors=icon_info.number_colors; |
| 343 | if (image->colors == 0) |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 344 | image->colors=one << icon_info.bits_per_pixel; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 345 | } |
| 346 | if (image->storage_class == PseudoClass) |
| 347 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 348 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 349 | i; |
| 350 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 351 | size_t |
cristy | 0b29b25 | 2010-05-30 01:59:46 +0000 | [diff] [blame] | 352 | number_colors, |
| 353 | one; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 354 | |
cristy | ebc891a | 2011-04-24 23:04:16 +0000 | [diff] [blame^] | 355 | unsigned char |
| 356 | *icon_colormap; |
| 357 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 358 | /* |
| 359 | Read Icon raster colormap. |
| 360 | */ |
cristy | 0b29b25 | 2010-05-30 01:59:46 +0000 | [diff] [blame] | 361 | one=1; |
| 362 | number_colors=one << icon_info.bits_per_pixel; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 363 | if (AcquireImageColormap(image,number_colors) == MagickFalse) |
| 364 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
| 365 | icon_colormap=(unsigned char *) AcquireQuantumMemory((size_t) |
| 366 | image->colors,4UL*sizeof(*icon_colormap)); |
| 367 | if (icon_colormap == (unsigned char *) NULL) |
| 368 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
| 369 | count=ReadBlob(image,(size_t) (4*image->colors),icon_colormap); |
| 370 | if (count != (ssize_t) (4*image->colors)) |
| 371 | ThrowReaderException(CorruptImageError, |
| 372 | "InsufficientImageDataInFile"); |
| 373 | p=icon_colormap; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 374 | for (i=0; i < (ssize_t) image->colors; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 375 | { |
| 376 | image->colormap[i].blue=(Quantum) ScaleCharToQuantum(*p++); |
| 377 | image->colormap[i].green=(Quantum) ScaleCharToQuantum(*p++); |
| 378 | image->colormap[i].red=(Quantum) ScaleCharToQuantum(*p++); |
| 379 | p++; |
| 380 | } |
| 381 | icon_colormap=(unsigned char *) RelinquishMagickMemory(icon_colormap); |
| 382 | } |
| 383 | /* |
| 384 | Convert Icon raster image to pixel packets. |
| 385 | */ |
| 386 | if ((image_info->ping != MagickFalse) && |
| 387 | (image_info->number_scenes != 0)) |
| 388 | if (image->scene >= (image_info->scene+image_info->number_scenes-1)) |
| 389 | break; |
| 390 | bytes_per_line=(((image->columns*icon_info.bits_per_pixel)+31) & |
| 391 | ~31) >> 3; |
cristy | da16f16 | 2011-02-19 23:52:17 +0000 | [diff] [blame] | 392 | (void) bytes_per_line; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 393 | scanline_pad=((((image->columns*icon_info.bits_per_pixel)+31) & ~31)- |
| 394 | (image->columns*icon_info.bits_per_pixel)) >> 3; |
| 395 | switch (icon_info.bits_per_pixel) |
| 396 | { |
| 397 | case 1: |
| 398 | { |
| 399 | /* |
| 400 | Convert bitmap scanline. |
| 401 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 402 | for (y=(ssize_t) image->rows-1; y >= 0; y--) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 403 | { |
| 404 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
| 405 | if (q == (PixelPacket *) NULL) |
| 406 | break; |
| 407 | indexes=GetAuthenticIndexQueue(image); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 408 | for (x=0; x < (ssize_t) (image->columns-7); x+=8) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 409 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 410 | byte=(size_t) ReadBlobByte(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 411 | for (bit=0; bit < 8; bit++) |
cristy | ebc891a | 2011-04-24 23:04:16 +0000 | [diff] [blame^] | 412 | SetIndexPixelComponent(indexes+x+bit, |
| 413 | ((byte & (0x80 >> bit)) != 0 ? 0x01 : 0x00)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 414 | } |
| 415 | if ((image->columns % 8) != 0) |
| 416 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 417 | byte=(size_t) ReadBlobByte(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 418 | for (bit=0; bit < (image->columns % 8); bit++) |
cristy | ebc891a | 2011-04-24 23:04:16 +0000 | [diff] [blame^] | 419 | SetIndexPixelComponent(indexes+x+bit, |
| 420 | ((byte & (0x80 >> bit)) != 0 ? 0x01 : 0x00)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 421 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 422 | for (x=0; x < (ssize_t) scanline_pad; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 423 | (void) ReadBlobByte(image); |
| 424 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 425 | break; |
| 426 | if (image->previous == (Image *) NULL) |
| 427 | { |
| 428 | status=SetImageProgress(image,LoadImageTag,image->rows-y-1, |
| 429 | image->rows); |
| 430 | if (status == MagickFalse) |
| 431 | break; |
| 432 | } |
| 433 | } |
| 434 | break; |
| 435 | } |
| 436 | case 4: |
| 437 | { |
| 438 | /* |
| 439 | Read 4-bit Icon scanline. |
| 440 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 441 | for (y=(ssize_t) image->rows-1; y >= 0; y--) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 442 | { |
| 443 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
| 444 | if (q == (PixelPacket *) NULL) |
| 445 | break; |
| 446 | indexes=GetAuthenticIndexQueue(image); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 447 | for (x=0; x < ((ssize_t) image->columns-1); x+=2) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 448 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 449 | byte=(size_t) ReadBlobByte(image); |
cristy | ebc891a | 2011-04-24 23:04:16 +0000 | [diff] [blame^] | 450 | SetIndexPixelComponent(indexes+x,((byte >> 4) & 0xf)); |
| 451 | SetIndexPixelComponent(indexes+x+1,((byte) & 0xf)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 452 | } |
| 453 | if ((image->columns % 2) != 0) |
| 454 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 455 | byte=(size_t) ReadBlobByte(image); |
cristy | ebc891a | 2011-04-24 23:04:16 +0000 | [diff] [blame^] | 456 | SetIndexPixelComponent(indexes+x,((byte >> 4) & 0xf)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 457 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 458 | for (x=0; x < (ssize_t) scanline_pad; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 459 | (void) ReadBlobByte(image); |
| 460 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 461 | break; |
| 462 | if (image->previous == (Image *) NULL) |
| 463 | { |
| 464 | status=SetImageProgress(image,LoadImageTag,image->rows-y-1, |
| 465 | image->rows); |
| 466 | if (status == MagickFalse) |
| 467 | break; |
| 468 | } |
| 469 | } |
| 470 | break; |
| 471 | } |
| 472 | case 8: |
| 473 | { |
| 474 | /* |
| 475 | Convert PseudoColor scanline. |
| 476 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 477 | for (y=(ssize_t) image->rows-1; y >= 0; y--) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 478 | { |
| 479 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
| 480 | if (q == (PixelPacket *) NULL) |
| 481 | break; |
| 482 | indexes=GetAuthenticIndexQueue(image); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 483 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 484 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 485 | byte=(size_t) ReadBlobByte(image); |
cristy | ebc891a | 2011-04-24 23:04:16 +0000 | [diff] [blame^] | 486 | SetIndexPixelComponent(indexes+x,byte); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 487 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 488 | for (x=0; x < (ssize_t) scanline_pad; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 489 | (void) ReadBlobByte(image); |
| 490 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 491 | break; |
| 492 | if (image->previous == (Image *) NULL) |
| 493 | { |
| 494 | status=SetImageProgress(image,LoadImageTag,image->rows-y-1, |
| 495 | image->rows); |
| 496 | if (status == MagickFalse) |
| 497 | break; |
| 498 | } |
| 499 | } |
| 500 | break; |
| 501 | } |
| 502 | case 16: |
| 503 | { |
| 504 | /* |
| 505 | Convert PseudoColor scanline. |
| 506 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 507 | for (y=(ssize_t) image->rows-1; y >= 0; y--) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 508 | { |
| 509 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
| 510 | if (q == (PixelPacket *) NULL) |
| 511 | break; |
| 512 | indexes=GetAuthenticIndexQueue(image); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 513 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 514 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 515 | byte=(size_t) ReadBlobByte(image); |
| 516 | byte|=(size_t) (ReadBlobByte(image) << 8); |
cristy | ebc891a | 2011-04-24 23:04:16 +0000 | [diff] [blame^] | 517 | SetIndexPixelComponent(indexes+x,byte); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 518 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 519 | for (x=0; x < (ssize_t) scanline_pad; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 520 | (void) ReadBlobByte(image); |
| 521 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 522 | break; |
| 523 | if (image->previous == (Image *) NULL) |
| 524 | { |
| 525 | status=SetImageProgress(image,LoadImageTag,image->rows-y-1, |
| 526 | image->rows); |
| 527 | if (status == MagickFalse) |
| 528 | break; |
| 529 | } |
| 530 | } |
| 531 | break; |
| 532 | } |
| 533 | case 24: |
| 534 | case 32: |
| 535 | { |
| 536 | /* |
| 537 | Convert DirectColor scanline. |
| 538 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 539 | for (y=(ssize_t) image->rows-1; y >= 0; y--) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 540 | { |
| 541 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
| 542 | if (q == (PixelPacket *) NULL) |
| 543 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 544 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 545 | { |
cristy | ebc891a | 2011-04-24 23:04:16 +0000 | [diff] [blame^] | 546 | SetBluePixelComponent(q,ScaleCharToQuantum((unsigned char) |
| 547 | ReadBlobByte(image))); |
| 548 | SetGreenPixelComponent(q,ScaleCharToQuantum((unsigned char) |
| 549 | ReadBlobByte(image))); |
| 550 | SetRedPixelComponent(q,ScaleCharToQuantum((unsigned char) |
| 551 | ReadBlobByte(image))); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 552 | if (icon_info.bits_per_pixel == 32) |
cristy | ebc891a | 2011-04-24 23:04:16 +0000 | [diff] [blame^] | 553 | SetOpacityPixelComponent(q,(QuantumRange-ScaleCharToQuantum( |
| 554 | (unsigned char) ReadBlobByte(image)))); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 555 | q++; |
| 556 | } |
| 557 | if (icon_info.bits_per_pixel == 24) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 558 | for (x=0; x < (ssize_t) scanline_pad; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 559 | (void) ReadBlobByte(image); |
| 560 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 561 | break; |
| 562 | if (image->previous == (Image *) NULL) |
| 563 | { |
| 564 | status=SetImageProgress(image,LoadImageTag,image->rows-y-1, |
| 565 | image->rows); |
| 566 | if (status == MagickFalse) |
| 567 | break; |
| 568 | } |
| 569 | } |
| 570 | break; |
| 571 | } |
| 572 | default: |
| 573 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
| 574 | } |
cristy | 5dd7188 | 2010-08-01 20:53:13 +0000 | [diff] [blame] | 575 | if (image_info->ping == MagickFalse) |
| 576 | (void) SyncImage(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 577 | if (icon_info.bits_per_pixel != 32) |
| 578 | { |
| 579 | /* |
| 580 | Read the ICON alpha mask. |
| 581 | */ |
| 582 | image->storage_class=DirectClass; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 583 | for (y=(ssize_t) image->rows-1; y >= 0; y--) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 584 | { |
| 585 | q=GetAuthenticPixels(image,0,y,image->columns,1,exception); |
| 586 | if (q == (PixelPacket *) NULL) |
| 587 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 588 | for (x=0; x < ((ssize_t) image->columns-7); x+=8) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 589 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 590 | byte=(size_t) ReadBlobByte(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 591 | for (bit=0; bit < 8; bit++) |
cristy | ebc891a | 2011-04-24 23:04:16 +0000 | [diff] [blame^] | 592 | SetOpacityPixelComponent(q+x+bit,(((byte & (0x80 >> bit)) != |
| 593 | 0) ? TransparentOpacity : OpaqueOpacity)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 594 | } |
| 595 | if ((image->columns % 8) != 0) |
| 596 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 597 | byte=(size_t) ReadBlobByte(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 598 | for (bit=0; bit < (image->columns % 8); bit++) |
cristy | ebc891a | 2011-04-24 23:04:16 +0000 | [diff] [blame^] | 599 | SetOpacityPixelComponent(q+x+bit,(((byte & (0x80 >> bit)) != |
| 600 | 0) ? TransparentOpacity : OpaqueOpacity)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 601 | } |
cristy | 0e8200f | 2009-09-13 21:10:06 +0000 | [diff] [blame] | 602 | if ((image->columns % 32) != 0) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 603 | for (x=0; x < (ssize_t) ((32-(image->columns % 32))/8); x++) |
cristy | 0e8200f | 2009-09-13 21:10:06 +0000 | [diff] [blame] | 604 | (void) ReadBlobByte(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 605 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 606 | break; |
| 607 | } |
| 608 | } |
| 609 | if (EOFBlob(image) != MagickFalse) |
| 610 | { |
| 611 | ThrowFileException(exception,CorruptImageError, |
| 612 | "UnexpectedEndOfFile",image->filename); |
| 613 | break; |
| 614 | } |
| 615 | } |
| 616 | /* |
| 617 | Proceed to next image. |
| 618 | */ |
| 619 | if (image_info->number_scenes != 0) |
| 620 | if (image->scene >= (image_info->scene+image_info->number_scenes-1)) |
| 621 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 622 | if (i < (ssize_t) (icon_file.count-1)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 623 | { |
| 624 | /* |
| 625 | Allocate next image structure. |
| 626 | */ |
| 627 | AcquireNextImage(image_info,image); |
| 628 | if (GetNextImageInList(image) == (Image *) NULL) |
| 629 | { |
| 630 | image=DestroyImageList(image); |
| 631 | return((Image *) NULL); |
| 632 | } |
| 633 | image=SyncNextImageInList(image); |
| 634 | status=SetImageProgress(image,LoadImagesTag,TellBlob(image), |
| 635 | GetBlobSize(image)); |
| 636 | if (status == MagickFalse) |
| 637 | break; |
| 638 | } |
| 639 | } |
| 640 | (void) CloseBlob(image); |
| 641 | return(GetFirstImageInList(image)); |
| 642 | } |
| 643 | |
| 644 | /* |
| 645 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 646 | % % |
| 647 | % % |
| 648 | % % |
| 649 | % R e g i s t e r I C O N I m a g e % |
| 650 | % % |
| 651 | % % |
| 652 | % % |
| 653 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 654 | % |
| 655 | % RegisterICONImage() adds attributes for the Icon image format to |
| 656 | % the list of supported formats. The attributes include the image format |
| 657 | % tag, a method to read and/or write the format, whether the format |
| 658 | % supports the saving of more than one frame to the same file or blob, |
| 659 | % whether the format supports native in-memory I/O, and a brief |
| 660 | % description of the format. |
| 661 | % |
| 662 | % The format of the RegisterICONImage method is: |
| 663 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 664 | % size_t RegisterICONImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 665 | % |
| 666 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 667 | ModuleExport size_t RegisterICONImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 668 | { |
| 669 | MagickInfo |
| 670 | *entry; |
| 671 | |
| 672 | entry=SetMagickInfo("CUR"); |
| 673 | entry->decoder=(DecodeImageHandler *) ReadICONImage; |
| 674 | entry->encoder=(EncodeImageHandler *) WriteICONImage; |
| 675 | entry->adjoin=MagickFalse; |
| 676 | entry->seekable_stream=MagickTrue; |
| 677 | entry->description=ConstantString("Microsoft icon"); |
| 678 | entry->module=ConstantString("CUR"); |
| 679 | (void) RegisterMagickInfo(entry); |
| 680 | entry=SetMagickInfo("ICO"); |
| 681 | entry->decoder=(DecodeImageHandler *) ReadICONImage; |
| 682 | entry->encoder=(EncodeImageHandler *) WriteICONImage; |
| 683 | entry->adjoin=MagickTrue; |
| 684 | entry->seekable_stream=MagickTrue; |
| 685 | entry->description=ConstantString("Microsoft icon"); |
| 686 | entry->module=ConstantString("ICON"); |
| 687 | (void) RegisterMagickInfo(entry); |
| 688 | entry=SetMagickInfo("ICON"); |
| 689 | entry->decoder=(DecodeImageHandler *) ReadICONImage; |
| 690 | entry->encoder=(EncodeImageHandler *) WriteICONImage; |
| 691 | entry->adjoin=MagickFalse; |
| 692 | entry->seekable_stream=MagickTrue; |
| 693 | entry->description=ConstantString("Microsoft icon"); |
| 694 | entry->module=ConstantString("ICON"); |
| 695 | (void) RegisterMagickInfo(entry); |
| 696 | return(MagickImageCoderSignature); |
| 697 | } |
| 698 | |
| 699 | /* |
| 700 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 701 | % % |
| 702 | % % |
| 703 | % % |
| 704 | % U n r e g i s t e r I C O N I m a g e % |
| 705 | % % |
| 706 | % % |
| 707 | % % |
| 708 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 709 | % |
| 710 | % UnregisterICONImage() removes format registrations made by the |
| 711 | % ICON module from the list of supported formats. |
| 712 | % |
| 713 | % The format of the UnregisterICONImage method is: |
| 714 | % |
| 715 | % UnregisterICONImage(void) |
| 716 | % |
| 717 | */ |
| 718 | ModuleExport void UnregisterICONImage(void) |
| 719 | { |
| 720 | (void) UnregisterMagickInfo("CUR"); |
| 721 | (void) UnregisterMagickInfo("ICO"); |
| 722 | (void) UnregisterMagickInfo("ICON"); |
| 723 | } |
| 724 | |
| 725 | /* |
| 726 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 727 | % % |
| 728 | % % |
| 729 | % % |
| 730 | % W r i t e I C O N I m a g e % |
| 731 | % % |
| 732 | % % |
| 733 | % % |
| 734 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 735 | % |
| 736 | % WriteICONImage() writes an image in Microsoft Windows bitmap encoded |
| 737 | % image format, version 3 for Windows or (if the image has a matte channel) |
| 738 | % version 4. |
| 739 | % |
| 740 | % The format of the WriteICONImage method is: |
| 741 | % |
| 742 | % MagickBooleanType WriteICONImage(const ImageInfo *image_info, |
| 743 | % Image *image) |
| 744 | % |
| 745 | % A description of each parameter follows. |
| 746 | % |
| 747 | % o image_info: the image info. |
| 748 | % |
| 749 | % o image: The image. |
| 750 | % |
| 751 | */ |
| 752 | static MagickBooleanType WriteICONImage(const ImageInfo *image_info, |
| 753 | Image *image) |
| 754 | { |
| 755 | IconFile |
| 756 | icon_file; |
| 757 | |
| 758 | IconInfo |
| 759 | icon_info; |
| 760 | |
| 761 | Image |
| 762 | *next; |
| 763 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 764 | MagickBooleanType |
| 765 | status; |
| 766 | |
| 767 | MagickOffsetType |
| 768 | offset, |
| 769 | scene; |
| 770 | |
| 771 | register const IndexPacket |
| 772 | *indexes; |
| 773 | |
| 774 | register const PixelPacket |
| 775 | *p; |
| 776 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 777 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 778 | i, |
| 779 | x; |
| 780 | |
| 781 | register unsigned char |
| 782 | *q; |
| 783 | |
cristy | ebc891a | 2011-04-24 23:04:16 +0000 | [diff] [blame^] | 784 | size_t |
| 785 | bytes_per_line, |
| 786 | scanline_pad; |
| 787 | |
| 788 | ssize_t |
| 789 | y; |
| 790 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 791 | unsigned char |
| 792 | bit, |
| 793 | byte, |
| 794 | *pixels; |
| 795 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 796 | /* |
| 797 | Open output image file. |
| 798 | */ |
| 799 | assert(image_info != (const ImageInfo *) NULL); |
| 800 | assert(image_info->signature == MagickSignature); |
| 801 | assert(image != (Image *) NULL); |
| 802 | assert(image->signature == MagickSignature); |
| 803 | (void) LogMagickEvent(CoderEvent,GetMagickModule(),"%s",image->filename); |
| 804 | status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception); |
| 805 | if (status == MagickFalse) |
| 806 | return(status); |
| 807 | scene=0; |
| 808 | next=image; |
| 809 | do |
| 810 | { |
| 811 | if ((image->columns > 256L) || (image->rows > 256L)) |
| 812 | ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit"); |
| 813 | scene++; |
| 814 | next=SyncNextImageInList(next); |
| 815 | } while ((next != (Image *) NULL) && (image_info->adjoin != MagickFalse)); |
| 816 | /* |
| 817 | Dump out a ICON header template to be properly initialized later. |
| 818 | */ |
| 819 | (void) WriteBlobLSBShort(image,0); |
| 820 | (void) WriteBlobLSBShort(image,1); |
| 821 | (void) WriteBlobLSBShort(image,(unsigned char) scene); |
| 822 | (void) ResetMagickMemory(&icon_file,0,sizeof(icon_file)); |
| 823 | (void) ResetMagickMemory(&icon_info,0,sizeof(icon_info)); |
| 824 | scene=0; |
| 825 | next=image; |
| 826 | do |
| 827 | { |
| 828 | (void) WriteBlobByte(image,icon_file.directory[scene].width); |
| 829 | (void) WriteBlobByte(image,icon_file.directory[scene].height); |
| 830 | (void) WriteBlobByte(image,icon_file.directory[scene].colors); |
| 831 | (void) WriteBlobByte(image,icon_file.directory[scene].reserved); |
| 832 | (void) WriteBlobLSBShort(image,icon_file.directory[scene].planes); |
| 833 | (void) WriteBlobLSBShort(image,icon_file.directory[scene].bits_per_pixel); |
cristy | 0b29b25 | 2010-05-30 01:59:46 +0000 | [diff] [blame] | 834 | (void) WriteBlobLSBLong(image,(unsigned int) |
| 835 | icon_file.directory[scene].size); |
| 836 | (void) WriteBlobLSBLong(image,(unsigned int) |
| 837 | icon_file.directory[scene].offset); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 838 | scene++; |
| 839 | next=SyncNextImageInList(next); |
| 840 | } while ((next != (Image *) NULL) && (image_info->adjoin != MagickFalse)); |
| 841 | scene=0; |
| 842 | next=image; |
| 843 | do |
| 844 | { |
| 845 | if ((next->columns == 256) && (next->rows == 256)) |
| 846 | { |
| 847 | Image |
| 848 | *write_image; |
| 849 | |
| 850 | ImageInfo |
| 851 | *write_info; |
| 852 | |
| 853 | size_t |
| 854 | length; |
| 855 | |
| 856 | unsigned char |
| 857 | *png; |
| 858 | |
| 859 | /* |
| 860 | Icon image encoded as a compressed PNG image. |
| 861 | */ |
| 862 | write_image=CloneImage(next,0,0,MagickTrue,&image->exception); |
| 863 | if (write_image == (Image *) NULL) |
| 864 | return(MagickFalse); |
| 865 | write_info=CloneImageInfo(image_info); |
| 866 | (void) CopyMagickString(write_info->filename,"PNG:",MaxTextExtent); |
| 867 | png=(unsigned char *) ImageToBlob(write_info,write_image,&length, |
| 868 | &image->exception); |
| 869 | write_image=DestroyImage(write_image); |
| 870 | write_info=DestroyImageInfo(write_info); |
| 871 | if (png == (unsigned char *) NULL) |
| 872 | return(MagickFalse); |
| 873 | icon_file.directory[scene].width=0; |
| 874 | icon_file.directory[scene].height=0; |
| 875 | icon_file.directory[scene].colors=0; |
| 876 | icon_file.directory[scene].reserved=0; |
| 877 | icon_file.directory[scene].planes=1; |
| 878 | icon_file.directory[scene].bits_per_pixel=32; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 879 | icon_file.directory[scene].size=(size_t) length; |
| 880 | icon_file.directory[scene].offset=(size_t) TellBlob(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 881 | (void) WriteBlob(image,(size_t) length,png); |
| 882 | png=(unsigned char *) RelinquishMagickMemory(png); |
| 883 | } |
| 884 | else |
| 885 | { |
| 886 | /* |
| 887 | Initialize ICON raster file header. |
| 888 | */ |
| 889 | if (next->colorspace != RGBColorspace) |
| 890 | (void) TransformImageColorspace(next,RGBColorspace); |
| 891 | icon_info.file_size=14+12+28; |
| 892 | icon_info.offset_bits=icon_info.file_size; |
| 893 | icon_info.compression=BI_RGB; |
| 894 | if ((next->storage_class != DirectClass) && (next->colors > 256)) |
| 895 | (void) SetImageStorageClass(next,DirectClass); |
| 896 | if (next->storage_class == DirectClass) |
| 897 | { |
| 898 | /* |
| 899 | Full color ICON raster. |
| 900 | */ |
| 901 | icon_info.number_colors=0; |
| 902 | icon_info.bits_per_pixel=32; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 903 | icon_info.compression=(size_t) BI_RGB; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 904 | } |
| 905 | else |
| 906 | { |
cristy | 35ef824 | 2010-06-03 16:24:13 +0000 | [diff] [blame] | 907 | size_t |
| 908 | one; |
| 909 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 910 | /* |
| 911 | Colormapped ICON raster. |
| 912 | */ |
| 913 | icon_info.bits_per_pixel=8; |
| 914 | if (next->colors <= 256) |
| 915 | icon_info.bits_per_pixel=8; |
| 916 | if (next->colors <= 16) |
| 917 | icon_info.bits_per_pixel=4; |
| 918 | if (next->colors <= 2) |
| 919 | icon_info.bits_per_pixel=1; |
cristy | 35ef824 | 2010-06-03 16:24:13 +0000 | [diff] [blame] | 920 | one=1; |
| 921 | icon_info.number_colors=one << icon_info.bits_per_pixel; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 922 | if (icon_info.number_colors < next->colors) |
| 923 | { |
| 924 | (void) SetImageStorageClass(next,DirectClass); |
| 925 | icon_info.number_colors=0; |
| 926 | icon_info.bits_per_pixel=(unsigned short) 24; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 927 | icon_info.compression=(size_t) BI_RGB; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 928 | } |
| 929 | else |
| 930 | { |
cristy | 0b29b25 | 2010-05-30 01:59:46 +0000 | [diff] [blame] | 931 | size_t |
| 932 | one; |
| 933 | |
| 934 | one=1; |
| 935 | icon_info.file_size+=3*(one << icon_info.bits_per_pixel); |
| 936 | icon_info.offset_bits+=3*(one << icon_info.bits_per_pixel); |
| 937 | icon_info.file_size+=(one << icon_info.bits_per_pixel); |
| 938 | icon_info.offset_bits+=(one << icon_info.bits_per_pixel); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 939 | } |
| 940 | } |
| 941 | bytes_per_line=(((next->columns*icon_info.bits_per_pixel)+31) & |
| 942 | ~31) >> 3; |
| 943 | icon_info.ba_offset=0; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 944 | icon_info.width=(ssize_t) next->columns; |
| 945 | icon_info.height=(ssize_t) next->rows; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 946 | icon_info.planes=1; |
| 947 | icon_info.image_size=bytes_per_line*next->rows; |
| 948 | icon_info.size=40; |
| 949 | icon_info.size+=(4*icon_info.number_colors); |
| 950 | icon_info.size+=icon_info.image_size; |
| 951 | icon_info.size+=(((icon_info.width+31) & ~31) >> 3)*icon_info.height; |
| 952 | icon_info.file_size+=icon_info.image_size; |
| 953 | icon_info.x_pixels=0; |
| 954 | icon_info.y_pixels=0; |
| 955 | switch (next->units) |
| 956 | { |
| 957 | case UndefinedResolution: |
| 958 | case PixelsPerInchResolution: |
| 959 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 960 | icon_info.x_pixels=(size_t) (100.0*next->x_resolution/2.54); |
| 961 | icon_info.y_pixels=(size_t) (100.0*next->y_resolution/2.54); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 962 | break; |
| 963 | } |
| 964 | case PixelsPerCentimeterResolution: |
| 965 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 966 | icon_info.x_pixels=(size_t) (100.0*next->x_resolution); |
| 967 | icon_info.y_pixels=(size_t) (100.0*next->y_resolution); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 968 | break; |
| 969 | } |
| 970 | } |
| 971 | icon_info.colors_important=icon_info.number_colors; |
| 972 | /* |
| 973 | Convert MIFF to ICON raster pixels. |
| 974 | */ |
| 975 | pixels=(unsigned char *) AcquireQuantumMemory((size_t) |
| 976 | icon_info.image_size,sizeof(*pixels)); |
| 977 | if (pixels == (unsigned char *) NULL) |
| 978 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
| 979 | (void) ResetMagickMemory(pixels,0,(size_t) icon_info.image_size); |
| 980 | switch (icon_info.bits_per_pixel) |
| 981 | { |
| 982 | case 1: |
| 983 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 984 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 985 | bit, |
| 986 | byte; |
| 987 | |
| 988 | /* |
| 989 | Convert PseudoClass image to a ICON monochrome image. |
| 990 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 991 | for (y=0; y < (ssize_t) next->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 992 | { |
| 993 | p=GetVirtualPixels(next,0,y,next->columns,1,&next->exception); |
| 994 | if (p == (const PixelPacket *) NULL) |
| 995 | break; |
| 996 | indexes=GetVirtualIndexQueue(next); |
| 997 | q=pixels+(next->rows-y-1)*bytes_per_line; |
| 998 | bit=0; |
| 999 | byte=0; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1000 | for (x=0; x < (ssize_t) next->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1001 | { |
| 1002 | byte<<=1; |
cristy | ebc891a | 2011-04-24 23:04:16 +0000 | [diff] [blame^] | 1003 | byte|=GetIndexPixelComponent(indexes+x) != 0 ? 0x01 : 0x00; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1004 | bit++; |
| 1005 | if (bit == 8) |
| 1006 | { |
| 1007 | *q++=(unsigned char) byte; |
| 1008 | bit=0; |
| 1009 | byte=0; |
| 1010 | } |
| 1011 | } |
| 1012 | if (bit != 0) |
| 1013 | *q++=(unsigned char) (byte << (8-bit)); |
| 1014 | if (next->previous == (Image *) NULL) |
| 1015 | { |
| 1016 | status=SetImageProgress(next,SaveImageTag,y,next->rows); |
| 1017 | if (status == MagickFalse) |
| 1018 | break; |
| 1019 | } |
| 1020 | } |
| 1021 | break; |
| 1022 | } |
| 1023 | case 4: |
| 1024 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1025 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1026 | nibble, |
| 1027 | byte; |
| 1028 | |
| 1029 | /* |
| 1030 | Convert PseudoClass image to a ICON monochrome image. |
| 1031 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1032 | for (y=0; y < (ssize_t) next->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1033 | { |
| 1034 | p=GetVirtualPixels(next,0,y,next->columns,1,&next->exception); |
| 1035 | if (p == (const PixelPacket *) NULL) |
| 1036 | break; |
| 1037 | indexes=GetVirtualIndexQueue(next); |
| 1038 | q=pixels+(next->rows-y-1)*bytes_per_line; |
| 1039 | nibble=0; |
| 1040 | byte=0; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1041 | for (x=0; x < (ssize_t) next->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1042 | { |
| 1043 | byte<<=4; |
cristy | ebc891a | 2011-04-24 23:04:16 +0000 | [diff] [blame^] | 1044 | byte|=((size_t) GetIndexPixelComponent(indexes+x) & 0x0f); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1045 | nibble++; |
| 1046 | if (nibble == 2) |
| 1047 | { |
| 1048 | *q++=(unsigned char) byte; |
| 1049 | nibble=0; |
| 1050 | byte=0; |
| 1051 | } |
| 1052 | } |
| 1053 | if (nibble != 0) |
| 1054 | *q++=(unsigned char) (byte << 4); |
| 1055 | if (next->previous == (Image *) NULL) |
| 1056 | { |
| 1057 | status=SetImageProgress(next,SaveImageTag,y,next->rows); |
| 1058 | if (status == MagickFalse) |
| 1059 | break; |
| 1060 | } |
| 1061 | } |
| 1062 | break; |
| 1063 | } |
| 1064 | case 8: |
| 1065 | { |
| 1066 | /* |
| 1067 | Convert PseudoClass packet to ICON pixel. |
| 1068 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1069 | for (y=0; y < (ssize_t) next->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1070 | { |
| 1071 | p=GetVirtualPixels(next,0,y,next->columns,1,&next->exception); |
| 1072 | if (p == (const PixelPacket *) NULL) |
| 1073 | break; |
| 1074 | indexes=GetVirtualIndexQueue(next); |
| 1075 | q=pixels+(next->rows-y-1)*bytes_per_line; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1076 | for (x=0; x < (ssize_t) next->columns; x++) |
cristy | 4e82e51 | 2011-04-24 01:33:42 +0000 | [diff] [blame] | 1077 | *q++=(unsigned char) GetIndexPixelComponent(indexes+x); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1078 | if (next->previous == (Image *) NULL) |
| 1079 | { |
| 1080 | status=SetImageProgress(next,SaveImageTag,y,next->rows); |
| 1081 | if (status == MagickFalse) |
| 1082 | break; |
| 1083 | } |
| 1084 | } |
| 1085 | break; |
| 1086 | } |
| 1087 | case 24: |
| 1088 | case 32: |
| 1089 | { |
| 1090 | /* |
| 1091 | Convert DirectClass packet to ICON BGR888 or BGRA8888 pixel. |
| 1092 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1093 | for (y=0; y < (ssize_t) next->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1094 | { |
| 1095 | p=GetVirtualPixels(next,0,y,next->columns,1,&next->exception); |
| 1096 | if (p == (const PixelPacket *) NULL) |
| 1097 | break; |
| 1098 | q=pixels+(next->rows-y-1)*bytes_per_line; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1099 | for (x=0; x < (ssize_t) next->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1100 | { |
cristy | ce70c17 | 2010-01-07 17:15:30 +0000 | [diff] [blame] | 1101 | *q++=ScaleQuantumToChar(GetBluePixelComponent(p)); |
| 1102 | *q++=ScaleQuantumToChar(GetGreenPixelComponent(p)); |
| 1103 | *q++=ScaleQuantumToChar(GetRedPixelComponent(p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1104 | if (next->matte == MagickFalse) |
| 1105 | *q++=ScaleQuantumToChar(QuantumRange); |
| 1106 | else |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1107 | *q++=ScaleQuantumToChar(GetAlphaPixelComponent(p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1108 | p++; |
| 1109 | } |
| 1110 | if (icon_info.bits_per_pixel == 24) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1111 | for (x=3L*(ssize_t) next->columns; x < (ssize_t) bytes_per_line; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1112 | *q++=0x00; |
| 1113 | if (next->previous == (Image *) NULL) |
| 1114 | { |
| 1115 | status=SetImageProgress(next,SaveImageTag,y,next->rows); |
| 1116 | if (status == MagickFalse) |
| 1117 | break; |
| 1118 | } |
| 1119 | } |
| 1120 | break; |
| 1121 | } |
| 1122 | } |
| 1123 | /* |
| 1124 | Write 40-byte version 3+ bitmap header. |
| 1125 | */ |
| 1126 | icon_file.directory[scene].width=(unsigned char) icon_info.width; |
| 1127 | icon_file.directory[scene].height=(unsigned char) icon_info.height; |
| 1128 | icon_file.directory[scene].colors=(unsigned char) |
| 1129 | icon_info.number_colors; |
| 1130 | icon_file.directory[scene].reserved=0; |
| 1131 | icon_file.directory[scene].planes=icon_info.planes; |
| 1132 | icon_file.directory[scene].bits_per_pixel=icon_info.bits_per_pixel; |
| 1133 | icon_file.directory[scene].size=icon_info.size; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1134 | icon_file.directory[scene].offset=(size_t) TellBlob(image); |
cristy | 35ef824 | 2010-06-03 16:24:13 +0000 | [diff] [blame] | 1135 | (void) WriteBlobLSBLong(image,(unsigned int) 40); |
| 1136 | (void) WriteBlobLSBLong(image,(unsigned int) icon_info.width); |
| 1137 | (void) WriteBlobLSBLong(image,(unsigned int) icon_info.height*2); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1138 | (void) WriteBlobLSBShort(image,icon_info.planes); |
| 1139 | (void) WriteBlobLSBShort(image,icon_info.bits_per_pixel); |
cristy | 35ef824 | 2010-06-03 16:24:13 +0000 | [diff] [blame] | 1140 | (void) WriteBlobLSBLong(image,(unsigned int) icon_info.compression); |
| 1141 | (void) WriteBlobLSBLong(image,(unsigned int) icon_info.image_size); |
| 1142 | (void) WriteBlobLSBLong(image,(unsigned int) icon_info.x_pixels); |
| 1143 | (void) WriteBlobLSBLong(image,(unsigned int) icon_info.y_pixels); |
| 1144 | (void) WriteBlobLSBLong(image,(unsigned int) icon_info.number_colors); |
| 1145 | (void) WriteBlobLSBLong(image,(unsigned int) icon_info.colors_important); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1146 | if (next->storage_class == PseudoClass) |
| 1147 | { |
| 1148 | unsigned char |
| 1149 | *icon_colormap; |
| 1150 | |
| 1151 | /* |
| 1152 | Dump colormap to file. |
| 1153 | */ |
| 1154 | icon_colormap=(unsigned char *) AcquireQuantumMemory((size_t) |
| 1155 | (1UL << icon_info.bits_per_pixel),4UL*sizeof(*icon_colormap)); |
| 1156 | if (icon_colormap == (unsigned char *) NULL) |
| 1157 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
| 1158 | q=icon_colormap; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1159 | for (i=0; i < (ssize_t) next->colors; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1160 | { |
| 1161 | *q++=ScaleQuantumToChar(next->colormap[i].blue); |
| 1162 | *q++=ScaleQuantumToChar(next->colormap[i].green); |
| 1163 | *q++=ScaleQuantumToChar(next->colormap[i].red); |
| 1164 | *q++=(unsigned char) 0x0; |
| 1165 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1166 | for ( ; i < (ssize_t) (1UL << icon_info.bits_per_pixel); i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1167 | { |
| 1168 | *q++=(unsigned char) 0x00; |
| 1169 | *q++=(unsigned char) 0x00; |
| 1170 | *q++=(unsigned char) 0x00; |
| 1171 | *q++=(unsigned char) 0x00; |
| 1172 | } |
| 1173 | (void) WriteBlob(image,(size_t) (4UL*(1UL << |
| 1174 | icon_info.bits_per_pixel)),icon_colormap); |
| 1175 | icon_colormap=(unsigned char *) RelinquishMagickMemory( |
| 1176 | icon_colormap); |
| 1177 | } |
| 1178 | (void) WriteBlob(image,(size_t) icon_info.image_size,pixels); |
| 1179 | pixels=(unsigned char *) RelinquishMagickMemory(pixels); |
| 1180 | /* |
| 1181 | Write matte mask. |
| 1182 | */ |
| 1183 | scanline_pad=(((next->columns+31) & ~31)-next->columns) >> 3; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1184 | for (y=((ssize_t) next->rows - 1); y >= 0; y--) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1185 | { |
| 1186 | p=GetVirtualPixels(next,0,y,next->columns,1,&next->exception); |
| 1187 | if (p == (const PixelPacket *) NULL) |
| 1188 | break; |
| 1189 | bit=0; |
| 1190 | byte=0; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1191 | for (x=0; x < (ssize_t) next->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1192 | { |
| 1193 | byte<<=1; |
| 1194 | if ((next->matte == MagickTrue) && |
cristy | d05ecd1 | 2011-04-22 20:44:42 +0000 | [diff] [blame] | 1195 | (GetOpacityPixelComponent(p) == (Quantum) TransparentOpacity)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1196 | byte|=0x01; |
| 1197 | bit++; |
| 1198 | if (bit == 8) |
| 1199 | { |
| 1200 | (void) WriteBlobByte(image,(unsigned char) byte); |
| 1201 | bit=0; |
| 1202 | byte=0; |
| 1203 | } |
| 1204 | p++; |
| 1205 | } |
| 1206 | if (bit != 0) |
| 1207 | (void) WriteBlobByte(image,(unsigned char) (byte << (8-bit))); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1208 | for (i=0; i < (ssize_t) scanline_pad; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1209 | (void) WriteBlobByte(image,(unsigned char) 0); |
| 1210 | } |
| 1211 | } |
| 1212 | if (GetNextImageInList(next) == (Image *) NULL) |
| 1213 | break; |
| 1214 | next=SyncNextImageInList(next); |
| 1215 | status=SetImageProgress(next,SaveImagesTag,scene++, |
| 1216 | GetImageListLength(next)); |
| 1217 | if (status == MagickFalse) |
| 1218 | break; |
| 1219 | } while ((next != (Image *) NULL) && (image_info->adjoin != MagickFalse)); |
| 1220 | offset=SeekBlob(image,0,SEEK_SET); |
cristy | da16f16 | 2011-02-19 23:52:17 +0000 | [diff] [blame] | 1221 | (void) offset; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1222 | (void) WriteBlobLSBShort(image,0); |
| 1223 | (void) WriteBlobLSBShort(image,1); |
| 1224 | (void) WriteBlobLSBShort(image,(unsigned short) (scene+1)); |
| 1225 | scene=0; |
| 1226 | next=image; |
| 1227 | do |
| 1228 | { |
| 1229 | (void) WriteBlobByte(image,icon_file.directory[scene].width); |
| 1230 | (void) WriteBlobByte(image,icon_file.directory[scene].height); |
| 1231 | (void) WriteBlobByte(image,icon_file.directory[scene].colors); |
| 1232 | (void) WriteBlobByte(image,icon_file.directory[scene].reserved); |
| 1233 | (void) WriteBlobLSBShort(image,icon_file.directory[scene].planes); |
| 1234 | (void) WriteBlobLSBShort(image,icon_file.directory[scene].bits_per_pixel); |
cristy | 0b29b25 | 2010-05-30 01:59:46 +0000 | [diff] [blame] | 1235 | (void) WriteBlobLSBLong(image,(unsigned int) |
| 1236 | icon_file.directory[scene].size); |
| 1237 | (void) WriteBlobLSBLong(image,(unsigned int) |
| 1238 | icon_file.directory[scene].offset); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1239 | scene++; |
| 1240 | next=SyncNextImageInList(next); |
| 1241 | } while ((next != (Image *) NULL) && (image_info->adjoin != MagickFalse)); |
| 1242 | (void) CloseBlob(image); |
| 1243 | return(MagickTrue); |
| 1244 | } |