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