Blender V2.61 - r43446
Classes | Defines | Typedefs | Functions

tiff.c File Reference

#include <string.h>
#include "imbuf.h"
#include "BLI_math.h"
#include "BLI_string.h"
#include "BLI_utildefines.h"
#include "BKE_global.h"
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
#include "IMB_allocimbuf.h"
#include "IMB_filetype.h"
#include "IMB_filter.h"
#include "tiffio.h"

Go to the source code of this file.

Classes

struct  ImbTIFFMemFile

Defines

#define IMB_TIFF_GET_MEMFILE(x)   ((ImbTIFFMemFile*)(x));
#define IMB_TIFF_NCB   4

Typedefs

typedef struct ImbTIFFMemFile ImbTIFFMemFile

Functions

static tsize_t imb_tiff_ReadProc (thandle_t handle, tdata_t data, tsize_t n)
static tsize_t imb_tiff_WriteProc (thandle_t handle, tdata_t data, tsize_t n)
static toff_t imb_tiff_SeekProc (thandle_t handle, toff_t ofs, int whence)
static int imb_tiff_CloseProc (thandle_t handle)
static toff_t imb_tiff_SizeProc (thandle_t handle)
static int imb_tiff_DummyMapProc (thandle_t fd, tdata_t *pbase, toff_t *psize)
static void imb_tiff_DummyUnmapProc (thandle_t fd, tdata_t base, toff_t size)
static TIFF * imb_tiff_client_open (ImbTIFFMemFile *memFile, unsigned char *mem, size_t size)
int imb_is_a_tiff (unsigned char *mem)
static void scanline_contig_16bit (float *rectf, unsigned short *sbuf, int scanline_w, int spp)
static void scanline_contig_32bit (float *rectf, float *fbuf, int scanline_w, int spp)
static void scanline_separate_16bit (float *rectf, unsigned short *sbuf, int scanline_w, int chan)
static void scanline_separate_32bit (float *rectf, float *fbuf, int scanline_w, int chan)
static void imb_read_tiff_resolution (ImBuf *ibuf, TIFF *image)
static int imb_read_tiff_pixels (ImBuf *ibuf, TIFF *image, int premul)
void imb_inittiff (void)
ImBufimb_loadtiff (unsigned char *mem, size_t size, int flags)
void imb_loadtiletiff (ImBuf *ibuf, unsigned char *mem, size_t size, int tx, int ty, unsigned int *rect)
int imb_savetiff (ImBuf *ibuf, const char *name, int flags)

Detailed Description

Definition in file tiff.c.


Define Documentation

#define IMB_TIFF_GET_MEMFILE (   x)    ((ImbTIFFMemFile*)(x));

Definition at line 88 of file tiff.c.

Referenced by imb_tiff_CloseProc(), imb_tiff_ReadProc(), imb_tiff_SeekProc(), and imb_tiff_SizeProc().

#define IMB_TIFF_NCB   4

Checks whether a given memory buffer contains a TIFF file.

This method uses the format identifiers from: http://www.faqs.org/faqs/graphics/fileformats-faq/part4/section-9.html The first four bytes of big-endian and little-endian TIFF files respectively are (hex): 4d 4d 00 2a 49 49 2a 00 Note that TIFF files on *any* platform can be either big- or little-endian; it's not platform-specific.

AFAICT, libtiff doesn't provide a method to do this automatically, and hence my manual comparison. - Jonathan Merritt (lancelet) 4th Sept 2005.

Definition at line 308 of file tiff.c.

Referenced by imb_is_a_tiff(), and imb_loadtiff().


Typedef Documentation


Function Documentation

void imb_inittiff ( void  )

Definition at line 488 of file tiff.c.

References G, G_DEBUG, and NULL.

int imb_is_a_tiff ( unsigned char *  mem)

Definition at line 309 of file tiff.c.

References IMB_TIFF_NCB.

Referenced by imb_loadtiff().

ImBuf* imb_loadtiff ( unsigned char *  mem,
size_t  size,
int  flags 
) [read]

Loads a TIFF file.

Parameters:
mem,:Memory containing the TIFF file.
size,:Size of the mem buffer.
flags,:If flags has IB_test set then the file is not actually loaded, but all other operations take place.
Returns:
: A newly allocated ImBuf structure if successful, otherwise NULL.

Definition at line 505 of file tiff.c.

References ImBuf::flags, ImBuf::ftype, IB_premul, IB_test, IB_tilecache, imb_addtilesImBuf(), IMB_allocImBuf(), imb_is_a_tiff(), imb_read_tiff_pixels(), imb_tiff_client_open(), IMB_TIFF_NCB, ImBuf::mipmap, ImBuf::miptot, and NULL.

void imb_loadtiletiff ( ImBuf ibuf,
unsigned char *  mem,
size_t  size,
int  tx,
int  ty,
unsigned int *  rect 
)
static int imb_read_tiff_pixels ( ImBuf ibuf,
TIFF *  image,
int  premul 
) [static]
static void imb_read_tiff_resolution ( ImBuf ibuf,
TIFF *  image 
) [static]

Definition at line 354 of file tiff.c.

References ImBuf::ppm.

Referenced by imb_read_tiff_pixels().

int imb_savetiff ( ImBuf ibuf,
const char *  name,
int  flags 
)

Saves a TIFF file.

ImBuf structures with 1, 3 or 4 bytes per pixel (GRAY, RGB, RGBA respectively) are accepted, and interpreted correctly. Note that the TIFF convention is to use pre-multiplied alpha, which can be achieved within Blender by setting "Premul" alpha handling. Other alpha conventions are not strictly correct, but are permitted anyhow.

Parameters:
ibuf,:Image buffer.
name,:Name of the TIFF file to create.
flags,:Currently largely ignored.
Returns:
: 1 if the function is successful, 0 on failure.

Definition at line 671 of file tiff.c.

References copy_v3_v3(), FTOUSHORT, ImBuf::ftype, i, IB_mem, IB_PROFILE_LINEAR_RGB, linearrgb_to_srgb_v3_v3(), NULL, ImBuf::planes, ImBuf::ppm, ImBuf::profile, ImBuf::rect, ImBuf::rect_float, ImBuf::x, and ImBuf::y.

static TIFF* imb_tiff_client_open ( ImbTIFFMemFile memFile,
unsigned char *  mem,
size_t  size 
) [static]
static int imb_tiff_CloseProc ( thandle_t  handle) [static]

Closes (virtually) an in-memory TIFF file.

NOTE: All this function actually does is sets the data pointer within the TIFF file to NULL. That should trigger assertion errors if attempts are made to access the file after that point. However, no such attempts should ever be made (in theory).

Parameters:
handle,:Handle of the TIFF file (pointer to ImbTIFFMemFile).
Returns:
: 0

Definition at line 238 of file tiff.c.

References IMB_TIFF_GET_MEMFILE, ImbTIFFMemFile::mem, NULL, ImbTIFFMemFile::offset, and ImbTIFFMemFile::size.

Referenced by imb_tiff_client_open().

static int imb_tiff_DummyMapProc ( thandle_t  fd,
tdata_t *  pbase,
toff_t *  psize 
) [static]

Definition at line 104 of file tiff.c.

Referenced by imb_tiff_client_open().

static void imb_tiff_DummyUnmapProc ( thandle_t  fd,
tdata_t  base,
toff_t  size 
) [static]

Definition at line 97 of file tiff.c.

Referenced by imb_tiff_client_open().

static tsize_t imb_tiff_ReadProc ( thandle_t  handle,
tdata_t  data,
tsize_t  n 
) [static]

Provides TIFF file loading and saving for Blender, via libtiff.

The task of loading is complicated somewhat by the fact that Blender has already loaded the file into a memory buffer. libtiff is not well configured to handle files in memory, so a client wrapper is written to surround the memory and turn it into a virtual file. Currently, reading of TIFF files is done using libtiff's RGBAImage support. This is a high-level routine that loads all images as 32-bit RGBA, handling all the required conversions between many different TIFF types internally.

Saving supports RGB, RGBA and BW (greyscale) images correctly, with 8 bits per channel in all cases. The "deflate" compression algorithm is used to compress images.

Reads data from an in-memory TIFF file.

Parameters:
handle,:Handle of the TIFF file (pointer to ImbTIFFMemFile).
data,:Buffer to contain data (treat as void*).
n,:Number of bytes to read.
Returns:
: Number of bytes actually read. 0 = EOF.

Definition at line 123 of file tiff.c.

References IMB_TIFF_GET_MEMFILE, ImbTIFFMemFile::mem, ImbTIFFMemFile::offset, and ImbTIFFMemFile::size.

Referenced by imb_tiff_client_open().

static toff_t imb_tiff_SeekProc ( thandle_t  handle,
toff_t  ofs,
int  whence 
) [static]

Seeks to a new location in an in-memory TIFF file.

Parameters:
handle,:Handle of the TIFF file (pointer to ImbTIFFMemFile).
ofs,:Offset value (interpreted according to whence below).
whence,:This can be one of three values: SEEK_SET - The offset is set to ofs bytes. SEEK_CUR - The offset is set to its current location plus ofs bytes. SEEK_END - (This is unsupported and will return -1, indicating an error).
Returns:
: Resulting offset location within the file, measured in bytes from the beginning of the file. (-1) indicates an error.

Definition at line 191 of file tiff.c.

References IMB_TIFF_GET_MEMFILE, ImbTIFFMemFile::mem, and ImbTIFFMemFile::offset.

Referenced by imb_tiff_client_open().

static toff_t imb_tiff_SizeProc ( thandle_t  handle) [static]

Returns the size of an in-memory TIFF file in bytes.

Returns:
: Size of file (in bytes).

Definition at line 264 of file tiff.c.

References IMB_TIFF_GET_MEMFILE, ImbTIFFMemFile::mem, and ImbTIFFMemFile::size.

Referenced by imb_tiff_client_open().

static tsize_t imb_tiff_WriteProc ( thandle_t  handle,
tdata_t  data,
tsize_t  n 
) [static]

Writes data to an in-memory TIFF file.

NOTE: The current Blender implementation should not need this function. It is simply a stub.

Definition at line 165 of file tiff.c.

Referenced by imb_tiff_client_open().

static void scanline_contig_16bit ( float *  rectf,
unsigned short *  sbuf,
int  scanline_w,
int  spp 
) [static]

Definition at line 318 of file tiff.c.

References i.

Referenced by imb_read_tiff_pixels().

static void scanline_contig_32bit ( float *  rectf,
float *  fbuf,
int  scanline_w,
int  spp 
) [static]

Definition at line 329 of file tiff.c.

References i.

Referenced by imb_read_tiff_pixels().

static void scanline_separate_16bit ( float *  rectf,
unsigned short *  sbuf,
int  scanline_w,
int  chan 
) [static]

Definition at line 340 of file tiff.c.

References i.

Referenced by imb_read_tiff_pixels().

static void scanline_separate_32bit ( float *  rectf,
float *  fbuf,
int  scanline_w,
int  chan 
) [static]

Definition at line 347 of file tiff.c.

References i.

Referenced by imb_read_tiff_pixels().