| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | #include "magick/studio.h" |
|---|
| 43 | #include "magick/blob.h" |
|---|
| 44 | #include "magick/blob-private.h" |
|---|
| 45 | #include "magick/colorspace.h" |
|---|
| 46 | #include "magick/exception.h" |
|---|
| 47 | #include "magick/exception-private.h" |
|---|
| 48 | #include "magick/compress.h" |
|---|
| 49 | #include "magick/image.h" |
|---|
| 50 | #include "magick/image-private.h" |
|---|
| 51 | #include "magick/list.h" |
|---|
| 52 | #include "magick/magick.h" |
|---|
| 53 | #include "magick/memory_.h" |
|---|
| 54 | #include "magick/monitor.h" |
|---|
| 55 | #include "magick/monitor-private.h" |
|---|
| 56 | #include "magick/quantum-private.h" |
|---|
| 57 | #include "magick/static.h" |
|---|
| 58 | #include "magick/string_.h" |
|---|
| 59 | #include "magick/module.h" |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | static MagickBooleanType |
|---|
| 65 | WriteFAXImage(const ImageInfo *,Image *); |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | static MagickBooleanType IsFAX(const unsigned char *magick,const size_t length) |
|---|
| 94 | { |
|---|
| 95 | if (length < 4) |
|---|
| 96 | return(MagickFalse); |
|---|
| 97 | if (LocaleNCompare((char *) magick,"DFAX",4) == 0) |
|---|
| 98 | return(MagickTrue); |
|---|
| 99 | return(MagickFalse); |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | static Image *ReadFAXImage(const ImageInfo *image_info,ExceptionInfo *exception) |
|---|
| 129 | { |
|---|
| 130 | Image |
|---|
| 131 | *image; |
|---|
| 132 | |
|---|
| 133 | MagickBooleanType |
|---|
| 134 | status; |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | assert(image_info != (const ImageInfo *) NULL); |
|---|
| 140 | assert(image_info->signature == MagickSignature); |
|---|
| 141 | if (image_info->debug != MagickFalse) |
|---|
| 142 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
|---|
| 143 | image_info->filename); |
|---|
| 144 | assert(exception != (ExceptionInfo *) NULL); |
|---|
| 145 | assert(exception->signature == MagickSignature); |
|---|
| 146 | image=AcquireImage(image_info); |
|---|
| 147 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
|---|
| 148 | if (status == MagickFalse) |
|---|
| 149 | { |
|---|
| 150 | image=DestroyImageList(image); |
|---|
| 151 | return((Image *) NULL); |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | image->storage_class=PseudoClass; |
|---|
| 157 | if (image->columns == 0) |
|---|
| 158 | image->columns=2592; |
|---|
| 159 | if (image->rows == 0) |
|---|
| 160 | image->rows=3508; |
|---|
| 161 | image->depth=8; |
|---|
| 162 | if (AcquireImageColormap(image,2) == MagickFalse) |
|---|
| 163 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 166 | |
|---|
| 167 | image->colormap[0].red=(Quantum) QuantumRange; |
|---|
| 168 | image->colormap[0].green=(Quantum) QuantumRange; |
|---|
| 169 | image->colormap[0].blue=(Quantum) QuantumRange; |
|---|
| 170 | image->colormap[1].red=(Quantum) 0; |
|---|
| 171 | image->colormap[1].green=(Quantum) 0; |
|---|
| 172 | image->colormap[1].blue=(Quantum) 0; |
|---|
| 173 | if (image_info->ping != MagickFalse) |
|---|
| 174 | { |
|---|
| 175 | (void) CloseBlob(image); |
|---|
| 176 | return(GetFirstImageInList(image)); |
|---|
| 177 | } |
|---|
| 178 | status=HuffmanDecodeImage(image); |
|---|
| 179 | if (status == MagickFalse) |
|---|
| 180 | ThrowReaderException(CorruptImageError,"UnableToReadImageData"); |
|---|
| 181 | if (EOFBlob(image) != MagickFalse) |
|---|
| 182 | ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", |
|---|
| 183 | image->filename); |
|---|
| 184 | (void) CloseBlob(image); |
|---|
| 185 | return(GetFirstImageInList(image)); |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | |
|---|
| 189 | |
|---|
| 190 | |
|---|
| 191 | |
|---|
| 192 | |
|---|
| 193 | |
|---|
| 194 | |
|---|
| 195 | |
|---|
| 196 | |
|---|
| 197 | |
|---|
| 198 | |
|---|
| 199 | |
|---|
| 200 | |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | |
|---|
| 207 | |
|---|
| 208 | |
|---|
| 209 | |
|---|
| 210 | |
|---|
| 211 | ModuleExport unsigned long RegisterFAXImage(void) |
|---|
| 212 | { |
|---|
| 213 | MagickInfo |
|---|
| 214 | *entry; |
|---|
| 215 | |
|---|
| 216 | static const char |
|---|
| 217 | *Note= |
|---|
| 218 | { |
|---|
| 219 | "FAX machines use non-square pixels which are 1.5 times wider than they\n" |
|---|
| 220 | "are tall but computer displays use square pixels, therefore FAX images\n" |
|---|
| 221 | "may appear to be narrow unless they are explicitly resized using a\n" |
|---|
| 222 | "geometry of \"150x100%\".\n" |
|---|
| 223 | }; |
|---|
| 224 | |
|---|
| 225 | entry=SetMagickInfo("FAX"); |
|---|
| 226 | entry->decoder=(DecodeImageHandler *) ReadFAXImage; |
|---|
| 227 | entry->encoder=(EncodeImageHandler *) WriteFAXImage; |
|---|
| 228 | entry->magick=(IsImageFormatHandler *) IsFAX; |
|---|
| 229 | entry->description=ConstantString("Group 3 FAX"); |
|---|
| 230 | entry->note=ConstantString(Note); |
|---|
| 231 | entry->module=ConstantString("FAX"); |
|---|
| 232 | (void) RegisterMagickInfo(entry); |
|---|
| 233 | entry=SetMagickInfo("G3"); |
|---|
| 234 | entry->decoder=(DecodeImageHandler *) ReadFAXImage; |
|---|
| 235 | entry->encoder=(EncodeImageHandler *) WriteFAXImage; |
|---|
| 236 | entry->magick=(IsImageFormatHandler *) IsFAX; |
|---|
| 237 | entry->adjoin=MagickFalse; |
|---|
| 238 | entry->description=ConstantString("Group 3 FAX"); |
|---|
| 239 | entry->module=ConstantString("FAX"); |
|---|
| 240 | (void) RegisterMagickInfo(entry); |
|---|
| 241 | return(MagickImageCoderSignature); |
|---|
| 242 | } |
|---|
| 243 | |
|---|
| 244 | |
|---|
| 245 | |
|---|
| 246 | |
|---|
| 247 | |
|---|
| 248 | |
|---|
| 249 | |
|---|
| 250 | |
|---|
| 251 | |
|---|
| 252 | |
|---|
| 253 | |
|---|
| 254 | |
|---|
| 255 | |
|---|
| 256 | |
|---|
| 257 | |
|---|
| 258 | |
|---|
| 259 | |
|---|
| 260 | |
|---|
| 261 | |
|---|
| 262 | |
|---|
| 263 | ModuleExport void UnregisterFAXImage(void) |
|---|
| 264 | { |
|---|
| 265 | (void) UnregisterMagickInfo("FAX"); |
|---|
| 266 | (void) UnregisterMagickInfo("G3"); |
|---|
| 267 | } |
|---|
| 268 | |
|---|
| 269 | |
|---|
| 270 | |
|---|
| 271 | |
|---|
| 272 | |
|---|
| 273 | |
|---|
| 274 | |
|---|
| 275 | |
|---|
| 276 | |
|---|
| 277 | |
|---|
| 278 | |
|---|
| 279 | |
|---|
| 280 | |
|---|
| 281 | |
|---|
| 282 | |
|---|
| 283 | |
|---|
| 284 | |
|---|
| 285 | |
|---|
| 286 | |
|---|
| 287 | |
|---|
| 288 | |
|---|
| 289 | |
|---|
| 290 | |
|---|
| 291 | |
|---|
| 292 | |
|---|
| 293 | |
|---|
| 294 | static MagickBooleanType WriteFAXImage(const ImageInfo *image_info,Image *image) |
|---|
| 295 | { |
|---|
| 296 | ImageInfo |
|---|
| 297 | *write_info; |
|---|
| 298 | |
|---|
| 299 | MagickBooleanType |
|---|
| 300 | status; |
|---|
| 301 | |
|---|
| 302 | MagickOffsetType |
|---|
| 303 | scene; |
|---|
| 304 | |
|---|
| 305 | |
|---|
| 306 | |
|---|
| 307 | |
|---|
| 308 | assert(image_info != (const ImageInfo *) NULL); |
|---|
| 309 | assert(image_info->signature == MagickSignature); |
|---|
| 310 | assert(image != (Image *) NULL); |
|---|
| 311 | assert(image->signature == MagickSignature); |
|---|
| 312 | if (image->debug != MagickFalse) |
|---|
| 313 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
|---|
| 314 | status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception); |
|---|
| 315 | if (status == MagickFalse) |
|---|
| 316 | return(status); |
|---|
| 317 | write_info=CloneImageInfo(image_info); |
|---|
| 318 | (void) CopyMagickString(write_info->magick,"FAX",MaxTextExtent); |
|---|
| 319 | scene=0; |
|---|
| 320 | do |
|---|
| 321 | { |
|---|
| 322 | |
|---|
| 323 | |
|---|
| 324 | |
|---|
| 325 | if (image->colorspace != RGBColorspace) |
|---|
| 326 | (void) TransformImageColorspace(image,RGBColorspace); |
|---|
| 327 | status=HuffmanEncodeImage(write_info,image,image); |
|---|
| 328 | if (GetNextImageInList(image) == (Image *) NULL) |
|---|
| 329 | break; |
|---|
| 330 | image=SyncNextImageInList(image); |
|---|
| 331 | status=SetImageProgress(image,SaveImagesTag,scene++, |
|---|
| 332 | GetImageListLength(image)); |
|---|
| 333 | if (status == MagickFalse) |
|---|
| 334 | break; |
|---|
| 335 | } while (write_info->adjoin != MagickFalse); |
|---|
| 336 | write_info=DestroyImageInfo(write_info); |
|---|
| 337 | (void) CloseBlob(image); |
|---|
| 338 | return(status); |
|---|
| 339 | } |
|---|