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