cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % EEEEE PPPP TTTTT % |
| 7 | % E P P T % |
| 8 | % EEE PPPP T % |
| 9 | % E P T % |
| 10 | % EEEEE P T % |
| 11 | % % |
| 12 | % % |
| 13 | % Read/Write Encapsulated Postscript Format (with preview). % |
| 14 | % % |
| 15 | % Software Design % |
cristy | de984cd | 2013-12-01 14:49:27 +0000 | [diff] [blame] | 16 | % Cristy % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 17 | % July 1992 % |
| 18 | % % |
| 19 | % % |
cristy | b56bb24 | 2014-11-25 17:12:48 +0000 | [diff] [blame] | 20 | % Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 21 | % dedicated to making software imaging solutions freely available. % |
| 22 | % % |
| 23 | % You may not use this file except in compliance with the License. You may % |
| 24 | % obtain a copy of the License at % |
| 25 | % % |
| 26 | % http://www.imagemagick.org/script/license.php % |
| 27 | % % |
| 28 | % Unless required by applicable law or agreed to in writing, software % |
| 29 | % distributed under the License is distributed on an "AS IS" BASIS, % |
| 30 | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
| 31 | % See the License for the specific language governing permissions and % |
| 32 | % limitations under the License. % |
| 33 | % % |
| 34 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 35 | % |
| 36 | % |
| 37 | */ |
| 38 | |
| 39 | /* |
| 40 | Include declarations. |
| 41 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 42 | #include "MagickCore/studio.h" |
| 43 | #include "MagickCore/blob.h" |
| 44 | #include "MagickCore/blob-private.h" |
| 45 | #include "MagickCore/color.h" |
| 46 | #include "MagickCore/constitute.h" |
| 47 | #include "MagickCore/draw.h" |
| 48 | #include "MagickCore/exception.h" |
| 49 | #include "MagickCore/exception-private.h" |
| 50 | #include "MagickCore/delegate.h" |
| 51 | #include "MagickCore/geometry.h" |
| 52 | #include "MagickCore/histogram.h" |
| 53 | #include "MagickCore/image.h" |
| 54 | #include "MagickCore/image-private.h" |
| 55 | #include "MagickCore/list.h" |
| 56 | #include "MagickCore/magick.h" |
| 57 | #include "MagickCore/memory_.h" |
| 58 | #include "MagickCore/monitor.h" |
| 59 | #include "MagickCore/monitor-private.h" |
| 60 | #include "MagickCore/quantize.h" |
| 61 | #include "MagickCore/resource_.h" |
| 62 | #include "MagickCore/quantum-private.h" |
| 63 | #include "MagickCore/static.h" |
| 64 | #include "MagickCore/string_.h" |
| 65 | #include "MagickCore/module.h" |
| 66 | #include "MagickCore/transform.h" |
| 67 | #include "MagickCore/utility.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 68 | |
| 69 | /* |
| 70 | Typedef declarations. |
| 71 | */ |
| 72 | typedef struct _EPTInfo |
| 73 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 74 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 75 | magick; |
| 76 | |
| 77 | MagickOffsetType |
| 78 | postscript_offset, |
| 79 | tiff_offset; |
| 80 | |
| 81 | size_t |
| 82 | postscript_length, |
| 83 | tiff_length; |
| 84 | |
| 85 | unsigned char |
| 86 | *postscript, |
| 87 | *tiff; |
| 88 | } EPTInfo; |
| 89 | |
| 90 | /* |
| 91 | Forward declarations. |
| 92 | */ |
| 93 | static MagickBooleanType |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 94 | WriteEPTImage(const ImageInfo *,Image *,ExceptionInfo *); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 95 | |
| 96 | /* |
| 97 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 98 | % % |
| 99 | % % |
| 100 | % % |
| 101 | % I s E P T % |
| 102 | % % |
| 103 | % % |
| 104 | % % |
| 105 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 106 | % |
| 107 | % IsEPT() returns MagickTrue if the image format type, identified by the |
| 108 | % magick string, is EPT. |
| 109 | % |
| 110 | % The format of the IsEPT method is: |
| 111 | % |
| 112 | % MagickBooleanType IsEPT(const unsigned char *magick,const size_t length) |
| 113 | % |
| 114 | % A description of each parameter follows: |
| 115 | % |
| 116 | % o magick: compare image format pattern against these bytes. |
| 117 | % |
| 118 | % o length: Specifies the length of the magick string. |
| 119 | % |
| 120 | */ |
| 121 | static MagickBooleanType IsEPT(const unsigned char *magick,const size_t length) |
| 122 | { |
| 123 | if (length < 4) |
| 124 | return(MagickFalse); |
| 125 | if (memcmp(magick,"\305\320\323\306",4) == 0) |
| 126 | return(MagickTrue); |
| 127 | return(MagickFalse); |
| 128 | } |
| 129 | |
| 130 | /* |
| 131 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 132 | % % |
| 133 | % % |
| 134 | % % |
| 135 | % R e a d E P T I m a g e % |
| 136 | % % |
| 137 | % % |
| 138 | % % |
| 139 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 140 | % |
| 141 | % ReadEPTImage() reads a binary Postscript image file and returns it. It |
| 142 | % allocates the memory necessary for the new Image structure and returns a |
| 143 | % pointer to the new image. |
| 144 | % |
| 145 | % The format of the ReadEPTImage method is: |
| 146 | % |
| 147 | % Image *ReadEPTImage(const ImageInfo *image_info, |
| 148 | % ExceptionInfo *exception) |
| 149 | % |
| 150 | % A description of each parameter follows: |
| 151 | % |
| 152 | % o image_info: the image info. |
| 153 | % |
| 154 | % o exception: return any errors or warnings in this structure. |
| 155 | % |
| 156 | */ |
| 157 | static Image *ReadEPTImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 158 | { |
| 159 | EPTInfo |
| 160 | ept_info; |
| 161 | |
| 162 | Image |
| 163 | *image; |
| 164 | |
| 165 | ImageInfo |
| 166 | *read_info; |
| 167 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 168 | MagickBooleanType |
| 169 | status; |
| 170 | |
| 171 | MagickOffsetType |
| 172 | offset; |
| 173 | |
cristy | 202de44 | 2011-04-24 18:19:07 +0000 | [diff] [blame] | 174 | ssize_t |
| 175 | count; |
| 176 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 177 | /* |
| 178 | Open image file. |
| 179 | */ |
| 180 | assert(image_info != (const ImageInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 181 | assert(image_info->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 182 | if (image_info->debug != MagickFalse) |
| 183 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 184 | image_info->filename); |
| 185 | assert(exception != (ExceptionInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 186 | assert(exception->signature == MagickCoreSignature); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 187 | image=AcquireImage(image_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 188 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 189 | if (status == MagickFalse) |
| 190 | { |
| 191 | image=DestroyImageList(image); |
| 192 | return((Image *) NULL); |
| 193 | } |
| 194 | ept_info.magick=ReadBlobLSBLong(image); |
| 195 | if (ept_info.magick != 0xc6d3d0c5ul) |
| 196 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
| 197 | ept_info.postscript_offset=(MagickOffsetType) ReadBlobLSBLong(image); |
| 198 | ept_info.postscript_length=ReadBlobLSBLong(image); |
| 199 | (void) ReadBlobLSBLong(image); |
| 200 | (void) ReadBlobLSBLong(image); |
| 201 | ept_info.tiff_offset=(MagickOffsetType) ReadBlobLSBLong(image); |
| 202 | ept_info.tiff_length=ReadBlobLSBLong(image); |
| 203 | (void) ReadBlobLSBShort(image); |
| 204 | ept_info.postscript=(unsigned char *) AcquireQuantumMemory( |
cristy | 86db873 | 2010-03-02 14:11:33 +0000 | [diff] [blame] | 205 | ept_info.postscript_length+1,sizeof(*ept_info.postscript)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 206 | if (ept_info.postscript == (unsigned char *) NULL) |
| 207 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
cristy | 86db873 | 2010-03-02 14:11:33 +0000 | [diff] [blame] | 208 | (void) ResetMagickMemory(ept_info.postscript,0,(ept_info.postscript_length+1)* |
| 209 | sizeof(*ept_info.postscript)); |
| 210 | ept_info.tiff=(unsigned char *) AcquireQuantumMemory(ept_info.tiff_length+1, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 211 | sizeof(*ept_info.tiff)); |
cristy | 86db873 | 2010-03-02 14:11:33 +0000 | [diff] [blame] | 212 | if (ept_info.tiff == (unsigned char *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 213 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
cristy | 86db873 | 2010-03-02 14:11:33 +0000 | [diff] [blame] | 214 | (void) ResetMagickMemory(ept_info.tiff,0,(ept_info.tiff_length+1)* |
| 215 | sizeof(*ept_info.tiff)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 216 | offset=SeekBlob(image,ept_info.tiff_offset,SEEK_SET); |
| 217 | if (offset < 0) |
| 218 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
| 219 | count=ReadBlob(image,ept_info.tiff_length,ept_info.tiff); |
| 220 | if (count != (ssize_t) (ept_info.tiff_length)) |
cristy | 88bae1c | 2010-02-22 13:58:51 +0000 | [diff] [blame] | 221 | (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageWarning, |
| 222 | "InsufficientImageDataInFile","`%s'",image->filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 223 | offset=SeekBlob(image,ept_info.postscript_offset,SEEK_SET); |
| 224 | if (offset < 0) |
| 225 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
| 226 | count=ReadBlob(image,ept_info.postscript_length,ept_info.postscript); |
| 227 | if (count != (ssize_t) (ept_info.postscript_length)) |
cristy | 88bae1c | 2010-02-22 13:58:51 +0000 | [diff] [blame] | 228 | (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageWarning, |
| 229 | "InsufficientImageDataInFile","`%s'",image->filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 230 | (void) CloseBlob(image); |
| 231 | image=DestroyImage(image); |
| 232 | read_info=CloneImageInfo(image_info); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 233 | (void) CopyMagickString(read_info->magick,"EPS",MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 234 | image=BlobToImage(read_info,ept_info.postscript,ept_info.postscript_length, |
| 235 | exception); |
| 236 | if (image == (Image *) NULL) |
| 237 | { |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 238 | (void) CopyMagickString(read_info->magick,"TIFF",MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 239 | image=BlobToImage(read_info,ept_info.tiff,ept_info.tiff_length,exception); |
| 240 | } |
| 241 | read_info=DestroyImageInfo(read_info); |
| 242 | if (image != (Image *) NULL) |
cristy | 28f5f36 | 2013-09-23 17:27:50 +0000 | [diff] [blame] | 243 | { |
| 244 | (void) CopyMagickString(image->filename,image_info->filename, |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 245 | MagickPathExtent); |
| 246 | (void) CopyMagickString(image->magick,"EPT",MagickPathExtent); |
cristy | 28f5f36 | 2013-09-23 17:27:50 +0000 | [diff] [blame] | 247 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 248 | ept_info.tiff=(unsigned char *) RelinquishMagickMemory(ept_info.tiff); |
| 249 | ept_info.postscript=(unsigned char *) RelinquishMagickMemory( |
| 250 | ept_info.postscript); |
| 251 | return(image); |
| 252 | } |
| 253 | |
| 254 | /* |
| 255 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 256 | % % |
| 257 | % % |
| 258 | % % |
| 259 | % R e g i s t e r E P T I m a g e % |
| 260 | % % |
| 261 | % % |
| 262 | % % |
| 263 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 264 | % |
| 265 | % RegisterEPTImage() adds attributes for the EPT image format to |
| 266 | % the list of supported formats. The attributes include the image format |
| 267 | % tag, a method to read and/or write the format, whether the format |
| 268 | % supports the saving of more than one frame to the same file or blob, |
| 269 | % whether the format supports native in-memory I/O, and a brief |
| 270 | % description of the format. |
| 271 | % |
| 272 | % The format of the RegisterEPTImage method is: |
| 273 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 274 | % size_t RegisterEPTImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 275 | % |
| 276 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 277 | ModuleExport size_t RegisterEPTImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 278 | { |
| 279 | MagickInfo |
| 280 | *entry; |
| 281 | |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 282 | entry=AcquireMagickInfo("EPT","EPT", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 283 | "Encapsulated PostScript with TIFF preview"); |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 284 | entry->decoder=(DecodeImageHandler *) ReadEPTImage; |
| 285 | entry->encoder=(EncodeImageHandler *) WriteEPTImage; |
| 286 | entry->magick=(IsImageFormatHandler *) IsEPT; |
| 287 | entry->flags|=CoderSeekableStreamFlag; |
| 288 | entry->flags^=CoderAdjoinFlag; |
| 289 | entry->flags^=CoderBlobSupportFlag; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 290 | (void) RegisterMagickInfo(entry); |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 291 | entry=AcquireMagickInfo("EPT","EPT2", |
| 292 | "Encapsulated PostScript Level II with TIFF preview"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 293 | entry->decoder=(DecodeImageHandler *) ReadEPTImage; |
| 294 | entry->encoder=(EncodeImageHandler *) WriteEPTImage; |
| 295 | entry->magick=(IsImageFormatHandler *) IsEPT; |
dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame] | 296 | entry->flags^=CoderAdjoinFlag; |
| 297 | entry->flags|=CoderSeekableStreamFlag; |
| 298 | entry->flags^=CoderBlobSupportFlag; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 299 | (void) RegisterMagickInfo(entry); |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 300 | entry=AcquireMagickInfo("EPT","EPT3", |
| 301 | "Encapsulated PostScript Level III with TIFF preview"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 302 | entry->decoder=(DecodeImageHandler *) ReadEPTImage; |
| 303 | entry->encoder=(EncodeImageHandler *) WriteEPTImage; |
| 304 | entry->magick=(IsImageFormatHandler *) IsEPT; |
dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame] | 305 | entry->flags|=CoderSeekableStreamFlag; |
| 306 | entry->flags^=CoderBlobSupportFlag; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 307 | (void) RegisterMagickInfo(entry); |
| 308 | return(MagickImageCoderSignature); |
| 309 | } |
| 310 | |
| 311 | /* |
| 312 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 313 | % % |
| 314 | % % |
| 315 | % % |
| 316 | % U n r e g i s t e r E P T I m a g e % |
| 317 | % % |
| 318 | % % |
| 319 | % % |
| 320 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 321 | % |
| 322 | % UnregisterEPTImage() removes format registrations made by the |
| 323 | % EPT module from the list of supported formats. |
| 324 | % |
| 325 | % The format of the UnregisterEPTImage method is: |
| 326 | % |
| 327 | % UnregisterEPTImage(void) |
| 328 | % |
| 329 | */ |
| 330 | ModuleExport void UnregisterEPTImage(void) |
| 331 | { |
| 332 | (void) UnregisterMagickInfo("EPT"); |
| 333 | } |
| 334 | |
| 335 | /* |
| 336 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 337 | % % |
| 338 | % % |
| 339 | % % |
| 340 | % W r i t e E P T I m a g e % |
| 341 | % % |
| 342 | % % |
| 343 | % % |
| 344 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 345 | % |
| 346 | % WriteEPTImage() writes an image in the Encapsulated Postscript format |
| 347 | % with a TIFF preview. |
| 348 | % |
| 349 | % The format of the WriteEPTImage method is: |
| 350 | % |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 351 | % MagickBooleanType WriteEPTImage(const ImageInfo *image_info, |
| 352 | % Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 353 | % |
| 354 | % A description of each parameter follows. |
| 355 | % |
| 356 | % o image_info: the image info. |
| 357 | % |
| 358 | % o image: The image. |
| 359 | % |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 360 | % o exception: return any errors or warnings in this structure. |
| 361 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 362 | */ |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 363 | static MagickBooleanType WriteEPTImage(const ImageInfo *image_info,Image *image, |
| 364 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 365 | { |
cristy | 2d6ccc3 | 2009-09-25 03:18:25 +0000 | [diff] [blame] | 366 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 367 | filename[MagickPathExtent]; |
cristy | 2d6ccc3 | 2009-09-25 03:18:25 +0000 | [diff] [blame] | 368 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 369 | EPTInfo |
| 370 | ept_info; |
| 371 | |
| 372 | Image |
| 373 | *write_image; |
| 374 | |
| 375 | ImageInfo |
| 376 | *write_info; |
| 377 | |
| 378 | MagickBooleanType |
| 379 | status; |
| 380 | |
| 381 | /* |
| 382 | Write EPT image. |
| 383 | */ |
| 384 | assert(image_info != (const ImageInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 385 | assert(image_info->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 386 | assert(image != (Image *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 387 | assert(image->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 388 | if (image->debug != MagickFalse) |
| 389 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 390 | assert(exception != (ExceptionInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 391 | assert(exception->signature == MagickCoreSignature); |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 392 | status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 393 | if (status == MagickFalse) |
| 394 | return(status); |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 395 | write_image=CloneImage(image,0,0,MagickTrue,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 396 | if (write_image == (Image *) NULL) |
| 397 | return(MagickFalse); |
| 398 | write_info=CloneImageInfo(image_info); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 399 | (void) CopyMagickString(write_info->magick,"EPS",MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 400 | if (LocaleCompare(image_info->magick,"EPT2") == 0) |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 401 | (void) CopyMagickString(write_info->magick,"EPS2",MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 402 | if (LocaleCompare(image_info->magick,"EPT3") == 0) |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 403 | (void) CopyMagickString(write_info->magick,"EPS3",MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 404 | (void) ResetMagickMemory(&ept_info,0,sizeof(ept_info)); |
| 405 | ept_info.magick=0xc6d3d0c5ul; |
| 406 | ept_info.postscript=(unsigned char *) ImageToBlob(write_info,write_image, |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 407 | &ept_info.postscript_length,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 408 | write_image=DestroyImage(write_image); |
| 409 | write_info=DestroyImageInfo(write_info); |
| 410 | if (ept_info.postscript == (void *) NULL) |
| 411 | return(MagickFalse); |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 412 | write_image=CloneImage(image,0,0,MagickTrue,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 413 | if (write_image == (Image *) NULL) |
| 414 | return(MagickFalse); |
| 415 | write_info=CloneImageInfo(image_info); |
cristy | f6f32c5 | 2015-02-25 21:33:21 +0000 | [diff] [blame] | 416 | *write_info->magick='\0'; |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 417 | (void) CopyMagickString(write_info->magick,"TIFF",MagickPathExtent); |
| 418 | (void) FormatLocaleString(filename,MagickPathExtent,"tiff:%s", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 419 | write_info->filename); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 420 | (void) CopyMagickString(write_info->filename,filename,MagickPathExtent); |
cristy | e941a75 | 2011-10-15 01:52:48 +0000 | [diff] [blame] | 421 | (void) TransformImage(&write_image,(char *) NULL,"512x512>",exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 422 | if ((write_image->storage_class == DirectClass) || |
| 423 | (write_image->colors > 256)) |
| 424 | { |
| 425 | QuantizeInfo |
| 426 | quantize_info; |
| 427 | |
| 428 | /* |
| 429 | EPT preview requires that the image is colormapped. |
| 430 | */ |
| 431 | GetQuantizeInfo(&quantize_info); |
dirk | ab4f0bb | 2015-07-25 11:46:32 +0000 | [diff] [blame] | 432 | quantize_info.dither_method=IdentifyPaletteImage(write_image, |
| 433 | exception) == MagickFalse ? RiemersmaDitherMethod : NoDitherMethod; |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 434 | (void) QuantizeImage(&quantize_info,write_image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 435 | } |
| 436 | write_info->compression=NoCompression; |
| 437 | ept_info.tiff=(unsigned char *) ImageToBlob(write_info,write_image, |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 438 | &ept_info.tiff_length,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 439 | write_image=DestroyImage(write_image); |
| 440 | write_info=DestroyImageInfo(write_info); |
| 441 | if (ept_info.tiff == (void *) NULL) |
| 442 | { |
| 443 | ept_info.postscript=(unsigned char *) RelinquishMagickMemory( |
| 444 | ept_info.postscript); |
| 445 | return(MagickFalse); |
| 446 | } |
| 447 | /* |
| 448 | Write EPT image. |
| 449 | */ |
cristy | 2d6ccc3 | 2009-09-25 03:18:25 +0000 | [diff] [blame] | 450 | (void) WriteBlobLSBLong(image,(unsigned int) ept_info.magick); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 451 | (void) WriteBlobLSBLong(image,30); |
cristy | 2d6ccc3 | 2009-09-25 03:18:25 +0000 | [diff] [blame] | 452 | (void) WriteBlobLSBLong(image,(unsigned int) ept_info.postscript_length); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 453 | (void) WriteBlobLSBLong(image,0); |
| 454 | (void) WriteBlobLSBLong(image,0); |
cristy | 2d6ccc3 | 2009-09-25 03:18:25 +0000 | [diff] [blame] | 455 | (void) WriteBlobLSBLong(image,(unsigned int) ept_info.postscript_length+30); |
| 456 | (void) WriteBlobLSBLong(image,(unsigned int) ept_info.tiff_length); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 457 | (void) WriteBlobLSBShort(image,0xffff); |
| 458 | (void) WriteBlob(image,ept_info.postscript_length,ept_info.postscript); |
| 459 | (void) WriteBlob(image,ept_info.tiff_length,ept_info.tiff); |
| 460 | /* |
| 461 | Relinquish resources. |
| 462 | */ |
| 463 | ept_info.postscript=(unsigned char *) RelinquishMagickMemory( |
| 464 | ept_info.postscript); |
| 465 | ept_info.tiff=(unsigned char *) RelinquishMagickMemory(ept_info.tiff); |
| 466 | (void) CloseBlob(image); |
| 467 | return(MagickTrue); |
| 468 | } |