ReactOS 0.4.16-dev-2617-g01a0906
tif_getimage.c File Reference
#include "tiffiop.h"
#include <limits.h>
#include <stdio.h>
Include dependency graph for tif_getimage.c:

Go to the source code of this file.

Macros

#define FLIP_VERTICALLY   0x01
 
#define FLIP_HORIZONTALLY   0x02
 
#define EMSG_BUF_SIZE   1024
 
#define REPEAT8(op)
 
#define REPEAT4(op)
 
#define REPEAT2(op)
 
#define CASE8(x, op)
 
#define CASE4(x, op)
 
#define NOP
 
#define UNROLL8(w, op1, op2)
 
#define UNROLL4(w, op1, op2)
 
#define UNROLL2(w, op1, op2)
 
#define SKEW(r, g, b, skew)
 
#define SKEW4(r, g, b, a, skew)
 
#define A1   (((uint32_t)0xffL) << 24)
 
#define PACK(r, g, b)    ((uint32_t)(r) | ((uint32_t)(g) << 8) | ((uint32_t)(b) << 16) | A1)
 
#define PACK4(r, g, b, a)
 
#define W2B(v)   (((v) >> 8) & 0xff)
 
#define PACKW(r, g, b)    ((uint32_t)W2B(r) | ((uint32_t)W2B(g) << 8) | ((uint32_t)W2B(b) << 16) | A1)
 
#define PACKW4(r, g, b, a)
 
#define DECLAREContigPutFunc(name)
 
#define DECLARESepPutFunc(name)
 
#define YCbCrtoRGB(dst, Y)
 
#define GREY(x)
 
#define CVT(x)   ((uint16_t)((x) >> 8))
 
#define CMAP(x)
 

Functions

static int gtTileContig (TIFFRGBAImage *, uint32_t *, uint32_t, uint32_t)
 
static int gtTileSeparate (TIFFRGBAImage *, uint32_t *, uint32_t, uint32_t)
 
static int gtStripContig (TIFFRGBAImage *, uint32_t *, uint32_t, uint32_t)
 
static int gtStripSeparate (TIFFRGBAImage *, uint32_t *, uint32_t, uint32_t)
 
static int PickContigCase (TIFFRGBAImage *)
 
static int PickSeparateCase (TIFFRGBAImage *)
 
static int BuildMapUaToAa (TIFFRGBAImage *img)
 
static int BuildMapBitdepth16To8 (TIFFRGBAImage *img)
 
int TIFFRGBAImageOK (TIFF *tif, char emsg[EMSG_BUF_SIZE])
 
void TIFFRGBAImageEnd (TIFFRGBAImage *img)
 
static int isCCITTCompression (TIFF *tif)
 
int TIFFRGBAImageBegin (TIFFRGBAImage *img, TIFF *tif, int stop, char emsg[EMSG_BUF_SIZE])
 
int TIFFRGBAImageGet (TIFFRGBAImage *img, uint32_t *raster, uint32_t w, uint32_t h)
 
int TIFFReadRGBAImageOriented (TIFF *tif, uint32_t rwidth, uint32_t rheight, uint32_t *raster, int orientation, int stop)
 
int TIFFReadRGBAImage (TIFF *tif, uint32_t rwidth, uint32_t rheight, uint32_t *raster, int stop)
 
static int setorientation (TIFFRGBAImage *img)
 
 DECLAREContigPutFunc (put8bitcmaptile)
 
 DECLAREContigPutFunc (put4bitcmaptile)
 
 DECLAREContigPutFunc (put2bitcmaptile)
 
 DECLAREContigPutFunc (put1bitcmaptile)
 
 DECLAREContigPutFunc (putgreytile)
 
 DECLAREContigPutFunc (putagreytile)
 
 DECLAREContigPutFunc (put16bitbwtile)
 
 DECLAREContigPutFunc (put1bitbwtile)
 
 DECLAREContigPutFunc (put2bitbwtile)
 
 DECLAREContigPutFunc (put4bitbwtile)
 
 DECLAREContigPutFunc (putRGBcontig8bittile)
 
 DECLAREContigPutFunc (putRGBAAcontig8bittile)
 
 DECLAREContigPutFunc (putRGBUAcontig8bittile)
 
 DECLAREContigPutFunc (putRGBcontig16bittile)
 
 DECLAREContigPutFunc (putRGBAAcontig16bittile)
 
 DECLAREContigPutFunc (putRGBUAcontig16bittile)
 
 DECLAREContigPutFunc (putRGBcontig8bitCMYKtile)
 
 DECLAREContigPutFunc (putRGBcontig8bitCMYKMaptile)
 
 DECLARESepPutFunc (putRGBseparate8bittile)
 
 DECLARESepPutFunc (putRGBAAseparate8bittile)
 
 DECLARESepPutFunc (putCMYKseparate8bittile)
 
 DECLARESepPutFunc (putRGBUAseparate8bittile)
 
 DECLARESepPutFunc (putRGBseparate16bittile)
 
 DECLARESepPutFunc (putRGBAAseparate16bittile)
 
 DECLARESepPutFunc (putRGBUAseparate16bittile)
 
 DECLAREContigPutFunc (putcontig8bitCIELab8)
 
 DECLAREContigPutFunc (putcontig8bitCIELab16)
 
 DECLAREContigPutFunc (putcontig8bitYCbCr44tile)
 
 DECLAREContigPutFunc (putcontig8bitYCbCr42tile)
 
 DECLAREContigPutFunc (putcontig8bitYCbCr41tile)
 
 DECLAREContigPutFunc (putcontig8bitYCbCr22tile)
 
 DECLAREContigPutFunc (putcontig8bitYCbCr21tile)
 
 DECLAREContigPutFunc (putcontig8bitYCbCr12tile)
 
 DECLAREContigPutFunc (putcontig8bitYCbCr11tile)
 
 DECLARESepPutFunc (putseparate8bitYCbCr11tile)
 
static int isInRefBlackWhiteRange (float f)
 
static int initYCbCrConversion (TIFFRGBAImage *img)
 
static tileContigRoutine initCIELabConversion (TIFFRGBAImage *img)
 
static int makebwmap (TIFFRGBAImage *img)
 
static int setupMap (TIFFRGBAImage *img)
 
static int checkcmap (TIFFRGBAImage *img)
 
static void cvtcmap (TIFFRGBAImage *img)
 
static int makecmap (TIFFRGBAImage *img)
 
static int buildMap (TIFFRGBAImage *img)
 
int TIFFReadRGBAStrip (TIFF *tif, uint32_t row, uint32_t *raster)
 
int TIFFReadRGBAStripExt (TIFF *tif, uint32_t row, uint32_t *raster, int stop_on_error)
 
int TIFFReadRGBATile (TIFF *tif, uint32_t col, uint32_t row, uint32_t *raster)
 
int TIFFReadRGBATileExt (TIFF *tif, uint32_t col, uint32_t row, uint32_t *raster, int stop_on_error)
 

Variables

static const char photoTag [] = "PhotometricInterpretation"
 
static const TIFFDisplay display_sRGB
 

Macro Definition Documentation

◆ A1

#define A1   (((uint32_t)0xffL) << 24)

Definition at line 1578 of file tif_getimage.c.

◆ CASE4

#define CASE4 (   x,
  op 
)
Value:
switch (x) \
{ \
case 3: \
op; /*-fallthrough*/ \
case 2: \
op; /*-fallthrough*/ \
case 1: \
op; \
}
UINT op
Definition: effect.c:236
GLint GLint GLint GLint GLint x
Definition: gl.h:1548

Definition at line 1509 of file tif_getimage.c.

◆ CASE8

#define CASE8 (   x,
  op 
)
Value:
switch (x) \
{ \
case 7: \
op; /*-fallthrough*/ \
case 6: \
op; /*-fallthrough*/ \
case 5: \
op; /*-fallthrough*/ \
case 4: \
op; /*-fallthrough*/ \
case 3: \
op; /*-fallthrough*/ \
case 2: \
op; /*-fallthrough*/ \
case 1: \
op; \
}

Definition at line 1491 of file tif_getimage.c.

◆ CMAP

#define CMAP (   x)
Value:
*p++ = PACK(r[c] & 0xff, g[c] & 0xff, b[c] & 0xff);
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
const GLubyte * c
Definition: glext.h:8905
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean g
Definition: glext.h:6204
GLfloat GLfloat p
Definition: glext.h:8902
#define PACK(r, g, b)
unsigned char TIFFRGBValue
Definition: tiffio.h:138

◆ CVT

#define CVT (   x)    ((uint16_t)((x) >> 8))

◆ DECLAREContigPutFunc

#define DECLAREContigPutFunc (   name)
Value:
uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, \
unsigned char *pp)
INT32 int32_t
Definition: types.h:71
UINT32 uint32_t
Definition: types.h:75
GLint GLvoid * img
Definition: gl.h:1956
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:6102
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
POINT cp
Definition: magnifier.c:59
Definition: name.c:39

Definition at line 1592 of file tif_getimage.c.

◆ DECLARESepPutFunc

#define DECLARESepPutFunc (   name)
Value:
uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, \
unsigned char *r, unsigned char *g, unsigned char *b, \
unsigned char *a)
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204

Definition at line 1993 of file tif_getimage.c.

◆ EMSG_BUF_SIZE

#define EMSG_BUF_SIZE   1024

Definition at line 52 of file tif_getimage.c.

◆ FLIP_HORIZONTALLY

#define FLIP_HORIZONTALLY   0x02

Definition at line 50 of file tif_getimage.c.

◆ FLIP_VERTICALLY

#define FLIP_VERTICALLY   0x01

Definition at line 49 of file tif_getimage.c.

◆ GREY

#define GREY (   x)
Value:
c = Map[x]; \
*p++ = PACK(c, c, c);

◆ NOP

#define NOP

Definition at line 1519 of file tif_getimage.c.

◆ PACK

#define PACK (   r,
  g,
  b 
)     ((uint32_t)(r) | ((uint32_t)(g) << 8) | ((uint32_t)(b) << 16) | A1)

Definition at line 1579 of file tif_getimage.c.

◆ PACK4

#define PACK4 (   r,
  g,
  b,
  a 
)
Value:
((uint32_t)(r) | ((uint32_t)(g) << 8) | ((uint32_t)(b) << 16) | \
((uint32_t)(a) << 24))
#define b
Definition: ke_i.h:79
#define uint32_t
Definition: nsiface.idl:61

Definition at line 1581 of file tif_getimage.c.

◆ PACKW

#define PACKW (   r,
  g,
  b 
)     ((uint32_t)W2B(r) | ((uint32_t)W2B(g) << 8) | ((uint32_t)W2B(b) << 16) | A1)

Definition at line 1586 of file tif_getimage.c.

◆ PACKW4

#define PACKW4 (   r,
  g,
  b,
  a 
)
Value:
((uint32_t)W2B(r) | ((uint32_t)W2B(g) << 8) | ((uint32_t)W2B(b) << 16) | \
((uint32_t)W2B(a) << 24))
#define W2B(v)

Definition at line 1588 of file tif_getimage.c.

◆ REPEAT2

#define REPEAT2 (   op)
Value:
op; \

Definition at line 1488 of file tif_getimage.c.

◆ REPEAT4

#define REPEAT4 (   op)
Value:
REPEAT2(op); \
REPEAT2(op)
#define REPEAT2(op)

Definition at line 1485 of file tif_getimage.c.

◆ REPEAT8

#define REPEAT8 (   op)
Value:
REPEAT4(op); \
REPEAT4(op)
#define REPEAT4(op)

Definition at line 1482 of file tif_getimage.c.

◆ SKEW

#define SKEW (   r,
  g,
  b,
  skew 
)
Value:
{ \
r += skew; \
g += skew; \
b += skew; \
}

Definition at line 1564 of file tif_getimage.c.

◆ SKEW4

#define SKEW4 (   r,
  g,
  b,
  a,
  skew 
)
Value:
{ \
r += skew; \
g += skew; \
b += skew; \
a += skew; \
}

Definition at line 1570 of file tif_getimage.c.

◆ UNROLL2

#define UNROLL2 (   w,
  op1,
  op2 
)
Value:
{ \
for (_x = w; _x >= 2; _x -= 2) \
{ \
op1; \
REPEAT2(op2); \
} \
if (_x) \
{ \
op1; \
op2; \
} \
}
#define _x(oid)

Definition at line 1549 of file tif_getimage.c.

◆ UNROLL4

#define UNROLL4 (   w,
  op1,
  op2 
)
Value:
{ \
for (_x = w; _x >= 4; _x -= 4) \
{ \
op1; \
REPEAT4(op2); \
} \
if (_x > 0) \
{ \
op1; \
CASE4(_x, op2); \
} \
}

Definition at line 1535 of file tif_getimage.c.

◆ UNROLL8

#define UNROLL8 (   w,
  op1,
  op2 
)
Value:
{ \
for (_x = w; _x >= 8; _x -= 8) \
{ \
op1; \
REPEAT8(op2); \
} \
if (_x > 0) \
{ \
op1; \
CASE8(_x, op2); \
} \
}

Definition at line 1521 of file tif_getimage.c.

◆ W2B

#define W2B (   v)    (((v) >> 8) & 0xff)

Definition at line 1584 of file tif_getimage.c.

◆ YCbCrtoRGB

#define YCbCrtoRGB (   dst,
  Y 
)
Value:
{ \
uint32_t r, g, b; \
TIFFYCbCrtoRGB(img->ycbcr, (Y), Cb, Cr, &r, &g, &b); \
dst = PACK(r, g, b); \
}
#define Y(I)
GLenum GLenum dst
Definition: glext.h:6340

Definition at line 2204 of file tif_getimage.c.

Function Documentation

◆ buildMap()

static int buildMap ( TIFFRGBAImage img)
static

Definition at line 3019 of file tif_getimage.c.

3020{
3021 switch (img->photometric)
3022 {
3023 case PHOTOMETRIC_RGB:
3024 case PHOTOMETRIC_YCBCR:
3026 if (img->bitspersample == 8)
3027 break;
3028 /* fall through... */
3031 if (!setupMap(img))
3032 return (0);
3033 break;
3035 /*
3036 * Convert 16-bit colormap to 8-bit (unless it looks
3037 * like an old-style 8-bit colormap).
3038 */
3039 if (checkcmap(img) == 16)
3040 cvtcmap(img);
3041 else
3042 TIFFWarningExtR(img->tif, TIFFFileName(img->tif),
3043 "Assuming 8-bit colormap");
3044 /*
3045 * Use mapping table and colormap to construct
3046 * unpacking tables for samples < 8 bits.
3047 */
3048 if (img->bitspersample <= 8 && !makecmap(img))
3049 return (0);
3050 break;
3051 }
3052 return (1);
3053}
static int setupMap(TIFFRGBAImage *img)
static void cvtcmap(TIFFRGBAImage *img)
static int checkcmap(TIFFRGBAImage *img)
static int makecmap(TIFFRGBAImage *img)
const char * TIFFFileName(TIFF *tif)
Definition: tif_open.c:798
void TIFFWarningExtR(TIFF *tif, const char *module, const char *fmt,...)
Definition: tif_warning.c:80
#define PHOTOMETRIC_PALETTE
Definition: tiff.h:224
#define PHOTOMETRIC_SEPARATED
Definition: tiff.h:226
#define PHOTOMETRIC_YCBCR
Definition: tiff.h:227
#define PHOTOMETRIC_MINISWHITE
Definition: tiff.h:221
#define PHOTOMETRIC_MINISBLACK
Definition: tiff.h:222
#define PHOTOMETRIC_RGB
Definition: tiff.h:223

Referenced by PickContigCase().

◆ BuildMapBitdepth16To8()

static int BuildMapBitdepth16To8 ( TIFFRGBAImage img)
static

Definition at line 3316 of file tif_getimage.c.

3317{
3318 static const char module[] = "BuildMapBitdepth16To8";
3319 uint8_t *m;
3320 uint32_t n;
3321 assert(img->Bitdepth16To8 == NULL);
3322 img->Bitdepth16To8 = _TIFFmallocExt(img->tif, 65536);
3323 if (img->Bitdepth16To8 == NULL)
3324 {
3325 TIFFErrorExtR(img->tif, module, "Out of memory");
3326 return (0);
3327 }
3328 m = img->Bitdepth16To8;
3329 for (n = 0; n < 65536; n++)
3330 *m++ = (uint8_t)((n + 128) / 257);
3331 return (1);
3332}
#define NULL
Definition: types.h:112
#define assert(_expr)
Definition: assert.h:32
unsigned char uint8_t
Definition: stdint.h:33
GLdouble n
Definition: glext.h:7729
const GLfloat * m
Definition: glext.h:10848
void TIFFErrorExtR(TIFF *tif, const char *module, const char *fmt,...)
Definition: tif_error.c:107
void * _TIFFmallocExt(TIFF *tif, tmsize_t s)
Definition: tif_open.c:173

Referenced by PickContigCase(), and PickSeparateCase().

◆ BuildMapUaToAa()

static int BuildMapUaToAa ( TIFFRGBAImage img)
static

Definition at line 3295 of file tif_getimage.c.

3296{
3297 static const char module[] = "BuildMapUaToAa";
3298 uint8_t *m;
3299 uint16_t na, nv;
3300 assert(img->UaToAa == NULL);
3301 img->UaToAa = _TIFFmallocExt(img->tif, 65536);
3302 if (img->UaToAa == NULL)
3303 {
3304 TIFFErrorExtR(img->tif, module, "Out of memory");
3305 return (0);
3306 }
3307 m = img->UaToAa;
3308 for (na = 0; na < 256; na++)
3309 {
3310 for (nv = 0; nv < 256; nv++)
3311 *m++ = (uint8_t)((nv * na + 127) / 255);
3312 }
3313 return (1);
3314}
unsigned short uint16_t
Definition: stdint.h:35

Referenced by PickContigCase(), and PickSeparateCase().

◆ checkcmap()

static int checkcmap ( TIFFRGBAImage img)
static

Definition at line 2920 of file tif_getimage.c.

2921{
2922 uint16_t *r = img->redcmap;
2923 uint16_t *g = img->greencmap;
2924 uint16_t *b = img->bluecmap;
2925 long n = 1L << img->bitspersample;
2926
2927 while (n-- > 0)
2928 if (*r++ >= 256 || *g++ >= 256 || *b++ >= 256)
2929 return (16);
2930 return (8);
2931}

Referenced by buildMap().

◆ cvtcmap()

static void cvtcmap ( TIFFRGBAImage img)
static

Definition at line 2933 of file tif_getimage.c.

2934{
2935 uint16_t *r = img->redcmap;
2936 uint16_t *g = img->greencmap;
2937 uint16_t *b = img->bluecmap;
2938 long i;
2939
2940 for (i = (1L << img->bitspersample) - 1; i >= 0; i--)
2941 {
2942#define CVT(x) ((uint16_t)((x) >> 8))
2943 r[i] = CVT(r[i]);
2944 g[i] = CVT(g[i]);
2945 b[i] = CVT(b[i]);
2946#undef CVT
2947 }
2948}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define CVT(x)

Referenced by buildMap().

◆ DECLAREContigPutFunc() [1/27]

DECLAREContigPutFunc ( put16bitbwtile  )

Definition at line 1720 of file tif_getimage.c.

1721{
1722 int samplesperpixel = img->samplesperpixel;
1723 uint32_t **BWmap = img->BWmap;
1724
1725 (void)y;
1726 for (; h > 0; --h)
1727 {
1728 uint16_t *wp = (uint16_t *)pp;
1729
1730 for (x = w; x > 0; --x)
1731 {
1732 /* use high order byte of 16bit value */
1733
1734 *cp++ = BWmap[*wp >> 8][0];
1735 pp += 2 * samplesperpixel;
1736 wp += samplesperpixel;
1737 }
1738 cp += toskew;
1739 pp += fromskew;
1740 }
1741}

◆ DECLAREContigPutFunc() [2/27]

DECLAREContigPutFunc ( put1bitbwtile  )

Definition at line 1746 of file tif_getimage.c.

1747{
1748 uint32_t **BWmap = img->BWmap;
1749
1750 (void)x;
1751 (void)y;
1752 fromskew /= 8;
1753 for (; h > 0; --h)
1754 {
1755 uint32_t *bw;
1756 UNROLL8(w, bw = BWmap[*pp++], *cp++ = *bw++);
1757 cp += toskew;
1758 pp += fromskew;
1759 }
1760}
static int bw
Definition: maze.c:120
#define UNROLL8(w, op1, op2)

◆ DECLAREContigPutFunc() [3/27]

DECLAREContigPutFunc ( put1bitcmaptile  )

Definition at line 1659 of file tif_getimage.c.

1660{
1661 uint32_t **PALmap = img->PALmap;
1662
1663 (void)x;
1664 (void)y;
1665 fromskew /= 8;
1666 for (; h > 0; --h)
1667 {
1668 uint32_t *bw;
1669 UNROLL8(w, bw = PALmap[*pp++], *cp++ = *bw++);
1670 cp += toskew;
1671 pp += fromskew;
1672 }
1673}

◆ DECLAREContigPutFunc() [4/27]

DECLAREContigPutFunc ( put2bitbwtile  )

Definition at line 1765 of file tif_getimage.c.

1766{
1767 uint32_t **BWmap = img->BWmap;
1768
1769 (void)x;
1770 (void)y;
1771 fromskew /= 4;
1772 for (; h > 0; --h)
1773 {
1774 uint32_t *bw;
1775 UNROLL4(w, bw = BWmap[*pp++], *cp++ = *bw++);
1776 cp += toskew;
1777 pp += fromskew;
1778 }
1779}
#define UNROLL4(w, op1, op2)

◆ DECLAREContigPutFunc() [5/27]

DECLAREContigPutFunc ( put2bitcmaptile  )

Definition at line 1640 of file tif_getimage.c.

1641{
1642 uint32_t **PALmap = img->PALmap;
1643
1644 (void)x;
1645 (void)y;
1646 fromskew /= 4;
1647 for (; h > 0; --h)
1648 {
1649 uint32_t *bw;
1650 UNROLL4(w, bw = PALmap[*pp++], *cp++ = *bw++);
1651 cp += toskew;
1652 pp += fromskew;
1653 }
1654}

◆ DECLAREContigPutFunc() [6/27]

DECLAREContigPutFunc ( put4bitbwtile  )

Definition at line 1784 of file tif_getimage.c.

1785{
1786 uint32_t **BWmap = img->BWmap;
1787
1788 (void)x;
1789 (void)y;
1790 fromskew /= 2;
1791 for (; h > 0; --h)
1792 {
1793 uint32_t *bw;
1794 UNROLL2(w, bw = BWmap[*pp++], *cp++ = *bw++);
1795 cp += toskew;
1796 pp += fromskew;
1797 }
1798}
#define UNROLL2(w, op1, op2)

◆ DECLAREContigPutFunc() [7/27]

DECLAREContigPutFunc ( put4bitcmaptile  )

Definition at line 1621 of file tif_getimage.c.

1622{
1623 uint32_t **PALmap = img->PALmap;
1624
1625 (void)x;
1626 (void)y;
1627 fromskew /= 2;
1628 for (; h > 0; --h)
1629 {
1630 uint32_t *bw;
1631 UNROLL2(w, bw = PALmap[*pp++], *cp++ = *bw++);
1632 cp += toskew;
1633 pp += fromskew;
1634 }
1635}

◆ DECLAREContigPutFunc() [8/27]

DECLAREContigPutFunc ( put8bitcmaptile  )

Definition at line 1600 of file tif_getimage.c.

1601{
1602 uint32_t **PALmap = img->PALmap;
1603 int samplesperpixel = img->samplesperpixel;
1604
1605 (void)y;
1606 for (; h > 0; --h)
1607 {
1608 for (x = w; x > 0; --x)
1609 {
1610 *cp++ = PALmap[*pp][0];
1611 pp += samplesperpixel;
1612 }
1613 cp += toskew;
1614 pp += fromskew;
1615 }
1616}

◆ DECLAREContigPutFunc() [9/27]

DECLAREContigPutFunc ( putagreytile  )

Definition at line 1699 of file tif_getimage.c.

1700{
1701 int samplesperpixel = img->samplesperpixel;
1702 uint32_t **BWmap = img->BWmap;
1703
1704 (void)y;
1705 for (; h > 0; --h)
1706 {
1707 for (x = w; x > 0; --x)
1708 {
1709 *cp++ = BWmap[*pp][0] & ((uint32_t) * (pp + 1) << 24 | ~A1);
1710 pp += samplesperpixel;
1711 }
1712 cp += toskew;
1713 pp += fromskew;
1714 }
1715}

◆ DECLAREContigPutFunc() [10/27]

DECLAREContigPutFunc ( putcontig8bitCIELab16  )

Definition at line 2178 of file tif_getimage.c.

2179{
2180 float X, Y, Z;
2181 uint32_t r, g, b;
2182 uint16_t *wp = (uint16_t *)pp;
2183 (void)y;
2184 fromskew *= 3;
2185 for (; h > 0; --h)
2186 {
2187 for (x = w; x > 0; --x)
2188 {
2189 TIFFCIELab16ToXYZ(img->cielab, (uint16_t)wp[0], (int16_t)wp[1],
2190 (int16_t)wp[2], &X, &Y, &Z);
2191 TIFFXYZToRGB(img->cielab, X, Y, Z, &r, &g, &b);
2192 *cp++ = PACK(r, g, b);
2193 wp += 3;
2194 }
2195 cp += toskew;
2196 wp += fromskew;
2197 }
2198}
INT16 int16_t
Definition: types.h:70
#define Z(I)
#define X(b, s)
void TIFFCIELab16ToXYZ(TIFFCIELabToRGB *cielab, uint32_t l, int32_t a, int32_t b, float *X, float *Y, float *Z)
Definition: tif_color.c:55
void TIFFXYZToRGB(TIFFCIELabToRGB *cielab, float X, float Y, float Z, uint32_t *r, uint32_t *g, uint32_t *b)
Definition: tif_color.c:89

◆ DECLAREContigPutFunc() [11/27]

DECLAREContigPutFunc ( putcontig8bitCIELab8  )

Definition at line 2154 of file tif_getimage.c.

2155{
2156 float X, Y, Z;
2157 uint32_t r, g, b;
2158 (void)y;
2159 fromskew *= 3;
2160 for (; h > 0; --h)
2161 {
2162 for (x = w; x > 0; --x)
2163 {
2164 TIFFCIELabToXYZ(img->cielab, (unsigned char)pp[0],
2165 (signed char)pp[1], (signed char)pp[2], &X, &Y, &Z);
2166 TIFFXYZToRGB(img->cielab, X, Y, Z, &r, &g, &b);
2167 *cp++ = PACK(r, g, b);
2168 pp += 3;
2169 }
2170 cp += toskew;
2171 pp += fromskew;
2172 }
2173}
void TIFFCIELabToXYZ(TIFFCIELabToRGB *cielab, uint32_t l, int32_t a, int32_t b, float *X, float *Y, float *Z)
Definition: tif_color.c:43

◆ DECLAREContigPutFunc() [12/27]

DECLAREContigPutFunc ( putcontig8bitYCbCr11tile  )

Definition at line 2657 of file tif_getimage.c.

2658{
2659 (void)y;
2660 fromskew = (fromskew / 1) * (1 * 1 + 2);
2661 do
2662 {
2663 x = w; /* was x = w>>1; patched 2000/09/25 warmerda@home.com */
2664 do
2665 {
2666 int32_t Cb = pp[1];
2667 int32_t Cr = pp[2];
2668
2669 YCbCrtoRGB(*cp++, pp[0]);
2670
2671 pp += 3;
2672 } while (--x);
2673 cp += toskew;
2674 pp += fromskew;
2675 } while (--h);
2676}
#define YCbCrtoRGB(dst, Y)

◆ DECLAREContigPutFunc() [13/27]

DECLAREContigPutFunc ( putcontig8bitYCbCr12tile  )

Definition at line 2615 of file tif_getimage.c.

2616{
2617 uint32_t *cp2;
2618 int32_t incr = 2 * toskew + w;
2619 (void)y;
2620 fromskew = (fromskew / 1) * (1 * 2 + 2);
2621 cp2 = cp + w + toskew;
2622 while (h >= 2)
2623 {
2624 x = w;
2625 do
2626 {
2627 uint32_t Cb = pp[2];
2628 uint32_t Cr = pp[3];
2629 YCbCrtoRGB(cp[0], pp[0]);
2630 YCbCrtoRGB(cp2[0], pp[1]);
2631 cp++;
2632 cp2++;
2633 pp += 4;
2634 } while (--x);
2635 cp += incr;
2636 cp2 += incr;
2637 pp += fromskew;
2638 h -= 2;
2639 }
2640 if (h == 1)
2641 {
2642 x = w;
2643 do
2644 {
2645 uint32_t Cb = pp[2];
2646 uint32_t Cr = pp[3];
2647 YCbCrtoRGB(cp[0], pp[0]);
2648 cp++;
2649 pp += 4;
2650 } while (--x);
2651 }
2652}

◆ DECLAREContigPutFunc() [14/27]

DECLAREContigPutFunc ( putcontig8bitYCbCr21tile  )

Definition at line 2576 of file tif_getimage.c.

2577{
2578 (void)y;
2579 fromskew = (fromskew / 2) * (2 * 1 + 2);
2580 do
2581 {
2582 x = w >> 1;
2583 while (x > 0)
2584 {
2585 int32_t Cb = pp[2];
2586 int32_t Cr = pp[3];
2587
2588 YCbCrtoRGB(cp[0], pp[0]);
2589 YCbCrtoRGB(cp[1], pp[1]);
2590
2591 cp += 2;
2592 pp += 4;
2593 x--;
2594 }
2595
2596 if ((w & 1) != 0)
2597 {
2598 int32_t Cb = pp[2];
2599 int32_t Cr = pp[3];
2600
2601 YCbCrtoRGB(cp[0], pp[0]);
2602
2603 cp += 1;
2604 pp += 4;
2605 }
2606
2607 cp += toskew;
2608 pp += fromskew;
2609 } while (--h);
2610}

◆ DECLAREContigPutFunc() [15/27]

DECLAREContigPutFunc ( putcontig8bitYCbCr22tile  )

Definition at line 2512 of file tif_getimage.c.

2513{
2514 uint32_t *cp2;
2515 int32_t incr = 2 * toskew + w;
2516 (void)y;
2517 fromskew = (fromskew / 2) * (2 * 2 + 2);
2518 cp2 = cp + w + toskew;
2519 while (h >= 2)
2520 {
2521 x = w;
2522 while (x >= 2)
2523 {
2524 uint32_t Cb = pp[4];
2525 uint32_t Cr = pp[5];
2526 YCbCrtoRGB(cp[0], pp[0]);
2527 YCbCrtoRGB(cp[1], pp[1]);
2528 YCbCrtoRGB(cp2[0], pp[2]);
2529 YCbCrtoRGB(cp2[1], pp[3]);
2530 cp += 2;
2531 cp2 += 2;
2532 pp += 6;
2533 x -= 2;
2534 }
2535 if (x == 1)
2536 {
2537 uint32_t Cb = pp[4];
2538 uint32_t Cr = pp[5];
2539 YCbCrtoRGB(cp[0], pp[0]);
2540 YCbCrtoRGB(cp2[0], pp[2]);
2541 cp++;
2542 cp2++;
2543 pp += 6;
2544 }
2545 cp += incr;
2546 cp2 += incr;
2547 pp += fromskew;
2548 h -= 2;
2549 }
2550 if (h == 1)
2551 {
2552 x = w;
2553 while (x >= 2)
2554 {
2555 uint32_t Cb = pp[4];
2556 uint32_t Cr = pp[5];
2557 YCbCrtoRGB(cp[0], pp[0]);
2558 YCbCrtoRGB(cp[1], pp[1]);
2559 cp += 2;
2560 cp2 += 2;
2561 pp += 6;
2562 x -= 2;
2563 }
2564 if (x == 1)
2565 {
2566 uint32_t Cb = pp[4];
2567 uint32_t Cr = pp[5];
2568 YCbCrtoRGB(cp[0], pp[0]);
2569 }
2570 }
2571}

◆ DECLAREContigPutFunc() [16/27]

DECLAREContigPutFunc ( putcontig8bitYCbCr41tile  )

Definition at line 2461 of file tif_getimage.c.

2462{
2463 (void)y;
2464 fromskew = (fromskew / 4) * (4 * 1 + 2);
2465 do
2466 {
2467 x = w >> 2;
2468 while (x > 0)
2469 {
2470 int32_t Cb = pp[4];
2471 int32_t Cr = pp[5];
2472
2473 YCbCrtoRGB(cp[0], pp[0]);
2474 YCbCrtoRGB(cp[1], pp[1]);
2475 YCbCrtoRGB(cp[2], pp[2]);
2476 YCbCrtoRGB(cp[3], pp[3]);
2477
2478 cp += 4;
2479 pp += 6;
2480 x--;
2481 }
2482
2483 if ((w & 3) != 0)
2484 {
2485 int32_t Cb = pp[4];
2486 int32_t Cr = pp[5];
2487
2488 switch ((w & 3))
2489 {
2490 case 3:
2491 YCbCrtoRGB(cp[2], pp[2]); /*-fallthrough*/
2492 case 2:
2493 YCbCrtoRGB(cp[1], pp[1]); /*-fallthrough*/
2494 case 1:
2495 YCbCrtoRGB(cp[0], pp[0]); /*-fallthrough*/
2496 case 0:
2497 break;
2498 }
2499
2500 cp += (w & 3);
2501 pp += 6;
2502 }
2503
2504 cp += toskew;
2505 pp += fromskew;
2506 } while (--h);
2507}

◆ DECLAREContigPutFunc() [17/27]

DECLAREContigPutFunc ( putcontig8bitYCbCr42tile  )

Definition at line 2356 of file tif_getimage.c.

2357{
2358 uint32_t *cp1 = cp + w + toskew;
2359 int32_t incr = 2 * toskew + w;
2360
2361 (void)y;
2362 fromskew = (fromskew / 4) * (4 * 2 + 2);
2363 if ((w & 3) == 0 && (h & 1) == 0)
2364 {
2365 for (; h >= 2; h -= 2)
2366 {
2367 x = w >> 2;
2368 do
2369 {
2370 int32_t Cb = pp[8];
2371 int32_t Cr = pp[9];
2372
2373 YCbCrtoRGB(cp[0], pp[0]);
2374 YCbCrtoRGB(cp[1], pp[1]);
2375 YCbCrtoRGB(cp[2], pp[2]);
2376 YCbCrtoRGB(cp[3], pp[3]);
2377 YCbCrtoRGB(cp1[0], pp[4]);
2378 YCbCrtoRGB(cp1[1], pp[5]);
2379 YCbCrtoRGB(cp1[2], pp[6]);
2380 YCbCrtoRGB(cp1[3], pp[7]);
2381
2382 cp += 4;
2383 cp1 += 4;
2384 pp += 10;
2385 } while (--x);
2386 cp += incr;
2387 cp1 += incr;
2388 pp += fromskew;
2389 }
2390 }
2391 else
2392 {
2393 while (h > 0)
2394 {
2395 for (x = w; x > 0;)
2396 {
2397 int32_t Cb = pp[8];
2398 int32_t Cr = pp[9];
2399 switch (x)
2400 {
2401 default:
2402 switch (h)
2403 {
2404 default:
2405 YCbCrtoRGB(cp1[3], pp[7]); /* FALLTHROUGH */
2406 case 1:
2407 YCbCrtoRGB(cp[3], pp[3]); /* FALLTHROUGH */
2408 } /* FALLTHROUGH */
2409 case 3:
2410 switch (h)
2411 {
2412 default:
2413 YCbCrtoRGB(cp1[2], pp[6]); /* FALLTHROUGH */
2414 case 1:
2415 YCbCrtoRGB(cp[2], pp[2]); /* FALLTHROUGH */
2416 } /* FALLTHROUGH */
2417 case 2:
2418 switch (h)
2419 {
2420 default:
2421 YCbCrtoRGB(cp1[1], pp[5]); /* FALLTHROUGH */
2422 case 1:
2423 YCbCrtoRGB(cp[1], pp[1]); /* FALLTHROUGH */
2424 } /* FALLTHROUGH */
2425 case 1:
2426 switch (h)
2427 {
2428 default:
2429 YCbCrtoRGB(cp1[0], pp[4]); /* FALLTHROUGH */
2430 case 1:
2431 YCbCrtoRGB(cp[0], pp[0]); /* FALLTHROUGH */
2432 } /* FALLTHROUGH */
2433 }
2434 if (x < 4)
2435 {
2436 cp += x;
2437 cp1 += x;
2438 x = 0;
2439 }
2440 else
2441 {
2442 cp += 4;
2443 cp1 += 4;
2444 x -= 4;
2445 }
2446 pp += 10;
2447 }
2448 if (h <= 2)
2449 break;
2450 h -= 2;
2451 cp += incr;
2452 cp1 += incr;
2453 pp += fromskew;
2454 }
2455 }
2456}

◆ DECLAREContigPutFunc() [18/27]

DECLAREContigPutFunc ( putcontig8bitYCbCr44tile  )

Definition at line 2214 of file tif_getimage.c.

2215{
2216 uint32_t *cp1 = cp + w + toskew;
2217 uint32_t *cp2 = cp1 + w + toskew;
2218 uint32_t *cp3 = cp2 + w + toskew;
2219 int32_t incr = 3 * w + 4 * toskew;
2220
2221 (void)y;
2222 /* adjust fromskew */
2223 fromskew = (fromskew / 4) * (4 * 2 + 2);
2224 if ((h & 3) == 0 && (w & 3) == 0)
2225 {
2226 for (; h >= 4; h -= 4)
2227 {
2228 x = w >> 2;
2229 do
2230 {
2231 int32_t Cb = pp[16];
2232 int32_t Cr = pp[17];
2233
2234 YCbCrtoRGB(cp[0], pp[0]);
2235 YCbCrtoRGB(cp[1], pp[1]);
2236 YCbCrtoRGB(cp[2], pp[2]);
2237 YCbCrtoRGB(cp[3], pp[3]);
2238 YCbCrtoRGB(cp1[0], pp[4]);
2239 YCbCrtoRGB(cp1[1], pp[5]);
2240 YCbCrtoRGB(cp1[2], pp[6]);
2241 YCbCrtoRGB(cp1[3], pp[7]);
2242 YCbCrtoRGB(cp2[0], pp[8]);
2243 YCbCrtoRGB(cp2[1], pp[9]);
2244 YCbCrtoRGB(cp2[2], pp[10]);
2245 YCbCrtoRGB(cp2[3], pp[11]);
2246 YCbCrtoRGB(cp3[0], pp[12]);
2247 YCbCrtoRGB(cp3[1], pp[13]);
2248 YCbCrtoRGB(cp3[2], pp[14]);
2249 YCbCrtoRGB(cp3[3], pp[15]);
2250
2251 cp += 4;
2252 cp1 += 4;
2253 cp2 += 4;
2254 cp3 += 4;
2255 pp += 18;
2256 } while (--x);
2257 cp += incr;
2258 cp1 += incr;
2259 cp2 += incr;
2260 cp3 += incr;
2261 pp += fromskew;
2262 }
2263 }
2264 else
2265 {
2266 while (h > 0)
2267 {
2268 for (x = w; x > 0;)
2269 {
2270 int32_t Cb = pp[16];
2271 int32_t Cr = pp[17];
2272 switch (x)
2273 {
2274 default:
2275 switch (h)
2276 {
2277 default:
2278 YCbCrtoRGB(cp3[3], pp[15]); /* FALLTHROUGH */
2279 case 3:
2280 YCbCrtoRGB(cp2[3], pp[11]); /* FALLTHROUGH */
2281 case 2:
2282 YCbCrtoRGB(cp1[3], pp[7]); /* FALLTHROUGH */
2283 case 1:
2284 YCbCrtoRGB(cp[3], pp[3]); /* FALLTHROUGH */
2285 } /* FALLTHROUGH */
2286 case 3:
2287 switch (h)
2288 {
2289 default:
2290 YCbCrtoRGB(cp3[2], pp[14]); /* FALLTHROUGH */
2291 case 3:
2292 YCbCrtoRGB(cp2[2], pp[10]); /* FALLTHROUGH */
2293 case 2:
2294 YCbCrtoRGB(cp1[2], pp[6]); /* FALLTHROUGH */
2295 case 1:
2296 YCbCrtoRGB(cp[2], pp[2]); /* FALLTHROUGH */
2297 } /* FALLTHROUGH */
2298 case 2:
2299 switch (h)
2300 {
2301 default:
2302 YCbCrtoRGB(cp3[1], pp[13]); /* FALLTHROUGH */
2303 case 3:
2304 YCbCrtoRGB(cp2[1], pp[9]); /* FALLTHROUGH */
2305 case 2:
2306 YCbCrtoRGB(cp1[1], pp[5]); /* FALLTHROUGH */
2307 case 1:
2308 YCbCrtoRGB(cp[1], pp[1]); /* FALLTHROUGH */
2309 } /* FALLTHROUGH */
2310 case 1:
2311 switch (h)
2312 {
2313 default:
2314 YCbCrtoRGB(cp3[0], pp[12]); /* FALLTHROUGH */
2315 case 3:
2316 YCbCrtoRGB(cp2[0], pp[8]); /* FALLTHROUGH */
2317 case 2:
2318 YCbCrtoRGB(cp1[0], pp[4]); /* FALLTHROUGH */
2319 case 1:
2320 YCbCrtoRGB(cp[0], pp[0]); /* FALLTHROUGH */
2321 } /* FALLTHROUGH */
2322 }
2323 if (x < 4)
2324 {
2325 cp += x;
2326 cp1 += x;
2327 cp2 += x;
2328 cp3 += x;
2329 x = 0;
2330 }
2331 else
2332 {
2333 cp += 4;
2334 cp1 += 4;
2335 cp2 += 4;
2336 cp3 += 4;
2337 x -= 4;
2338 }
2339 pp += 18;
2340 }
2341 if (h <= 4)
2342 break;
2343 h -= 4;
2344 cp += incr;
2345 cp1 += incr;
2346 cp2 += incr;
2347 cp3 += incr;
2348 pp += fromskew;
2349 }
2350 }
2351}

◆ DECLAREContigPutFunc() [19/27]

DECLAREContigPutFunc ( putgreytile  )

Definition at line 1678 of file tif_getimage.c.

1679{
1680 int samplesperpixel = img->samplesperpixel;
1681 uint32_t **BWmap = img->BWmap;
1682
1683 (void)y;
1684 for (; h > 0; --h)
1685 {
1686 for (x = w; x > 0; --x)
1687 {
1688 *cp++ = BWmap[*pp][0];
1689 pp += samplesperpixel;
1690 }
1691 cp += toskew;
1692 pp += fromskew;
1693 }
1694}

◆ DECLAREContigPutFunc() [20/27]

DECLAREContigPutFunc ( putRGBAAcontig16bittile  )

Definition at line 1893 of file tif_getimage.c.

1894{
1895 int samplesperpixel = img->samplesperpixel;
1896 uint16_t *wp = (uint16_t *)pp;
1897 (void)y;
1898 fromskew *= samplesperpixel;
1899 for (; h > 0; --h)
1900 {
1901 for (x = w; x > 0; --x)
1902 {
1903 *cp++ = PACK4(img->Bitdepth16To8[wp[0]], img->Bitdepth16To8[wp[1]],
1904 img->Bitdepth16To8[wp[2]], img->Bitdepth16To8[wp[3]]);
1905 wp += samplesperpixel;
1906 }
1907 cp += toskew;
1908 wp += fromskew;
1909 }
1910}
#define PACK4(r, g, b, a)

◆ DECLAREContigPutFunc() [21/27]

DECLAREContigPutFunc ( putRGBAAcontig8bittile  )

Definition at line 1823 of file tif_getimage.c.

1824{
1825 int samplesperpixel = img->samplesperpixel;
1826
1827 (void)x;
1828 (void)y;
1829 fromskew *= samplesperpixel;
1830 for (; h > 0; --h)
1831 {
1832 UNROLL8(w, NOP, *cp++ = PACK4(pp[0], pp[1], pp[2], pp[3]);
1833 pp += samplesperpixel);
1834 cp += toskew;
1835 pp += fromskew;
1836 }
1837}
#define NOP

◆ DECLAREContigPutFunc() [22/27]

DECLAREContigPutFunc ( putRGBcontig16bittile  )

Definition at line 1870 of file tif_getimage.c.

1871{
1872 int samplesperpixel = img->samplesperpixel;
1873 uint16_t *wp = (uint16_t *)pp;
1874 (void)y;
1875 fromskew *= samplesperpixel;
1876 for (; h > 0; --h)
1877 {
1878 for (x = w; x > 0; --x)
1879 {
1880 *cp++ = PACK(img->Bitdepth16To8[wp[0]], img->Bitdepth16To8[wp[1]],
1881 img->Bitdepth16To8[wp[2]]);
1882 wp += samplesperpixel;
1883 }
1884 cp += toskew;
1885 wp += fromskew;
1886 }
1887}

◆ DECLAREContigPutFunc() [23/27]

DECLAREContigPutFunc ( putRGBcontig8bitCMYKMaptile  )

Definition at line 1969 of file tif_getimage.c.

1970{
1971 int samplesperpixel = img->samplesperpixel;
1972 TIFFRGBValue *Map = img->Map;
1973 uint16_t r, g, b, k;
1974
1975 (void)y;
1976 fromskew *= samplesperpixel;
1977 for (; h > 0; --h)
1978 {
1979 for (x = w; x > 0; --x)
1980 {
1981 k = 255 - pp[3];
1982 r = (k * (255 - pp[0])) / 255;
1983 g = (k * (255 - pp[1])) / 255;
1984 b = (k * (255 - pp[2])) / 255;
1985 *cp++ = PACK(Map[r], Map[g], Map[b]);
1986 pp += samplesperpixel;
1987 }
1988 pp += fromskew;
1989 cp += toskew;
1990 }
1991}
int k
Definition: mpi.c:3369

◆ DECLAREContigPutFunc() [24/27]

DECLAREContigPutFunc ( putRGBcontig8bitCMYKtile  )

Definition at line 1946 of file tif_getimage.c.

1947{
1948 int samplesperpixel = img->samplesperpixel;
1949 uint16_t r, g, b, k;
1950
1951 (void)x;
1952 (void)y;
1953 fromskew *= samplesperpixel;
1954 for (; h > 0; --h)
1955 {
1956 UNROLL8(w, NOP, k = 255 - pp[3]; r = (k * (255 - pp[0])) / 255;
1957 g = (k * (255 - pp[1])) / 255; b = (k * (255 - pp[2])) / 255;
1958 *cp++ = PACK(r, g, b); pp += samplesperpixel);
1959 cp += toskew;
1960 pp += fromskew;
1961 }
1962}

◆ DECLAREContigPutFunc() [25/27]

DECLAREContigPutFunc ( putRGBcontig8bittile  )

Definition at line 1803 of file tif_getimage.c.

1804{
1805 int samplesperpixel = img->samplesperpixel;
1806
1807 (void)x;
1808 (void)y;
1809 fromskew *= samplesperpixel;
1810 for (; h > 0; --h)
1811 {
1812 UNROLL8(w, NOP, *cp++ = PACK(pp[0], pp[1], pp[2]);
1813 pp += samplesperpixel);
1814 cp += toskew;
1815 pp += fromskew;
1816 }
1817}

◆ DECLAREContigPutFunc() [26/27]

DECLAREContigPutFunc ( putRGBUAcontig16bittile  )

Definition at line 1916 of file tif_getimage.c.

1917{
1918 int samplesperpixel = img->samplesperpixel;
1919 uint16_t *wp = (uint16_t *)pp;
1920 (void)y;
1921 fromskew *= samplesperpixel;
1922 for (; h > 0; --h)
1923 {
1924 uint32_t r, g, b, a;
1925 uint8_t *m;
1926 for (x = w; x > 0; --x)
1927 {
1928 a = img->Bitdepth16To8[wp[3]];
1929 m = img->UaToAa + ((size_t)a << 8);
1930 r = m[img->Bitdepth16To8[wp[0]]];
1931 g = m[img->Bitdepth16To8[wp[1]]];
1932 b = m[img->Bitdepth16To8[wp[2]]];
1933 *cp++ = PACK4(r, g, b, a);
1934 wp += samplesperpixel;
1935 }
1936 cp += toskew;
1937 wp += fromskew;
1938 }
1939}
unsigned int size_t
Definition: corecrt.h:203
#define a
Definition: ke_i.h:78

◆ DECLAREContigPutFunc() [27/27]

DECLAREContigPutFunc ( putRGBUAcontig8bittile  )

Definition at line 1843 of file tif_getimage.c.

1844{
1845 int samplesperpixel = img->samplesperpixel;
1846 (void)y;
1847 fromskew *= samplesperpixel;
1848 for (; h > 0; --h)
1849 {
1850 uint32_t r, g, b, a;
1851 uint8_t *m;
1852 for (x = w; x > 0; --x)
1853 {
1854 a = pp[3];
1855 m = img->UaToAa + ((size_t)a << 8);
1856 r = m[pp[0]];
1857 g = m[pp[1]];
1858 b = m[pp[2]];
1859 *cp++ = PACK4(r, g, b, a);
1860 pp += samplesperpixel;
1861 }
1862 cp += toskew;
1863 pp += fromskew;
1864 }
1865}

◆ DECLARESepPutFunc() [1/8]

DECLARESepPutFunc ( putCMYKseparate8bittile  )

Definition at line 2035 of file tif_getimage.c.

2036{
2037 (void)img;
2038 (void)y;
2039 for (; h > 0; --h)
2040 {
2041 uint32_t rv, gv, bv, kv;
2042 for (x = w; x > 0; --x)
2043 {
2044 kv = 255 - *a++;
2045 rv = (kv * (255 - *r++)) / 255;
2046 gv = (kv * (255 - *g++)) / 255;
2047 bv = (kv * (255 - *b++)) / 255;
2048 *cp++ = PACK4(rv, gv, bv, 255);
2049 }
2050 SKEW4(r, g, b, a, fromskew);
2051 cp += toskew;
2052 }
2053}
#define SKEW4(r, g, b, a, skew)

◆ DECLARESepPutFunc() [2/8]

DECLARESepPutFunc ( putRGBAAseparate16bittile  )

Definition at line 2104 of file tif_getimage.c.

2105{
2106 uint16_t *wr = (uint16_t *)r;
2107 uint16_t *wg = (uint16_t *)g;
2108 uint16_t *wb = (uint16_t *)b;
2109 uint16_t *wa = (uint16_t *)a;
2110 (void)img;
2111 (void)y;
2112 for (; h > 0; --h)
2113 {
2114 for (x = 0; x < w; x++)
2115 *cp++ = PACK4(img->Bitdepth16To8[*wr++], img->Bitdepth16To8[*wg++],
2116 img->Bitdepth16To8[*wb++], img->Bitdepth16To8[*wa++]);
2117 SKEW4(wr, wg, wb, wa, fromskew);
2118 cp += toskew;
2119 }
2120}

◆ DECLARESepPutFunc() [3/8]

DECLARESepPutFunc ( putRGBAAseparate8bittile  )

Definition at line 2019 of file tif_getimage.c.

2020{
2021 (void)img;
2022 (void)x;
2023 (void)y;
2024 for (; h > 0; --h)
2025 {
2026 UNROLL8(w, NOP, *cp++ = PACK4(*r++, *g++, *b++, *a++));
2027 SKEW4(r, g, b, a, fromskew);
2028 cp += toskew;
2029 }
2030}

◆ DECLARESepPutFunc() [4/8]

DECLARESepPutFunc ( putRGBseparate16bittile  )

Definition at line 2083 of file tif_getimage.c.

2084{
2085 uint16_t *wr = (uint16_t *)r;
2086 uint16_t *wg = (uint16_t *)g;
2087 uint16_t *wb = (uint16_t *)b;
2088 (void)img;
2089 (void)y;
2090 (void)a;
2091 for (; h > 0; --h)
2092 {
2093 for (x = 0; x < w; x++)
2094 *cp++ = PACK(img->Bitdepth16To8[*wr++], img->Bitdepth16To8[*wg++],
2095 img->Bitdepth16To8[*wb++]);
2096 SKEW(wr, wg, wb, fromskew);
2097 cp += toskew;
2098 }
2099}
#define SKEW(r, g, b, skew)

◆ DECLARESepPutFunc() [5/8]

DECLARESepPutFunc ( putRGBseparate8bittile  )

Definition at line 2002 of file tif_getimage.c.

2003{
2004 (void)img;
2005 (void)x;
2006 (void)y;
2007 (void)a;
2008 for (; h > 0; --h)
2009 {
2010 UNROLL8(w, NOP, *cp++ = PACK(*r++, *g++, *b++));
2011 SKEW(r, g, b, fromskew);
2012 cp += toskew;
2013 }
2014}

◆ DECLARESepPutFunc() [6/8]

DECLARESepPutFunc ( putRGBUAseparate16bittile  )

Definition at line 2125 of file tif_getimage.c.

2126{
2127 uint16_t *wr = (uint16_t *)r;
2128 uint16_t *wg = (uint16_t *)g;
2129 uint16_t *wb = (uint16_t *)b;
2130 uint16_t *wa = (uint16_t *)a;
2131 (void)img;
2132 (void)y;
2133 for (; h > 0; --h)
2134 {
2135 uint32_t r2, g2, b2, a2;
2136 uint8_t *m;
2137 for (x = w; x > 0; --x)
2138 {
2139 a2 = img->Bitdepth16To8[*wa++];
2140 m = img->UaToAa + ((size_t)a2 << 8);
2141 r2 = m[img->Bitdepth16To8[*wr++]];
2142 g2 = m[img->Bitdepth16To8[*wg++]];
2143 b2 = m[img->Bitdepth16To8[*wb++]];
2144 *cp++ = PACK4(r2, g2, b2, a2);
2145 }
2146 SKEW4(wr, wg, wb, wa, fromskew);
2147 cp += toskew;
2148 }
2149}
static const struct update_accum a2
Definition: msg.c:542
static CRYPT_DATA_BLOB b2[]
Definition: msg.c:538
static DNS_RECORDW r2
Definition: record.c:38

◆ DECLARESepPutFunc() [7/8]

DECLARESepPutFunc ( putRGBUAseparate8bittile  )

Definition at line 2058 of file tif_getimage.c.

2059{
2060 (void)img;
2061 (void)y;
2062 for (; h > 0; --h)
2063 {
2064 uint32_t rv, gv, bv, av;
2065 uint8_t *m;
2066 for (x = w; x > 0; --x)
2067 {
2068 av = *a++;
2069 m = img->UaToAa + ((size_t)av << 8);
2070 rv = m[*r++];
2071 gv = m[*g++];
2072 bv = m[*b++];
2073 *cp++ = PACK4(rv, gv, bv, av);
2074 }
2075 SKEW4(r, g, b, a, fromskew);
2076 cp += toskew;
2077 }
2078}

◆ DECLARESepPutFunc() [8/8]

DECLARESepPutFunc ( putseparate8bitYCbCr11tile  )

Definition at line 2681 of file tif_getimage.c.

2682{
2683 (void)y;
2684 (void)a;
2685 /* TODO: naming of input vars is still off, change obfuscating declaration
2686 * inside define, or resolve obfuscation */
2687 for (; h > 0; --h)
2688 {
2689 x = w;
2690 do
2691 {
2692 uint32_t dr, dg, db;
2693 TIFFYCbCrtoRGB(img->ycbcr, *r++, *g++, *b++, &dr, &dg, &db);
2694 *cp++ = PACK(dr, dg, db);
2695 } while (--x);
2696 SKEW(r, g, b, fromskew);
2697 cp += toskew;
2698 }
2699}
void TIFFYCbCrtoRGB(TIFFYCbCrToRGB *ycbcr, uint32_t Y, int32_t Cb, int32_t Cr, uint32_t *r, uint32_t *g, uint32_t *b)
Definition: tif_color.c:199

◆ gtStripContig()

static int gtStripContig ( TIFFRGBAImage img,
uint32_t raster,
uint32_t  w,
uint32_t  h 
)
static

Definition at line 1135 of file tif_getimage.c.

1137{
1138 TIFF *tif = img->tif;
1139 tileContigRoutine put = img->put.contig;
1140 uint32_t row, y, nrow, nrowsub, rowstoread;
1141 tmsize_t pos;
1142 unsigned char *buf = NULL;
1143 uint32_t rowsperstrip;
1144 uint16_t subsamplinghor, subsamplingver;
1145 uint32_t imagewidth = img->width;
1146 tmsize_t scanline;
1147 /* fromskew, toskew are the increments within the input image or the raster
1148 * from the end of a line to the start of the next line to read or write. */
1149 int32_t fromskew, toskew;
1150 int ret = 1, flip;
1151 tmsize_t maxstripsize;
1152
1153 /* If the raster is smaller than the image,
1154 * or if there is a col_offset, adapt the samples to be copied per row. */
1155 uint32_t wmin;
1156 if (0 <= img->col_offset && (uint32_t)img->col_offset < imagewidth)
1157 {
1158 wmin = TIFFmin(w, imagewidth - img->col_offset);
1159 }
1160 else
1161 {
1162 TIFFErrorExtR(tif, TIFFFileName(tif),
1163 "Error in gtStripContig: column offset %d exceeds "
1164 "image width %d",
1165 img->col_offset, imagewidth);
1166 return 0;
1167 }
1168
1169 TIFFGetFieldDefaulted(tif, TIFFTAG_YCBCRSUBSAMPLING, &subsamplinghor,
1170 &subsamplingver);
1171 if (subsamplingver == 0)
1172 {
1173 TIFFErrorExtR(tif, TIFFFileName(tif),
1174 "Invalid vertical YCbCr subsampling");
1175 return (0);
1176 }
1177
1178 maxstripsize = TIFFStripSize(tif);
1179
1180 flip = setorientation(img);
1181 if (flip & FLIP_VERTICALLY)
1182 {
1183 if (w > INT_MAX / 2)
1184 {
1185 TIFFErrorExtR(tif, TIFFFileName(tif), "Width overflow");
1186 return (0);
1187 }
1188 y = h - 1;
1189 /* Skew back to the raster row before the currently written row
1190 * -> one raster width plus copied image pixels. */
1191 toskew = -(int32_t)(w + wmin);
1192 }
1193 else
1194 {
1195 y = 0;
1196 /* Skew forward to the end of the raster width of the row currently
1197 * copied. */
1198 toskew = w - wmin;
1199 }
1200
1201 TIFFGetFieldDefaulted(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);
1202 if (rowsperstrip == 0)
1203 {
1204 TIFFErrorExtR(tif, TIFFFileName(tif), "rowsperstrip is zero");
1205 return (0);
1206 }
1207
1208 scanline = TIFFScanlineSize(tif);
1209 fromskew = (w < imagewidth ? imagewidth - w : 0);
1210 for (row = 0; row < h; row += nrow)
1211 {
1212 uint32_t temp;
1213 rowstoread = rowsperstrip - (row + img->row_offset) % rowsperstrip;
1214 nrow = (row + rowstoread > h ? h - row : rowstoread);
1215 nrowsub = nrow;
1216 if ((nrowsub % subsamplingver) != 0)
1217 nrowsub += subsamplingver - nrowsub % subsamplingver;
1218 temp = (row + img->row_offset) % rowsperstrip + nrowsub;
1219 if (scanline > 0 && temp > (size_t)(TIFF_TMSIZE_T_MAX / scanline))
1220 {
1221 TIFFErrorExtR(tif, TIFFFileName(tif),
1222 "Integer overflow in gtStripContig");
1223 return 0;
1224 }
1226 tif, TIFFComputeStrip(tif, row + img->row_offset, 0),
1227 (void **)(&buf), maxstripsize,
1228 temp * scanline) == (tmsize_t)(-1) &&
1229 (buf == NULL || img->stoponerr))
1230 {
1231 ret = 0;
1232 break;
1233 }
1234
1235 pos = ((row + img->row_offset) % rowsperstrip) * scanline +
1236 ((tmsize_t)img->col_offset * img->samplesperpixel);
1237 tmsize_t roffset = (tmsize_t)y * w;
1238 (*put)(img, raster + roffset, 0, y, wmin, nrow, fromskew, toskew,
1239 buf + pos);
1240 y += ((flip & FLIP_VERTICALLY) ? -(int32_t)nrow : (int32_t)nrow);
1241 }
1242
1243 if (flip & FLIP_HORIZONTALLY)
1244 {
1245 /* Flips the complete raster matrix horizontally. If raster width is
1246 * larger than image width, data are moved horizontally to the right
1247 * side.
1248 * Use wmin to only flip data in place. */
1249 uint32_t line;
1250
1251 for (line = 0; line < h; line++)
1252 {
1253 uint32_t *left = raster + (line * w);
1254 /* Use wmin to only flip horizontally data in place and not complete
1255 * raster-row. */
1256 uint32_t *right = left + wmin - 1;
1257
1258 while (left < right)
1259 {
1260 uint32_t temp = *left;
1261 *left = *right;
1262 *right = temp;
1263 left++;
1264 right--;
1265 }
1266 }
1267 }
1268
1269 _TIFFfreeExt(img->tif, buf);
1270 return (ret);
1271}
#define INT_MAX
Definition: limits.h:26
struct png_info_def *typedef unsigned char **typedef struct png_info_def *typedef struct png_info_def *typedef struct png_info_def *typedef unsigned char ** row
Definition: typeof.h:78
return ret
Definition: mutex.c:146
GLdouble GLdouble right
Definition: glext.h:10859
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLint left
Definition: glext.h:7726
#define put(ret, state, sp, n)
Definition: match.c:105
#define int32_t
Definition: nsiface.idl:56
static calc_node_t temp
Definition: rpn_ieee.c:38
Definition: parser.c:49
Definition: tiffiop.h:113
int TIFFGetFieldDefaulted(TIFF *tif, uint32_t tag,...)
Definition: tif_aux.c:380
#define FLIP_VERTICALLY
Definition: tif_getimage.c:49
static int setorientation(TIFFRGBAImage *img)
Definition: tif_getimage.c:663
#define FLIP_HORIZONTALLY
Definition: tif_getimage.c:50
void _TIFFfreeExt(TIFF *tif, void *p)
Definition: tif_open.c:275
tmsize_t _TIFFReadEncodedStripAndAllocBuffer(TIFF *tif, uint32_t strip, void **buf, tmsize_t bufsizetoalloc, tmsize_t size_to_read)
Definition: tif_read.c:584
tmsize_t TIFFStripSize(TIFF *tif)
Definition: tif_strip.c:204
tmsize_t TIFFScanlineSize(TIFF *tif)
Definition: tif_strip.c:343
uint32_t TIFFComputeStrip(TIFF *tif, uint32_t row, uint16_t sample)
Definition: tif_strip.c:35
#define TIFFTAG_YCBCRSUBSAMPLING
Definition: tiff.h:388
#define TIFFTAG_ROWSPERSTRIP
Definition: tiff.h:258
TIFF_SSIZE_T tmsize_t
Definition: tiffio.h:67
void(* tileContigRoutine)(TIFFRGBAImage *, uint32_t *, uint32_t, uint32_t, uint32_t, uint32_t, int32_t, int32_t, unsigned char *)
Definition: tiffio.h:205
#define TIFF_TMSIZE_T_MAX
Definition: tiffio.h:68
#define TIFFmin(A, B)
Definition: tiffiop.h:331

Referenced by PickContigCase().

◆ gtStripSeparate()

static int gtStripSeparate ( TIFFRGBAImage img,
uint32_t raster,
uint32_t  w,
uint32_t  h 
)
static

Definition at line 1279 of file tif_getimage.c.

1281{
1282 TIFF *tif = img->tif;
1283 tileSeparateRoutine put = img->put.separate;
1284 unsigned char *buf = NULL;
1285 unsigned char *p0 = NULL, *p1 = NULL, *p2 = NULL, *pa = NULL;
1286 uint32_t row, y, nrow, rowstoread;
1287 tmsize_t pos;
1288 tmsize_t scanline;
1289 uint32_t rowsperstrip, offset_row;
1290 uint32_t imagewidth = img->width;
1291 tmsize_t stripsize;
1293 int32_t fromskew, toskew;
1294 int alpha = img->alpha;
1295 int ret = 1, flip;
1296 uint16_t colorchannels;
1297
1298 /* If the raster is smaller than the image,
1299 * or if there is a col_offset, adapt the samples to be copied per row. */
1300 uint32_t wmin;
1301 if (0 <= img->col_offset && (uint32_t)img->col_offset < imagewidth)
1302 {
1303 wmin = TIFFmin(w, imagewidth - img->col_offset);
1304 }
1305 else
1306 {
1307 TIFFErrorExtR(tif, TIFFFileName(tif),
1308 "Error in gtStripSeparate: column offset %d exceeds "
1309 "image width %d",
1310 img->col_offset, imagewidth);
1311 return 0;
1312 }
1313
1314 stripsize = TIFFStripSize(tif);
1315 bufsize =
1316 _TIFFMultiplySSize(tif, alpha ? 4 : 3, stripsize, "gtStripSeparate");
1317 if (bufsize == 0)
1318 {
1319 return (0);
1320 }
1321
1322 flip = setorientation(img);
1323 if (flip & FLIP_VERTICALLY)
1324 {
1325 if (w > INT_MAX / 2)
1326 {
1327 TIFFErrorExtR(tif, TIFFFileName(tif), "Width overflow");
1328 return (0);
1329 }
1330 y = h - 1;
1331 /* Skew back to the raster row before the currently written row
1332 * -> one raster width plus one image width. */
1333 toskew = -(int32_t)(w + wmin);
1334 }
1335 else
1336 {
1337 y = 0;
1338 /* Skew forward to the end of the raster width of the row currently
1339 * written. */
1340 toskew = w - wmin;
1341 }
1342
1343 switch (img->photometric)
1344 {
1348 colorchannels = 1;
1349 break;
1350
1351 default:
1352 colorchannels = 3;
1353 break;
1354 }
1355
1356 TIFFGetFieldDefaulted(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);
1357 if (rowsperstrip == 0)
1358 {
1359 TIFFErrorExtR(tif, TIFFFileName(tif), "rowsperstrip is zero");
1360 return (0);
1361 }
1362
1363 scanline = TIFFScanlineSize(tif);
1364 fromskew = (w < imagewidth ? imagewidth - w : 0);
1365 for (row = 0; row < h; row += nrow)
1366 {
1367 uint32_t temp;
1368 rowstoread = rowsperstrip - (row + img->row_offset) % rowsperstrip;
1369 nrow = (row + rowstoread > h ? h - row : rowstoread);
1370 offset_row = row + img->row_offset;
1371 temp = (row + img->row_offset) % rowsperstrip + nrow;
1372 if (scanline > 0 && temp > (size_t)(TIFF_TMSIZE_T_MAX / scanline))
1373 {
1374 TIFFErrorExtR(tif, TIFFFileName(tif),
1375 "Integer overflow in gtStripSeparate");
1376 return 0;
1377 }
1378 if (buf == NULL)
1379 {
1381 tif, TIFFComputeStrip(tif, offset_row, 0), (void **)&buf,
1382 bufsize, temp * scanline) == (tmsize_t)(-1) &&
1383 (buf == NULL || img->stoponerr))
1384 {
1385 ret = 0;
1386 break;
1387 }
1388 p0 = buf;
1389 if (colorchannels == 1)
1390 {
1391 p2 = p1 = p0;
1392 pa = (alpha ? (p0 + 3 * stripsize) : NULL);
1393 }
1394 else
1395 {
1396 p1 = p0 + stripsize;
1397 p2 = p1 + stripsize;
1398 pa = (alpha ? (p2 + stripsize) : NULL);
1399 }
1400 }
1401 else if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 0),
1402 p0, temp * scanline) == (tmsize_t)(-1) &&
1403 img->stoponerr)
1404 {
1405 ret = 0;
1406 break;
1407 }
1408 if (colorchannels > 1 &&
1409 TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 1), p1,
1410 temp * scanline) == (tmsize_t)(-1) &&
1411 img->stoponerr)
1412 {
1413 ret = 0;
1414 break;
1415 }
1416 if (colorchannels > 1 &&
1417 TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 2), p2,
1418 temp * scanline) == (tmsize_t)(-1) &&
1419 img->stoponerr)
1420 {
1421 ret = 0;
1422 break;
1423 }
1424 if (alpha)
1425 {
1427 tif, TIFFComputeStrip(tif, offset_row, colorchannels), pa,
1428 temp * scanline) == (tmsize_t)(-1) &&
1429 img->stoponerr)
1430 {
1431 ret = 0;
1432 break;
1433 }
1434 }
1435
1436 /* For SEPARATE the pos-offset is per sample and should not be
1437 * multiplied by img->samplesperpixel. */
1438 pos = ((row + img->row_offset) % rowsperstrip) * scanline +
1439 (tmsize_t)img->col_offset;
1440 tmsize_t roffset = (tmsize_t)y * w;
1441 (*put)(img, raster + roffset, 0, y, wmin, nrow, fromskew, toskew,
1442 p0 + pos, p1 + pos, p2 + pos, (alpha ? (pa + pos) : NULL));
1443 y += ((flip & FLIP_VERTICALLY) ? -(int32_t)nrow : (int32_t)nrow);
1444 }
1445
1446 if (flip & FLIP_HORIZONTALLY)
1447 {
1448 uint32_t line;
1449
1450 for (line = 0; line < h; line++)
1451 {
1452 uint32_t *left = raster + (line * w);
1453 /* Use wmin to only flip horizontally data in place and not complete
1454 * raster-row. */
1455 uint32_t *right = left + wmin - 1;
1456
1457 while (left < right)
1458 {
1459 uint32_t temp = *left;
1460 *left = *right;
1461 *right = temp;
1462 left++;
1463 right--;
1464 }
1465 }
1466 }
1467
1468 _TIFFfreeExt(img->tif, buf);
1469 return (ret);
1470}
GLclampf GLclampf GLclampf alpha
Definition: gl.h:1740
GLenum GLuint GLsizei bufsize
Definition: glext.h:7473
static int ** pa
Definition: server.c:145
tmsize_t _TIFFMultiplySSize(TIFF *tif, tmsize_t first, tmsize_t second, const char *where)
Definition: tif_aux.c:59
tmsize_t TIFFReadEncodedStrip(TIFF *tif, uint32_t strip, void *buf, tmsize_t size)
Definition: tif_read.c:534
void(* tileSeparateRoutine)(TIFFRGBAImage *, uint32_t *, uint32_t, uint32_t, uint32_t, uint32_t, int32_t, int32_t, unsigned char *, unsigned char *, unsigned char *, unsigned char *)
Definition: tiffio.h:208

Referenced by PickSeparateCase().

◆ gtTileContig()

static int gtTileContig ( TIFFRGBAImage img,
uint32_t raster,
uint32_t  w,
uint32_t  h 
)
static

Definition at line 730 of file tif_getimage.c.

732{
733 TIFF *tif = img->tif;
734 tileContigRoutine put = img->put.contig;
735 uint32_t col, row, y, rowstoread;
737 uint32_t tw, th;
738 unsigned char *buf = NULL;
739 int32_t fromskew, toskew;
740 uint32_t nrow;
741 int ret = 1, flip;
742 uint32_t this_tw, tocol;
743 int32_t this_toskew, leftmost_toskew;
744 int32_t leftmost_fromskew;
745 uint32_t leftmost_tw;
747
748 /* If the raster is smaller than the image,
749 * or if there is a col_offset, adapt the samples to be copied per row. */
750 uint32_t wmin;
751
752 if (0 <= img->col_offset && (uint32_t)img->col_offset < img->width)
753 {
754 wmin = TIFFmin(w, img->width - img->col_offset);
755 }
756 else
757 {
758 TIFFErrorExtR(tif, TIFFFileName(tif),
759 "Error in gtTileContig: column offset %d exceeds "
760 "image width %d",
761 img->col_offset, img->width);
762 return 0;
763 }
764 bufsize = TIFFTileSize(tif);
765 if (bufsize == 0)
766 {
767 TIFFErrorExtR(tif, TIFFFileName(tif), "%s", "No space for tile buffer");
768 return (0);
769 }
770
773
774 flip = setorientation(img);
775 if (flip & FLIP_VERTICALLY)
776 {
777 if (((int64_t)tw + w) > INT_MAX)
778 {
779 TIFFErrorExtR(tif, TIFFFileName(tif), "%s",
780 "unsupported tile size (too wide)");
781 return (0);
782 }
783 y = h - 1;
784 toskew = -(int32_t)(tw + w);
785 }
786 else
787 {
788 if (tw > ((int64_t)INT_MAX + w))
789 {
790 TIFFErrorExtR(tif, TIFFFileName(tif), "%s",
791 "unsupported tile size (too wide)");
792 return (0);
793 }
794 y = 0;
795 toskew = -(int32_t)(tw - w);
796 }
797
798 if (tw == 0 || th == 0)
799 {
800 TIFFErrorExtR(tif, TIFFFileName(tif), "tile width or height is zero");
801 return (0);
802 }
803
804 /*
805 * Leftmost tile is clipped on left side if col_offset > 0.
806 */
807 leftmost_fromskew = img->col_offset % tw;
808 leftmost_tw = tw - leftmost_fromskew;
809 int64_t skew_i64 = (int64_t)toskew + leftmost_fromskew;
810 if (skew_i64 > INT_MAX || skew_i64 < INT_MIN)
811 {
812 TIFFErrorExtR(tif, TIFFFileName(tif), "%s %" PRId64, "Invalid skew",
813 skew_i64);
814 return (0);
815 }
816 leftmost_toskew = (int32_t)skew_i64;
817 for (row = 0; ret != 0 && row < h; row += nrow)
818 {
819 rowstoread = th - (row + img->row_offset) % th;
820 nrow = (row + rowstoread > h ? h - row : rowstoread);
821 fromskew = leftmost_fromskew;
822 this_tw = leftmost_tw;
823 this_toskew = leftmost_toskew;
824 tocol = 0;
825 col = img->col_offset;
826 /* wmin: only write imagewidth if raster is bigger. */
827 while (tocol < wmin)
828 {
829 if (_TIFFReadTileAndAllocBuffer(tif, (void **)&buf, bufsize, col,
830 row + img->row_offset, 0,
831 0) == (tmsize_t)(-1) &&
832 (buf == NULL || img->stoponerr))
833 {
834 ret = 0;
835 break;
836 }
837 pos = ((row + img->row_offset) % th) * TIFFTileRowSize(tif) +
838 ((tmsize_t)fromskew * img->samplesperpixel);
839 if (tocol + this_tw > wmin)
840 {
841 /*
842 * Rightmost tile is clipped on right side.
843 */
844 fromskew = tw - (wmin - tocol);
845 this_tw = tw - fromskew;
846 this_toskew = toskew + fromskew;
847 }
848 tmsize_t roffset = (tmsize_t)y * w + tocol;
849 (*put)(img, raster + roffset, tocol, y, this_tw, nrow, fromskew,
850 this_toskew, buf + pos);
851 tocol += this_tw;
852 col += this_tw;
853 /*
854 * After the leftmost tile, tiles are no longer clipped on left
855 * side.
856 */
857 fromskew = 0;
858 this_tw = tw;
859 this_toskew = toskew;
860 }
861
862 y += ((flip & FLIP_VERTICALLY) ? -(int32_t)nrow : (int32_t)nrow);
863 }
864 _TIFFfreeExt(img->tif, buf);
865
866 if (flip & FLIP_HORIZONTALLY)
867 {
869
870 for (line = 0; line < h; line++)
871 {
872 uint32_t *left = raster + (line * w);
873 /* Use wmin to only flip horizontally data in place and not complete
874 * raster-row. */
875 uint32_t *right = left + wmin - 1;
876
877 while (left < right)
878 {
879 uint32_t temp = *left;
880 *left = *right;
881 *right = temp;
882 left++;
883 right--;
884 }
885 }
886 }
887
888 return (ret);
889}
INT64 int64_t
Definition: types.h:72
#define PRId64
Definition: inttypes.h:25
#define INT_MIN
Definition: limits.h:25
#define int64_t
Definition: nsiface.idl:57
int TIFFGetField(TIFF *tif, uint32_t tag,...)
Definition: tif_dir.c:1582
tmsize_t _TIFFReadTileAndAllocBuffer(TIFF *tif, void **buf, tmsize_t bufsizetoalloc, uint32_t x, uint32_t y, uint32_t z, uint16_t s)
Definition: tif_read.c:1012
tmsize_t TIFFTileSize(TIFF *tif)
Definition: tif_tile.c:253
tmsize_t TIFFTileRowSize(TIFF *tif)
Definition: tif_tile.c:177
#define TIFFTAG_TILELENGTH
Definition: tiff.h:312
#define TIFFTAG_TILEWIDTH
Definition: tiff.h:311

Referenced by PickContigCase().

◆ gtTileSeparate()

static int gtTileSeparate ( TIFFRGBAImage img,
uint32_t raster,
uint32_t  w,
uint32_t  h 
)
static

Definition at line 897 of file tif_getimage.c.

899{
900 TIFF *tif = img->tif;
901 tileSeparateRoutine put = img->put.separate;
902 uint32_t col, row, y, rowstoread;
904 uint32_t tw, th;
905 unsigned char *buf = NULL;
906 unsigned char *p0 = NULL;
907 unsigned char *p1 = NULL;
908 unsigned char *p2 = NULL;
909 unsigned char *pa = NULL;
910 tmsize_t tilesize;
912 int32_t fromskew, toskew;
913 int alpha = img->alpha;
914 uint32_t nrow;
915 int ret = 1, flip;
916 uint16_t colorchannels;
917 uint32_t this_tw, tocol;
918 int32_t this_toskew, leftmost_toskew;
919 int32_t leftmost_fromskew;
920 uint32_t leftmost_tw;
921
922 /* If the raster is smaller than the image,
923 * or if there is a col_offset, adapt the samples to be copied per row. */
924 uint32_t wmin;
925 if (0 <= img->col_offset && (uint32_t)img->col_offset < img->width)
926 {
927 wmin = TIFFmin(w, img->width - img->col_offset);
928 }
929 else
930 {
931 TIFFErrorExtR(tif, TIFFFileName(tif),
932 "Error in gtTileSeparate: column offset %d exceeds "
933 "image width %d",
934 img->col_offset, img->width);
935 return 0;
936 }
937
938 tilesize = TIFFTileSize(tif);
939 bufsize =
940 _TIFFMultiplySSize(tif, alpha ? 4 : 3, tilesize, "gtTileSeparate");
941 if (bufsize == 0)
942 {
943 return (0);
944 }
945
948
949 flip = setorientation(img);
950 if (flip & FLIP_VERTICALLY)
951 {
952 if (((int64_t)tw + w) > INT_MAX)
953 {
954 TIFFErrorExtR(tif, TIFFFileName(tif), "%s",
955 "unsupported tile size (too wide)");
956 return (0);
957 }
958 y = h - 1;
959 toskew = -(int32_t)(tw + w);
960 }
961 else
962 {
963 if (tw > ((int64_t)INT_MAX + w))
964 {
965 TIFFErrorExtR(tif, TIFFFileName(tif), "%s",
966 "unsupported tile size (too wide)");
967 return (0);
968 }
969 y = 0;
970 toskew = -(int32_t)(tw - w);
971 }
972
973 switch (img->photometric)
974 {
978 colorchannels = 1;
979 break;
980
981 default:
982 colorchannels = 3;
983 break;
984 }
985
986 if (tw == 0 || th == 0)
987 {
988 TIFFErrorExtR(tif, TIFFFileName(tif), "tile width or height is zero");
989 return (0);
990 }
991
992 /*
993 * Leftmost tile is clipped on left side if col_offset > 0.
994 */
995 leftmost_fromskew = img->col_offset % tw;
996 leftmost_tw = tw - leftmost_fromskew;
997 int64_t skew_i64 = (int64_t)toskew + leftmost_fromskew;
998 if (skew_i64 > INT_MAX || skew_i64 < INT_MIN)
999 {
1000 TIFFErrorExtR(tif, TIFFFileName(tif), "%s %" PRId64, "Invalid skew",
1001 skew_i64);
1002 return (0);
1003 }
1004 leftmost_toskew = (int32_t)skew_i64;
1005 for (row = 0; ret != 0 && row < h; row += nrow)
1006 {
1007 rowstoread = th - (row + img->row_offset) % th;
1008 nrow = (row + rowstoread > h ? h - row : rowstoread);
1009 fromskew = leftmost_fromskew;
1010 this_tw = leftmost_tw;
1011 this_toskew = leftmost_toskew;
1012 tocol = 0;
1013 col = img->col_offset;
1014 /* wmin: only write imagewidth if raster is bigger. */
1015 while (tocol < wmin)
1016 {
1017 if (buf == NULL)
1018 {
1019 if (_TIFFReadTileAndAllocBuffer(tif, (void **)&buf, bufsize,
1020 col, row + img->row_offset, 0,
1021 0) == (tmsize_t)(-1) &&
1022 (buf == NULL || img->stoponerr))
1023 {
1024 ret = 0;
1025 break;
1026 }
1027 p0 = buf;
1028 if (colorchannels == 1)
1029 {
1030 p2 = p1 = p0;
1031 pa = (alpha ? (p0 + 3 * tilesize) : NULL);
1032 }
1033 else
1034 {
1035 p1 = p0 + tilesize;
1036 p2 = p1 + tilesize;
1037 pa = (alpha ? (p2 + tilesize) : NULL);
1038 }
1039 }
1040 else if (TIFFReadTile(tif, p0, col, row + img->row_offset, 0, 0) ==
1041 (tmsize_t)(-1) &&
1042 img->stoponerr)
1043 {
1044 ret = 0;
1045 break;
1046 }
1047 if (colorchannels > 1 &&
1048 TIFFReadTile(tif, p1, col, row + img->row_offset, 0, 1) ==
1049 (tmsize_t)(-1) &&
1050 img->stoponerr)
1051 {
1052 ret = 0;
1053 break;
1054 }
1055 if (colorchannels > 1 &&
1056 TIFFReadTile(tif, p2, col, row + img->row_offset, 0, 2) ==
1057 (tmsize_t)(-1) &&
1058 img->stoponerr)
1059 {
1060 ret = 0;
1061 break;
1062 }
1063 if (alpha &&
1064 TIFFReadTile(tif, pa, col, row + img->row_offset, 0,
1065 colorchannels) == (tmsize_t)(-1) &&
1066 img->stoponerr)
1067 {
1068 ret = 0;
1069 break;
1070 }
1071
1072 /* For SEPARATE the pos-offset is per sample and should not be
1073 * multiplied by img->samplesperpixel. */
1074 pos = ((row + img->row_offset) % th) * TIFFTileRowSize(tif) +
1075 (tmsize_t)fromskew;
1076 if (tocol + this_tw > wmin)
1077 {
1078 /*
1079 * Rightmost tile is clipped on right side.
1080 */
1081 fromskew = tw - (wmin - tocol);
1082 this_tw = tw - fromskew;
1083 this_toskew = toskew + fromskew;
1084 }
1085 tmsize_t roffset = (tmsize_t)y * w + tocol;
1086 (*put)(img, raster + roffset, tocol, y, this_tw, nrow, fromskew,
1087 this_toskew, p0 + pos, p1 + pos, p2 + pos,
1088 (alpha ? (pa + pos) : NULL));
1089 tocol += this_tw;
1090 col += this_tw;
1091 /*
1092 * After the leftmost tile, tiles are no longer clipped on left
1093 * side.
1094 */
1095 fromskew = 0;
1096 this_tw = tw;
1097 this_toskew = toskew;
1098 }
1099
1100 y += ((flip & FLIP_VERTICALLY) ? -(int32_t)nrow : (int32_t)nrow);
1101 }
1102
1103 if (flip & FLIP_HORIZONTALLY)
1104 {
1105 uint32_t line;
1106
1107 for (line = 0; line < h; line++)
1108 {
1109 uint32_t *left = raster + (line * w);
1110 /* Use wmin to only flip horizontally data in place and not complete
1111 * raster-row. */
1112 uint32_t *right = left + wmin - 1;
1113
1114 while (left < right)
1115 {
1116 uint32_t temp = *left;
1117 *left = *right;
1118 *right = temp;
1119 left++;
1120 right--;
1121 }
1122 }
1123 }
1124
1125 _TIFFfreeExt(img->tif, buf);
1126 return (ret);
1127}
tmsize_t TIFFReadTile(TIFF *tif, void *buf, uint32_t x, uint32_t y, uint32_t z, uint16_t s)
Definition: tif_read.c:940

Referenced by PickSeparateCase().

◆ initCIELabConversion()

static tileContigRoutine initCIELabConversion ( TIFFRGBAImage img)
static

Definition at line 2758 of file tif_getimage.c.

2759{
2760 static const char module[] = "initCIELabConversion";
2761
2762 float *whitePoint;
2763 float refWhite[3];
2764
2765 TIFFGetFieldDefaulted(img->tif, TIFFTAG_WHITEPOINT, &whitePoint);
2766 if (whitePoint[1] == 0.0f)
2767 {
2768 TIFFErrorExtR(img->tif, module, "Invalid value for WhitePoint tag.");
2769 return NULL;
2770 }
2771
2772 if (!img->cielab)
2773 {
2774 img->cielab = (TIFFCIELabToRGB *)_TIFFmallocExt(
2775 img->tif, sizeof(TIFFCIELabToRGB));
2776 if (!img->cielab)
2777 {
2778 TIFFErrorExtR(img->tif, module,
2779 "No space for CIE L*a*b*->RGB conversion state.");
2780 return NULL;
2781 }
2782 }
2783
2784 refWhite[1] = 100.0F;
2785 refWhite[0] = whitePoint[0] / whitePoint[1] * refWhite[1];
2786 refWhite[2] =
2787 (1.0F - whitePoint[0] - whitePoint[1]) / whitePoint[1] * refWhite[1];
2788 if (TIFFCIELabToRGBInit(img->cielab, &display_sRGB, refWhite) < 0)
2789 {
2790 TIFFErrorExtR(img->tif, module,
2791 "Failed to initialize CIE L*a*b*->RGB conversion state.");
2792 _TIFFfreeExt(img->tif, img->cielab);
2793 return NULL;
2794 }
2795
2796 if (img->bitspersample == 8)
2797 return putcontig8bitCIELab8;
2798 else if (img->bitspersample == 16)
2799 return putcontig8bitCIELab16;
2800 return NULL;
2801}
int TIFFCIELabToRGBInit(TIFFCIELabToRGB *cielab, const TIFFDisplay *display, float *refWhite)
Definition: tif_color.c:135
static const TIFFDisplay display_sRGB
Definition: tif_getimage.c:58
#define TIFFTAG_WHITEPOINT
Definition: tiff.h:307

Referenced by PickContigCase().

◆ initYCbCrConversion()

static int initYCbCrConversion ( TIFFRGBAImage img)
static

Definition at line 2707 of file tif_getimage.c.

2708{
2709 static const char module[] = "initYCbCrConversion";
2710
2711 float *luma, *refBlackWhite;
2712
2713 if (img->ycbcr == NULL)
2714 {
2715 img->ycbcr = (TIFFYCbCrToRGB *)_TIFFmallocExt(
2716 img->tif, TIFFroundup_32(sizeof(TIFFYCbCrToRGB), sizeof(long)) +
2717 4 * 256 * sizeof(TIFFRGBValue) +
2718 2 * 256 * sizeof(int) + 3 * 256 * sizeof(int32_t));
2719 if (img->ycbcr == NULL)
2720 {
2721 TIFFErrorExtR(img->tif, module,
2722 "No space for YCbCr->RGB conversion state");
2723 return (0);
2724 }
2725 }
2726
2729 &refBlackWhite);
2730
2731 /* Do some validation to avoid later issues. Detect NaN for now */
2732 /* and also if lumaGreen is zero since we divide by it later */
2733 if (luma[0] != luma[0] || luma[1] != luma[1] || luma[1] == 0.0 ||
2734 luma[2] != luma[2])
2735 {
2736 TIFFErrorExtR(img->tif, module,
2737 "Invalid values for YCbCrCoefficients tag");
2738 return (0);
2739 }
2740
2741 if (!isInRefBlackWhiteRange(refBlackWhite[0]) ||
2742 !isInRefBlackWhiteRange(refBlackWhite[1]) ||
2743 !isInRefBlackWhiteRange(refBlackWhite[2]) ||
2744 !isInRefBlackWhiteRange(refBlackWhite[3]) ||
2745 !isInRefBlackWhiteRange(refBlackWhite[4]) ||
2746 !isInRefBlackWhiteRange(refBlackWhite[5]))
2747 {
2748 TIFFErrorExtR(img->tif, module,
2749 "Invalid values for ReferenceBlackWhite tag");
2750 return (0);
2751 }
2752
2753 if (TIFFYCbCrToRGBInit(img->ycbcr, luma, refBlackWhite) < 0)
2754 return (0);
2755 return (1);
2756}
int TIFFYCbCrToRGBInit(TIFFYCbCrToRGB *ycbcr, float *luma, float *refBlackWhite)
Definition: tif_color.c:251
static int isInRefBlackWhiteRange(float f)
#define TIFFTAG_YCBCRCOEFFICIENTS
Definition: tiff.h:387
#define TIFFTAG_REFERENCEBLACKWHITE
Definition: tiff.h:392
#define TIFFroundup_32(x, y)
Definition: tiffiop.h:316

Referenced by PickContigCase(), and PickSeparateCase().

◆ isCCITTCompression()

static int isCCITTCompression ( TIFF tif)
static

Definition at line 300 of file tif_getimage.c.

301{
304 return (compress == COMPRESSION_CCITTFAX3 ||
308}
int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
Definition: compress.c:68
#define COMPRESSION_CCITTFAX3
Definition: tiff.h:184
#define COMPRESSION_CCITTRLE
Definition: tiff.h:183
#define COMPRESSION_CCITTRLEW
Definition: tiff.h:194
#define TIFFTAG_COMPRESSION
Definition: tiff.h:181
#define COMPRESSION_CCITTFAX4
Definition: tiff.h:186

Referenced by TIFFRGBAImageBegin().

◆ isInRefBlackWhiteRange()

static int isInRefBlackWhiteRange ( float  f)
static

Definition at line 2702 of file tif_getimage.c.

2703{
2704 return f > (float)(-0x7FFFFFFF + 128) && f < (float)0x7FFFFFFF;
2705}
GLfloat f
Definition: glext.h:7540
static float(__cdecl *square_half_float)(float x

Referenced by initYCbCrConversion().

◆ makebwmap()

static int makebwmap ( TIFFRGBAImage img)
static

Definition at line 2810 of file tif_getimage.c.

2811{
2812 TIFFRGBValue *Map = img->Map;
2813 int bitspersample = img->bitspersample;
2814 int nsamples = 8 / bitspersample;
2815 int i;
2816 uint32_t *p;
2817
2818 if (nsamples == 0)
2819 nsamples = 1;
2820
2821 img->BWmap = (uint32_t **)_TIFFmallocExt(
2822 img->tif,
2823 256 * sizeof(uint32_t *) + (256 * nsamples * sizeof(uint32_t)));
2824 if (img->BWmap == NULL)
2825 {
2826 TIFFErrorExtR(img->tif, TIFFFileName(img->tif),
2827 "No space for B&W mapping table");
2828 return (0);
2829 }
2830 p = (uint32_t *)(img->BWmap + 256);
2831 for (i = 0; i < 256; i++)
2832 {
2834 img->BWmap[i] = p;
2835 switch (bitspersample)
2836 {
2837#define GREY(x) \
2838 c = Map[x]; \
2839 *p++ = PACK(c, c, c);
2840 case 1:
2841 GREY(i >> 7);
2842 GREY((i >> 6) & 1);
2843 GREY((i >> 5) & 1);
2844 GREY((i >> 4) & 1);
2845 GREY((i >> 3) & 1);
2846 GREY((i >> 2) & 1);
2847 GREY((i >> 1) & 1);
2848 GREY(i & 1);
2849 break;
2850 case 2:
2851 GREY(i >> 6);
2852 GREY((i >> 4) & 3);
2853 GREY((i >> 2) & 3);
2854 GREY(i & 3);
2855 break;
2856 case 4:
2857 GREY(i >> 4);
2858 GREY(i & 0xf);
2859 break;
2860 case 8:
2861 case 16:
2862 GREY(i);
2863 break;
2864 }
2865#undef GREY
2866 }
2867 return (1);
2868}
#define c
Definition: ke_i.h:80
#define GREY(x)

Referenced by setupMap().

◆ makecmap()

static int makecmap ( TIFFRGBAImage img)
static

Definition at line 2957 of file tif_getimage.c.

2958{
2959 int bitspersample = img->bitspersample;
2960 int nsamples = 8 / bitspersample;
2961 uint16_t *r = img->redcmap;
2962 uint16_t *g = img->greencmap;
2963 uint16_t *b = img->bluecmap;
2964 uint32_t *p;
2965 int i;
2966
2967 img->PALmap = (uint32_t **)_TIFFmallocExt(
2968 img->tif,
2969 256 * sizeof(uint32_t *) + (256 * nsamples * sizeof(uint32_t)));
2970 if (img->PALmap == NULL)
2971 {
2972 TIFFErrorExtR(img->tif, TIFFFileName(img->tif),
2973 "No space for Palette mapping table");
2974 return (0);
2975 }
2976 p = (uint32_t *)(img->PALmap + 256);
2977 for (i = 0; i < 256; i++)
2978 {
2980 img->PALmap[i] = p;
2981#define CMAP(x) \
2982 c = (TIFFRGBValue)x; \
2983 *p++ = PACK(r[c] & 0xff, g[c] & 0xff, b[c] & 0xff);
2984 switch (bitspersample)
2985 {
2986 case 1:
2987 CMAP(i >> 7);
2988 CMAP((i >> 6) & 1);
2989 CMAP((i >> 5) & 1);
2990 CMAP((i >> 4) & 1);
2991 CMAP((i >> 3) & 1);
2992 CMAP((i >> 2) & 1);
2993 CMAP((i >> 1) & 1);
2994 CMAP(i & 1);
2995 break;
2996 case 2:
2997 CMAP(i >> 6);
2998 CMAP((i >> 4) & 3);
2999 CMAP((i >> 2) & 3);
3000 CMAP(i & 3);
3001 break;
3002 case 4:
3003 CMAP(i >> 4);
3004 CMAP(i & 0xf);
3005 break;
3006 case 8:
3007 CMAP(i);
3008 break;
3009 }
3010#undef CMAP
3011 }
3012 return (1);
3013}
#define CMAP(x)

Referenced by buildMap().

◆ PickContigCase()

static int PickContigCase ( TIFFRGBAImage img)
static

Definition at line 3058 of file tif_getimage.c.

3059{
3060 img->get = TIFFIsTiled(img->tif) ? gtTileContig : gtStripContig;
3061 img->put.contig = NULL;
3062 switch (img->photometric)
3063 {
3064 case PHOTOMETRIC_RGB:
3065 switch (img->bitspersample)
3066 {
3067 case 8:
3068 if (img->alpha == EXTRASAMPLE_ASSOCALPHA &&
3069 img->samplesperpixel >= 4)
3070 img->put.contig = putRGBAAcontig8bittile;
3071 else if (img->alpha == EXTRASAMPLE_UNASSALPHA &&
3072 img->samplesperpixel >= 4)
3073 {
3074 if (BuildMapUaToAa(img))
3075 img->put.contig = putRGBUAcontig8bittile;
3076 }
3077 else if (img->samplesperpixel >= 3)
3078 img->put.contig = putRGBcontig8bittile;
3079 break;
3080 case 16:
3081 if (img->alpha == EXTRASAMPLE_ASSOCALPHA &&
3082 img->samplesperpixel >= 4)
3083 {
3085 img->put.contig = putRGBAAcontig16bittile;
3086 }
3087 else if (img->alpha == EXTRASAMPLE_UNASSALPHA &&
3088 img->samplesperpixel >= 4)
3089 {
3091 img->put.contig = putRGBUAcontig16bittile;
3092 }
3093 else if (img->samplesperpixel >= 3)
3094 {
3096 img->put.contig = putRGBcontig16bittile;
3097 }
3098 break;
3099 }
3100 break;
3102 if (img->samplesperpixel >= 4 && buildMap(img))
3103 {
3104 if (img->bitspersample == 8)
3105 {
3106 if (!img->Map)
3107 img->put.contig = putRGBcontig8bitCMYKtile;
3108 else
3109 img->put.contig = putRGBcontig8bitCMYKMaptile;
3110 }
3111 }
3112 break;
3114 if (buildMap(img))
3115 {
3116 switch (img->bitspersample)
3117 {
3118 case 8:
3119 img->put.contig = put8bitcmaptile;
3120 break;
3121 case 4:
3122 img->put.contig = put4bitcmaptile;
3123 break;
3124 case 2:
3125 img->put.contig = put2bitcmaptile;
3126 break;
3127 case 1:
3128 img->put.contig = put1bitcmaptile;
3129 break;
3130 }
3131 }
3132 break;
3135 if (buildMap(img))
3136 {
3137 switch (img->bitspersample)
3138 {
3139 case 16:
3140 img->put.contig = put16bitbwtile;
3141 break;
3142 case 8:
3143 if (img->alpha && img->samplesperpixel == 2)
3144 img->put.contig = putagreytile;
3145 else
3146 img->put.contig = putgreytile;
3147 break;
3148 case 4:
3149 img->put.contig = put4bitbwtile;
3150 break;
3151 case 2:
3152 img->put.contig = put2bitbwtile;
3153 break;
3154 case 1:
3155 img->put.contig = put1bitbwtile;
3156 break;
3157 }
3158 }
3159 break;
3160 case PHOTOMETRIC_YCBCR:
3161 if ((img->bitspersample == 8) && (img->samplesperpixel == 3))
3162 {
3163 if (initYCbCrConversion(img) != 0)
3164 {
3165 /*
3166 * The 6.0 spec says that subsampling must be
3167 * one of 1, 2, or 4, and that vertical subsampling
3168 * must always be <= horizontal subsampling; so
3169 * there are only a few possibilities and we just
3170 * enumerate the cases.
3171 * Joris: added support for the [1,2] case, nonetheless, to
3172 * accommodate some OJPEG files
3173 */
3174 uint16_t SubsamplingHor;
3175 uint16_t SubsamplingVer;
3177 &SubsamplingHor, &SubsamplingVer);
3178 switch ((SubsamplingHor << 4) | SubsamplingVer)
3179 {
3180 case 0x44:
3181 img->put.contig = putcontig8bitYCbCr44tile;
3182 break;
3183 case 0x42:
3184 img->put.contig = putcontig8bitYCbCr42tile;
3185 break;
3186 case 0x41:
3187 img->put.contig = putcontig8bitYCbCr41tile;
3188 break;
3189 case 0x22:
3190 img->put.contig = putcontig8bitYCbCr22tile;
3191 break;
3192 case 0x21:
3193 img->put.contig = putcontig8bitYCbCr21tile;
3194 break;
3195 case 0x12:
3196 img->put.contig = putcontig8bitYCbCr12tile;
3197 break;
3198 case 0x11:
3199 img->put.contig = putcontig8bitYCbCr11tile;
3200 break;
3201 }
3202 }
3203 }
3204 break;
3205 case PHOTOMETRIC_CIELAB:
3206 if (img->samplesperpixel == 3 && buildMap(img))
3207 {
3208 if (img->bitspersample == 8 || img->bitspersample == 16)
3209 img->put.contig = initCIELabConversion(img);
3210 break;
3211 }
3212 }
3213 return ((img->get != NULL) && (img->put.contig != NULL));
3214}
static int gtStripContig(TIFFRGBAImage *, uint32_t *, uint32_t, uint32_t)
static int buildMap(TIFFRGBAImage *img)
static tileContigRoutine initCIELabConversion(TIFFRGBAImage *img)
static int gtTileContig(TIFFRGBAImage *, uint32_t *, uint32_t, uint32_t)
Definition: tif_getimage.c:730
static int initYCbCrConversion(TIFFRGBAImage *img)
static int BuildMapUaToAa(TIFFRGBAImage *img)
static int BuildMapBitdepth16To8(TIFFRGBAImage *img)
int TIFFIsTiled(TIFF *tif)
Definition: tif_open.c:859
#define EXTRASAMPLE_UNASSALPHA
Definition: tiff.h:332
#define EXTRASAMPLE_ASSOCALPHA
Definition: tiff.h:331
#define PHOTOMETRIC_CIELAB
Definition: tiff.h:228

Referenced by TIFFRGBAImageBegin().

◆ PickSeparateCase()

static int PickSeparateCase ( TIFFRGBAImage img)
static

Definition at line 3222 of file tif_getimage.c.

3223{
3225 img->put.separate = NULL;
3226 switch (img->photometric)
3227 {
3230 /* greyscale images processed pretty much as RGB by gtTileSeparate
3231 */
3232 case PHOTOMETRIC_RGB:
3233 switch (img->bitspersample)
3234 {
3235 case 8:
3236 if (img->alpha == EXTRASAMPLE_ASSOCALPHA)
3237 img->put.separate = putRGBAAseparate8bittile;
3238 else if (img->alpha == EXTRASAMPLE_UNASSALPHA)
3239 {
3240 if (BuildMapUaToAa(img))
3241 img->put.separate = putRGBUAseparate8bittile;
3242 }
3243 else
3244 img->put.separate = putRGBseparate8bittile;
3245 break;
3246 case 16:
3247 if (img->alpha == EXTRASAMPLE_ASSOCALPHA)
3248 {
3250 img->put.separate = putRGBAAseparate16bittile;
3251 }
3252 else if (img->alpha == EXTRASAMPLE_UNASSALPHA)
3253 {
3255 img->put.separate = putRGBUAseparate16bittile;
3256 }
3257 else
3258 {
3260 img->put.separate = putRGBseparate16bittile;
3261 }
3262 break;
3263 }
3264 break;
3266 if (img->bitspersample == 8 && img->samplesperpixel == 4)
3267 {
3268 /* Not alpha, but seems like the only way to get 4th band */
3269 img->alpha = 1;
3270 img->put.separate = putCMYKseparate8bittile;
3271 }
3272 break;
3273 case PHOTOMETRIC_YCBCR:
3274 if ((img->bitspersample == 8) && (img->samplesperpixel == 3))
3275 {
3276 if (initYCbCrConversion(img) != 0)
3277 {
3278 uint16_t hs, vs;
3280 &hs, &vs);
3281 switch ((hs << 4) | vs)
3282 {
3283 case 0x11:
3284 img->put.separate = putseparate8bitYCbCr11tile;
3285 break;
3286 /* TODO: add other cases here */
3287 }
3288 }
3289 }
3290 break;
3291 }
3292 return ((img->get != NULL) && (img->put.separate != NULL));
3293}
static vector_t * vs
Definition: server.c:146
static int gtTileSeparate(TIFFRGBAImage *, uint32_t *, uint32_t, uint32_t)
Definition: tif_getimage.c:897
static int gtStripSeparate(TIFFRGBAImage *, uint32_t *, uint32_t, uint32_t)

Referenced by TIFFRGBAImageBegin().

◆ setorientation()

static int setorientation ( TIFFRGBAImage img)
static

Definition at line 663 of file tif_getimage.c.

664{
665 switch (img->orientation)
666 {
669 if (img->req_orientation == ORIENTATION_TOPRIGHT ||
670 img->req_orientation == ORIENTATION_RIGHTTOP)
671 return FLIP_HORIZONTALLY;
672 else if (img->req_orientation == ORIENTATION_BOTRIGHT ||
673 img->req_orientation == ORIENTATION_RIGHTBOT)
675 else if (img->req_orientation == ORIENTATION_BOTLEFT ||
676 img->req_orientation == ORIENTATION_LEFTBOT)
677 return FLIP_VERTICALLY;
678 else
679 return 0;
682 if (img->req_orientation == ORIENTATION_TOPLEFT ||
683 img->req_orientation == ORIENTATION_LEFTTOP)
684 return FLIP_HORIZONTALLY;
685 else if (img->req_orientation == ORIENTATION_BOTRIGHT ||
686 img->req_orientation == ORIENTATION_RIGHTBOT)
687 return FLIP_VERTICALLY;
688 else if (img->req_orientation == ORIENTATION_BOTLEFT ||
689 img->req_orientation == ORIENTATION_LEFTBOT)
691 else
692 return 0;
695 if (img->req_orientation == ORIENTATION_TOPLEFT ||
696 img->req_orientation == ORIENTATION_LEFTTOP)
698 else if (img->req_orientation == ORIENTATION_TOPRIGHT ||
699 img->req_orientation == ORIENTATION_RIGHTTOP)
700 return FLIP_VERTICALLY;
701 else if (img->req_orientation == ORIENTATION_BOTLEFT ||
702 img->req_orientation == ORIENTATION_LEFTBOT)
703 return FLIP_HORIZONTALLY;
704 else
705 return 0;
708 if (img->req_orientation == ORIENTATION_TOPLEFT ||
709 img->req_orientation == ORIENTATION_LEFTTOP)
710 return FLIP_VERTICALLY;
711 else if (img->req_orientation == ORIENTATION_TOPRIGHT ||
712 img->req_orientation == ORIENTATION_RIGHTTOP)
714 else if (img->req_orientation == ORIENTATION_BOTRIGHT ||
715 img->req_orientation == ORIENTATION_RIGHTBOT)
716 return FLIP_HORIZONTALLY;
717 else
718 return 0;
719 default: /* NOTREACHED */
720 return 0;
721 }
722}
#define ORIENTATION_BOTRIGHT
Definition: tiff.h:251
#define ORIENTATION_LEFTTOP
Definition: tiff.h:253
#define ORIENTATION_BOTLEFT
Definition: tiff.h:252
#define ORIENTATION_TOPLEFT
Definition: tiff.h:249
#define ORIENTATION_RIGHTBOT
Definition: tiff.h:255
#define ORIENTATION_RIGHTTOP
Definition: tiff.h:254
#define ORIENTATION_TOPRIGHT
Definition: tiff.h:250
#define ORIENTATION_LEFTBOT
Definition: tiff.h:256

Referenced by gtStripContig(), gtStripSeparate(), gtTileContig(), and gtTileSeparate().

◆ setupMap()

static int setupMap ( TIFFRGBAImage img)
static

Definition at line 2875 of file tif_getimage.c.

2876{
2877 int32_t x, range;
2878
2879 range = (int32_t)((1L << img->bitspersample) - 1);
2880
2881 /* treat 16 bit the same as eight bit */
2882 if (img->bitspersample == 16)
2883 range = (int32_t)255;
2884
2886 img->tif, (range + 1) * sizeof(TIFFRGBValue));
2887 if (img->Map == NULL)
2888 {
2889 TIFFErrorExtR(img->tif, TIFFFileName(img->tif),
2890 "No space for photometric conversion table");
2891 return (0);
2892 }
2893 if (img->photometric == PHOTOMETRIC_MINISWHITE)
2894 {
2895 for (x = 0; x <= range; x++)
2896 img->Map[x] = (TIFFRGBValue)(((range - x) * 255) / range);
2897 }
2898 else
2899 {
2900 for (x = 0; x <= range; x++)
2901 img->Map[x] = (TIFFRGBValue)((x * 255) / range);
2902 }
2903 if (img->bitspersample <= 16 &&
2904 (img->photometric == PHOTOMETRIC_MINISBLACK ||
2905 img->photometric == PHOTOMETRIC_MINISWHITE))
2906 {
2907 /*
2908 * Use photometric mapping table to construct
2909 * unpacking tables for samples <= 8 bits.
2910 */
2911 if (!makebwmap(img))
2912 return (0);
2913 /* no longer need Map, free it */
2914 _TIFFfreeExt(img->tif, img->Map);
2915 img->Map = NULL;
2916 }
2917 return (1);
2918}
GLenum GLint * range
Definition: glext.h:7539
static int makebwmap(TIFFRGBAImage *img)

Referenced by buildMap().

◆ TIFFReadRGBAImage()

int TIFFReadRGBAImage ( TIFF tif,
uint32_t  rwidth,
uint32_t  rheight,
uint32_t raster,
int  stop 
)

Definition at line 656 of file tif_getimage.c.

658{
659 return TIFFReadRGBAImageOriented(tif, rwidth, rheight, raster,
660 ORIENTATION_BOTLEFT, stop);
661}
int TIFFReadRGBAImageOriented(TIFF *tif, uint32_t rwidth, uint32_t rheight, uint32_t *raster, int orientation, int stop)
Definition: tif_getimage.c:631

◆ TIFFReadRGBAImageOriented()

int TIFFReadRGBAImageOriented ( TIFF tif,
uint32_t  rwidth,
uint32_t  rheight,
uint32_t raster,
int  orientation,
int  stop 
)

Definition at line 631 of file tif_getimage.c.

633{
634 char emsg[EMSG_BUF_SIZE] = "";
636 int ok;
637
638 if (TIFFRGBAImageBegin(&img, tif, stop, emsg))
639 {
640 img.req_orientation = (uint16_t)orientation;
641 ok = TIFFRGBAImageGet(&img, raster, rwidth, rheight);
643 }
644 else
645 {
646 TIFFErrorExtR(tif, TIFFFileName(tif), "%s", emsg);
647 ok = 0;
648 }
649 return (ok);
650}
#define ok(value,...)
Definition: atltest.h:57
#define uint16_t
Definition: nsiface.idl:60
#define EMSG_BUF_SIZE
Definition: tif_getimage.c:52
int TIFFRGBAImageGet(TIFFRGBAImage *img, uint32_t *raster, uint32_t w, uint32_t h)
Definition: tif_getimage.c:587
void TIFFRGBAImageEnd(TIFFRGBAImage *img)
Definition: tif_getimage.c:253
int TIFFRGBAImageBegin(TIFFRGBAImage *img, TIFF *tif, int stop, char emsg[EMSG_BUF_SIZE])
Definition: tif_getimage.c:310

Referenced by TIFFReadRGBAImage().

◆ TIFFReadRGBAStrip()

int TIFFReadRGBAStrip ( TIFF tif,
uint32_t  row,
uint32_t raster 
)

Definition at line 3341 of file tif_getimage.c.

3343{
3344 return TIFFReadRGBAStripExt(tif, row, raster, 0);
3345}
int TIFFReadRGBAStripExt(TIFF *tif, uint32_t row, uint32_t *raster, int stop_on_error)

◆ TIFFReadRGBAStripExt()

int TIFFReadRGBAStripExt ( TIFF tif,
uint32_t  row,
uint32_t raster,
int  stop_on_error 
)

Definition at line 3347 of file tif_getimage.c.

3350{
3351 char emsg[EMSG_BUF_SIZE] = "";
3353 int ok;
3354 uint32_t rowsperstrip, rows_to_read;
3355
3356 if (TIFFIsTiled(tif))
3357 {
3358 TIFFErrorExtR(tif, TIFFFileName(tif),
3359 "Can't use TIFFReadRGBAStrip() with tiled file.");
3360 return (0);
3361 }
3362
3363 TIFFGetFieldDefaulted(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);
3364
3365 if (rowsperstrip == 0)
3366 {
3367 TIFFErrorExtR(tif, TIFFFileName(tif), "rowsperstrip is zero");
3368 return (0);
3369 }
3370
3371 if ((row % rowsperstrip) != 0)
3372 {
3374 tif, TIFFFileName(tif),
3375 "Row passed to TIFFReadRGBAStrip() must be first in a strip.");
3376 return (0);
3377 }
3378
3379 if (TIFFRGBAImageBegin(&img, tif, stop_on_error, emsg))
3380 {
3381 if (row >= img.height)
3382 {
3383 TIFFErrorExtR(tif, TIFFFileName(tif),
3384 "Invalid row passed to TIFFReadRGBAStrip().");
3386 return (0);
3387 }
3388
3389 img.row_offset = row;
3390 img.col_offset = 0;
3391
3392 if (row + rowsperstrip > img.height)
3393 rows_to_read = img.height - row;
3394 else
3395 rows_to_read = rowsperstrip;
3396
3397 ok = TIFFRGBAImageGet(&img, raster, img.width, rows_to_read);
3398
3400 }
3401 else
3402 {
3403 TIFFErrorExtR(tif, TIFFFileName(tif), "%s", emsg);
3404 ok = 0;
3405 }
3406
3407 return (ok);
3408}

Referenced by TIFFReadRGBAStrip().

◆ TIFFReadRGBATile()

int TIFFReadRGBATile ( TIFF tif,
uint32_t  col,
uint32_t  row,
uint32_t raster 
)

Definition at line 3416 of file tif_getimage.c.

3418{
3419 return TIFFReadRGBATileExt(tif, col, row, raster, 0);
3420}
int TIFFReadRGBATileExt(TIFF *tif, uint32_t col, uint32_t row, uint32_t *raster, int stop_on_error)

◆ TIFFReadRGBATileExt()

int TIFFReadRGBATileExt ( TIFF tif,
uint32_t  col,
uint32_t  row,
uint32_t raster,
int  stop_on_error 
)

Definition at line 3422 of file tif_getimage.c.

3424{
3425 char emsg[EMSG_BUF_SIZE] = "";
3427 int ok;
3428 uint32_t tile_xsize, tile_ysize;
3429 uint32_t read_xsize, read_ysize;
3430 uint32_t i_row;
3431
3432 /*
3433 * Verify that our request is legal - on a tile file, and on a
3434 * tile boundary.
3435 */
3436
3437 if (!TIFFIsTiled(tif))
3438 {
3439 TIFFErrorExtR(tif, TIFFFileName(tif),
3440 "Can't use TIFFReadRGBATile() with striped file.");
3441 return (0);
3442 }
3443
3444 TIFFGetFieldDefaulted(tif, TIFFTAG_TILEWIDTH, &tile_xsize);
3445 TIFFGetFieldDefaulted(tif, TIFFTAG_TILELENGTH, &tile_ysize);
3446 if (tile_xsize == 0 || tile_ysize == 0)
3447 {
3448 TIFFErrorExtR(tif, TIFFFileName(tif),
3449 "tile_xsize or tile_ysize is zero");
3450 return (0);
3451 }
3452
3453 if ((col % tile_xsize) != 0 || (row % tile_ysize) != 0)
3454 {
3455 TIFFErrorExtR(tif, TIFFFileName(tif),
3456 "Row/col passed to TIFFReadRGBATile() must be top"
3457 "left corner of a tile.");
3458 return (0);
3459 }
3460
3461 /*
3462 * Setup the RGBA reader.
3463 */
3464
3465 if (!TIFFRGBAImageBegin(&img, tif, stop_on_error, emsg))
3466 {
3467 TIFFErrorExtR(tif, TIFFFileName(tif), "%s", emsg);
3468 return (0);
3469 }
3470
3471 if (col >= img.width || row >= img.height)
3472 {
3473 TIFFErrorExtR(tif, TIFFFileName(tif),
3474 "Invalid row/col passed to TIFFReadRGBATile().");
3476 return (0);
3477 }
3478
3479 /*
3480 * The TIFFRGBAImageGet() function doesn't allow us to get off the
3481 * edge of the image, even to fill an otherwise valid tile. So we
3482 * figure out how much we can read, and fix up the tile buffer to
3483 * a full tile configuration afterwards.
3484 */
3485
3486 if (row + tile_ysize > img.height)
3487 read_ysize = img.height - row;
3488 else
3489 read_ysize = tile_ysize;
3490
3491 if (col + tile_xsize > img.width)
3492 read_xsize = img.width - col;
3493 else
3494 read_xsize = tile_xsize;
3495
3496 /*
3497 * Read the chunk of imagery.
3498 */
3499
3500 img.row_offset = row;
3501 img.col_offset = col;
3502
3503 ok = TIFFRGBAImageGet(&img, raster, read_xsize, read_ysize);
3504
3506
3507 /*
3508 * If our read was incomplete we will need to fix up the tile by
3509 * shifting the data around as if a full tile of data is being returned.
3510 *
3511 * This is all the more complicated because the image is organized in
3512 * bottom to top format.
3513 */
3514
3515 if (read_xsize == tile_xsize && read_ysize == tile_ysize)
3516 return (ok);
3517
3518 for (i_row = 0; i_row < read_ysize; i_row++)
3519 {
3520 memmove(raster + (size_t)(tile_ysize - i_row - 1) * tile_xsize,
3521 raster + (size_t)(read_ysize - i_row - 1) * read_xsize,
3522 read_xsize * sizeof(uint32_t));
3523 _TIFFmemset(raster + (size_t)(tile_ysize - i_row - 1) * tile_xsize +
3524 read_xsize,
3525 0, sizeof(uint32_t) * (tile_xsize - read_xsize));
3526 }
3527
3528 for (i_row = read_ysize; i_row < tile_ysize; i_row++)
3529 {
3530 _TIFFmemset(raster + (size_t)(tile_ysize - i_row - 1) * tile_xsize, 0,
3531 sizeof(uint32_t) * tile_xsize);
3532 }
3533
3534 return (ok);
3535}
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
void _TIFFmemset(void *p, int v, tmsize_t c)
Definition: tif_unix.c:353

Referenced by TIFFReadRGBATile().

◆ TIFFRGBAImageBegin()

int TIFFRGBAImageBegin ( TIFFRGBAImage img,
TIFF tif,
int  stop,
char  emsg[EMSG_BUF_SIZE] 
)

Definition at line 310 of file tif_getimage.c.

312{
313 uint16_t *sampleinfo;
314 uint16_t extrasamples;
315 uint16_t planarconfig;
317 int colorchannels;
318 uint16_t *red_orig, *green_orig, *blue_orig;
319 int n_color;
320
321 if (!TIFFRGBAImageOK(tif, emsg))
322 return 0;
323
324 /* Initialize to normal values */
325 img->row_offset = 0;
326 img->col_offset = 0;
327 img->redcmap = NULL;
328 img->greencmap = NULL;
329 img->bluecmap = NULL;
330 img->Map = NULL;
331 img->BWmap = NULL;
332 img->PALmap = NULL;
333 img->ycbcr = NULL;
334 img->cielab = NULL;
335 img->UaToAa = NULL;
336 img->Bitdepth16To8 = NULL;
337 img->req_orientation = ORIENTATION_BOTLEFT; /* It is the default */
338
339 img->tif = tif;
340 img->stoponerr = stop;
341 TIFFGetFieldDefaulted(tif, TIFFTAG_BITSPERSAMPLE, &img->bitspersample);
342 switch (img->bitspersample)
343 {
344 case 1:
345 case 2:
346 case 4:
347 case 8:
348 case 16:
349 break;
350 default:
352 "Sorry, can not handle images with %" PRIu16
353 "-bit samples",
354 img->bitspersample);
355 goto fail_return;
356 }
357 img->alpha = 0;
358 TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLESPERPIXEL, &img->samplesperpixel);
360 &sampleinfo);
361 if (extrasamples >= 1)
362 {
363 switch (sampleinfo[0])
364 {
365 case EXTRASAMPLE_UNSPECIFIED: /* Workaround for some images without
366 */
367 if (img->samplesperpixel >
368 3) /* correct info about alpha channel */
370 break;
371 case EXTRASAMPLE_ASSOCALPHA: /* data is pre-multiplied */
372 case EXTRASAMPLE_UNASSALPHA: /* data is not pre-multiplied */
373 img->alpha = sampleinfo[0];
374 break;
375 }
376 }
377
378#ifdef DEFAULT_EXTRASAMPLE_AS_ALPHA
379 if (!TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &img->photometric))
380 img->photometric = PHOTOMETRIC_MINISWHITE;
381
382 if (extrasamples == 0 && img->samplesperpixel == 4 &&
383 img->photometric == PHOTOMETRIC_RGB)
384 {
386 extrasamples = 1;
387 }
388#endif
389
390 colorchannels = img->samplesperpixel - extrasamples;
392 TIFFGetFieldDefaulted(tif, TIFFTAG_PLANARCONFIG, &planarconfig);
393 if (!TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &img->photometric))
394 {
395 switch (colorchannels)
396 {
397 case 1:
398 if (isCCITTCompression(tif))
399 img->photometric = PHOTOMETRIC_MINISWHITE;
400 else
401 img->photometric = PHOTOMETRIC_MINISBLACK;
402 break;
403 case 3:
404 img->photometric = PHOTOMETRIC_RGB;
405 break;
406 default:
407 snprintf(emsg, EMSG_BUF_SIZE, "Missing needed %s tag",
408 photoTag);
409 goto fail_return;
410 }
411 }
412 switch (img->photometric)
413 {
415 if (!TIFFGetField(tif, TIFFTAG_COLORMAP, &red_orig, &green_orig,
416 &blue_orig))
417 {
419 "Missing required \"Colormap\" tag");
420 goto fail_return;
421 }
422
423 /* copy the colormaps so we can modify them */
424 n_color = (1U << img->bitspersample);
425 img->redcmap =
426 (uint16_t *)_TIFFmallocExt(tif, sizeof(uint16_t) * n_color);
427 img->greencmap =
428 (uint16_t *)_TIFFmallocExt(tif, sizeof(uint16_t) * n_color);
429 img->bluecmap =
430 (uint16_t *)_TIFFmallocExt(tif, sizeof(uint16_t) * n_color);
431 if (!img->redcmap || !img->greencmap || !img->bluecmap)
432 {
434 "Out of memory for colormap copy");
435 goto fail_return;
436 }
437
438 _TIFFmemcpy(img->redcmap, red_orig, n_color * 2);
439 _TIFFmemcpy(img->greencmap, green_orig, n_color * 2);
440 _TIFFmemcpy(img->bluecmap, blue_orig, n_color * 2);
441
442 /* fall through... */
445 if (planarconfig == PLANARCONFIG_CONTIG &&
446 img->samplesperpixel != 1 && img->bitspersample < 8)
447 {
448 snprintf(
449 emsg, EMSG_BUF_SIZE,
450 "Sorry, can not handle contiguous data with %s=%" PRIu16
451 ", "
452 "and %s=%" PRIu16 " and Bits/Sample=%" PRIu16,
453 photoTag, img->photometric, "Samples/pixel",
454 img->samplesperpixel, img->bitspersample);
455 goto fail_return;
456 }
457 break;
459 /* It would probably be nice to have a reality check here. */
460 if (planarconfig == PLANARCONFIG_CONTIG)
461 /* can rely on libjpeg to convert to RGB */
462 /* XXX should restore current state on exit */
463 switch (compress)
464 {
465 case COMPRESSION_JPEG:
466 /*
467 * TODO: when complete tests verify complete
468 * desubsampling and YCbCr handling, remove use of
469 * TIFFTAG_JPEGCOLORMODE in favor of tif_getimage.c
470 * native handling
471 */
474 img->photometric = PHOTOMETRIC_RGB;
475 break;
476 default:
477 /* do nothing */;
478 break;
479 }
480 /*
481 * TODO: if at all meaningful and useful, make more complete
482 * support check here, or better still, refactor to let supporting
483 * code decide whether there is support and what meaningful
484 * error to return
485 */
486 break;
487 case PHOTOMETRIC_RGB:
488 if (colorchannels < 3)
489 {
491 "Sorry, can not handle RGB image with %s=%d",
492 "Color channels", colorchannels);
493 goto fail_return;
494 }
495 break;
497 {
498 uint16_t inkset;
500 if (inkset != INKSET_CMYK)
501 {
502 snprintf(
503 emsg, EMSG_BUF_SIZE,
504 "Sorry, can not handle separated image with %s=%" PRIu16,
505 "InkSet", inkset);
506 goto fail_return;
507 }
508 if (img->samplesperpixel < 4)
509 {
510 snprintf(
511 emsg, EMSG_BUF_SIZE,
512 "Sorry, can not handle separated image with %s=%" PRIu16,
513 "Samples/pixel", img->samplesperpixel);
514 goto fail_return;
515 }
516 }
517 break;
518 case PHOTOMETRIC_LOGL:
520 {
522 "Sorry, LogL data must have %s=%d", "Compression",
524 goto fail_return;
525 }
527 img->photometric = PHOTOMETRIC_MINISBLACK; /* little white lie */
528 img->bitspersample = 8;
529 break;
533 {
535 "Sorry, LogLuv data must have %s=%d or %d",
536 "Compression", COMPRESSION_SGILOG,
538 goto fail_return;
539 }
540 if (planarconfig != PLANARCONFIG_CONTIG)
541 {
543 "Sorry, can not handle LogLuv images with %s=%" PRIu16,
544 "Planarconfiguration", planarconfig);
545 return (0);
546 }
548 img->photometric = PHOTOMETRIC_RGB; /* little white lie */
549 img->bitspersample = 8;
550 break;
552 break;
553 default:
555 "Sorry, can not handle image with %s=%" PRIu16, photoTag,
556 img->photometric);
557 goto fail_return;
558 }
559 TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &img->width);
560 TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &img->height);
561 TIFFGetFieldDefaulted(tif, TIFFTAG_ORIENTATION, &img->orientation);
562 img->isContig =
563 !(planarconfig == PLANARCONFIG_SEPARATE && img->samplesperpixel > 1);
564 if (img->isContig)
565 {
566 if (!PickContigCase(img))
567 {
568 snprintf(emsg, EMSG_BUF_SIZE, "Sorry, can not handle image");
569 goto fail_return;
570 }
571 }
572 else
573 {
574 if (!PickSeparateCase(img))
575 {
576 snprintf(emsg, EMSG_BUF_SIZE, "Sorry, can not handle image");
577 goto fail_return;
578 }
579 }
580 return 1;
581
582fail_return:
584 return 0;
585}
#define PRIu16
Definition: inttypes.h:83
int TIFFSetField(TIFF *tif, uint32_t tag,...)
Definition: tif_dir.c:1146
static int PickContigCase(TIFFRGBAImage *)
static int isCCITTCompression(TIFF *tif)
Definition: tif_getimage.c:300
int TIFFRGBAImageOK(TIFF *tif, char emsg[EMSG_BUF_SIZE])
Definition: tif_getimage.c:83
static int PickSeparateCase(TIFFRGBAImage *)
static const char photoTag[]
Definition: tif_getimage.c:44
void _TIFFmemcpy(void *d, const void *s, tmsize_t c)
Definition: tif_unix.c:355
#define TIFFTAG_BITSPERSAMPLE
Definition: tiff.h:180
#define PLANARCONFIG_SEPARATE
Definition: tiff.h:266
#define TIFFTAG_SAMPLESPERPIXEL
Definition: tiff.h:257
#define PHOTOMETRIC_LOGL
Definition: tiff.h:232
#define TIFFTAG_INKSET
Definition: tiff.h:322
#define COMPRESSION_SGILOG
Definition: tiff.h:210
#define TIFFTAG_COLORMAP
Definition: tiff.h:309
#define EXTRASAMPLE_UNSPECIFIED
Definition: tiff.h:330
#define TIFFTAG_PHOTOMETRIC
Definition: tiff.h:220
#define TIFFTAG_EXTRASAMPLES
Definition: tiff.h:329
#define TIFFTAG_IMAGEWIDTH
Definition: tiff.h:178
#define TIFFTAG_ORIENTATION
Definition: tiff.h:248
#define PHOTOMETRIC_LOGLUV
Definition: tiff.h:233
#define SGILOGDATAFMT_8BIT
Definition: tiff.h:747
#define INKSET_CMYK
Definition: tiff.h:323
#define TIFFTAG_SGILOGDATAFMT
Definition: tiff.h:743
#define COMPRESSION_SGILOG24
Definition: tiff.h:211
#define TIFFTAG_IMAGELENGTH
Definition: tiff.h:179
#define TIFFTAG_PLANARCONFIG
Definition: tiff.h:264
#define TIFFTAG_JPEGCOLORMODE
Definition: tiff.h:706
#define JPEGCOLORMODE_RGB
Definition: tiff.h:708
#define COMPRESSION_JPEG
Definition: tiff.h:190
#define PLANARCONFIG_CONTIG
Definition: tiff.h:265
#define snprintf
Definition: wintirpc.h:48

Referenced by TIFFReadRGBAImageOriented(), TIFFReadRGBAStripExt(), and TIFFReadRGBATileExt().

◆ TIFFRGBAImageEnd()

void TIFFRGBAImageEnd ( TIFFRGBAImage img)

Definition at line 253 of file tif_getimage.c.

254{
255 if (img->Map)
256 {
257 _TIFFfreeExt(img->tif, img->Map);
258 img->Map = NULL;
259 }
260 if (img->BWmap)
261 {
262 _TIFFfreeExt(img->tif, img->BWmap);
263 img->BWmap = NULL;
264 }
265 if (img->PALmap)
266 {
267 _TIFFfreeExt(img->tif, img->PALmap);
268 img->PALmap = NULL;
269 }
270 if (img->ycbcr)
271 {
272 _TIFFfreeExt(img->tif, img->ycbcr);
273 img->ycbcr = NULL;
274 }
275 if (img->cielab)
276 {
277 _TIFFfreeExt(img->tif, img->cielab);
278 img->cielab = NULL;
279 }
280 if (img->UaToAa)
281 {
282 _TIFFfreeExt(img->tif, img->UaToAa);
283 img->UaToAa = NULL;
284 }
285 if (img->Bitdepth16To8)
286 {
287 _TIFFfreeExt(img->tif, img->Bitdepth16To8);
288 img->Bitdepth16To8 = NULL;
289 }
290
291 if (img->redcmap)
292 {
293 _TIFFfreeExt(img->tif, img->redcmap);
294 _TIFFfreeExt(img->tif, img->greencmap);
295 _TIFFfreeExt(img->tif, img->bluecmap);
296 img->redcmap = img->greencmap = img->bluecmap = NULL;
297 }
298}

Referenced by TIFFReadRGBAImageOriented(), TIFFReadRGBAStripExt(), TIFFReadRGBATileExt(), and TIFFRGBAImageBegin().

◆ TIFFRGBAImageGet()

int TIFFRGBAImageGet ( TIFFRGBAImage img,
uint32_t raster,
uint32_t  w,
uint32_t  h 
)

Definition at line 587 of file tif_getimage.c.

589{
590 if (img->get == NULL)
591 {
592 TIFFErrorExtR(img->tif, TIFFFileName(img->tif),
593 "No \"get\" routine setup");
594 return (0);
595 }
596 if (img->put.any == NULL)
597 {
599 img->tif, TIFFFileName(img->tif),
600 "No \"put\" routine setupl; probably can not handle image format");
601 return (0);
602 }
603 /* Verify raster height against image height.
604 * Width is checked in img->get() function individually. */
605 if (0 <= img->row_offset && (uint32_t)img->row_offset < img->height)
606 {
607 uint32_t hx = img->height - img->row_offset;
608 if (h > hx)
609 {
610 /* Adapt parameters to read only available lines and put image
611 * at the bottom of the raster. */
612 raster += (size_t)(h - hx) * w;
613 h = hx;
614 }
615 }
616 else
617 {
618 TIFFErrorExtR(img->tif, TIFFFileName(img->tif),
619 "Error in TIFFRGBAImageGet: row offset %d exceeds "
620 "image height %d",
621 img->row_offset, img->height);
622 return 0;
623 }
624 return (*img->get)(img, raster, w, h);
625}

Referenced by TIFFReadRGBAImageOriented(), TIFFReadRGBAStripExt(), and TIFFReadRGBATileExt().

◆ TIFFRGBAImageOK()

int TIFFRGBAImageOK ( TIFF tif,
char  emsg[EMSG_BUF_SIZE] 
)

Definition at line 83 of file tif_getimage.c.

84{
85 TIFFDirectory *td = &tif->tif_dir;
86 uint16_t photometric;
87 int colorchannels;
88
89 if (!tif->tif_decodestatus)
90 {
92 "Sorry, requested compression method is not configured");
93 return (0);
94 }
95 switch (td->td_bitspersample)
96 {
97 case 1:
98 case 2:
99 case 4:
100 case 8:
101 case 16:
102 break;
103 default:
105 "Sorry, can not handle images with %" PRIu16
106 "-bit samples",
107 td->td_bitspersample);
108 return (0);
109 }
111 {
112 snprintf(
113 emsg, EMSG_BUF_SIZE,
114 "Sorry, can not handle images with IEEE floating-point samples");
115 return (0);
116 }
117 colorchannels = td->td_samplesperpixel - td->td_extrasamples;
118 if (!TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &photometric))
119 {
120 switch (colorchannels)
121 {
122 case 1:
123 photometric = PHOTOMETRIC_MINISBLACK;
124 break;
125 case 3:
126 photometric = PHOTOMETRIC_RGB;
127 break;
128 default:
129 snprintf(emsg, EMSG_BUF_SIZE, "Missing needed %s tag",
130 photoTag);
131 return (0);
132 }
133 }
134 switch (photometric)
135 {
140 td->td_samplesperpixel != 1 && td->td_bitspersample < 8)
141 {
142 snprintf(
143 emsg, EMSG_BUF_SIZE,
144 "Sorry, can not handle contiguous data with %s=%" PRIu16
145 ", "
146 "and %s=%" PRIu16 " and Bits/Sample=%" PRIu16 "",
147 photoTag, photometric, "Samples/pixel",
149 return (0);
150 }
151 /*
152 * We should likely validate that any extra samples are either
153 * to be ignored, or are alpha, and if alpha we should try to use
154 * them. But for now we won't bother with this.
155 */
156 break;
158 /*
159 * TODO: if at all meaningful and useful, make more complete
160 * support check here, or better still, refactor to let supporting
161 * code decide whether there is support and what meaningful
162 * error to return
163 */
164 break;
165 case PHOTOMETRIC_RGB:
166 if (colorchannels < 3)
167 {
169 "Sorry, can not handle RGB image with %s=%d",
170 "Color channels", colorchannels);
171 return (0);
172 }
173 break;
175 {
176 uint16_t inkset;
178 if (inkset != INKSET_CMYK)
179 {
181 "Sorry, can not handle separated image with %s=%d",
182 "InkSet", inkset);
183 return 0;
184 }
185 if (td->td_samplesperpixel < 4)
186 {
187 snprintf(
188 emsg, EMSG_BUF_SIZE,
189 "Sorry, can not handle separated image with %s=%" PRIu16,
190 "Samples/pixel", td->td_samplesperpixel);
191 return 0;
192 }
193 break;
194 }
195 case PHOTOMETRIC_LOGL:
197 {
199 "Sorry, LogL data must have %s=%d", "Compression",
201 return (0);
202 }
203 break;
207 {
209 "Sorry, LogLuv data must have %s=%d or %d",
210 "Compression", COMPRESSION_SGILOG,
212 return (0);
213 }
215 {
217 "Sorry, can not handle LogLuv images with %s=%" PRIu16,
218 "Planarconfiguration", td->td_planarconfig);
219 return (0);
220 }
221 if (td->td_samplesperpixel != 3 || colorchannels != 3)
222 {
224 "Sorry, can not handle image with %s=%" PRIu16
225 ", %s=%d",
226 "Samples/pixel", td->td_samplesperpixel,
227 "colorchannels", colorchannels);
228 return 0;
229 }
230 break;
232 if (td->td_samplesperpixel != 3 || colorchannels != 3 ||
233 (td->td_bitspersample != 8 && td->td_bitspersample != 16))
234 {
236 "Sorry, can not handle image with %s=%" PRIu16
237 ", %s=%d and %s=%" PRIu16,
238 "Samples/pixel", td->td_samplesperpixel,
239 "colorchannels", colorchannels, "Bits/sample",
240 td->td_bitspersample);
241 return 0;
242 }
243 break;
244 default:
246 "Sorry, can not handle image with %s=%" PRIu16, photoTag,
247 photometric);
248 return (0);
249 }
250 return (1);
251}
uint16_t td_compression
Definition: tif_dir.h:88
uint16_t td_extrasamples
Definition: tif_dir.h:105
uint16_t td_bitspersample
Definition: tif_dir.h:86
uint16_t td_planarconfig
Definition: tif_dir.h:100
uint16_t td_sampleformat
Definition: tif_dir.h:87
uint16_t td_samplesperpixel
Definition: tif_dir.h:93
TIFFDirectory tif_dir
Definition: tiffiop.h:157
int tif_decodestatus
Definition: tiffiop.h:197
#define SAMPLEFORMAT_IEEEFP
Definition: tiff.h:336

Referenced by TIFFRGBAImageBegin().

Variable Documentation

◆ display_sRGB

const TIFFDisplay display_sRGB
static
Initial value:
= {
{
{3.2410F, -1.5374F, -0.4986F},
{-0.9692F, 1.8760F, 0.0416F},
{0.0556F, -0.2040F, 1.0570F}},
100.0F,
100.0F,
100.0F,
255,
255,
255,
1.0F,
1.0F,
1.0F,
2.4F,
2.4F,
2.4F,
}

Definition at line 58 of file tif_getimage.c.

Referenced by initCIELabConversion().

◆ photoTag

const char photoTag[] = "PhotometricInterpretation"
static

Definition at line 44 of file tif_getimage.c.

Referenced by TIFFRGBAImageBegin(), and TIFFRGBAImageOK().