Blender
V3.3
|
#include <string.h>
#include "imbuf.h"
#include "BLI_endian_defines.h"
#include "BLI_math.h"
#include "BLI_utildefines.h"
#include "BKE_global.h"
#include "IMB_imbuf.h"
#include "IMB_imbuf_types.h"
#include "IMB_filetype.h"
#include "IMB_colormanagement.h"
#include "IMB_colormanagement_intern.h"
#include <tiffio.h>
Go to the source code of this file.
Classes | |
struct | ImbTIFFMemFile |
Functions | |
Function Implementations | |
static TIFF * | imb_tiff_client_open (ImbTIFFMemFile *memFile, const unsigned char *mem, size_t size) |
Save TIFF | |
bool | imb_savetiff (ImBuf *ibuf, const char *filepath, int flags) |
Local Declarations | |
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 (gray-scale) images correctly, with 8 bits per channel in all cases. The "deflate" compression algorithm is used to compress images. | |
#define | IMB_TIFF_GET_MEMFILE(x) ((ImbTIFFMemFile *)(x)) |
typedef struct ImbTIFFMemFile | ImbTIFFMemFile |
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) |
Load TIFF | |
#define | IMB_TIFF_NCB 4 /* number of comparison bytes used */ |
bool | imb_is_a_tiff (const unsigned char *buf, size_t size) |
static void | scanline_contig_16bit (float *rectf, const unsigned short *sbuf, int scanline_w, int spp) |
static void | scanline_contig_32bit (float *rectf, const float *fbuf, int scanline_w, int spp) |
static void | scanline_separate_16bit (float *rectf, const unsigned short *sbuf, int scanline_w, int chan) |
static void | scanline_separate_32bit (float *rectf, const 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) |
void | imb_inittiff (void) |
ImBuf * | imb_loadtiff (const unsigned char *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE]) |
void | imb_loadtiletiff (ImBuf *ibuf, const unsigned char *mem, size_t size, int tx, int ty, unsigned int *rect) |
#define IMB_TIFF_NCB 4 /* number of comparison bytes used */ |
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.
typedef struct ImbTIFFMemFile ImbTIFFMemFile |
Structure for in-memory TIFF file.
bool imb_is_a_tiff | ( | const unsigned char * | buf, |
size_t | size | ||
) |
Definition at line 306 of file tiff.c.
References IMB_TIFF_NCB, and size().
Referenced by imb_loadtiff().
ImBuf* imb_loadtiff | ( | const unsigned char * | mem, |
size_t | size, | ||
int | flags, | ||
char | colorspace[IM_MAX_SPACE] | ||
) |
Loads a TIFF file.
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. |
Definition at line 542 of file tiff.c.
References ceil(), COLOR_ROLE_DEFAULT_BYTE, colorspace_set_default_role(), ImBuf::flags, ImBuf::ftype, height, IB_alphamode_detect, IB_alphamode_premul, IB_test, IB_tilecache, IM_MAX_SPACE, image(), imb_addtilesImBuf(), IMB_allocImBuf(), imb_is_a_tiff(), imb_read_tiff_pixels(), imb_tiff_client_open(), ImBuf::mipmap, ImBuf::miptot, NULL, size(), STREQ, and width.
void imb_loadtiletiff | ( | ImBuf * | ibuf, |
const unsigned char * | mem, | ||
size_t | size, | ||
int | tx, | ||
int | ty, | ||
unsigned int * | rect | ||
) |
Definition at line 667 of file tiff.c.
References height, image(), imb_tiff_client_open(), ImBuf::miplevel, NULL, size(), ImBuf::tilex, ImBuf::tiley, width, ImBuf::x, ImBuf::y, and ImBuf::ytiles.
|
static |
Definition at line 387 of file tiff.c.
References B_ENDIAN, copy_vn_fl(), copy_vn_ushort(), ELEM, ENDIAN_ORDER, ImBuf::flags, IB_rect, IB_rectfloat, image(), IMB_allocImBuf(), IMB_convert_rgba_to_abgr(), IMB_freeImBuf(), imb_read_tiff_resolution(), ImBuf::mall, NULL, ImBuf::planes, ImBuf::rect, ImBuf::rect_float, scanline_contig_16bit(), scanline_contig_32bit(), scanline_separate_16bit(), scanline_separate_32bit(), ImBuf::x, and ImBuf::y.
Referenced by imb_loadtiff().
Definition at line 362 of file tiff.c.
References double(), image(), and ImBuf::ppm.
Referenced by imb_read_tiff_pixels().
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.
ibuf | Image buffer. |
filepath | Name of the TIFF file to create. |
flags | Currently largely ignored. |
Definition at line 724 of file tiff.c.
References alloc_utf16_from_8(), ImBuf::channels, ImBuf::colormanage_flag, copy_v3_v3(), ELEM, ImbFormatOptions::flag, float(), ImBuf::float_colorspace, ImBuf::foptions, free(), from, IB_mem, image(), IMB_COLORMANAGE_IS_DATA, IMB_DPI_DEFAULT, linearrgb_to_srgb(), linearrgb_to_srgb_v3_v3(), NULL, ImBuf::planes, ImBuf::ppm, ImBuf::rect, ImBuf::rect_float, usdtokens::rgb(), unit_float_to_ushort_clamp(), x, ImBuf::x, y, and ImBuf::y.
|
static |
Definition at line 265 of file tiff.c.
References imb_tiff_CloseProc(), imb_tiff_DummyMapProc(), imb_tiff_DummyUnmapProc(), imb_tiff_ReadProc(), imb_tiff_SeekProc(), imb_tiff_SizeProc(), imb_tiff_WriteProc(), ImbTIFFMemFile::mem, ImbTIFFMemFile::offset, size(), and ImbTIFFMemFile::size.
Referenced by imb_loadtiff(), and imb_loadtiletiff().
|
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).
handle | Handle of the TIFF file (pointer to ImbTIFFMemFile). |
Definition at line 226 of file tiff.c.
References IMB_TIFF_GET_MEMFILE, ImbTIFFMemFile::mem, NULL, ImbTIFFMemFile::offset, and ImbTIFFMemFile::size.
Referenced by imb_tiff_client_open().
|
static |
|
static |
Definition at line 77 of file tiff.c.
Referenced by imb_tiff_client_open().
|
static |
Reads data from an in-memory TIFF file.
handle | Handle of the TIFF file (pointer to ImbTIFFMemFile). |
data | Buffer to contain data (treat as (void *)). |
n | Number of bytes to read. |
Definition at line 113 of file tiff.c.
References data, IMB_TIFF_GET_MEMFILE, ImbTIFFMemFile::mem, ImbTIFFMemFile::offset, and ImbTIFFMemFile::size.
Referenced by imb_tiff_client_open().
|
static |
Seeks to a new location in an in-memory TIFF file.
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). |
Definition at line 181 of file tiff.c.
References IMB_TIFF_GET_MEMFILE, ImbTIFFMemFile::mem, and ImbTIFFMemFile::offset.
Referenced by imb_tiff_client_open().
|
static |
Returns the size of an in-memory TIFF file in bytes.
Definition at line 250 of file tiff.c.
References IMB_TIFF_GET_MEMFILE, ImbTIFFMemFile::mem, and ImbTIFFMemFile::size.
Referenced by imb_tiff_client_open().
|
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 157 of file tiff.c.
Referenced by imb_tiff_client_open().
|
static |
Definition at line 318 of file tiff.c.
Referenced by imb_read_tiff_pixels().
|
static |
Definition at line 332 of file tiff.c.
Referenced by imb_read_tiff_pixels().
|
static |
Definition at line 343 of file tiff.c.
Referenced by imb_read_tiff_pixels().