AWARE [SYSTEMS] Imaging expertise for the Delphi developer
AWare Systems, Imaging expertise for the Delphi developer, Home TIFF and LibTiff Mailing List Archive

LibTiff Mailing List

TIFF and LibTiff Mailing List Archive
September 2003

Previous Thread
Next Thread

Previous by Thread
Next by Thread

Previous by Date
Next by Date

Contact

The TIFF Mailing List Homepage
This list is run by Frank Warmerdam
Archive maintained by AWare Systems



Valid HTML 4.01!



2003.09.25 10:45 "Extended rational tag.", by Dave Christopher

Hi,

I'm new to libtiff and have been trying to read values
from an extended rational tag in a variant of a tiff
file. I've used Niles' code for this and replaced his
example tags with my own. However the values that I'm
getting when I try to read the tag are nonsense.
However, TIFFGetField doesn't return 0 so it suggests
that it can find the tag ok. Hence I guess I haven't
declared the correct data types in places.

I've copied the parts of the code that I've changed
below. Can anybody tell me what I've done wrong?!

Regards

Dave Christopher


// from tif_dir.c
static const TIFFFieldInfo xtiffFieldInfo[] = {
  
  /* XXX Replace these example tags with your own
extended tags */  
    { TIFFTAG_UIC3_STKINFO,	-1, -1, TIFF_RATIONAL,
FIELD_UIC3_STKINFO, TRUE, TRUE, "UIC3STKTag" },
};

static int
_XTIFFVSetField(TIFF* tif, ttag_t tag, va_list ap)
{
	xtiff *xt = XTIFFDIR(tif);
	XTIFFDirectory* xd = &xt->xtif_dir;
	int status = 1;
	uint32 v32=0;
	int i=0, v=0;
	va_list ap1 = ap;

	/* va_start is called by the calling routine */
	
	switch (tag) 
	{
		/* 
                 * XXX put your extended tags here;
replace the implemented
                 *     example tags with your own. 
                 */
    case TIFFTAG_UIC3_STKINFO:
		xd->xd_uic3_stkinfo_size = (uint32) va_arg(ap,
uint32);
/ *** in the long array here I've passed two * size as
I think size is the number of rationals, but I want
twice this number for the long array? *****/
		_TIFFsetLongArray( &xd->tag3_extra, (uint32*)
va_arg(ap, uint32*), (long) 2*xd->xd_uic3_stkinfo_size
);
		break;
	default:
		/* call the inherited method */
		return (PARENT(xt,vsetfield))(tif,tag,ap);
		break;
	}
	if (status) {
		/* we have to override the print method here,
 		 * after the compression tags have gotten to it.
		 * This makes sense because the only time we would
		 * need the extended print method is if an extended
		 * tag is set by the reader.
		 */
		if (!(xt->xtif_flags & XTIFFP_PRINT))
		{
	        	PARENT(xt,printdir) = 
TIFFMEMBER(tif,printdir);
      		  	TIFFMEMBER(tif,printdir) =
_XTIFFPrintDirectory;
			xt->xtif_flags |= XTIFFP_PRINT;
		}
		TIFFSetFieldBit(tif, _TIFFFieldWithTag(tif,
tag)->field_bit);
		tif->tif_flags |= TIFF_DIRTYDIRECT;
	}
	va_end(ap);
	return (status);
}


static int
_XTIFFVGetField(TIFF* tif, ttag_t tag, va_list ap)
{
	xtiff *xt = XTIFFDIR(tif);
	XTIFFDirectory* xd = &xt->xtif_dir;

	switch (tag) {
		/* 
                 * XXX put your extended tags here;
replace the implemented
                 *     example tags with your own.
                 */
    case TIFFTAG_UIC3_STKINFO:

	    *va_arg(ap, uint32*) = xd->xd_uic3_stkinfo_size;
		   *va_arg(ap, uint32**) = xd->tag3_extra;
		break;
	default:
		/* return inherited method */
		return (PARENT(xt,vgetfield))(tif,tag,ap);
		break;
	}
	return (1);
}

/// From tiffiop.h
/* XXX - Define number of your extended tags here */
#define NUM_XFIELD 1
#define XFIELD_BASE (FIELD_LAST-NUM_XFIELD)

/*  XXX - Define your Tag Fields here  */
#define	FIELD_UIC3_STKINFO      (XFIELD_BASE+0)



/* XXX - Define Private directory tag structure here
*/
struct XTIFFDirectory 
{
	uint32   xd_uic3_stkinfo_size;
 uint32*  tag3_extra;
};
typedef struct XTIFFDirectory XTIFFDirectory;