cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % PPPP IIIII CCCC TTTTT % |
| 7 | % P P I C T % |
| 8 | % PPPP I C T % |
| 9 | % P I C T % |
| 10 | % P IIIII CCCC T % |
| 11 | % % |
| 12 | % % |
| 13 | % Read/Write Apple Macintosh QuickDraw/PICT 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 | 93b707b | 2017-12-06 07:05:51 -0500 | [diff] [blame] | 20 | % Copyright 1999-2018 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 | % % |
Cristy | f19d414 | 2017-04-24 11:34:30 -0400 | [diff] [blame] | 26 | % https://www.imagemagick.org/script/license.php % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 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" |
| 43 | #include "MagickCore/blob.h" |
| 44 | #include "MagickCore/blob-private.h" |
| 45 | #include "MagickCore/cache.h" |
| 46 | #include "MagickCore/color-private.h" |
| 47 | #include "MagickCore/colormap.h" |
| 48 | #include "MagickCore/colormap-private.h" |
| 49 | #include "MagickCore/colorspace.h" |
cristy | 510d06a | 2011-07-06 23:43:54 +0000 | [diff] [blame] | 50 | #include "MagickCore/colorspace-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 51 | #include "MagickCore/composite.h" |
| 52 | #include "MagickCore/constitute.h" |
| 53 | #include "MagickCore/exception.h" |
| 54 | #include "MagickCore/exception-private.h" |
| 55 | #include "MagickCore/image.h" |
| 56 | #include "MagickCore/image-private.h" |
| 57 | #include "MagickCore/list.h" |
| 58 | #include "MagickCore/log.h" |
| 59 | #include "MagickCore/magick.h" |
| 60 | #include "MagickCore/memory_.h" |
| 61 | #include "MagickCore/monitor.h" |
| 62 | #include "MagickCore/monitor-private.h" |
| 63 | #include "MagickCore/pixel-accessor.h" |
| 64 | #include "MagickCore/profile.h" |
| 65 | #include "MagickCore/resource_.h" |
| 66 | #include "MagickCore/quantum-private.h" |
| 67 | #include "MagickCore/static.h" |
| 68 | #include "MagickCore/string_.h" |
| 69 | #include "MagickCore/module.h" |
| 70 | #include "MagickCore/transform.h" |
| 71 | #include "MagickCore/utility.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 72 | |
| 73 | /* |
| 74 | ImageMagick Macintosh PICT Methods. |
| 75 | */ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 76 | typedef struct _PICTCode |
| 77 | { |
| 78 | const char |
| 79 | *name; |
| 80 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 81 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 82 | length; |
| 83 | |
| 84 | const char |
| 85 | *description; |
| 86 | } PICTCode; |
| 87 | |
| 88 | typedef struct _PICTPixmap |
| 89 | { |
| 90 | short |
| 91 | version, |
| 92 | pack_type; |
| 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 | pack_size, |
| 96 | horizontal_resolution, |
| 97 | vertical_resolution; |
| 98 | |
| 99 | short |
| 100 | pixel_type, |
| 101 | bits_per_pixel, |
| 102 | component_count, |
| 103 | component_size; |
| 104 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 105 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 106 | plane_bytes, |
| 107 | table, |
| 108 | reserved; |
| 109 | } PICTPixmap; |
| 110 | |
| 111 | typedef struct _PICTRectangle |
| 112 | { |
| 113 | short |
| 114 | top, |
| 115 | left, |
| 116 | bottom, |
| 117 | right; |
| 118 | } PICTRectangle; |
| 119 | |
| 120 | static const PICTCode |
| 121 | codes[] = |
| 122 | { |
| 123 | /* 0x00 */ { "NOP", 0, "nop" }, |
| 124 | /* 0x01 */ { "Clip", 0, "clip" }, |
| 125 | /* 0x02 */ { "BkPat", 8, "background pattern" }, |
| 126 | /* 0x03 */ { "TxFont", 2, "text font (word)" }, |
| 127 | /* 0x04 */ { "TxFace", 1, "text face (byte)" }, |
| 128 | /* 0x05 */ { "TxMode", 2, "text mode (word)" }, |
| 129 | /* 0x06 */ { "SpExtra", 4, "space extra (fixed point)" }, |
| 130 | /* 0x07 */ { "PnSize", 4, "pen size (point)" }, |
| 131 | /* 0x08 */ { "PnMode", 2, "pen mode (word)" }, |
| 132 | /* 0x09 */ { "PnPat", 8, "pen pattern" }, |
| 133 | /* 0x0a */ { "FillPat", 8, "fill pattern" }, |
| 134 | /* 0x0b */ { "OvSize", 4, "oval size (point)" }, |
| 135 | /* 0x0c */ { "Origin", 4, "dh, dv (word)" }, |
| 136 | /* 0x0d */ { "TxSize", 2, "text size (word)" }, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 137 | /* 0x0e */ { "FgColor", 4, "foreground color (ssize_tword)" }, |
| 138 | /* 0x0f */ { "BkColor", 4, "background color (ssize_tword)" }, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 139 | /* 0x10 */ { "TxRatio", 8, "numerator (point), denominator (point)" }, |
| 140 | /* 0x11 */ { "Version", 1, "version (byte)" }, |
| 141 | /* 0x12 */ { "BkPixPat", 0, "color background pattern" }, |
| 142 | /* 0x13 */ { "PnPixPat", 0, "color pen pattern" }, |
| 143 | /* 0x14 */ { "FillPixPat", 0, "color fill pattern" }, |
| 144 | /* 0x15 */ { "PnLocHFrac", 2, "fractional pen position" }, |
| 145 | /* 0x16 */ { "ChExtra", 2, "extra for each character" }, |
| 146 | /* 0x17 */ { "reserved", 0, "reserved for Apple use" }, |
| 147 | /* 0x18 */ { "reserved", 0, "reserved for Apple use" }, |
| 148 | /* 0x19 */ { "reserved", 0, "reserved for Apple use" }, |
| 149 | /* 0x1a */ { "RGBFgCol", 6, "RGB foreColor" }, |
| 150 | /* 0x1b */ { "RGBBkCol", 6, "RGB backColor" }, |
| 151 | /* 0x1c */ { "HiliteMode", 0, "hilite mode flag" }, |
| 152 | /* 0x1d */ { "HiliteColor", 6, "RGB hilite color" }, |
| 153 | /* 0x1e */ { "DefHilite", 0, "Use default hilite color" }, |
| 154 | /* 0x1f */ { "OpColor", 6, "RGB OpColor for arithmetic modes" }, |
| 155 | /* 0x20 */ { "Line", 8, "pnLoc (point), newPt (point)" }, |
| 156 | /* 0x21 */ { "LineFrom", 4, "newPt (point)" }, |
| 157 | /* 0x22 */ { "ShortLine", 6, "pnLoc (point, dh, dv (-128 .. 127))" }, |
| 158 | /* 0x23 */ { "ShortLineFrom", 2, "dh, dv (-128 .. 127)" }, |
| 159 | /* 0x24 */ { "reserved", -1, "reserved for Apple use" }, |
| 160 | /* 0x25 */ { "reserved", -1, "reserved for Apple use" }, |
| 161 | /* 0x26 */ { "reserved", -1, "reserved for Apple use" }, |
| 162 | /* 0x27 */ { "reserved", -1, "reserved for Apple use" }, |
| 163 | /* 0x28 */ { "LongText", 0, "txLoc (point), count (0..255), text" }, |
| 164 | /* 0x29 */ { "DHText", 0, "dh (0..255), count (0..255), text" }, |
| 165 | /* 0x2a */ { "DVText", 0, "dv (0..255), count (0..255), text" }, |
| 166 | /* 0x2b */ { "DHDVText", 0, "dh, dv (0..255), count (0..255), text" }, |
| 167 | /* 0x2c */ { "reserved", -1, "reserved for Apple use" }, |
| 168 | /* 0x2d */ { "reserved", -1, "reserved for Apple use" }, |
| 169 | /* 0x2e */ { "reserved", -1, "reserved for Apple use" }, |
| 170 | /* 0x2f */ { "reserved", -1, "reserved for Apple use" }, |
| 171 | /* 0x30 */ { "frameRect", 8, "rect" }, |
| 172 | /* 0x31 */ { "paintRect", 8, "rect" }, |
| 173 | /* 0x32 */ { "eraseRect", 8, "rect" }, |
| 174 | /* 0x33 */ { "invertRect", 8, "rect" }, |
| 175 | /* 0x34 */ { "fillRect", 8, "rect" }, |
| 176 | /* 0x35 */ { "reserved", 8, "reserved for Apple use" }, |
| 177 | /* 0x36 */ { "reserved", 8, "reserved for Apple use" }, |
| 178 | /* 0x37 */ { "reserved", 8, "reserved for Apple use" }, |
| 179 | /* 0x38 */ { "frameSameRect", 0, "rect" }, |
| 180 | /* 0x39 */ { "paintSameRect", 0, "rect" }, |
| 181 | /* 0x3a */ { "eraseSameRect", 0, "rect" }, |
| 182 | /* 0x3b */ { "invertSameRect", 0, "rect" }, |
| 183 | /* 0x3c */ { "fillSameRect", 0, "rect" }, |
| 184 | /* 0x3d */ { "reserved", 0, "reserved for Apple use" }, |
| 185 | /* 0x3e */ { "reserved", 0, "reserved for Apple use" }, |
| 186 | /* 0x3f */ { "reserved", 0, "reserved for Apple use" }, |
| 187 | /* 0x40 */ { "frameRRect", 8, "rect" }, |
| 188 | /* 0x41 */ { "paintRRect", 8, "rect" }, |
| 189 | /* 0x42 */ { "eraseRRect", 8, "rect" }, |
| 190 | /* 0x43 */ { "invertRRect", 8, "rect" }, |
| 191 | /* 0x44 */ { "fillRRrect", 8, "rect" }, |
| 192 | /* 0x45 */ { "reserved", 8, "reserved for Apple use" }, |
| 193 | /* 0x46 */ { "reserved", 8, "reserved for Apple use" }, |
| 194 | /* 0x47 */ { "reserved", 8, "reserved for Apple use" }, |
| 195 | /* 0x48 */ { "frameSameRRect", 0, "rect" }, |
| 196 | /* 0x49 */ { "paintSameRRect", 0, "rect" }, |
| 197 | /* 0x4a */ { "eraseSameRRect", 0, "rect" }, |
| 198 | /* 0x4b */ { "invertSameRRect", 0, "rect" }, |
| 199 | /* 0x4c */ { "fillSameRRect", 0, "rect" }, |
| 200 | /* 0x4d */ { "reserved", 0, "reserved for Apple use" }, |
| 201 | /* 0x4e */ { "reserved", 0, "reserved for Apple use" }, |
| 202 | /* 0x4f */ { "reserved", 0, "reserved for Apple use" }, |
| 203 | /* 0x50 */ { "frameOval", 8, "rect" }, |
| 204 | /* 0x51 */ { "paintOval", 8, "rect" }, |
| 205 | /* 0x52 */ { "eraseOval", 8, "rect" }, |
| 206 | /* 0x53 */ { "invertOval", 8, "rect" }, |
| 207 | /* 0x54 */ { "fillOval", 8, "rect" }, |
| 208 | /* 0x55 */ { "reserved", 8, "reserved for Apple use" }, |
| 209 | /* 0x56 */ { "reserved", 8, "reserved for Apple use" }, |
| 210 | /* 0x57 */ { "reserved", 8, "reserved for Apple use" }, |
| 211 | /* 0x58 */ { "frameSameOval", 0, "rect" }, |
| 212 | /* 0x59 */ { "paintSameOval", 0, "rect" }, |
| 213 | /* 0x5a */ { "eraseSameOval", 0, "rect" }, |
| 214 | /* 0x5b */ { "invertSameOval", 0, "rect" }, |
| 215 | /* 0x5c */ { "fillSameOval", 0, "rect" }, |
| 216 | /* 0x5d */ { "reserved", 0, "reserved for Apple use" }, |
| 217 | /* 0x5e */ { "reserved", 0, "reserved for Apple use" }, |
| 218 | /* 0x5f */ { "reserved", 0, "reserved for Apple use" }, |
| 219 | /* 0x60 */ { "frameArc", 12, "rect, startAngle, arcAngle" }, |
| 220 | /* 0x61 */ { "paintArc", 12, "rect, startAngle, arcAngle" }, |
| 221 | /* 0x62 */ { "eraseArc", 12, "rect, startAngle, arcAngle" }, |
| 222 | /* 0x63 */ { "invertArc", 12, "rect, startAngle, arcAngle" }, |
| 223 | /* 0x64 */ { "fillArc", 12, "rect, startAngle, arcAngle" }, |
| 224 | /* 0x65 */ { "reserved", 12, "reserved for Apple use" }, |
| 225 | /* 0x66 */ { "reserved", 12, "reserved for Apple use" }, |
| 226 | /* 0x67 */ { "reserved", 12, "reserved for Apple use" }, |
| 227 | /* 0x68 */ { "frameSameArc", 4, "rect, startAngle, arcAngle" }, |
| 228 | /* 0x69 */ { "paintSameArc", 4, "rect, startAngle, arcAngle" }, |
| 229 | /* 0x6a */ { "eraseSameArc", 4, "rect, startAngle, arcAngle" }, |
| 230 | /* 0x6b */ { "invertSameArc", 4, "rect, startAngle, arcAngle" }, |
| 231 | /* 0x6c */ { "fillSameArc", 4, "rect, startAngle, arcAngle" }, |
| 232 | /* 0x6d */ { "reserved", 4, "reserved for Apple use" }, |
| 233 | /* 0x6e */ { "reserved", 4, "reserved for Apple use" }, |
| 234 | /* 0x6f */ { "reserved", 4, "reserved for Apple use" }, |
| 235 | /* 0x70 */ { "framePoly", 0, "poly" }, |
| 236 | /* 0x71 */ { "paintPoly", 0, "poly" }, |
| 237 | /* 0x72 */ { "erasePoly", 0, "poly" }, |
| 238 | /* 0x73 */ { "invertPoly", 0, "poly" }, |
| 239 | /* 0x74 */ { "fillPoly", 0, "poly" }, |
| 240 | /* 0x75 */ { "reserved", 0, "reserved for Apple use" }, |
| 241 | /* 0x76 */ { "reserved", 0, "reserved for Apple use" }, |
| 242 | /* 0x77 */ { "reserved", 0, "reserved for Apple use" }, |
| 243 | /* 0x78 */ { "frameSamePoly", 0, "poly (NYI)" }, |
| 244 | /* 0x79 */ { "paintSamePoly", 0, "poly (NYI)" }, |
| 245 | /* 0x7a */ { "eraseSamePoly", 0, "poly (NYI)" }, |
| 246 | /* 0x7b */ { "invertSamePoly", 0, "poly (NYI)" }, |
| 247 | /* 0x7c */ { "fillSamePoly", 0, "poly (NYI)" }, |
| 248 | /* 0x7d */ { "reserved", 0, "reserved for Apple use" }, |
| 249 | /* 0x7e */ { "reserved", 0, "reserved for Apple use" }, |
| 250 | /* 0x7f */ { "reserved", 0, "reserved for Apple use" }, |
| 251 | /* 0x80 */ { "frameRgn", 0, "region" }, |
| 252 | /* 0x81 */ { "paintRgn", 0, "region" }, |
| 253 | /* 0x82 */ { "eraseRgn", 0, "region" }, |
| 254 | /* 0x83 */ { "invertRgn", 0, "region" }, |
| 255 | /* 0x84 */ { "fillRgn", 0, "region" }, |
| 256 | /* 0x85 */ { "reserved", 0, "reserved for Apple use" }, |
| 257 | /* 0x86 */ { "reserved", 0, "reserved for Apple use" }, |
| 258 | /* 0x87 */ { "reserved", 0, "reserved for Apple use" }, |
| 259 | /* 0x88 */ { "frameSameRgn", 0, "region (NYI)" }, |
| 260 | /* 0x89 */ { "paintSameRgn", 0, "region (NYI)" }, |
| 261 | /* 0x8a */ { "eraseSameRgn", 0, "region (NYI)" }, |
| 262 | /* 0x8b */ { "invertSameRgn", 0, "region (NYI)" }, |
| 263 | /* 0x8c */ { "fillSameRgn", 0, "region (NYI)" }, |
| 264 | /* 0x8d */ { "reserved", 0, "reserved for Apple use" }, |
| 265 | /* 0x8e */ { "reserved", 0, "reserved for Apple use" }, |
| 266 | /* 0x8f */ { "reserved", 0, "reserved for Apple use" }, |
| 267 | /* 0x90 */ { "BitsRect", 0, "copybits, rect clipped" }, |
| 268 | /* 0x91 */ { "BitsRgn", 0, "copybits, rgn clipped" }, |
| 269 | /* 0x92 */ { "reserved", -1, "reserved for Apple use" }, |
| 270 | /* 0x93 */ { "reserved", -1, "reserved for Apple use" }, |
| 271 | /* 0x94 */ { "reserved", -1, "reserved for Apple use" }, |
| 272 | /* 0x95 */ { "reserved", -1, "reserved for Apple use" }, |
| 273 | /* 0x96 */ { "reserved", -1, "reserved for Apple use" }, |
| 274 | /* 0x97 */ { "reserved", -1, "reserved for Apple use" }, |
| 275 | /* 0x98 */ { "PackBitsRect", 0, "packed copybits, rect clipped" }, |
| 276 | /* 0x99 */ { "PackBitsRgn", 0, "packed copybits, rgn clipped" }, |
| 277 | /* 0x9a */ { "DirectBitsRect", 0, "PixMap, srcRect, dstRect, mode, PixData" }, |
| 278 | /* 0x9b */ { "DirectBitsRgn", 0, "PixMap, srcRect, dstRect, mode, maskRgn, PixData" }, |
| 279 | /* 0x9c */ { "reserved", -1, "reserved for Apple use" }, |
| 280 | /* 0x9d */ { "reserved", -1, "reserved for Apple use" }, |
| 281 | /* 0x9e */ { "reserved", -1, "reserved for Apple use" }, |
| 282 | /* 0x9f */ { "reserved", -1, "reserved for Apple use" }, |
| 283 | /* 0xa0 */ { "ShortComment", 2, "kind (word)" }, |
| 284 | /* 0xa1 */ { "LongComment", 0, "kind (word), size (word), data" } |
| 285 | }; |
| 286 | |
| 287 | /* |
| 288 | Forward declarations. |
| 289 | */ |
| 290 | static MagickBooleanType |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 291 | WritePICTImage(const ImageInfo *,Image *,ExceptionInfo *); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 292 | |
| 293 | /* |
| 294 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 295 | % % |
| 296 | % % |
| 297 | % % |
| 298 | % D e c o d e I m a g e % |
| 299 | % % |
| 300 | % % |
| 301 | % % |
| 302 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 303 | % |
| 304 | % DecodeImage decompresses an image via Macintosh pack bits decoding for |
| 305 | % Macintosh PICT images. |
| 306 | % |
| 307 | % The format of the DecodeImage method is: |
| 308 | % |
| 309 | % unsigned char *DecodeImage(Image *blob,Image *image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 310 | % size_t bytes_per_line,const int bits_per_pixel, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 311 | % unsigned size_t extent) |
| 312 | % |
| 313 | % A description of each parameter follows: |
| 314 | % |
| 315 | % o image_info: the image info. |
| 316 | % |
| 317 | % o blob,image: the address of a structure of type Image. |
| 318 | % |
| 319 | % o bytes_per_line: This integer identifies the number of bytes in a |
| 320 | % scanline. |
| 321 | % |
| 322 | % o bits_per_pixel: the number of bits in a pixel. |
| 323 | % |
| 324 | % o extent: the number of pixels allocated. |
| 325 | % |
| 326 | */ |
| 327 | |
| 328 | static unsigned char *ExpandBuffer(unsigned char *pixels, |
| 329 | MagickSizeType *bytes_per_line,const unsigned int bits_per_pixel) |
| 330 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 331 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 332 | i; |
| 333 | |
| 334 | register unsigned char |
| 335 | *p, |
| 336 | *q; |
| 337 | |
| 338 | static unsigned char |
| 339 | scanline[8*256]; |
| 340 | |
| 341 | p=pixels; |
| 342 | q=scanline; |
| 343 | switch (bits_per_pixel) |
| 344 | { |
| 345 | case 8: |
| 346 | case 16: |
| 347 | case 32: |
| 348 | return(pixels); |
| 349 | case 4: |
| 350 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 351 | for (i=0; i < (ssize_t) *bytes_per_line; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 352 | { |
| 353 | *q++=(*p >> 4) & 0xff; |
| 354 | *q++=(*p & 15); |
| 355 | p++; |
| 356 | } |
| 357 | *bytes_per_line*=2; |
| 358 | break; |
| 359 | } |
| 360 | case 2: |
| 361 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 362 | for (i=0; i < (ssize_t) *bytes_per_line; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 363 | { |
| 364 | *q++=(*p >> 6) & 0x03; |
| 365 | *q++=(*p >> 4) & 0x03; |
| 366 | *q++=(*p >> 2) & 0x03; |
| 367 | *q++=(*p & 3); |
| 368 | p++; |
| 369 | } |
| 370 | *bytes_per_line*=4; |
| 371 | break; |
| 372 | } |
| 373 | case 1: |
| 374 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 375 | for (i=0; i < (ssize_t) *bytes_per_line; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 376 | { |
| 377 | *q++=(*p >> 7) & 0x01; |
| 378 | *q++=(*p >> 6) & 0x01; |
| 379 | *q++=(*p >> 5) & 0x01; |
| 380 | *q++=(*p >> 4) & 0x01; |
| 381 | *q++=(*p >> 3) & 0x01; |
| 382 | *q++=(*p >> 2) & 0x01; |
| 383 | *q++=(*p >> 1) & 0x01; |
| 384 | *q++=(*p & 0x01); |
| 385 | p++; |
| 386 | } |
| 387 | *bytes_per_line*=8; |
| 388 | break; |
| 389 | } |
| 390 | default: |
| 391 | break; |
| 392 | } |
| 393 | return(scanline); |
| 394 | } |
| 395 | |
| 396 | static unsigned char *DecodeImage(Image *blob,Image *image, |
Dirk Lemstra | ede9342 | 2018-04-13 22:18:52 +0200 | [diff] [blame] | 397 | size_t bytes_per_line,const unsigned int bits_per_pixel,size_t *extent) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 398 | { |
Dirk Lemstra | ede9342 | 2018-04-13 22:18:52 +0200 | [diff] [blame] | 399 | MagickBooleanType |
| 400 | status; |
| 401 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 402 | MagickSizeType |
| 403 | number_pixels; |
| 404 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 405 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 406 | i; |
| 407 | |
| 408 | register unsigned char |
| 409 | *p, |
| 410 | *q; |
| 411 | |
| 412 | size_t |
cristy | aff6d80 | 2011-04-26 01:46:31 +0000 | [diff] [blame] | 413 | bytes_per_pixel, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 414 | length, |
cristy | aff6d80 | 2011-04-26 01:46:31 +0000 | [diff] [blame] | 415 | row_bytes, |
| 416 | scanline_length, |
| 417 | width; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 418 | |
| 419 | ssize_t |
cristy | aff6d80 | 2011-04-26 01:46:31 +0000 | [diff] [blame] | 420 | count, |
| 421 | j, |
| 422 | y; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 423 | |
| 424 | unsigned char |
| 425 | *pixels, |
| 426 | *scanline; |
| 427 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 428 | /* |
| 429 | Determine pixel buffer size. |
| 430 | */ |
| 431 | if (bits_per_pixel <= 8) |
| 432 | bytes_per_line&=0x7fff; |
| 433 | width=image->columns; |
| 434 | bytes_per_pixel=1; |
| 435 | if (bits_per_pixel == 16) |
| 436 | { |
| 437 | bytes_per_pixel=2; |
| 438 | width*=2; |
| 439 | } |
| 440 | else |
| 441 | if (bits_per_pixel == 32) |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 442 | width*=image->alpha_trait ? 4 : 3; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 443 | if (bytes_per_line == 0) |
| 444 | bytes_per_line=width; |
| 445 | row_bytes=(size_t) (image->columns | 0x8000); |
| 446 | if (image->storage_class == DirectClass) |
| 447 | row_bytes=(size_t) ((4*image->columns) | 0x8000); |
| 448 | /* |
| 449 | Allocate pixel and scanline buffer. |
| 450 | */ |
| 451 | pixels=(unsigned char *) AcquireQuantumMemory(image->rows,row_bytes* |
| 452 | sizeof(*pixels)); |
| 453 | if (pixels == (unsigned char *) NULL) |
| 454 | return((unsigned char *) NULL); |
| 455 | *extent=row_bytes*image->rows*sizeof(*pixels); |
Cristy | 81bfff2 | 2018-03-10 07:58:31 -0500 | [diff] [blame] | 456 | (void) memset(pixels,0,*extent); |
cristy | f432c63 | 2014-12-07 15:11:28 +0000 | [diff] [blame] | 457 | scanline=(unsigned char *) AcquireQuantumMemory(row_bytes,2* |
| 458 | sizeof(*scanline)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 459 | if (scanline == (unsigned char *) NULL) |
Cristy | 5ebe27c | 2017-09-30 11:30:43 -0400 | [diff] [blame] | 460 | { |
| 461 | pixels=(unsigned char *) RelinquishMagickMemory(pixels); |
| 462 | return((unsigned char *) NULL); |
| 463 | } |
Cristy | 81bfff2 | 2018-03-10 07:58:31 -0500 | [diff] [blame] | 464 | (void) memset(scanline,0,2*row_bytes*sizeof(*scanline)); |
Dirk Lemstra | ede9342 | 2018-04-13 22:18:52 +0200 | [diff] [blame] | 465 | status=MagickTrue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 466 | if (bytes_per_line < 8) |
| 467 | { |
| 468 | /* |
| 469 | Pixels are already uncompressed. |
| 470 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 471 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 472 | { |
Cristy | 7c892c9 | 2018-03-23 20:16:36 -0400 | [diff] [blame] | 473 | q=pixels+y*width*GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 474 | number_pixels=bytes_per_line; |
| 475 | count=ReadBlob(blob,(size_t) number_pixels,scanline); |
cristy | 6d62e4b | 2015-01-11 14:07:17 +0000 | [diff] [blame] | 476 | if (count != (ssize_t) number_pixels) |
| 477 | { |
Dirk Lemstra | ede9342 | 2018-04-13 22:18:52 +0200 | [diff] [blame] | 478 | status=MagickFalse; |
cristy | 6d62e4b | 2015-01-11 14:07:17 +0000 | [diff] [blame] | 479 | break; |
| 480 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 481 | p=ExpandBuffer(scanline,&number_pixels,bits_per_pixel); |
| 482 | if ((q+number_pixels) > (pixels+(*extent))) |
| 483 | { |
Dirk Lemstra | ede9342 | 2018-04-13 22:18:52 +0200 | [diff] [blame] | 484 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 485 | break; |
| 486 | } |
Cristy | fc31dc5 | 2018-03-10 10:42:46 -0500 | [diff] [blame] | 487 | (void) memcpy(q,p,(size_t) number_pixels); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 488 | } |
| 489 | scanline=(unsigned char *) RelinquishMagickMemory(scanline); |
Dirk Lemstra | ede9342 | 2018-04-13 22:18:52 +0200 | [diff] [blame] | 490 | if (status == MagickFalse) |
| 491 | pixels=(unsigned char *) RelinquishMagickMemory(pixels); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 492 | return(pixels); |
| 493 | } |
| 494 | /* |
| 495 | Uncompress RLE pixels into uncompressed pixel buffer. |
| 496 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 497 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 498 | { |
| 499 | q=pixels+y*width; |
| 500 | if (bytes_per_line > 200) |
| 501 | scanline_length=ReadBlobMSBShort(blob); |
| 502 | else |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 503 | scanline_length=(size_t) ReadBlobByte(blob); |
Dirk Lemstra | c2c1622 | 2018-03-16 12:06:03 +0100 | [diff] [blame] | 504 | if ((scanline_length >= row_bytes) || (scanline_length == 0)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 505 | { |
Dirk Lemstra | ede9342 | 2018-04-13 22:18:52 +0200 | [diff] [blame] | 506 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 507 | break; |
| 508 | } |
| 509 | count=ReadBlob(blob,scanline_length,scanline); |
cristy | 6d62e4b | 2015-01-11 14:07:17 +0000 | [diff] [blame] | 510 | if (count != (ssize_t) scanline_length) |
| 511 | { |
Dirk Lemstra | ede9342 | 2018-04-13 22:18:52 +0200 | [diff] [blame] | 512 | status=MagickFalse; |
cristy | 6d62e4b | 2015-01-11 14:07:17 +0000 | [diff] [blame] | 513 | break; |
| 514 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 515 | for (j=0; j < (ssize_t) scanline_length; ) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 516 | if ((scanline[j] & 0x80) == 0) |
| 517 | { |
| 518 | length=(size_t) ((scanline[j] & 0xff)+1); |
| 519 | number_pixels=length*bytes_per_pixel; |
| 520 | p=ExpandBuffer(scanline+j+1,&number_pixels,bits_per_pixel); |
| 521 | if ((q-pixels+number_pixels) <= *extent) |
Cristy | fc31dc5 | 2018-03-10 10:42:46 -0500 | [diff] [blame] | 522 | (void) memcpy(q,p,(size_t) number_pixels); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 523 | q+=number_pixels; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 524 | j+=(ssize_t) (length*bytes_per_pixel+1); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 525 | } |
| 526 | else |
| 527 | { |
| 528 | length=(size_t) (((scanline[j] ^ 0xff) & 0xff)+2); |
| 529 | number_pixels=bytes_per_pixel; |
| 530 | p=ExpandBuffer(scanline+j+1,&number_pixels,bits_per_pixel); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 531 | for (i=0; i < (ssize_t) length; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 532 | { |
| 533 | if ((q-pixels+number_pixels) <= *extent) |
Cristy | fc31dc5 | 2018-03-10 10:42:46 -0500 | [diff] [blame] | 534 | (void) memcpy(q,p,(size_t) number_pixels); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 535 | q+=number_pixels; |
| 536 | } |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 537 | j+=(ssize_t) bytes_per_pixel+1; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 538 | } |
| 539 | } |
| 540 | scanline=(unsigned char *) RelinquishMagickMemory(scanline); |
Dirk Lemstra | ede9342 | 2018-04-13 22:18:52 +0200 | [diff] [blame] | 541 | if (status == MagickFalse) |
| 542 | pixels=(unsigned char *) RelinquishMagickMemory(pixels); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 543 | return(pixels); |
| 544 | } |
| 545 | |
| 546 | /* |
| 547 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 548 | % % |
| 549 | % % |
| 550 | % % |
| 551 | % E n c o d e I m a g e % |
| 552 | % % |
| 553 | % % |
| 554 | % % |
| 555 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 556 | % |
| 557 | % EncodeImage compresses an image via Macintosh pack bits encoding |
| 558 | % for Macintosh PICT images. |
| 559 | % |
| 560 | % The format of the EncodeImage method is: |
| 561 | % |
| 562 | % size_t EncodeImage(Image *image,const unsigned char *scanline, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 563 | % const size_t bytes_per_line,unsigned char *pixels) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 564 | % |
| 565 | % A description of each parameter follows: |
| 566 | % |
| 567 | % o image: the address of a structure of type Image. |
| 568 | % |
| 569 | % o scanline: A pointer to an array of characters to pack. |
| 570 | % |
| 571 | % o bytes_per_line: the number of bytes in a scanline. |
| 572 | % |
| 573 | % o pixels: A pointer to an array of characters where the packed |
| 574 | % characters are stored. |
| 575 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 576 | */ |
| 577 | static size_t EncodeImage(Image *image,const unsigned char *scanline, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 578 | const size_t bytes_per_line,unsigned char *pixels) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 579 | { |
| 580 | #define MaxCount 128 |
| 581 | #define MaxPackbitsRunlength 128 |
| 582 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 583 | register const unsigned char |
| 584 | *p; |
| 585 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 586 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 587 | i; |
| 588 | |
| 589 | register unsigned char |
| 590 | *q; |
| 591 | |
| 592 | size_t |
| 593 | length; |
| 594 | |
cristy | aff6d80 | 2011-04-26 01:46:31 +0000 | [diff] [blame] | 595 | ssize_t |
| 596 | count, |
| 597 | repeat_count, |
| 598 | runlength; |
| 599 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 600 | unsigned char |
| 601 | index; |
| 602 | |
| 603 | /* |
| 604 | Pack scanline. |
| 605 | */ |
| 606 | assert(image != (Image *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 607 | assert(image->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 608 | if (image->debug != MagickFalse) |
| 609 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 610 | assert(scanline != (unsigned char *) NULL); |
| 611 | assert(pixels != (unsigned char *) NULL); |
| 612 | count=0; |
| 613 | runlength=0; |
| 614 | p=scanline+(bytes_per_line-1); |
| 615 | q=pixels; |
| 616 | index=(*p); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 617 | for (i=(ssize_t) bytes_per_line-1; i >= 0; i--) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 618 | { |
| 619 | if (index == *p) |
| 620 | runlength++; |
| 621 | else |
| 622 | { |
| 623 | if (runlength < 3) |
| 624 | while (runlength > 0) |
| 625 | { |
| 626 | *q++=(unsigned char) index; |
| 627 | runlength--; |
| 628 | count++; |
| 629 | if (count == MaxCount) |
| 630 | { |
| 631 | *q++=(unsigned char) (MaxCount-1); |
| 632 | count-=MaxCount; |
| 633 | } |
| 634 | } |
| 635 | else |
| 636 | { |
| 637 | if (count > 0) |
| 638 | *q++=(unsigned char) (count-1); |
| 639 | count=0; |
| 640 | while (runlength > 0) |
| 641 | { |
| 642 | repeat_count=runlength; |
| 643 | if (repeat_count > MaxPackbitsRunlength) |
| 644 | repeat_count=MaxPackbitsRunlength; |
| 645 | *q++=(unsigned char) index; |
| 646 | *q++=(unsigned char) (257-repeat_count); |
| 647 | runlength-=repeat_count; |
| 648 | } |
| 649 | } |
| 650 | runlength=1; |
| 651 | } |
| 652 | index=(*p); |
| 653 | p--; |
| 654 | } |
| 655 | if (runlength < 3) |
| 656 | while (runlength > 0) |
| 657 | { |
| 658 | *q++=(unsigned char) index; |
| 659 | runlength--; |
| 660 | count++; |
| 661 | if (count == MaxCount) |
| 662 | { |
| 663 | *q++=(unsigned char) (MaxCount-1); |
| 664 | count-=MaxCount; |
| 665 | } |
| 666 | } |
| 667 | else |
| 668 | { |
| 669 | if (count > 0) |
| 670 | *q++=(unsigned char) (count-1); |
| 671 | count=0; |
| 672 | while (runlength > 0) |
| 673 | { |
| 674 | repeat_count=runlength; |
| 675 | if (repeat_count > MaxPackbitsRunlength) |
| 676 | repeat_count=MaxPackbitsRunlength; |
| 677 | *q++=(unsigned char) index; |
| 678 | *q++=(unsigned char) (257-repeat_count); |
| 679 | runlength-=repeat_count; |
| 680 | } |
| 681 | } |
| 682 | if (count > 0) |
| 683 | *q++=(unsigned char) (count-1); |
| 684 | /* |
| 685 | Write the number of and the packed length. |
| 686 | */ |
| 687 | length=(size_t) (q-pixels); |
| 688 | if (bytes_per_line > 200) |
| 689 | { |
| 690 | (void) WriteBlobMSBShort(image,(unsigned short) length); |
| 691 | length+=2; |
| 692 | } |
| 693 | else |
| 694 | { |
| 695 | (void) WriteBlobByte(image,(unsigned char) length); |
| 696 | length++; |
| 697 | } |
| 698 | while (q != pixels) |
| 699 | { |
| 700 | q--; |
| 701 | (void) WriteBlobByte(image,*q); |
| 702 | } |
| 703 | return(length); |
| 704 | } |
| 705 | |
| 706 | /* |
| 707 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 708 | % % |
| 709 | % % |
| 710 | % % |
| 711 | % I s P I C T % |
| 712 | % % |
| 713 | % % |
| 714 | % % |
| 715 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 716 | % |
| 717 | % IsPICT()() returns MagickTrue if the image format type, identified by the |
| 718 | % magick string, is PICT. |
| 719 | % |
| 720 | % The format of the ReadPICTImage method is: |
| 721 | % |
| 722 | % MagickBooleanType IsPICT(const unsigned char *magick,const size_t length) |
| 723 | % |
| 724 | % A description of each parameter follows: |
| 725 | % |
| 726 | % o magick: compare image format pattern against these bytes. |
| 727 | % |
| 728 | % o length: Specifies the length of the magick string. |
| 729 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 730 | */ |
| 731 | static MagickBooleanType IsPICT(const unsigned char *magick,const size_t length) |
| 732 | { |
cristy | 80af6b6 | 2012-11-12 12:48:16 +0000 | [diff] [blame] | 733 | if (length < 12) |
| 734 | return(MagickFalse); |
| 735 | /* |
| 736 | Embedded OLE2 macintosh have "PICT" instead of 512 platform header. |
| 737 | */ |
| 738 | if (memcmp(magick,"PICT",4) == 0) |
| 739 | return(MagickTrue); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 740 | if (length < 528) |
| 741 | return(MagickFalse); |
| 742 | if (memcmp(magick+522,"\000\021\002\377\014\000",6) == 0) |
| 743 | return(MagickTrue); |
| 744 | return(MagickFalse); |
| 745 | } |
| 746 | |
| 747 | #if !defined(macintosh) |
| 748 | /* |
| 749 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 750 | % % |
| 751 | % % |
| 752 | % % |
| 753 | % R e a d P I C T I m a g e % |
| 754 | % % |
| 755 | % % |
| 756 | % % |
| 757 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 758 | % |
| 759 | % ReadPICTImage() reads an Apple Macintosh QuickDraw/PICT image file |
| 760 | % and returns it. It allocates the memory necessary for the new Image |
| 761 | % structure and returns a pointer to the new image. |
| 762 | % |
| 763 | % The format of the ReadPICTImage method is: |
| 764 | % |
| 765 | % Image *ReadPICTImage(const ImageInfo *image_info, |
| 766 | % ExceptionInfo *exception) |
| 767 | % |
| 768 | % A description of each parameter follows: |
| 769 | % |
| 770 | % o image_info: the image info. |
| 771 | % |
| 772 | % o exception: return any errors or warnings in this structure. |
| 773 | % |
| 774 | */ |
| 775 | |
Cristy | ffcb8f8 | 2017-07-25 07:46:37 -0400 | [diff] [blame] | 776 | static MagickBooleanType ReadPixmap(Image *image,PICTPixmap *pixmap) |
| 777 | { |
| 778 | pixmap->version=(short) ReadBlobMSBShort(image); |
| 779 | pixmap->pack_type=(short) ReadBlobMSBShort(image); |
| 780 | pixmap->pack_size=ReadBlobMSBLong(image); |
| 781 | pixmap->horizontal_resolution=1UL*ReadBlobMSBShort(image); |
| 782 | (void) ReadBlobMSBShort(image); |
| 783 | pixmap->vertical_resolution=1UL*ReadBlobMSBShort(image); |
| 784 | (void) ReadBlobMSBShort(image); |
| 785 | pixmap->pixel_type=(short) ReadBlobMSBShort(image); |
| 786 | pixmap->bits_per_pixel=(short) ReadBlobMSBShort(image); |
| 787 | pixmap->component_count=(short) ReadBlobMSBShort(image); |
| 788 | pixmap->component_size=(short) ReadBlobMSBShort(image); |
| 789 | pixmap->plane_bytes=ReadBlobMSBLong(image); |
| 790 | pixmap->table=ReadBlobMSBLong(image); |
| 791 | pixmap->reserved=ReadBlobMSBLong(image); |
| 792 | if ((EOFBlob(image) != MagickFalse) || (pixmap->bits_per_pixel <= 0) || |
| 793 | (pixmap->bits_per_pixel > 32) || (pixmap->component_count <= 0) || |
| 794 | (pixmap->component_count > 4) || (pixmap->component_size <= 0)) |
| 795 | return(MagickFalse); |
| 796 | return(MagickTrue); |
| 797 | } |
| 798 | |
cristy | c944c57 | 2014-05-12 00:19:16 +0000 | [diff] [blame] | 799 | static MagickBooleanType ReadRectangle(Image *image,PICTRectangle *rectangle) |
| 800 | { |
| 801 | rectangle->top=(short) ReadBlobMSBShort(image); |
| 802 | rectangle->left=(short) ReadBlobMSBShort(image); |
| 803 | rectangle->bottom=(short) ReadBlobMSBShort(image); |
| 804 | rectangle->right=(short) ReadBlobMSBShort(image); |
Cristy | 6876875 | 2018-02-26 20:32:42 -0500 | [diff] [blame] | 805 | if ((EOFBlob(image) != MagickFalse) || |
Cristy | d813fea | 2018-02-26 20:57:21 -0500 | [diff] [blame] | 806 | ((rectangle->bottom-rectangle->top) <= 0) || |
| 807 | ((rectangle->right-rectangle->left) <= 0)) |
cristy | c944c57 | 2014-05-12 00:19:16 +0000 | [diff] [blame] | 808 | return(MagickFalse); |
| 809 | return(MagickTrue); |
| 810 | } |
| 811 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 812 | static Image *ReadPICTImage(const ImageInfo *image_info, |
| 813 | ExceptionInfo *exception) |
| 814 | { |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 815 | #define ThrowPICTException(exception,message) \ |
| 816 | { \ |
| 817 | if (tile_image != (Image *) NULL) \ |
| 818 | tile_image=DestroyImage(tile_image); \ |
| 819 | if (read_info != (ImageInfo *) NULL) \ |
| 820 | read_info=DestroyImageInfo(read_info); \ |
| 821 | ThrowReaderException((exception),(message)); \ |
| 822 | } |
| 823 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 824 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 825 | geometry[MagickPathExtent], |
cristy | 80af6b6 | 2012-11-12 12:48:16 +0000 | [diff] [blame] | 826 | header_ole[4]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 827 | |
| 828 | Image |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 829 | *image, |
| 830 | *tile_image; |
| 831 | |
| 832 | ImageInfo |
| 833 | *read_info; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 834 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 835 | int |
| 836 | c, |
| 837 | code; |
| 838 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 839 | MagickBooleanType |
| 840 | jpeg, |
| 841 | status; |
| 842 | |
| 843 | PICTRectangle |
| 844 | frame; |
| 845 | |
| 846 | PICTPixmap |
| 847 | pixmap; |
| 848 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 849 | Quantum |
| 850 | index; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 851 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 852 | register Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 853 | *q; |
| 854 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 855 | register ssize_t |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 856 | i, |
| 857 | x; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 858 | |
| 859 | size_t |
| 860 | extent, |
| 861 | length; |
| 862 | |
| 863 | ssize_t |
cristy | aff6d80 | 2011-04-26 01:46:31 +0000 | [diff] [blame] | 864 | count, |
| 865 | flags, |
| 866 | j, |
| 867 | version, |
| 868 | y; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 869 | |
| 870 | StringInfo |
| 871 | *profile; |
| 872 | |
| 873 | /* |
| 874 | Open image file. |
| 875 | */ |
| 876 | assert(image_info != (const ImageInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 877 | assert(image_info->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 878 | if (image_info->debug != MagickFalse) |
| 879 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 880 | image_info->filename); |
| 881 | assert(exception != (ExceptionInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 882 | assert(exception->signature == MagickCoreSignature); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 883 | image=AcquireImage(image_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 884 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 885 | if (status == MagickFalse) |
| 886 | { |
| 887 | image=DestroyImageList(image); |
| 888 | return((Image *) NULL); |
| 889 | } |
| 890 | /* |
| 891 | Read PICT header. |
| 892 | */ |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 893 | read_info=(ImageInfo *) NULL; |
| 894 | tile_image=(Image *) NULL; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 895 | pixmap.bits_per_pixel=0; |
| 896 | pixmap.component_count=0; |
cristy | 80af6b6 | 2012-11-12 12:48:16 +0000 | [diff] [blame] | 897 | /* |
| 898 | Skip header : 512 for standard PICT and 4, ie "PICT" for OLE2. |
| 899 | */ |
| 900 | header_ole[0]=ReadBlobByte(image); |
| 901 | header_ole[1]=ReadBlobByte(image); |
| 902 | header_ole[2]=ReadBlobByte(image); |
| 903 | header_ole[3]=ReadBlobByte(image); |
| 904 | if (!((header_ole[0] == 0x50) && (header_ole[1] == 0x49) && |
| 905 | (header_ole[2] == 0x43) && (header_ole[3] == 0x54 ))) |
| 906 | for (i=0; i < 508; i++) |
cristy | e11ddbd | 2015-03-20 14:34:55 +0000 | [diff] [blame] | 907 | if (ReadBlobByte(image) == EOF) |
| 908 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 909 | (void) ReadBlobMSBShort(image); /* skip picture size */ |
cristy | c944c57 | 2014-05-12 00:19:16 +0000 | [diff] [blame] | 910 | if (ReadRectangle(image,&frame) == MagickFalse) |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 911 | ThrowPICTException(CorruptImageError,"ImproperImageHeader"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 912 | while ((c=ReadBlobByte(image)) == 0) ; |
| 913 | if (c != 0x11) |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 914 | ThrowPICTException(CorruptImageError,"ImproperImageHeader"); |
| 915 | version=(ssize_t) ReadBlobByte(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 916 | if (version == 2) |
| 917 | { |
| 918 | c=ReadBlobByte(image); |
| 919 | if (c != 0xff) |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 920 | ThrowPICTException(CorruptImageError,"ImproperImageHeader"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 921 | } |
| 922 | else |
| 923 | if (version != 1) |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 924 | ThrowPICTException(CorruptImageError,"ImproperImageHeader"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 925 | if ((frame.left < 0) || (frame.right < 0) || (frame.top < 0) || |
| 926 | (frame.bottom < 0) || (frame.left >= frame.right) || |
| 927 | (frame.top >= frame.bottom)) |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 928 | ThrowPICTException(CorruptImageError,"ImproperImageHeader"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 929 | /* |
| 930 | Create black canvas. |
| 931 | */ |
| 932 | flags=0; |
cristy | 65cb963 | 2012-12-08 00:34:29 +0000 | [diff] [blame] | 933 | image->depth=8; |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 934 | image->columns=(size_t) (frame.right-frame.left); |
| 935 | image->rows=(size_t) (frame.bottom-frame.top); |
cristy | 2a11bef | 2011-10-28 18:33:11 +0000 | [diff] [blame] | 936 | image->resolution.x=DefaultResolution; |
| 937 | image->resolution.y=DefaultResolution; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 938 | image->units=UndefinedResolution; |
cristy | d6d3b0d | 2015-01-01 17:46:31 +0000 | [diff] [blame] | 939 | if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0)) |
| 940 | if (image->scene >= (image_info->scene+image_info->number_scenes-1)) |
| 941 | { |
| 942 | (void) CloseBlob(image); |
| 943 | return(GetFirstImageInList(image)); |
| 944 | } |
| 945 | status=SetImageExtent(image,image->columns,image->rows,exception); |
| 946 | if (status == MagickFalse) |
| 947 | return(DestroyImageList(image)); |
Cristy | d1ef38e | 2018-03-17 10:19:50 -0400 | [diff] [blame] | 948 | status=ResetImagePixels(image,exception); |
| 949 | if (status == MagickFalse) |
| 950 | return(DestroyImageList(image)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 951 | /* |
| 952 | Interpret PICT opcodes. |
| 953 | */ |
| 954 | jpeg=MagickFalse; |
| 955 | for (code=0; EOFBlob(image) == MagickFalse; ) |
| 956 | { |
| 957 | if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0)) |
| 958 | if (image->scene >= (image_info->scene+image_info->number_scenes-1)) |
| 959 | break; |
| 960 | if ((version == 1) || ((TellBlob(image) % 2) != 0)) |
| 961 | code=ReadBlobByte(image); |
| 962 | if (version == 2) |
Cristy | 1fe0b87 | 2016-04-23 10:48:31 -0400 | [diff] [blame] | 963 | code=ReadBlobMSBSignedShort(image); |
cristy | f9f8502 | 2014-05-18 12:46:29 +0000 | [diff] [blame] | 964 | if (code < 0) |
| 965 | break; |
Dirk Lemstra | c2c1622 | 2018-03-16 12:06:03 +0100 | [diff] [blame] | 966 | if (code == 0) |
| 967 | continue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 968 | if (code > 0xa1) |
| 969 | { |
| 970 | if (image->debug != MagickFalse) |
| 971 | (void) LogMagickEvent(CoderEvent,GetMagickModule(),"%04X:",code); |
| 972 | } |
| 973 | else |
| 974 | { |
| 975 | if (image->debug != MagickFalse) |
| 976 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), |
| 977 | " %04X %s: %s",code,codes[code].name,codes[code].description); |
| 978 | switch (code) |
| 979 | { |
| 980 | case 0x01: |
| 981 | { |
| 982 | /* |
| 983 | Clipping rectangle. |
| 984 | */ |
| 985 | length=ReadBlobMSBShort(image); |
| 986 | if (length != 0x000a) |
| 987 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 988 | for (i=0; i < (ssize_t) (length-2); i++) |
cristy | e11ddbd | 2015-03-20 14:34:55 +0000 | [diff] [blame] | 989 | if (ReadBlobByte(image) == EOF) |
| 990 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 991 | break; |
| 992 | } |
cristy | c944c57 | 2014-05-12 00:19:16 +0000 | [diff] [blame] | 993 | if (ReadRectangle(image,&frame) == MagickFalse) |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 994 | ThrowPICTException(CorruptImageError,"ImproperImageHeader"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 995 | if (((frame.left & 0x8000) != 0) || ((frame.top & 0x8000) != 0)) |
| 996 | break; |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 997 | image->columns=(size_t) (frame.right-frame.left); |
| 998 | image->rows=(size_t) (frame.bottom-frame.top); |
Cristy | 2b008a8 | 2015-09-07 09:51:07 -0400 | [diff] [blame] | 999 | status=SetImageExtent(image,image->columns,image->rows,exception); |
| 1000 | if (status == MagickFalse) |
| 1001 | return(DestroyImageList(image)); |
Cristy | df22c92 | 2018-03-20 19:34:26 -0400 | [diff] [blame] | 1002 | status=ResetImagePixels(image,exception); |
| 1003 | if (status == MagickFalse) |
| 1004 | return(DestroyImageList(image)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1005 | break; |
| 1006 | } |
| 1007 | case 0x12: |
| 1008 | case 0x13: |
| 1009 | case 0x14: |
| 1010 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1011 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1012 | pattern; |
| 1013 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1014 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1015 | height, |
| 1016 | width; |
| 1017 | |
| 1018 | /* |
| 1019 | Skip pattern definition. |
| 1020 | */ |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 1021 | pattern=(ssize_t) ReadBlobMSBShort(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1022 | for (i=0; i < 8; i++) |
cristy | e11ddbd | 2015-03-20 14:34:55 +0000 | [diff] [blame] | 1023 | if (ReadBlobByte(image) == EOF) |
| 1024 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1025 | if (pattern == 2) |
| 1026 | { |
| 1027 | for (i=0; i < 5; i++) |
cristy | e11ddbd | 2015-03-20 14:34:55 +0000 | [diff] [blame] | 1028 | if (ReadBlobByte(image) == EOF) |
| 1029 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1030 | break; |
| 1031 | } |
| 1032 | if (pattern != 1) |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 1033 | ThrowPICTException(CorruptImageError,"UnknownPatternType"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1034 | length=ReadBlobMSBShort(image); |
cristy | c944c57 | 2014-05-12 00:19:16 +0000 | [diff] [blame] | 1035 | if (ReadRectangle(image,&frame) == MagickFalse) |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 1036 | ThrowPICTException(CorruptImageError,"ImproperImageHeader"); |
Cristy | ffcb8f8 | 2017-07-25 07:46:37 -0400 | [diff] [blame] | 1037 | if (ReadPixmap(image,&pixmap) == MagickFalse) |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 1038 | ThrowPICTException(CorruptImageError,"ImproperImageHeader"); |
| 1039 | image->depth=(size_t) pixmap.component_size; |
cristy | 2a11bef | 2011-10-28 18:33:11 +0000 | [diff] [blame] | 1040 | image->resolution.x=1.0*pixmap.horizontal_resolution; |
| 1041 | image->resolution.y=1.0*pixmap.vertical_resolution; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1042 | image->units=PixelsPerInchResolution; |
| 1043 | (void) ReadBlobMSBLong(image); |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 1044 | flags=(ssize_t) ReadBlobMSBShort(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1045 | length=ReadBlobMSBShort(image); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1046 | for (i=0; i <= (ssize_t) length; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1047 | (void) ReadBlobMSBLong(image); |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 1048 | width=(size_t) (frame.bottom-frame.top); |
| 1049 | height=(size_t) (frame.right-frame.left); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1050 | if (pixmap.bits_per_pixel <= 8) |
| 1051 | length&=0x7fff; |
| 1052 | if (pixmap.bits_per_pixel == 16) |
| 1053 | width<<=1; |
| 1054 | if (length == 0) |
| 1055 | length=width; |
| 1056 | if (length < 8) |
| 1057 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1058 | for (i=0; i < (ssize_t) (length*height); i++) |
cristy | e11ddbd | 2015-03-20 14:34:55 +0000 | [diff] [blame] | 1059 | if (ReadBlobByte(image) == EOF) |
| 1060 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1061 | } |
| 1062 | else |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 1063 | for (i=0; i < (ssize_t) height; i++) |
Cristy | 6876875 | 2018-02-26 20:32:42 -0500 | [diff] [blame] | 1064 | { |
| 1065 | if (EOFBlob(image) != MagickFalse) |
| 1066 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1067 | if (length > 200) |
cristy | 46a5434 | 2015-03-29 00:16:16 +0000 | [diff] [blame] | 1068 | { |
| 1069 | for (j=0; j < (ssize_t) ReadBlobMSBShort(image); j++) |
| 1070 | if (ReadBlobByte(image) == EOF) |
| 1071 | break; |
| 1072 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1073 | else |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1074 | for (j=0; j < (ssize_t) ReadBlobByte(image); j++) |
cristy | e11ddbd | 2015-03-20 14:34:55 +0000 | [diff] [blame] | 1075 | if (ReadBlobByte(image) == EOF) |
| 1076 | break; |
Cristy | 6876875 | 2018-02-26 20:32:42 -0500 | [diff] [blame] | 1077 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1078 | break; |
| 1079 | } |
| 1080 | case 0x1b: |
| 1081 | { |
| 1082 | /* |
| 1083 | Initialize image background color. |
| 1084 | */ |
| 1085 | image->background_color.red=(Quantum) |
| 1086 | ScaleShortToQuantum(ReadBlobMSBShort(image)); |
| 1087 | image->background_color.green=(Quantum) |
| 1088 | ScaleShortToQuantum(ReadBlobMSBShort(image)); |
| 1089 | image->background_color.blue=(Quantum) |
| 1090 | ScaleShortToQuantum(ReadBlobMSBShort(image)); |
| 1091 | break; |
| 1092 | } |
| 1093 | case 0x70: |
| 1094 | case 0x71: |
| 1095 | case 0x72: |
| 1096 | case 0x73: |
| 1097 | case 0x74: |
| 1098 | case 0x75: |
| 1099 | case 0x76: |
| 1100 | case 0x77: |
| 1101 | { |
| 1102 | /* |
| 1103 | Skip polygon or region. |
| 1104 | */ |
| 1105 | length=ReadBlobMSBShort(image); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1106 | for (i=0; i < (ssize_t) (length-2); i++) |
cristy | e11ddbd | 2015-03-20 14:34:55 +0000 | [diff] [blame] | 1107 | if (ReadBlobByte(image) == EOF) |
| 1108 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1109 | break; |
| 1110 | } |
| 1111 | case 0x90: |
| 1112 | case 0x91: |
| 1113 | case 0x98: |
| 1114 | case 0x99: |
| 1115 | case 0x9a: |
| 1116 | case 0x9b: |
| 1117 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1118 | PICTRectangle |
| 1119 | source, |
| 1120 | destination; |
| 1121 | |
| 1122 | register unsigned char |
| 1123 | *p; |
| 1124 | |
| 1125 | size_t |
| 1126 | j; |
| 1127 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1128 | ssize_t |
| 1129 | bytes_per_line; |
| 1130 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1131 | unsigned char |
| 1132 | *pixels; |
| 1133 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1134 | /* |
| 1135 | Pixmap clipped by a rectangle. |
| 1136 | */ |
| 1137 | bytes_per_line=0; |
| 1138 | if ((code != 0x9a) && (code != 0x9b)) |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 1139 | bytes_per_line=(ssize_t) ReadBlobMSBShort(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1140 | else |
| 1141 | { |
| 1142 | (void) ReadBlobMSBShort(image); |
| 1143 | (void) ReadBlobMSBShort(image); |
| 1144 | (void) ReadBlobMSBShort(image); |
| 1145 | } |
cristy | c944c57 | 2014-05-12 00:19:16 +0000 | [diff] [blame] | 1146 | if (ReadRectangle(image,&frame) == MagickFalse) |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 1147 | ThrowPICTException(CorruptImageError,"ImproperImageHeader"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1148 | /* |
| 1149 | Initialize tile image. |
| 1150 | */ |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 1151 | tile_image=CloneImage(image,(size_t) (frame.right-frame.left), |
| 1152 | (size_t) (frame.bottom-frame.top),MagickTrue,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1153 | if (tile_image == (Image *) NULL) |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 1154 | ThrowPICTException(CorruptImageError,"ImproperImageHeader"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1155 | if ((code == 0x9a) || (code == 0x9b) || |
| 1156 | ((bytes_per_line & 0x8000) != 0)) |
| 1157 | { |
Cristy | ffcb8f8 | 2017-07-25 07:46:37 -0400 | [diff] [blame] | 1158 | if (ReadPixmap(image,&pixmap) == MagickFalse) |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 1159 | ThrowPICTException(CorruptImageError,"ImproperImageHeader"); |
| 1160 | tile_image->depth=(size_t) pixmap.component_size; |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 1161 | tile_image->alpha_trait=pixmap.component_count == 4 ? |
cristy | b0a657e | 2012-08-29 00:45:37 +0000 | [diff] [blame] | 1162 | BlendPixelTrait : UndefinedPixelTrait; |
cristy | 2a11bef | 2011-10-28 18:33:11 +0000 | [diff] [blame] | 1163 | tile_image->resolution.x=(double) pixmap.horizontal_resolution; |
| 1164 | tile_image->resolution.y=(double) pixmap.vertical_resolution; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1165 | tile_image->units=PixelsPerInchResolution; |
cristy | 17f11b0 | 2014-12-20 19:37:04 +0000 | [diff] [blame] | 1166 | if (tile_image->alpha_trait != UndefinedPixelTrait) |
Cristy | 5fb86b2 | 2018-03-31 08:27:42 -0400 | [diff] [blame] | 1167 | (void) SetImageAlpha(tile_image,OpaqueAlpha,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1168 | } |
| 1169 | if ((code != 0x9a) && (code != 0x9b)) |
| 1170 | { |
| 1171 | /* |
| 1172 | Initialize colormap. |
| 1173 | */ |
| 1174 | tile_image->colors=2; |
| 1175 | if ((bytes_per_line & 0x8000) != 0) |
| 1176 | { |
| 1177 | (void) ReadBlobMSBLong(image); |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 1178 | flags=(ssize_t) ReadBlobMSBShort(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1179 | tile_image->colors=1UL*ReadBlobMSBShort(image)+1; |
| 1180 | } |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1181 | status=AcquireImageColormap(tile_image,tile_image->colors, |
| 1182 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1183 | if (status == MagickFalse) |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 1184 | ThrowPICTException(ResourceLimitError, |
| 1185 | "MemoryAllocationFailed"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1186 | if ((bytes_per_line & 0x8000) != 0) |
| 1187 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1188 | for (i=0; i < (ssize_t) tile_image->colors; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1189 | { |
| 1190 | j=ReadBlobMSBShort(image) % tile_image->colors; |
| 1191 | if ((flags & 0x8000) != 0) |
| 1192 | j=(size_t) i; |
| 1193 | tile_image->colormap[j].red=(Quantum) |
| 1194 | ScaleShortToQuantum(ReadBlobMSBShort(image)); |
| 1195 | tile_image->colormap[j].green=(Quantum) |
| 1196 | ScaleShortToQuantum(ReadBlobMSBShort(image)); |
| 1197 | tile_image->colormap[j].blue=(Quantum) |
| 1198 | ScaleShortToQuantum(ReadBlobMSBShort(image)); |
| 1199 | } |
| 1200 | } |
| 1201 | else |
| 1202 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1203 | for (i=0; i < (ssize_t) tile_image->colors; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1204 | { |
| 1205 | tile_image->colormap[i].red=(Quantum) (QuantumRange- |
| 1206 | tile_image->colormap[i].red); |
| 1207 | tile_image->colormap[i].green=(Quantum) (QuantumRange- |
| 1208 | tile_image->colormap[i].green); |
| 1209 | tile_image->colormap[i].blue=(Quantum) (QuantumRange- |
| 1210 | tile_image->colormap[i].blue); |
| 1211 | } |
| 1212 | } |
| 1213 | } |
Cristy | 9662081 | 2018-03-31 14:30:50 -0400 | [diff] [blame] | 1214 | if (EOFBlob(image) != MagickFalse) |
Cristy | f8e684d | 2018-04-01 07:33:48 -0400 | [diff] [blame] | 1215 | ThrowPICTException(CorruptImageError, |
| 1216 | "InsufficientImageDataInFile"); |
cristy | c944c57 | 2014-05-12 00:19:16 +0000 | [diff] [blame] | 1217 | if (ReadRectangle(image,&source) == MagickFalse) |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 1218 | ThrowPICTException(CorruptImageError,"ImproperImageHeader"); |
cristy | c944c57 | 2014-05-12 00:19:16 +0000 | [diff] [blame] | 1219 | if (ReadRectangle(image,&destination) == MagickFalse) |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 1220 | ThrowPICTException(CorruptImageError,"ImproperImageHeader"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1221 | (void) ReadBlobMSBShort(image); |
| 1222 | if ((code == 0x91) || (code == 0x99) || (code == 0x9b)) |
| 1223 | { |
| 1224 | /* |
| 1225 | Skip region. |
| 1226 | */ |
| 1227 | length=ReadBlobMSBShort(image); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1228 | for (i=0; i < (ssize_t) (length-2); i++) |
cristy | e11ddbd | 2015-03-20 14:34:55 +0000 | [diff] [blame] | 1229 | if (ReadBlobByte(image) == EOF) |
| 1230 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1231 | } |
| 1232 | if ((code != 0x9a) && (code != 0x9b) && |
| 1233 | (bytes_per_line & 0x8000) == 0) |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 1234 | pixels=DecodeImage(image,tile_image,(size_t) bytes_per_line,1, |
Dirk Lemstra | ede9342 | 2018-04-13 22:18:52 +0200 | [diff] [blame] | 1235 | &extent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1236 | else |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 1237 | pixels=DecodeImage(image,tile_image,(size_t) bytes_per_line, |
Dirk Lemstra | ede9342 | 2018-04-13 22:18:52 +0200 | [diff] [blame] | 1238 | (unsigned int) pixmap.bits_per_pixel,&extent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1239 | if (pixels == (unsigned char *) NULL) |
Dirk Lemstra | ede9342 | 2018-04-13 22:18:52 +0200 | [diff] [blame] | 1240 | ThrowPICTException(CorruptImageError,"UnableToUncompressImage"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1241 | /* |
| 1242 | Convert PICT tile image to pixel packets. |
| 1243 | */ |
| 1244 | p=pixels; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1245 | for (y=0; y < (ssize_t) tile_image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1246 | { |
| 1247 | if (p > (pixels+extent+image->columns)) |
Dirk Lemstra | e11e0dd | 2018-04-06 20:39:20 +0200 | [diff] [blame] | 1248 | { |
| 1249 | pixels=(unsigned char *) RelinquishMagickMemory(pixels); |
| 1250 | ThrowPICTException(CorruptImageError,"NotEnoughPixelData"); |
| 1251 | } |
cristy | 3669d04 | 2009-10-16 01:36:31 +0000 | [diff] [blame] | 1252 | q=QueueAuthenticPixels(tile_image,0,y,tile_image->columns,1, |
| 1253 | exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1254 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1255 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1256 | for (x=0; x < (ssize_t) tile_image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1257 | { |
| 1258 | if (tile_image->storage_class == PseudoClass) |
| 1259 | { |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 1260 | index=(Quantum) ConstrainColormapIndex(tile_image,(ssize_t) |
| 1261 | *p,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1262 | SetPixelIndex(tile_image,index,q); |
| 1263 | SetPixelRed(tile_image, |
| 1264 | tile_image->colormap[(ssize_t) index].red,q); |
| 1265 | SetPixelGreen(tile_image, |
| 1266 | tile_image->colormap[(ssize_t) index].green,q); |
| 1267 | SetPixelBlue(tile_image, |
| 1268 | tile_image->colormap[(ssize_t) index].blue,q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1269 | } |
| 1270 | else |
| 1271 | { |
| 1272 | if (pixmap.bits_per_pixel == 16) |
| 1273 | { |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 1274 | i=(ssize_t) (*p++); |
| 1275 | j=(size_t) (*p); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1276 | SetPixelRed(tile_image,ScaleCharToQuantum( |
| 1277 | (unsigned char) ((i & 0x7c) << 1)),q); |
| 1278 | SetPixelGreen(tile_image,ScaleCharToQuantum( |
cristy | aff6d80 | 2011-04-26 01:46:31 +0000 | [diff] [blame] | 1279 | (unsigned char) (((i & 0x03) << 6) | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1280 | ((j & 0xe0) >> 2))),q); |
| 1281 | SetPixelBlue(tile_image,ScaleCharToQuantum( |
| 1282 | (unsigned char) ((j & 0x1f) << 3)),q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1283 | } |
| 1284 | else |
cristy | 17f11b0 | 2014-12-20 19:37:04 +0000 | [diff] [blame] | 1285 | if (tile_image->alpha_trait == UndefinedPixelTrait) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1286 | { |
| 1287 | if (p > (pixels+extent+2*image->columns)) |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 1288 | ThrowPICTException(CorruptImageError, |
| 1289 | "NotEnoughPixelData"); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1290 | SetPixelRed(tile_image,ScaleCharToQuantum(*p),q); |
| 1291 | SetPixelGreen(tile_image,ScaleCharToQuantum( |
| 1292 | *(p+tile_image->columns)),q); |
| 1293 | SetPixelBlue(tile_image,ScaleCharToQuantum( |
| 1294 | *(p+2*tile_image->columns)),q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1295 | } |
| 1296 | else |
| 1297 | { |
| 1298 | if (p > (pixels+extent+3*image->columns)) |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 1299 | ThrowPICTException(CorruptImageError, |
| 1300 | "NotEnoughPixelData"); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1301 | SetPixelAlpha(tile_image,ScaleCharToQuantum(*p),q); |
| 1302 | SetPixelRed(tile_image,ScaleCharToQuantum( |
| 1303 | *(p+tile_image->columns)),q); |
| 1304 | SetPixelGreen(tile_image,ScaleCharToQuantum( |
| 1305 | *(p+2*tile_image->columns)),q); |
| 1306 | SetPixelBlue(tile_image,ScaleCharToQuantum( |
| 1307 | *(p+3*tile_image->columns)),q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1308 | } |
| 1309 | } |
| 1310 | p++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1311 | q+=GetPixelChannels(tile_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1312 | } |
| 1313 | if (SyncAuthenticPixels(tile_image,exception) == MagickFalse) |
| 1314 | break; |
| 1315 | if ((tile_image->storage_class == DirectClass) && |
| 1316 | (pixmap.bits_per_pixel != 16)) |
| 1317 | { |
| 1318 | p+=(pixmap.component_count-1)*tile_image->columns; |
| 1319 | if (p < pixels) |
| 1320 | break; |
| 1321 | } |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 1322 | status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, |
| 1323 | tile_image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1324 | if (status == MagickFalse) |
| 1325 | break; |
| 1326 | } |
| 1327 | pixels=(unsigned char *) RelinquishMagickMemory(pixels); |
Cristy | 5e75ae2 | 2018-03-20 19:25:44 -0400 | [diff] [blame] | 1328 | if ((jpeg == MagickFalse) && (EOFBlob(image) == MagickFalse)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1329 | if ((code == 0x9a) || (code == 0x9b) || |
| 1330 | ((bytes_per_line & 0x8000) != 0)) |
cristy | feb3e96 | 2012-03-29 17:25:55 +0000 | [diff] [blame] | 1331 | (void) CompositeImage(image,tile_image,CopyCompositeOp, |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 1332 | MagickTrue,(ssize_t) destination.left,(ssize_t) |
| 1333 | destination.top,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1334 | tile_image=DestroyImage(tile_image); |
| 1335 | break; |
| 1336 | } |
| 1337 | case 0xa1: |
| 1338 | { |
| 1339 | unsigned char |
| 1340 | *info; |
| 1341 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1342 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1343 | type; |
| 1344 | |
| 1345 | /* |
| 1346 | Comment. |
| 1347 | */ |
| 1348 | type=ReadBlobMSBShort(image); |
| 1349 | length=ReadBlobMSBShort(image); |
| 1350 | if (length == 0) |
| 1351 | break; |
| 1352 | (void) ReadBlobMSBLong(image); |
Cristy | 70293c7 | 2017-10-01 21:03:00 -0400 | [diff] [blame] | 1353 | length-=MagickMin(length,4); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1354 | if (length == 0) |
| 1355 | break; |
| 1356 | info=(unsigned char *) AcquireQuantumMemory(length,sizeof(*info)); |
| 1357 | if (info == (unsigned char *) NULL) |
| 1358 | break; |
| 1359 | count=ReadBlob(image,length,info); |
cristy | 6d62e4b | 2015-01-11 14:07:17 +0000 | [diff] [blame] | 1360 | if (count != (ssize_t) length) |
root | c94962c | 2017-09-15 15:19:43 +0000 | [diff] [blame] | 1361 | { |
| 1362 | info=(unsigned char *) RelinquishMagickMemory(info); |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 1363 | ThrowPICTException(ResourceLimitError,"UnableToReadImageData"); |
root | c94962c | 2017-09-15 15:19:43 +0000 | [diff] [blame] | 1364 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1365 | switch (type) |
| 1366 | { |
| 1367 | case 0xe0: |
| 1368 | { |
cristy | 8723e4b | 2011-09-01 13:11:19 +0000 | [diff] [blame] | 1369 | profile=BlobToStringInfo((const void *) NULL,length); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1370 | SetStringInfoDatum(profile,info); |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 1371 | status=SetImageProfile(image,"icc",profile,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1372 | profile=DestroyStringInfo(profile); |
| 1373 | if (status == MagickFalse) |
Cristy | a537c72 | 2017-04-26 18:14:02 -0400 | [diff] [blame] | 1374 | { |
| 1375 | info=(unsigned char *) RelinquishMagickMemory(info); |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 1376 | ThrowPICTException(ResourceLimitError, |
Cristy | a537c72 | 2017-04-26 18:14:02 -0400 | [diff] [blame] | 1377 | "MemoryAllocationFailed"); |
| 1378 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1379 | break; |
| 1380 | } |
| 1381 | case 0x1f2: |
| 1382 | { |
cristy | 8723e4b | 2011-09-01 13:11:19 +0000 | [diff] [blame] | 1383 | profile=BlobToStringInfo((const void *) NULL,length); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1384 | SetStringInfoDatum(profile,info); |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 1385 | status=SetImageProfile(image,"iptc",profile,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1386 | if (status == MagickFalse) |
Cristy | a537c72 | 2017-04-26 18:14:02 -0400 | [diff] [blame] | 1387 | { |
| 1388 | info=(unsigned char *) RelinquishMagickMemory(info); |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 1389 | ThrowPICTException(ResourceLimitError, |
Cristy | a537c72 | 2017-04-26 18:14:02 -0400 | [diff] [blame] | 1390 | "MemoryAllocationFailed"); |
| 1391 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1392 | profile=DestroyStringInfo(profile); |
| 1393 | break; |
| 1394 | } |
| 1395 | default: |
| 1396 | break; |
| 1397 | } |
| 1398 | info=(unsigned char *) RelinquishMagickMemory(info); |
| 1399 | break; |
| 1400 | } |
| 1401 | default: |
| 1402 | { |
| 1403 | /* |
| 1404 | Skip to next op code. |
| 1405 | */ |
| 1406 | if (codes[code].length == -1) |
| 1407 | (void) ReadBlobMSBShort(image); |
| 1408 | else |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1409 | for (i=0; i < (ssize_t) codes[code].length; i++) |
cristy | e11ddbd | 2015-03-20 14:34:55 +0000 | [diff] [blame] | 1410 | if (ReadBlobByte(image) == EOF) |
| 1411 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1412 | } |
| 1413 | } |
| 1414 | } |
| 1415 | if (code == 0xc00) |
| 1416 | { |
| 1417 | /* |
| 1418 | Skip header. |
| 1419 | */ |
| 1420 | for (i=0; i < 24; i++) |
cristy | e11ddbd | 2015-03-20 14:34:55 +0000 | [diff] [blame] | 1421 | if (ReadBlobByte(image) == EOF) |
| 1422 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1423 | continue; |
| 1424 | } |
| 1425 | if (((code >= 0xb0) && (code <= 0xcf)) || |
| 1426 | ((code >= 0x8000) && (code <= 0x80ff))) |
| 1427 | continue; |
| 1428 | if (code == 0x8200) |
| 1429 | { |
Cristy | 6876875 | 2018-02-26 20:32:42 -0500 | [diff] [blame] | 1430 | char |
| 1431 | filename[MaxTextExtent]; |
| 1432 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1433 | FILE |
| 1434 | *file; |
| 1435 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1436 | int |
| 1437 | unique_file; |
| 1438 | |
| 1439 | /* |
| 1440 | Embedded JPEG. |
| 1441 | */ |
| 1442 | jpeg=MagickTrue; |
| 1443 | read_info=CloneImageInfo(image_info); |
| 1444 | SetImageInfoBlob(read_info,(void *) NULL,0); |
| 1445 | file=(FILE *) NULL; |
Cristy | 6876875 | 2018-02-26 20:32:42 -0500 | [diff] [blame] | 1446 | unique_file=AcquireUniqueFileResource(filename); |
| 1447 | (void) FormatLocaleString(read_info->filename,MaxTextExtent,"jpeg:%s", |
| 1448 | filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1449 | if (unique_file != -1) |
cristy | d0305b9 | 2009-10-19 13:12:21 +0000 | [diff] [blame] | 1450 | file=fdopen(unique_file,"wb"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1451 | if ((unique_file == -1) || (file == (FILE *) NULL)) |
| 1452 | { |
dirk | ce6b122 | 2014-11-06 21:09:46 +0000 | [diff] [blame] | 1453 | (void) RelinquishUniqueFileResource(read_info->filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1454 | (void) CopyMagickString(image->filename,read_info->filename, |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1455 | MagickPathExtent); |
Cristy | 6fbb6e3 | 2018-04-19 19:38:32 -0400 | [diff] [blame^] | 1456 | ThrowPICTException(FileOpenError,"UnableToCreateTemporaryFile"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1457 | } |
| 1458 | length=ReadBlobMSBLong(image); |
cristy | e11ddbd | 2015-03-20 14:34:55 +0000 | [diff] [blame] | 1459 | if (length > 154) |
cristy | c944c57 | 2014-05-12 00:19:16 +0000 | [diff] [blame] | 1460 | { |
cristy | e11ddbd | 2015-03-20 14:34:55 +0000 | [diff] [blame] | 1461 | for (i=0; i < 6; i++) |
| 1462 | (void) ReadBlobMSBLong(image); |
| 1463 | if (ReadRectangle(image,&frame) == MagickFalse) |
| 1464 | { |
| 1465 | (void) fclose(file); |
| 1466 | (void) RelinquishUniqueFileResource(read_info->filename); |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 1467 | ThrowPICTException(CorruptImageError,"ImproperImageHeader"); |
cristy | e11ddbd | 2015-03-20 14:34:55 +0000 | [diff] [blame] | 1468 | } |
| 1469 | for (i=0; i < 122; i++) |
| 1470 | if (ReadBlobByte(image) == EOF) |
| 1471 | break; |
| 1472 | for (i=0; i < (ssize_t) (length-154); i++) |
| 1473 | { |
| 1474 | c=ReadBlobByte(image); |
| 1475 | if (c == EOF) |
| 1476 | break; |
| 1477 | (void) fputc(c,file); |
| 1478 | } |
cristy | c944c57 | 2014-05-12 00:19:16 +0000 | [diff] [blame] | 1479 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1480 | (void) fclose(file); |
cristy | 100a056 | 2014-04-18 01:27:37 +0000 | [diff] [blame] | 1481 | (void) close(unique_file); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1482 | tile_image=ReadImage(read_info,exception); |
Cristy | 6876875 | 2018-02-26 20:32:42 -0500 | [diff] [blame] | 1483 | (void) RelinquishUniqueFileResource(filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1484 | read_info=DestroyImageInfo(read_info); |
| 1485 | if (tile_image == (Image *) NULL) |
| 1486 | continue; |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1487 | (void) FormatLocaleString(geometry,MagickPathExtent,"%.20gx%.20g", |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 1488 | (double) MagickMax(image->columns,tile_image->columns), |
| 1489 | (double) MagickMax(image->rows,tile_image->rows)); |
cristy | a051173 | 2010-02-17 02:38:35 +0000 | [diff] [blame] | 1490 | (void) SetImageExtent(image, |
| 1491 | MagickMax(image->columns,tile_image->columns), |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 1492 | MagickMax(image->rows,tile_image->rows),exception); |
cristy | af8d391 | 2014-02-21 14:50:33 +0000 | [diff] [blame] | 1493 | (void) TransformImageColorspace(image,tile_image->colorspace,exception); |
cristy | 3917240 | 2012-03-30 13:04:39 +0000 | [diff] [blame] | 1494 | (void) CompositeImage(image,tile_image,CopyCompositeOp,MagickTrue, |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 1495 | (ssize_t) frame.left,(ssize_t) frame.right,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1496 | image->compression=tile_image->compression; |
| 1497 | tile_image=DestroyImage(tile_image); |
| 1498 | continue; |
| 1499 | } |
| 1500 | if ((code == 0xff) || (code == 0xffff)) |
| 1501 | break; |
| 1502 | if (((code >= 0xd0) && (code <= 0xfe)) || |
| 1503 | ((code >= 0x8100) && (code <= 0xffff))) |
| 1504 | { |
| 1505 | /* |
| 1506 | Skip reserved. |
| 1507 | */ |
| 1508 | length=ReadBlobMSBShort(image); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1509 | for (i=0; i < (ssize_t) length; i++) |
cristy | e11ddbd | 2015-03-20 14:34:55 +0000 | [diff] [blame] | 1510 | if (ReadBlobByte(image) == EOF) |
| 1511 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1512 | continue; |
| 1513 | } |
| 1514 | if ((code >= 0x100) && (code <= 0x7fff)) |
| 1515 | { |
| 1516 | /* |
| 1517 | Skip reserved. |
| 1518 | */ |
| 1519 | length=(size_t) ((code >> 7) & 0xff); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1520 | for (i=0; i < (ssize_t) length; i++) |
cristy | e11ddbd | 2015-03-20 14:34:55 +0000 | [diff] [blame] | 1521 | if (ReadBlobByte(image) == EOF) |
| 1522 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1523 | continue; |
| 1524 | } |
| 1525 | } |
| 1526 | (void) CloseBlob(image); |
| 1527 | return(GetFirstImageInList(image)); |
| 1528 | } |
| 1529 | #endif |
| 1530 | |
| 1531 | /* |
| 1532 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1533 | % % |
| 1534 | % % |
| 1535 | % % |
| 1536 | % R e g i s t e r P I C T I m a g e % |
| 1537 | % % |
| 1538 | % % |
| 1539 | % % |
| 1540 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1541 | % |
| 1542 | % RegisterPICTImage() adds attributes for the PICT image format to |
| 1543 | % the list of supported formats. The attributes include the image format |
| 1544 | % tag, a method to read and/or write the format, whether the format |
| 1545 | % supports the saving of more than one frame to the same file or blob, |
| 1546 | % whether the format supports native in-memory I/O, and a brief |
| 1547 | % description of the format. |
| 1548 | % |
| 1549 | % The format of the RegisterPICTImage method is: |
| 1550 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1551 | % size_t RegisterPICTImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1552 | % |
| 1553 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1554 | ModuleExport size_t RegisterPICTImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1555 | { |
| 1556 | MagickInfo |
| 1557 | *entry; |
| 1558 | |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 1559 | entry=AcquireMagickInfo("PICT","PCT","Apple Macintosh QuickDraw/PICT"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1560 | entry->decoder=(DecodeImageHandler *) ReadPICTImage; |
| 1561 | entry->encoder=(EncodeImageHandler *) WritePICTImage; |
dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame] | 1562 | entry->flags^=CoderAdjoinFlag; |
Dirk Lemstra | 8974d77 | 2017-01-22 03:19:27 +0100 | [diff] [blame] | 1563 | entry->flags|=CoderEncoderSeekableStreamFlag; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1564 | entry->magick=(IsImageFormatHandler *) IsPICT; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1565 | (void) RegisterMagickInfo(entry); |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 1566 | entry=AcquireMagickInfo("PICT","PICT","Apple Macintosh QuickDraw/PICT"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1567 | entry->decoder=(DecodeImageHandler *) ReadPICTImage; |
| 1568 | entry->encoder=(EncodeImageHandler *) WritePICTImage; |
dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame] | 1569 | entry->flags^=CoderAdjoinFlag; |
Dirk Lemstra | 8974d77 | 2017-01-22 03:19:27 +0100 | [diff] [blame] | 1570 | entry->flags|=CoderEncoderSeekableStreamFlag; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1571 | entry->magick=(IsImageFormatHandler *) IsPICT; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1572 | (void) RegisterMagickInfo(entry); |
| 1573 | return(MagickImageCoderSignature); |
| 1574 | } |
| 1575 | |
| 1576 | /* |
| 1577 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1578 | % % |
| 1579 | % % |
| 1580 | % % |
| 1581 | % U n r e g i s t e r P I C T I m a g e % |
| 1582 | % % |
| 1583 | % % |
| 1584 | % % |
| 1585 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1586 | % |
| 1587 | % UnregisterPICTImage() removes format registrations made by the |
| 1588 | % PICT module from the list of supported formats. |
| 1589 | % |
| 1590 | % The format of the UnregisterPICTImage method is: |
| 1591 | % |
| 1592 | % UnregisterPICTImage(void) |
| 1593 | % |
| 1594 | */ |
| 1595 | ModuleExport void UnregisterPICTImage(void) |
| 1596 | { |
| 1597 | (void) UnregisterMagickInfo("PCT"); |
| 1598 | (void) UnregisterMagickInfo("PICT"); |
| 1599 | } |
| 1600 | |
| 1601 | /* |
| 1602 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1603 | % % |
| 1604 | % % |
| 1605 | % % |
| 1606 | % W r i t e P I C T I m a g e % |
| 1607 | % % |
| 1608 | % % |
| 1609 | % % |
| 1610 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1611 | % |
| 1612 | % WritePICTImage() writes an image to a file in the Apple Macintosh |
| 1613 | % QuickDraw/PICT image format. |
| 1614 | % |
| 1615 | % The format of the WritePICTImage method is: |
| 1616 | % |
cristy | 3669d04 | 2009-10-16 01:36:31 +0000 | [diff] [blame] | 1617 | % MagickBooleanType WritePICTImage(const ImageInfo *image_info, |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1618 | % Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1619 | % |
| 1620 | % A description of each parameter follows. |
| 1621 | % |
| 1622 | % o image_info: the image info. |
| 1623 | % |
| 1624 | % o image: The image. |
| 1625 | % |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1626 | % o exception: return any errors or warnings in this structure. |
| 1627 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1628 | */ |
| 1629 | static MagickBooleanType WritePICTImage(const ImageInfo *image_info, |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1630 | Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1631 | { |
| 1632 | #define MaxCount 128 |
| 1633 | #define PictCropRegionOp 0x01 |
| 1634 | #define PictEndOfPictureOp 0xff |
| 1635 | #define PictJPEGOp 0x8200 |
| 1636 | #define PictInfoOp 0x0C00 |
| 1637 | #define PictInfoSize 512 |
| 1638 | #define PictPixmapOp 0x9A |
| 1639 | #define PictPICTOp 0x98 |
| 1640 | #define PictVersion 0x11 |
| 1641 | |
| 1642 | const StringInfo |
| 1643 | *profile; |
| 1644 | |
| 1645 | double |
| 1646 | x_resolution, |
| 1647 | y_resolution; |
| 1648 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1649 | MagickBooleanType |
| 1650 | status; |
| 1651 | |
| 1652 | MagickOffsetType |
| 1653 | offset; |
| 1654 | |
| 1655 | PICTPixmap |
| 1656 | pixmap; |
| 1657 | |
| 1658 | PICTRectangle |
| 1659 | bounds, |
| 1660 | crop_rectangle, |
| 1661 | destination_rectangle, |
| 1662 | frame_rectangle, |
| 1663 | size_rectangle, |
| 1664 | source_rectangle; |
| 1665 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1666 | register const Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1667 | *p; |
| 1668 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1669 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1670 | i, |
| 1671 | x; |
| 1672 | |
| 1673 | size_t |
cristy | aff6d80 | 2011-04-26 01:46:31 +0000 | [diff] [blame] | 1674 | bytes_per_line, |
| 1675 | count, |
cristy | 0f6fc2d | 2015-05-30 00:49:11 +0000 | [diff] [blame] | 1676 | row_bytes, |
cristy | aff6d80 | 2011-04-26 01:46:31 +0000 | [diff] [blame] | 1677 | storage_class; |
| 1678 | |
| 1679 | ssize_t |
| 1680 | y; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1681 | |
| 1682 | unsigned char |
| 1683 | *buffer, |
| 1684 | *packed_scanline, |
| 1685 | *scanline; |
| 1686 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1687 | unsigned short |
| 1688 | base_address, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1689 | transfer_mode; |
| 1690 | |
| 1691 | /* |
| 1692 | Open output image file. |
| 1693 | */ |
| 1694 | assert(image_info != (const ImageInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 1695 | assert(image_info->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1696 | assert(image != (Image *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 1697 | assert(image->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1698 | if (image->debug != MagickFalse) |
| 1699 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1700 | if ((image->columns > 65535L) || (image->rows > 65535L)) |
| 1701 | ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit"); |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1702 | assert(exception != (ExceptionInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 1703 | assert(exception->signature == MagickCoreSignature); |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1704 | status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1705 | if (status == MagickFalse) |
| 1706 | return(status); |
cristy | af8d391 | 2014-02-21 14:50:33 +0000 | [diff] [blame] | 1707 | (void) TransformImageColorspace(image,sRGBColorspace,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1708 | /* |
| 1709 | Initialize image info. |
| 1710 | */ |
| 1711 | size_rectangle.top=0; |
| 1712 | size_rectangle.left=0; |
| 1713 | size_rectangle.bottom=(short) image->rows; |
| 1714 | size_rectangle.right=(short) image->columns; |
| 1715 | frame_rectangle=size_rectangle; |
| 1716 | crop_rectangle=size_rectangle; |
| 1717 | source_rectangle=size_rectangle; |
| 1718 | destination_rectangle=size_rectangle; |
| 1719 | base_address=0xff; |
cristy | 0f6fc2d | 2015-05-30 00:49:11 +0000 | [diff] [blame] | 1720 | row_bytes=image->columns; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1721 | bounds.top=0; |
| 1722 | bounds.left=0; |
| 1723 | bounds.bottom=(short) image->rows; |
| 1724 | bounds.right=(short) image->columns; |
| 1725 | pixmap.version=0; |
| 1726 | pixmap.pack_type=0; |
| 1727 | pixmap.pack_size=0; |
| 1728 | pixmap.pixel_type=0; |
| 1729 | pixmap.bits_per_pixel=8; |
| 1730 | pixmap.component_count=1; |
| 1731 | pixmap.component_size=8; |
| 1732 | pixmap.plane_bytes=0; |
| 1733 | pixmap.table=0; |
| 1734 | pixmap.reserved=0; |
| 1735 | transfer_mode=0; |
cristy | 2a11bef | 2011-10-28 18:33:11 +0000 | [diff] [blame] | 1736 | x_resolution=image->resolution.x != 0.0 ? image->resolution.x : |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1737 | DefaultResolution; |
cristy | 2a11bef | 2011-10-28 18:33:11 +0000 | [diff] [blame] | 1738 | y_resolution=image->resolution.y != 0.0 ? image->resolution.y : |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1739 | DefaultResolution; |
| 1740 | storage_class=image->storage_class; |
| 1741 | if (image_info->compression == JPEGCompression) |
| 1742 | storage_class=DirectClass; |
cristy | 213770a | 2014-09-27 00:12:23 +0000 | [diff] [blame] | 1743 | if (storage_class == DirectClass) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1744 | { |
cristy | 17f11b0 | 2014-12-20 19:37:04 +0000 | [diff] [blame] | 1745 | pixmap.component_count=image->alpha_trait != UndefinedPixelTrait ? 4 : 3; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1746 | pixmap.pixel_type=16; |
| 1747 | pixmap.bits_per_pixel=32; |
| 1748 | pixmap.pack_type=0x04; |
| 1749 | transfer_mode=0x40; |
cristy | 0f6fc2d | 2015-05-30 00:49:11 +0000 | [diff] [blame] | 1750 | row_bytes=4*image->columns; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1751 | } |
| 1752 | /* |
| 1753 | Allocate memory. |
| 1754 | */ |
| 1755 | bytes_per_line=image->columns; |
cristy | 213770a | 2014-09-27 00:12:23 +0000 | [diff] [blame] | 1756 | if (storage_class == DirectClass) |
cristy | 17f11b0 | 2014-12-20 19:37:04 +0000 | [diff] [blame] | 1757 | bytes_per_line*=image->alpha_trait != UndefinedPixelTrait ? 4 : 3; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1758 | buffer=(unsigned char *) AcquireQuantumMemory(PictInfoSize,sizeof(*buffer)); |
| 1759 | packed_scanline=(unsigned char *) AcquireQuantumMemory((size_t) |
| 1760 | (row_bytes+MaxCount),sizeof(*packed_scanline)); |
| 1761 | scanline=(unsigned char *) AcquireQuantumMemory(row_bytes,sizeof(*scanline)); |
| 1762 | if ((buffer == (unsigned char *) NULL) || |
| 1763 | (packed_scanline == (unsigned char *) NULL) || |
| 1764 | (scanline == (unsigned char *) NULL)) |
Cristy | c1b09bb | 2017-07-17 19:20:45 -0400 | [diff] [blame] | 1765 | { |
| 1766 | if (scanline != (unsigned char *) NULL) |
| 1767 | scanline=(unsigned char *) RelinquishMagickMemory(scanline); |
| 1768 | if (packed_scanline != (unsigned char *) NULL) |
| 1769 | packed_scanline=(unsigned char *) RelinquishMagickMemory( |
| 1770 | packed_scanline); |
| 1771 | if (buffer != (unsigned char *) NULL) |
| 1772 | buffer=(unsigned char *) RelinquishMagickMemory(buffer); |
| 1773 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
| 1774 | } |
Cristy | 81bfff2 | 2018-03-10 07:58:31 -0500 | [diff] [blame] | 1775 | (void) memset(scanline,0,row_bytes); |
| 1776 | (void) memset(packed_scanline,0,(size_t) (row_bytes+MaxCount)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1777 | /* |
| 1778 | Write header, header size, size bounding box, version, and reserved. |
| 1779 | */ |
Cristy | 81bfff2 | 2018-03-10 07:58:31 -0500 | [diff] [blame] | 1780 | (void) memset(buffer,0,PictInfoSize); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1781 | (void) WriteBlob(image,PictInfoSize,buffer); |
| 1782 | (void) WriteBlobMSBShort(image,0); |
| 1783 | (void) WriteBlobMSBShort(image,(unsigned short) size_rectangle.top); |
| 1784 | (void) WriteBlobMSBShort(image,(unsigned short) size_rectangle.left); |
| 1785 | (void) WriteBlobMSBShort(image,(unsigned short) size_rectangle.bottom); |
| 1786 | (void) WriteBlobMSBShort(image,(unsigned short) size_rectangle.right); |
| 1787 | (void) WriteBlobMSBShort(image,PictVersion); |
| 1788 | (void) WriteBlobMSBShort(image,0x02ff); /* version #2 */ |
| 1789 | (void) WriteBlobMSBShort(image,PictInfoOp); |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 1790 | (void) WriteBlobMSBLong(image,0xFFFE0000U); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1791 | /* |
| 1792 | Write full size of the file, resolution, frame bounding box, and reserved. |
| 1793 | */ |
| 1794 | (void) WriteBlobMSBShort(image,(unsigned short) x_resolution); |
| 1795 | (void) WriteBlobMSBShort(image,0x0000); |
| 1796 | (void) WriteBlobMSBShort(image,(unsigned short) y_resolution); |
| 1797 | (void) WriteBlobMSBShort(image,0x0000); |
| 1798 | (void) WriteBlobMSBShort(image,(unsigned short) frame_rectangle.top); |
| 1799 | (void) WriteBlobMSBShort(image,(unsigned short) frame_rectangle.left); |
| 1800 | (void) WriteBlobMSBShort(image,(unsigned short) frame_rectangle.bottom); |
| 1801 | (void) WriteBlobMSBShort(image,(unsigned short) frame_rectangle.right); |
| 1802 | (void) WriteBlobMSBLong(image,0x00000000L); |
| 1803 | profile=GetImageProfile(image,"iptc"); |
| 1804 | if (profile != (StringInfo *) NULL) |
| 1805 | { |
| 1806 | (void) WriteBlobMSBShort(image,0xa1); |
| 1807 | (void) WriteBlobMSBShort(image,0x1f2); |
cristy | ed55252 | 2009-10-16 14:04:35 +0000 | [diff] [blame] | 1808 | (void) WriteBlobMSBShort(image,(unsigned short) |
| 1809 | (GetStringInfoLength(profile)+4)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1810 | (void) WriteBlobString(image,"8BIM"); |
cristy | ed55252 | 2009-10-16 14:04:35 +0000 | [diff] [blame] | 1811 | (void) WriteBlob(image,GetStringInfoLength(profile), |
| 1812 | GetStringInfoDatum(profile)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1813 | } |
| 1814 | profile=GetImageProfile(image,"icc"); |
| 1815 | if (profile != (StringInfo *) NULL) |
| 1816 | { |
| 1817 | (void) WriteBlobMSBShort(image,0xa1); |
| 1818 | (void) WriteBlobMSBShort(image,0xe0); |
cristy | ed55252 | 2009-10-16 14:04:35 +0000 | [diff] [blame] | 1819 | (void) WriteBlobMSBShort(image,(unsigned short) |
| 1820 | (GetStringInfoLength(profile)+4)); |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 1821 | (void) WriteBlobMSBLong(image,0x00000000U); |
cristy | ed55252 | 2009-10-16 14:04:35 +0000 | [diff] [blame] | 1822 | (void) WriteBlob(image,GetStringInfoLength(profile), |
| 1823 | GetStringInfoDatum(profile)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1824 | (void) WriteBlobMSBShort(image,0xa1); |
| 1825 | (void) WriteBlobMSBShort(image,0xe0); |
| 1826 | (void) WriteBlobMSBShort(image,4); |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 1827 | (void) WriteBlobMSBLong(image,0x00000002U); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1828 | } |
| 1829 | /* |
| 1830 | Write crop region opcode and crop bounding box. |
| 1831 | */ |
| 1832 | (void) WriteBlobMSBShort(image,PictCropRegionOp); |
| 1833 | (void) WriteBlobMSBShort(image,0xa); |
| 1834 | (void) WriteBlobMSBShort(image,(unsigned short) crop_rectangle.top); |
| 1835 | (void) WriteBlobMSBShort(image,(unsigned short) crop_rectangle.left); |
| 1836 | (void) WriteBlobMSBShort(image,(unsigned short) crop_rectangle.bottom); |
| 1837 | (void) WriteBlobMSBShort(image,(unsigned short) crop_rectangle.right); |
| 1838 | if (image_info->compression == JPEGCompression) |
| 1839 | { |
| 1840 | Image |
| 1841 | *jpeg_image; |
| 1842 | |
| 1843 | ImageInfo |
| 1844 | *jpeg_info; |
| 1845 | |
| 1846 | size_t |
| 1847 | length; |
| 1848 | |
| 1849 | unsigned char |
| 1850 | *blob; |
| 1851 | |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1852 | jpeg_image=CloneImage(image,0,0,MagickTrue,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1853 | if (jpeg_image == (Image *) NULL) |
| 1854 | { |
| 1855 | (void) CloseBlob(image); |
| 1856 | return(MagickFalse); |
| 1857 | } |
| 1858 | jpeg_info=CloneImageInfo(image_info); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1859 | (void) CopyMagickString(jpeg_info->magick,"JPEG",MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1860 | length=0; |
| 1861 | blob=(unsigned char *) ImageToBlob(jpeg_info,jpeg_image,&length, |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1862 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1863 | jpeg_info=DestroyImageInfo(jpeg_info); |
| 1864 | if (blob == (unsigned char *) NULL) |
| 1865 | return(MagickFalse); |
| 1866 | jpeg_image=DestroyImage(jpeg_image); |
| 1867 | (void) WriteBlobMSBShort(image,PictJPEGOp); |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 1868 | (void) WriteBlobMSBLong(image,(unsigned int) length+154); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1869 | (void) WriteBlobMSBShort(image,0x0000); |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 1870 | (void) WriteBlobMSBLong(image,0x00010000U); |
| 1871 | (void) WriteBlobMSBLong(image,0x00000000U); |
| 1872 | (void) WriteBlobMSBLong(image,0x00000000U); |
| 1873 | (void) WriteBlobMSBLong(image,0x00000000U); |
| 1874 | (void) WriteBlobMSBLong(image,0x00010000U); |
| 1875 | (void) WriteBlobMSBLong(image,0x00000000U); |
| 1876 | (void) WriteBlobMSBLong(image,0x00000000U); |
| 1877 | (void) WriteBlobMSBLong(image,0x00000000U); |
| 1878 | (void) WriteBlobMSBLong(image,0x40000000U); |
| 1879 | (void) WriteBlobMSBLong(image,0x00000000U); |
| 1880 | (void) WriteBlobMSBLong(image,0x00000000U); |
| 1881 | (void) WriteBlobMSBLong(image,0x00000000U); |
| 1882 | (void) WriteBlobMSBLong(image,0x00400000U); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1883 | (void) WriteBlobMSBShort(image,0x0000); |
| 1884 | (void) WriteBlobMSBShort(image,(unsigned short) image->rows); |
| 1885 | (void) WriteBlobMSBShort(image,(unsigned short) image->columns); |
| 1886 | (void) WriteBlobMSBShort(image,0x0000); |
| 1887 | (void) WriteBlobMSBShort(image,768); |
| 1888 | (void) WriteBlobMSBShort(image,0x0000); |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 1889 | (void) WriteBlobMSBLong(image,0x00000000U); |
| 1890 | (void) WriteBlobMSBLong(image,0x00566A70U); |
| 1891 | (void) WriteBlobMSBLong(image,0x65670000U); |
| 1892 | (void) WriteBlobMSBLong(image,0x00000000U); |
| 1893 | (void) WriteBlobMSBLong(image,0x00000001U); |
| 1894 | (void) WriteBlobMSBLong(image,0x00016170U); |
| 1895 | (void) WriteBlobMSBLong(image,0x706C0000U); |
| 1896 | (void) WriteBlobMSBLong(image,0x00000000U); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1897 | (void) WriteBlobMSBShort(image,768); |
| 1898 | (void) WriteBlobMSBShort(image,(unsigned short) image->columns); |
| 1899 | (void) WriteBlobMSBShort(image,(unsigned short) image->rows); |
| 1900 | (void) WriteBlobMSBShort(image,(unsigned short) x_resolution); |
| 1901 | (void) WriteBlobMSBShort(image,0x0000); |
| 1902 | (void) WriteBlobMSBShort(image,(unsigned short) y_resolution); |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 1903 | (void) WriteBlobMSBLong(image,0x00000000U); |
| 1904 | (void) WriteBlobMSBLong(image,0x87AC0001U); |
| 1905 | (void) WriteBlobMSBLong(image,0x0B466F74U); |
| 1906 | (void) WriteBlobMSBLong(image,0x6F202D20U); |
| 1907 | (void) WriteBlobMSBLong(image,0x4A504547U); |
| 1908 | (void) WriteBlobMSBLong(image,0x00000000U); |
| 1909 | (void) WriteBlobMSBLong(image,0x00000000U); |
| 1910 | (void) WriteBlobMSBLong(image,0x00000000U); |
| 1911 | (void) WriteBlobMSBLong(image,0x00000000U); |
| 1912 | (void) WriteBlobMSBLong(image,0x00000000U); |
| 1913 | (void) WriteBlobMSBLong(image,0x0018FFFFU); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1914 | (void) WriteBlob(image,length,blob); |
| 1915 | if ((length & 0x01) != 0) |
| 1916 | (void) WriteBlobByte(image,'\0'); |
| 1917 | blob=(unsigned char *) RelinquishMagickMemory(blob); |
| 1918 | } |
| 1919 | /* |
| 1920 | Write picture opcode, row bytes, and picture bounding box, and version. |
| 1921 | */ |
| 1922 | if (storage_class == PseudoClass) |
| 1923 | (void) WriteBlobMSBShort(image,PictPICTOp); |
| 1924 | else |
| 1925 | { |
| 1926 | (void) WriteBlobMSBShort(image,PictPixmapOp); |
Cristy | 18718a9 | 2018-03-25 12:45:12 -0400 | [diff] [blame] | 1927 | (void) WriteBlobMSBLong(image,(unsigned int) base_address); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1928 | } |
| 1929 | (void) WriteBlobMSBShort(image,(unsigned short) (row_bytes | 0x8000)); |
| 1930 | (void) WriteBlobMSBShort(image,(unsigned short) bounds.top); |
| 1931 | (void) WriteBlobMSBShort(image,(unsigned short) bounds.left); |
| 1932 | (void) WriteBlobMSBShort(image,(unsigned short) bounds.bottom); |
| 1933 | (void) WriteBlobMSBShort(image,(unsigned short) bounds.right); |
| 1934 | /* |
| 1935 | Write pack type, pack size, resolution, pixel type, and pixel size. |
| 1936 | */ |
| 1937 | (void) WriteBlobMSBShort(image,(unsigned short) pixmap.version); |
| 1938 | (void) WriteBlobMSBShort(image,(unsigned short) pixmap.pack_type); |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 1939 | (void) WriteBlobMSBLong(image,(unsigned int) pixmap.pack_size); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1940 | (void) WriteBlobMSBShort(image,(unsigned short) (x_resolution+0.5)); |
| 1941 | (void) WriteBlobMSBShort(image,0x0000); |
| 1942 | (void) WriteBlobMSBShort(image,(unsigned short) (y_resolution+0.5)); |
| 1943 | (void) WriteBlobMSBShort(image,0x0000); |
| 1944 | (void) WriteBlobMSBShort(image,(unsigned short) pixmap.pixel_type); |
| 1945 | (void) WriteBlobMSBShort(image,(unsigned short) pixmap.bits_per_pixel); |
| 1946 | /* |
| 1947 | Write component count, size, plane bytes, table size, and reserved. |
| 1948 | */ |
| 1949 | (void) WriteBlobMSBShort(image,(unsigned short) pixmap.component_count); |
| 1950 | (void) WriteBlobMSBShort(image,(unsigned short) pixmap.component_size); |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 1951 | (void) WriteBlobMSBLong(image,(unsigned int) pixmap.plane_bytes); |
| 1952 | (void) WriteBlobMSBLong(image,(unsigned int) pixmap.table); |
| 1953 | (void) WriteBlobMSBLong(image,(unsigned int) pixmap.reserved); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1954 | if (storage_class == PseudoClass) |
| 1955 | { |
| 1956 | /* |
| 1957 | Write image colormap. |
| 1958 | */ |
| 1959 | (void) WriteBlobMSBLong(image,0x00000000L); /* color seed */ |
| 1960 | (void) WriteBlobMSBShort(image,0L); /* color flags */ |
| 1961 | (void) WriteBlobMSBShort(image,(unsigned short) (image->colors-1)); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1962 | for (i=0; i < (ssize_t) image->colors; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1963 | { |
| 1964 | (void) WriteBlobMSBShort(image,(unsigned short) i); |
| 1965 | (void) WriteBlobMSBShort(image,ScaleQuantumToShort( |
| 1966 | image->colormap[i].red)); |
| 1967 | (void) WriteBlobMSBShort(image,ScaleQuantumToShort( |
| 1968 | image->colormap[i].green)); |
| 1969 | (void) WriteBlobMSBShort(image,ScaleQuantumToShort( |
| 1970 | image->colormap[i].blue)); |
| 1971 | } |
| 1972 | } |
| 1973 | /* |
| 1974 | Write source and destination rectangle. |
| 1975 | */ |
| 1976 | (void) WriteBlobMSBShort(image,(unsigned short) source_rectangle.top); |
| 1977 | (void) WriteBlobMSBShort(image,(unsigned short) source_rectangle.left); |
| 1978 | (void) WriteBlobMSBShort(image,(unsigned short) source_rectangle.bottom); |
| 1979 | (void) WriteBlobMSBShort(image,(unsigned short) source_rectangle.right); |
| 1980 | (void) WriteBlobMSBShort(image,(unsigned short) destination_rectangle.top); |
| 1981 | (void) WriteBlobMSBShort(image,(unsigned short) destination_rectangle.left); |
| 1982 | (void) WriteBlobMSBShort(image,(unsigned short) destination_rectangle.bottom); |
| 1983 | (void) WriteBlobMSBShort(image,(unsigned short) destination_rectangle.right); |
| 1984 | (void) WriteBlobMSBShort(image,(unsigned short) transfer_mode); |
| 1985 | /* |
| 1986 | Write picture data. |
| 1987 | */ |
| 1988 | count=0; |
cristy | 213770a | 2014-09-27 00:12:23 +0000 | [diff] [blame] | 1989 | if (storage_class == PseudoClass) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1990 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1991 | { |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1992 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1993 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1994 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1995 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1996 | { |
| 1997 | scanline[x]=(unsigned char) GetPixelIndex(image,p); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1998 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1999 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2000 | count+=EncodeImage(image,scanline,(size_t) (row_bytes & 0x7FFF), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2001 | packed_scanline); |
cristy | 8b27a6d | 2010-02-14 03:31:15 +0000 | [diff] [blame] | 2002 | if (image->previous == (Image *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2003 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 2004 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
cristy | aff6d80 | 2011-04-26 01:46:31 +0000 | [diff] [blame] | 2005 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2006 | if (status == MagickFalse) |
| 2007 | break; |
| 2008 | } |
| 2009 | } |
| 2010 | else |
| 2011 | if (image_info->compression == JPEGCompression) |
| 2012 | { |
Cristy | 81bfff2 | 2018-03-10 07:58:31 -0500 | [diff] [blame] | 2013 | (void) memset(scanline,0,row_bytes); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2014 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | aff6d80 | 2011-04-26 01:46:31 +0000 | [diff] [blame] | 2015 | count+=EncodeImage(image,scanline,(size_t) (row_bytes & 0x7FFF), |
| 2016 | packed_scanline); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2017 | } |
| 2018 | else |
| 2019 | { |
| 2020 | register unsigned char |
| 2021 | *blue, |
| 2022 | *green, |
| 2023 | *opacity, |
| 2024 | *red; |
| 2025 | |
| 2026 | red=scanline; |
| 2027 | green=scanline+image->columns; |
| 2028 | blue=scanline+2*image->columns; |
| 2029 | opacity=scanline+3*image->columns; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2030 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2031 | { |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 2032 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2033 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2034 | break; |
| 2035 | red=scanline; |
| 2036 | green=scanline+image->columns; |
| 2037 | blue=scanline+2*image->columns; |
cristy | 17f11b0 | 2014-12-20 19:37:04 +0000 | [diff] [blame] | 2038 | if (image->alpha_trait != UndefinedPixelTrait) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2039 | { |
| 2040 | opacity=scanline; |
| 2041 | red=scanline+image->columns; |
| 2042 | green=scanline+2*image->columns; |
| 2043 | blue=scanline+3*image->columns; |
| 2044 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2045 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2046 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2047 | *red++=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 2048 | *green++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 2049 | *blue++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
cristy | 17f11b0 | 2014-12-20 19:37:04 +0000 | [diff] [blame] | 2050 | if (image->alpha_trait != UndefinedPixelTrait) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2051 | *opacity++=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p))); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2052 | p+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2053 | } |
Cristy | 2174484 | 2016-01-13 18:31:21 -0500 | [diff] [blame] | 2054 | count+=EncodeImage(image,scanline,bytes_per_line,packed_scanline); |
cristy | 8b27a6d | 2010-02-14 03:31:15 +0000 | [diff] [blame] | 2055 | if (image->previous == (Image *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2056 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 2057 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
| 2058 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2059 | if (status == MagickFalse) |
| 2060 | break; |
| 2061 | } |
| 2062 | } |
| 2063 | } |
| 2064 | if ((count & 0x01) != 0) |
| 2065 | (void) WriteBlobByte(image,'\0'); |
| 2066 | (void) WriteBlobMSBShort(image,PictEndOfPictureOp); |
| 2067 | offset=TellBlob(image); |
| 2068 | offset=SeekBlob(image,512,SEEK_SET); |
| 2069 | (void) WriteBlobMSBShort(image,(unsigned short) offset); |
| 2070 | scanline=(unsigned char *) RelinquishMagickMemory(scanline); |
| 2071 | packed_scanline=(unsigned char *) RelinquishMagickMemory(packed_scanline); |
| 2072 | buffer=(unsigned char *) RelinquishMagickMemory(buffer); |
| 2073 | (void) CloseBlob(image); |
| 2074 | return(MagickTrue); |
| 2075 | } |