📄 tif_dir.c
字号:
case TIFFTAG_STONITS:
d = va_arg(ap, dblparam_t);
if (d <= 0.)
goto badvaluedbl;
td->td_stonits = d;
break;
/* Begin Pixar Tags */
case TIFFTAG_PIXAR_IMAGEFULLWIDTH:
td->td_imagefullwidth = va_arg(ap, uint32);
break;
case TIFFTAG_PIXAR_IMAGEFULLLENGTH:
td->td_imagefulllength = va_arg(ap, uint32);
break;
case TIFFTAG_PIXAR_TEXTUREFORMAT:
_TIFFsetString(&td->td_textureformat, va_arg(ap, char*));
break;
case TIFFTAG_PIXAR_WRAPMODES:
_TIFFsetString(&td->td_wrapmodes, va_arg(ap, char*));
break;
case TIFFTAG_PIXAR_FOVCOT:
td->td_fovcot = (float) va_arg(ap, dblparam_t);
break;
case TIFFTAG_PIXAR_MATRIX_WORLDTOSCREEN:
_TIFFsetFloatArray(&td->td_matrixWorldToScreen,
va_arg(ap, float*), 16);
break;
case TIFFTAG_PIXAR_MATRIX_WORLDTOCAMERA:
_TIFFsetFloatArray(&td->td_matrixWorldToCamera,
va_arg(ap, float*), 16);
break;
/* End Pixar Tags */
case TIFFTAG_SUBIFD:
if ((tif->tif_flags & TIFF_INSUBIFD) == 0) {
td->td_nsubifd = (uint16) va_arg(ap, int);
_TIFFsetLongArray(&td->td_subifd, va_arg(ap, uint32*),
(long) td->td_nsubifd);
} else {
TIFFError(module, "%s: Sorry, cannot nest SubIFDs",
tif->tif_name);
status = 0;
}
break;
case TIFFTAG_YCBCRCOEFFICIENTS:
_TIFFsetFloatArray(&td->td_ycbcrcoeffs, va_arg(ap, float*), 3);
break;
case TIFFTAG_YCBCRPOSITIONING:
td->td_ycbcrpositioning = (uint16) va_arg(ap, int);
break;
case TIFFTAG_YCBCRSUBSAMPLING:
td->td_ycbcrsubsampling[0] = (uint16) va_arg(ap, int);
td->td_ycbcrsubsampling[1] = (uint16) va_arg(ap, int);
break;
case TIFFTAG_WHITEPOINT:
_TIFFsetFloatArray(&td->td_whitepoint, va_arg(ap, float*), 2);
break;
case TIFFTAG_PRIMARYCHROMATICITIES:
_TIFFsetFloatArray(&td->td_primarychromas, va_arg(ap, float*), 6);
break;
case TIFFTAG_TRANSFERFUNCTION:
v = (td->td_samplesperpixel - td->td_extrasamples) > 1 ? 3 : 1;
for (i = 0; i < v; i++)
_TIFFsetShortArray(&td->td_transferfunction[i],
va_arg(ap, uint16*), 1L<<td->td_bitspersample);
break;
case TIFFTAG_REFERENCEBLACKWHITE:
/* XXX should check for null range */
_TIFFsetFloatArray(&td->td_refblackwhite, va_arg(ap, float*), 6);
break;
case TIFFTAG_INKSET:
td->td_inkset = (uint16) va_arg(ap, int);
break;
case TIFFTAG_DOTRANGE:
/* XXX should check for null range */
td->td_dotrange[0] = (uint16) va_arg(ap, int);
td->td_dotrange[1] = (uint16) va_arg(ap, int);
break;
case TIFFTAG_INKNAMES:
i = va_arg(ap, int);
s = va_arg(ap, char*);
i = checkInkNamesString(tif, i, s);
status = i > 0;
if( i > 0 ) {
_TIFFsetNString(&td->td_inknames, s, i);
td->td_inknameslen = i;
}
break;
case TIFFTAG_NUMBEROFINKS:
td->td_ninks = (uint16) va_arg(ap, int);
break;
case TIFFTAG_TARGETPRINTER:
_TIFFsetString(&td->td_targetprinter, va_arg(ap, char*));
break;
case TIFFTAG_ICCPROFILE:
td->td_profileLength = (uint32) va_arg(ap, uint32);
_TIFFsetByteArray(&td->td_profileData, va_arg(ap, void*),
td->td_profileLength);
break;
case TIFFTAG_PHOTOSHOP:
td->td_photoshopLength = (uint32) va_arg(ap, uint32);
_TIFFsetByteArray (&td->td_photoshopData, va_arg(ap, void*),
td->td_photoshopLength);
break;
case TIFFTAG_RICHTIFFIPTC:
td->td_richtiffiptcLength = (uint32) va_arg(ap, uint32);
_TIFFsetLongArray ((uint32**)&td->td_richtiffiptcData,
va_arg(ap, uint32*),
td->td_richtiffiptcLength);
break;
case TIFFTAG_XMLPACKET:
td->td_xmlpacketLength = (uint32) va_arg(ap, uint32);
_TIFFsetByteArray(&td->td_xmlpacketData, va_arg(ap, void*),
td->td_xmlpacketLength);
break;
default: {
const TIFFFieldInfo* fip = _TIFFFindFieldInfo(tif, tag, TIFF_ANY);
TIFFTagValue *tv;
int tv_size, iCustom;
/*
* This can happen if multiple images are open with
* different codecs which have private tags. The
* global tag information table may then have tags
* that are valid for one file but not the other.
* If the client tries to set a tag that is not valid
* for the image's codec then we'll arrive here. This
* happens, for example, when tiffcp is used to convert
* between compression schemes and codec-specific tags
* are blindly copied.
*/
if( fip == NULL || fip->field_bit != FIELD_CUSTOM )
{
TIFFError(module,
"%s: Invalid %stag \"%s\" (not supported by codec)",
tif->tif_name, isPseudoTag(tag) ? "pseudo-" : "",
_TIFFFieldWithTag(tif, tag)->field_name);
status = 0;
break;
}
/*
* Find the existing entry for this custom value.
*/
tv = NULL;
for( iCustom = 0; iCustom < td->td_customValueCount; iCustom++ )
{
if( td->td_customValues[iCustom].info == fip )
{
tv = td->td_customValues + iCustom;
if( tv->value != NULL )
_TIFFfree( tv->value );
break;
}
}
/*
* Grow the custom list if the entry was not found.
*/
if( tv == NULL )
{
TIFFTagValue *new_customValues;
td->td_customValueCount++;
new_customValues = (TIFFTagValue *)
_TIFFrealloc(td->td_customValues,
sizeof(TIFFTagValue) * td->td_customValueCount);
if (!new_customValues) {
TIFFError(module,
"%s: Failed to allocate space for list of custom values",
tif->tif_name);
status = 0;
goto end;
}
td->td_customValues = new_customValues;
tv = td->td_customValues + (td->td_customValueCount-1);
tv->info = fip;
tv->value = NULL;
tv->count = 0;
}
/*
* Set custom value ... save a copy of the custom tag value.
*/
switch (fip->field_type) {
/*
* XXX: We can't use TIFFDataWidth() to determine the
* space needed to store the value. For TIFF_RATIONAL
* values TIFFDataWidth() returns 8, but we use 4-byte
* float to represent rationals.
*/
case TIFF_BYTE:
case TIFF_ASCII:
case TIFF_SBYTE:
case TIFF_UNDEFINED:
tv_size = 1;
break;
case TIFF_SHORT:
case TIFF_SSHORT:
tv_size = 2;
break;
case TIFF_LONG:
case TIFF_SLONG:
case TIFF_FLOAT:
case TIFF_IFD:
case TIFF_RATIONAL:
case TIFF_SRATIONAL:
tv_size = 4;
break;
case TIFF_DOUBLE:
tv_size = 8;
break;
default:
status = 0;
TIFFError(module, "%s: Bad field type %d for \"%s\"",
tif->tif_name, fip->field_type,
fip->field_name);
goto end;
}
if(fip->field_passcount)
tv->count = (int) va_arg(ap, int);
else
tv->count = 1;
if (fip->field_passcount) {
tv->value = _TIFFmalloc(tv_size * tv->count);
if ( !tv->value ) {
status = 0;
goto end;
}
_TIFFmemcpy(tv->value, (void *) va_arg(ap,void*),
tv->count * tv_size);
} else if (fip->field_type == TIFF_ASCII) {
const char *value = (const char *) va_arg(ap,const char *);
tv->count = strlen(value)+1;
tv->value = _TIFFmalloc(tv->count);
if (!tv->value) {
status = 0;
goto end;
}
strcpy(tv->value, value);
} else {
/* not supporting "pass by value" types yet */
TIFFError(module,
"%s: Pass by value is not implemented.",
tif->tif_name);
tv->value = _TIFFmalloc(tv_size * tv->count);
if (!tv->value) {
status = 0;
goto end;
}
_TIFFmemset(tv->value, 0, tv->count * tv_size);
status = 0;
}
}
}
if (status) {
TIFFSetFieldBit(tif, _TIFFFieldWithTag(tif, tag)->field_bit);
tif->tif_flags |= TIFF_DIRTYDIRECT;
}
end:
va_end(ap);
return (status);
badvalue:
TIFFError(module, "%s: Bad value %d for \"%s\"",
tif->tif_name, v, _TIFFFieldWithTag(tif, tag)->field_name);
va_end(ap);
return (0);
badvalue32:
TIFFError(module, "%s: Bad value %ld for \"%s\"",
tif->tif_name, v32, _TIFFFieldWithTag(tif, tag)->field_name);
va_end(ap);
return (0);
badvaluedbl:
TIFFError(module, "%s: Bad value %f for \"%s\"",
tif->tif_name, d, _TIFFFieldWithTag(tif, tag)->field_name);
va_end(ap);
return (0);
}
/*
* Return 1/0 according to whether or not
* it is permissible to set the tag's value.
* Note that we allow ImageLength to be changed
* so that we can append and extend to images.
* Any other tag may not be altered once writing
* has commenced, unless its value has no effect
* on the format of the data that is written.
*/
static int
OkToChangeTag(TIFF* tif, ttag_t tag)
{
const TIFFFieldInfo* fip = _TIFFFindFieldInfo(tif, tag, TIFF_ANY);
if (!fip) { /* unknown tag */
TIFFError("TIFFSetField", "%s: Unknown %stag %u",
tif->tif_name, isPseudoTag(tag) ? "pseudo-" : "", tag);
return (0);
}
if (tag != TIFFTAG_IMAGELENGTH && (tif->tif_flags & TIFF_BEENWRITING) &&
!fip->field_oktochange) {
/*
* Consult info table to see if tag can be changed
* after we've started writing. We only allow changes
* to those tags that don't/shouldn't affect the
* compression and/or format of the data.
*/
TIFFError("TIFFSetField",
"%s: Cannot modify tag \"%s\" while writing",
tif->tif_name, fip->field_name);
return (0);
}
return (1);
}
/*
* Record the value of a field in the
* internal directory structure. The
* field will be written to the file
* when/if the directory structure is
* updated.
*/
int
TIFFSetField(TIFF* tif, ttag_t tag, ...)
{
va_list ap;
int status;
va_start(ap, tag);
status = TIFFVSetField(tif, tag, ap);
va_end(ap);
return (status);
}
/*
* Like TIFFSetField, but taking a varargs
* parameter list. This routine is useful
* for building higher-level interfaces on
* top of the library.
*/
int
TIFFVSetField(TIFF* tif, ttag_t tag, va_list ap)
{
return OkToChangeTag(tif, tag) ?
(*tif->tif_tagmethods.vsetfield)(tif, tag, ap) : 0;
}
static int
_TIFFVGetField(TIFF* tif, ttag_t tag, va_list ap)
{
TIFFDirectory* td = &tif->tif_dir;
int ret_val = 1;
switch (tag) {
case TIFFTAG_SUBFILETYPE:
*va_arg(ap, uint32*) = td->td_subfiletype;
break;
case TIFFTAG_IMAGEWIDTH:
*va_arg(ap, uint32*) = td->td_imagewidth;
break;
case TIFFTAG_IMAGELENGTH:
*va_arg(ap, uint32*) = td->td_imagelength;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -