Powered by Pair ImageMagick logo
Image Magick
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages

ImageMagick-6.1.1/coders/ept.c

Go to the documentation of this file.
00001 /* 00002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00003 % % 00004 % % 00005 % % 00006 % EEEEE PPPP TTTTT % 00007 % E P P T % 00008 % EEE PPPP T % 00009 % E P T % 00010 % EEEEE P T % 00011 % % 00012 % % 00013 % Read/Write Encapsulated Postscript Format (with preview). % 00014 % % 00015 % Software Design % 00016 % John Cristy % 00017 % July 1992 % 00018 % % 00019 % % 00020 % Copyright 1999-2004 ImageMagick Studio LLC, a non-profit organization % 00021 % dedicated to making software imaging solutions freely available. % 00022 % % 00023 % You may not use this file except in compliance with the License. You may % 00024 % obtain a copy of the License at % 00025 % % 00026 % http://www.imagemagick.org/www/Copyright.html % 00027 % % 00028 % Unless required by applicable law or agreed to in writing, software % 00029 % distributed under the License is distributed on an "AS IS" BASIS, % 00030 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % 00031 % See the License for the specific language governing permissions and % 00032 % limitations under the License. % 00033 % % 00034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00035 % 00036 % 00037 */ 00038 00039 /* 00040 Include declarations. 00041 */ 00042 #include "magick/studio.h" 00043 #include "magick/blob.h" 00044 #include "magick/blob_private.h" 00045 #include "magick/color.h" 00046 #include "magick/constitute.h" 00047 #include "magick/draw.h" 00048 #include "magick/error.h" 00049 #include "magick/error_private.h" 00050 #include "magick/delegate.h" 00051 #include "magick/geometry.h" 00052 #include "magick/image.h" 00053 #include "magick/image_private.h" 00054 #include "magick/list.h" 00055 #include "magick/magick.h" 00056 #include "magick/memory_.h" 00057 #include "magick/monitor.h" 00058 #include "magick/quantize.h" 00059 #include "magick/resource_.h" 00060 #include "magick/static.h" 00061 #include "magick/string_.h" 00062 #include "magick/transform.h" 00063 #include "magick/utility.h" 00064 00065 /* 00066 Typedef declarations. 00067 */ 00068 typedef struct _EPTInfo 00069 { 00070 unsigned long 00071 magick; 00072 00073 MagickOffsetType 00074 postscript_offset, 00075 tiff_offset; 00076 00077 size_t 00078 postscript_length, 00079 tiff_length; 00080 00081 unsigned char 00082 *postscript, 00083 *tiff; 00084 } EPTInfo; 00085 00086 /* 00087 Forward declarations. 00088 */ 00089 static MagickBooleanType 00090 WriteEPTImage(const ImageInfo *,Image *); 00091 00092 /* 00093 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00094 % % 00095 % % 00096 % % 00097 % I s E P T % 00098 % % 00099 % % 00100 % % 00101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00102 % 00103 % IsEPT() returns MagickTrue if the image format type, identified by the 00104 % magick string, is EPT. 00105 % 00106 % The format of the IsEPT method is: 00107 % 00108 % MagickBooleanType IsEPT(const unsigned char *magick,const size_t length) 00109 % 00110 % A description of each parameter follows: 00111 % 00112 % o magick: This string is generally the first few bytes of an image file 00113 % or blob. 00114 % 00115 % o length: Specifies the length of the magick string. 00116 % 00117 % 00118 */ 00119 static MagickBooleanType IsEPT(const unsigned char *magick,const size_t length) 00120 { 00121 if (length < 4) 00122 return(MagickFalse); 00123 if (memcmp(magick,"\305\320\323\306",4) == 0) 00124 return(MagickTrue); 00125 return(MagickFalse); 00126 } 00127 00128 /* 00129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00130 % % 00131 % % 00132 % % 00133 % R e a d E P T I m a g e % 00134 % % 00135 % % 00136 % % 00137 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00138 % 00139 % ReadEPTImage() reads a binary Postscript image file and returns it. It 00140 % allocates the memory necessary for the new Image structure and returns a 00141 % pointer to the new image. 00142 % 00143 % The format of the ReadEPTImage method is: 00144 % 00145 % Image *ReadEPTImage(const ImageInfo *image_info, 00146 % ExceptionInfo *exception) 00147 % 00148 % A description of each parameter follows: 00149 % 00150 % o image_info: The image info. 00151 % 00152 % o exception: return any errors or warnings in this structure. 00153 % 00154 % 00155 */ 00156 static Image *ReadEPTImage(const ImageInfo *image_info,ExceptionInfo *exception) 00157 { 00158 EPTInfo 00159 ept_info; 00160 00161 Image 00162 *image; 00163 00164 ImageInfo 00165 *read_info; 00166 00167 MagickBooleanType 00168 status; 00169 00170 /* 00171 Open image file. 00172 */ 00173 assert(image_info != (const ImageInfo *) NULL); 00174 assert(image_info->signature == MagickSignature); 00175 if (image_info->debug != MagickFalse) 00176 (void) LogMagickEvent(TraceEvent,GetMagickModule(),image_info->filename); 00177 assert(exception != (ExceptionInfo *) NULL); 00178 assert(exception->signature == MagickSignature); 00179 image=AllocateImage(image_info); 00180 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); 00181 if (status == MagickFalse) 00182 { 00183 DestroyImageList(image); 00184 return((Image *) NULL); 00185 } 00186 ept_info.magick=ReadBlobLSBLong(image); 00187 if (ept_info.magick != 0xc6d3d0c5ul) 00188 ThrowReaderException(CorruptImageError,"ImproperImageHeader"); 00189 ept_info.postscript_offset=(MagickOffsetType) ReadBlobLSBLong(image); 00190 ept_info.postscript_length=ReadBlobLSBLong(image); 00191 (void) ReadBlobLSBLong(image); 00192 (void) ReadBlobLSBLong(image); 00193 ept_info.tiff_offset=(MagickOffsetType) ReadBlobLSBLong(image); 00194 ept_info.tiff_length=ReadBlobLSBLong(image); 00195 (void) ReadBlobLSBShort(image); 00196 ept_info.postscript=(unsigned char *) 00197 AcquireMagickMemory(ept_info.postscript_length); 00198 ept_info.tiff=(unsigned char *) AcquireMagickMemory(ept_info.tiff_length); 00199 if ((ept_info.postscript == (unsigned char *) NULL) || 00200 (ept_info.tiff == (unsigned char *) NULL)) 00201 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); 00202 (void) SeekBlob(image,ept_info.tiff_offset,SEEK_SET); 00203 (void) ReadBlob(image,ept_info.tiff_length,ept_info.tiff); 00204 (void) SeekBlob(image,ept_info.postscript_offset,SEEK_SET); 00205 (void) ReadBlob(image,ept_info.postscript_length,ept_info.postscript); 00206 CloseBlob(image); 00207 image=DestroyImage(image); 00208 read_info=CloneImageInfo(image_info); 00209 (void) CopyMagickString(read_info->magick,"EPS",MaxTextExtent); 00210 image=BlobToImage(read_info,ept_info.postscript,ept_info.postscript_length, 00211 exception); 00212 if (image == (Image *) NULL) 00213 { 00214 (void) CopyMagickString(read_info->magick,"TIFF",MaxTextExtent); 00215 image=BlobToImage(read_info,ept_info.tiff,ept_info.tiff_length,exception); 00216 } 00217 read_info=DestroyImageInfo(read_info); 00218 if (image != (Image *) NULL) 00219 (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent); 00220 ept_info.tiff=(unsigned char *) RelinquishMagickMemory(ept_info.tiff); 00221 ept_info.postscript=(unsigned char *) 00222 RelinquishMagickMemory(ept_info.postscript); 00223 return(image); 00224 } 00225 00226 /* 00227 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00228 % % 00229 % % 00230 % % 00231 % R e g i s t e r E P T I m a g e % 00232 % % 00233 % % 00234 % % 00235 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00236 % 00237 % RegisterEPTImage() adds attributes for the EPT image format to 00238 % the list of supported formats. The attributes include the image format 00239 % tag, a method to read and/or write the format, whether the format 00240 % supports the saving of more than one frame to the same file or blob, 00241 % whether the format supports native in-memory I/O, and a brief 00242 % description of the format. 00243 % 00244 % The format of the RegisterEPTImage method is: 00245 % 00246 % RegisterEPTImage(void) 00247 % 00248 */ 00249 ModuleExport void RegisterEPTImage(void) 00250 { 00251 MagickInfo 00252 *entry; 00253 00254 entry=SetMagickInfo("EPT"); 00255 entry->decoder=(DecoderHandler *) ReadEPTImage; 00256 entry->encoder=(EncoderHandler *) WriteEPTImage; 00257 entry->magick=(MagickHandler *) IsEPT; 00258 entry->adjoin=MagickFalse; 00259 entry->blob_support=MagickFalse; 00260 entry->description=AcquireString("Encapsulated PostScript with TIFF preview"); 00261 entry->module=AcquireString("EPT"); 00262 (void) RegisterMagickInfo(entry); 00263 entry=SetMagickInfo("EPT2"); 00264 entry->decoder=(DecoderHandler *) ReadEPTImage; 00265 entry->encoder=(EncoderHandler *) WriteEPTImage; 00266 entry->magick=(MagickHandler *) IsEPT; 00267 entry->adjoin=MagickFalse; 00268 entry->blob_support=MagickFalse; 00269 entry->description= 00270 AcquireString("Encapsulated PostScript Level II with TIFF preview"); 00271 entry->module=AcquireString("EPT"); 00272 (void) RegisterMagickInfo(entry); 00273 entry=SetMagickInfo("EPT3"); 00274 entry->decoder=(DecoderHandler *) ReadEPTImage; 00275 entry->encoder=(EncoderHandler *) WriteEPTImage; 00276 entry->magick=(MagickHandler *) IsEPT; 00277 entry->blob_support=MagickFalse; 00278 entry->description= 00279 AcquireString("Encapsulated PostScript Level III with TIFF preview"); 00280 entry->module=AcquireString("EPT"); 00281 (void) RegisterMagickInfo(entry); 00282 } 00283 00284 /* 00285 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00286 % % 00287 % % 00288 % % 00289 % U n r e g i s t e r E P T I m a g e % 00290 % % 00291 % % 00292 % % 00293 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00294 % 00295 % UnregisterEPTImage() removes format registrations made by the 00296 % EPT module from the list of supported formats. 00297 % 00298 % The format of the UnregisterEPTImage method is: 00299 % 00300 % UnregisterEPTImage(void) 00301 % 00302 */ 00303 ModuleExport void UnregisterEPTImage(void) 00304 { 00305 (void) UnregisterMagickInfo("EPT"); 00306 } 00307 00308 /* 00309 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00310 % % 00311 % % 00312 % % 00313 % W r i t e E P T I m a g e % 00314 % % 00315 % % 00316 % % 00317 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00318 % 00319 % WriteEPTImage() writes an image in the Encapsulated Postscript format 00320 % with a TIFF preview. 00321 % 00322 % The format of the WriteEPTImage method is: 00323 % 00324 % MagickBooleanType WriteEPTImage(const ImageInfo *image_info,Image *image) 00325 % 00326 % A description of each parameter follows. 00327 % 00328 % o image_info: The image info. 00329 % 00330 % o image: The image. 00331 % 00332 % 00333 */ 00334 static MagickBooleanType WriteEPTImage(const ImageInfo *image_info,Image *image) 00335 { 00336 EPTInfo 00337 ept_info; 00338 00339 Image 00340 *write_image; 00341 00342 ImageInfo 00343 *write_info; 00344 00345 MagickBooleanType 00346 status; 00347 00348 /* 00349 Write EPT image. 00350 */ 00351 assert(image_info != (const ImageInfo *) NULL); 00352 assert(image_info->signature == MagickSignature); 00353 assert(image != (Image *) NULL); 00354 assert(image->signature == MagickSignature); 00355 if (image->debug != MagickFalse) 00356 (void) LogMagickEvent(TraceEvent,GetMagickModule(),image->filename); 00357 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception); 00358 if (status == MagickFalse) 00359 return(status); 00360 write_image=CloneImage(image,0,0,MagickTrue,&image->exception); 00361 if (write_image == (Image *) NULL) 00362 return(MagickFalse); 00363 write_info=CloneImageInfo(image_info); 00364 DestroyBlob(write_image); 00365 write_image->blob=CloneBlobInfo((BlobInfo *) NULL); 00366 (void) CopyMagickString(write_image->magick,"EPS",MaxTextExtent); 00367 if (LocaleCompare(image_info->magick,"EPT2") == 0) 00368 (void) CopyMagickString(write_image->magick,"EPS2",MaxTextExtent); 00369 if (LocaleCompare(image_info->magick,"EPT3") == 0) 00370 (void) CopyMagickString(write_image->magick,"EPS3",MaxTextExtent); 00371 (void) ResetMagickMemory(&ept_info,0,sizeof(ept_info)); 00372 ept_info.magick=0xc6d3d0c5ul; 00373 ept_info.postscript=(unsigned char *) ImageToBlob(write_info,write_image, 00374 &ept_info.postscript_length,&image->exception); 00375 if (ept_info.postscript == (void *) NULL) 00376 { 00377 write_image=DestroyImage(write_image); 00378 write_info=DestroyImageInfo(write_info); 00379 return(MagickFalse); 00380 } 00381 DestroyBlob(write_image); 00382 write_image->blob=CloneBlobInfo((BlobInfo *) NULL); 00383 (void) CopyMagickString(write_image->magick,"TIFF",MaxTextExtent); 00384 (void) TransformImage(&write_image,(char *) NULL,"512x512>"); 00385 if ((write_image->storage_class == DirectClass) || 00386 (write_image->colors > 256)) 00387 { 00388 QuantizeInfo 00389 quantize_info; 00390 00391 /* 00392 EPT preview requires that the image is colormapped. 00393 */ 00394 GetQuantizeInfo(&quantize_info); 00395 quantize_info.dither= 00396 IsPaletteImage(write_image,&image->exception) == MagickFalse; 00397 (void) QuantizeImage(&quantize_info,write_image); 00398 } 00399 write_image->compression=NoCompression; 00400 ept_info.tiff=(unsigned char *) ImageToBlob(write_info,write_image, 00401 &ept_info.tiff_length,&image->exception); 00402 write_image=DestroyImage(write_image); 00403 write_info=DestroyImageInfo(write_info); 00404 if (ept_info.tiff == (void *) NULL) 00405 { 00406 ept_info.postscript=(unsigned char *) 00407 RelinquishMagickMemory(ept_info.postscript); 00408 return(MagickFalse); 00409 } 00410 /* 00411 Write EPT image. 00412 */ 00413 (void) WriteBlobLSBLong(image,ept_info.magick); 00414 (void) WriteBlobLSBLong(image,30); 00415 (void) WriteBlobLSBLong(image,ept_info.postscript_length); 00416 (void) WriteBlobLSBLong(image,0); 00417 (void) WriteBlobLSBLong(image,0); 00418 (void) WriteBlobLSBLong(image,ept_info.postscript_length+30); 00419 (void) WriteBlobLSBLong(image,ept_info.tiff_length); 00420 (void) WriteBlobLSBShort(image,0xffff); 00421 (void) WriteBlob(image,ept_info.postscript_length,ept_info.postscript); 00422 (void) WriteBlob(image,ept_info.tiff_length,ept_info.tiff); 00423 /* 00424 Relinquish resources. 00425 */ 00426 ept_info.postscript=(unsigned char *) 00427 RelinquishMagickMemory(ept_info.postscript); 00428 ept_info.tiff=(unsigned char *) RelinquishMagickMemory(ept_info.tiff); 00429 CloseBlob(image); 00430 return(MagickTrue); 00431 }

Generated on Mon Oct 25 13:40:36 2004 for ImageMagick by doxygen 1.3.7
ImageMagick Copyright © 2004, ImageMagick Studio LLC