summaryrefslogtreecommitdiff
path: root/src/libtiff/tif_fax3.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libtiff/tif_fax3.c')
-rw-r--r--src/libtiff/tif_fax3.c129
1 files changed, 46 insertions, 83 deletions
diff --git a/src/libtiff/tif_fax3.c b/src/libtiff/tif_fax3.c
index 9c909c4..afca796 100644
--- a/src/libtiff/tif_fax3.c
+++ b/src/libtiff/tif_fax3.c
@@ -1,4 +1,4 @@
-/* $Id: tif_fax3.c,v 1.3 2009/12/11 15:17:41 scuri Exp $ */
+/* $Id: tif_fax3.c,v 1.4 2010/01/26 15:56:36 scuri Exp $ */
/*
* Copyright (c) 1990-1997 Sam Leffler
@@ -63,7 +63,6 @@ typedef struct {
char* faxdcs; /* Table 2/T.30 encoded session params */
TIFFVGetMethod vgetparent; /* super-class method */
TIFFVSetMethod vsetparent; /* super-class method */
- TIFFPrintMethod printdir; /* super-class method */
} Fax3BaseState;
#define Fax3State(tif) ((Fax3BaseState*) (tif)->tif_data)
@@ -86,8 +85,6 @@ typedef struct {
unsigned char* refline; /* reference line for 2d decoding */
int k; /* #rows left that can be 2d encoded */
int maxk; /* max #rows that can be 2d encoded */
-
- int line;
} Fax3CodecState;
#define DecoderState(tif) ((Fax3CodecState*) Fax3State(tif))
#define EncoderState(tif) ((Fax3CodecState*) Fax3State(tif))
@@ -170,7 +167,6 @@ Fax3PreDecode(TIFF* tif, tsample_t s)
sp->refruns[0] = (uint32) sp->b.rowpixels;
sp->refruns[1] = 0;
}
- sp->line = 0;
return (1);
}
@@ -183,46 +179,46 @@ Fax3PreDecode(TIFF* tif, tsample_t s)
static void
Fax3Unexpected(const char* module, TIFF* tif, uint32 line, uint32 a0)
{
- TIFFErrorExt(tif->tif_clientdata, module, "%s: Bad code word at line %u of %s %u (x %u)",
- tif->tif_name, line, isTiled(tif) ? "tile" : "strip",
- (isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip),
- a0);
+ TIFFErrorExt(tif->tif_clientdata, module, "%s: Bad code word at line %lu of %s %lu (x %lu)",
+ tif->tif_name, (unsigned long) line, isTiled(tif) ? "tile" : "strip",
+ (unsigned long) (isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip),
+ (unsigned long) a0);
}
-#define unexpected(table, a0) Fax3Unexpected(module, tif, sp->line, a0)
+#define unexpected(table, a0) Fax3Unexpected(module, tif, line, a0)
static void
Fax3Extension(const char* module, TIFF* tif, uint32 line, uint32 a0)
{
TIFFErrorExt(tif->tif_clientdata, module,
- "%s: Uncompressed data (not supported) at line %u of %s %u (x %u)",
- tif->tif_name, line, isTiled(tif) ? "tile" : "strip",
- (isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip),
- a0);
+ "%s: Uncompressed data (not supported) at line %lu of %s %lu (x %lu)",
+ tif->tif_name, (unsigned long) line, isTiled(tif) ? "tile" : "strip",
+ (unsigned long) (isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip),
+ (unsigned long) a0);
}
-#define extension(a0) Fax3Extension(module, tif, sp->line, a0)
+#define extension(a0) Fax3Extension(module, tif, line, a0)
static void
Fax3BadLength(const char* module, TIFF* tif, uint32 line, uint32 a0, uint32 lastx)
{
- TIFFWarningExt(tif->tif_clientdata, module, "%s: %s at line %u of %s %u (got %u, expected %u)",
- tif->tif_name,
- a0 < lastx ? "Premature EOL" : "Line length mismatch",
- line, isTiled(tif) ? "tile" : "strip",
- (isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip),
- a0, lastx);
+ TIFFWarningExt(tif->tif_clientdata, module, "%s: %s at line %lu of %s %lu (got %lu, expected %lu)",
+ tif->tif_name,
+ a0 < lastx ? "Premature EOL" : "Line length mismatch",
+ (unsigned long) line, isTiled(tif) ? "tile" : "strip",
+ (unsigned long) (isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip),
+ (unsigned long) a0, lastx);
}
-#define badlength(a0,lastx) Fax3BadLength(module, tif, sp->line, a0, lastx)
+#define badlength(a0,lastx) Fax3BadLength(module, tif, line, a0, lastx)
static void
Fax3PrematureEOF(const char* module, TIFF* tif, uint32 line, uint32 a0)
{
- TIFFWarningExt(tif->tif_clientdata, module, "%s: Premature EOF at line %u of %s %u (x %u)",
+ TIFFWarningExt(tif->tif_clientdata, module, "%s: Premature EOF at line %lu of %s %lu (x %lu)",
tif->tif_name,
- line, isTiled(tif) ? "tile" : "strip",
- (isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip),
- a0);
+ (unsigned long) line, isTiled(tif) ? "tile" : "strip",
+ (unsigned long) (isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip),
+ (unsigned long) a0);
}
-#define prematureEOF(a0) Fax3PrematureEOF(module, tif, sp->line, a0)
+#define prematureEOF(a0) Fax3PrematureEOF(module, tif, line, a0)
#define Nop
@@ -233,6 +229,7 @@ static int
Fax3Decode1D(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
{
DECLARE_STATE(tif, sp, "Fax3Decode1D");
+ int line = 0;
(void) s;
CACHE_STATE(tif, sp);
@@ -251,7 +248,7 @@ Fax3Decode1D(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
(*sp->fill)(buf, thisrun, pa, lastx);
buf += sp->b.rowbytes;
occ -= sp->b.rowbytes;
- sp->line++;
+ line++;
continue;
EOF1D: /* premature EOF */
CLEANUP_RUNS();
@@ -272,6 +269,7 @@ static int
Fax3Decode2D(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
{
DECLARE_STATE_2D(tif, sp, "Fax3Decode2D");
+ int line = 0;
int is1D; /* current line is 1d/2d-encoded */
(void) s;
@@ -304,7 +302,7 @@ Fax3Decode2D(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
SWAP(uint32*, sp->curruns, sp->refruns);
buf += sp->b.rowbytes;
occ -= sp->b.rowbytes;
- sp->line++;
+ line++;
continue;
EOF2D: /* premature EOF */
CLEANUP_RUNS();
@@ -494,14 +492,14 @@ Fax3SetupState(TIFF* tif)
);
nruns = needsRefLine ? 2*TIFFroundup(rowpixels,32) : rowpixels;
- nruns += 3;
- dsp->runs = (uint32*) _TIFFCheckMalloc(tif, 2*nruns, sizeof (uint32),
+
+ dsp->runs = (uint32*) _TIFFCheckMalloc(tif, 2*nruns+3, sizeof (uint32),
"for Group 3/4 run arrays");
if (dsp->runs == NULL)
return (0);
dsp->curruns = dsp->runs;
if (needsRefLine)
- dsp->refruns = dsp->runs + nruns;
+ dsp->refruns = dsp->runs + (nruns>>1);
else
dsp->refruns = NULL;
if (td->td_compression == COMPRESSION_CCITTFAX3
@@ -720,7 +718,6 @@ Fax3PreEncode(TIFF* tif, tsample_t s)
sp->k = sp->maxk-1;
} else
sp->k = sp->maxk = 0;
- sp->line = 0;
return (1);
}
@@ -776,7 +773,7 @@ static int32 find1span(unsigned char*, int32, int32);
* table. The ``base'' of the bit string is supplied
* along with the start+end bit indices.
*/
-static int32
+inline static int32
find0span(unsigned char* bp, int32 bs, int32 be)
{
int32 bits = be - bs;
@@ -835,7 +832,7 @@ find0span(unsigned char* bp, int32 bs, int32 be)
return (span);
}
-static int32
+inline static int32
find1span(unsigned char* bp, int32 bs, int32 be)
{
int32 bits = be - bs;
@@ -1077,7 +1074,6 @@ Fax3Cleanup(TIFF* tif)
tif->tif_tagmethods.vgetfield = sp->b.vgetparent;
tif->tif_tagmethods.vsetfield = sp->b.vsetparent;
- tif->tif_tagmethods.printdir = sp->b.printdir;
if (sp->runs)
_TIFFfree(sp->runs);
@@ -1086,9 +1082,6 @@ Fax3Cleanup(TIFF* tif)
if (Fax3State(tif)->subaddress)
_TIFFfree(Fax3State(tif)->subaddress);
- if (Fax3State(tif)->faxdcs)
- _TIFFfree(Fax3State(tif)->faxdcs);
-
_TIFFfree(tif->tif_data);
tif->tif_data = NULL;
@@ -1143,7 +1136,6 @@ static int
Fax3VSetField(TIFF* tif, ttag_t tag, va_list ap)
{
Fax3BaseState* sp = Fax3State(tif);
- const TIFFFieldInfo* fip;
assert(sp != 0);
assert(sp->vsetparent != 0);
@@ -1151,10 +1143,10 @@ Fax3VSetField(TIFF* tif, ttag_t tag, va_list ap)
switch (tag) {
case TIFFTAG_FAXMODE:
sp->mode = va_arg(ap, int);
- return 1; /* NB: pseudo tag */
+ return (1); /* NB: pseudo tag */
case TIFFTAG_FAXFILLFUNC:
DecoderState(tif)->fill = va_arg(ap, TIFFFaxFillFunc);
- return 1; /* NB: pseudo tag */
+ return (1); /* NB: pseudo tag */
case TIFFTAG_GROUP3OPTIONS:
/* XXX: avoid reading options if compression mismatches. */
if (tif->tif_dir.td_compression == COMPRESSION_CCITTFAX3)
@@ -1189,14 +1181,9 @@ Fax3VSetField(TIFF* tif, ttag_t tag, va_list ap)
default:
return (*sp->vsetparent)(tif, tag, ap);
}
-
- if ((fip = _TIFFFieldWithTag(tif, tag)))
- TIFFSetFieldBit(tif, fip->field_bit);
- else
- return 0;
-
+ TIFFSetFieldBit(tif, _TIFFFieldWithTag(tif, tag)->field_bit);
tif->tif_flags |= TIFF_DIRTYDIRECT;
- return 1;
+ return (1);
}
static int
@@ -1204,8 +1191,6 @@ Fax3VGetField(TIFF* tif, ttag_t tag, va_list ap)
{
Fax3BaseState* sp = Fax3State(tif);
- assert(sp != 0);
-
switch (tag) {
case TIFFTAG_FAXMODE:
*va_arg(ap, int*) = sp->mode;
@@ -1249,8 +1234,6 @@ Fax3PrintDir(TIFF* tif, FILE* fd, long flags)
{
Fax3BaseState* sp = Fax3State(tif);
- assert(sp != 0);
-
(void) flags;
if (TIFFFieldSet(tif,FIELD_OPTIONS)) {
const char* sep = " ";
@@ -1312,15 +1295,6 @@ InitCCITTFax3(TIFF* tif)
Fax3BaseState* sp;
/*
- * Merge codec-specific tag information.
- */
- if (!_TIFFMergeFieldInfo(tif, faxFieldInfo, N(faxFieldInfo))) {
- TIFFErrorExt(tif->tif_clientdata, "InitCCITTFax3",
- "Merging common CCITT Fax codec-specific tags failed");
- return 0;
- }
-
- /*
* Allocate state block so tag methods have storage to record values.
*/
tif->tif_data = (tidata_t)
@@ -1336,13 +1310,14 @@ InitCCITTFax3(TIFF* tif)
sp->rw_mode = tif->tif_mode;
/*
- * Override parent get/set field methods.
+ * Merge codec-specific tag information and
+ * override parent get/set field methods.
*/
+ _TIFFMergeFieldInfo(tif, faxFieldInfo, N(faxFieldInfo));
sp->vgetparent = tif->tif_tagmethods.vgetfield;
tif->tif_tagmethods.vgetfield = Fax3VGetField; /* hook for codec tags */
sp->vsetparent = tif->tif_tagmethods.vsetfield;
tif->tif_tagmethods.vsetfield = Fax3VSetField; /* hook for codec tags */
- sp->printdir = tif->tif_tagmethods.printdir;
tif->tif_tagmethods.printdir = Fax3PrintDir; /* hook for codec tags */
sp->groupoptions = 0;
sp->recvparams = 0;
@@ -1380,21 +1355,14 @@ TIFFInitCCITTFax3(TIFF* tif, int scheme)
{
(void) scheme;
if (InitCCITTFax3(tif)) {
- /*
- * Merge codec-specific tag information.
- */
- if (!_TIFFMergeFieldInfo(tif, fax3FieldInfo, N(fax3FieldInfo))) {
- TIFFErrorExt(tif->tif_clientdata, "TIFFInitCCITTFax3",
- "Merging CCITT Fax 3 codec-specific tags failed");
- return 0;
- }
+ _TIFFMergeFieldInfo(tif, fax3FieldInfo, N(fax3FieldInfo));
/*
* The default format is Class/F-style w/o RTC.
*/
return TIFFSetField(tif, TIFFTAG_FAXMODE, FAXMODE_CLASSF);
} else
- return 01;
+ return (0);
}
/*
@@ -1410,6 +1378,7 @@ static int
Fax4Decode(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
{
DECLARE_STATE_2D(tif, sp, "Fax4Decode");
+ int line = 0;
(void) s;
CACHE_STATE(tif, sp);
@@ -1432,7 +1401,7 @@ Fax4Decode(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
SWAP(uint32*, sp->curruns, sp->refruns);
buf += sp->b.rowbytes;
occ -= sp->b.rowbytes;
- sp->line++;
+ line++;
continue;
EOFG4:
NeedBits16( 13, BADG4 );
@@ -1488,14 +1457,7 @@ TIFFInitCCITTFax4(TIFF* tif, int scheme)
{
(void) scheme;
if (InitCCITTFax3(tif)) { /* reuse G3 support */
- /*
- * Merge codec-specific tag information.
- */
- if (!_TIFFMergeFieldInfo(tif, fax4FieldInfo, N(fax4FieldInfo))) {
- TIFFErrorExt(tif->tif_clientdata, "TIFFInitCCITTFax4",
- "Merging CCITT Fax 4 codec-specific tags failed");
- return 0;
- }
+ _TIFFMergeFieldInfo(tif, fax4FieldInfo, N(fax4FieldInfo));
tif->tif_decoderow = Fax4Decode;
tif->tif_decodestrip = Fax4Decode;
@@ -1525,6 +1487,7 @@ Fax3DecodeRLE(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
{
DECLARE_STATE(tif, sp, "Fax3DecodeRLE");
int mode = sp->b.mode;
+ int line = 0;
(void) s;
CACHE_STATE(tif, sp);
@@ -1554,7 +1517,7 @@ Fax3DecodeRLE(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
}
buf += sp->b.rowbytes;
occ -= sp->b.rowbytes;
- sp->line++;
+ line++;
continue;
EOFRLE: /* premature EOF */
(*sp->fill)(buf, thisrun, pa, lastx);