63 const unsigned char *
mem;
69 #define IMB_TIFF_GET_MEMFILE(x) ((ImbTIFFMemFile *)(x))
115 tsize_t nRemaining, nCopy;
121 if (!mfile || !mfile->
mem) {
122 fprintf(stderr,
"imb_tiff_ReadProc: !mfile || !mfile->mem!\n");
135 if (nCopy > nRemaining) {
145 srcAddr = (
void *)(&(mfile->
mem[mfile->
offset]));
146 memcpy((
void *)
data, srcAddr, nCopy);
163 printf(
"imb_tiff_WriteProc: this function should not be called.\n");
188 if (!mfile || !mfile->
mem) {
189 fprintf(stderr,
"imb_tiff_SeekProc: !mfile || !mfile->mem!\n");
199 new_offset = mfile->
offset + ofs;
204 "imb_tiff_SeekProc: "
205 "Unsupported TIFF SEEK type.\n");
210 mfile->
offset = new_offset;
232 if (!mfile || !mfile->
mem) {
233 fprintf(stderr,
"imb_tiff_CloseProc: !mfile || !mfile->mem!\n");
256 if (!mfile || !mfile->
mem) {
257 fprintf(stderr,
"imb_tiff_SizeProc: !mfile || !mfile->mem!\n");
262 return (toff_t)(mfile->
size);
272 return TIFFClientOpen(
"(Blender TIFF Interface Layer)",
274 (thandle_t)(memFile),
305 #define IMB_TIFF_NCB 4
308 const char big_endian[
IMB_TIFF_NCB] = {0x4d, 0x4d, 0x00, 0x2a};
309 const char lil_endian[
IMB_TIFF_NCB] = {0x49, 0x49, 0x2a, 0x00};
319 const unsigned short *sbuf,
324 for (i = 0; i < scanline_w; i++) {
325 rectf[i * 4 + 0] = sbuf[i * spp + 0] / 65535.0;
326 rectf[i * 4 + 1] = (spp >= 3) ? sbuf[i * spp + 1] / 65535.0 : sbuf[i * spp + 0] / 65535.0;
327 rectf[i * 4 + 2] = (spp >= 3) ? sbuf[i * spp + 2] / 65535.0 : sbuf[i * spp + 0] / 65535.0;
328 rectf[i * 4 + 3] = (spp == 4) ? (sbuf[i * spp + 3] / 65535.0) : 1.0;
335 for (i = 0; i < scanline_w; i++) {
336 rectf[i * 4 + 0] = fbuf[i * spp + 0];
337 rectf[i * 4 + 1] = (spp >= 3) ? fbuf[i * spp + 1] : fbuf[i * spp + 0];
338 rectf[i * 4 + 2] = (spp >= 3) ? fbuf[i * spp + 2] : fbuf[i * spp + 0];
339 rectf[i * 4 + 3] = (spp == 4) ? fbuf[i * spp + 3] : 1.0f;
344 const unsigned short *sbuf,
349 for (i = 0; i < scanline_w; i++) {
350 rectf[i * 4 + chan] = sbuf[i] / 65535.0;
357 for (i = 0; i < scanline_w; i++) {
358 rectf[i * 4 + chan] = fbuf[i];
368 TIFFGetFieldDefaulted(
image, TIFFTAG_RESOLUTIONUNIT, &unit);
369 TIFFGetFieldDefaulted(
image, TIFFTAG_XRESOLUTION, &xres);
370 TIFFGetFieldDefaulted(
image, TIFFTAG_YRESOLUTION, &yres);
372 if (unit == RESUNIT_CENTIMETER) {
391 short bitspersample, spp, config;
393 int ib_flag = 0, row, chan;
395 unsigned short *sbuf =
NULL;
397 TIFFGetField(
image, TIFFTAG_BITSPERSAMPLE, &bitspersample);
398 TIFFGetField(
image, TIFFTAG_SAMPLESPERPIXEL, &spp);
399 TIFFGetField(
image, TIFFTAG_PLANARCONFIG, &config);
413 unsigned short extraSampleTypes[1];
414 extraSampleTypes[0] = EXTRASAMPLE_ASSOCALPHA;
415 TIFFSetField(
image, TIFFTAG_EXTRASAMPLES, 1, extraSampleTypes);
420 scanline = TIFFScanlineSize(
image);
422 if (bitspersample == 32) {
424 fbuf = (
float *)_TIFFmalloc(scanline);
429 else if (bitspersample == 16) {
431 sbuf = (
unsigned short *)_TIFFmalloc(scanline);
446 if (!(
ELEM(bitspersample, 32, 16))) {
447 success |= TIFFReadRGBAImage(
image, ibuf->
x, ibuf->
y, tmpibuf->
rect, 0);
450 else if (config == PLANARCONFIG_CONTIG) {
451 for (row = 0; row < ibuf->
y; row++) {
452 size_t ib_offset = (size_t)ibuf->
x * 4 * ((
size_t)ibuf->
y - ((size_t)row + 1));
454 if (bitspersample == 32) {
455 success |= TIFFReadScanline(
image, fbuf, row, 0);
458 else if (bitspersample == 16) {
459 success |= TIFFReadScanline(
image, sbuf, row, 0);
465 else if (config == PLANARCONFIG_SEPARATE) {
469 for (chan = 0; chan < 4; chan++) {
470 for (row = 0; row < ibuf->
y; row++) {
471 size_t ib_offset = (size_t)ibuf->
x * 4 * ((
size_t)ibuf->
y - ((size_t)row + 1));
473 if (bitspersample == 32) {
474 if (chan == 3 && spp == 3) {
477 else if (chan >= spp) {
478 success |= TIFFReadScanline(
image, fbuf, row, 0);
481 success |= TIFFReadScanline(
image, fbuf, row, chan);
485 else if (bitspersample == 16) {
486 if (chan == 3 && spp == 3) {
489 else if (chan >= spp) {
490 success |= TIFFReadScanline(
image, fbuf, row, 0);
493 success |= TIFFReadScanline(
image, sbuf, row, chan);
503 if (bitspersample < 16) {
516 ibuf->
mall |= ib_flag;
517 ibuf->
flags |= ib_flag;
519 tmpibuf->
mall &= ~ib_flag;
523 if (bitspersample == 32) {
526 else if (bitspersample == 16) {
538 TIFFSetErrorHandler(
NULL);
568 printf(
"imb_loadtiff: could not open TIFF IO layer.\n");
573 TIFFGetField(
image, TIFFTAG_IMAGEWIDTH, &
width);
575 TIFFGetField(
image, TIFFTAG_SAMPLESPERPIXEL, &spp);
577 ib_depth = (spp == 3) ? 24 : 32;
581 ibuf->
ftype = IMB_FTYPE_TIF;
585 "imb_loadtiff: could not allocate memory for TIFF "
594 unsigned short extra, *extraSampleTypes;
596 found = TIFFGetField(
image, TIFFTAG_EXTRASAMPLES, &extra, &extraSampleTypes);
598 if (found && (extraSampleTypes[0] == EXTRASAMPLE_ASSOCALPHA)) {
614 TIFFGetField(
image, TIFFTAG_PIXAR_TEXTUREFORMAT, &
format);
617 int numlevel = TIFFNumberOfDirectories(
image);
620 for (level = 0; level < numlevel; level++) {
621 if (!TIFFSetDirectory(
image, level)) {
630 hbuf->miplevel = level;
631 hbuf->ftype = ibuf->
ftype;
632 ibuf->
mipmap[level - 1] = hbuf;
640 TIFFGetField(
image, TIFFTAG_TILEWIDTH, &hbuf->tilex);
641 TIFFGetField(
image, TIFFTAG_TILELENGTH, &hbuf->tiley);
643 hbuf->xtiles =
ceil(hbuf->x / (
float)hbuf->tilex);
644 hbuf->ytiles =
ceil(hbuf->y / (
float)hbuf->tiley);
655 fprintf(stderr,
"imb_loadtiff: Failed to read tiff image.\n");
668 ImBuf *ibuf,
const unsigned char *mem,
size_t size,
int tx,
int ty,
unsigned int *rect)
677 printf(
"imb_loadtiff: could not open TIFF IO layer for loading mipmap level.\n");
682 TIFFGetField(
image, TIFFTAG_IMAGEWIDTH, &
width);
688 if (TIFFReadRGBATile(
690 if (ibuf->
tiley > ibuf->
y) {
693 sizeof(
int) * ibuf->
tilex * ibuf->
y);
697 printf(
"imb_loadtiff: failed to read tiff tile at mipmap level %d\n", ibuf->
miplevel);
702 printf(
"imb_loadtiff: mipmap level %d has unexpected size %ux%u instead of %dx%d\n",
711 printf(
"imb_loadtiff: could not find mipmap level %d\n", ibuf->
miplevel);
727 uint16_t samplesperpixel, bitspersample;
729 unsigned char *pixels =
NULL;
731 unsigned short *pixels16 =
NULL, *to16 =
NULL;
734 int x,
y, from_i, to_i, i;
735 int compress_mode = COMPRESSION_NONE;
741 if ((samplesperpixel > 4) || (samplesperpixel == 2)) {
743 "imb_savetiff: unsupported number of bytes per "
757 compress_mode = COMPRESSION_DEFLATE;
760 compress_mode = COMPRESSION_LZW;
763 compress_mode = COMPRESSION_PACKBITS;
770 "imb_savetiff: creation of in-memory TIFF files is "
771 "not yet supported.\n");
778 image = TIFFOpenW(wname,
"w");
781 image = TIFFOpen(filepath,
"w");
785 fprintf(stderr,
"imb_savetiff: could not open TIFF for writing.\n");
790 npixels = ibuf->
x * ibuf->
y;
791 if (bitspersample == 16) {
792 pixels16 = (
unsigned short *)_TIFFmalloc(npixels * samplesperpixel *
sizeof(
unsigned short));
795 pixels = (
unsigned char *)_TIFFmalloc(npixels * samplesperpixel *
sizeof(
unsigned char));
798 if (pixels ==
NULL && pixels16 ==
NULL) {
799 fprintf(stderr,
"imb_savetiff: could not allocate pixels array.\n");
805 if (bitspersample == 16) {
815 TIFFSetField(
image, TIFFTAG_BITSPERSAMPLE, bitspersample);
816 TIFFSetField(
image, TIFFTAG_SAMPLESPERPIXEL, samplesperpixel);
818 if (samplesperpixel == 4) {
819 unsigned short extraSampleTypes[1];
821 if (bitspersample == 16) {
822 extraSampleTypes[0] = EXTRASAMPLE_ASSOCALPHA;
825 extraSampleTypes[0] = EXTRASAMPLE_UNASSALPHA;
829 TIFFSetField(
image, TIFFTAG_EXTRASAMPLES, 1, extraSampleTypes);
830 TIFFSetField(
image, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
832 else if (samplesperpixel == 3) {
834 TIFFSetField(
image, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
836 else if (samplesperpixel == 1) {
838 TIFFSetField(
image, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
843 for (
x = 0;
x < ibuf->
x;
x++) {
844 for (
y = 0;
y < ibuf->
y;
y++) {
845 from_i = ((size_t)channels_in_float) * (
y * ibuf->
x +
x);
846 to_i = samplesperpixel * ((ibuf->
y -
y - 1) * ibuf->
x +
x);
852 if (
ELEM(channels_in_float, 3, 4)) {
863 if (channels_in_float == 4) {
864 rgb[3] = fromf[from_i + 3];
872 rgb[0] = fromf[from_i];
881 for (i = 0; i < samplesperpixel; i++, to_i++) {
886 for (i = 0; i < samplesperpixel; i++, to_i++, from_i++) {
887 to[to_i] =
from[from_i];
894 TIFFSetField(
image, TIFFTAG_IMAGEWIDTH, ibuf->
x);
895 TIFFSetField(
image, TIFFTAG_IMAGELENGTH, ibuf->
y);
896 TIFFSetField(
image, TIFFTAG_ROWSPERSTRIP, ibuf->
y);
897 TIFFSetField(
image, TIFFTAG_COMPRESSION, compress_mode);
898 TIFFSetField(
image, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);
899 TIFFSetField(
image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
901 if (ibuf->
ppm[0] > 0.0 && ibuf->
ppm[1] > 0.0) {
902 xres = (
float)(ibuf->
ppm[0] * 0.0254);
903 yres = (
float)(ibuf->
ppm[1] * 0.0254);
909 TIFFSetField(
image, TIFFTAG_XRESOLUTION, xres);
910 TIFFSetField(
image, TIFFTAG_YRESOLUTION, yres);
911 TIFFSetField(
image, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
912 if (TIFFWriteEncodedStrip(
image,
914 (bitspersample == 16) ? (
unsigned char *)pixels16 : pixels,
915 (
size_t)ibuf->
x * ibuf->
y * samplesperpixel * bitspersample / 8) ==
917 fprintf(stderr,
"imb_savetiff: Could not write encoded TIFF.\n");
typedef float(TangentPoint)[2]
void BLI_kdtree_nd_() free(KDTree *tree)
MINLINE void linearrgb_to_srgb_v3_v3(float srgb[3], const float linear[3])
float linearrgb_to_srgb(float c)
MINLINE void copy_v3_v3(float r[3], const float a[3])
void copy_vn_fl(float *array_tar, int size, float val)
void copy_vn_ushort(unsigned short *array_tar, int size, unsigned short val)
typedef double(DMatrix)[4][4]
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
@ COLOR_ROLE_DEFAULT_BYTE
struct ImBuf * IMB_allocImBuf(unsigned int x, unsigned int y, unsigned char planes, unsigned int flags)
bool imb_addtilesImBuf(struct ImBuf *ibuf)
void IMB_convert_rgba_to_abgr(struct ImBuf *ibuf)
Contains defines and structs used throughout the imbuf module.
@ IMB_COLORMANAGE_IS_DATA
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
void colorspace_set_default_role(char *colorspace, int size, int role)
SyclQueue void void size_t num_bytes void
depth_tx normal_tx diffuse_light_tx specular_light_tx volume_light_tx environment_tx ambient_occlusion_tx aov_value_tx in_weight_img image(1, GPU_R32F, Qualifier::WRITE, ImageType::FLOAT_2D_ARRAY, "out_weight_img") .image(3
void IMB_freeImBuf(ImBuf *UNUSED(ibuf))
MINLINE unsigned short unit_float_to_ushort_clamp(float val)
ccl_device_inline float3 ceil(const float3 &a)
static const pxr::TfToken rgb("rgb", pxr::TfToken::Immortal)
struct ImBuf * mipmap[IMB_MIPMAP_LEVELS]
ImbFormatOptions foptions
struct ColorSpace * float_colorspace
const unsigned char * mem
bool imb_is_a_tiff(const unsigned char *buf, size_t size)
static int imb_tiff_DummyMapProc(thandle_t fd, tdata_t *pbase, toff_t *psize)
#define IMB_TIFF_GET_MEMFILE(x)
static toff_t imb_tiff_SeekProc(thandle_t handle, toff_t ofs, int whence)
static tsize_t imb_tiff_WriteProc(thandle_t handle, tdata_t data, tsize_t n)
struct ImbTIFFMemFile ImbTIFFMemFile
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 toff_t imb_tiff_SizeProc(thandle_t handle)
void imb_loadtiletiff(ImBuf *ibuf, const unsigned char *mem, size_t size, int tx, int ty, unsigned int *rect)
ImBuf * imb_loadtiff(const unsigned char *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE])
static TIFF * imb_tiff_client_open(ImbTIFFMemFile *memFile, const unsigned char *mem, size_t size)
static void scanline_separate_32bit(float *rectf, const float *fbuf, int scanline_w, int chan)
bool imb_savetiff(ImBuf *ibuf, const char *filepath, int flags)
static tsize_t imb_tiff_ReadProc(thandle_t handle, tdata_t data, tsize_t n)
static void imb_tiff_DummyUnmapProc(thandle_t fd, tdata_t base, toff_t size)
static int imb_read_tiff_pixels(ImBuf *ibuf, TIFF *image)
static int imb_tiff_CloseProc(thandle_t handle)
static void imb_read_tiff_resolution(ImBuf *ibuf, TIFF *image)
static void scanline_contig_16bit(float *rectf, const unsigned short *sbuf, int scanline_w, int spp)
wchar_t * alloc_utf16_from_8(const char *in8, size_t add)