cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % PPPP SSSSS 22222 % |
| 7 | % P P SS 22 % |
| 8 | % PPPP SSS 222 % |
| 9 | % P SS 22 % |
| 10 | % P SSSSS 22222 % |
| 11 | % % |
| 12 | % % |
| 13 | % Write Postscript Level II Format % |
| 14 | % % |
| 15 | % Software Design % |
| 16 | % John Cristy % |
| 17 | % July 1992 % |
| 18 | % % |
| 19 | % % |
cristy | 45ef08f | 2012-12-07 13:13:34 +0000 | [diff] [blame] | 20 | % Copyright 1999-2013 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/attribute.h" |
| 44 | #include "MagickCore/blob.h" |
| 45 | #include "MagickCore/blob-private.h" |
| 46 | #include "MagickCore/cache.h" |
| 47 | #include "MagickCore/color.h" |
| 48 | #include "MagickCore/color-private.h" |
| 49 | #include "MagickCore/compress.h" |
| 50 | #include "MagickCore/constitute.h" |
| 51 | #include "MagickCore/draw.h" |
| 52 | #include "MagickCore/exception.h" |
| 53 | #include "MagickCore/exception-private.h" |
| 54 | #include "MagickCore/geometry.h" |
| 55 | #include "MagickCore/image.h" |
| 56 | #include "MagickCore/image-private.h" |
| 57 | #include "MagickCore/list.h" |
| 58 | #include "MagickCore/magick.h" |
| 59 | #include "MagickCore/memory_.h" |
| 60 | #include "MagickCore/monitor.h" |
| 61 | #include "MagickCore/monitor-private.h" |
| 62 | #include "MagickCore/monitor-private.h" |
| 63 | #include "MagickCore/option.h" |
| 64 | #include "MagickCore/pixel-accessor.h" |
| 65 | #include "MagickCore/property.h" |
| 66 | #include "MagickCore/quantum-private.h" |
| 67 | #include "MagickCore/resource_.h" |
| 68 | #include "MagickCore/static.h" |
| 69 | #include "MagickCore/string_.h" |
| 70 | #include "MagickCore/module.h" |
| 71 | #include "MagickCore/utility.h" |
cristy | 8097586 | 2009-09-25 14:34:31 +0000 | [diff] [blame] | 72 | |
| 73 | /* |
| 74 | Define declarations. |
| 75 | */ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 76 | #if defined(MAGICKCORE_TIFF_DELEGATE) |
| 77 | #define CCITTParam "-1" |
| 78 | #else |
| 79 | #define CCITTParam "0" |
| 80 | #endif |
| 81 | |
| 82 | /* |
| 83 | Forward declarations. |
| 84 | */ |
| 85 | static MagickBooleanType |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 86 | WritePS2Image(const ImageInfo *,Image *,ExceptionInfo *); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 87 | |
| 88 | /* |
| 89 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 90 | % % |
| 91 | % % |
| 92 | % % |
| 93 | % R e g i s t e r P S 2 I m a g e % |
| 94 | % % |
| 95 | % % |
| 96 | % % |
| 97 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 98 | % |
| 99 | % RegisterPS2Image() adds properties for the PS2 image format to |
| 100 | % the list of supported formats. The properties include the image format |
| 101 | % tag, a method to read and/or write the format, whether the format |
| 102 | % supports the saving of more than one frame to the same file or blob, |
| 103 | % whether the format supports native in-memory I/O, and a brief |
| 104 | % description of the format. |
| 105 | % |
| 106 | % The format of the RegisterPS2Image method is: |
| 107 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 108 | % size_t RegisterPS2Image(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 109 | % |
| 110 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 111 | ModuleExport size_t RegisterPS2Image(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 112 | { |
| 113 | MagickInfo |
| 114 | *entry; |
| 115 | |
| 116 | entry=SetMagickInfo("EPS2"); |
| 117 | entry->encoder=(EncodeImageHandler *) WritePS2Image; |
| 118 | entry->adjoin=MagickFalse; |
| 119 | entry->seekable_stream=MagickTrue; |
| 120 | entry->description=ConstantString("Level II Encapsulated PostScript"); |
| 121 | entry->module=ConstantString("PS2"); |
| 122 | (void) RegisterMagickInfo(entry); |
| 123 | entry=SetMagickInfo("PS2"); |
| 124 | entry->encoder=(EncodeImageHandler *) WritePS2Image; |
| 125 | entry->seekable_stream=MagickTrue; |
| 126 | entry->description=ConstantString("Level II PostScript"); |
| 127 | entry->module=ConstantString("PS2"); |
| 128 | (void) RegisterMagickInfo(entry); |
| 129 | return(MagickImageCoderSignature); |
| 130 | } |
| 131 | |
| 132 | /* |
| 133 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 134 | % % |
| 135 | % % |
| 136 | % % |
| 137 | % U n r e g i s t e r P S 2 I m a g e % |
| 138 | % % |
| 139 | % % |
| 140 | % % |
| 141 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 142 | % |
| 143 | % UnregisterPS2Image() removes format registrations made by the |
| 144 | % PS2 module from the list of supported formats. |
| 145 | % |
| 146 | % The format of the UnregisterPS2Image method is: |
| 147 | % |
| 148 | % UnregisterPS2Image(void) |
| 149 | % |
| 150 | */ |
| 151 | ModuleExport void UnregisterPS2Image(void) |
| 152 | { |
| 153 | (void) UnregisterMagickInfo("EPS2"); |
| 154 | (void) UnregisterMagickInfo("PS2"); |
| 155 | } |
| 156 | |
| 157 | /* |
| 158 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 159 | % % |
| 160 | % % |
| 161 | % % |
| 162 | % W r i t e P S 2 I m a g e % |
| 163 | % % |
| 164 | % % |
| 165 | % % |
| 166 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 167 | % |
| 168 | % WritePS2Image translates an image to encapsulated Postscript |
| 169 | % Level II for printing. If the supplied geometry is null, the image is |
| 170 | % centered on the Postscript page. Otherwise, the image is positioned as |
| 171 | % specified by the geometry. |
| 172 | % |
| 173 | % The format of the WritePS2Image method is: |
| 174 | % |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 175 | % MagickBooleanType WritePS2Image(const ImageInfo *image_info, |
| 176 | % Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 177 | % |
| 178 | % A description of each parameter follows: |
| 179 | % |
| 180 | % o image_info: the image info. |
| 181 | % |
| 182 | % o image: the image. |
| 183 | % |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 184 | % o exception: return any errors or warnings in this structure. |
| 185 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 186 | */ |
cristy | 47b838c | 2009-09-19 16:09:30 +0000 | [diff] [blame] | 187 | |
| 188 | static MagickBooleanType Huffman2DEncodeImage(const ImageInfo *image_info, |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 189 | Image *image,Image *inject_image,ExceptionInfo *exception) |
cristy | 47b838c | 2009-09-19 16:09:30 +0000 | [diff] [blame] | 190 | { |
cristy | 47b838c | 2009-09-19 16:09:30 +0000 | [diff] [blame] | 191 | Image |
cristy | 8097586 | 2009-09-25 14:34:31 +0000 | [diff] [blame] | 192 | *group4_image; |
cristy | 47b838c | 2009-09-19 16:09:30 +0000 | [diff] [blame] | 193 | |
| 194 | ImageInfo |
| 195 | *write_info; |
| 196 | |
cristy | 47b838c | 2009-09-19 16:09:30 +0000 | [diff] [blame] | 197 | MagickBooleanType |
| 198 | status; |
| 199 | |
cristy | 8097586 | 2009-09-25 14:34:31 +0000 | [diff] [blame] | 200 | size_t |
| 201 | length; |
cristy | 47b838c | 2009-09-19 16:09:30 +0000 | [diff] [blame] | 202 | |
| 203 | unsigned char |
cristy | 8097586 | 2009-09-25 14:34:31 +0000 | [diff] [blame] | 204 | *group4; |
cristy | 47b838c | 2009-09-19 16:09:30 +0000 | [diff] [blame] | 205 | |
cristy | 42751fe | 2009-10-05 00:15:50 +0000 | [diff] [blame] | 206 | status=MagickTrue; |
cristy | 47b838c | 2009-09-19 16:09:30 +0000 | [diff] [blame] | 207 | write_info=CloneImageInfo(image_info); |
cristy | 8097586 | 2009-09-25 14:34:31 +0000 | [diff] [blame] | 208 | (void) CopyMagickString(write_info->filename,"GROUP4:",MaxTextExtent); |
| 209 | (void) CopyMagickString(write_info->magick,"GROUP4",MaxTextExtent); |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 210 | group4_image=CloneImage(inject_image,0,0,MagickTrue,exception); |
cristy | 8097586 | 2009-09-25 14:34:31 +0000 | [diff] [blame] | 211 | if (group4_image == (Image *) NULL) |
| 212 | return(MagickFalse); |
| 213 | group4=(unsigned char *) ImageToBlob(write_info,group4_image,&length, |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 214 | exception); |
cristy | 8097586 | 2009-09-25 14:34:31 +0000 | [diff] [blame] | 215 | group4_image=DestroyImage(group4_image); |
| 216 | if (group4 == (unsigned char *) NULL) |
| 217 | return(MagickFalse); |
cristy | 47b838c | 2009-09-19 16:09:30 +0000 | [diff] [blame] | 218 | write_info=DestroyImageInfo(write_info); |
cristy | 8097586 | 2009-09-25 14:34:31 +0000 | [diff] [blame] | 219 | if (WriteBlob(image,length,group4) != (ssize_t) length) |
| 220 | status=MagickFalse; |
| 221 | group4=(unsigned char *) RelinquishMagickMemory(group4); |
| 222 | return(status); |
cristy | 47b838c | 2009-09-19 16:09:30 +0000 | [diff] [blame] | 223 | } |
| 224 | |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 225 | static MagickBooleanType WritePS2Image(const ImageInfo *image_info,Image *image, |
| 226 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 227 | { |
| 228 | static const char |
| 229 | *PostscriptProlog[]= |
| 230 | { |
| 231 | "%%%%BeginProlog", |
| 232 | "%%", |
| 233 | "%% Display a color image. The image is displayed in color on", |
| 234 | "%% Postscript viewers or printers that support color, otherwise", |
| 235 | "%% it is displayed as grayscale.", |
| 236 | "%%", |
| 237 | "/DirectClassImage", |
| 238 | "{", |
| 239 | " %%", |
| 240 | " %% Display a DirectClass image.", |
| 241 | " %%", |
| 242 | " colorspace 0 eq", |
| 243 | " {", |
| 244 | " /DeviceRGB setcolorspace", |
| 245 | " <<", |
| 246 | " /ImageType 1", |
| 247 | " /Width columns", |
| 248 | " /Height rows", |
| 249 | " /BitsPerComponent 8", |
| 250 | " /Decode [0 1 0 1 0 1]", |
| 251 | " /ImageMatrix [columns 0 0 rows neg 0 rows]", |
| 252 | " compression 0 gt", |
cristy | 8097586 | 2009-09-25 14:34:31 +0000 | [diff] [blame] | 253 | " { /DataSource pixel_stream %s }", |
| 254 | " { /DataSource pixel_stream %s } ifelse", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 255 | " >> image", |
| 256 | " }", |
| 257 | " {", |
| 258 | " /DeviceCMYK setcolorspace", |
| 259 | " <<", |
| 260 | " /ImageType 1", |
| 261 | " /Width columns", |
| 262 | " /Height rows", |
| 263 | " /BitsPerComponent 8", |
| 264 | " /Decode [1 0 1 0 1 0 1 0]", |
| 265 | " /ImageMatrix [columns 0 0 rows neg 0 rows]", |
| 266 | " compression 0 gt", |
cristy | 8097586 | 2009-09-25 14:34:31 +0000 | [diff] [blame] | 267 | " { /DataSource pixel_stream %s }", |
| 268 | " { /DataSource pixel_stream %s } ifelse", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 269 | " >> image", |
| 270 | " } ifelse", |
| 271 | "} bind def", |
| 272 | "", |
| 273 | "/PseudoClassImage", |
| 274 | "{", |
| 275 | " %%", |
| 276 | " %% Display a PseudoClass image.", |
| 277 | " %%", |
| 278 | " %% Parameters:", |
| 279 | " %% colors: number of colors in the colormap.", |
| 280 | " %%", |
| 281 | " currentfile buffer readline pop", |
| 282 | " token pop /colors exch def pop", |
| 283 | " colors 0 eq", |
| 284 | " {", |
| 285 | " %%", |
| 286 | " %% Image is grayscale.", |
| 287 | " %%", |
| 288 | " currentfile buffer readline pop", |
| 289 | " token pop /bits exch def pop", |
| 290 | " /DeviceGray setcolorspace", |
| 291 | " <<", |
| 292 | " /ImageType 1", |
| 293 | " /Width columns", |
| 294 | " /Height rows", |
| 295 | " /BitsPerComponent bits", |
| 296 | " /Decode [0 1]", |
| 297 | " /ImageMatrix [columns 0 0 rows neg 0 rows]", |
| 298 | " compression 0 gt", |
cristy | 8097586 | 2009-09-25 14:34:31 +0000 | [diff] [blame] | 299 | " { /DataSource pixel_stream %s }", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 300 | " {", |
cristy | 8097586 | 2009-09-25 14:34:31 +0000 | [diff] [blame] | 301 | " /DataSource pixel_stream %s", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 302 | " <<", |
| 303 | " /K "CCITTParam, |
| 304 | " /Columns columns", |
| 305 | " /Rows rows", |
| 306 | " >> /CCITTFaxDecode filter", |
| 307 | " } ifelse", |
| 308 | " >> image", |
| 309 | " }", |
| 310 | " {", |
| 311 | " %%", |
| 312 | " %% Parameters:", |
| 313 | " %% colormap: red, green, blue color packets.", |
| 314 | " %%", |
| 315 | " /colormap colors 3 mul string def", |
| 316 | " currentfile colormap readhexstring pop pop", |
| 317 | " currentfile buffer readline pop", |
| 318 | " [ /Indexed /DeviceRGB colors 1 sub colormap ] setcolorspace", |
| 319 | " <<", |
| 320 | " /ImageType 1", |
| 321 | " /Width columns", |
| 322 | " /Height rows", |
| 323 | " /BitsPerComponent 8", |
| 324 | " /Decode [0 255]", |
| 325 | " /ImageMatrix [columns 0 0 rows neg 0 rows]", |
| 326 | " compression 0 gt", |
cristy | 8097586 | 2009-09-25 14:34:31 +0000 | [diff] [blame] | 327 | " { /DataSource pixel_stream %s }", |
| 328 | " { /DataSource pixel_stream %s } ifelse", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 329 | " >> image", |
| 330 | " } ifelse", |
| 331 | "} bind def", |
| 332 | "", |
| 333 | "/DisplayImage", |
| 334 | "{", |
| 335 | " %%", |
| 336 | " %% Display a DirectClass or PseudoClass image.", |
| 337 | " %%", |
| 338 | " %% Parameters:", |
| 339 | " %% x & y translation.", |
| 340 | " %% x & y scale.", |
| 341 | " %% label pointsize.", |
| 342 | " %% image label.", |
| 343 | " %% image columns & rows.", |
| 344 | " %% class: 0-DirectClass or 1-PseudoClass.", |
| 345 | " %% colorspace: 0-RGB or 1-CMYK.", |
| 346 | " %% compression: 0-RLECompression or 1-NoCompression.", |
| 347 | " %% hex color packets.", |
| 348 | " %%", |
| 349 | " gsave", |
| 350 | " /buffer 512 string def", |
| 351 | " /pixel_stream currentfile def", |
| 352 | "", |
| 353 | " currentfile buffer readline pop", |
| 354 | " token pop /x exch def", |
| 355 | " token pop /y exch def pop", |
| 356 | " x y translate", |
| 357 | " currentfile buffer readline pop", |
| 358 | " token pop /x exch def", |
| 359 | " token pop /y exch def pop", |
| 360 | " currentfile buffer readline pop", |
| 361 | " token pop /pointsize exch def pop", |
| 362 | " /Helvetica findfont pointsize scalefont setfont", |
| 363 | (char *) NULL |
| 364 | }, |
| 365 | *PostscriptEpilog[]= |
| 366 | { |
| 367 | " x y scale", |
| 368 | " currentfile buffer readline pop", |
| 369 | " token pop /columns exch def", |
| 370 | " token pop /rows exch def pop", |
| 371 | " currentfile buffer readline pop", |
| 372 | " token pop /class exch def pop", |
| 373 | " currentfile buffer readline pop", |
| 374 | " token pop /colorspace exch def pop", |
| 375 | " currentfile buffer readline pop", |
| 376 | " token pop /compression exch def pop", |
| 377 | " class 0 gt { PseudoClassImage } { DirectClassImage } ifelse", |
cristy | 8b4ff22 | 2012-03-02 13:01:39 +0000 | [diff] [blame] | 378 | " grestore", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 379 | (char *) NULL |
| 380 | }; |
| 381 | |
| 382 | char |
| 383 | buffer[MaxTextExtent], |
| 384 | date[MaxTextExtent], |
| 385 | page_geometry[MaxTextExtent], |
| 386 | **labels; |
| 387 | |
| 388 | CompressionType |
| 389 | compression; |
| 390 | |
| 391 | const char |
| 392 | **q, |
| 393 | *value; |
| 394 | |
| 395 | double |
| 396 | pointsize; |
| 397 | |
| 398 | GeometryInfo |
| 399 | geometry_info; |
| 400 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 401 | MagickOffsetType |
| 402 | scene, |
| 403 | start, |
| 404 | stop; |
| 405 | |
| 406 | MagickBooleanType |
| 407 | progress, |
| 408 | status; |
| 409 | |
| 410 | MagickOffsetType |
| 411 | offset; |
| 412 | |
| 413 | MagickSizeType |
| 414 | number_pixels; |
| 415 | |
| 416 | MagickStatusType |
| 417 | flags; |
| 418 | |
| 419 | PointInfo |
| 420 | delta, |
| 421 | resolution, |
| 422 | scale; |
| 423 | |
| 424 | RectangleInfo |
| 425 | geometry, |
| 426 | media_info, |
| 427 | page_info; |
| 428 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 429 | register const Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 430 | *p; |
| 431 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 432 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 433 | x; |
| 434 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 435 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 436 | i; |
| 437 | |
| 438 | SegmentInfo |
| 439 | bounds; |
| 440 | |
| 441 | size_t |
cristy | 802d364 | 2011-04-27 02:02:41 +0000 | [diff] [blame] | 442 | length, |
| 443 | page, |
| 444 | text_size; |
| 445 | |
| 446 | ssize_t |
| 447 | j, |
| 448 | y; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 449 | |
| 450 | time_t |
| 451 | timer; |
| 452 | |
| 453 | unsigned char |
| 454 | *pixels; |
| 455 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 456 | /* |
| 457 | Open output image file. |
| 458 | */ |
| 459 | assert(image_info != (const ImageInfo *) NULL); |
| 460 | assert(image_info->signature == MagickSignature); |
| 461 | assert(image != (Image *) NULL); |
| 462 | assert(image->signature == MagickSignature); |
| 463 | if (image->debug != MagickFalse) |
| 464 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 465 | assert(exception != (ExceptionInfo *) NULL); |
| 466 | assert(exception->signature == MagickSignature); |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 467 | status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 468 | if (status == MagickFalse) |
| 469 | return(status); |
| 470 | compression=image->compression; |
| 471 | if (image_info->compression != UndefinedCompression) |
| 472 | compression=image_info->compression; |
| 473 | switch (compression) |
| 474 | { |
| 475 | #if !defined(MAGICKCORE_JPEG_DELEGATE) |
| 476 | case JPEGCompression: |
| 477 | { |
| 478 | compression=RLECompression; |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 479 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 480 | MissingDelegateError,"DelegateLibrarySupportNotBuiltIn","`%s' (JPEG)", |
| 481 | image->filename); |
| 482 | break; |
| 483 | } |
| 484 | #endif |
| 485 | default: |
| 486 | break; |
| 487 | } |
| 488 | (void) ResetMagickMemory(&bounds,0,sizeof(bounds)); |
| 489 | page=1; |
| 490 | scene=0; |
| 491 | do |
| 492 | { |
| 493 | /* |
| 494 | Scale relative to dots-per-inch. |
| 495 | */ |
| 496 | delta.x=DefaultResolution; |
| 497 | delta.y=DefaultResolution; |
cristy | 2a11bef | 2011-10-28 18:33:11 +0000 | [diff] [blame] | 498 | resolution.x=image->resolution.x; |
| 499 | resolution.y=image->resolution.y; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 500 | if ((resolution.x == 0.0) || (resolution.y == 0.0)) |
| 501 | { |
| 502 | flags=ParseGeometry(PSDensityGeometry,&geometry_info); |
| 503 | resolution.x=geometry_info.rho; |
| 504 | resolution.y=geometry_info.sigma; |
| 505 | if ((flags & SigmaValue) == 0) |
| 506 | resolution.y=resolution.x; |
| 507 | } |
| 508 | if (image_info->density != (char *) NULL) |
| 509 | { |
| 510 | flags=ParseGeometry(image_info->density,&geometry_info); |
| 511 | resolution.x=geometry_info.rho; |
| 512 | resolution.y=geometry_info.sigma; |
| 513 | if ((flags & SigmaValue) == 0) |
| 514 | resolution.y=resolution.x; |
| 515 | } |
| 516 | if (image->units == PixelsPerCentimeterResolution) |
| 517 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 518 | resolution.x=(size_t) (100.0*2.54*resolution.x+0.5)/100.0; |
| 519 | resolution.y=(size_t) (100.0*2.54*resolution.y+0.5)/100.0; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 520 | } |
| 521 | SetGeometry(image,&geometry); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 522 | (void) FormatLocaleString(page_geometry,MaxTextExtent,"%.20gx%.20g", |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 523 | (double) image->columns,(double) image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 524 | if (image_info->page != (char *) NULL) |
| 525 | (void) CopyMagickString(page_geometry,image_info->page,MaxTextExtent); |
| 526 | else |
| 527 | if ((image->page.width != 0) && (image->page.height != 0)) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 528 | (void) FormatLocaleString(page_geometry,MaxTextExtent, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 529 | "%.20gx%.20g%+.20g%+.20g",(double) image->page.width,(double) |
| 530 | image->page.height,(double) image->page.x,(double) image->page.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 531 | else |
| 532 | if ((image->gravity != UndefinedGravity) && |
| 533 | (LocaleCompare(image_info->magick,"PS") == 0)) |
| 534 | (void) CopyMagickString(page_geometry,PSPageGeometry,MaxTextExtent); |
| 535 | (void) ConcatenateMagickString(page_geometry,">",MaxTextExtent); |
| 536 | (void) ParseMetaGeometry(page_geometry,&geometry.x,&geometry.y, |
| 537 | &geometry.width,&geometry.height); |
| 538 | scale.x=(double) (geometry.width*delta.x)/resolution.x; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 539 | geometry.width=(size_t) floor(scale.x+0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 540 | scale.y=(double) (geometry.height*delta.y)/resolution.y; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 541 | geometry.height=(size_t) floor(scale.y+0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 542 | (void) ParseAbsoluteGeometry(page_geometry,&media_info); |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 543 | (void) ParseGravityGeometry(image,page_geometry,&page_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 544 | if (image->gravity != UndefinedGravity) |
| 545 | { |
| 546 | geometry.x=(-page_info.x); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 547 | geometry.y=(ssize_t) (media_info.height+page_info.y-image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 548 | } |
| 549 | pointsize=12.0; |
| 550 | if (image_info->pointsize != 0.0) |
| 551 | pointsize=image_info->pointsize; |
| 552 | text_size=0; |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 553 | value=GetImageProperty(image,"label",exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 554 | if (value != (const char *) NULL) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 555 | text_size=(size_t) (MultilineCensus(value)*pointsize+12); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 556 | if (page == 1) |
| 557 | { |
| 558 | /* |
| 559 | Output Postscript header. |
| 560 | */ |
| 561 | if (LocaleCompare(image_info->magick,"PS2") == 0) |
| 562 | (void) CopyMagickString(buffer,"%!PS-Adobe-3.0\n",MaxTextExtent); |
| 563 | else |
| 564 | (void) CopyMagickString(buffer,"%!PS-Adobe-3.0 EPSF-3.0\n", |
| 565 | MaxTextExtent); |
| 566 | (void) WriteBlobString(image,buffer); |
| 567 | (void) WriteBlobString(image,"%%Creator: (ImageMagick)\n"); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 568 | (void) FormatLocaleString(buffer,MaxTextExtent,"%%%%Title: (%s)\n", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 569 | image->filename); |
| 570 | (void) WriteBlobString(image,buffer); |
| 571 | timer=time((time_t *) NULL); |
| 572 | (void) FormatMagickTime(timer,MaxTextExtent,date); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 573 | (void) FormatLocaleString(buffer,MaxTextExtent, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 574 | "%%%%CreationDate: (%s)\n",date); |
| 575 | (void) WriteBlobString(image,buffer); |
| 576 | bounds.x1=(double) geometry.x; |
| 577 | bounds.y1=(double) geometry.y; |
| 578 | bounds.x2=(double) geometry.x+geometry.width; |
| 579 | bounds.y2=(double) geometry.y+geometry.height+text_size; |
| 580 | if ((image_info->adjoin != MagickFalse) && |
| 581 | (GetNextImageInList(image) != (Image *) NULL)) |
| 582 | (void) CopyMagickString(buffer,"%%BoundingBox: (atend)\n", |
| 583 | MaxTextExtent); |
| 584 | else |
| 585 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 586 | (void) FormatLocaleString(buffer,MaxTextExtent, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 587 | "%%%%BoundingBox: %.20g %.20g %.20g %.20g\n",ceil(bounds.x1-0.5), |
cristy | 8071c47 | 2012-09-24 12:41:06 +0000 | [diff] [blame] | 588 | ceil(bounds.y1-0.5),floor(bounds.x2+0.5),floor(bounds.y2+0.5)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 589 | (void) WriteBlobString(image,buffer); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 590 | (void) FormatLocaleString(buffer,MaxTextExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 591 | "%%%%HiResBoundingBox: %g %g %g %g\n",bounds.x1, |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 592 | bounds.y1,bounds.x2,bounds.y2); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 593 | } |
| 594 | (void) WriteBlobString(image,buffer); |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 595 | value=GetImageProperty(image,"label",exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 596 | if (value != (const char *) NULL) |
| 597 | (void) WriteBlobString(image, |
| 598 | "%%DocumentNeededResources: font Helvetica\n"); |
| 599 | (void) WriteBlobString(image,"%%LanguageLevel: 2\n"); |
| 600 | if (LocaleCompare(image_info->magick,"PS2") != 0) |
| 601 | (void) WriteBlobString(image,"%%Pages: 1\n"); |
| 602 | else |
| 603 | { |
| 604 | (void) WriteBlobString(image,"%%Orientation: Portrait\n"); |
| 605 | (void) WriteBlobString(image,"%%PageOrder: Ascend\n"); |
| 606 | if (image_info->adjoin == MagickFalse) |
| 607 | (void) CopyMagickString(buffer,"%%Pages: 1\n",MaxTextExtent); |
| 608 | else |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 609 | (void) FormatLocaleString(buffer,MaxTextExtent, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 610 | "%%%%Pages: %.20g\n",(double) GetImageListLength(image)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 611 | (void) WriteBlobString(image,buffer); |
| 612 | } |
| 613 | (void) WriteBlobString(image,"%%EndComments\n"); |
| 614 | (void) WriteBlobString(image,"\n%%BeginDefaults\n"); |
| 615 | (void) WriteBlobString(image,"%%EndDefaults\n\n"); |
| 616 | /* |
| 617 | Output Postscript commands. |
| 618 | */ |
| 619 | for (q=PostscriptProlog; *q; q++) |
| 620 | { |
| 621 | switch (compression) |
| 622 | { |
| 623 | case NoCompression: |
| 624 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 625 | (void) FormatLocaleString(buffer,MaxTextExtent,*q, |
cristy | 8097586 | 2009-09-25 14:34:31 +0000 | [diff] [blame] | 626 | "/ASCII85Decode filter"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 627 | break; |
| 628 | } |
| 629 | case JPEGCompression: |
| 630 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 631 | (void) FormatLocaleString(buffer,MaxTextExtent,*q, |
cristy | 8097586 | 2009-09-25 14:34:31 +0000 | [diff] [blame] | 632 | "/DCTDecode filter"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 633 | break; |
| 634 | } |
| 635 | case LZWCompression: |
| 636 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 637 | (void) FormatLocaleString(buffer,MaxTextExtent,*q, |
cristy | 8097586 | 2009-09-25 14:34:31 +0000 | [diff] [blame] | 638 | "/LZWDecode filter"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 639 | break; |
| 640 | } |
| 641 | case FaxCompression: |
| 642 | case Group4Compression: |
| 643 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 644 | (void) FormatLocaleString(buffer,MaxTextExtent,*q," "); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 645 | break; |
| 646 | } |
| 647 | default: |
| 648 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 649 | (void) FormatLocaleString(buffer,MaxTextExtent,*q, |
cristy | 8097586 | 2009-09-25 14:34:31 +0000 | [diff] [blame] | 650 | "/RunLengthDecode filter"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 651 | break; |
| 652 | } |
| 653 | } |
| 654 | (void) WriteBlobString(image,buffer); |
| 655 | (void) WriteBlobByte(image,'\n'); |
| 656 | } |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 657 | value=GetImageProperty(image,"label",exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 658 | if (value != (const char *) NULL) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 659 | for (j=(ssize_t) MultilineCensus(value)-1; j >= 0; j--) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 660 | { |
| 661 | (void) WriteBlobString(image," /label 512 string def\n"); |
| 662 | (void) WriteBlobString(image," currentfile label readline pop\n"); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 663 | (void) FormatLocaleString(buffer,MaxTextExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 664 | " 0 y %g add moveto label show pop\n",j*pointsize+12); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 665 | (void) WriteBlobString(image,buffer); |
| 666 | } |
| 667 | for (q=PostscriptEpilog; *q; q++) |
| 668 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 669 | (void) FormatLocaleString(buffer,MaxTextExtent,"%s\n",*q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 670 | (void) WriteBlobString(image,buffer); |
| 671 | } |
| 672 | if (LocaleCompare(image_info->magick,"PS2") == 0) |
| 673 | (void) WriteBlobString(image," showpage\n"); |
| 674 | (void) WriteBlobString(image,"} bind def\n"); |
| 675 | (void) WriteBlobString(image,"%%EndProlog\n"); |
| 676 | } |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 677 | (void) FormatLocaleString(buffer,MaxTextExtent,"%%%%Page: 1 %.20g\n", |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 678 | (double) page++); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 679 | (void) WriteBlobString(image,buffer); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 680 | (void) FormatLocaleString(buffer,MaxTextExtent, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 681 | "%%%%PageBoundingBox: %.20g %.20g %.20g %.20g\n",(double) geometry.x, |
| 682 | (double) geometry.y,geometry.x+(double) geometry.width,geometry.y+(double) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 683 | (geometry.height+text_size)); |
| 684 | (void) WriteBlobString(image,buffer); |
| 685 | if ((double) geometry.x < bounds.x1) |
| 686 | bounds.x1=(double) geometry.x; |
| 687 | if ((double) geometry.y < bounds.y1) |
| 688 | bounds.y1=(double) geometry.y; |
| 689 | if ((double) (geometry.x+geometry.width-1) > bounds.x2) |
| 690 | bounds.x2=(double) geometry.x+geometry.width-1; |
| 691 | if ((double) (geometry.y+(geometry.height+text_size)-1) > bounds.y2) |
| 692 | bounds.y2=(double) geometry.y+(geometry.height+text_size)-1; |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 693 | value=GetImageProperty(image,"label",exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 694 | if (value != (const char *) NULL) |
| 695 | (void) WriteBlobString(image,"%%PageResources: font Times-Roman\n"); |
| 696 | if (LocaleCompare(image_info->magick,"PS2") != 0) |
| 697 | (void) WriteBlobString(image,"userdict begin\n"); |
| 698 | start=TellBlob(image); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 699 | (void) FormatLocaleString(buffer,MaxTextExtent, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 700 | "%%%%BeginData:%13ld %s Bytes\n",0L, |
| 701 | compression == NoCompression ? "ASCII" : "Binary"); |
| 702 | (void) WriteBlobString(image,buffer); |
| 703 | stop=TellBlob(image); |
| 704 | (void) WriteBlobString(image,"DisplayImage\n"); |
| 705 | /* |
| 706 | Output image data. |
| 707 | */ |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 708 | (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g %.20g\n%g %g\n%g\n", |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 709 | (double) geometry.x,(double) geometry.y,scale.x,scale.y,pointsize); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 710 | (void) WriteBlobString(image,buffer); |
| 711 | labels=(char **) NULL; |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 712 | value=GetImageProperty(image,"label",exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 713 | if (value != (const char *) NULL) |
| 714 | labels=StringToList(value); |
| 715 | if (labels != (char **) NULL) |
| 716 | { |
| 717 | for (i=0; labels[i] != (char *) NULL; i++) |
| 718 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 719 | (void) FormatLocaleString(buffer,MaxTextExtent,"%s \n", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 720 | labels[i]); |
| 721 | (void) WriteBlobString(image,buffer); |
| 722 | labels[i]=DestroyString(labels[i]); |
| 723 | } |
| 724 | labels=(char **) RelinquishMagickMemory(labels); |
| 725 | } |
| 726 | number_pixels=(MagickSizeType) image->columns*image->rows; |
| 727 | if (number_pixels != (MagickSizeType) ((size_t) number_pixels)) |
| 728 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
| 729 | if ((compression == FaxCompression) || (compression == Group4Compression) || |
| 730 | ((image_info->type != TrueColorType) && |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 731 | (IsImageGray(image,exception) != MagickFalse))) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 732 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 733 | (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g %.20g\n1\n%d\n", |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 734 | (double) image->columns,(double) image->rows,(int) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 735 | (image->colorspace == CMYKColorspace)); |
| 736 | (void) WriteBlobString(image,buffer); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 737 | (void) FormatLocaleString(buffer,MaxTextExtent,"%d\n", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 738 | (int) ((compression != FaxCompression) && |
| 739 | (compression != Group4Compression))); |
| 740 | (void) WriteBlobString(image,buffer); |
| 741 | (void) WriteBlobString(image,"0\n"); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 742 | (void) FormatLocaleString(buffer,MaxTextExtent,"%d\n", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 743 | (compression == FaxCompression) || |
| 744 | (compression == Group4Compression) ? 1 : 8); |
| 745 | (void) WriteBlobString(image,buffer); |
| 746 | switch (compression) |
| 747 | { |
| 748 | case FaxCompression: |
| 749 | case Group4Compression: |
| 750 | { |
| 751 | if (LocaleCompare(CCITTParam,"0") == 0) |
| 752 | { |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 753 | (void) HuffmanEncodeImage(image_info,image,image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 754 | break; |
| 755 | } |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 756 | (void) Huffman2DEncodeImage(image_info,image,image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 757 | break; |
| 758 | } |
| 759 | case JPEGCompression: |
| 760 | { |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 761 | status=InjectImageBlob(image_info,image,image,"jpeg",exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 762 | if (status == MagickFalse) |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 763 | { |
| 764 | (void) CloseBlob(image); |
| 765 | return(MagickFalse); |
| 766 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 767 | break; |
| 768 | } |
| 769 | case RLECompression: |
| 770 | default: |
| 771 | { |
| 772 | register unsigned char |
| 773 | *q; |
| 774 | |
| 775 | /* |
| 776 | Allocate pixel array. |
| 777 | */ |
| 778 | length=(size_t) number_pixels; |
| 779 | pixels=(unsigned char *) AcquireQuantumMemory(length, |
| 780 | sizeof(*pixels)); |
| 781 | if (pixels == (unsigned char *) NULL) |
| 782 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
| 783 | /* |
| 784 | Dump Runlength encoded pixels. |
| 785 | */ |
| 786 | q=pixels; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 787 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 788 | { |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 789 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 790 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 791 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 792 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 793 | { |
cristy | d032322 | 2013-04-07 16:13:21 +0000 | [diff] [blame^] | 794 | *q++=ScaleQuantumToChar(ClampToQuantum(GetPixelLuma(image,p))); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 795 | p+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 796 | } |
cristy | 802d364 | 2011-04-27 02:02:41 +0000 | [diff] [blame] | 797 | progress=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
| 798 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 799 | if (progress == MagickFalse) |
| 800 | break; |
| 801 | } |
| 802 | length=(size_t) (q-pixels); |
| 803 | if (compression == LZWCompression) |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 804 | status=LZWEncodeImage(image,length,pixels,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 805 | else |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 806 | status=PackbitsEncodeImage(image,length,pixels,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 807 | pixels=(unsigned char *) RelinquishMagickMemory(pixels); |
| 808 | if (status == MagickFalse) |
| 809 | { |
| 810 | (void) CloseBlob(image); |
| 811 | return(MagickFalse); |
| 812 | } |
| 813 | break; |
| 814 | } |
| 815 | case NoCompression: |
| 816 | { |
| 817 | /* |
| 818 | Dump uncompressed PseudoColor packets. |
| 819 | */ |
| 820 | Ascii85Initialize(image); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 821 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 822 | { |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 823 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 824 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 825 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 826 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 827 | { |
cristy | d032322 | 2013-04-07 16:13:21 +0000 | [diff] [blame^] | 828 | Ascii85Encode(image,ScaleQuantumToChar(ClampToQuantum( |
| 829 | GetPixelLuma(image,p)))); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 830 | p+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 831 | } |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 832 | progress=SetImageProgress(image,SaveImageTag,(MagickOffsetType) |
| 833 | y,image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 834 | if (progress == MagickFalse) |
| 835 | break; |
| 836 | } |
| 837 | Ascii85Flush(image); |
| 838 | break; |
| 839 | } |
| 840 | } |
| 841 | } |
| 842 | else |
| 843 | if ((image->storage_class == DirectClass) || (image->colors > 256) || |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 844 | (compression == JPEGCompression) || (image->alpha_trait == BlendPixelTrait)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 845 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 846 | (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g %.20g\n0\n%d\n", |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 847 | (double) image->columns,(double) image->rows,(int) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 848 | (image->colorspace == CMYKColorspace)); |
| 849 | (void) WriteBlobString(image,buffer); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 850 | (void) FormatLocaleString(buffer,MaxTextExtent,"%d\n", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 851 | (int) (compression == NoCompression)); |
| 852 | (void) WriteBlobString(image,buffer); |
| 853 | switch (compression) |
| 854 | { |
| 855 | case JPEGCompression: |
| 856 | { |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 857 | status=InjectImageBlob(image_info,image,image,"jpeg",exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 858 | if (status == MagickFalse) |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 859 | { |
| 860 | (void) CloseBlob(image); |
| 861 | return(MagickFalse); |
| 862 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 863 | break; |
| 864 | } |
| 865 | case RLECompression: |
| 866 | default: |
| 867 | { |
| 868 | register unsigned char |
| 869 | *q; |
| 870 | |
| 871 | /* |
| 872 | Allocate pixel array. |
| 873 | */ |
| 874 | length=(size_t) number_pixels; |
| 875 | pixels=(unsigned char *) AcquireQuantumMemory(length, |
| 876 | 4*sizeof(*pixels)); |
| 877 | if (pixels == (unsigned char *) NULL) |
| 878 | ThrowWriterException(ResourceLimitError, |
| 879 | "MemoryAllocationFailed"); |
| 880 | /* |
| 881 | Dump Packbit encoded pixels. |
| 882 | */ |
| 883 | q=pixels; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 884 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 885 | { |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 886 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 887 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 888 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 889 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 890 | { |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 891 | if ((image->alpha_trait == BlendPixelTrait) && |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 892 | (GetPixelAlpha(image,p) == (Quantum) TransparentAlpha)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 893 | { |
cristy | 6e963d8 | 2012-06-19 15:23:24 +0000 | [diff] [blame] | 894 | *q++=ScaleQuantumToChar(QuantumRange); |
| 895 | *q++=ScaleQuantumToChar(QuantumRange); |
| 896 | *q++=ScaleQuantumToChar(QuantumRange); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 897 | } |
| 898 | else |
| 899 | if (image->colorspace != CMYKColorspace) |
| 900 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 901 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 902 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 903 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 904 | } |
| 905 | else |
| 906 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 907 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 908 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 909 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
| 910 | *q++=ScaleQuantumToChar(GetPixelBlack(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 911 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 912 | p+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 913 | } |
cristy | 802d364 | 2011-04-27 02:02:41 +0000 | [diff] [blame] | 914 | progress=SetImageProgress(image,SaveImageTag,(MagickOffsetType) |
| 915 | y,image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 916 | if (progress == MagickFalse) |
| 917 | break; |
| 918 | } |
| 919 | length=(size_t) (q-pixels); |
| 920 | if (compression == LZWCompression) |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 921 | status=LZWEncodeImage(image,length,pixels,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 922 | else |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 923 | status=PackbitsEncodeImage(image,length,pixels,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 924 | if (status == MagickFalse) |
| 925 | { |
| 926 | (void) CloseBlob(image); |
| 927 | return(MagickFalse); |
| 928 | } |
| 929 | pixels=(unsigned char *) RelinquishMagickMemory(pixels); |
| 930 | break; |
| 931 | } |
| 932 | case NoCompression: |
| 933 | { |
| 934 | /* |
| 935 | Dump uncompressed DirectColor packets. |
| 936 | */ |
| 937 | Ascii85Initialize(image); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 938 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 939 | { |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 940 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 941 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 942 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 943 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 944 | { |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 945 | if ((image->alpha_trait == BlendPixelTrait) && |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 946 | (GetPixelAlpha(image,p) == (Quantum) TransparentAlpha)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 947 | { |
| 948 | Ascii85Encode(image,ScaleQuantumToChar((Quantum) |
| 949 | QuantumRange)); |
| 950 | Ascii85Encode(image,ScaleQuantumToChar((Quantum) |
| 951 | QuantumRange)); |
| 952 | Ascii85Encode(image,ScaleQuantumToChar((Quantum) |
| 953 | QuantumRange)); |
| 954 | } |
| 955 | else |
| 956 | if (image->colorspace != CMYKColorspace) |
| 957 | { |
cristy | 802d364 | 2011-04-27 02:02:41 +0000 | [diff] [blame] | 958 | Ascii85Encode(image,ScaleQuantumToChar( |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 959 | GetPixelRed(image,p))); |
cristy | 802d364 | 2011-04-27 02:02:41 +0000 | [diff] [blame] | 960 | Ascii85Encode(image,ScaleQuantumToChar( |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 961 | GetPixelGreen(image,p))); |
cristy | 802d364 | 2011-04-27 02:02:41 +0000 | [diff] [blame] | 962 | Ascii85Encode(image,ScaleQuantumToChar( |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 963 | GetPixelBlue(image,p))); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 964 | } |
| 965 | else |
| 966 | { |
cristy | 802d364 | 2011-04-27 02:02:41 +0000 | [diff] [blame] | 967 | Ascii85Encode(image,ScaleQuantumToChar( |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 968 | GetPixelRed(image,p))); |
cristy | 802d364 | 2011-04-27 02:02:41 +0000 | [diff] [blame] | 969 | Ascii85Encode(image,ScaleQuantumToChar( |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 970 | GetPixelGreen(image,p))); |
cristy | 802d364 | 2011-04-27 02:02:41 +0000 | [diff] [blame] | 971 | Ascii85Encode(image,ScaleQuantumToChar( |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 972 | GetPixelBlue(image,p))); |
cristy | 9fff7b4 | 2011-04-29 01:09:31 +0000 | [diff] [blame] | 973 | Ascii85Encode(image,ScaleQuantumToChar( |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 974 | GetPixelBlack(image,p))); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 975 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 976 | p+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 977 | } |
cristy | 802d364 | 2011-04-27 02:02:41 +0000 | [diff] [blame] | 978 | progress=SetImageProgress(image,SaveImageTag,(MagickOffsetType) |
| 979 | y,image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 980 | if (progress == MagickFalse) |
| 981 | break; |
| 982 | } |
| 983 | Ascii85Flush(image); |
| 984 | break; |
| 985 | } |
| 986 | } |
| 987 | } |
| 988 | else |
| 989 | { |
| 990 | /* |
| 991 | Dump number of colors and colormap. |
| 992 | */ |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 993 | (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g %.20g\n1\n%d\n", |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 994 | (double) image->columns,(double) image->rows,(int) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 995 | (image->colorspace == CMYKColorspace)); |
| 996 | (void) WriteBlobString(image,buffer); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 997 | (void) FormatLocaleString(buffer,MaxTextExtent,"%d\n", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 998 | (int) (compression == NoCompression)); |
| 999 | (void) WriteBlobString(image,buffer); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1000 | (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g\n",(double) |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 1001 | image->colors); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1002 | (void) WriteBlobString(image,buffer); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1003 | for (i=0; i < (ssize_t) image->colors; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1004 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1005 | (void) FormatLocaleString(buffer,MaxTextExtent,"%02X%02X%02X\n", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1006 | ScaleQuantumToChar(image->colormap[i].red), |
| 1007 | ScaleQuantumToChar(image->colormap[i].green), |
| 1008 | ScaleQuantumToChar(image->colormap[i].blue)); |
| 1009 | (void) WriteBlobString(image,buffer); |
| 1010 | } |
| 1011 | switch (compression) |
| 1012 | { |
| 1013 | case RLECompression: |
| 1014 | default: |
| 1015 | { |
| 1016 | register unsigned char |
| 1017 | *q; |
| 1018 | |
| 1019 | /* |
| 1020 | Allocate pixel array. |
| 1021 | */ |
| 1022 | length=(size_t) number_pixels; |
| 1023 | pixels=(unsigned char *) AcquireQuantumMemory(length, |
| 1024 | sizeof(*pixels)); |
| 1025 | if (pixels == (unsigned char *) NULL) |
| 1026 | ThrowWriterException(ResourceLimitError, |
| 1027 | "MemoryAllocationFailed"); |
| 1028 | /* |
| 1029 | Dump Runlength encoded pixels. |
| 1030 | */ |
| 1031 | q=pixels; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1032 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1033 | { |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1034 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1035 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1036 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1037 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1038 | { |
| 1039 | *q++=(unsigned char) GetPixelIndex(image,p); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1040 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1041 | } |
cristy | 802d364 | 2011-04-27 02:02:41 +0000 | [diff] [blame] | 1042 | progress=SetImageProgress(image,SaveImageTag,(MagickOffsetType) |
| 1043 | y,image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1044 | if (progress == MagickFalse) |
| 1045 | break; |
| 1046 | } |
| 1047 | length=(size_t) (q-pixels); |
| 1048 | if (compression == LZWCompression) |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1049 | status=LZWEncodeImage(image,length,pixels,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1050 | else |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1051 | status=PackbitsEncodeImage(image,length,pixels,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1052 | pixels=(unsigned char *) RelinquishMagickMemory(pixels); |
| 1053 | if (status == MagickFalse) |
| 1054 | { |
| 1055 | (void) CloseBlob(image); |
| 1056 | return(MagickFalse); |
| 1057 | } |
| 1058 | break; |
| 1059 | } |
| 1060 | case NoCompression: |
| 1061 | { |
| 1062 | /* |
| 1063 | Dump uncompressed PseudoColor packets. |
| 1064 | */ |
| 1065 | Ascii85Initialize(image); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1066 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1067 | { |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1068 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1069 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1070 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1071 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1072 | { |
| 1073 | Ascii85Encode(image,(unsigned char) GetPixelIndex(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1074 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1075 | } |
cristy | 802d364 | 2011-04-27 02:02:41 +0000 | [diff] [blame] | 1076 | progress=SetImageProgress(image,SaveImageTag,(MagickOffsetType) |
| 1077 | y,image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1078 | if (progress == MagickFalse) |
| 1079 | break; |
| 1080 | } |
| 1081 | Ascii85Flush(image); |
| 1082 | break; |
| 1083 | } |
| 1084 | } |
| 1085 | } |
| 1086 | (void) WriteBlobByte(image,'\n'); |
| 1087 | length=(size_t) (TellBlob(image)-stop); |
| 1088 | stop=TellBlob(image); |
| 1089 | offset=SeekBlob(image,start,SEEK_SET); |
| 1090 | if (offset < 0) |
| 1091 | ThrowWriterException(CorruptImageError,"ImproperImageHeader"); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1092 | (void) FormatLocaleString(buffer,MaxTextExtent, |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 1093 | "%%%%BeginData:%13ld %s Bytes\n",(long) length, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1094 | compression == NoCompression ? "ASCII" : "Binary"); |
| 1095 | (void) WriteBlobString(image,buffer); |
| 1096 | offset=SeekBlob(image,stop,SEEK_SET); |
| 1097 | (void) WriteBlobString(image,"%%EndData\n"); |
| 1098 | if (LocaleCompare(image_info->magick,"PS2") != 0) |
| 1099 | (void) WriteBlobString(image,"end\n"); |
| 1100 | (void) WriteBlobString(image,"%%PageTrailer\n"); |
| 1101 | if (GetNextImageInList(image) == (Image *) NULL) |
| 1102 | break; |
| 1103 | image=SyncNextImageInList(image); |
| 1104 | status=SetImageProgress(image,SaveImagesTag,scene++, |
| 1105 | GetImageListLength(image)); |
| 1106 | if (status == MagickFalse) |
| 1107 | break; |
| 1108 | } while (image_info->adjoin != MagickFalse); |
| 1109 | (void) WriteBlobString(image,"%%Trailer\n"); |
| 1110 | if (page > 1) |
| 1111 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1112 | (void) FormatLocaleString(buffer,MaxTextExtent, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 1113 | "%%%%BoundingBox: %.20g %.20g %.20g %.20g\n",ceil(bounds.x1-0.5), |
cristy | 8071c47 | 2012-09-24 12:41:06 +0000 | [diff] [blame] | 1114 | ceil(bounds.y1-0.5),floor(bounds.x2+0.5),floor(bounds.y2+0.5)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1115 | (void) WriteBlobString(image,buffer); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1116 | (void) FormatLocaleString(buffer,MaxTextExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 1117 | "%%%%HiResBoundingBox: %g %g %g %g\n",bounds.x1,bounds.y1, |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 1118 | bounds.x2,bounds.y2); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1119 | (void) WriteBlobString(image,buffer); |
| 1120 | } |
| 1121 | (void) WriteBlobString(image,"%%EOF\n"); |
| 1122 | (void) CloseBlob(image); |
| 1123 | return(MagickTrue); |
| 1124 | } |