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/fax.c

Go to the documentation of this file.
00001 /* 00002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00003 % % 00004 % % 00005 % % 00006 % FFFFF AAA X X % 00007 % F A A X X % 00008 % FFF AAAAA X % 00009 % F A A X X % 00010 % F A A X X % 00011 % % 00012 % % 00013 % Read/Write Group 3 Fax Image Format. % 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/colorspace.h" 00046 #include "magick/error.h" 00047 #include "magick/error_private.h" 00048 #include "magick/compress.h" 00049 #include "magick/image.h" 00050 #include "magick/image_private.h" 00051 #include "magick/list.h" 00052 #include "magick/magick.h" 00053 #include "magick/memory_.h" 00054 #include "magick/monitor.h" 00055 #include "magick/static.h" 00056 #include "magick/string_.h" 00057 00058 /* 00059 Forward declarations. 00060 */ 00061 static MagickBooleanType 00062 WriteFAXImage(const ImageInfo *,Image *); 00063 00064 /* 00065 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00066 % % 00067 % % 00068 % % 00069 % I s F A X % 00070 % % 00071 % % 00072 % % 00073 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00074 % 00075 % IsFAX() returns MagickTrue if the image format type, identified by the 00076 % magick string, is FAX. 00077 % 00078 % The format of the IsFAX method is: 00079 % 00080 % MagickBooleanType IsFAX(const unsigned char *magick,const size_t length) 00081 % 00082 % A description of each parameter follows: 00083 % 00084 % o magick: This string is generally the first few bytes of an image file 00085 % or blob. 00086 % 00087 % o length: Specifies the length of the magick string. 00088 % 00089 % 00090 */ 00091 static MagickBooleanType IsFAX(const unsigned char *magick,const size_t length) 00092 { 00093 if (length < 4) 00094 return(MagickFalse); 00095 if (LocaleNCompare((char *) magick,"DFAX",4) == 0) 00096 return(MagickTrue); 00097 return(MagickFalse); 00098 } 00099 00100 /* 00101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00102 % % 00103 % % 00104 % % 00105 % R e a d F A X I m a g e % 00106 % % 00107 % % 00108 % % 00109 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00110 % 00111 % ReadFAXImage() reads a Group 3 FAX image file and returns it. It 00112 % allocates the memory necessary for the new Image structure and returns a 00113 % pointer to the new image. 00114 % 00115 % The format of the ReadFAXImage method is: 00116 % 00117 % Image *ReadFAXImage(const ImageInfo *image_info,ExceptionInfo *exception) 00118 % 00119 % A description of each parameter follows: 00120 % 00121 % o image_info: The image info. 00122 % 00123 % o exception: return any errors or warnings in this structure. 00124 % 00125 % 00126 */ 00127 static Image *ReadFAXImage(const ImageInfo *image_info,ExceptionInfo *exception) 00128 { 00129 Image 00130 *image; 00131 00132 MagickBooleanType 00133 status; 00134 00135 /* 00136 Open image file. 00137 */ 00138 assert(image_info != (const ImageInfo *) NULL); 00139 assert(image_info->signature == MagickSignature); 00140 if (image_info->debug != MagickFalse) 00141 (void) LogMagickEvent(TraceEvent,GetMagickModule(),image_info->filename); 00142 assert(exception != (ExceptionInfo *) NULL); 00143 assert(exception->signature == MagickSignature); 00144 image=AllocateImage(image_info); 00145 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); 00146 if (status == MagickFalse) 00147 { 00148 DestroyImageList(image); 00149 return((Image *) NULL); 00150 } 00151 /* 00152 Initialize image structure. 00153 */ 00154 image->storage_class=PseudoClass; 00155 if (image->columns == 0) 00156 image->columns=2592; 00157 if (image->rows == 0) 00158 image->rows=3508; 00159 image->depth=8; 00160 if (AllocateImageColormap(image,2) == MagickFalse) 00161 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); 00162 /* 00163 Monochrome colormap. 00164 */ 00165 image->colormap[0].red=MaxRGB; 00166 image->colormap[0].green=MaxRGB; 00167 image->colormap[0].blue=MaxRGB; 00168 image->colormap[1].red=0; 00169 image->colormap[1].green=0; 00170 image->colormap[1].blue=0; 00171 if (image_info->ping != MagickFalse) 00172 { 00173 CloseBlob(image); 00174 return(GetFirstImageInList(image)); 00175 } 00176 status=HuffmanDecodeImage(image); 00177 if (status == MagickFalse) 00178 ThrowReaderException(CorruptImageError,"UnableToReadImageData"); 00179 if (EOFBlob(image) != MagickFalse) 00180 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", 00181 image->filename); 00182 CloseBlob(image); 00183 return(GetFirstImageInList(image)); 00184 } 00185 00186 /* 00187 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00188 % % 00189 % % 00190 % % 00191 % R e g i s t e r F A X I m a g e % 00192 % % 00193 % % 00194 % % 00195 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00196 % 00197 % RegisterFAXImage() adds attributes for the FAX image format to 00198 % the list of supported formats. The attributes include the image format 00199 % tag, a method to read and/or write the format, whether the format 00200 % supports the saving of more than one frame to the same file or blob, 00201 % whether the format supports native in-memory I/O, and a brief 00202 % description of the format. 00203 % 00204 % The format of the RegisterFAXImage method is: 00205 % 00206 % RegisterFAXImage(void) 00207 % 00208 */ 00209 ModuleExport void RegisterFAXImage(void) 00210 { 00211 MagickInfo 00212 *entry; 00213 00214 static const char 00215 *Note= 00216 { 00217 "See TIFF format. Note that FAX machines use non-square pixels which\n" 00218 "are 1.5 times wider than they are tall but computer displays use\n" 00219 "square pixels. FAX images may appear to be narrow unless they are\n" 00220 "explicitly resized using a resize specification of \"150x100%\"." 00221 }; 00222 00223 entry=SetMagickInfo("FAX"); 00224 entry->decoder=(DecoderHandler *) ReadFAXImage; 00225 entry->encoder=(EncoderHandler *) WriteFAXImage; 00226 entry->magick=(MagickHandler *) IsFAX; 00227 entry->description=AcquireString("Group 3 FAX"); 00228 entry->note=AcquireString(Note); 00229 entry->module=AcquireString("FAX"); 00230 (void) RegisterMagickInfo(entry); 00231 entry=SetMagickInfo("G3"); 00232 entry->decoder=(DecoderHandler *) ReadFAXImage; 00233 entry->encoder=(EncoderHandler *) WriteFAXImage; 00234 entry->magick=(MagickHandler *) IsFAX; 00235 entry->adjoin=MagickFalse; 00236 entry->description=AcquireString("Group 3 FAX"); 00237 entry->module=AcquireString("FAX"); 00238 (void) RegisterMagickInfo(entry); 00239 } 00240 00241 /* 00242 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00243 % % 00244 % % 00245 % % 00246 % U n r e g i s t e r F A X I m a g e % 00247 % % 00248 % % 00249 % % 00250 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00251 % 00252 % UnregisterFAXImage() removes format registrations made by the 00253 % FAX module from the list of supported formats. 00254 % 00255 % The format of the UnregisterFAXImage method is: 00256 % 00257 % UnregisterFAXImage(void) 00258 % 00259 */ 00260 ModuleExport void UnregisterFAXImage(void) 00261 { 00262 (void) UnregisterMagickInfo("FAX"); 00263 (void) UnregisterMagickInfo("G3"); 00264 } 00265 00266 /* 00267 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00268 % % 00269 % % 00270 % % 00271 % W r i t e F A X I m a g e % 00272 % % 00273 % % 00274 % % 00275 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00276 % 00277 % Procedure WriteFAXImage() writes an image to a file in 1 dimensional Huffman 00278 % encoded format. 00279 % 00280 % The format of the WriteFAXImage method is: 00281 % 00282 % MagickBooleanType WriteFAXImage(const ImageInfo *image_info,Image *image) 00283 % 00284 % A description of each parameter follows. 00285 % 00286 % o image_info: The image info. 00287 % 00288 % o image: The image. 00289 % 00290 % 00291 */ 00292 static MagickBooleanType WriteFAXImage(const ImageInfo *image_info,Image *image) 00293 { 00294 ImageInfo 00295 *write_info; 00296 00297 MagickBooleanType 00298 status; 00299 00300 MagickOffsetType 00301 scene; 00302 00303 /* 00304 Open output image file. 00305 */ 00306 assert(image_info != (const ImageInfo *) NULL); 00307 assert(image_info->signature == MagickSignature); 00308 assert(image != (Image *) NULL); 00309 assert(image->signature == MagickSignature); 00310 if (image->debug != MagickFalse) 00311 (void) LogMagickEvent(TraceEvent,GetMagickModule(),image->filename); 00312 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception); 00313 if (status == MagickFalse) 00314 return(status); 00315 write_info=CloneImageInfo(image_info); 00316 (void) strcpy(write_info->magick,"FAX"); 00317 scene=0; 00318 do 00319 { 00320 /* 00321 Convert MIFF to monochrome. 00322 */ 00323 (void) SetImageColorspace(image,RGBColorspace); 00324 status=HuffmanEncodeImage(write_info,image); 00325 if (image->next == (Image *) NULL) 00326 break; 00327 image=SyncNextImageInList(image); 00328 if (image->progress_monitor != (MagickProgressMonitor) NULL) 00329 { 00330 status=image->progress_monitor(SaveImagesTag,scene, 00331 GetImageListLength(image),image->client_data); 00332 if (status == MagickFalse) 00333 break; 00334 } 00335 scene++; 00336 } while (write_info->adjoin != MagickFalse); 00337 write_info=DestroyImageInfo(write_info); 00338 CloseBlob(image); 00339 return(status); 00340 }

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