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