Blender TIFF support
authorMatt Ebb <matt@mke3.net>
Fri, 21 May 2010 03:25:38 +0000 (03:25 +0000)
committerMatt Ebb <matt@mke3.net>
Fri, 21 May 2010 03:25:38 +0000 (03:25 +0000)
* Removed dynamic linking libTIFF code and change it to static linking
(built into the blender executable). Dynamic linking made things a
fair bit more complicated and wasn't working at all before on OS X -
the dylib didn't exist and wasn't being copied. Since TIFF is more heavily
depended upon now in Blender, it makes sense to make it less 'optional'
and more in line with other libraries.

I've updated both CMake and scons, and CMake on OS X/64bit works fine.
It's now up to other platform/build system maintainers to enable this for
their respective platforms (Campbell will check it for linux). For windows,
and non-64bit osx, we need static libtiff libraries in /lib.

I've added options WITH_TIFF for CMake and WITH_BF_TIFF for scons,
so if blender won't build because of this, you should be able to disable
these options until your build system has been updated.

* Bonus feature: while doing this, I added support for loading 16bit and 32bit
per channel TIFFs - they get converted to Blender's float buffers. Handy for
zbrush displacement maps!

31 files changed:
CMake/macros.cmake
CMakeLists.txt
config/darwin-config.py
config/linux2-config.py
config/win32-mingw-config.py
config/win32-vc-config.py
config/win64-vc-config.py
source/blender/blenkernel/BKE_global.h
source/blender/blenkernel/CMakeLists.txt
source/blender/blenkernel/SConscript
source/blender/blenkernel/intern/image.c
source/blender/editors/CMakeLists.txt
source/blender/editors/space_file/SConscript
source/blender/editors/space_file/writeimage.c
source/blender/editors/space_image/SConscript
source/blender/editors/space_image/image_ops.c
source/blender/imbuf/CMakeLists.txt
source/blender/imbuf/SConscript
source/blender/imbuf/intern/dynlibtiff.c [deleted file]
source/blender/imbuf/intern/dynlibtiff.h [deleted file]
source/blender/imbuf/intern/filetype.c
source/blender/imbuf/intern/tiff.c
source/blender/imbuf/intern/util.c
source/blender/makesrna/SConscript
source/blender/makesrna/intern/CMakeLists.txt
source/blender/makesrna/intern/rna_scene.c
source/creator/CMakeLists.txt
source/creator/SConscript
source/creator/creator.c
tools/Blender.py
tools/btools.py

index 73458d7312e80cb595d304970dfc0a2d631d6651..54b14dbd5ce4e0efff485b2d097ea101fd8b8737 100644 (file)
@@ -61,6 +61,9 @@ MACRO(SETUP_LIBDIRS)
   IF(WITH_OPENEXR)
     LINK_DIRECTORIES(${OPENEXR_LIBPATH})
   ENDIF(WITH_OPENEXR)
+  IF(WITH_TIFF)
+    LINK_DIRECTORIES(${TIFF_LIBPATH})
+  ENDIF(WITH_TIFF)
   IF(WITH_QUICKTIME)
     LINK_DIRECTORIES(${QUICKTIME_LIBPATH})
   ENDIF(WITH_QUICKTIME)
@@ -134,6 +137,9 @@ MACRO(SETUP_LIBLINKS
   IF(WITH_QUICKTIME)
     TARGET_LINK_LIBRARIES(${target} ${QUICKTIME_LIB})
   ENDIF(WITH_QUICKTIME)
+  IF(WITH_TIFF)
+    TARGET_LINK_LIBRARIES(${target} ${TIFF_LIBRARY})
+  ENDIF(WITH_TIFF)
   IF(WITH_OPENEXR)
     IF(WIN32)
       FOREACH(loop_var ${OPENEXR_LIB})
index 038b61e56a687f86dbd5b7a6f5408d8c935a656b..57a6e8998fdeea111f3f2e48ee2017b946a44736 100644 (file)
@@ -63,6 +63,7 @@ OPTION(WITH_BULLET        "Enable Bullet (Physics Engine)" ON)
 OPTION(WITH_INTERNATIONAL "Enable I18N   (International fonts and text)" ON)
 OPTION(WITH_ELBEEM        "Enable Elbeem (Fluid Simulation)" ON)
 OPTION(WITH_OPENEXR       "Enable OpenEXR Support (http://www.openexr.com)" ON)
+OPTION(WITH_TIFF          "Enable LibTIFF Support" ON)
 OPTION(WITH_DDS           "Enable DDS Support" ON)
 OPTION(WITH_FFMPEG        "Enable FFMPeg Support (http://ffmpeg.mplayerhq.hu/)" OFF)
 OPTION(WITH_PYTHON        "Enable Embedded Python API" ON)
@@ -410,6 +411,8 @@ IF(WIN32)
 
        SET(TIFF ${LIBDIR}/tiff)
        SET(TIFF_INC ${TIFF}/include)
+       SET(TIFF_LIBRARY tiff)
+       SET(TIFF_LIBPATH ${TIFF}/lib)
   
        SET(WINTAB_INC ${LIBDIR}/wintab/include) 
 
@@ -586,6 +589,8 @@ IF(APPLE)
 
        SET(TIFF ${LIBDIR}/tiff)
        SET(TIFF_INC ${TIFF}/include)
+       SET(TIFF_LIBRARY tiff)
+       SET(TIFF_LIBPATH ${TIFF}/lib)
 
        SET(EXETYPE MACOSX_BUNDLE)
 
index bac4c9ab165a4a14267621025b5d3bd5ed5010a6..2c3d0a7e87e93909be80fb4f0d4e6892e94be46c 100644 (file)
@@ -163,8 +163,11 @@ BF_PNG_INC = '${BF_PNG}/include'
 BF_PNG_LIB = 'png'
 BF_PNG_LIBPATH = '${BF_PNG}/lib'
 
+WITH_BF_TIFF = True
 BF_TIFF = LIBDIR + '/tiff'
 BF_TIFF_INC = '${BF_TIFF}/include'
+BF_TIFF_LIB = 'tiff'
+BF_TIFF_LIBPATH = '${BF_TIFF}/lib'
 
 WITH_BF_ZLIB = True
 BF_ZLIB = '/usr'
index 3951dac2454fdfddcb11b3791c0230a7e46a5dfc..199ea391d4e5b409ccb4d659eafb3590a20d4d46 100644 (file)
@@ -68,8 +68,10 @@ BF_PNG = '/usr'
 BF_PNG_INC = '${BF_PNG}/include'
 BF_PNG_LIB = 'png'
 
+WITH_BF_TIFF = True
 BF_TIFF = '/usr'
 BF_TIFF_INC = '${BF_TIFF}/include'
+BF_TIFF_LIB = 'tiff'
 
 WITH_BF_ZLIB = True
 BF_ZLIB = '/usr'
index 9088db5a5d8493422bdbe9b6dbf3860a0a5a07d9..319c9b264f2966702a0ec793bfc7a2c8cb202db9 100644 (file)
@@ -73,6 +73,7 @@ BF_PNG_INC = '${BF_PNG}/include'
 BF_PNG_LIB = 'png'
 BF_PNG_LIBPATH = '${BF_PNG}/lib'
 
+WITH_BF_TIFF = True
 BF_TIFF = LIBDIR + '/tiff'
 BF_TIFF_INC = '${BF_TIFF}/include'
 BF_TIFF_LIB = 'libtiff'
index 3e8dfc3d5dfbbe2ae374d76248d9373a8d50d3a4..b3766247d2de9797d7ed8cd89ce54f46859ac178 100644 (file)
@@ -79,6 +79,7 @@ BF_PNG_INC = '${BF_PNG}/include'
 BF_PNG_LIB = 'libpng_st'
 BF_PNG_LIBPATH = '${BF_PNG}/lib'
 
+WITH_BF_TIFF = True
 BF_TIFF = LIBDIR + '/tiff'
 BF_TIFF_INC = '${BF_TIFF}/include'
 BF_TIFF_LIB = 'libtiff'
index 41772dea14b5c6de76e0f363be0a6d196ed64b9f..c1cbb7cfee8384bb68dd1a7d7eedfaa24a96c356 100644 (file)
@@ -75,6 +75,7 @@ BF_PNG_INC = '${BF_PNG}/include'
 BF_PNG_LIB = 'libpng'
 BF_PNG_LIBPATH = '${BF_PNG}/lib'
 
+WITH_BF_TIFF = True
 BF_TIFF = LIBDIR + '/tiff'
 BF_TIFF_INC = '${BF_TIFF}/include'
 BF_TIFF_LIB = 'libtiff'
index 291deb5ea702b74a33381275cfeb6d464db7d2e7..6a602339e111cda407c689b7275dc58bef47a18e 100644 (file)
@@ -83,9 +83,6 @@ typedef struct Global {
        struct VFont *selfont;
        struct ListBase ttfdata;
 
-       /* libtiff flag used to determine if shared library loaded for libtiff*/
-       int have_libtiff;
-
        /* this variable is written to / read from FileGlobal->fileflags */
        int fileflags;
     
index afb29fbcd628319ddd401156f9b81e4fb37ac216..68684bcc0a15203dcd9491b60d00ec357ce56f15 100644 (file)
@@ -50,6 +50,10 @@ IF(WITH_OPENEXR)
        ADD_DEFINITIONS(-DWITH_OPENEXR)
 ENDIF(WITH_OPENEXR)
 
+IF(WITH_TIFF)
+       ADD_DEFINITIONS(-DWITH_TIFF)
+ENDIF(WITH_TIFF)
+
 IF(WITH_OPENJPEG)
        ADD_DEFINITIONS(-DWITH_OPENJPEG)
 ENDIF(WITH_OPENJPEG)
index 57d7e45d986545d03a0ddf3e9ba5cf9b74bd0d00..6198520c853a3b2a57dfd92b70f507dc2dac6ce6 100644 (file)
@@ -38,6 +38,9 @@ else:
 if env['WITH_BF_OPENEXR']:
        defs.append('WITH_OPENEXR')
 
+if env['WITH_BF_TIFF']:
+       defs.append('WITH_TIFF')
+
 if env['WITH_BF_OPENJPEG']:
        defs.append('WITH_OPENJPEG')
 
index eb478eaddf5c3180cf644b5c646681a5bf5f0e64..5588c8df161e55cee5e476b062c689f0f2e7ccbb 100644 (file)
@@ -779,10 +779,12 @@ void BKE_add_image_extension(char *string, int imtype)
                if(!BLI_testextensie(string, ".bmp"))
                        extension= ".bmp";
        }
-       else if(G.have_libtiff && (imtype==R_TIFF)) {
+#ifdef WITH_TIFF
+       else if(imtype==R_TIFF) {
                if(!BLI_testextensie(string, ".tif") && 
                        !BLI_testextensie(string, ".tiff")) extension= ".tif";
        }
+#endif
 #ifdef WITH_OPENEXR
        else if( ELEM(imtype, R_OPENEXR, R_MULTILAYER)) {
                if(!BLI_testextensie(string, ".exr"))
@@ -1187,12 +1189,14 @@ int BKE_write_ibuf(Scene *scene, ImBuf *ibuf, char *name, int imtype, int subimt
        else if ((imtype==R_BMP)) {
                ibuf->ftype= BMP;
        }
-       else if ((G.have_libtiff) && (imtype==R_TIFF)) {
+#ifdef WITH_TIFF
+       else if (imtype==R_TIFF) {
                ibuf->ftype= TIF;
 
                if(subimtype & R_TIFF_16BIT)
                        ibuf->ftype |= TIF_16BIT;
        }
+#endif
 #ifdef WITH_OPENEXR
        else if (imtype==R_OPENEXR || imtype==R_MULTILAYER) {
                ibuf->ftype= OPENEXR;
index 86085aa0573e494bbe52a36746e9b352f886453f..bf379ae3ca6ed1bc883a35f301d06e55580c237e 100644 (file)
@@ -57,6 +57,10 @@ IF(WITH_OPENEXR)
        ADD_DEFINITIONS(-DWITH_OPENEXR)
 ENDIF(WITH_OPENEXR)
 
+IF(WITH_TIFF)
+       ADD_DEFINITIONS(-DWITH_TIFF)
+ENDIF(WITH_TIFF)
+
 IF(WITH_OPENJPEG)
        ADD_DEFINITIONS(-DWITH_OPENJPEG)
 ENDIF(WITH_OPENJPEG)
index b22a265dcbc05df02a3ee7136da0dc5abaf9aa98..9de705e99d37c0cb32e258e8431168027b164160 100644 (file)
@@ -12,9 +12,13 @@ defs = []
 
 if env['WITH_BF_OPENJPEG']:
     defs.append('WITH_OPENJPEG')
+
 if env['WITH_BF_OPENEXR']:
        defs.append('WITH_OPENEXR')
 
+if env['WITH_BF_TIFF']:
+       defs.append('WITH_TIFF')
+
 if env['OURPLATFORM'] == 'linux2':
     cflags='-pthread'
     incs += ' ../../../extern/binreloc/include'
index c9b30983b93cb779f12f7477daa025e167969571..05efdc125966119e824c1a5bc57e22ef67096b9c 100644 (file)
@@ -143,10 +143,11 @@ void save_image_filesel_str(Scene *scene, char *str)
                case R_BMP:
                        strcpy(str, "Save BMP");
                        break;
+#ifdef WITH_TIFF
                case R_TIFF:
-                       if (G.have_libtiff)
-                               strcpy(str, "Save TIFF");
+                       strcpy(str, "Save TIFF");
                        break;
+#endif
 #ifdef WITH_OPENEXR
                case R_OPENEXR:
                        strcpy(str, "Save OpenEXR");
index dd43559645d93dd3fd25d91859a3179d387f2279..b38e1473a0c86d4a34756a86a2efe9488d1d9f0d 100644 (file)
@@ -13,6 +13,8 @@ if env['WITH_BF_LCMS']:
        defs.append('WITH_LCMS')
 if env['WITH_BF_OPENEXR']:
        defs.append('WITH_OPENEXR')
+if env['WITH_BF_TIFF']:
+       defs.append('WITH_TIFF')
     
 if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc'):
     incs += ' ' + env['BF_PTHREADS_INC']
index 274d26c8760aea106d02a9c7b2aef63fc33aac7d..64d24ed578ab87673f9c6cce511587d945c81361 100644 (file)
@@ -637,8 +637,9 @@ static const EnumPropertyItem image_file_type_items[] = {
                {R_JP2, "JPEG_2000", 0, "Jpeg 2000", ""},
 #endif
                {R_IRIS, "IRIS", 0, "Iris", ""},
-       //if(G.have_libtiff)
+#ifdef WITH_TIFF
                {R_TIFF, "TIFF", 0, "Tiff", ""},
+#endif
                {R_RADHDR, "RADIANCE_HDR", 0, "Radiance HDR", ""},
                {R_CINEON, "CINEON", 0, "Cineon", ""},
                {R_DPX, "DPX", 0, "DPX", ""},
index 5af39cea8326991556cb7ea077947ad157e1b871..6940ac8514f084596acf248df1964e7ea3163c53 100644 (file)
@@ -32,7 +32,6 @@ SET(INC
        ../avi ../blenkernel
        ${JPEG_INC}
        ${PNG_INC}
-       ${TIFF_INC}
        ${ZLIB_INC}
        ${OPENJPEG_INC}
 )
@@ -45,6 +44,11 @@ IF(WITH_OPENEXR)
        ADD_DEFINITIONS(-DWITH_OPENEXR)
 ENDIF(WITH_OPENEXR)
 
+IF(WITH_TIFF)
+       SET(INC ${INC} ${TIFF_INC})
+       ADD_DEFINITIONS(-DWITH_TIFF)
+ENDIF(WITH_TIFF)
+
 IF(WITH_OPENJPEG)
        ADD_DEFINITIONS(-DWITH_OPENJPEG)
 ENDIF(WITH_OPENJPEG)
index b4f56df9ec03a4aab45dcba35fa075aa0c6c342f..439cdecdf5b065d94e79ea8839512d6cdbe4360c 100644 (file)
@@ -20,6 +20,9 @@ if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc'):
 if env['WITH_BF_OPENEXR']:
     defs.append('WITH_OPENEXR')
 
+if env['WITH_BF_TIFF']:
+    defs.append('WITH_TIFF')
+
 if env['WITH_BF_DDS']:
     defs.append('WITH_DDS')
 
diff --git a/source/blender/imbuf/intern/dynlibtiff.c b/source/blender/imbuf/intern/dynlibtiff.c
deleted file mode 100644 (file)
index eb1b5f8..0000000
+++ /dev/null
@@ -1,280 +0,0 @@
-/**
- * Dynamically loaded libtiff support.
- *
- * This file is automatically generated by the gen_dynlibtiff.py script.
- * 
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): Jonathan Merritt.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-/**
- * To use the dynamic libtiff support, you must initialize the library using:
- *     libtiff_init()
- * This attempts to load libtiff dynamically at runtime.  G.have_libtiff will
- * be set to indicate whether or not libtiff is available.  If libtiff is
- * not available, Blender can proceed with no ill effects, provided that
- * it does not attempt to use any of the libtiff_ functions.  When you're
- * finished, close the library with:
- *     libtiff_exit()
- * These functions are both declared in IMB_imbuf.h
- *
- * The functions provided by dyn_libtiff.h are the same as those in the
- * normal static / shared libtiff, except that they are prefixed by the 
- * string "libtiff_" to indicate that they belong to a dynamically-loaded 
- * version.
- */
-#include "dynlibtiff.h"
-
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "BLI_blenlib.h"
-
-#include "imbuf.h"
-#include "IMB_imbuf.h"
-
-#include "BKE_global.h"
-#include "PIL_dynlib.h"
-
-/*********************
- * LOCAL DEFINITIONS *
- *********************/
-PILdynlib *libtiff = NULL;
-void  libtiff_loadlibtiff(void);
-void* libtiff_findsymbol(char*);
-int   libtiff_load_symbols(void);
-
-
-/**************************
- * LIBRARY INITIALIZATION *
- **************************/
-
-void libtiff_loadlibtiff(void)
-{
-       char *filename;
-       libtiff = NULL;
-
-       filename = getenv("BF_TIFF_LIB");
-       if (filename) libtiff = PIL_dynlib_open(filename);
-       if (libtiff != NULL)  return;
-
-       /* Try to find libtiff in a couple of standard places */
-#ifdef __APPLE__
-       /* OSX has version specific library */
-       //standard install location
-       libtiff = PIL_dynlib_open("/usr/local/lib/libtiff.dylib");
-       if (libtiff != NULL)  return;
-       libtiff = PIL_dynlib_open("/usr/local/lib/libtiff.3.dylib");
-       if (libtiff != NULL)  return;
-       libtiff = PIL_dynlib_open("/usr/local/lib/libtiff.4.dylib");
-       if (libtiff != NULL)  return;
-       //inside the blender app package contents/resources
-       libtiff = PIL_dynlib_open("@executable_path/../resources/libtiff.dylib");
-       if (libtiff != NULL)  return;
-       libtiff = PIL_dynlib_open("@executable_path/../resources/libtiff.3.dylib");
-       if (libtiff != NULL)  return;
-       libtiff = PIL_dynlib_open("@executable_path/../resources/libtiff.4.dylib");
-       if (libtiff != NULL)  return;
-       //inside the blender app package contents/frameworks
-       libtiff = PIL_dynlib_open("@executable_path/../frameworks/libtiff.dylib");
-       if (libtiff != NULL)  return;
-       libtiff = PIL_dynlib_open("@executable_path/../frameworks/libtiff.3.dylib");
-       if (libtiff != NULL)  return;
-       libtiff = PIL_dynlib_open("@executable_path/../frameworks/libtiff.4.dylib");
-       if (libtiff != NULL)  return;
-       //along side the blender app package
-       libtiff = PIL_dynlib_open("@executable_path/../../../libtiff.dylib");
-       if (libtiff != NULL)  return;
-       libtiff = PIL_dynlib_open("@executable_path/../../../libtiff.3.dylib");
-       if (libtiff != NULL)  return;
-       libtiff = PIL_dynlib_open("@executable_path/../../../libtiff.4.dylib");
-       if (libtiff != NULL)  return;
-       //inside the blender app package contents/MacOS
-       libtiff = PIL_dynlib_open("@executable_path/libtiff.dylib");
-       if (libtiff != NULL)  return;
-       libtiff = PIL_dynlib_open("@executable_path/libtiff.3.dylib");
-       if (libtiff != NULL)  return;
-       libtiff = PIL_dynlib_open("@executable_path/libtiff.4.dylib");
-       if (libtiff != NULL)  return;
-#else
-       libtiff = PIL_dynlib_open("libtiff.so");
-       if (libtiff != NULL)  return;
-       libtiff = PIL_dynlib_open("libtiff.so.3");
-       if (libtiff != NULL)  return;
-       libtiff = PIL_dynlib_open("libtiff.so.4");
-       if (libtiff != NULL)  return;
-       libtiff = PIL_dynlib_open("libtiff.dll");
-       if (libtiff != NULL)  return;
-       libtiff = PIL_dynlib_open("/usr/lib/libtiff.so");
-       if (libtiff != NULL)  return;
-       libtiff = PIL_dynlib_open("/usr/lib/libtiff.so.3");
-       if (libtiff != NULL)  return;
-       libtiff = PIL_dynlib_open("/usr/lib/libtiff.so.4");
-       if (libtiff != NULL)  return;
-#ifdef __x86_64__
-       libtiff = PIL_dynlib_open("/usr/lib64/libtiff.so");
-       if (libtiff != NULL)  return;
-       libtiff = PIL_dynlib_open("/usr/lib64/libtiff.so.3");
-       if (libtiff != NULL)  return;
-       libtiff = PIL_dynlib_open("/usr/lib64/libtiff.so.4");
-       if (libtiff != NULL)  return;
-#endif
-       libtiff = PIL_dynlib_open("/usr/local/lib/libtiff.so");
-       if (libtiff != NULL)  return;
-       /* For solaris */
-       libtiff = PIL_dynlib_open("/usr/openwin/lib/libtiff.so");
-#endif
-
-}
-
-void *libtiff_findsymbol(char *name)
-{
-       void *symbol = NULL;
-       assert(libtiff != NULL);
-       symbol = PIL_dynlib_find_symbol(libtiff, name);
-       if (symbol == NULL) {
-               char *err = PIL_dynlib_get_error_as_string(libtiff);
-
-               if (err) printf("libtiff_findsymbol: error %s\n",err);
-               else printf("libtiff_findsymbol: error Unknown.\n");
-
-               libtiff = NULL;
-               G.have_libtiff = (0);
-               return NULL;
-       }
-       return symbol;
-}
-
-void libtiff_init(void)
-{
-       if (libtiff != NULL) {
-               printf("libtiff_init: Attempted to load libtiff twice!\n");
-               return;
-       }
-       libtiff_loadlibtiff();
-       G.have_libtiff = ((libtiff != NULL) && (libtiff_load_symbols()));
-
-       if (!G.have_libtiff && (G.f & G_DEBUG)) {
-               printf("Unable to load: libtiff.\n");
-               printf("Try setting the BF_TIFF_LIB environment variable if you want this support.\n");
-               printf("Example: setenv BF_TIFF_LIB /usr/lib/libtiff.so\n");
-       }
-}
-
-void libtiff_exit(void)
-{
-       if (libtiff != NULL) {
-               PIL_dynlib_close(libtiff);
-               libtiff = NULL;
-       }
-}
-
-
-int libtiff_load_symbols(void)
-{
-       /* Attempt to load TIFFClientOpen */
-       libtiff_TIFFClientOpen = libtiff_findsymbol("TIFFClientOpen");
-       if (libtiff_TIFFClientOpen == NULL) {
-               return (0);
-       }
-       /* Attempt to load TIFFClose */
-       libtiff_TIFFClose = libtiff_findsymbol("TIFFClose");
-       if (libtiff_TIFFClose == NULL) {
-               return (0);
-       }
-       /* Attempt to load TIFFGetField */
-       libtiff_TIFFGetField = libtiff_findsymbol("TIFFGetField");
-       if (libtiff_TIFFGetField == NULL) {
-               return (0);
-       }
-       /* Attempt to load TIFFOpen */
-       libtiff_TIFFOpen = libtiff_findsymbol("TIFFOpen");
-       if (libtiff_TIFFOpen == NULL) {
-               return (0);
-       }
-       /* Attempt to load TIFFReadRGBAImage */
-       libtiff_TIFFReadRGBAImage = libtiff_findsymbol("TIFFReadRGBAImage");
-       if (libtiff_TIFFReadRGBAImage == NULL) {
-               return (0);
-       }
-       /* Attempt to load TIFFSetField */
-       libtiff_TIFFSetField = libtiff_findsymbol("TIFFSetField");
-       if (libtiff_TIFFSetField == NULL) {
-               return (0);
-       }
-       /* Attempt to load TIFFWriteEncodedStrip */
-       libtiff_TIFFWriteEncodedStrip = libtiff_findsymbol("TIFFWriteEncodedStrip");
-       if (libtiff_TIFFWriteEncodedStrip == NULL) {
-               return (0);
-       }
-       /* Attempt to load _TIFFfree */
-       libtiff__TIFFfree = libtiff_findsymbol("_TIFFfree");
-       if (libtiff__TIFFfree == NULL) {
-               return (0);
-       }
-       /* Attempt to load _TIFFmalloc */
-       libtiff__TIFFmalloc = libtiff_findsymbol("_TIFFmalloc");
-       if (libtiff__TIFFmalloc == NULL) {
-               return (0);
-       }
-       /* Attempt to load TIFFSetDirectory */
-       libtiff_TIFFSetDirectory = libtiff_findsymbol("TIFFSetDirectory");
-       if (libtiff_TIFFSetDirectory == NULL) {
-               return (0);
-       }
-       /* Attempt to load TIFFNumberOfDirectories */
-       libtiff_TIFFNumberOfDirectories = libtiff_findsymbol("TIFFNumberOfDirectories");
-       if (libtiff_TIFFNumberOfDirectories == NULL) {
-               return (0);
-       }
-       /* Attempt to load TIFFIsTiled */
-       libtiff_TIFFIsTiled = libtiff_findsymbol("TIFFIsTiled");
-       if (libtiff_TIFFIsTiled == NULL) {
-               return (0);
-       }
-       /* Attempt to load TIFFReadRGBATile */
-       libtiff_TIFFReadRGBATile = libtiff_findsymbol("TIFFReadRGBATile");
-       if (libtiff_TIFFReadRGBATile == NULL) {
-               return (0);
-       }
-       return (1);
-}
-
-       
-/*******************
- * SYMBOL POINTERS *
- *******************/
-
-TIFF* (*libtiff_TIFFClientOpen)(const char*, const char*, thandle_t, TIFFReadWriteProc, TIFFReadWriteProc, TIFFSeekProc, TIFFCloseProc, TIFFSizeProc, TIFFMapFileProc, TIFFUnmapFileProc) = NULL;
-void (*libtiff_TIFFClose)(TIFF*) = NULL;
-int (*libtiff_TIFFGetField)(TIFF*, ttag_t, ...) = NULL;
-TIFF* (*libtiff_TIFFOpen)(const char*, const char*) = NULL;
-int (*libtiff_TIFFReadRGBAImage)(TIFF*, uint32, uint32, uint32*, int) = NULL;
-int (*libtiff_TIFFSetField)(TIFF*, ttag_t, ...) = NULL;
-tsize_t (*libtiff_TIFFWriteEncodedStrip)(TIFF*, tstrip_t, tdata_t, tsize_t) = NULL;
-void (*libtiff__TIFFfree)(tdata_t) = NULL;
-tdata_t (*libtiff__TIFFmalloc)(tsize_t) = NULL;
-int (*libtiff_TIFFSetDirectory)(TIFF*, tdir_t) = NULL;
-tdir_t (*libtiff_TIFFNumberOfDirectories)(TIFF*) = NULL;
-int (*libtiff_TIFFIsTiled)(TIFF*) = NULL;
-int (*libtiff_TIFFReadRGBATile)(TIFF*, uint32, uint32, uint32 * ) = NULL;
-
-
diff --git a/source/blender/imbuf/intern/dynlibtiff.h b/source/blender/imbuf/intern/dynlibtiff.h
deleted file mode 100644 (file)
index 5fafafb..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
- * Dynamically loaded libtiff support.
- *
- * This file is automatically generated by the gen_dynlibtiff.py script.
- * 
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): Jonathan Merritt.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-/**
- * To use the dynamic libtiff support, you must initialize the library using:
- *     libtiff_init()
- * This attempts to load libtiff dynamically at runtime.  G.have_libtiff will
- * be set to indicate whether or not libtiff is available.  If libtiff is
- * not available, Blender can proceed with no ill effects, provided that
- * it does not attempt to use any of the libtiff_ functions.  When you're
- * finished, close the library with:
- *     libtiff_exit()
- * These functions are both declared in IMB_imbuf.h
- *
- * The functions provided by dyn_libtiff.h are the same as those in the
- * normal static / shared libtiff, except that they are prefixed by the 
- * string "libtiff_" to indicate that they belong to a dynamically-loaded 
- * version.
- */
-#ifndef DYN_LIBTIFF_H
-#include "tiffio.h"
-extern TIFF* (*libtiff_TIFFClientOpen)(const char*, const char*, thandle_t, TIFFReadWriteProc, TIFFReadWriteProc, TIFFSeekProc, TIFFCloseProc, TIFFSizeProc, TIFFMapFileProc, TIFFUnmapFileProc);
-extern void (*libtiff_TIFFClose)(TIFF*);
-extern int (*libtiff_TIFFGetField)(TIFF*, ttag_t, ...);
-extern TIFF* (*libtiff_TIFFOpen)(const char*, const char*);
-extern int (*libtiff_TIFFReadRGBAImage)(TIFF*, uint32, uint32, uint32*, int);
-extern int (*libtiff_TIFFSetField)(TIFF*, ttag_t, ...);
-extern tsize_t (*libtiff_TIFFWriteEncodedStrip)(TIFF*, tstrip_t, tdata_t, tsize_t);
-extern void (*libtiff__TIFFfree)(tdata_t);
-extern tdata_t (*libtiff__TIFFmalloc)(tsize_t);
-extern int (*libtiff_TIFFSetDirectory)(TIFF*, tdir_t);
-extern tdir_t (*libtiff_TIFFNumberOfDirectories)(TIFF*);
-extern int (*libtiff_TIFFIsTiled)(TIFF*);
-extern int (*libtiff_TIFFReadRGBATile)(TIFF*, uint32, uint32, uint32 * );
-#endif /* DYN_LIBTIFF_H */
-
index 4a491ceba2259fc2694f1f6b8ebd6676ca36b980..a0ff4476556c521335b0d870427bb086ae3b479a 100644 (file)
@@ -65,10 +65,10 @@ ImFileType IMB_FILE_TYPES[]= {
        {NULL, NULL, imb_is_a_targa, imb_ftype_default, imb_loadtarga, imb_savetarga, NULL, 0, TGA},
        {NULL, NULL, imb_is_dpx, imb_ftype_default, imb_loaddpx, imb_save_dpx, NULL, IM_FTYPE_FLOAT, DPX},
        {NULL, NULL, imb_is_cineon, imb_ftype_default, imb_loadcineon, imb_savecineon, NULL, IM_FTYPE_FLOAT, CINEON},
-#if defined(__APPLE__) && defined(IMBUF_COCOA)
+#ifdef WITH_TIFF
+       {NULL, NULL, imb_is_a_tiff, imb_ftype_default, imb_loadtiff, imb_savetiff, imb_loadtiletiff, 0, TIF},
+#elif defined(__APPLE__) && defined(IMBUF_COCOA)
        {NULL, NULL, imb_is_a_cocoa, imb_ftype_cocoa, imb_imb_cocoaLoadImage, imb_savecocoa, NULL, 0, TIF},
-#else
-       {libtiff_init, libtiff_exit, imb_is_a_tiff, imb_ftype_default, imb_loadtiff, imb_savetiff, imb_loadtiletiff, 0, TIF},
 #endif
        {NULL, NULL, imb_is_a_hdr, imb_ftype_default, imb_loadhdr, imb_savehdr, NULL, IM_FTYPE_FLOAT, RADHDR},
 #ifdef WITH_OPENEXR
index 3bc3f616da0f1d28f6b89ed7f0c911fe40a24024..1e4b2ea7110cdbdc850971df50bbb519d3e1b1bc 100644 (file)
  * used to compress images.
  */
 
+#ifdef WITH_TIFF
+
 #include <string.h>
 
 #include "imbuf.h"
-
 #include "BKE_global.h"
 #include "BKE_utildefines.h"
 
@@ -57,7 +59,7 @@
 #include "IMB_filetype.h"
 #include "IMB_filter.h"
 
-#include "dynlibtiff.h"
+#include "tiffio.h"
 
 
 
@@ -267,7 +269,7 @@ static TIFF *imb_tiff_client_open(ImbTIFFMemFile *memFile, unsigned char *mem, i
        memFile->offset = 0;
        memFile->size = size;
 
-       return libtiff_TIFFClientOpen("(Blender TIFF Interface Layer)", 
+       return TIFFClientOpen("(Blender TIFF Interface Layer)", 
                "r", (thandle_t)(memFile),
                imb_tiff_ReadProc, imb_tiff_WriteProc,
                imb_tiff_SeekProc, imb_tiff_CloseProc,
@@ -299,16 +301,77 @@ int imb_is_a_tiff(unsigned char *mem)
                 (memcmp(lil_endian, mem, IMB_TIFF_NCB) == 0) );
 }
 
-static int imb_read_tiff_pixels(ImBuf *ibuf, TIFF *image, int premul)
+static void scanline_contig_8bit(unsigned char *rect, unsigned char *cbuf, int scanline_w, int spp)
+{
+       int i;
+       for (i=0; i < scanline_w; i++) {
+               rect[i*4 + 0] = cbuf[i*spp + 0];
+               rect[i*4 + 1] = cbuf[i*spp + 1];
+               rect[i*4 + 2] = cbuf[i*spp + 2];
+               rect[i*4 + 3] = (spp==4)?cbuf[i*spp + 3]:255;
+       }
+}
+
+static void scanline_contig_16bit(float *rectf, unsigned short *sbuf, int scanline_w, int spp)
+{
+       int i;
+       for (i=0; i < scanline_w; i++) {
+               rectf[i*4 + 0] = sbuf[i*spp + 0] / 65535.0;
+               rectf[i*4 + 1] = sbuf[i*spp + 1] / 65535.0;
+               rectf[i*4 + 2] = sbuf[i*spp + 2] / 65535.0;
+               rectf[i*4 + 3] = (spp==4)?(sbuf[i*spp + 3] / 65535.0):1.0;
+       }
+}
+
+static void scanline_contig_32bit(float *rectf, float *fbuf, int scanline_w, int spp)
+{
+       int i;
+       for (i=0; i < scanline_w; i++) {
+               rectf[i*4 + 0] = fbuf[i*spp + 0];
+               rectf[i*4 + 1] = fbuf[i*spp + 1];
+               rectf[i*4 + 2] = fbuf[i*spp + 2];
+               rectf[i*4 + 3] = (spp==4)?fbuf[i*spp + 3]:1.0;
+       }
+}
+
+static void scanline_separate_8bit(unsigned char *rect, unsigned char *cbuf, int scanline_w, int chan)
+{
+       int i;
+       for (i=0; i < scanline_w; i++)
+               rect[i*4 + chan] = cbuf[i];
+}
+
+static void scanline_separate_16bit(float *rectf, unsigned short *sbuf, int scanline_w, int chan)
+{
+       int i;
+       for (i=0; i < scanline_w; i++)
+               rectf[i*4 + chan] = sbuf[i] / 65535.0;
+}
+
+static void scanline_separate_32bit(float *rectf, float *fbuf, int scanline_w, int chan)
+{
+       int i;
+       for (i=0; i < scanline_w; i++)
+               rectf[i*4 + chan] = fbuf[i];
+}
+
+
+/* 
+ * Use the libTIFF RGBAImage API to read a TIFF image.
+ * This function uses the "RGBA Image" support from libtiff, which enables
+ * it to load most commonly-encountered TIFF formats.  libtiff handles format
+ * conversion, color depth conversion, etc.
+ */
+static int imb_read_tiff_pixels_rgba(ImBuf *ibuf, TIFF *image, int premul)
 {
        ImBuf *tmpibuf;
        int success;
-
+       
        tmpibuf= IMB_allocImBuf(ibuf->x, ibuf->y, 32, IB_rect, 0);
-       success= libtiff_TIFFReadRGBAImage(image, ibuf->x, ibuf->y, tmpibuf->rect, 0);
+       success= TIFFReadRGBAImage(image, ibuf->x, ibuf->y, tmpibuf->rect, 0);
 
        if(ENDIAN_ORDER == B_ENDIAN)
-               IMB_convert_rgba_to_abgr(tmpibuf);
+       IMB_convert_rgba_to_abgr(tmpibuf);
        if(premul) {
                IMB_premultiply_alpha(tmpibuf);
                ibuf->flags |= IB_premul;
@@ -325,12 +388,133 @@ static int imb_read_tiff_pixels(ImBuf *ibuf, TIFF *image, int premul)
        return success;
 }
 
+/* 
+ * Use the libTIFF scanline API to read a TIFF image.
+ * This method is most flexible and can handle multiple different bit depths 
+ * and RGB channel orderings.
+ */
+static int imb_read_tiff_pixels(ImBuf *ibuf, TIFF *image, int premul)
+{
+       ImBuf *tmpibuf;
+       int success;
+       short bitspersample, spp, config;
+       size_t scanline;
+       int ib_flag=0, row, chan;
+       float *fbuf=NULL;
+       unsigned short *sbuf=NULL;
+       unsigned char *cbuf=NULL;
+       
+       TIFFGetField(image, TIFFTAG_BITSPERSAMPLE, &bitspersample);
+       TIFFGetField(image, TIFFTAG_SAMPLESPERPIXEL, &spp);             /* number of 'channels' */
+       TIFFGetField(image, TIFFTAG_PLANARCONFIG, &config);
+       scanline = TIFFScanlineSize(image);
+       
+       /* if file has an unsupported channel count, use libTIFF to 
+        * convert to an 8 bit RGBA image */
+       if (!ELEM(spp, 3, 4))
+               return imb_read_tiff_pixels_rgba(ibuf, image, premul);
+
+       
+       if (bitspersample == 32) {
+               ib_flag = IB_rectfloat;
+               fbuf = (float *)_TIFFmalloc(scanline);
+       } else if (bitspersample == 16) {
+               ib_flag = IB_rectfloat;
+               sbuf = (unsigned short *)_TIFFmalloc(scanline);
+       } else if (bitspersample == 8) {
+               ib_flag = IB_rect;
+               cbuf = (unsigned char *)_TIFFmalloc(scanline);
+       }
+       
+       tmpibuf= IMB_allocImBuf(ibuf->x, ibuf->y, ibuf->depth, ib_flag, 0);
+
+       /* contiguous channels: RGBRGBRGB */
+       if (config == PLANARCONFIG_CONTIG) {
+               for (row = 0; row < ibuf->y; row++) {
+                       int ib_offset = ibuf->x*ibuf->y*4 - ibuf->x*4 * (row+1);
+               
+                       if (bitspersample == 32) {
+                               success = TIFFReadScanline(image, fbuf, row, 0);
+                               scanline_contig_32bit(tmpibuf->rect_float+ib_offset, fbuf, ibuf->x, spp);
+                               
+                       } else if (bitspersample == 16) {
+                               success = TIFFReadScanline(image, sbuf, row, 0);
+                               scanline_contig_16bit(tmpibuf->rect_float+ib_offset, sbuf, ibuf->x, spp);
+                               
+                       } else if (bitspersample == 8) {
+                               unsigned char *crect = (unsigned char*)tmpibuf->rect;
+                               success = TIFFReadScanline(image, cbuf, row, 0);
+                               scanline_contig_8bit(crect+ib_offset, cbuf, ibuf->x, spp);
+                       }
+               }
+       /* separate channels: RRRGGGBBB */
+       } else if (config == PLANARCONFIG_SEPARATE) {
+               
+               /* imbufs always have 4 channels of data, so we iterate over all of them
+                * but only fill in from the TIFF scanline where necessary. */
+               for (chan = 0; chan < 4; chan++) {
+                       for (row = 0; row < ibuf->y; row++) {
+                               int ib_offset = ibuf->x*ibuf->y*4 - ibuf->x*4 * (row+1);
+                               
+                               if (bitspersample == 32) {
+                                       if (chan == 3 && spp == 3) /* fill alpha if only RGB TIFF */
+                                               memset(fbuf, 1.0, sizeof(fbuf));
+                                       else
+                                               success = TIFFReadScanline(image, fbuf, row, chan);
+                                       scanline_separate_32bit(tmpibuf->rect_float+ib_offset, fbuf, ibuf->x, chan);
+                                       
+                               } else if (bitspersample == 16) {
+                                       if (chan == 3 && spp == 3) /* fill alpha if only RGB TIFF */
+                                               memset(sbuf, 65535, sizeof(sbuf));
+                                       else
+                                               success = TIFFReadScanline(image, sbuf, row, chan);
+                                       scanline_separate_16bit(tmpibuf->rect_float+ib_offset, sbuf, ibuf->x, chan);
+                                       
+                               } else if (bitspersample == 8) {
+                                       unsigned char *crect = (unsigned char*)tmpibuf->rect;
+                                       if (chan == 3 && spp == 3) /* fill alpha if only RGB TIFF */
+                                               memset(cbuf, 255, sizeof(cbuf));
+                                       else
+                                               success = TIFFReadScanline(image, cbuf, row, chan);
+                                       scanline_separate_8bit(crect+ib_offset, cbuf, ibuf->x, chan);
+                               }
+                       }
+               }
+       }
+       
+       ibuf->profile = (bitspersample==32)?IB_PROFILE_LINEAR_RGB:IB_PROFILE_SRGB;
+       
+       if (bitspersample == 32)
+               _TIFFfree(fbuf);
+       else if (bitspersample == 16)
+               _TIFFfree(sbuf);
+       else if (bitspersample == 8)
+               _TIFFfree(cbuf);
+               
+       if(ENDIAN_ORDER == B_ENDIAN)
+               IMB_convert_rgba_to_abgr(tmpibuf);
+       if(premul) {
+               IMB_premultiply_alpha(tmpibuf);
+               ibuf->flags |= IB_premul;
+       }
+       
+       /* assign rect last */
+       if (tmpibuf->rect_float)
+               ibuf->rect_float= tmpibuf->rect_float;
+       else    
+               ibuf->rect= tmpibuf->rect;
+       ibuf->mall |= ib_flag;
+       ibuf->flags |= ib_flag;
+       
+       tmpibuf->mall &= ~ib_flag;
+       IMB_freeImBuf(tmpibuf);
+       
+       return success;
+}
+
 /**
  * Loads a TIFF file.
  *
- * This function uses the "RGBA Image" support from libtiff, which enables
- * it to load most commonly-encountered TIFF formats.  libtiff handles format
- * conversion, color depth conversion, etc.
  *
  * @param mem:   Memory containing the TIFF file.
  * @param size:  Size of the mem buffer.
@@ -347,9 +531,8 @@ ImBuf *imb_loadtiff(unsigned char *mem, int size, int flags)
        uint32 width, height;
        char *format = NULL;
        int level;
-
-       if(!G.have_libtiff)
-               return NULL;
+       short spp;
+       int ib_depth;
 
        /* check whether or not we have a TIFF file */
        if(size < IMB_TIFF_NCB) {
@@ -367,24 +550,27 @@ ImBuf *imb_loadtiff(unsigned char *mem, int size, int flags)
        }
 
        /* allocate the image buffer */
-       libtiff_TIFFGetField(image, TIFFTAG_IMAGEWIDTH,  &width);
-       libtiff_TIFFGetField(image, TIFFTAG_IMAGELENGTH, &height);
-       ibuf = IMB_allocImBuf(width, height, 32, 0, 0);
+       TIFFGetField(image, TIFFTAG_IMAGEWIDTH,  &width);
+       TIFFGetField(image, TIFFTAG_IMAGELENGTH, &height);
+       TIFFGetField(image, TIFFTAG_SAMPLESPERPIXEL, &spp);
+       
+       ib_depth = (spp==3)?24:32;
+       
+       ibuf = IMB_allocImBuf(width, height, ib_depth, 0, 0);
        if(ibuf) {
                ibuf->ftype = TIF;
-               ibuf->profile = IB_PROFILE_SRGB;
        }
        else {
                fprintf(stderr, 
                        "imb_loadtiff: could not allocate memory for TIFF " \
                        "image.\n");
-               libtiff_TIFFClose(image);
+               TIFFClose(image);
                return NULL;
        }
 
        /* if testing, we're done */
        if(flags & IB_test) {
-               libtiff_TIFFClose(image);
+               TIFFClose(image);
                return ibuf;
        }
 
@@ -392,14 +578,14 @@ ImBuf *imb_loadtiff(unsigned char *mem, int size, int flags)
           we don't read pixels but leave it to the cache to load tiles */
        if(flags & IB_tilecache) {
                format= NULL;
-               libtiff_TIFFGetField(image, TIFFTAG_PIXAR_TEXTUREFORMAT, &format);
+               TIFFGetField(image, TIFFTAG_PIXAR_TEXTUREFORMAT, &format);
 
-               if(format && strcmp(format, "Plain Texture")==0 && libtiff_TIFFIsTiled(image)) {
-                       int numlevel = libtiff_TIFFNumberOfDirectories(image);
+               if(format && strcmp(format, "Plain Texture")==0 && TIFFIsTiled(image)) {
+                       int numlevel = TIFFNumberOfDirectories(image);
 
                        /* create empty mipmap levels in advance */
                        for(level=0; level<numlevel; level++) {
-                               if(!libtiff_TIFFSetDirectory(image, level))
+                               if(!TIFFSetDirectory(image, level))
                                        break;
 
                                if(level > 0) {
@@ -418,8 +604,8 @@ ImBuf *imb_loadtiff(unsigned char *mem, int size, int flags)
                                else
                                        hbuf= ibuf;
 
-                               libtiff_TIFFGetField(image, TIFFTAG_TILEWIDTH, &hbuf->tilex);
-                               libtiff_TIFFGetField(image, TIFFTAG_TILELENGTH, &hbuf->tiley);
+                               TIFFGetField(image, TIFFTAG_TILEWIDTH, &hbuf->tilex);
+                               TIFFGetField(image, TIFFTAG_TILELENGTH, &hbuf->tiley);
 
                                hbuf->xtiles= ceil(hbuf->x/(float)hbuf->tilex);
                                hbuf->ytiles= ceil(hbuf->y/(float)hbuf->tiley);
@@ -434,12 +620,12 @@ ImBuf *imb_loadtiff(unsigned char *mem, int size, int flags)
        /* read pixels */
        if(!(ibuf->flags & IB_tilecache) && !imb_read_tiff_pixels(ibuf, image, 0)) {
                fprintf(stderr, "imb_loadtiff: Failed to read tiff image.\n");
-               libtiff_TIFFClose(image);
+               TIFFClose(image);
                return NULL;
        }
 
        /* close the client layer interface to the in-memory file */
-       libtiff_TIFFClose(image);
+       TIFFClose(image);
 
        /* return successfully */
        return ibuf;
@@ -458,15 +644,15 @@ void imb_loadtiletiff(ImBuf *ibuf, unsigned char *mem, int size, int tx, int ty,
                return;
        }
 
-       if(libtiff_TIFFSetDirectory(image, ibuf->miplevel)) {
+       if(TIFFSetDirectory(image, ibuf->miplevel)) {
                /* allocate the image buffer */
-               libtiff_TIFFGetField(image, TIFFTAG_IMAGEWIDTH,  &width);
-               libtiff_TIFFGetField(image, TIFFTAG_IMAGELENGTH, &height);
+               TIFFGetField(image, TIFFTAG_IMAGEWIDTH,  &width);
+               TIFFGetField(image, TIFFTAG_IMAGELENGTH, &height);
 
                if(width == ibuf->x && height == ibuf->y) {
                        if(rect) {
                                /* tiff pixels are bottom to top, tiles are top to bottom */
-                               if(libtiff_TIFFReadRGBATile(image, tx*ibuf->tilex, (ibuf->ytiles - 1 - ty)*ibuf->tiley, rect) == 1) {
+                               if(TIFFReadRGBATile(image, tx*ibuf->tilex, (ibuf->ytiles - 1 - ty)*ibuf->tiley, rect) == 1) {
                                        if(ibuf->tiley > ibuf->y)
                                                memmove(rect, rect+ibuf->tilex*(ibuf->tiley - ibuf->y), sizeof(int)*ibuf->tilex*ibuf->y);
 
@@ -484,7 +670,7 @@ void imb_loadtiletiff(ImBuf *ibuf, unsigned char *mem, int size, int tx, int ty,
                printf("imb_loadtiff: could not find mipmap level %d\n", ibuf->miplevel);
 
        /* close the client layer interface to the in-memory file */
-       libtiff_TIFFClose(image);
+       TIFFClose(image);
 }
 
 /**
@@ -515,10 +701,6 @@ int imb_savetiff(ImBuf *ibuf, char *name, int flags)
        int x, y, from_i, to_i, i;
        int extraSampleTypes[1] = { EXTRASAMPLE_ASSOCALPHA };
        
-       if(!G.have_libtiff) {
-               fprintf(stderr, "imb_savetiff: no tiff library available.\n");
-               return (0);
-       }
 
        /* check for a valid number of bytes per pixel.  Like the PNG writer,
         * the TIFF writer supports 1, 3 or 4 bytes per pixel, corresponding
@@ -546,7 +728,7 @@ int imb_savetiff(ImBuf *ibuf, char *name, int flags)
        }
        else {
                /* create image as a file */
-               image = libtiff_TIFFOpen(name, "w");
+               image = TIFFOpen(name, "w");
        }
        if(image == NULL) {
                fprintf(stderr,
@@ -557,16 +739,16 @@ int imb_savetiff(ImBuf *ibuf, char *name, int flags)
        /* allocate array for pixel data */
        npixels = ibuf->x * ibuf->y;
        if(bitspersample == 16)
-               pixels16 = (unsigned short*)libtiff__TIFFmalloc(npixels *
+               pixels16 = (unsigned short*)_TIFFmalloc(npixels *
                        samplesperpixel * sizeof(unsigned short));
        else
-               pixels = (unsigned char*)libtiff__TIFFmalloc(npixels *
+               pixels = (unsigned char*)_TIFFmalloc(npixels *
                        samplesperpixel * sizeof(unsigned char));
 
        if(pixels == NULL && pixels16 == NULL) {
                fprintf(stderr,
                        "imb_savetiff: could not allocate pixels array.\n");
-               libtiff_TIFFClose(image);
+               TIFFClose(image);
                return (0);
        }
 
@@ -581,24 +763,24 @@ int imb_savetiff(ImBuf *ibuf, char *name, int flags)
        }
 
        /* setup samples per pixel */
-       libtiff_TIFFSetField(image, TIFFTAG_BITSPERSAMPLE, bitspersample);
-       libtiff_TIFFSetField(image, TIFFTAG_SAMPLESPERPIXEL, samplesperpixel);
+       TIFFSetField(image, TIFFTAG_BITSPERSAMPLE, bitspersample);
+       TIFFSetField(image, TIFFTAG_SAMPLESPERPIXEL, samplesperpixel);
 
        if(samplesperpixel == 4) {
                /* RGBA images */
-               libtiff_TIFFSetField(image, TIFFTAG_EXTRASAMPLES, 1,
+               TIFFSetField(image, TIFFTAG_EXTRASAMPLES, 1,
                                extraSampleTypes);
-               libtiff_TIFFSetField(image, TIFFTAG_PHOTOMETRIC, 
+               TIFFSetField(image, TIFFTAG_PHOTOMETRIC, 
                                PHOTOMETRIC_RGB);
        }
        else if(samplesperpixel == 3) {
                /* RGB images */
-               libtiff_TIFFSetField(image, TIFFTAG_PHOTOMETRIC,
+               TIFFSetField(image, TIFFTAG_PHOTOMETRIC,
                                PHOTOMETRIC_RGB);
        }
        else if(samplesperpixel == 1) {
                /* greyscale images, 1 channel */
-               libtiff_TIFFSetField(image, TIFFTAG_PHOTOMETRIC,
+               TIFFSetField(image, TIFFTAG_PHOTOMETRIC,
                                PHOTOMETRIC_MINISBLACK);
        }
 
@@ -635,30 +817,31 @@ int imb_savetiff(ImBuf *ibuf, char *name, int flags)
        }
 
        /* write the actual TIFF file */
-       libtiff_TIFFSetField(image, TIFFTAG_IMAGEWIDTH,      ibuf->x);
-       libtiff_TIFFSetField(image, TIFFTAG_IMAGELENGTH,     ibuf->y);
-       libtiff_TIFFSetField(image, TIFFTAG_ROWSPERSTRIP,    ibuf->y);
-       libtiff_TIFFSetField(image, TIFFTAG_COMPRESSION, COMPRESSION_DEFLATE);
-       libtiff_TIFFSetField(image, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);
-       libtiff_TIFFSetField(image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
-       libtiff_TIFFSetField(image, TIFFTAG_XRESOLUTION,     150.0);
-       libtiff_TIFFSetField(image, TIFFTAG_YRESOLUTION,     150.0);
-       libtiff_TIFFSetField(image, TIFFTAG_RESOLUTIONUNIT,  RESUNIT_INCH);
-       if(libtiff_TIFFWriteEncodedStrip(image, 0,
+       TIFFSetField(image, TIFFTAG_IMAGEWIDTH,      ibuf->x);
+       TIFFSetField(image, TIFFTAG_IMAGELENGTH,     ibuf->y);
+       TIFFSetField(image, TIFFTAG_ROWSPERSTRIP,    ibuf->y);
+       TIFFSetField(image, TIFFTAG_COMPRESSION, COMPRESSION_DEFLATE);
+       TIFFSetField(image, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);
+       TIFFSetField(image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
+       TIFFSetField(image, TIFFTAG_XRESOLUTION,     150.0);
+       TIFFSetField(image, TIFFTAG_YRESOLUTION,     150.0);
+       TIFFSetField(image, TIFFTAG_RESOLUTIONUNIT,  RESUNIT_INCH);
+       if(TIFFWriteEncodedStrip(image, 0,
                        (bitspersample == 16)? (unsigned char*)pixels16: pixels,
                        ibuf->x*ibuf->y*samplesperpixel*bitspersample/8) == -1) {
                fprintf(stderr,
                        "imb_savetiff: Could not write encoded TIFF.\n");
-               libtiff_TIFFClose(image);
-               if(pixels) libtiff__TIFFfree(pixels);
-               if(pixels16) libtiff__TIFFfree(pixels16);
+               TIFFClose(image);
+               if(pixels) _TIFFfree(pixels);
+               if(pixels16) _TIFFfree(pixels16);
                return (1);
        }
 
        /* close the TIFF file */
-       libtiff_TIFFClose(image);
-       if(pixels) libtiff__TIFFfree(pixels);
-       if(pixels16) libtiff__TIFFfree(pixels16);
+       TIFFClose(image);
+       if(pixels) _TIFFfree(pixels);
+       if(pixels16) _TIFFfree(pixels16);
        return (1);
 }
 
+#endif /* WITH_TIFF */
\ No newline at end of file
index aff05b4eaff00b35b98497cc70be04cf0d598685..e6f4e226caa0b6740604d2dd6876de876e505317 100644 (file)
@@ -105,17 +105,19 @@ static int IMB_ispic_name(char *name)
 int IMB_ispic(char *filename)
 {
        if(U.uiflag & USER_FILTERFILEEXTS) {
-               if (G.have_libtiff && (BLI_testextensie(filename, ".tif")
+               if (BLI_testextensie(filename, ".tif")
                                ||      BLI_testextensie(filename, ".tiff")
-                               ||      BLI_testextensie(filename, ".tx"))) {
+                               ||      BLI_testextensie(filename, ".tx")) {
                                return IMB_ispic_name(filename);
                }
                if (G.have_quicktime){
                        if(             BLI_testextensie(filename, ".jpg")
                                ||      BLI_testextensie(filename, ".jpeg")
+#ifdef WITH_TIFF
                                ||      BLI_testextensie(filename, ".tif")
                                ||      BLI_testextensie(filename, ".tiff")
                                ||      BLI_testextensie(filename, ".tx")
+#endif
                                ||      BLI_testextensie(filename, ".hdr")
                                ||      BLI_testextensie(filename, ".tga")
                                ||      BLI_testextensie(filename, ".rgb")
@@ -144,9 +146,14 @@ int IMB_ispic(char *filename)
                        } else {
                                return(FALSE);                  
                        }
-               } else { /* no quicktime or libtiff */
+               } else { /* no quicktime */
                        if(             BLI_testextensie(filename, ".jpg")
                                ||      BLI_testextensie(filename, ".jpeg")
+#ifdef WITH_TIFF
+                               ||      BLI_testextensie(filename, ".tif")
+                               ||      BLI_testextensie(filename, ".tiff")
+                               ||      BLI_testextensie(filename, ".tx")
+#endif
                                ||      BLI_testextensie(filename, ".hdr")
                                ||      BLI_testextensie(filename, ".tga")
                                ||      BLI_testextensie(filename, ".rgb")
index 71cfc3c7da4b976243517bf92f4da4ef116d2b89..c4ee90dde16360b9d9d72bf7312ac74b4a975477 100644 (file)
@@ -15,6 +15,9 @@ defs = []
 if env['WITH_BF_OPENEXR']:
        defs.append('WITH_OPENEXR')
 
+if env['WITH_BF_TIFF']:
+       defs.append('WITH_TIFF')
+
 if env['WITH_BF_OPENJPEG']:
        defs.append('WITH_OPENJPEG')
 
index 0e25160cdff0166f658ce8aefcc095ccdbc184a9..e9fc5c10f9eed9ed036c0574ee0dc0a136c02881 100644 (file)
@@ -58,6 +58,10 @@ IF(WITH_OPENEXR)
        ADD_DEFINITIONS(-DWITH_OPENEXR)
 ENDIF(WITH_OPENEXR)
 
+IF(WITH_TIFF)
+       ADD_DEFINITIONS(-DWITH_TIFF)
+ENDIF(WITH_TIFF)
+
 IF(WITH_OPENJPEG)
        ADD_DEFINITIONS(-DWITH_OPENJPEG)
 ENDIF(WITH_OPENJPEG)
index 6a84846597b98f7a4260179c62dc36adccdb1c0d..a18c1021a8ae5f0b7822a1fb9541480decc3f7dd 100644 (file)
@@ -111,7 +111,9 @@ EnumPropertyItem image_type_items[] = {
        {R_OPENEXR, "OPEN_EXR", ICON_FILE_IMAGE, "OpenEXR", ""},
 #endif
        {R_RADHDR, "HDR", ICON_FILE_IMAGE, "Radiance HDR", ""},
-       {R_TIFF, "TIFF", ICON_FILE_IMAGE, "TIFF", ""},  // XXX only with G.have_libtiff
+#ifdef WITH_TIFF
+       {R_TIFF, "TIFF", ICON_FILE_IMAGE, "TIFF", ""},
+#endif
        {0, "", 0, "Movie", NULL},
 #ifdef _WIN32
        {R_AVICODEC, "AVICODEC", ICON_FILE_MOVIE, "AVI Codec", ""}, // XXX Missing codec menu
index 193217abc9d1511df891d2e75fffbe8f867a2fd0..d170e2374a834f500fdfac1fe0a0bacdc133d337 100644 (file)
@@ -61,6 +61,10 @@ IF(WITH_OPENEXR)
        ADD_DEFINITIONS(-DWITH_OPENEXR)
 ENDIF(WITH_OPENEXR)
 
+IF(WITH_TIFF)
+       ADD_DEFINITIONS(-DWITH_TIFF)
+ENDIF(WITH_TIFF)
+
 IF(WITH_PYTHON)
        INCLUDE_DIRECTORIES(../blender/python)
 ELSE(WITH_PYTHON)
@@ -280,7 +284,6 @@ IF(WITH_INSTALL)
                        COMMAND copy /Y \"${WIN_LIBDIR}\\png\\lib\\libpng.dll\" \"${TARGETDIR}\\\"
                        COMMAND copy /Y \"${WIN_LIBDIR}\\sdl\\lib\\SDL.dll\" \"${TARGETDIR}\\\"
                        COMMAND copy /Y \"${WIN_LIBDIR}\\zlib\\lib\\zlib.dll\" \"${TARGETDIR}\\\"
-                       COMMAND copy /Y \"${WIN_LIBDIR}\\tiff\\lib\\libtiff.dll\" \"${TARGETDIR}\\\"
                        COMMAND copy /Y \"${WIN_LIBDIR}\\python\\lib\\python31.dll\" \"${TARGETDIR}\\\"
                        COMMAND copy /Y \"${WIN_LIBDIR}\\python\\lib\\python31_d.dll\" \"${TARGETDIR}\\\"
                        COMMAND copy /Y \"${WIN_LIBDIR}\\pthreads\\lib\\pthreadVC2.dll\" \"${TARGETDIR}\\\"
index 6364f256cc552a24896ac43ce36e86898d6449fa..815bd351f690a69899c45c49f5dfe8c1ec17db92 100644 (file)
@@ -23,6 +23,9 @@ if env['WITH_BF_BINRELOC']:
 if env['WITH_BF_OPENEXR']:
        defs.append('WITH_OPENEXR')
 
+if env['WITH_BF_TIFF']:
+       defs.append('WITH_TIFF')
+
 if not env['WITH_BF_SDL']:
        defs.append('DISABLE_SDL')
 
index 7544c3f8ff90c15c49f5bde1ca2ed08c36d5dee2..e3475e6ffe47e028815d6459e157777f09853f51 100644 (file)
@@ -543,7 +543,9 @@ static int set_image_type(int argc, char **argv, void *data)
                        else if (!strcmp(imtype,"QUICKTIME")) scene->r.imtype = R_QUICKTIME;
                        else if (!strcmp(imtype,"BMP")) scene->r.imtype = R_BMP;
                        else if (!strcmp(imtype,"HDR")) scene->r.imtype = R_RADHDR;
+#ifdef WITH_TIFF
                        else if (!strcmp(imtype,"TIFF")) scene->r.imtype = R_TIFF;
+#endif
 #ifdef WITH_OPENEXR
                        else if (!strcmp(imtype,"EXR")) scene->r.imtype = R_OPENEXR;
                        else if (!strcmp(imtype,"MULTILAYER")) scene->r.imtype = R_MULTILAYER;
index 441d454b782647aaa6d777c76e3dd696ea38c453..69f6850fa52df68920399b9153f7287f742e6fb3 100644 (file)
@@ -146,6 +146,8 @@ def setup_staticlibs(lenv):
                libincs += Split(lenv['BF_OPENEXR_LIBPATH'])
                if lenv['WITH_BF_STATICOPENEXR']:
                        statlibs += Split(lenv['BF_OPENEXR_LIB_STATIC'])
+       if lenv['WITH_BF_TIFF']:
+               libincs += Split(lenv['BF_TIFF_LIBPATH'])
        if lenv['WITH_BF_FFTW3']:
                libincs += Split(lenv['BF_FFTW3_LIBPATH'])
        if lenv['WITH_BF_INTERNATIONAL']:
@@ -208,6 +210,8 @@ def setup_syslibs(lenv):
        if lenv['WITH_BF_OPENEXR']:
                if not lenv['WITH_BF_STATICOPENEXR']:
                        syslibs += Split(lenv['BF_OPENEXR_LIB'])
+       if lenv['WITH_BF_TIFF']:
+                       syslibs += Split(lenv['BF_TIFF_LIB'])
        if lenv['WITH_BF_FFMPEG']:
                syslibs += Split(lenv['BF_FFMPEG_LIB'])
                if lenv['WITH_BF_OGG']:
index 4cb86ecee6203f0502e59e09804130840b843f15..271fccff50c1582e0750776e94f928d724b721d4 100644 (file)
@@ -42,7 +42,7 @@ def validate_arguments(args, bc):
             'WITH_BF_OPENJPEG', 'BF_OPENJPEG', 'BF_OPENJPEG_INC', 'BF_OPENJPEG_LIB', 'BF_OPENJPEG_LIBPATH',
             'WITH_BF_REDCODE', 'BF_REDCODE', 'BF_REDCODE_INC', 'BF_REDCODE_LIB', 'BF_REDCODE_LIBPATH',
             'WITH_BF_PNG', 'BF_PNG', 'BF_PNG_INC', 'BF_PNG_LIB', 'BF_PNG_LIBPATH',
-            'BF_TIFF', 'BF_TIFF_INC', 'BF_TIFF_LIB', 'BF_TIFF_LIBPATH',
+            'WITH_BF_TIFF', 'BF_TIFF', 'BF_TIFF_INC', 'BF_TIFF_LIB', 'BF_TIFF_LIBPATH',
             'WITH_BF_ZLIB', 'BF_ZLIB', 'BF_ZLIB_INC', 'BF_ZLIB_LIB', 'BF_ZLIB_LIBPATH',
             'WITH_BF_INTERNATIONAL',
             'BF_GETTEXT', 'BF_GETTEXT_INC', 'BF_GETTEXT_LIB', 'BF_GETTEXT_LIBPATH',
@@ -261,6 +261,7 @@ def read_opts(cfg, args):
         ('BF_PNG_LIB', 'PNG library', ''),
         ('BF_PNG_LIBPATH', 'PNG library path', ''),
 
+       (BoolVariable('WITH_BF_TIFF', 'Use TIFF if true', True)),
         ('BF_TIFF', 'TIFF base path', ''),
         ('BF_TIFF_INC', 'TIFF include path', ''),
         ('BF_TIFF_LIB', 'TIFF library', ''),