#pragma warning (disable : 4786) // identifier was truncated to 'number' characters
#endif
-#include "../LibTIFF4/tiffiop.h"
+#include <tiffio.h>
#include "FreeImage.h"
#include "Utilities.h"
#include "FreeImageTag.h"
#include "FIRational.h"
+/*
+ * Caveat emperor this is a private libtiff functions which we need,
+ * there is no better solution I'm afraid.
+ */
+extern "C"
+{
+ int _TIFFDataSize(TIFFDataType type);
+}
+
// ----------------------------------------------------------
// Extended TIFF Directory GEO Tag Support
// ----------------------------------------------------------
Read a single exif tag
*/
static BOOL
-tiff_read_exif_tag(TIFF *tif, TagLib::MDMODEL md_model, FIBITMAP *dib, TagLib& tagLib, TIFFDirectory *td, uint32 tag) {
+tiff_read_exif_tag(TIFF *tif, TagLib::MDMODEL md_model, FIBITMAP *dib, TagLib& tagLib, uint32 tag) {
const TIFFField *fip;
uint32 value_count;
int mem_alloc = 0;
return TRUE;
}
- if(fip->field_passcount) { //<- "passcount" means "returns count"
- if (fip->field_readcount != TIFF_VARIABLE2) { //<- TIFF_VARIABLE2 means "uses LONG count"
+ if(TIFFFieldPassCount(fip)) { //<- "passcount" means "returns count"
+ if (TIFFFieldReadCount(fip) != TIFF_VARIABLE2) { //<- TIFF_VARIABLE2 means "uses LONG count"
// assume TIFF_VARIABLE (uses SHORT count)
uint16 value_count16;
// determine count
- if (fip->field_readcount == TIFF_VARIABLE || fip->field_readcount == TIFF_VARIABLE2) {
+ if (TIFFFieldReadCount(fip) == TIFF_VARIABLE || TIFFFieldReadCount(fip) == TIFF_VARIABLE2) {
value_count = 1;
- } else if (fip->field_readcount == TIFF_SPP) {
- value_count = td->td_samplesperpixel;
+ } else if (TIFFFieldReadCount(fip) == TIFF_SPP) {
+ uint16 spp;
+ TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLESPERPIXEL, &spp);
+ value_count = spp;
} else {
- value_count = fip->field_readcount;
+ value_count = TIFFFieldReadCount(fip);
}
// access fields as pointers to data
// (### determining this is NOT robust... and hardly can be. It is implemented looking the _TIFFVGetField code)
- if(fip->field_tag == TIFFTAG_TRANSFERFUNCTION) {
+ if(TIFFFieldTag(fip) == TIFFTAG_TRANSFERFUNCTION) {
// reading this tag cause a bug probably located somewhere inside libtiff
return TRUE;
}
- if ((fip->field_type == TIFF_ASCII
- || fip->field_readcount == TIFF_VARIABLE
- || fip->field_readcount == TIFF_VARIABLE2
- || fip->field_readcount == TIFF_SPP
+ if ((TIFFFieldDataType(fip) == TIFF_ASCII
+ || TIFFFieldReadCount(fip) == TIFF_VARIABLE
+ || TIFFFieldReadCount(fip) == TIFF_VARIABLE2
+ || TIFFFieldReadCount(fip) == TIFF_SPP
|| value_count > 1)
- && fip->field_tag != TIFFTAG_PAGENUMBER
- && fip->field_tag != TIFFTAG_HALFTONEHINTS
- && fip->field_tag != TIFFTAG_YCBCRSUBSAMPLING
- && fip->field_tag != TIFFTAG_DOTRANGE
+ && TIFFFieldTag(fip) != TIFFTAG_PAGENUMBER
+ && TIFFFieldTag(fip) != TIFFTAG_HALFTONEHINTS
+ && TIFFFieldTag(fip) != TIFFTAG_YCBCRSUBSAMPLING
+ && TIFFFieldTag(fip) != TIFFTAG_DOTRANGE
- && fip->field_tag != TIFFTAG_BITSPERSAMPLE //<- these two are tricky -
- && fip->field_tag != TIFFTAG_COMPRESSION //<- they are defined as TIFF_VARIABLE but in reality return a single value
+ && TIFFFieldTag(fip) != TIFFTAG_BITSPERSAMPLE //<- these two are tricky:
+ && TIFFFieldTag(fip) != TIFFTAG_COMPRESSION //<- they are defined as TIFF_VARIABLE but in reality return a single value
) {
if(TIFFGetField(tif, tag, &raw_data) != 1) {
return TRUE;
// access fields as values
- const int value_size = _TIFFDataSize(fip->field_type);
+ const int value_size = _TIFFDataSize((TIFFFieldDataType(fip)));
raw_data = _TIFFmalloc(value_size * value_count);
mem_alloc = 1;
int ok = FALSE;
break;
*/
default:
- FreeImage_OutputMessageProc(FIF_TIFF, "Unimplemented variable number of parameters for Tiff Tag %s", fip->field_name);
+ FreeImage_OutputMessageProc(FIF_TIFF, "Unimplemented variable number of parameters for Tiff Tag %s", TIFFFieldName(fip));
break;
}
if(ok != 1) {
FreeImage_SetTagID(fitag, (WORD)tag);
FreeImage_SetTagKey(fitag, key);
- switch(fip->field_type) {
+ switch(TIFFFieldDataType(fip)) {
case TIFF_BYTE:
FreeImage_SetTagType(fitag, FIDT_BYTE);
- FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count);
+ FreeImage_SetTagLength(fitag, TIFFDataWidth(TIFFFieldDataType(fip)) * value_count);
FreeImage_SetTagCount(fitag, value_count);
FreeImage_SetTagValue(fitag, raw_data);
break;
case TIFF_UNDEFINED:
FreeImage_SetTagType(fitag, FIDT_UNDEFINED);
- FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count);
+ FreeImage_SetTagLength(fitag, TIFFDataWidth(TIFFFieldDataType(fip)) * value_count);
FreeImage_SetTagCount(fitag, value_count);
FreeImage_SetTagValue(fitag, raw_data);
break;
case TIFF_SBYTE:
FreeImage_SetTagType(fitag, FIDT_SBYTE);
- FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count);
+ FreeImage_SetTagLength(fitag, TIFFDataWidth(TIFFFieldDataType(fip)) * value_count);
FreeImage_SetTagCount(fitag, value_count);
FreeImage_SetTagValue(fitag, raw_data);
break;
case TIFF_SHORT:
FreeImage_SetTagType(fitag, FIDT_SHORT);
- FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count);
+ FreeImage_SetTagLength(fitag, TIFFDataWidth(TIFFFieldDataType(fip)) * value_count);
FreeImage_SetTagCount(fitag, value_count);
FreeImage_SetTagValue(fitag, raw_data);
break;
case TIFF_SSHORT:
FreeImage_SetTagType(fitag, FIDT_SSHORT);
- FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count);
+ FreeImage_SetTagLength(fitag, TIFFDataWidth(TIFFFieldDataType(fip)) * value_count);
FreeImage_SetTagCount(fitag, value_count);
FreeImage_SetTagValue(fitag, raw_data);
break;
case TIFF_LONG:
FreeImage_SetTagType(fitag, FIDT_LONG);
- FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count);
+ FreeImage_SetTagLength(fitag, TIFFDataWidth(TIFFFieldDataType(fip)) * value_count);
FreeImage_SetTagCount(fitag, value_count);
FreeImage_SetTagValue(fitag, raw_data);
break;
case TIFF_IFD:
FreeImage_SetTagType(fitag, FIDT_IFD);
- FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count);
+ FreeImage_SetTagLength(fitag, TIFFDataWidth(TIFFFieldDataType(fip)) * value_count);
FreeImage_SetTagCount(fitag, value_count);
FreeImage_SetTagValue(fitag, raw_data);
break;
case TIFF_SLONG:
FreeImage_SetTagType(fitag, FIDT_SLONG);
- FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count);
+ FreeImage_SetTagLength(fitag, TIFFDataWidth(TIFFFieldDataType(fip)) * value_count);
FreeImage_SetTagCount(fitag, value_count);
FreeImage_SetTagValue(fitag, raw_data);
break;
rvalue[2*i+1] = rational.getDenominator();
}
FreeImage_SetTagType(fitag, FIDT_RATIONAL);
- FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count);
+ FreeImage_SetTagLength(fitag, TIFFDataWidth(TIFFFieldDataType(fip)) * value_count);
FreeImage_SetTagCount(fitag, value_count);
FreeImage_SetTagValue(fitag, rvalue);
free(rvalue);
rvalue[2*i+1] = rational.getDenominator();
}
FreeImage_SetTagType(fitag, FIDT_RATIONAL);
- FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count);
+ FreeImage_SetTagLength(fitag, TIFFDataWidth(TIFFFieldDataType(fip)) * value_count);
FreeImage_SetTagCount(fitag, value_count);
FreeImage_SetTagValue(fitag, rvalue);
free(rvalue);
case TIFF_FLOAT:
FreeImage_SetTagType(fitag, FIDT_FLOAT);
- FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count);
+ FreeImage_SetTagLength(fitag, TIFFDataWidth(TIFFFieldDataType(fip)) * value_count);
FreeImage_SetTagCount(fitag, value_count);
FreeImage_SetTagValue(fitag, raw_data);
break;
case TIFF_DOUBLE:
FreeImage_SetTagType(fitag, FIDT_DOUBLE);
- FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count);
+ FreeImage_SetTagLength(fitag, TIFFDataWidth(TIFFFieldDataType(fip)) * value_count);
FreeImage_SetTagCount(fitag, value_count);
FreeImage_SetTagValue(fitag, raw_data);
break;
case TIFF_LONG8: // BigTIFF 64-bit unsigned integer
FreeImage_SetTagType(fitag, FIDT_LONG8);
- FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count);
+ FreeImage_SetTagLength(fitag, TIFFDataWidth(TIFFFieldDataType(fip)) * value_count);
FreeImage_SetTagCount(fitag, value_count);
FreeImage_SetTagValue(fitag, raw_data);
break;
case TIFF_IFD8: // BigTIFF 64-bit unsigned integer (offset)
FreeImage_SetTagType(fitag, FIDT_IFD8);
- FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count);
+ FreeImage_SetTagLength(fitag, TIFFDataWidth(TIFFFieldDataType(fip)) * value_count);
FreeImage_SetTagCount(fitag, value_count);
FreeImage_SetTagValue(fitag, raw_data);
break;
case TIFF_SLONG8: // BigTIFF 64-bit signed integer
FreeImage_SetTagType(fitag, FIDT_SLONG8);
- FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count);
+ FreeImage_SetTagLength(fitag, TIFFDataWidth(TIFFFieldDataType(fip)) * value_count);
FreeImage_SetTagCount(fitag, value_count);
FreeImage_SetTagValue(fitag, raw_data);
break;
default: {
// remember that raw_data = _TIFFmalloc(value_size * value_count);
- const int value_size = _TIFFDataSize(fip->field_type);
+ const int value_size = _TIFFDataSize(TIFFFieldDataType(fip));
size_t length = value_size * value_count;
FreeImage_SetTagType(fitag, FIDT_ASCII);
FreeImage_SetTagLength(fitag, (DWORD)length);
TagLib& tagLib = TagLib::instance();
- TIFFDirectory *td = &tif->tif_dir;
-
count = (short) TIFFGetTagListCount(tif);
for(i = 0; i < count; i++) {
uint32 tag = TIFFGetTagListEntry(tif, i);
// read the tag
- if (!tiff_read_exif_tag(tif, md_model, dib, tagLib, td, tag))
+ if (!tiff_read_exif_tag(tif, md_model, dib, tagLib, tag))
return FALSE;
}
+/* Disabled for Fedora as it is using internal library structures. */
+#if 0
// we want to know values of standard tags too!!
// loop over all Core Directory Tags
// process *all* other tags (some will be ignored)
- tiff_read_exif_tag(tif, md_model, dib, tagLib, td, fld->field_tag);
+ tiff_read_exif_tag(tif, md_model, dib, tagLib, fld->field_tag);
lastTag = fld->field_tag;
}
}
+#endif
return TRUE;
*/
BOOL
tiff_write_exif_tags(TIFF *tif, TagLib::MDMODEL md_model, FIBITMAP *dib) {
+/* Disabled for Fedora as it is using internal library structures. Siberia
+ * winter on upstream developer! :-) */
+ return FALSE;
+#if 0
char defaultKey[16];
// only EXIF_MAIN so far
}
return TRUE;
+#endif
}