Handle all data types in custom tags.

This commit is contained in:
Andrey Kiselev 2005-03-21 10:17:37 +00:00
parent 5cdbfc3664
commit 78cf75a417
2 changed files with 45 additions and 17 deletions

View File

@ -1,4 +1,4 @@
/* $Id: tif_dir.c,v 1.45 2005-03-18 13:29:39 dron Exp $ */
/* $Id: tif_dir.c,v 1.46 2005-03-21 10:17:37 dron Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
@ -553,8 +553,7 @@ _TIFFVSetField(TIFF* tif, ttag_t tag, va_list ap)
if (tv_size == 0) {
status = 0;
TIFFError(module, "%s: Bad field type %d for \"%s\"",
tif->tif_name, fip->field_type,
fip->field_name);
tif->tif_name, fip->field_type, fip->field_name);
goto end;
}
@ -563,8 +562,7 @@ _TIFFVSetField(TIFF* tif, ttag_t tag, va_list ap)
tv->count = (uint32) va_arg(ap, uint32);
else
tv->count = (int) va_arg(ap, int);
}
else if (fip->field_writecount == TIFF_VARIABLE
} else if (fip->field_writecount == TIFF_VARIABLE
|| fip->field_writecount == TIFF_VARIABLE2)
tv->count = 1;
else if (fip->field_writecount == TIFF_SPP)
@ -602,21 +600,32 @@ _TIFFVSetField(TIFF* tif, ttag_t tag, va_list ap)
case TIFF_SBYTE:
case TIFF_SHORT:
case TIFF_SSHORT:
case TIFF_UNDEFINED:
{
int v = va_arg(ap, int);
_TIFFmemcpy(tv->value, &v, tv_size*tv->count);
}
break;
case TIFF_LONG:
case TIFF_IFD:
{
uint32 v32 = va_arg(ap, uint32);
_TIFFmemcpy(tv->value, &v32, tv_size*tv->count);
uint32 v = va_arg(ap, uint32);
_TIFFmemcpy(tv->value, &v, tv_size*tv->count);
}
break;
case TIFF_SLONG:
{
int32 v32 = va_arg(ap, int32);
_TIFFmemcpy(tv->value, &v32, tv_size*tv->count);
int32 v = va_arg(ap, int32);
_TIFFmemcpy(tv->value, &v, tv_size*tv->count);
}
break;
case TIFF_RATIONAL:
case TIFF_SRATIONAL:
case TIFF_FLOAT:
case TIFF_DOUBLE:
{
double v = va_arg(ap, double);
_TIFFmemcpy(tv->value, &v, tv_size*tv->count);
}
break;
default:
@ -1018,6 +1027,7 @@ _TIFFVGetField(TIFF* tif, ttag_t tag, va_list ap)
} else {
switch (fip->field_type) {
case TIFF_BYTE:
case TIFF_UNDEFINED:
*va_arg(ap, uint8*) =
*(uint8 *)tv->value;
ret_val = 1;
@ -1038,6 +1048,7 @@ _TIFFVGetField(TIFF* tif, ttag_t tag, va_list ap)
ret_val = 1;
break;
case TIFF_LONG:
case TIFF_IFD:
*va_arg(ap, uint32*) =
*(uint32 *)tv->value;
ret_val = 1;
@ -1047,6 +1058,18 @@ _TIFFVGetField(TIFF* tif, ttag_t tag, va_list ap)
*(int32 *)tv->value;
ret_val = 1;
break;
case TIFF_RATIONAL:
case TIFF_SRATIONAL:
case TIFF_FLOAT:
*va_arg(ap, float*) =
*(float *)tv->value;
ret_val = 1;
break;
case TIFF_DOUBLE:
*va_arg(ap, double*) =
*(double *)tv->value;
ret_val = 1;
break;
default:
ret_val = 0;
break;

View File

@ -1,4 +1,4 @@
/* $Id: tif_print.c,v 1.21 2005-03-18 13:29:39 dron Exp $ */
/* $Id: tif_print.c,v 1.22 2005-03-21 10:17:37 dron Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
@ -538,7 +538,9 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags)
if(fip->field_type == TIFF_BYTE)
fprintf(fd, "%u",
(unsigned int) ((unsigned char *) raw_data)[j]);
else if(fip->field_type == TIFF_SBYTE)
else if(fip->field_type == TIFF_UNDEFINED)
fprintf(fd, "0x%x",
(unsigned int) ((unsigned char *) raw_data)[j]); else if(fip->field_type == TIFF_SBYTE)
fprintf(fd, "%d", (int) ((char *) raw_data)[j]);
else if(fip->field_type == TIFF_SHORT)
fprintf(fd, "%u",
@ -550,10 +552,13 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags)
(int)((unsigned long *) raw_data)[j]);
else if(fip->field_type == TIFF_SLONG)
fprintf(fd, "%ld", (long)((long *) raw_data)[j]);
else if(fip->field_type == TIFF_RATIONAL)
fprintf(fd, "%f", ((float *) raw_data)[j]);
else if(fip->field_type == TIFF_SRATIONAL)
else if(fip->field_type == TIFF_RATIONAL
|| fip->field_type == TIFF_SRATIONAL
|| fip->field_type == TIFF_FLOAT)
fprintf(fd, "%f", ((float *) raw_data)[j]);
else if(fip->field_type == TIFF_IFD)
fprintf(fd, "0x%x",
(int)((unsigned long *) raw_data)[j]);
else if(fip->field_type == TIFF_ASCII) {
fprintf(fd, "%s", (char *) raw_data);
break;