Added new function TIFFPredictorCleanup() to restore parent

decode/encode/field methods.
This commit is contained in:
Andrey Kiselev 2006-03-03 14:10:09 +00:00
parent 2dfa4ad011
commit 2ed09338d9
2 changed files with 32 additions and 3 deletions

View File

@ -1,4 +1,4 @@
/* $Id: tif_predict.c,v 1.10 2005-12-21 12:23:13 joris Exp $ */ /* $Id: tif_predict.c,v 1.11 2006-03-03 14:10:09 dron Exp $ */
/* /*
* Copyright (c) 1988-1997 Sam Leffler * Copyright (c) 1988-1997 Sam Leffler
@ -339,6 +339,7 @@ PredictorDecodeRow(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
assert(sp != NULL); assert(sp != NULL);
assert(sp->coderow != NULL); assert(sp->coderow != NULL);
assert(sp->pfunc != NULL); assert(sp->pfunc != NULL);
if ((*sp->coderow)(tif, op0, occ0, s)) { if ((*sp->coderow)(tif, op0, occ0, s)) {
(*sp->pfunc)(tif, op0, occ0); (*sp->pfunc)(tif, op0, occ0);
return 1; return 1;
@ -360,6 +361,7 @@ PredictorDecodeTile(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
assert(sp != NULL); assert(sp != NULL);
assert(sp->codetile != NULL); assert(sp->codetile != NULL);
if ((*sp->codetile)(tif, op0, occ0, s)) { if ((*sp->codetile)(tif, op0, occ0, s)) {
tsize_t rowsize = sp->rowsize; tsize_t rowsize = sp->rowsize;
assert(rowsize > 0); assert(rowsize > 0);
@ -481,7 +483,8 @@ PredictorEncodeRow(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
assert(sp != NULL); assert(sp != NULL);
assert(sp->pfunc != NULL); assert(sp->pfunc != NULL);
assert(sp->coderow != NULL); assert(sp->coderow != NULL);
/* XXX horizontal differencing alters user's data XXX */
/* XXX horizontal differencing alters user's data XXX */
(*sp->pfunc)(tif, bp, cc); (*sp->pfunc)(tif, bp, cc);
return (*sp->coderow)(tif, bp, cc, s); return (*sp->coderow)(tif, bp, cc, s);
} }
@ -496,6 +499,7 @@ PredictorEncodeTile(TIFF* tif, tidata_t bp0, tsize_t cc0, tsample_t s)
assert(sp != NULL); assert(sp != NULL);
assert(sp->pfunc != NULL); assert(sp->pfunc != NULL);
assert(sp->codetile != NULL); assert(sp->codetile != NULL);
rowsize = sp->rowsize; rowsize = sp->rowsize;
assert(rowsize > 0); assert(rowsize > 0);
while ((long)cc > 0) { while ((long)cc > 0) {
@ -519,6 +523,9 @@ PredictorVSetField(TIFF* tif, ttag_t tag, va_list ap)
{ {
TIFFPredictorState *sp = PredictorState(tif); TIFFPredictorState *sp = PredictorState(tif);
assert(sp != NULL);
assert(sp->vsetparent != NULL);
switch (tag) { switch (tag) {
case TIFFTAG_PREDICTOR: case TIFFTAG_PREDICTOR:
sp->predictor = (uint16) va_arg(ap, int); sp->predictor = (uint16) va_arg(ap, int);
@ -536,6 +543,9 @@ PredictorVGetField(TIFF* tif, ttag_t tag, va_list ap)
{ {
TIFFPredictorState *sp = PredictorState(tif); TIFFPredictorState *sp = PredictorState(tif);
assert(sp != NULL);
assert(sp->vgetparent != NULL);
switch (tag) { switch (tag) {
case TIFFTAG_PREDICTOR: case TIFFTAG_PREDICTOR:
*va_arg(ap, uint16*) = sp->predictor; *va_arg(ap, uint16*) = sp->predictor;
@ -570,6 +580,8 @@ TIFFPredictorInit(TIFF* tif)
{ {
TIFFPredictorState* sp = PredictorState(tif); TIFFPredictorState* sp = PredictorState(tif);
assert(sp != 0);
/* /*
* Merge codec-specific tag information and * Merge codec-specific tag information and
* override parent get/set field methods. * override parent get/set field methods.
@ -595,4 +607,20 @@ TIFFPredictorInit(TIFF* tif)
return 1; return 1;
} }
int
TIFFPredictorCleanup(TIFF* tif)
{
TIFFPredictorState* sp = PredictorState(tif);
assert(sp != 0);
tif->tif_tagmethods.vgetfield = sp->vgetparent;
tif->tif_tagmethods.vsetfield = sp->vsetparent;
tif->tif_tagmethods.printdir = sp->printdir;
tif->tif_setupdecode = sp->setupdecode;
tif->tif_setupencode = sp->setupencode;
return 1;
}
/* vim: set ts=8 sts=8 sw=8 noet: */ /* vim: set ts=8 sts=8 sw=8 noet: */

View File

@ -1,4 +1,4 @@
/* $Id: tif_predict.h,v 1.2 2005-04-14 11:57:30 dron Exp $ */ /* $Id: tif_predict.h,v 1.3 2006-03-03 14:10:09 dron Exp $ */
/* /*
* Copyright (c) 1995-1997 Sam Leffler * Copyright (c) 1995-1997 Sam Leffler
@ -55,6 +55,7 @@ typedef struct {
extern "C" { extern "C" {
#endif #endif
extern int TIFFPredictorInit(TIFF*); extern int TIFFPredictorInit(TIFF*);
extern int TIFFPredictorCleanup(TIFF*);
#if defined(__cplusplus) #if defined(__cplusplus)
} }
#endif #endif