00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
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
00060
00061
static MagickBooleanType
00062
WriteFAXImage(
const ImageInfo *,
Image *);
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
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
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
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
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
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
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
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
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
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260 ModuleExport void UnregisterFAXImage(
void)
00261 {
00262 (
void)
UnregisterMagickInfo(
"FAX");
00263 (
void)
UnregisterMagickInfo(
"G3");
00264 }
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
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
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
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 }