Dev:Source/Blender/Images/TIFF

From BlenderWiki

Jump to: navigation, search

Contents

[edit] TIFF File Format Support via libtiff

[edit] The patch

This Wiki article describes patch #2995.

[edit] Introduction

On Windows and Apple Macintosh platforms, the QuickTime library can be used to load and save TIFF files. However, under Linux, this can be problematic. TIFF also supports more features than can easily be accessed via QuickTime. For these reasons, it is useful to be able to access TIFF files via a lower-level interface, such as that provided by libtiff.

[edit] Problems with incorporating libtiff as a static library

Using libtiff as a static library would increase the size of the binary distribution of Blender by about 400 kB. This is an undesirably large increase.

[edit] The dynamic loading approach

Instead of static linkage, the patch above uses dynamic linkage, established at run time. Note that dynamic linkage is different from shared linkage. With shared linkage, a binary cannot be run without access to the shared library. Using dynamic linkage, on the other hand, the binary is "smarter" about loading the library, and can run perfectly well without it - just with some reduced functionality. Dynamic linkage is more commonly used to implement "plugin" type behaviour.

[edit] Implementation

In terms of programmer use, the dynamic linked version of libtiff is nearly identical to a normal static linkage. The only differences are that function pointers are used instead of functions, and they are prefixed with the string libtiff_. To use the dynamic-linked libtiff, you need to do the following (already set up correctly in the patch):

  • #include "IMB_imbuf.h"
  • Call IMB_libtiff_init(). This will attempt to load the libtiff library dynamically, and sets the G.have_libtiff variable to indicate presence or absence of the library.
  • Check G.have_libtiff. If this is non-zero, then dynamic loading was successful.
  • Call functions from dynlibtiff.h, treating them the same way as you would functions from the normal libtiff library.
  • When finished, call IMB_libtiff_exit()

The dynamic linking code is written semi-automatically by the helper script gen_dynlibtiff.py. This script creates the files dynlibtiff.c and dynlibtiff.h. This script should only need to be run if: i. The programmer wants access to more functions from libtiff than are currently available in the dynamic API. ii. The libtiff API changes in a future version.

If you want to add more functions to the API that is available dynamically, simply add them to the tiff_functions[] list inside gen_dynlibtiff.py, copying their definitions from the libtiff headers.

[edit] Requirements at build time and run time

  • Build time
    • libtiff headers only
  • Run time
    • No additional requirements. If the shared library (eg: libtiff.so.3) is available, however, then its features will be used and TIFF options will magically appear.

-- Jonathan Merritt - 08 Sep 2005