cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % PPPP SSSSS 33333 % |
| 7 | % P P SS 33 % |
| 8 | % PPPP SSS 333 % |
| 9 | % P SS 33 % |
| 10 | % P SSSSS 33333 % |
| 11 | % % |
| 12 | % % |
| 13 | % Write Postscript Level III Format % |
| 14 | % % |
| 15 | % Software Design % |
| 16 | % John Cristy % |
| 17 | % Lars Ruben Skyum % |
| 18 | % July 1992 % |
| 19 | % % |
| 20 | % % |
cristy | 1454be7 | 2011-12-19 01:52:48 +0000 | [diff] [blame] | 21 | % Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 22 | % dedicated to making software imaging solutions freely available. % |
| 23 | % % |
| 24 | % You may not use this file except in compliance with the License. You may % |
| 25 | % obtain a copy of the License at % |
| 26 | % % |
| 27 | % http://www.imagemagick.org/script/license.php % |
| 28 | % % |
| 29 | % Unless required by applicable law or agreed to in writing, software % |
| 30 | % distributed under the License is distributed on an "AS IS" BASIS, % |
| 31 | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
| 32 | % See the License for the specific language governing permissions and % |
| 33 | % limitations under the License. % |
| 34 | % % |
| 35 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 36 | % |
| 37 | % |
| 38 | */ |
| 39 | |
| 40 | /* |
| 41 | Include declarations. |
| 42 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 43 | #include "MagickCore/studio.h" |
| 44 | #include "MagickCore/attribute.h" |
| 45 | #include "MagickCore/blob.h" |
| 46 | #include "MagickCore/blob-private.h" |
| 47 | #include "MagickCore/cache.h" |
cristy | 500d6b9 | 2012-03-05 19:12:49 +0000 | [diff] [blame] | 48 | #include "MagickCore/channel.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 49 | #include "MagickCore/color.h" |
| 50 | #include "MagickCore/color-private.h" |
| 51 | #include "MagickCore/compress.h" |
| 52 | #include "MagickCore/constitute.h" |
| 53 | #include "MagickCore/draw.h" |
| 54 | #include "MagickCore/exception.h" |
| 55 | #include "MagickCore/exception-private.h" |
| 56 | #include "MagickCore/geometry.h" |
| 57 | #include "MagickCore/image.h" |
| 58 | #include "MagickCore/image-private.h" |
| 59 | #include "MagickCore/list.h" |
| 60 | #include "MagickCore/magick.h" |
| 61 | #include "MagickCore/memory_.h" |
| 62 | #include "MagickCore/monitor.h" |
| 63 | #include "MagickCore/monitor-private.h" |
| 64 | #include "MagickCore/option.h" |
| 65 | #include "MagickCore/pixel-accessor.h" |
| 66 | #include "MagickCore/property.h" |
| 67 | #include "MagickCore/quantum-private.h" |
| 68 | #include "MagickCore/resource_.h" |
| 69 | #include "MagickCore/static.h" |
| 70 | #include "MagickCore/string_.h" |
| 71 | #include "MagickCore/module.h" |
| 72 | #include "MagickCore/token.h" |
| 73 | #include "MagickCore/utility.h" |
| 74 | #include "MagickCore/module.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 75 | |
| 76 | /* |
| 77 | Define declarations. |
| 78 | */ |
| 79 | #define PS3_NoCompression "0" |
| 80 | #define PS3_FaxCompression "1" |
| 81 | #define PS3_JPEGCompression "2" |
| 82 | #define PS3_LZWCompression "3" |
| 83 | #define PS3_RLECompression "4" |
| 84 | #define PS3_ZipCompression "5" |
| 85 | |
| 86 | #define PS3_RGBColorspace "0" |
| 87 | #define PS3_CMYKColorspace "1" |
| 88 | |
| 89 | #define PS3_DirectClass "0" |
| 90 | #define PS3_PseudoClass "1" |
cristy | 8097586 | 2009-09-25 14:34:31 +0000 | [diff] [blame] | 91 | |
| 92 | #if defined(MAGICKCORE_TIFF_DELEGATE) |
cristy | 8097586 | 2009-09-25 14:34:31 +0000 | [diff] [blame] | 93 | #define CCITTParam "-1" |
| 94 | #else |
| 95 | #define CCITTParam "0" |
| 96 | #endif |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 97 | |
| 98 | /* |
| 99 | Forward declarations. |
| 100 | */ |
| 101 | static MagickBooleanType |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 102 | WritePS3Image(const ImageInfo *,Image *,ExceptionInfo *); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 103 | |
| 104 | /* |
| 105 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 106 | % % |
| 107 | % % |
| 108 | % % |
| 109 | % R e g i s t e r P S 3 I m a g e % |
| 110 | % % |
| 111 | % % |
| 112 | % % |
| 113 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 114 | % |
| 115 | % RegisterPS3Image() adds properties for the PS3 image format to the list of |
| 116 | % supported formats. The properties include the image format tag, a method to |
| 117 | % read and/or write the format, whether the format supports the saving of more |
| 118 | % than one frame to the same file or blob, whether the format supports native |
| 119 | % in-memory I/O, and a brief description of the format. |
| 120 | % |
| 121 | % The format of the RegisterPS3Image method is: |
| 122 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 123 | % size_t RegisterPS3Image(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 124 | % |
| 125 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 126 | ModuleExport size_t RegisterPS3Image(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 127 | { |
| 128 | MagickInfo |
| 129 | *entry; |
| 130 | |
| 131 | entry=SetMagickInfo("EPS3"); |
| 132 | entry->encoder=(EncodeImageHandler *) WritePS3Image; |
| 133 | entry->description=ConstantString("Level III Encapsulated PostScript"); |
| 134 | entry->module=ConstantString("PS3"); |
cristy | ffaf978 | 2011-04-13 19:50:51 +0000 | [diff] [blame] | 135 | entry->seekable_stream=MagickTrue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 136 | (void) RegisterMagickInfo(entry); |
| 137 | entry=SetMagickInfo("PS3"); |
| 138 | entry->encoder=(EncodeImageHandler *) WritePS3Image; |
| 139 | entry->description=ConstantString("Level III PostScript"); |
| 140 | entry->module=ConstantString("PS3"); |
cristy | ffaf978 | 2011-04-13 19:50:51 +0000 | [diff] [blame] | 141 | entry->seekable_stream=MagickTrue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 142 | (void) RegisterMagickInfo(entry); |
| 143 | return(MagickImageCoderSignature); |
| 144 | } |
| 145 | |
| 146 | /* |
| 147 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 148 | % % |
| 149 | % % |
| 150 | % % |
| 151 | % U n r e g i s t e r P S 3 I m a g e % |
| 152 | % % |
| 153 | % % |
| 154 | % % |
| 155 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 156 | % |
| 157 | % UnregisterPS3Image() removes format registrations made by the PS3 module |
| 158 | % from the list of supported formats. |
| 159 | % |
| 160 | % The format of the UnregisterPS3Image method is: |
| 161 | % |
| 162 | % UnregisterPS3Image(void) |
| 163 | % |
| 164 | */ |
| 165 | ModuleExport void UnregisterPS3Image(void) |
| 166 | { |
| 167 | (void) UnregisterMagickInfo("EPS3"); |
| 168 | (void) UnregisterMagickInfo("PS3"); |
| 169 | } |
| 170 | |
| 171 | /* |
| 172 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 173 | % % |
| 174 | % % |
| 175 | % % |
| 176 | % W r i t e P S 3 I m a g e % |
| 177 | % % |
| 178 | % % |
| 179 | % % |
| 180 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 181 | % |
| 182 | % WritePS3Image() translates an image to encapsulated Postscript Level III |
| 183 | % for printing. If the supplied geometry is null, the image is centered on |
| 184 | % the Postscript page. Otherwise, the image is positioned as specified by the |
| 185 | % geometry. |
| 186 | % |
| 187 | % The format of the WritePS3Image method is: |
| 188 | % |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 189 | % MagickBooleanType WritePS3Image(const ImageInfo *image_info, |
| 190 | % Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 191 | % |
| 192 | % A description of each parameter follows: |
| 193 | % |
| 194 | % o image_info: Specifies a pointer to a ImageInfo structure. |
| 195 | % |
| 196 | % o image: the image. |
| 197 | % |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 198 | % o exception: return any errors or warnings in this structure. |
| 199 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 200 | */ |
| 201 | |
cristy | 47b838c | 2009-09-19 16:09:30 +0000 | [diff] [blame] | 202 | static MagickBooleanType Huffman2DEncodeImage(const ImageInfo *image_info, |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 203 | Image *image,Image *inject_image,ExceptionInfo *exception) |
cristy | 47b838c | 2009-09-19 16:09:30 +0000 | [diff] [blame] | 204 | { |
cristy | 47b838c | 2009-09-19 16:09:30 +0000 | [diff] [blame] | 205 | Image |
cristy | 8097586 | 2009-09-25 14:34:31 +0000 | [diff] [blame] | 206 | *group4_image; |
cristy | 47b838c | 2009-09-19 16:09:30 +0000 | [diff] [blame] | 207 | |
| 208 | ImageInfo |
| 209 | *write_info; |
| 210 | |
cristy | 47b838c | 2009-09-19 16:09:30 +0000 | [diff] [blame] | 211 | MagickBooleanType |
| 212 | status; |
| 213 | |
cristy | 8097586 | 2009-09-25 14:34:31 +0000 | [diff] [blame] | 214 | size_t |
| 215 | length; |
cristy | 47b838c | 2009-09-19 16:09:30 +0000 | [diff] [blame] | 216 | |
| 217 | unsigned char |
cristy | 8097586 | 2009-09-25 14:34:31 +0000 | [diff] [blame] | 218 | *group4; |
cristy | 47b838c | 2009-09-19 16:09:30 +0000 | [diff] [blame] | 219 | |
cristy | 42751fe | 2009-10-05 00:15:50 +0000 | [diff] [blame] | 220 | status=MagickTrue; |
cristy | 47b838c | 2009-09-19 16:09:30 +0000 | [diff] [blame] | 221 | write_info=CloneImageInfo(image_info); |
cristy | 8097586 | 2009-09-25 14:34:31 +0000 | [diff] [blame] | 222 | (void) CopyMagickString(write_info->filename,"GROUP4:",MaxTextExtent); |
| 223 | (void) CopyMagickString(write_info->magick,"GROUP4",MaxTextExtent); |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 224 | group4_image=CloneImage(inject_image,0,0,MagickTrue,exception); |
cristy | 8097586 | 2009-09-25 14:34:31 +0000 | [diff] [blame] | 225 | if (group4_image == (Image *) NULL) |
| 226 | return(MagickFalse); |
| 227 | group4=(unsigned char *) ImageToBlob(write_info,group4_image,&length, |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 228 | exception); |
cristy | 8097586 | 2009-09-25 14:34:31 +0000 | [diff] [blame] | 229 | group4_image=DestroyImage(group4_image); |
| 230 | if (group4 == (unsigned char *) NULL) |
| 231 | return(MagickFalse); |
cristy | 47b838c | 2009-09-19 16:09:30 +0000 | [diff] [blame] | 232 | write_info=DestroyImageInfo(write_info); |
cristy | 8097586 | 2009-09-25 14:34:31 +0000 | [diff] [blame] | 233 | if (WriteBlob(image,length,group4) != (ssize_t) length) |
| 234 | status=MagickFalse; |
| 235 | group4=(unsigned char *) RelinquishMagickMemory(group4); |
| 236 | return(status); |
cristy | 47b838c | 2009-09-19 16:09:30 +0000 | [diff] [blame] | 237 | } |
cristy | 8097586 | 2009-09-25 14:34:31 +0000 | [diff] [blame] | 238 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 239 | static MagickBooleanType SerializeImage(const ImageInfo *image_info, |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 240 | Image *image,unsigned char **pixels,size_t *length,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 241 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 242 | MagickBooleanType |
| 243 | status; |
| 244 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 245 | register const Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 246 | *p; |
| 247 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 248 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 249 | x; |
| 250 | |
| 251 | register unsigned char |
| 252 | *q; |
| 253 | |
cristy | 802d364 | 2011-04-27 02:02:41 +0000 | [diff] [blame] | 254 | ssize_t |
| 255 | y; |
| 256 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 257 | assert(image != (Image *) NULL); |
| 258 | assert(image->signature == MagickSignature); |
| 259 | if (image->debug != MagickFalse) |
| 260 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 261 | status=MagickTrue; |
cristy | 802d364 | 2011-04-27 02:02:41 +0000 | [diff] [blame] | 262 | *length=(image->colorspace == CMYKColorspace ? 4 : 3)*(size_t) |
| 263 | image->columns*image->rows; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 264 | *pixels=(unsigned char *) AcquireQuantumMemory(*length,sizeof(**pixels)); |
| 265 | if (*pixels == (unsigned char *) NULL) |
| 266 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
| 267 | q=(*pixels); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 268 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 269 | { |
cristy | c82a27b | 2011-10-21 01:07:16 +0000 | [diff] [blame] | 270 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 271 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 272 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 273 | if (image->colorspace != CMYKColorspace) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 274 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 275 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 276 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 277 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 278 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 279 | p+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 280 | } |
| 281 | else |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 282 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 283 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 284 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 285 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 286 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
| 287 | *q++=ScaleQuantumToChar(GetPixelBlack(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 288 | p+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 289 | } |
| 290 | if (image->previous == (Image *) NULL) |
| 291 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 292 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
cristy | 802d364 | 2011-04-27 02:02:41 +0000 | [diff] [blame] | 293 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 294 | if (status == MagickFalse) |
| 295 | break; |
| 296 | } |
| 297 | } |
| 298 | if (status == MagickFalse) |
| 299 | *pixels=(unsigned char *) RelinquishMagickMemory(*pixels); |
| 300 | return(status); |
| 301 | } |
| 302 | |
| 303 | static MagickBooleanType SerializeImageChannel(const ImageInfo *image_info, |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 304 | Image *image,unsigned char **pixels,size_t *length,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 305 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 306 | MagickBooleanType |
| 307 | status; |
| 308 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 309 | register const Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 310 | *p; |
| 311 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 312 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 313 | x; |
| 314 | |
| 315 | register unsigned char |
| 316 | *q; |
| 317 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 318 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 319 | pack, |
| 320 | padded_columns; |
| 321 | |
cristy | 802d364 | 2011-04-27 02:02:41 +0000 | [diff] [blame] | 322 | ssize_t |
| 323 | y; |
| 324 | |
| 325 | unsigned char |
| 326 | code, |
| 327 | bit; |
| 328 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 329 | assert(image != (Image *) NULL); |
| 330 | assert(image->signature == MagickSignature); |
| 331 | if (image->debug != MagickFalse) |
| 332 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 333 | status=MagickTrue; |
cristy | c82a27b | 2011-10-21 01:07:16 +0000 | [diff] [blame] | 334 | pack=IsImageMonochrome(image,exception) == MagickFalse ? 1UL : 8UL; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 335 | padded_columns=((image->columns+pack-1)/pack)*pack; |
| 336 | *length=(size_t) padded_columns*image->rows/pack; |
| 337 | *pixels=(unsigned char *) AcquireQuantumMemory(*length,sizeof(**pixels)); |
| 338 | if (*pixels == (unsigned char *) NULL) |
| 339 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
| 340 | q=(*pixels); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 341 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 342 | { |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 343 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 344 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 345 | break; |
| 346 | if (pack == 1) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 347 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 348 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 349 | *q++=ScaleQuantumToChar(GetPixelIntensity(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 350 | p+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 351 | } |
| 352 | else |
| 353 | { |
| 354 | code='\0'; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 355 | for (x=0; x < (ssize_t) padded_columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 356 | { |
| 357 | bit=(unsigned char) 0x00; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 358 | if (x < (ssize_t) image->columns) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 359 | bit=(unsigned char) (GetPixelIntensity(image,p) == (Quantum) |
| 360 | TransparentAlpha ? 0x01 : 0x00); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 361 | code=(code << 1)+bit; |
| 362 | if (((x+1) % pack) == 0) |
| 363 | { |
| 364 | *q++=code; |
| 365 | code='\0'; |
| 366 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 367 | p+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 368 | } |
| 369 | } |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 370 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
cristy | 802d364 | 2011-04-27 02:02:41 +0000 | [diff] [blame] | 371 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 372 | if (status == MagickFalse) |
| 373 | break; |
| 374 | } |
| 375 | if (status == MagickFalse) |
| 376 | *pixels=(unsigned char *) RelinquishMagickMemory(*pixels); |
| 377 | return(status); |
| 378 | } |
| 379 | |
| 380 | static MagickBooleanType SerializeImageIndexes(const ImageInfo *image_info, |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 381 | Image *image,unsigned char **pixels,size_t *length,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 382 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 383 | MagickBooleanType |
| 384 | status; |
| 385 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 386 | register const Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 387 | *p; |
| 388 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 389 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 390 | x; |
| 391 | |
| 392 | register unsigned char |
| 393 | *q; |
| 394 | |
cristy | 802d364 | 2011-04-27 02:02:41 +0000 | [diff] [blame] | 395 | ssize_t |
| 396 | y; |
| 397 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 398 | assert(image != (Image *) NULL); |
| 399 | assert(image->signature == MagickSignature); |
| 400 | if (image->debug != MagickFalse) |
| 401 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 402 | status=MagickTrue; |
| 403 | *length=(size_t) image->columns*image->rows; |
| 404 | *pixels=(unsigned char *) AcquireQuantumMemory(*length,sizeof(**pixels)); |
| 405 | if (*pixels == (unsigned char *) NULL) |
| 406 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
| 407 | q=(*pixels); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 408 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 409 | { |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 410 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 411 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 412 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 413 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 414 | { |
| 415 | *q++=(unsigned char) GetPixelIndex(image,p); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 416 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 417 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 418 | if (image->previous == (Image *) NULL) |
| 419 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 420 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
cristy | 802d364 | 2011-04-27 02:02:41 +0000 | [diff] [blame] | 421 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 422 | if (status == MagickFalse) |
| 423 | break; |
| 424 | } |
| 425 | } |
| 426 | if (status == MagickFalse) |
| 427 | *pixels=(unsigned char *) RelinquishMagickMemory(*pixels); |
| 428 | return(status); |
| 429 | } |
| 430 | |
| 431 | static MagickBooleanType WritePS3MaskImage(const ImageInfo *image_info, |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 432 | Image *image,const CompressionType compression,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 433 | { |
| 434 | char |
| 435 | buffer[MaxTextExtent]; |
| 436 | |
| 437 | Image |
| 438 | *mask_image; |
| 439 | |
| 440 | MagickBooleanType |
| 441 | status; |
| 442 | |
| 443 | MagickOffsetType |
| 444 | offset, |
| 445 | start, |
| 446 | stop; |
| 447 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 448 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 449 | i; |
| 450 | |
| 451 | size_t |
| 452 | length; |
| 453 | |
| 454 | unsigned char |
| 455 | *pixels; |
| 456 | |
| 457 | assert(image_info != (ImageInfo *) NULL); |
| 458 | assert(image_info->signature == MagickSignature); |
| 459 | assert(image != (Image *) NULL); |
| 460 | assert(image->signature == MagickSignature); |
| 461 | if (image->debug != MagickFalse) |
| 462 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 463 | assert(image->matte != MagickFalse); |
| 464 | status=MagickTrue; |
| 465 | /* |
| 466 | Note BeginData DSC comment for update later. |
| 467 | */ |
| 468 | start=TellBlob(image); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 469 | (void) FormatLocaleString(buffer,MaxTextExtent, |
cristy | 802d364 | 2011-04-27 02:02:41 +0000 | [diff] [blame] | 470 | "%%%%BeginData:%13ld %s Bytes\n",0L,compression == NoCompression ? |
| 471 | "ASCII" : "BINARY"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 472 | (void) WriteBlobString(image,buffer); |
| 473 | stop=TellBlob(image); |
| 474 | /* |
| 475 | Only lossless compressions for the mask. |
| 476 | */ |
| 477 | switch (compression) |
| 478 | { |
| 479 | case NoCompression: |
| 480 | default: |
| 481 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 482 | (void) FormatLocaleString(buffer,MaxTextExtent, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 483 | "currentfile %.20g %.20g "PS3_NoCompression" ByteStreamDecodeFilter\n", |
| 484 | (double) image->columns,(double) image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 485 | break; |
| 486 | } |
| 487 | case FaxCompression: |
| 488 | case Group4Compression: |
| 489 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 490 | (void) FormatLocaleString(buffer,MaxTextExtent, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 491 | "currentfile %.20g %.20g "PS3_FaxCompression" ByteStreamDecodeFilter\n", |
| 492 | (double) image->columns,(double) image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 493 | break; |
| 494 | } |
| 495 | case LZWCompression: |
| 496 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 497 | (void) FormatLocaleString(buffer,MaxTextExtent, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 498 | "currentfile %.20g %.20g "PS3_LZWCompression" ByteStreamDecodeFilter\n", |
| 499 | (double) image->columns,(double) image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 500 | break; |
| 501 | } |
| 502 | case RLECompression: |
| 503 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 504 | (void) FormatLocaleString(buffer,MaxTextExtent, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 505 | "currentfile %.20g %.20g "PS3_RLECompression" ByteStreamDecodeFilter\n", |
| 506 | (double) image->columns,(double) image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 507 | break; |
| 508 | } |
| 509 | case ZipCompression: |
| 510 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 511 | (void) FormatLocaleString(buffer,MaxTextExtent, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 512 | "currentfile %.20g %.20g "PS3_ZipCompression" ByteStreamDecodeFilter\n", |
| 513 | (double) image->columns,(double) image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 514 | break; |
| 515 | } |
| 516 | } |
| 517 | (void) WriteBlobString(image,buffer); |
| 518 | (void) WriteBlobString(image,"/ReusableStreamDecode filter\n"); |
cristy | dbeca02 | 2012-01-11 17:07:34 +0000 | [diff] [blame] | 519 | mask_image=SeparateImage(image,AlphaChannel,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 520 | if (mask_image == (Image *) NULL) |
cristy | c82a27b | 2011-10-21 01:07:16 +0000 | [diff] [blame] | 521 | ThrowWriterException(CoderError,exception->reason); |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 522 | (void) SetImageType(mask_image,BilevelType,exception); |
| 523 | (void) SetImageType(mask_image,PaletteType,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 524 | mask_image->matte=MagickFalse; |
| 525 | pixels=(unsigned char *) NULL; |
| 526 | length=0; |
| 527 | switch (compression) |
| 528 | { |
| 529 | case NoCompression: |
| 530 | default: |
| 531 | { |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 532 | status=SerializeImageChannel(image_info,mask_image,&pixels,&length, |
| 533 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 534 | if (status == MagickFalse) |
| 535 | break; |
| 536 | Ascii85Initialize(image); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 537 | for (i=0; i < (ssize_t) length; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 538 | Ascii85Encode(image,pixels[i]); |
| 539 | Ascii85Flush(image); |
| 540 | pixels=(unsigned char *) RelinquishMagickMemory(pixels); |
| 541 | break; |
| 542 | } |
| 543 | case FaxCompression: |
| 544 | case Group4Compression: |
| 545 | { |
| 546 | if ((compression == FaxCompression) || |
| 547 | (LocaleCompare(CCITTParam,"0") == 0)) |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 548 | status=HuffmanEncodeImage(image_info,image,mask_image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 549 | else |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 550 | status=Huffman2DEncodeImage(image_info,image,mask_image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 551 | break; |
| 552 | } |
| 553 | case LZWCompression: |
| 554 | { |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 555 | status=SerializeImageChannel(image_info,mask_image,&pixels,&length, |
| 556 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 557 | if (status == MagickFalse) |
| 558 | break; |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 559 | status=LZWEncodeImage(image,length,pixels,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 560 | pixels=(unsigned char *) RelinquishMagickMemory(pixels); |
| 561 | break; |
| 562 | } |
| 563 | case RLECompression: |
| 564 | { |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 565 | status=SerializeImageChannel(image_info,mask_image,&pixels,&length, |
| 566 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 567 | if (status == MagickFalse) |
| 568 | break; |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 569 | status=PackbitsEncodeImage(image,length,pixels,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 570 | pixels=(unsigned char *) RelinquishMagickMemory(pixels); |
| 571 | break; |
| 572 | } |
| 573 | case ZipCompression: |
| 574 | { |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 575 | status=SerializeImageChannel(image_info,mask_image,&pixels,&length, |
| 576 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 577 | if (status == MagickFalse) |
| 578 | break; |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 579 | status=ZLIBEncodeImage(image,length,pixels,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 580 | pixels=(unsigned char *) RelinquishMagickMemory(pixels); |
| 581 | break; |
| 582 | } |
| 583 | } |
| 584 | mask_image=DestroyImage(mask_image); |
| 585 | (void) WriteBlobByte(image,'\n'); |
| 586 | length=(size_t) (TellBlob(image)-stop); |
| 587 | stop=TellBlob(image); |
| 588 | offset=SeekBlob(image,start,SEEK_SET); |
| 589 | if (offset < 0) |
| 590 | ThrowWriterException(CorruptImageError,"ImproperImageHeader"); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 591 | (void) FormatLocaleString(buffer,MaxTextExtent, |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 592 | "%%%%BeginData:%13ld %s Bytes\n",(long) length, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 593 | compression == NoCompression ? "ASCII" : "BINARY"); |
| 594 | (void) WriteBlobString(image,buffer); |
| 595 | offset=SeekBlob(image,stop,SEEK_SET); |
| 596 | if (offset < 0) |
| 597 | ThrowWriterException(CorruptImageError,"ImproperImageHeader"); |
| 598 | (void) WriteBlobString(image,"%%EndData\n"); |
| 599 | (void) WriteBlobString(image, "/mask_stream exch def\n"); |
| 600 | return(status); |
| 601 | } |
| 602 | |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 603 | static MagickBooleanType WritePS3Image(const ImageInfo *image_info,Image *image, |
| 604 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 605 | { |
| 606 | static const char |
| 607 | *PostscriptProlog[]= |
| 608 | { |
| 609 | "/ByteStreamDecodeFilter", |
| 610 | "{", |
| 611 | " /z exch def", |
| 612 | " /r exch def", |
| 613 | " /c exch def", |
| 614 | " z "PS3_NoCompression" eq { /ASCII85Decode filter } if", |
| 615 | " z "PS3_FaxCompression" eq", |
| 616 | " {", |
| 617 | " <<", |
| 618 | " /K "CCITTParam, |
| 619 | " /Columns c", |
| 620 | " /Rows r", |
| 621 | " >>", |
| 622 | " /CCITTFaxDecode filter", |
| 623 | " } if", |
| 624 | " z "PS3_JPEGCompression" eq { /DCTDecode filter } if", |
| 625 | " z "PS3_LZWCompression" eq { /LZWDecode filter } if", |
| 626 | " z "PS3_RLECompression" eq { /RunLengthDecode filter } if", |
| 627 | " z "PS3_ZipCompression" eq { /FlateDecode filter } if", |
| 628 | "} bind def", |
| 629 | "", |
| 630 | "/DirectClassImageDict", |
| 631 | "{", |
| 632 | " colorspace "PS3_RGBColorspace" eq", |
| 633 | " {", |
| 634 | " /DeviceRGB setcolorspace", |
| 635 | " <<", |
| 636 | " /ImageType 1", |
| 637 | " /Width columns", |
| 638 | " /Height rows", |
| 639 | " /BitsPerComponent 8", |
| 640 | " /DataSource pixel_stream", |
| 641 | " /MultipleDataSources false", |
| 642 | " /ImageMatrix [columns 0 0 rows neg 0 rows]", |
| 643 | " /Decode [0 1 0 1 0 1]", |
| 644 | " >>", |
| 645 | " }", |
| 646 | " {", |
| 647 | " /DeviceCMYK setcolorspace", |
| 648 | " <<", |
| 649 | " /ImageType 1", |
| 650 | " /Width columns", |
| 651 | " /Height rows", |
| 652 | " /BitsPerComponent 8", |
| 653 | " /DataSource pixel_stream", |
| 654 | " /MultipleDataSources false", |
| 655 | " /ImageMatrix [columns 0 0 rows neg 0 rows]", |
| 656 | " /Decode", |
| 657 | " compression "PS3_JPEGCompression" eq", |
| 658 | " { [1 0 1 0 1 0 1 0] }", |
| 659 | " { [0 1 0 1 0 1 0 1] }", |
| 660 | " ifelse", |
| 661 | " >>", |
| 662 | " }", |
| 663 | " ifelse", |
| 664 | "} bind def", |
| 665 | "", |
| 666 | "/PseudoClassImageDict", |
| 667 | "{", |
| 668 | " % Colors in colormap image.", |
| 669 | " currentfile buffer readline pop", |
| 670 | " token pop /colors exch def pop", |
| 671 | " colors 0 eq", |
| 672 | " {", |
| 673 | " % Depth of grayscale image.", |
| 674 | " currentfile buffer readline pop", |
| 675 | " token pop /bits exch def pop", |
| 676 | " /DeviceGray setcolorspace", |
| 677 | " <<", |
| 678 | " /ImageType 1", |
| 679 | " /Width columns", |
| 680 | " /Height rows", |
| 681 | " /BitsPerComponent bits", |
| 682 | " /Decode [0 1]", |
| 683 | " /ImageMatrix [columns 0 0 rows neg 0 rows]", |
| 684 | " /DataSource pixel_stream", |
| 685 | " >>", |
| 686 | " }", |
| 687 | " {", |
| 688 | " % RGB colormap.", |
| 689 | " /colormap colors 3 mul string def", |
| 690 | " compression "PS3_NoCompression" eq", |
| 691 | " { currentfile /ASCII85Decode filter colormap readstring pop pop }", |
| 692 | " { currentfile colormap readstring pop pop }", |
| 693 | " ifelse", |
| 694 | " [ /Indexed /DeviceRGB colors 1 sub colormap ] setcolorspace", |
| 695 | " <<", |
| 696 | " /ImageType 1", |
| 697 | " /Width columns", |
| 698 | " /Height rows", |
| 699 | " /BitsPerComponent 8", |
| 700 | " /Decode [0 255]", |
| 701 | " /ImageMatrix [columns 0 0 rows neg 0 rows]", |
| 702 | " /DataSource pixel_stream", |
| 703 | " >>", |
| 704 | " }", |
| 705 | " ifelse", |
| 706 | "} bind def", |
| 707 | "", |
| 708 | "/NonMaskedImageDict", |
| 709 | "{", |
| 710 | " class "PS3_PseudoClass" eq", |
| 711 | " { PseudoClassImageDict }", |
| 712 | " { DirectClassImageDict }", |
| 713 | " ifelse", |
| 714 | "} bind def", |
| 715 | "", |
| 716 | "/MaskedImageDict", |
| 717 | "{", |
| 718 | " <<", |
| 719 | " /ImageType 3", |
| 720 | " /InterleaveType 3", |
| 721 | " /DataDict NonMaskedImageDict", |
| 722 | " /MaskDict", |
| 723 | " <<", |
| 724 | " /ImageType 1", |
| 725 | " /Width columns", |
| 726 | " /Height rows", |
| 727 | " /BitsPerComponent 1", |
| 728 | " /DataSource mask_stream", |
| 729 | " /MultipleDataSources false", |
| 730 | " /ImageMatrix [ columns 0 0 rows neg 0 rows]", |
| 731 | " /Decode [ 0 1 ]", |
| 732 | " >>", |
| 733 | " >>", |
| 734 | "} bind def", |
| 735 | "", |
| 736 | "/ClipImage", |
| 737 | "{} def", |
| 738 | "", |
| 739 | "/DisplayImage", |
| 740 | "{", |
| 741 | " /buffer 512 string def", |
| 742 | " % Translation.", |
| 743 | " currentfile buffer readline pop", |
| 744 | " token pop /x exch def", |
| 745 | " token pop /y exch def pop", |
| 746 | " x y translate", |
| 747 | " % Image size and font size.", |
| 748 | " currentfile buffer readline pop", |
| 749 | " token pop /x exch def", |
| 750 | " token pop /y exch def pop", |
| 751 | " currentfile buffer readline pop", |
| 752 | " token pop /pointsize exch def pop", |
| 753 | (char *) NULL |
| 754 | }, |
| 755 | *PostscriptEpilog[]= |
| 756 | { |
| 757 | " x y scale", |
| 758 | " % Clipping path.", |
| 759 | " currentfile buffer readline pop", |
| 760 | " token pop /clipped exch def pop", |
| 761 | " % Showpage.", |
| 762 | " currentfile buffer readline pop", |
| 763 | " token pop /sp exch def pop", |
| 764 | " % Image pixel size.", |
| 765 | " currentfile buffer readline pop", |
| 766 | " token pop /columns exch def", |
| 767 | " token pop /rows exch def pop", |
| 768 | " % Colorspace (RGB/CMYK).", |
| 769 | " currentfile buffer readline pop", |
| 770 | " token pop /colorspace exch def pop", |
| 771 | " % Transparency.", |
| 772 | " currentfile buffer readline pop", |
| 773 | " token pop /alpha exch def pop", |
| 774 | " % Stencil mask?", |
| 775 | " currentfile buffer readline pop", |
| 776 | " token pop /stencil exch def pop", |
| 777 | " % Image class (direct/pseudo).", |
| 778 | " currentfile buffer readline pop", |
| 779 | " token pop /class exch def pop", |
| 780 | " % Compression type.", |
| 781 | " currentfile buffer readline pop", |
| 782 | " token pop /compression exch def pop", |
| 783 | " % Clip and render.", |
| 784 | " /pixel_stream currentfile columns rows compression ByteStreamDecodeFilter def", |
| 785 | " clipped { ClipImage } if", |
| 786 | " alpha stencil not and", |
| 787 | " { MaskedImageDict mask_stream resetfile }", |
| 788 | " { NonMaskedImageDict }", |
| 789 | " ifelse", |
| 790 | " stencil { 0 setgray imagemask } { image } ifelse", |
| 791 | " sp { showpage } if", |
| 792 | "} bind def", |
| 793 | (char *) NULL |
| 794 | }; |
| 795 | |
| 796 | char |
| 797 | buffer[MaxTextExtent], |
| 798 | date[MaxTextExtent], |
| 799 | **labels, |
| 800 | page_geometry[MaxTextExtent]; |
| 801 | |
| 802 | CompressionType |
| 803 | compression; |
| 804 | |
| 805 | const char |
| 806 | *option, |
| 807 | **q, |
| 808 | *value; |
| 809 | |
| 810 | double |
| 811 | pointsize; |
| 812 | |
| 813 | GeometryInfo |
| 814 | geometry_info; |
| 815 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 816 | MagickBooleanType |
| 817 | status; |
| 818 | |
| 819 | MagickOffsetType |
| 820 | offset, |
| 821 | scene, |
| 822 | start, |
| 823 | stop; |
| 824 | |
| 825 | MagickStatusType |
| 826 | flags; |
| 827 | |
| 828 | PointInfo |
| 829 | delta, |
| 830 | resolution, |
| 831 | scale; |
| 832 | |
| 833 | RectangleInfo |
| 834 | geometry, |
| 835 | media_info, |
| 836 | page_info; |
| 837 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 838 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 839 | i; |
| 840 | |
| 841 | SegmentInfo |
| 842 | bounds; |
| 843 | |
| 844 | size_t |
cristy | 802d364 | 2011-04-27 02:02:41 +0000 | [diff] [blame] | 845 | length, |
| 846 | page, |
| 847 | pixel, |
| 848 | text_size; |
| 849 | |
| 850 | ssize_t |
| 851 | j; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 852 | |
| 853 | time_t |
| 854 | timer; |
| 855 | |
| 856 | unsigned char |
| 857 | *pixels; |
| 858 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 859 | /* |
| 860 | Open output image file. |
| 861 | */ |
| 862 | assert(image_info != (const ImageInfo *) NULL); |
| 863 | assert(image_info->signature == MagickSignature); |
| 864 | assert(image != (Image *) NULL); |
| 865 | assert(image->signature == MagickSignature); |
| 866 | if (image->debug != MagickFalse) |
| 867 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 868 | assert(exception != (ExceptionInfo *) NULL); |
| 869 | assert(exception->signature == MagickSignature); |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 870 | status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 871 | if (status == MagickFalse) |
| 872 | return(MagickFalse); |
| 873 | compression=image->compression; |
| 874 | if (image_info->compression != UndefinedCompression) |
| 875 | compression=image_info->compression; |
| 876 | switch (compression) |
| 877 | { |
| 878 | case FaxCompression: |
| 879 | case Group4Compression: |
| 880 | { |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 881 | if ((IsImageMonochrome(image,exception) == MagickFalse) || |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 882 | (image->matte != MagickFalse)) |
| 883 | compression=RLECompression; |
| 884 | break; |
| 885 | } |
| 886 | #if !defined(MAGICKCORE_JPEG_DELEGATE) |
| 887 | case JPEGCompression: |
| 888 | { |
| 889 | compression=RLECompression; |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 890 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 891 | MissingDelegateError,"DelegateLibrarySupportNotBuiltIn","`%s' (JPEG)", |
| 892 | image->filename); |
| 893 | break; |
| 894 | } |
| 895 | #endif |
| 896 | #if !defined(MAGICKCORE_ZLIB_DELEGATE) |
| 897 | case ZipCompression: |
| 898 | { |
| 899 | compression=RLECompression; |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 900 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 901 | MissingDelegateError,"DelegateLibrarySupportNotBuiltIn","`%s' (ZLIB)", |
| 902 | image->filename); |
| 903 | break; |
| 904 | } |
| 905 | #endif |
| 906 | default: |
| 907 | break; |
| 908 | } |
| 909 | (void) ResetMagickMemory(&bounds,0,sizeof(bounds)); |
| 910 | page=0; |
| 911 | scene=0; |
| 912 | do |
| 913 | { |
| 914 | /* |
| 915 | Scale relative to dots-per-inch. |
| 916 | */ |
| 917 | delta.x=DefaultResolution; |
| 918 | delta.y=DefaultResolution; |
cristy | 2a11bef | 2011-10-28 18:33:11 +0000 | [diff] [blame] | 919 | resolution.x=image->resolution.x; |
| 920 | resolution.y=image->resolution.y; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 921 | if ((resolution.x == 0.0) || (resolution.y == 0.0)) |
| 922 | { |
| 923 | flags=ParseGeometry(PSDensityGeometry,&geometry_info); |
| 924 | resolution.x=geometry_info.rho; |
| 925 | resolution.y=geometry_info.sigma; |
| 926 | if ((flags & SigmaValue) == 0) |
| 927 | resolution.y=resolution.x; |
| 928 | } |
| 929 | if (image_info->density != (char *) NULL) |
| 930 | { |
| 931 | flags=ParseGeometry(image_info->density,&geometry_info); |
| 932 | resolution.x=geometry_info.rho; |
| 933 | resolution.y=geometry_info.sigma; |
| 934 | if ((flags & SigmaValue) == 0) |
| 935 | resolution.y=resolution.x; |
| 936 | } |
| 937 | if (image->units == PixelsPerCentimeterResolution) |
| 938 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 939 | resolution.x=(size_t) (100.0*2.54*resolution.x+0.5)/100.0; |
| 940 | 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] | 941 | } |
| 942 | SetGeometry(image,&geometry); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 943 | (void) FormatLocaleString(page_geometry,MaxTextExtent,"%.20gx%.20g", |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 944 | (double) image->columns,(double) image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 945 | if (image_info->page != (char *) NULL) |
| 946 | (void) CopyMagickString(page_geometry,image_info->page,MaxTextExtent); |
| 947 | else |
| 948 | if ((image->page.width != 0) && (image->page.height != 0)) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 949 | (void) FormatLocaleString(page_geometry,MaxTextExtent, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 950 | "%.20gx%.20g%+.20g%+.20g",(double) image->page.width,(double) |
| 951 | image->page.height,(double) image->page.x,(double) image->page.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 952 | else |
| 953 | if ((image->gravity != UndefinedGravity) && |
| 954 | (LocaleCompare(image_info->magick,"PS") == 0)) |
| 955 | (void) CopyMagickString(page_geometry,PSPageGeometry,MaxTextExtent); |
| 956 | (void) ConcatenateMagickString(page_geometry,">",MaxTextExtent); |
| 957 | (void) ParseMetaGeometry(page_geometry,&geometry.x,&geometry.y, |
| 958 | &geometry.width,&geometry.height); |
| 959 | scale.x=(double) (geometry.width*delta.x)/resolution.x; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 960 | geometry.width=(size_t) floor(scale.x+0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 961 | scale.y=(double) (geometry.height*delta.y)/resolution.y; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 962 | geometry.height=(size_t) floor(scale.y+0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 963 | (void) ParseAbsoluteGeometry(page_geometry,&media_info); |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 964 | (void) ParseGravityGeometry(image,page_geometry,&page_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 965 | if (image->gravity != UndefinedGravity) |
| 966 | { |
| 967 | geometry.x=(-page_info.x); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 968 | geometry.y=(ssize_t) (media_info.height+page_info.y-image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 969 | } |
| 970 | pointsize=12.0; |
| 971 | if (image_info->pointsize != 0.0) |
| 972 | pointsize=image_info->pointsize; |
| 973 | text_size=0; |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 974 | value=GetImageProperty(image,"label",exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 975 | if (value != (const char *) NULL) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 976 | text_size=(size_t) (MultilineCensus(value)*pointsize+12); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 977 | page++; |
| 978 | if (page == 1) |
| 979 | { |
| 980 | /* |
| 981 | Postscript header on the first page. |
| 982 | */ |
| 983 | if (LocaleCompare(image_info->magick,"PS3") == 0) |
| 984 | (void) CopyMagickString(buffer,"%!PS-Adobe-3.0\n",MaxTextExtent); |
| 985 | else |
| 986 | (void) CopyMagickString(buffer,"%!PS-Adobe-3.0 EPSF-3.0\n", |
| 987 | MaxTextExtent); |
| 988 | (void) WriteBlobString(image,buffer); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 989 | (void) FormatLocaleString(buffer,MaxTextExtent, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 990 | "%%%%Creator: ImageMagick %s\n",MagickLibVersionText); |
| 991 | (void) WriteBlobString(image,buffer); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 992 | (void) FormatLocaleString(buffer,MaxTextExtent,"%%%%Title: %s\n", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 993 | image->filename); |
| 994 | (void) WriteBlobString(image,buffer); |
| 995 | timer=time((time_t *) NULL); |
| 996 | (void) FormatMagickTime(timer,MaxTextExtent,date); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 997 | (void) FormatLocaleString(buffer,MaxTextExtent, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 998 | "%%%%CreationDate: %s\n",date); |
| 999 | (void) WriteBlobString(image,buffer); |
| 1000 | bounds.x1=(double) geometry.x; |
| 1001 | bounds.y1=(double) geometry.y; |
| 1002 | bounds.x2=(double) geometry.x+scale.x; |
| 1003 | bounds.y2=(double) geometry.y+scale.y+text_size; |
| 1004 | if ((image_info->adjoin != MagickFalse) && |
| 1005 | (GetNextImageInList(image) != (Image *) NULL)) |
| 1006 | { |
| 1007 | (void) WriteBlobString(image,"%%BoundingBox: (atend)\n"); |
| 1008 | (void) WriteBlobString(image,"%%HiResBoundingBox: (atend)\n"); |
| 1009 | } |
| 1010 | else |
| 1011 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1012 | (void) FormatLocaleString(buffer,MaxTextExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 1013 | "%%%%BoundingBox: %g %g %g %g\n",floor(bounds.x1+0.5), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1014 | floor(bounds.y1+0.5),ceil(bounds.x2-0.5),ceil(bounds.y2-0.5)); |
| 1015 | (void) WriteBlobString(image,buffer); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1016 | (void) FormatLocaleString(buffer,MaxTextExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 1017 | "%%%%HiResBoundingBox: %g %g %g %g\n",bounds.x1, |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 1018 | bounds.y1,bounds.x2,bounds.y2); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1019 | (void) WriteBlobString(image,buffer); |
| 1020 | if (image->colorspace == CMYKColorspace) |
| 1021 | (void) WriteBlobString(image, |
| 1022 | "%%DocumentProcessColors: Cyan Magenta Yellow Black\n"); |
| 1023 | else |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1024 | if (IsImageGray(image,exception) != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1025 | (void) WriteBlobString(image, |
| 1026 | "%%DocumentProcessColors: Black\n"); |
| 1027 | } |
| 1028 | /* |
| 1029 | Font resources |
| 1030 | */ |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 1031 | value=GetImageProperty(image,"label",exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1032 | if (value != (const char *) NULL) |
| 1033 | (void) WriteBlobString(image, |
| 1034 | "%%DocumentNeededResources: font Helvetica\n"); |
| 1035 | (void) WriteBlobString(image,"%%LanguageLevel: 3\n"); |
| 1036 | /* |
| 1037 | Pages, orientation and order. |
| 1038 | */ |
| 1039 | if (LocaleCompare(image_info->magick,"PS3") != 0) |
| 1040 | (void) WriteBlobString(image,"%%Pages: 1\n"); |
| 1041 | else |
| 1042 | { |
| 1043 | (void) WriteBlobString(image,"%%Orientation: Portrait\n"); |
| 1044 | (void) WriteBlobString(image,"%%PageOrder: Ascend\n"); |
| 1045 | if (image_info->adjoin == MagickFalse) |
| 1046 | (void) CopyMagickString(buffer,"%%Pages: 1\n",MaxTextExtent); |
| 1047 | else |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1048 | (void) FormatLocaleString(buffer,MaxTextExtent, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 1049 | "%%%%Pages: %.20g\n",(double) GetImageListLength(image)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1050 | (void) WriteBlobString(image,buffer); |
| 1051 | } |
| 1052 | (void) WriteBlobString(image,"%%EndComments\n"); |
| 1053 | /* |
| 1054 | The static postscript procedures prolog. |
| 1055 | */ |
| 1056 | (void)WriteBlobString(image,"%%BeginProlog\n"); |
| 1057 | for (q=PostscriptProlog; *q; q++) |
| 1058 | { |
| 1059 | (void) WriteBlobString(image,*q); |
| 1060 | (void) WriteBlobByte(image,'\n'); |
| 1061 | } |
| 1062 | /* |
| 1063 | One label line for each line in label string. |
| 1064 | */ |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 1065 | value=GetImageProperty(image,"label",exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1066 | if (value != (const char *) NULL) |
| 1067 | { |
| 1068 | (void) WriteBlobString(image,"\n %% Labels.\n /Helvetica " |
| 1069 | " findfont pointsize scalefont setfont\n"); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1070 | for (i=(ssize_t) MultilineCensus(value)-1; i >= 0; i--) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1071 | { |
| 1072 | (void) WriteBlobString(image, |
| 1073 | " currentfile buffer readline pop token pop\n"); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1074 | (void) FormatLocaleString(buffer,MaxTextExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 1075 | " 0 y %g add moveto show pop\n",i*pointsize+12); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1076 | (void) WriteBlobString(image,buffer); |
| 1077 | } |
| 1078 | } |
| 1079 | /* |
| 1080 | The static postscript procedures epilog. |
| 1081 | */ |
| 1082 | for (q=PostscriptEpilog; *q; q++) |
| 1083 | { |
| 1084 | (void) WriteBlobString(image,*q); |
| 1085 | (void) WriteBlobByte(image,'\n'); |
| 1086 | } |
| 1087 | (void)WriteBlobString(image,"%%EndProlog\n"); |
| 1088 | } |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1089 | (void) FormatLocaleString(buffer,MaxTextExtent,"%%%%Page: 1 %.20g\n", |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 1090 | (double) page); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1091 | (void) WriteBlobString(image,buffer); |
| 1092 | /* |
| 1093 | Page bounding box. |
| 1094 | */ |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1095 | (void) FormatLocaleString(buffer,MaxTextExtent, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 1096 | "%%%%PageBoundingBox: %.20g %.20g %.20g %.20g\n",(double) geometry.x, |
| 1097 | (double) geometry.y,geometry.x+(double) geometry.width,geometry.y+ |
| 1098 | (double) (geometry.height+text_size)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1099 | (void) WriteBlobString(image,buffer); |
| 1100 | /* |
| 1101 | Page process colors if not RGB. |
| 1102 | */ |
| 1103 | if (image->colorspace == CMYKColorspace) |
| 1104 | (void) WriteBlobString(image, |
| 1105 | "%%PageProcessColors: Cyan Magenta Yellow Black\n"); |
| 1106 | else |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1107 | if (IsImageGray(image,exception) != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1108 | (void) WriteBlobString(image,"%%PageProcessColors: Black\n"); |
| 1109 | /* |
| 1110 | Adjust document bounding box to bound page bounding box. |
| 1111 | */ |
| 1112 | if ((double) geometry.x < bounds.x1) |
| 1113 | bounds.x1=(double) geometry.x; |
| 1114 | if ((double) geometry.y < bounds.y1) |
| 1115 | bounds.y1=(double) geometry.y; |
| 1116 | if ((double) (geometry.x+scale.x) > bounds.x2) |
| 1117 | bounds.x2=(double) geometry.x+scale.x; |
| 1118 | if ((double) (geometry.y+scale.y+text_size) > bounds.y2) |
| 1119 | bounds.y2=(double) geometry.y+scale.y+text_size; |
| 1120 | /* |
| 1121 | Page font resource if there's a label. |
| 1122 | */ |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 1123 | value=GetImageProperty(image,"label",exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1124 | if (value != (const char *) NULL) |
| 1125 | (void) WriteBlobString(image,"%%PageResources: font Helvetica\n"); |
| 1126 | /* |
| 1127 | PS clipping path from Photoshop clipping path. |
| 1128 | */ |
cristy | 183a5c7 | 2012-01-30 01:40:35 +0000 | [diff] [blame] | 1129 | if ((image->mask != MagickFalse) || |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 1130 | (LocaleNCompare("8BIM:",image->magick_filename,5) != 0)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1131 | (void) WriteBlobString(image,"/ClipImage {} def\n"); |
| 1132 | else |
| 1133 | { |
| 1134 | const char |
| 1135 | *value; |
| 1136 | |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 1137 | value=GetImageProperty(image,image->magick_filename,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1138 | if (value == (const char *) NULL) |
| 1139 | return(MagickFalse); |
| 1140 | (void) WriteBlobString(image,value); |
| 1141 | (void) WriteBlobByte(image,'\n'); |
| 1142 | } |
| 1143 | /* |
| 1144 | Push a dictionary for our own def's if this an EPS. |
| 1145 | */ |
| 1146 | if (LocaleCompare(image_info->magick,"PS3") != 0) |
| 1147 | (void) WriteBlobString(image,"userdict begin\n"); |
| 1148 | /* |
| 1149 | Image mask. |
| 1150 | */ |
| 1151 | if ((image->matte != MagickFalse) && |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1152 | (WritePS3MaskImage(image_info,image,compression,exception) == MagickFalse)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1153 | { |
| 1154 | (void) CloseBlob(image); |
| 1155 | return(MagickFalse); |
| 1156 | } |
| 1157 | /* |
| 1158 | Remember position of BeginData comment so we can update it. |
| 1159 | */ |
| 1160 | start=TellBlob(image); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1161 | (void) FormatLocaleString(buffer,MaxTextExtent, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1162 | "%%%%BeginData:%13ld %s Bytes\n",0L, |
| 1163 | compression == NoCompression ? "ASCII" : "BINARY"); |
| 1164 | (void) WriteBlobString(image,buffer); |
| 1165 | stop=TellBlob(image); |
| 1166 | (void) WriteBlobString(image,"DisplayImage\n"); |
| 1167 | /* |
| 1168 | Translate, scale, and font point size. |
| 1169 | */ |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1170 | (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g %.20g\n%g %g\n%g\n", |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 1171 | (double) geometry.x,(double) geometry.y,scale.x,scale.y,pointsize); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1172 | (void) WriteBlobString(image,buffer); |
| 1173 | /* |
| 1174 | Output labels. |
| 1175 | */ |
| 1176 | labels=(char **) NULL; |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 1177 | value=GetImageProperty(image,"label",exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1178 | if (value != (const char *) NULL) |
| 1179 | labels=StringToList(value); |
| 1180 | if (labels != (char **) NULL) |
| 1181 | { |
| 1182 | for (i=0; labels[i] != (char *) NULL; i++) |
| 1183 | { |
| 1184 | if (compression != NoCompression) |
| 1185 | { |
| 1186 | for (j=0; labels[i][j] != '\0'; j++) |
| 1187 | (void) WriteBlobByte(image,(unsigned char) labels[i][j]); |
| 1188 | (void) WriteBlobByte(image,'\n'); |
| 1189 | } |
| 1190 | else |
| 1191 | { |
| 1192 | (void) WriteBlobString(image,"<~"); |
| 1193 | Ascii85Initialize(image); |
| 1194 | for (j=0; labels[i][j] != '\0'; j++) |
| 1195 | Ascii85Encode(image,(unsigned char) labels[i][j]); |
| 1196 | Ascii85Flush(image); |
| 1197 | } |
| 1198 | labels[i]=DestroyString(labels[i]); |
| 1199 | } |
| 1200 | labels=(char **) RelinquishMagickMemory(labels); |
| 1201 | } |
| 1202 | /* |
| 1203 | Photoshop clipping path active? |
| 1204 | */ |
cristy | 183a5c7 | 2012-01-30 01:40:35 +0000 | [diff] [blame] | 1205 | if ((image->mask != MagickFalse) && |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 1206 | (LocaleNCompare("8BIM:",image->magick_filename,5) == 0)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1207 | (void) WriteBlobString(image,"true\n"); |
| 1208 | else |
| 1209 | (void) WriteBlobString(image,"false\n"); |
| 1210 | /* |
| 1211 | Showpage for non-EPS. |
| 1212 | */ |
| 1213 | (void) WriteBlobString(image, LocaleCompare(image_info->magick,"PS3") == 0 ? |
| 1214 | "true\n" : "false\n"); |
| 1215 | /* |
| 1216 | Image columns, rows, and color space. |
| 1217 | */ |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1218 | (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g %.20g\n%s\n", |
cristy | 802d364 | 2011-04-27 02:02:41 +0000 | [diff] [blame] | 1219 | (double) image->columns,(double) image->rows,image->colorspace == |
| 1220 | CMYKColorspace ? PS3_CMYKColorspace : PS3_RGBColorspace); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1221 | (void) WriteBlobString(image,buffer); |
| 1222 | /* |
| 1223 | Masked image? |
| 1224 | */ |
| 1225 | (void) WriteBlobString(image,image->matte != MagickFalse ? |
| 1226 | "true\n" : "false\n"); |
| 1227 | /* |
| 1228 | Render with imagemask operator? |
| 1229 | */ |
| 1230 | option=GetImageOption(image_info,"ps3:imagemask"); |
| 1231 | (void) WriteBlobString(image,((option != (const char *) NULL) && |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1232 | (IsImageMonochrome(image,exception) != MagickFalse)) ? |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1233 | "true\n" : "false\n"); |
| 1234 | /* |
| 1235 | Output pixel data. |
| 1236 | */ |
| 1237 | pixels=(unsigned char *) NULL; |
| 1238 | length=0; |
| 1239 | if ((image_info->type != TrueColorType) && |
| 1240 | (image_info->type != TrueColorMatteType) && |
| 1241 | (image_info->type != ColorSeparationType) && |
| 1242 | (image_info->type != ColorSeparationMatteType) && |
| 1243 | (image->colorspace != CMYKColorspace) && |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1244 | ((IsImageGray(image,exception) != MagickFalse) || |
| 1245 | (IsImageMonochrome(image,exception) != MagickFalse))) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1246 | { |
| 1247 | /* |
| 1248 | Gray images. |
| 1249 | */ |
| 1250 | (void) WriteBlobString(image,PS3_PseudoClass"\n"); |
| 1251 | switch (compression) |
| 1252 | { |
| 1253 | case NoCompression: |
| 1254 | default: |
| 1255 | { |
| 1256 | (void) WriteBlobString(image,PS3_NoCompression"\n"); |
| 1257 | break; |
| 1258 | } |
| 1259 | case FaxCompression: |
| 1260 | case Group4Compression: |
| 1261 | { |
| 1262 | (void) WriteBlobString(image,PS3_FaxCompression"\n"); |
| 1263 | break; |
| 1264 | } |
| 1265 | case JPEGCompression: |
| 1266 | { |
| 1267 | (void) WriteBlobString(image,PS3_JPEGCompression"\n"); |
| 1268 | break; |
| 1269 | } |
| 1270 | case LZWCompression: |
| 1271 | { |
| 1272 | (void) WriteBlobString(image,PS3_LZWCompression"\n"); |
| 1273 | break; |
| 1274 | } |
| 1275 | case RLECompression: |
| 1276 | { |
| 1277 | (void) WriteBlobString(image,PS3_RLECompression"\n"); |
| 1278 | break; |
| 1279 | } |
| 1280 | case ZipCompression: |
| 1281 | { |
| 1282 | (void) WriteBlobString(image,PS3_ZipCompression"\n"); |
| 1283 | break; |
| 1284 | } |
| 1285 | } |
| 1286 | /* |
| 1287 | Number of colors -- 0 for single component non-color mapped data. |
| 1288 | */ |
| 1289 | (void) WriteBlobString(image,"0\n"); |
| 1290 | /* |
| 1291 | 1 bit or 8 bit components? |
| 1292 | */ |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1293 | (void) FormatLocaleString(buffer,MaxTextExtent,"%d\n", |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1294 | IsImageMonochrome(image,exception) != MagickFalse ? 1 : 8); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1295 | (void) WriteBlobString(image,buffer); |
| 1296 | /* |
| 1297 | Image data. |
| 1298 | */ |
| 1299 | if (compression == JPEGCompression) |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1300 | status=InjectImageBlob(image_info,image,image,"jpeg",exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1301 | else |
| 1302 | if ((compression == FaxCompression) || |
| 1303 | (compression == Group4Compression)) |
| 1304 | { |
| 1305 | if (LocaleCompare(CCITTParam,"0") == 0) |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1306 | status=HuffmanEncodeImage(image_info,image,image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1307 | else |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1308 | status=Huffman2DEncodeImage(image_info,image,image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1309 | } |
| 1310 | else |
| 1311 | { |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1312 | status=SerializeImageChannel(image_info,image,&pixels,&length, |
| 1313 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1314 | if (status == MagickFalse) |
| 1315 | { |
| 1316 | (void) CloseBlob(image); |
| 1317 | return(MagickFalse); |
| 1318 | } |
| 1319 | switch (compression) |
| 1320 | { |
| 1321 | case NoCompression: |
| 1322 | default: |
| 1323 | { |
| 1324 | Ascii85Initialize(image); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1325 | for (i=0; i < (ssize_t) length; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1326 | Ascii85Encode(image,pixels[i]); |
| 1327 | Ascii85Flush(image); |
| 1328 | status=MagickTrue; |
| 1329 | break; |
| 1330 | } |
| 1331 | case LZWCompression: |
| 1332 | { |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1333 | status=LZWEncodeImage(image,length,pixels,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1334 | break; |
| 1335 | } |
| 1336 | case RLECompression: |
| 1337 | { |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1338 | status=PackbitsEncodeImage(image,length,pixels,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1339 | break; |
| 1340 | } |
| 1341 | case ZipCompression: |
| 1342 | { |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1343 | status=ZLIBEncodeImage(image,length,pixels,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1344 | break; |
| 1345 | } |
| 1346 | } |
| 1347 | pixels=(unsigned char *) RelinquishMagickMemory(pixels); |
| 1348 | } |
| 1349 | } |
| 1350 | else |
| 1351 | if ((image->storage_class == DirectClass) || (image->colors > 256) || |
| 1352 | (compression == JPEGCompression)) |
| 1353 | { |
| 1354 | /* |
| 1355 | Truecolor image. |
| 1356 | */ |
| 1357 | (void) WriteBlobString(image,PS3_DirectClass"\n"); |
| 1358 | switch (compression) |
| 1359 | { |
| 1360 | case NoCompression: |
| 1361 | default: |
| 1362 | { |
| 1363 | (void) WriteBlobString(image,PS3_NoCompression"\n"); |
| 1364 | break; |
| 1365 | } |
| 1366 | case RLECompression: |
| 1367 | { |
| 1368 | (void) WriteBlobString(image,PS3_RLECompression"\n"); |
| 1369 | break; |
| 1370 | } |
| 1371 | case JPEGCompression: |
| 1372 | { |
| 1373 | (void) WriteBlobString(image,PS3_JPEGCompression"\n"); |
| 1374 | break; |
| 1375 | } |
| 1376 | case LZWCompression: |
| 1377 | { |
| 1378 | (void) WriteBlobString(image,PS3_LZWCompression"\n"); |
| 1379 | break; |
| 1380 | } |
| 1381 | case ZipCompression: |
| 1382 | { |
| 1383 | (void) WriteBlobString(image,PS3_ZipCompression"\n"); |
| 1384 | break; |
| 1385 | } |
| 1386 | } |
| 1387 | /* |
| 1388 | Image data. |
| 1389 | */ |
| 1390 | if (compression == JPEGCompression) |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1391 | status=InjectImageBlob(image_info,image,image,"jpeg",exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1392 | else |
| 1393 | { |
| 1394 | /* |
| 1395 | Stream based compressions. |
| 1396 | */ |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1397 | status=SerializeImage(image_info,image,&pixels,&length,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1398 | if (status == MagickFalse) |
| 1399 | { |
| 1400 | (void) CloseBlob(image); |
| 1401 | return(MagickFalse); |
| 1402 | } |
| 1403 | switch (compression) |
| 1404 | { |
| 1405 | case NoCompression: |
| 1406 | default: |
| 1407 | { |
| 1408 | Ascii85Initialize(image); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1409 | for (i=0; i < (ssize_t) length; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1410 | Ascii85Encode(image,pixels[i]); |
| 1411 | Ascii85Flush(image); |
| 1412 | status=MagickTrue; |
| 1413 | break; |
| 1414 | } |
| 1415 | case RLECompression: |
| 1416 | { |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1417 | status=PackbitsEncodeImage(image,length,pixels,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1418 | break; |
| 1419 | } |
| 1420 | case LZWCompression: |
| 1421 | { |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1422 | status=LZWEncodeImage(image,length,pixels,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1423 | break; |
| 1424 | } |
| 1425 | case ZipCompression: |
| 1426 | { |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1427 | status=ZLIBEncodeImage(image,length,pixels,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1428 | break; |
| 1429 | } |
| 1430 | } |
| 1431 | pixels=(unsigned char *) RelinquishMagickMemory(pixels); |
| 1432 | } |
| 1433 | } |
| 1434 | else |
| 1435 | { |
| 1436 | /* |
| 1437 | Colormapped images. |
| 1438 | */ |
| 1439 | (void) WriteBlobString(image,PS3_PseudoClass"\n"); |
| 1440 | switch (compression) |
| 1441 | { |
| 1442 | case NoCompression: |
| 1443 | default: |
| 1444 | { |
| 1445 | (void) WriteBlobString(image,PS3_NoCompression"\n"); |
| 1446 | break; |
| 1447 | } |
| 1448 | case JPEGCompression: |
| 1449 | { |
| 1450 | (void) WriteBlobString(image,PS3_JPEGCompression"\n"); |
| 1451 | break; |
| 1452 | } |
| 1453 | case RLECompression: |
| 1454 | { |
| 1455 | (void) WriteBlobString(image,PS3_RLECompression"\n"); |
| 1456 | break; |
| 1457 | } |
| 1458 | case LZWCompression: |
| 1459 | { |
| 1460 | (void) WriteBlobString(image,PS3_LZWCompression"\n"); |
| 1461 | break; |
| 1462 | } |
| 1463 | case ZipCompression: |
| 1464 | { |
| 1465 | (void) WriteBlobString(image,PS3_ZipCompression"\n"); |
| 1466 | break; |
| 1467 | } |
| 1468 | } |
| 1469 | /* |
| 1470 | Number of colors in color map. |
| 1471 | */ |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1472 | (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g\n", |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 1473 | (double) image->colors); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1474 | (void) WriteBlobString(image,buffer); |
| 1475 | /* |
| 1476 | Color map - uncompressed. |
| 1477 | */ |
| 1478 | if ((compression != NoCompression) && |
| 1479 | (compression != UndefinedCompression)) |
| 1480 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1481 | for (i=0; i < (ssize_t) image->colors; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1482 | { |
| 1483 | pixel=ScaleQuantumToChar(image->colormap[i].red); |
| 1484 | (void) WriteBlobByte(image,(unsigned char) pixel); |
| 1485 | pixel=ScaleQuantumToChar(image->colormap[i].green); |
| 1486 | (void) WriteBlobByte(image,(unsigned char) pixel); |
| 1487 | pixel=ScaleQuantumToChar(image->colormap[i].blue); |
| 1488 | (void) WriteBlobByte(image,(unsigned char) pixel); |
| 1489 | } |
| 1490 | } |
| 1491 | else |
| 1492 | { |
| 1493 | Ascii85Initialize(image); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1494 | for (i=0; i < (ssize_t) image->colors; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1495 | { |
| 1496 | pixel=ScaleQuantumToChar(image->colormap[i].red); |
| 1497 | Ascii85Encode(image,(unsigned char) pixel); |
| 1498 | pixel=ScaleQuantumToChar(image->colormap[i].green); |
| 1499 | Ascii85Encode(image,(unsigned char) pixel); |
| 1500 | pixel=ScaleQuantumToChar(image->colormap[i].blue); |
| 1501 | Ascii85Encode(image,(unsigned char) pixel); |
| 1502 | } |
| 1503 | Ascii85Flush(image); |
| 1504 | } |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1505 | status=SerializeImageIndexes(image_info,image,&pixels,&length, |
| 1506 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1507 | if (status == MagickFalse) |
| 1508 | { |
| 1509 | (void) CloseBlob(image); |
| 1510 | return(MagickFalse); |
| 1511 | } |
| 1512 | switch (compression) |
| 1513 | { |
| 1514 | case NoCompression: |
| 1515 | default: |
| 1516 | { |
| 1517 | Ascii85Initialize(image); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1518 | for (i=0; i < (ssize_t) length; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1519 | Ascii85Encode(image,pixels[i]); |
| 1520 | Ascii85Flush(image); |
| 1521 | status=MagickTrue; |
| 1522 | break; |
| 1523 | } |
| 1524 | case JPEGCompression: |
| 1525 | { |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1526 | status=InjectImageBlob(image_info,image,image,"jpeg",exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1527 | break; |
| 1528 | } |
| 1529 | case RLECompression: |
| 1530 | { |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1531 | status=PackbitsEncodeImage(image,length,pixels,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1532 | break; |
| 1533 | } |
| 1534 | case LZWCompression: |
| 1535 | { |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1536 | status=LZWEncodeImage(image,length,pixels,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1537 | break; |
| 1538 | } |
| 1539 | case ZipCompression: |
| 1540 | { |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1541 | status=ZLIBEncodeImage(image,length,pixels,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1542 | break; |
| 1543 | } |
| 1544 | } |
| 1545 | pixels=(unsigned char *) RelinquishMagickMemory(pixels); |
| 1546 | } |
| 1547 | (void) WriteBlobByte(image,'\n'); |
| 1548 | if (status == MagickFalse) |
| 1549 | { |
| 1550 | (void) CloseBlob(image); |
| 1551 | return(MagickFalse); |
| 1552 | } |
| 1553 | /* |
| 1554 | Update BeginData now that we know the data size. |
| 1555 | */ |
| 1556 | length=(size_t) (TellBlob(image)-stop); |
| 1557 | stop=TellBlob(image); |
| 1558 | offset=SeekBlob(image,start,SEEK_SET); |
| 1559 | if (offset < 0) |
| 1560 | ThrowWriterException(CorruptImageError,"ImproperImageHeader"); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1561 | (void) FormatLocaleString(buffer,MaxTextExtent, |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 1562 | "%%%%BeginData:%13ld %s Bytes\n",(long) length, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1563 | compression == NoCompression ? "ASCII" : "BINARY"); |
| 1564 | (void) WriteBlobString(image,buffer); |
| 1565 | offset=SeekBlob(image,stop,SEEK_SET); |
| 1566 | (void) WriteBlobString(image,"%%EndData\n"); |
| 1567 | /* |
| 1568 | End private dictionary if this an EPS. |
| 1569 | */ |
| 1570 | if (LocaleCompare(image_info->magick,"PS3") != 0) |
| 1571 | (void) WriteBlobString(image,"end\n"); |
| 1572 | (void) WriteBlobString(image,"%%PageTrailer\n"); |
| 1573 | if (GetNextImageInList(image) == (Image *) NULL) |
| 1574 | break; |
| 1575 | image=SyncNextImageInList(image); |
| 1576 | status=SetImageProgress(image,SaveImagesTag,scene++, |
| 1577 | GetImageListLength(image)); |
| 1578 | if (status == MagickFalse) |
| 1579 | break; |
| 1580 | } while (image_info->adjoin != MagickFalse); |
| 1581 | (void) WriteBlobString(image,"%%Trailer\n"); |
| 1582 | if (page > 1) |
| 1583 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1584 | (void) FormatLocaleString(buffer,MaxTextExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 1585 | "%%%%BoundingBox: %g %g %g %g\n",floor(bounds.x1+0.5), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1586 | floor(bounds.y1+0.5),ceil(bounds.x2-0.5),ceil(bounds.y2-0.5)); |
| 1587 | (void) WriteBlobString(image,buffer); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1588 | (void) FormatLocaleString(buffer,MaxTextExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 1589 | "%%%%HiResBoundingBox: %g %g %g %g\n",bounds.x1,bounds.y1, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1590 | bounds.x2,bounds.y2); |
| 1591 | (void) WriteBlobString(image,buffer); |
| 1592 | } |
| 1593 | (void) WriteBlobString(image,"%%EOF\n"); |
| 1594 | (void) CloseBlob(image); |
| 1595 | return(MagickTrue); |
| 1596 | } |