| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | #include "magick/studio.h" |
|---|
| 43 | #include "magick/blob.h" |
|---|
| 44 | #include "magick/blob-private.h" |
|---|
| 45 | #include "magick/color-private.h" |
|---|
| 46 | #include "magick/colorspace.h" |
|---|
| 47 | #include "magick/composite.h" |
|---|
| 48 | #include "magick/constitute.h" |
|---|
| 49 | #include "magick/exception.h" |
|---|
| 50 | #include "magick/exception-private.h" |
|---|
| 51 | #include "magick/image.h" |
|---|
| 52 | #include "magick/image-private.h" |
|---|
| 53 | #include "magick/list.h" |
|---|
| 54 | #include "magick/log.h" |
|---|
| 55 | #include "magick/magick.h" |
|---|
| 56 | #include "magick/memory_.h" |
|---|
| 57 | #include "magick/monitor.h" |
|---|
| 58 | #include "magick/monitor-private.h" |
|---|
| 59 | #include "magick/profile.h" |
|---|
| 60 | #include "magick/resource_.h" |
|---|
| 61 | #include "magick/quantum-private.h" |
|---|
| 62 | #include "magick/static.h" |
|---|
| 63 | #include "magick/string_.h" |
|---|
| 64 | #include "magick/module.h" |
|---|
| 65 | #include "magick/transform.h" |
|---|
| 66 | #include "magick/utility.h" |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | #define ReadPixmap(pixmap) \ |
|---|
| 72 | { \ |
|---|
| 73 | pixmap.version=(short) ReadBlobMSBShort(image); \ |
|---|
| 74 | pixmap.pack_type=(short) ReadBlobMSBShort(image); \ |
|---|
| 75 | pixmap.pack_size=ReadBlobMSBLong(image); \ |
|---|
| 76 | pixmap.horizontal_resolution=1UL*ReadBlobMSBShort(image); \ |
|---|
| 77 | (void) ReadBlobMSBShort(image); \ |
|---|
| 78 | pixmap.vertical_resolution=1UL*ReadBlobMSBShort(image); \ |
|---|
| 79 | (void) ReadBlobMSBShort(image); \ |
|---|
| 80 | pixmap.pixel_type=(short) ReadBlobMSBShort(image); \ |
|---|
| 81 | pixmap.bits_per_pixel=(short) ReadBlobMSBShort(image); \ |
|---|
| 82 | pixmap.component_count=(short) ReadBlobMSBShort(image); \ |
|---|
| 83 | pixmap.component_size=(short) ReadBlobMSBShort(image); \ |
|---|
| 84 | pixmap.plane_bytes=ReadBlobMSBLong(image); \ |
|---|
| 85 | pixmap.table=ReadBlobMSBLong(image); \ |
|---|
| 86 | pixmap.reserved=ReadBlobMSBLong(image); \ |
|---|
| 87 | if ((pixmap.bits_per_pixel <= 0) || (pixmap.bits_per_pixel > 32) || \ |
|---|
| 88 | (pixmap.component_count <= 0) || (pixmap.component_count > 4) || \ |
|---|
| 89 | (pixmap.component_size <= 0)) \ |
|---|
| 90 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); \ |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | #define ReadRectangle(image,rectangle) \ |
|---|
| 94 | { \ |
|---|
| 95 | rectangle.top=(short) ReadBlobMSBShort(image); \ |
|---|
| 96 | rectangle.left=(short) ReadBlobMSBShort(image); \ |
|---|
| 97 | rectangle.bottom=(short) ReadBlobMSBShort(image); \ |
|---|
| 98 | rectangle.right=(short) ReadBlobMSBShort(image); \ |
|---|
| 99 | if ((rectangle.left > rectangle.right) || \ |
|---|
| 100 | (rectangle.top > rectangle.bottom)) \ |
|---|
| 101 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); \ |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | typedef struct _PICTCode |
|---|
| 105 | { |
|---|
| 106 | const char |
|---|
| 107 | *name; |
|---|
| 108 | |
|---|
| 109 | long |
|---|
| 110 | length; |
|---|
| 111 | |
|---|
| 112 | const char |
|---|
| 113 | *description; |
|---|
| 114 | } PICTCode; |
|---|
| 115 | |
|---|
| 116 | typedef struct _PICTPixmap |
|---|
| 117 | { |
|---|
| 118 | short |
|---|
| 119 | version, |
|---|
| 120 | pack_type; |
|---|
| 121 | |
|---|
| 122 | unsigned long |
|---|
| 123 | pack_size, |
|---|
| 124 | horizontal_resolution, |
|---|
| 125 | vertical_resolution; |
|---|
| 126 | |
|---|
| 127 | short |
|---|
| 128 | pixel_type, |
|---|
| 129 | bits_per_pixel, |
|---|
| 130 | component_count, |
|---|
| 131 | component_size; |
|---|
| 132 | |
|---|
| 133 | unsigned long |
|---|
| 134 | plane_bytes, |
|---|
| 135 | table, |
|---|
| 136 | reserved; |
|---|
| 137 | } PICTPixmap; |
|---|
| 138 | |
|---|
| 139 | typedef struct _PICTRectangle |
|---|
| 140 | { |
|---|
| 141 | short |
|---|
| 142 | top, |
|---|
| 143 | left, |
|---|
| 144 | bottom, |
|---|
| 145 | right; |
|---|
| 146 | } PICTRectangle; |
|---|
| 147 | |
|---|
| 148 | static const PICTCode |
|---|
| 149 | codes[] = |
|---|
| 150 | { |
|---|
| 151 | { "NOP", 0, "nop" }, |
|---|
| 152 | { "Clip", 0, "clip" }, |
|---|
| 153 | { "BkPat", 8, "background pattern" }, |
|---|
| 154 | { "TxFont", 2, "text font (word)" }, |
|---|
| 155 | { "TxFace", 1, "text face (byte)" }, |
|---|
| 156 | { "TxMode", 2, "text mode (word)" }, |
|---|
| 157 | { "SpExtra", 4, "space extra (fixed point)" }, |
|---|
| 158 | { "PnSize", 4, "pen size (point)" }, |
|---|
| 159 | { "PnMode", 2, "pen mode (word)" }, |
|---|
| 160 | { "PnPat", 8, "pen pattern" }, |
|---|
| 161 | { "FillPat", 8, "fill pattern" }, |
|---|
| 162 | { "OvSize", 4, "oval size (point)" }, |
|---|
| 163 | { "Origin", 4, "dh, dv (word)" }, |
|---|
| 164 | { "TxSize", 2, "text size (word)" }, |
|---|
| 165 | { "FgColor", 4, "foreground color (longword)" }, |
|---|
| 166 | { "BkColor", 4, "background color (longword)" }, |
|---|
| 167 | { "TxRatio", 8, "numerator (point), denominator (point)" }, |
|---|
| 168 | { "Version", 1, "version (byte)" }, |
|---|
| 169 | { "BkPixPat", 0, "color background pattern" }, |
|---|
| 170 | { "PnPixPat", 0, "color pen pattern" }, |
|---|
| 171 | { "FillPixPat", 0, "color fill pattern" }, |
|---|
| 172 | { "PnLocHFrac", 2, "fractional pen position" }, |
|---|
| 173 | { "ChExtra", 2, "extra for each character" }, |
|---|
| 174 | { "reserved", 0, "reserved for Apple use" }, |
|---|
| 175 | { "reserved", 0, "reserved for Apple use" }, |
|---|
| 176 | { "reserved", 0, "reserved for Apple use" }, |
|---|
| 177 | { "RGBFgCol", 6, "RGB foreColor" }, |
|---|
| 178 | { "RGBBkCol", 6, "RGB backColor" }, |
|---|
| 179 | { "HiliteMode", 0, "hilite mode flag" }, |
|---|
| 180 | { "HiliteColor", 6, "RGB hilite color" }, |
|---|
| 181 | { "DefHilite", 0, "Use default hilite color" }, |
|---|
| 182 | { "OpColor", 6, "RGB OpColor for arithmetic modes" }, |
|---|
| 183 | { "Line", 8, "pnLoc (point), newPt (point)" }, |
|---|
| 184 | { "LineFrom", 4, "newPt (point)" }, |
|---|
| 185 | { "ShortLine", 6, "pnLoc (point, dh, dv (-128 .. 127))" }, |
|---|
| 186 | { "ShortLineFrom", 2, "dh, dv (-128 .. 127)" }, |
|---|
| 187 | { "reserved", -1, "reserved for Apple use" }, |
|---|
| 188 | { "reserved", -1, "reserved for Apple use" }, |
|---|
| 189 | { "reserved", -1, "reserved for Apple use" }, |
|---|
| 190 | { "reserved", -1, "reserved for Apple use" }, |
|---|
| 191 | { "LongText", 0, "txLoc (point), count (0..255), text" }, |
|---|
| 192 | { "DHText", 0, "dh (0..255), count (0..255), text" }, |
|---|
| 193 | { "DVText", 0, "dv (0..255), count (0..255), text" }, |
|---|
| 194 | { "DHDVText", 0, "dh, dv (0..255), count (0..255), text" }, |
|---|
| 195 | { "reserved", -1, "reserved for Apple use" }, |
|---|
| 196 | { "reserved", -1, "reserved for Apple use" }, |
|---|
| 197 | { "reserved", -1, "reserved for Apple use" }, |
|---|
| 198 | { "reserved", -1, "reserved for Apple use" }, |
|---|
| 199 | { "frameRect", 8, "rect" }, |
|---|
| 200 | { "paintRect", 8, "rect" }, |
|---|
| 201 | { "eraseRect", 8, "rect" }, |
|---|
| 202 | { "invertRect", 8, "rect" }, |
|---|
| 203 | { "fillRect", 8, "rect" }, |
|---|
| 204 | { "reserved", 8, "reserved for Apple use" }, |
|---|
| 205 | { "reserved", 8, "reserved for Apple use" }, |
|---|
| 206 | { "reserved", 8, "reserved for Apple use" }, |
|---|
| 207 | { "frameSameRect", 0, "rect" }, |
|---|
| 208 | { "paintSameRect", 0, "rect" }, |
|---|
| 209 | { "eraseSameRect", 0, "rect" }, |
|---|
| 210 | { "invertSameRect", 0, "rect" }, |
|---|
| 211 | { "fillSameRect", 0, "rect" }, |
|---|
| 212 | { "reserved", 0, "reserved for Apple use" }, |
|---|
| 213 | { "reserved", 0, "reserved for Apple use" }, |
|---|
| 214 | { "reserved", 0, "reserved for Apple use" }, |
|---|
| 215 | { "frameRRect", 8, "rect" }, |
|---|
| 216 | { "paintRRect", 8, "rect" }, |
|---|
| 217 | { "eraseRRect", 8, "rect" }, |
|---|
| 218 | { "invertRRect", 8, "rect" }, |
|---|
| 219 | { "fillRRrect", 8, "rect" }, |
|---|
| 220 | { "reserved", 8, "reserved for Apple use" }, |
|---|
| 221 | { "reserved", 8, "reserved for Apple use" }, |
|---|
| 222 | { "reserved", 8, "reserved for Apple use" }, |
|---|
| 223 | { "frameSameRRect", 0, "rect" }, |
|---|
| 224 | { "paintSameRRect", 0, "rect" }, |
|---|
| 225 | { "eraseSameRRect", 0, "rect" }, |
|---|
| 226 | { "invertSameRRect", 0, "rect" }, |
|---|
| 227 | { "fillSameRRect", 0, "rect" }, |
|---|
| 228 | { "reserved", 0, "reserved for Apple use" }, |
|---|
| 229 | { "reserved", 0, "reserved for Apple use" }, |
|---|
| 230 | { "reserved", 0, "reserved for Apple use" }, |
|---|
| 231 | { "frameOval", 8, "rect" }, |
|---|
| 232 | { "paintOval", 8, "rect" }, |
|---|
| 233 | { "eraseOval", 8, "rect" }, |
|---|
| 234 | { "invertOval", 8, "rect" }, |
|---|
| 235 | { "fillOval", 8, "rect" }, |
|---|
| 236 | { "reserved", 8, "reserved for Apple use" }, |
|---|
| 237 | { "reserved", 8, "reserved for Apple use" }, |
|---|
| 238 | { "reserved", 8, "reserved for Apple use" }, |
|---|
| 239 | { "frameSameOval", 0, "rect" }, |
|---|
| 240 | { "paintSameOval", 0, "rect" }, |
|---|
| 241 | { "eraseSameOval", 0, "rect" }, |
|---|
| 242 | { "invertSameOval", 0, "rect" }, |
|---|
| 243 | { "fillSameOval", 0, "rect" }, |
|---|
| 244 | { "reserved", 0, "reserved for Apple use" }, |
|---|
| 245 | { "reserved", 0, "reserved for Apple use" }, |
|---|
| 246 | { "reserved", 0, "reserved for Apple use" }, |
|---|
| 247 | { "frameArc", 12, "rect, startAngle, arcAngle" }, |
|---|
| 248 | { "paintArc", 12, "rect, startAngle, arcAngle" }, |
|---|
| 249 | { "eraseArc", 12, "rect, startAngle, arcAngle" }, |
|---|
| 250 | { "invertArc", 12, "rect, startAngle, arcAngle" }, |
|---|
| 251 | { "fillArc", 12, "rect, startAngle, arcAngle" }, |
|---|
| 252 | { "reserved", 12, "reserved for Apple use" }, |
|---|
| 253 | { "reserved", 12, "reserved for Apple use" }, |
|---|
| 254 | { "reserved", 12, "reserved for Apple use" }, |
|---|
| 255 | { "frameSameArc", 4, "rect, startAngle, arcAngle" }, |
|---|
| 256 | { "paintSameArc", 4, "rect, startAngle, arcAngle" }, |
|---|
| 257 | { "eraseSameArc", 4, "rect, startAngle, arcAngle" }, |
|---|
| 258 | { "invertSameArc", 4, "rect, startAngle, arcAngle" }, |
|---|
| 259 | { "fillSameArc", 4, "rect, startAngle, arcAngle" }, |
|---|
| 260 | { "reserved", 4, "reserved for Apple use" }, |
|---|
| 261 | { "reserved", 4, "reserved for Apple use" }, |
|---|
| 262 | { "reserved", 4, "reserved for Apple use" }, |
|---|
| 263 | { "framePoly", 0, "poly" }, |
|---|
| 264 | { "paintPoly", 0, "poly" }, |
|---|
| 265 | { "erasePoly", 0, "poly" }, |
|---|
| 266 | { "invertPoly", 0, "poly" }, |
|---|
| 267 | { "fillPoly", 0, "poly" }, |
|---|
| 268 | { "reserved", 0, "reserved for Apple use" }, |
|---|
| 269 | { "reserved", 0, "reserved for Apple use" }, |
|---|
| 270 | { "reserved", 0, "reserved for Apple use" }, |
|---|
| 271 | { "frameSamePoly", 0, "poly (NYI)" }, |
|---|
| 272 | { "paintSamePoly", 0, "poly (NYI)" }, |
|---|
| 273 | { "eraseSamePoly", 0, "poly (NYI)" }, |
|---|
| 274 | { "invertSamePoly", 0, "poly (NYI)" }, |
|---|
| 275 | { "fillSamePoly", 0, "poly (NYI)" }, |
|---|
| 276 | { "reserved", 0, "reserved for Apple use" }, |
|---|
| 277 | { "reserved", 0, "reserved for Apple use" }, |
|---|
| 278 | { "reserved", 0, "reserved for Apple use" }, |
|---|
| 279 | { "frameRgn", 0, "region" }, |
|---|
| 280 | { "paintRgn", 0, "region" }, |
|---|
| 281 | { "eraseRgn", 0, "region" }, |
|---|
| 282 | { "invertRgn", 0, "region" }, |
|---|
| 283 | { "fillRgn", 0, "region" }, |
|---|
| 284 | { "reserved", 0, "reserved for Apple use" }, |
|---|
| 285 | { "reserved", 0, "reserved for Apple use" }, |
|---|
| 286 | { "reserved", 0, "reserved for Apple use" }, |
|---|
| 287 | { "frameSameRgn", 0, "region (NYI)" }, |
|---|
| 288 | { "paintSameRgn", 0, "region (NYI)" }, |
|---|
| 289 | { "eraseSameRgn", 0, "region (NYI)" }, |
|---|
| 290 | { "invertSameRgn", 0, "region (NYI)" }, |
|---|
| 291 | { "fillSameRgn", 0, "region (NYI)" }, |
|---|
| 292 | { "reserved", 0, "reserved for Apple use" }, |
|---|
| 293 | { "reserved", 0, "reserved for Apple use" }, |
|---|
| 294 | { "reserved", 0, "reserved for Apple use" }, |
|---|
| 295 | { "BitsRect", 0, "copybits, rect clipped" }, |
|---|
| 296 | { "BitsRgn", 0, "copybits, rgn clipped" }, |
|---|
| 297 | { "reserved", -1, "reserved for Apple use" }, |
|---|
| 298 | { "reserved", -1, "reserved for Apple use" }, |
|---|
| 299 | { "reserved", -1, "reserved for Apple use" }, |
|---|
| 300 | { "reserved", -1, "reserved for Apple use" }, |
|---|
| 301 | { "reserved", -1, "reserved for Apple use" }, |
|---|
| 302 | { "reserved", -1, "reserved for Apple use" }, |
|---|
| 303 | { "PackBitsRect", 0, "packed copybits, rect clipped" }, |
|---|
| 304 | { "PackBitsRgn", 0, "packed copybits, rgn clipped" }, |
|---|
| 305 | { "DirectBitsRect", 0, "PixMap, srcRect, dstRect, mode, PixData" }, |
|---|
| 306 | { "DirectBitsRgn", 0, "PixMap, srcRect, dstRect, mode, maskRgn, PixData" }, |
|---|
| 307 | { "reserved", -1, "reserved for Apple use" }, |
|---|
| 308 | { "reserved", -1, "reserved for Apple use" }, |
|---|
| 309 | { "reserved", -1, "reserved for Apple use" }, |
|---|
| 310 | { "reserved", -1, "reserved for Apple use" }, |
|---|
| 311 | { "ShortComment", 2, "kind (word)" }, |
|---|
| 312 | { "LongComment", 0, "kind (word), size (word), data" } |
|---|
| 313 | }; |
|---|
| 314 | |
|---|
| 315 | |
|---|
| 316 | |
|---|
| 317 | |
|---|
| 318 | static MagickBooleanType |
|---|
| 319 | WritePICTImage(const ImageInfo *,Image *); |
|---|
| 320 | |
|---|
| 321 | |
|---|
| 322 | |
|---|
| 323 | |
|---|
| 324 | |
|---|
| 325 | |
|---|
| 326 | |
|---|
| 327 | |
|---|
| 328 | |
|---|
| 329 | |
|---|
| 330 | |
|---|
| 331 | |
|---|
| 332 | |
|---|
| 333 | |
|---|
| 334 | |
|---|
| 335 | |
|---|
| 336 | |
|---|
| 337 | |
|---|
| 338 | |
|---|
| 339 | |
|---|
| 340 | |
|---|
| 341 | |
|---|
| 342 | |
|---|
| 343 | |
|---|
| 344 | |
|---|
| 345 | |
|---|
| 346 | |
|---|
| 347 | |
|---|
| 348 | |
|---|
| 349 | |
|---|
| 350 | |
|---|
| 351 | |
|---|
| 352 | |
|---|
| 353 | |
|---|
| 354 | |
|---|
| 355 | |
|---|
| 356 | static unsigned char *ExpandBuffer(unsigned char *pixels, |
|---|
| 357 | MagickSizeType *bytes_per_line,const unsigned int bits_per_pixel) |
|---|
| 358 | { |
|---|
| 359 | register long |
|---|
| 360 | i; |
|---|
| 361 | |
|---|
| 362 | register unsigned char |
|---|
| 363 | *p, |
|---|
| 364 | *q; |
|---|
| 365 | |
|---|
| 366 | static unsigned char |
|---|
| 367 | scanline[8*256]; |
|---|
| 368 | |
|---|
| 369 | p=pixels; |
|---|
| 370 | q=scanline; |
|---|
| 371 | switch (bits_per_pixel) |
|---|
| 372 | { |
|---|
| 373 | case 8: |
|---|
| 374 | case 16: |
|---|
| 375 | case 32: |
|---|
| 376 | return(pixels); |
|---|
| 377 | case 4: |
|---|
| 378 | { |
|---|
| 379 | for (i=0; i < (long) *bytes_per_line; i++) |
|---|
| 380 | { |
|---|
| 381 | *q++=(*p >> 4) & 0xff; |
|---|
| 382 | *q++=(*p & 15); |
|---|
| 383 | p++; |
|---|
| 384 | } |
|---|
| 385 | *bytes_per_line*=2; |
|---|
| 386 | break; |
|---|
| 387 | } |
|---|
| 388 | case 2: |
|---|
| 389 | { |
|---|
| 390 | for (i=0; i < (long) *bytes_per_line; i++) |
|---|
| 391 | { |
|---|
| 392 | *q++=(*p >> 6) & 0x03; |
|---|
| 393 | *q++=(*p >> 4) & 0x03; |
|---|
| 394 | *q++=(*p >> 2) & 0x03; |
|---|
| 395 | *q++=(*p & 3); |
|---|
| 396 | p++; |
|---|
| 397 | } |
|---|
| 398 | *bytes_per_line*=4; |
|---|
| 399 | break; |
|---|
| 400 | } |
|---|
| 401 | case 1: |
|---|
| 402 | { |
|---|
| 403 | for (i=0; i < (long) *bytes_per_line; i++) |
|---|
| 404 | { |
|---|
| 405 | *q++=(*p >> 7) & 0x01; |
|---|
| 406 | *q++=(*p >> 6) & 0x01; |
|---|
| 407 | *q++=(*p >> 5) & 0x01; |
|---|
| 408 | *q++=(*p >> 4) & 0x01; |
|---|
| 409 | *q++=(*p >> 3) & 0x01; |
|---|
| 410 | *q++=(*p >> 2) & 0x01; |
|---|
| 411 | *q++=(*p >> 1) & 0x01; |
|---|
| 412 | *q++=(*p & 0x01); |
|---|
| 413 | p++; |
|---|
| 414 | } |
|---|
| 415 | *bytes_per_line*=8; |
|---|
| 416 | break; |
|---|
| 417 | } |
|---|
| 418 | default: |
|---|
| 419 | break; |
|---|
| 420 | } |
|---|
| 421 | return(scanline); |
|---|
| 422 | } |
|---|
| 423 | |
|---|
| 424 | static unsigned char *DecodeImage(Image *blob,Image *image, |
|---|
| 425 | unsigned long bytes_per_line,const unsigned int bits_per_pixel,size_t *extent) |
|---|
| 426 | { |
|---|
| 427 | long |
|---|
| 428 | j, |
|---|
| 429 | y; |
|---|
| 430 | |
|---|
| 431 | MagickSizeType |
|---|
| 432 | number_pixels; |
|---|
| 433 | |
|---|
| 434 | register long |
|---|
| 435 | i; |
|---|
| 436 | |
|---|
| 437 | register unsigned char |
|---|
| 438 | *p, |
|---|
| 439 | *q; |
|---|
| 440 | |
|---|
| 441 | size_t |
|---|
| 442 | length, |
|---|
| 443 | row_bytes; |
|---|
| 444 | |
|---|
| 445 | ssize_t |
|---|
| 446 | count; |
|---|
| 447 | |
|---|
| 448 | unsigned char |
|---|
| 449 | *pixels, |
|---|
| 450 | *scanline; |
|---|
| 451 | |
|---|
| 452 | unsigned long |
|---|
| 453 | bytes_per_pixel, |
|---|
| 454 | scanline_length, |
|---|
| 455 | width; |
|---|
| 456 | |
|---|
| 457 | |
|---|
| 458 | |
|---|
| 459 | |
|---|
| 460 | if (bits_per_pixel <= 8) |
|---|
| 461 | bytes_per_line&=0x7fff; |
|---|
| 462 | width=image->columns; |
|---|
| 463 | bytes_per_pixel=1; |
|---|
| 464 | if (bits_per_pixel == 16) |
|---|
| 465 | { |
|---|
| 466 | bytes_per_pixel=2; |
|---|
| 467 | width*=2; |
|---|
| 468 | } |
|---|
| 469 | else |
|---|
| 470 | if (bits_per_pixel == 32) |
|---|
| 471 | width*=image->matte ? 4 : 3; |
|---|
| 472 | if (bytes_per_line == 0) |
|---|
| 473 | bytes_per_line=width; |
|---|
| 474 | row_bytes=(size_t) (image->columns | 0x8000); |
|---|
| 475 | if (image->storage_class == DirectClass) |
|---|
| 476 | row_bytes=(size_t) ((4*image->columns) | 0x8000); |
|---|
| 477 | |
|---|
| 478 | |
|---|
| 479 | |
|---|
| 480 | pixels=(unsigned char *) AcquireQuantumMemory(image->rows,row_bytes* |
|---|
| 481 | sizeof(*pixels)); |
|---|
| 482 | if (pixels == (unsigned char *) NULL) |
|---|
| 483 | return((unsigned char *) NULL); |
|---|
| 484 | *extent=row_bytes*image->rows*sizeof(*pixels); |
|---|
| 485 | (void) ResetMagickMemory(pixels,0,*extent); |
|---|
| 486 | scanline=(unsigned char *) AcquireQuantumMemory(row_bytes,sizeof(*scanline)); |
|---|
| 487 | if (scanline == (unsigned char *) NULL) |
|---|
| 488 | return((unsigned char *) NULL); |
|---|
| 489 | if (bytes_per_line < 8) |
|---|
| 490 | { |
|---|
| 491 | |
|---|
| 492 | |
|---|
| 493 | |
|---|
| 494 | for (y=0; y < (long) image->rows; y++) |
|---|
| 495 | { |
|---|
| 496 | q=pixels+y*width; |
|---|
| 497 | number_pixels=bytes_per_line; |
|---|
| 498 | count=ReadBlob(blob,(size_t) number_pixels,scanline); |
|---|
| 499 | p=ExpandBuffer(scanline,&number_pixels,bits_per_pixel); |
|---|
| 500 | if ((q+number_pixels) > (pixels+(*extent))) |
|---|
| 501 | { |
|---|
| 502 | (void) ThrowMagickException(&image->exception,GetMagickModule(), |
|---|
| 503 | CorruptImageError,"UnableToUncompressImage","`%s'", |
|---|
| 504 | image->filename); |
|---|
| 505 | break; |
|---|
| 506 | } |
|---|
| 507 | (void) CopyMagickMemory(q,p,(size_t) number_pixels); |
|---|
| 508 | } |
|---|
| 509 | scanline=(unsigned char *) RelinquishMagickMemory(scanline); |
|---|
| 510 | return(pixels); |
|---|
| 511 | } |
|---|
| 512 | |
|---|
| 513 | |
|---|
| 514 | |
|---|
| 515 | for (y=0; y < (long) image->rows; y++) |
|---|
| 516 | { |
|---|
| 517 | q=pixels+y*width; |
|---|
| 518 | if (bytes_per_line > 200) |
|---|
| 519 | scanline_length=ReadBlobMSBShort(blob); |
|---|
| 520 | else |
|---|
| 521 | scanline_length=1UL*ReadBlobByte(blob); |
|---|
| 522 | if (scanline_length >= row_bytes) |
|---|
| 523 | { |
|---|
| 524 | (void) ThrowMagickException(&image->exception,GetMagickModule(), |
|---|
| 525 | CorruptImageError,"UnableToUncompressImage","`%s'",image->filename); |
|---|
| 526 | break; |
|---|
| 527 | } |
|---|
| 528 | count=ReadBlob(blob,scanline_length,scanline); |
|---|
| 529 | for (j=0; j < (long) scanline_length; ) |
|---|
| 530 | if ((scanline[j] & 0x80) == 0) |
|---|
| 531 | { |
|---|
| 532 | length=(size_t) ((scanline[j] & 0xff)+1); |
|---|
| 533 | number_pixels=length*bytes_per_pixel; |
|---|
| 534 | p=ExpandBuffer(scanline+j+1,&number_pixels,bits_per_pixel); |
|---|
| 535 | if ((q-pixels+number_pixels) <= *extent) |
|---|
| 536 | (void) CopyMagickMemory(q,p,(size_t) number_pixels); |
|---|
| 537 | q+=number_pixels; |
|---|
| 538 | j+=(long) (length*bytes_per_pixel+1); |
|---|
| 539 | } |
|---|
| 540 | else |
|---|
| 541 | { |
|---|
| 542 | length=(size_t) (((scanline[j] ^ 0xff) & 0xff)+2); |
|---|
| 543 | number_pixels=bytes_per_pixel; |
|---|
| 544 | p=ExpandBuffer(scanline+j+1,&number_pixels,bits_per_pixel); |
|---|
| 545 | for (i=0; i < (long) length; i++) |
|---|
| 546 | { |
|---|
| 547 | if ((q-pixels+number_pixels) <= *extent) |
|---|
| 548 | (void) CopyMagickMemory(q,p,(size_t) number_pixels); |
|---|
| 549 | q+=number_pixels; |
|---|
| 550 | } |
|---|
| 551 | j+=bytes_per_pixel+1; |
|---|
| 552 | } |
|---|
| 553 | } |
|---|
| 554 | scanline=(unsigned char *) RelinquishMagickMemory(scanline); |
|---|
| 555 | return(pixels); |
|---|
| 556 | } |
|---|
| 557 | |
|---|
| 558 | |
|---|
| 559 | |
|---|
| 560 | |
|---|
| 561 | |
|---|
| 562 | |
|---|
| 563 | |
|---|
| 564 | |
|---|
| 565 | |
|---|
| 566 | |
|---|
| 567 | |
|---|
| 568 | |
|---|
| 569 | |
|---|
| 570 | |
|---|
| 571 | |
|---|
| 572 | |
|---|
| 573 | |
|---|
| 574 | |
|---|
| 575 | |
|---|
| 576 | |
|---|
| 577 | |
|---|
| 578 | |
|---|
| 579 | |
|---|
| 580 | |
|---|
| 581 | |
|---|
| 582 | |
|---|
| 583 | |
|---|
| 584 | |
|---|
| 585 | |
|---|
| 586 | |
|---|
| 587 | |
|---|
| 588 | |
|---|
| 589 | |
|---|
| 590 | static size_t EncodeImage(Image *image,const unsigned char *scanline, |
|---|
| 591 | const unsigned long bytes_per_line,unsigned char *pixels) |
|---|
| 592 | { |
|---|
| 593 | #define MaxCount 128 |
|---|
| 594 | #define MaxPackbitsRunlength 128 |
|---|
| 595 | |
|---|
| 596 | long |
|---|
| 597 | count, |
|---|
| 598 | repeat_count, |
|---|
| 599 | runlength; |
|---|
| 600 | |
|---|
| 601 | register const unsigned char |
|---|
| 602 | *p; |
|---|
| 603 | |
|---|
| 604 | register long |
|---|
| 605 | i; |
|---|
| 606 | |
|---|
| 607 | register unsigned char |
|---|
| 608 | *q; |
|---|
| 609 | |
|---|
| 610 | size_t |
|---|
| 611 | length; |
|---|
| 612 | |
|---|
| 613 | unsigned char |
|---|
| 614 | index; |
|---|
| 615 | |
|---|
| 616 | |
|---|
| 617 | |
|---|
| 618 | |
|---|
| 619 | assert(image != (Image *) NULL); |
|---|
| 620 | assert(image->signature == MagickSignature); |
|---|
| 621 | if (image->debug != MagickFalse) |
|---|
| 622 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
|---|
| 623 | assert(scanline != (unsigned char *) NULL); |
|---|
| 624 | assert(pixels != (unsigned char *) NULL); |
|---|
| 625 | count=0; |
|---|
| 626 | runlength=0; |
|---|
| 627 | p=scanline+(bytes_per_line-1); |
|---|
| 628 | q=pixels; |
|---|
| 629 | index=(*p); |
|---|
| 630 | for (i=(long) bytes_per_line-1; i >= 0; i--) |
|---|
| 631 | { |
|---|
| 632 | if (index == *p) |
|---|
| 633 | runlength++; |
|---|
| 634 | else |
|---|
| 635 | { |
|---|
| 636 | if (runlength < 3) |
|---|
| 637 | while (runlength > 0) |
|---|
| 638 | { |
|---|
| 639 | *q++=(unsigned char) index; |
|---|
| 640 | runlength--; |
|---|
| 641 | count++; |
|---|
| 642 | if (count == MaxCount) |
|---|
| 643 | { |
|---|
| 644 | *q++=(unsigned char) (MaxCount-1); |
|---|
| 645 | count-=MaxCount; |
|---|
| 646 | } |
|---|
| 647 | } |
|---|
| 648 | else |
|---|
| 649 | { |
|---|
| 650 | if (count > 0) |
|---|
| 651 | *q++=(unsigned char) (count-1); |
|---|
| 652 | count=0; |
|---|
| 653 | while (runlength > 0) |
|---|
| 654 | { |
|---|
| 655 | repeat_count=runlength; |
|---|
| 656 | if (repeat_count > MaxPackbitsRunlength) |
|---|
| 657 | repeat_count=MaxPackbitsRunlength; |
|---|
| 658 | *q++=(unsigned char) index; |
|---|
| 659 | *q++=(unsigned char) (257-repeat_count); |
|---|
| 660 | runlength-=repeat_count; |
|---|
| 661 | } |
|---|
| 662 | } |
|---|
| 663 | runlength=1; |
|---|
| 664 | } |
|---|
| 665 | index=(*p); |
|---|
| 666 | p--; |
|---|
| 667 | } |
|---|
| 668 | if (runlength < 3) |
|---|
| 669 | while (runlength > 0) |
|---|
| 670 | { |
|---|
| 671 | *q++=(unsigned char) index; |
|---|
| 672 | runlength--; |
|---|
| 673 | count++; |
|---|
| 674 | if (count == MaxCount) |
|---|
| 675 | { |
|---|
| 676 | *q++=(unsigned char) (MaxCount-1); |
|---|
| 677 | count-=MaxCount; |
|---|
| 678 | } |
|---|
| 679 | } |
|---|
| 680 | else |
|---|
| 681 | { |
|---|
| 682 | if (count > 0) |
|---|
| 683 | *q++=(unsigned char) (count-1); |
|---|
| 684 | count=0; |
|---|
| 685 | while (runlength > 0) |
|---|
| 686 | { |
|---|
| 687 | repeat_count=runlength; |
|---|
| 688 | if (repeat_count > MaxPackbitsRunlength) |
|---|
| 689 | repeat_count=MaxPackbitsRunlength; |
|---|
| 690 | *q++=(unsigned char) index; |
|---|
| 691 | *q++=(unsigned char) (257-repeat_count); |
|---|
| 692 | runlength-=repeat_count; |
|---|
| 693 | } |
|---|
| 694 | } |
|---|
| 695 | if (count > 0) |
|---|
| 696 | *q++=(unsigned char) (count-1); |
|---|
| 697 | |
|---|
| 698 | |
|---|
| 699 | |
|---|
| 700 | length=(size_t) (q-pixels); |
|---|
| 701 | if (bytes_per_line > 200) |
|---|
| 702 | { |
|---|
| 703 | (void) WriteBlobMSBShort(image,(unsigned short) length); |
|---|
| 704 | length+=2; |
|---|
| 705 | } |
|---|
| 706 | else |
|---|
| 707 | { |
|---|
| 708 | (void) WriteBlobByte(image,(unsigned char) length); |
|---|
| 709 | length++; |
|---|
| 710 | } |
|---|
| 711 | while (q != pixels) |
|---|
| 712 | { |
|---|
| 713 | q--; |
|---|
| 714 | (void) WriteBlobByte(image,*q); |
|---|
| 715 | } |
|---|
| 716 | return(length); |
|---|
| 717 | } |
|---|
| 718 | |
|---|
| 719 | |
|---|
| 720 | |
|---|
| 721 | |
|---|
| 722 | |
|---|
| 723 | |
|---|
| 724 | |
|---|
| 725 | |
|---|
| 726 | |
|---|
| 727 | |
|---|
| 728 | |
|---|
| 729 | |
|---|
| 730 | |
|---|
| 731 | |
|---|
| 732 | |
|---|
| 733 | |
|---|
| 734 | |
|---|
| 735 | |
|---|
| 736 | |
|---|
| 737 | |
|---|
| 738 | |
|---|
| 739 | |
|---|
| 740 | |
|---|
| 741 | |
|---|
| 742 | |
|---|
| 743 | |
|---|
| 744 | |
|---|
| 745 | |
|---|
| 746 | static MagickBooleanType IsPICT(const unsigned char *magick,const size_t length) |
|---|
| 747 | { |
|---|
| 748 | if (length < 528) |
|---|
| 749 | return(MagickFalse); |
|---|
| 750 | if (memcmp(magick+522,"\000\021\002\377\014\000",6) == 0) |
|---|
| 751 | return(MagickTrue); |
|---|
| 752 | return(MagickFalse); |
|---|
| 753 | } |
|---|
| 754 | |
|---|
| 755 | #if !defined(macintosh) |
|---|
| 756 | |
|---|
| 757 | |
|---|
| 758 | |
|---|
| 759 | |
|---|
| 760 | |
|---|
| 761 | |
|---|
| 762 | |
|---|
| 763 | |
|---|
| 764 | |
|---|
| 765 | |
|---|
| 766 | |
|---|
| 767 | |
|---|
| 768 | |
|---|
| 769 | |
|---|
| 770 | |
|---|
| 771 | |
|---|
| 772 | |
|---|
| 773 | |
|---|
| 774 | |
|---|
| 775 | |
|---|
| 776 | |
|---|
| 777 | |
|---|
| 778 | |
|---|
| 779 | |
|---|
| 780 | |
|---|
| 781 | |
|---|
| 782 | |
|---|
| 783 | |
|---|
| 784 | static inline unsigned long MagickMax(const unsigned long x, |
|---|
| 785 | const unsigned long y) |
|---|
| 786 | { |
|---|
| 787 | if (x > y) |
|---|
| 788 | return(x); |
|---|
| 789 | return(y); |
|---|
| 790 | } |
|---|
| 791 | |
|---|
| 792 | static Image *ReadPICTImage(const ImageInfo *image_info, |
|---|
| 793 | ExceptionInfo *exception) |
|---|
| 794 | { |
|---|
| 795 | char |
|---|
| 796 | geometry[MaxTextExtent]; |
|---|
| 797 | |
|---|
| 798 | Image |
|---|
| 799 | *image; |
|---|
| 800 | |
|---|
| 801 | IndexPacket |
|---|
| 802 | index; |
|---|
| 803 | |
|---|
| 804 | int |
|---|
| 805 | c, |
|---|
| 806 | code; |
|---|
| 807 | |
|---|
| 808 | long |
|---|
| 809 | flags, |
|---|
| 810 | j, |
|---|
| 811 | version, |
|---|
| 812 | y; |
|---|
| 813 | |
|---|
| 814 | MagickBooleanType |
|---|
| 815 | jpeg, |
|---|
| 816 | status; |
|---|
| 817 | |
|---|
| 818 | PICTRectangle |
|---|
| 819 | frame; |
|---|
| 820 | |
|---|
| 821 | PICTPixmap |
|---|
| 822 | pixmap; |
|---|
| 823 | |
|---|
| 824 | register IndexPacket |
|---|
| 825 | *indexes; |
|---|
| 826 | |
|---|
| 827 | register long |
|---|
| 828 | x; |
|---|
| 829 | |
|---|
| 830 | register PixelPacket |
|---|
| 831 | *q; |
|---|
| 832 | |
|---|
| 833 | register long |
|---|
| 834 | i; |
|---|
| 835 | |
|---|
| 836 | size_t |
|---|
| 837 | extent, |
|---|
| 838 | length; |
|---|
| 839 | |
|---|
| 840 | ssize_t |
|---|
| 841 | count; |
|---|
| 842 | |
|---|
| 843 | StringInfo |
|---|
| 844 | *profile; |
|---|
| 845 | |
|---|
| 846 | |
|---|
| 847 | |
|---|
| 848 | |
|---|
| 849 | assert(image_info != (const ImageInfo *) NULL); |
|---|
| 850 | assert(image_info->signature == MagickSignature); |
|---|
| 851 | if (image_info->debug != MagickFalse) |
|---|
| 852 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
|---|
| 853 | image_info->filename); |
|---|
| 854 | assert(exception != (ExceptionInfo *) NULL); |
|---|
| 855 | assert(exception->signature == MagickSignature); |
|---|
| 856 | image=AcquireImage(image_info); |
|---|
| 857 | image->depth=8; |
|---|
| 858 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
|---|
| 859 | if (status == MagickFalse) |
|---|
| 860 | { |
|---|
| 861 | image=DestroyImageList(image); |
|---|
| 862 | return((Image *) NULL); |
|---|
| 863 | } |
|---|
| 864 | |
|---|
| 865 | |
|---|
| 866 | |
|---|
| 867 | pixmap.bits_per_pixel=0; |
|---|
| 868 | pixmap.component_count=0; |
|---|
| 869 | for (i=0; i < 512; i++) |
|---|
| 870 | (void) ReadBlobByte(image); |
|---|
| 871 | (void) ReadBlobMSBShort(image); |
|---|
| 872 | ReadRectangle(image,frame); |
|---|