Unbundle: libtiff, disable G3 plugin, field access functions in XTIFF.cpp.
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Tue, 14 Jan 2014 17:34:11 +0000 (18:34 +0100)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Tue, 14 Jan 2014 19:05:59 +0000 (20:05 +0100)
FreeImage.2008.vcproj
Source/FreeImage.h
Source/FreeImage/Plugin.cpp
Source/FreeImage/PluginTIFF.cpp
Source/Metadata/XTIFF.cpp

index 55b2a4e..85f2606 100644 (file)
                                        >\r
                                </File>\r
                                <File\r
-                                       RelativePath="Source\FreeImage\PluginG3.cpp"\r
-                                       >\r
-                               </File>\r
-                               <File\r
                                        RelativePath="Source\FreeImage\PluginGIF.cpp"\r
                                        >\r
                                </File>\r
index 54d9cea..35ea5c6 100644 (file)
@@ -396,7 +396,12 @@ FI_ENUM(FREE_IMAGE_FORMAT) {
        FIF_DDS         = 24,
        FIF_GIF     = 25,
        FIF_HDR         = 26,
+/* The G3 fax format plugin is deliberately disabled in the Fedora build of
+   FreeImage as it requires that FreeImage uses a private copy of libtiff
+   which is a no no because of security reasons. */
+#if 0
        FIF_FAXG3       = 27,
+#endif
        FIF_SGI         = 28,
        FIF_EXR         = 29,
        FIF_J2K         = 30,
index d688f1a..d6287a2 100644 (file)
@@ -258,7 +258,12 @@ FreeImage_Initialise(BOOL load_local_plugins_only) {
                        s_plugins->AddNode(InitDDS);
                s_plugins->AddNode(InitGIF);
                s_plugins->AddNode(InitHDR);
+/* The G3 fax format plugin is deliberately disabled in the Fedora build of
+   FreeImage as it requires that FreeImage uses a private copy of libtiff
+   which is a no no because of security reasons. */
+#if 0
                        s_plugins->AddNode(InitG3);
+#endif
                        s_plugins->AddNode(InitSGI);
                        s_plugins->AddNode(InitEXR);
                        s_plugins->AddNode(InitJ2K);
index 456612b..2dd4e07 100644 (file)
@@ -37,7 +37,7 @@
 
 #include "FreeImage.h"
 #include "Utilities.h"
-#include "../LibTIFF4/tiffiop.h"
+#include <tiffio.h>
 #include "../Metadata/FreeImageTag.h"
 #include <half.h>
 
@@ -202,27 +202,9 @@ TIFFFdOpen(thandle_t handle, const char *name, const char *mode) {
            _tiffReadProc, _tiffWriteProc, _tiffSeekProc, _tiffCloseProc,
            _tiffSizeProc, _tiffMapProc, _tiffUnmapProc);
 
-       // Warning: tif_fd is declared as 'int' currently (see libTIFF), 
-    // may result in incorrect file pointers inside libTIFF on 
-    // 64bit machines (sizeof(int) != sizeof(long)). 
-    // Needs to be fixed within libTIFF.
-       if (tif) {
-               tif->tif_fd = (long)handle;
-       }
-
        return tif;
 }
 
-/**
-Open a TIFF file for reading or writing
-@param name
-@param mode
-*/
-TIFF*
-TIFFOpen(const char* name, const char* mode) {
-       return 0;
-}
-
 // ----------------------------------------------------------
 //   TIFF library FreeImage-specific routines.
 // ----------------------------------------------------------
index 94ccc48..41dbe6f 100644 (file)
 #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
 // ----------------------------------------------------------
@@ -205,7 +214,7 @@ tiff_write_geotiff_profile(TIFF *tif, FIBITMAP *dib) {
 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;
@@ -226,8 +235,8 @@ tiff_read_exif_tag(TIFF *tif, TagLib::MDMODEL md_model, FIBITMAP *dib, TagLib& t
                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;
@@ -244,35 +253,37 @@ tiff_read_exif_tag(TIFF *tif, TagLib::MDMODEL md_model, FIBITMAP *dib, TagLib& t
 
                // 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;
@@ -281,7 +292,7 @@ tiff_read_exif_tag(TIFF *tif, TagLib::MDMODEL md_model, FIBITMAP *dib, TagLib& t
 
                        // 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;
@@ -302,7 +313,7 @@ tiff_read_exif_tag(TIFF *tif, TagLib::MDMODEL md_model, FIBITMAP *dib, TagLib& t
                                        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) {
@@ -325,59 +336,59 @@ tiff_read_exif_tag(TIFF *tif, TagLib::MDMODEL md_model, FIBITMAP *dib, TagLib& t
        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;
@@ -392,7 +403,7 @@ tiff_read_exif_tag(TIFF *tif, TagLib::MDMODEL md_model, FIBITMAP *dib, TagLib& t
                                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);
@@ -409,7 +420,7 @@ tiff_read_exif_tag(TIFF *tif, TagLib::MDMODEL md_model, FIBITMAP *dib, TagLib& t
                                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);
@@ -418,42 +429,42 @@ tiff_read_exif_tag(TIFF *tif, TagLib::MDMODEL md_model, FIBITMAP *dib, TagLib& t
 
                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);
@@ -489,16 +500,16 @@ tiff_read_exif_tags(TIFF *tif, TagLib::MDMODEL md_model, FIBITMAP *dib) {
 
        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
@@ -533,13 +544,14 @@ tiff_read_exif_tags(TIFF *tif, TagLib::MDMODEL md_model, FIBITMAP *dib) {
 
                        // 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;
 
@@ -611,6 +623,10 @@ Write all known exif tags
 */
 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
@@ -662,4 +678,5 @@ tiff_write_exif_tags(TIFF *tif, TagLib::MDMODEL md_model, FIBITMAP *dib) {
        }
 
        return TRUE;
+#endif
 }