/src/imagemagick/coders/ept.c
Line | Count | Source |
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 % |
16 | | % Cristy % |
17 | | % July 1992 % |
18 | | % % |
19 | | % % |
20 | | % Copyright @ 1999 ImageMagick Studio LLC, a non-profit organization % |
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 | | % https://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 | | */ |
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/resize.h" |
63 | | #include "MagickCore/quantum-private.h" |
64 | | #include "MagickCore/static.h" |
65 | | #include "MagickCore/string_.h" |
66 | | #include "MagickCore/module.h" |
67 | | #include "MagickCore/utility.h" |
68 | | |
69 | | /* |
70 | | Typedef declarations. |
71 | | */ |
72 | | typedef struct _EPTInfo |
73 | | { |
74 | | size_t |
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 |
94 | | WriteEPTImage(const ImageInfo *,Image *,ExceptionInfo *); |
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 | 0 | { |
123 | 0 | if (length < 4) |
124 | 0 | return(MagickFalse); |
125 | 0 | if (memcmp(magick,"\305\320\323\306",4) == 0) |
126 | 0 | return(MagickTrue); |
127 | 0 | return(MagickFalse); |
128 | 0 | } |
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 | 61.9k | { |
159 | 61.9k | const void |
160 | 61.9k | *postscript_data, |
161 | 61.9k | *tiff_data; |
162 | | |
163 | 61.9k | EPTInfo |
164 | 61.9k | ept_info; |
165 | | |
166 | 61.9k | Image |
167 | 61.9k | *image, |
168 | 61.9k | *tiff_image; |
169 | | |
170 | 61.9k | ImageInfo |
171 | 61.9k | *read_info; |
172 | | |
173 | 61.9k | MagickBooleanType |
174 | 61.9k | status; |
175 | | |
176 | 61.9k | MagickOffsetType |
177 | 61.9k | offset; |
178 | | |
179 | 61.9k | ssize_t |
180 | 61.9k | count; |
181 | | |
182 | | /* |
183 | | Open image file. |
184 | | */ |
185 | 61.9k | assert(image_info != (const ImageInfo *) NULL); |
186 | 61.9k | assert(image_info->signature == MagickCoreSignature); |
187 | 61.9k | assert(exception != (ExceptionInfo *) NULL); |
188 | 61.9k | assert(exception->signature == MagickCoreSignature); |
189 | 61.9k | if (IsEventLogging() != MagickFalse) |
190 | 0 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
191 | 0 | image_info->filename); |
192 | 61.9k | image=AcquireImage(image_info,exception); |
193 | 61.9k | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
194 | 61.9k | if (status == MagickFalse) |
195 | 0 | { |
196 | 0 | image=DestroyImageList(image); |
197 | 0 | return((Image *) NULL); |
198 | 0 | } |
199 | 61.9k | ept_info.magick=ReadBlobLSBLong(image); |
200 | 61.9k | if (ept_info.magick != 0xc6d3d0c5ul) |
201 | 58.6k | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
202 | 58.6k | ept_info.postscript_offset=(MagickOffsetType) ReadBlobLSBLong(image); |
203 | 58.6k | ept_info.postscript_length=ReadBlobLSBLong(image); |
204 | 58.6k | if ((MagickSizeType) ept_info.postscript_length > GetBlobSize(image)) |
205 | 58.5k | ThrowReaderException(CorruptImageError,"InsufficientImageDataInFile"); |
206 | 58.5k | (void) ReadBlobLSBLong(image); |
207 | 58.5k | (void) ReadBlobLSBLong(image); |
208 | 58.5k | ept_info.tiff_offset=(MagickOffsetType) ReadBlobLSBLong(image); |
209 | 58.5k | ept_info.tiff_length=ReadBlobLSBLong(image); |
210 | 58.5k | if ((ept_info.postscript_length+ept_info.tiff_length) == 0) |
211 | 58.4k | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
212 | 58.4k | if ((MagickSizeType) ept_info.tiff_length > GetBlobSize(image)) |
213 | 58.3k | ThrowReaderException(CorruptImageError,"InsufficientImageDataInFile"); |
214 | 58.3k | (void) ReadBlobLSBShort(image); |
215 | 58.3k | ept_info.postscript=(unsigned char *) AcquireQuantumMemory( |
216 | 58.3k | ept_info.postscript_length+1,sizeof(*ept_info.postscript)); |
217 | 58.3k | if (ept_info.postscript == (unsigned char *) NULL) |
218 | 58.3k | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
219 | 58.3k | (void) memset(ept_info.postscript,0,(ept_info.postscript_length+1)* |
220 | 58.3k | sizeof(*ept_info.postscript)); |
221 | 58.3k | ept_info.tiff=(unsigned char *) AcquireQuantumMemory(ept_info.tiff_length+1, |
222 | 58.3k | sizeof(*ept_info.tiff)); |
223 | 58.3k | if (ept_info.tiff == (unsigned char *) NULL) |
224 | 0 | { |
225 | 0 | ept_info.postscript=(unsigned char *) RelinquishMagickMemory( |
226 | 0 | ept_info.postscript); |
227 | 0 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
228 | 0 | } |
229 | 58.3k | (void) memset(ept_info.tiff,0,(ept_info.tiff_length+1)* |
230 | 58.3k | sizeof(*ept_info.tiff)); |
231 | 58.3k | offset=SeekBlob(image,ept_info.tiff_offset,SEEK_SET); |
232 | 58.3k | if ((ept_info.tiff_length != 0) && (offset < 30)) |
233 | 13 | { |
234 | 13 | ept_info.tiff=(unsigned char *) RelinquishMagickMemory(ept_info.tiff); |
235 | 13 | ept_info.postscript=(unsigned char *) RelinquishMagickMemory( |
236 | 13 | ept_info.postscript); |
237 | 13 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
238 | 0 | } |
239 | 58.3k | tiff_data=ReadBlobStream(image,ept_info.tiff_length,ept_info.tiff,&count); |
240 | 58.3k | if (count != (ssize_t) (ept_info.tiff_length)) |
241 | 53.0k | (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageWarning, |
242 | 53.0k | "InsufficientImageDataInFile","`%s'",image->filename); |
243 | 58.3k | offset=SeekBlob(image,ept_info.postscript_offset,SEEK_SET); |
244 | 58.3k | if ((ept_info.postscript_length != 0) && (offset < 30)) |
245 | 38 | { |
246 | 38 | ept_info.tiff=(unsigned char *) RelinquishMagickMemory(ept_info.tiff); |
247 | 38 | ept_info.postscript=(unsigned char *) RelinquishMagickMemory( |
248 | 38 | ept_info.postscript); |
249 | 38 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
250 | 0 | } |
251 | 58.2k | postscript_data=ReadBlobStream(image,ept_info.postscript_length, |
252 | 58.2k | ept_info.postscript,&count); |
253 | 58.2k | if (count != (ssize_t) (ept_info.postscript_length)) |
254 | 450 | { |
255 | 450 | ept_info.tiff=(unsigned char *) RelinquishMagickMemory(ept_info.tiff); |
256 | 450 | ept_info.postscript=(unsigned char *) RelinquishMagickMemory( |
257 | 450 | ept_info.postscript); |
258 | 450 | ThrowReaderException(CorruptImageError,"InsufficientImageDataInFile"); |
259 | 0 | } |
260 | 57.8k | (void) CloseBlob(image); |
261 | 57.8k | image=DestroyImage(image); |
262 | 57.8k | read_info=CloneImageInfo(image_info); |
263 | 57.8k | read_info->number_scenes=1; |
264 | 57.8k | read_info->scene=0; |
265 | 57.8k | (void) CopyMagickString(read_info->magick,"EPS",MagickPathExtent); |
266 | 57.8k | if (ept_info.postscript_length != 0) |
267 | 7.00k | { |
268 | | /* |
269 | | Convert Postscript blob to image. |
270 | | */ |
271 | 7.00k | image=BlobToImage(read_info,postscript_data,ept_info.postscript_length, |
272 | 7.00k | exception); |
273 | 7.00k | if (image != (Image *) NULL) |
274 | 0 | { |
275 | 0 | (void) CopyMagickString(image->filename,image_info->filename, |
276 | 0 | MagickPathExtent); |
277 | 0 | (void) CopyMagickString(image->magick,"EPT",MagickPathExtent); |
278 | 0 | } |
279 | 7.00k | } |
280 | 57.8k | if (ept_info.tiff_length != 0) |
281 | 56.0k | { |
282 | | /* |
283 | | Convert TIFF blob to image. |
284 | | */ |
285 | 56.0k | (void) CopyMagickString(read_info->magick,"TIFF",MagickPathExtent); |
286 | 56.0k | tiff_image=BlobToImage(read_info,tiff_data,ept_info.tiff_length, |
287 | 56.0k | exception); |
288 | 56.0k | if (tiff_image != (Image *) NULL) |
289 | 23.5k | { |
290 | 23.5k | if (image == (Image *) NULL) |
291 | 23.5k | image=tiff_image; |
292 | 0 | else |
293 | 0 | AppendImageToList(&image,tiff_image); |
294 | 23.5k | } |
295 | 56.0k | } |
296 | 57.8k | read_info=DestroyImageInfo(read_info); |
297 | 57.8k | ept_info.tiff=(unsigned char *) RelinquishMagickMemory(ept_info.tiff); |
298 | 57.8k | ept_info.postscript=(unsigned char *) RelinquishMagickMemory( |
299 | 57.8k | ept_info.postscript); |
300 | 57.8k | return(GetFirstImageInList(image)); |
301 | 58.2k | } |
302 | | |
303 | | /* |
304 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
305 | | % % |
306 | | % % |
307 | | % % |
308 | | % R e g i s t e r E P T I m a g e % |
309 | | % % |
310 | | % % |
311 | | % % |
312 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
313 | | % |
314 | | % RegisterEPTImage() adds attributes for the EPT image format to |
315 | | % the list of supported formats. The attributes include the image format |
316 | | % tag, a method to read and/or write the format, whether the format |
317 | | % supports the saving of more than one frame to the same file or blob, |
318 | | % whether the format supports native in-memory I/O, and a brief |
319 | | % description of the format. |
320 | | % |
321 | | % The format of the RegisterEPTImage method is: |
322 | | % |
323 | | % size_t RegisterEPTImage(void) |
324 | | % |
325 | | */ |
326 | | ModuleExport size_t RegisterEPTImage(void) |
327 | 11 | { |
328 | 11 | MagickInfo |
329 | 11 | *entry; |
330 | | |
331 | 11 | entry=AcquireMagickInfo("EPT","EPT", |
332 | 11 | "Encapsulated PostScript with TIFF preview"); |
333 | 11 | entry->decoder=(DecodeImageHandler *) ReadEPTImage; |
334 | 11 | entry->encoder=(EncodeImageHandler *) WriteEPTImage; |
335 | 11 | entry->magick=(IsImageFormatHandler *) IsEPT; |
336 | 11 | entry->flags|=CoderDecoderSeekableStreamFlag; |
337 | 11 | entry->flags^=CoderAdjoinFlag; |
338 | 11 | entry->flags^=CoderBlobSupportFlag; |
339 | 11 | (void) RegisterMagickInfo(entry); |
340 | 11 | entry=AcquireMagickInfo("EPT","EPT2", |
341 | 11 | "Encapsulated PostScript Level II with TIFF preview"); |
342 | 11 | entry->decoder=(DecodeImageHandler *) ReadEPTImage; |
343 | 11 | entry->encoder=(EncodeImageHandler *) WriteEPTImage; |
344 | 11 | entry->magick=(IsImageFormatHandler *) IsEPT; |
345 | 11 | entry->flags^=CoderAdjoinFlag; |
346 | 11 | entry->flags|=CoderDecoderSeekableStreamFlag; |
347 | 11 | entry->flags^=CoderBlobSupportFlag; |
348 | 11 | (void) RegisterMagickInfo(entry); |
349 | 11 | entry=AcquireMagickInfo("EPT","EPT3", |
350 | 11 | "Encapsulated PostScript Level III with TIFF preview"); |
351 | 11 | entry->decoder=(DecodeImageHandler *) ReadEPTImage; |
352 | 11 | entry->encoder=(EncodeImageHandler *) WriteEPTImage; |
353 | 11 | entry->magick=(IsImageFormatHandler *) IsEPT; |
354 | 11 | entry->flags|=CoderDecoderSeekableStreamFlag; |
355 | 11 | entry->flags^=CoderBlobSupportFlag; |
356 | 11 | (void) RegisterMagickInfo(entry); |
357 | 11 | return(MagickImageCoderSignature); |
358 | 11 | } |
359 | | |
360 | | /* |
361 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
362 | | % % |
363 | | % % |
364 | | % % |
365 | | % U n r e g i s t e r E P T I m a g e % |
366 | | % % |
367 | | % % |
368 | | % % |
369 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
370 | | % |
371 | | % UnregisterEPTImage() removes format registrations made by the |
372 | | % EPT module from the list of supported formats. |
373 | | % |
374 | | % The format of the UnregisterEPTImage method is: |
375 | | % |
376 | | % UnregisterEPTImage(void) |
377 | | % |
378 | | */ |
379 | | ModuleExport void UnregisterEPTImage(void) |
380 | 0 | { |
381 | 0 | (void) UnregisterMagickInfo("EPT"); |
382 | 0 | } |
383 | | |
384 | | /* |
385 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
386 | | % % |
387 | | % % |
388 | | % % |
389 | | % W r i t e E P T I m a g e % |
390 | | % % |
391 | | % % |
392 | | % % |
393 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
394 | | % |
395 | | % WriteEPTImage() writes an image in the Encapsulated Postscript format |
396 | | % with a TIFF preview. |
397 | | % |
398 | | % The format of the WriteEPTImage method is: |
399 | | % |
400 | | % MagickBooleanType WriteEPTImage(const ImageInfo *image_info, |
401 | | % Image *image,ExceptionInfo *exception) |
402 | | % |
403 | | % A description of each parameter follows. |
404 | | % |
405 | | % o image_info: the image info. |
406 | | % |
407 | | % o image: The image. |
408 | | % |
409 | | % o exception: return any errors or warnings in this structure. |
410 | | % |
411 | | */ |
412 | | static MagickBooleanType WriteEPTImage(const ImageInfo *image_info,Image *image, |
413 | | ExceptionInfo *exception) |
414 | 0 | { |
415 | 0 | char |
416 | 0 | filename[MagickPathExtent]; |
417 | |
|
418 | 0 | EPTInfo |
419 | 0 | ept_info; |
420 | |
|
421 | 0 | Image |
422 | 0 | *write_image; |
423 | |
|
424 | 0 | ImageInfo |
425 | 0 | *write_info; |
426 | |
|
427 | 0 | MagickBooleanType |
428 | 0 | status; |
429 | | |
430 | | /* |
431 | | Write EPT image. |
432 | | */ |
433 | 0 | assert(image_info != (const ImageInfo *) NULL); |
434 | 0 | assert(image_info->signature == MagickCoreSignature); |
435 | 0 | assert(image != (Image *) NULL); |
436 | 0 | assert(image->signature == MagickCoreSignature); |
437 | 0 | if (IsEventLogging() != MagickFalse) |
438 | 0 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
439 | 0 | assert(exception != (ExceptionInfo *) NULL); |
440 | 0 | assert(exception->signature == MagickCoreSignature); |
441 | 0 | status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception); |
442 | 0 | if (status == MagickFalse) |
443 | 0 | return(status); |
444 | 0 | write_image=CloneImage(image,0,0,MagickTrue,exception); |
445 | 0 | if (write_image == (Image *) NULL) |
446 | 0 | return(MagickFalse); |
447 | 0 | write_info=CloneImageInfo(image_info); |
448 | 0 | (void) CopyMagickString(write_info->filename,"EPS:",MagickPathExtent); |
449 | 0 | (void) CopyMagickString(write_info->magick,"EPS",MagickPathExtent); |
450 | 0 | if (LocaleCompare(image_info->magick,"EPT2") == 0) |
451 | 0 | { |
452 | 0 | (void) CopyMagickString(write_info->filename,"EPS2:",MagickPathExtent); |
453 | 0 | (void) CopyMagickString(write_info->magick,"EPS2",MagickPathExtent); |
454 | 0 | } |
455 | 0 | if (LocaleCompare(image_info->magick,"EPT3") == 0) |
456 | 0 | { |
457 | 0 | (void) CopyMagickString(write_info->filename,"EPS3:",MagickPathExtent); |
458 | 0 | (void) CopyMagickString(write_info->magick,"EPS3",MagickPathExtent); |
459 | 0 | } |
460 | 0 | (void) memset(&ept_info,0,sizeof(ept_info)); |
461 | 0 | ept_info.magick=0xc6d3d0c5ul; |
462 | 0 | ept_info.postscript=(unsigned char *) ImageToBlob(write_info,write_image, |
463 | 0 | &ept_info.postscript_length,exception); |
464 | 0 | write_image=DestroyImage(write_image); |
465 | 0 | write_info=DestroyImageInfo(write_info); |
466 | 0 | if (ept_info.postscript == (void *) NULL) |
467 | 0 | return(MagickFalse); |
468 | 0 | write_image=CloneImage(image,0,0,MagickTrue,exception); |
469 | 0 | if (write_image == (Image *) NULL) |
470 | 0 | return(MagickFalse); |
471 | 0 | write_info=CloneImageInfo(image_info); |
472 | 0 | (void) CopyMagickString(write_info->magick,"TIFF",MagickPathExtent); |
473 | 0 | (void) FormatLocaleString(filename,MagickPathExtent,"tiff:%s", |
474 | 0 | write_info->filename); |
475 | 0 | (void) CopyMagickString(write_info->filename,filename,MagickPathExtent); |
476 | 0 | if ((write_image->columns > 512) || (write_image->rows > 512)) |
477 | 0 | { |
478 | 0 | Image |
479 | 0 | *resize_image; |
480 | |
|
481 | 0 | resize_image=ResizeImage(write_image,512,512,write_image->filter, |
482 | 0 | exception); |
483 | 0 | if (resize_image != (Image *) NULL) |
484 | 0 | { |
485 | 0 | write_image=DestroyImage(write_image); |
486 | 0 | write_image=resize_image; |
487 | 0 | } |
488 | 0 | } |
489 | 0 | if ((write_image->storage_class == DirectClass) || |
490 | 0 | (write_image->colors > 256)) |
491 | 0 | { |
492 | 0 | QuantizeInfo |
493 | 0 | quantize_info; |
494 | | |
495 | | /* |
496 | | EPT preview requires that the image is colormapped. |
497 | | */ |
498 | 0 | GetQuantizeInfo(&quantize_info); |
499 | 0 | quantize_info.dither_method=IdentifyPaletteImage(write_image, |
500 | 0 | exception) == MagickFalse ? RiemersmaDitherMethod : NoDitherMethod; |
501 | 0 | (void) QuantizeImage(&quantize_info,write_image,exception); |
502 | 0 | } |
503 | 0 | write_info->compression=NoCompression; |
504 | 0 | ept_info.tiff=(unsigned char *) ImageToBlob(write_info,write_image, |
505 | 0 | &ept_info.tiff_length,exception); |
506 | 0 | write_image=DestroyImage(write_image); |
507 | 0 | write_info=DestroyImageInfo(write_info); |
508 | 0 | if (ept_info.tiff == (void *) NULL) |
509 | 0 | { |
510 | 0 | ept_info.postscript=(unsigned char *) RelinquishMagickMemory( |
511 | 0 | ept_info.postscript); |
512 | 0 | return(MagickFalse); |
513 | 0 | } |
514 | | /* |
515 | | Write EPT image. |
516 | | */ |
517 | 0 | (void) WriteBlobLSBLong(image,(unsigned int) ept_info.magick); |
518 | 0 | (void) WriteBlobLSBLong(image,30); |
519 | 0 | (void) WriteBlobLSBLong(image,(unsigned int) ept_info.postscript_length); |
520 | 0 | (void) WriteBlobLSBLong(image,0); |
521 | 0 | (void) WriteBlobLSBLong(image,0); |
522 | 0 | (void) WriteBlobLSBLong(image,(unsigned int) ept_info.postscript_length+30); |
523 | 0 | (void) WriteBlobLSBLong(image,(unsigned int) ept_info.tiff_length); |
524 | 0 | (void) WriteBlobLSBShort(image,0xffff); |
525 | 0 | (void) WriteBlob(image,ept_info.postscript_length,ept_info.postscript); |
526 | 0 | (void) WriteBlob(image,ept_info.tiff_length,ept_info.tiff); |
527 | | /* |
528 | | Relinquish resources. |
529 | | */ |
530 | 0 | ept_info.postscript=(unsigned char *) RelinquishMagickMemory( |
531 | 0 | ept_info.postscript); |
532 | 0 | ept_info.tiff=(unsigned char *) RelinquishMagickMemory(ept_info.tiff); |
533 | 0 | if (CloseBlob(image) == MagickFalse) |
534 | 0 | status=MagickFalse; |
535 | 0 | return(status); |
536 | 0 | } |