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

Go to the source code of this file.

Macros

#define RINT(R)   ((uint32_t)((R) > 0 ? ((R) + 0.5) : ((R)-0.5)))
 
#define SHIFT   16
 
#define FIX(x)   ((int32_t)((x) * (1L << SHIFT) + 0.5))
 
#define ONE_HALF   ((int32_t)(1 << (SHIFT - 1)))
 
#define Code2V(c, RB, RW, CR)
 
#define CLAMP(f, min, max)    ((!((f) >= (min))) ? (min) : (f) > (max) ? (max) : (f))
 
#define HICLAMP(f, max)   ((f) > (max) ? (max) : (f))
 
#define LumaRed   luma[0]
 
#define LumaGreen   luma[1]
 
#define LumaBlue   luma[2]
 

Functions

void TIFFCIELabToXYZ (TIFFCIELabToRGB *cielab, uint32_t l, int32_t a, int32_t b, float *X, float *Y, float *Z)
 
void TIFFCIELab16ToXYZ (TIFFCIELabToRGB *cielab, uint32_t l, int32_t a, int32_t b, float *X, float *Y, float *Z)
 
void TIFFXYZToRGB (TIFFCIELabToRGB *cielab, float X, float Y, float Z, uint32_t *r, uint32_t *g, uint32_t *b)
 
int TIFFCIELabToRGBInit (TIFFCIELabToRGB *cielab, const TIFFDisplay *display, float *refWhite)
 
void TIFFYCbCrtoRGB (TIFFYCbCrToRGB *ycbcr, uint32_t Y, int32_t Cb, int32_t Cr, uint32_t *r, uint32_t *g, uint32_t *b)
 
static float CLAMPw (float v, float vmin, float vmax)
 
int TIFFYCbCrToRGBInit (TIFFYCbCrToRGB *ycbcr, float *luma, float *refBlackWhite)
 

Macro Definition Documentation

◆ CLAMP

#define CLAMP (   f,
  min,
  max 
)     ((!((f) >= (min))) ? (min) : (f) > (max) ? (max) : (f))

Definition at line 195 of file tif_color.c.

◆ Code2V

#define Code2V (   c,
  RB,
  RW,
  CR 
)
Value:
((((c) - (int32_t)(RB)) * (float)(CR)) / \
(float)(((RW) - (RB) != 0) ? ((RW) - (RB)) : 1))
INT32 int32_t
Definition: types.h:71
#define c
Definition: ke_i.h:80
static float(__cdecl *square_half_float)(float x
#define CR
Definition: telnetd.h:25

Definition at line 191 of file tif_color.c.

◆ FIX

#define FIX (   x)    ((int32_t)((x) * (1L << SHIFT) + 0.5))

Definition at line 189 of file tif_color.c.

◆ HICLAMP

#define HICLAMP (   f,
  max 
)    ((f) > (max) ? (max) : (f))

Definition at line 197 of file tif_color.c.

◆ LumaBlue

#define LumaBlue   luma[2]

◆ LumaGreen

#define LumaGreen   luma[1]

◆ LumaRed

#define LumaRed   luma[0]

◆ ONE_HALF

#define ONE_HALF   ((int32_t)(1 << (SHIFT - 1)))

Definition at line 190 of file tif_color.c.

◆ RINT

#define RINT (   R)    ((uint32_t)((R) > 0 ? ((R) + 0.5) : ((R)-0.5)))

Definition at line 85 of file tif_color.c.

◆ SHIFT

#define SHIFT   16

Definition at line 188 of file tif_color.c.

Function Documentation

◆ CLAMPw()

static float CLAMPw ( float  v,
float  vmin,
float  vmax 
)
static

Definition at line 220 of file tif_color.c.

221{
222 if (v < vmin)
223 {
224 /* printf("%f clamped to %f\n", v, vmin); */
225 return vmin;
226 }
227 if (v > vmax)
228 {
229 /* printf("%f clamped to %f\n", v, vmax); */
230 return vmax;
231 }
232 return v;
233}
const GLdouble * v
Definition: gl.h:2040

Referenced by TIFFYCbCrToRGBInit().

◆ TIFFCIELab16ToXYZ()

void TIFFCIELab16ToXYZ ( TIFFCIELabToRGB cielab,
uint32_t  l,
int32_t  a,
int32_t  b,
float X,
float Y,
float Z 
)

Definition at line 55 of file tif_color.c.

57{
58 float L = (float)l * 100.0F / 65535.0F;
59 float cby, tmp;
60
61 if (L < 8.856F)
62 {
63 *Y = (L * cielab->Y0) / 903.292F;
64 cby = 7.787F * (*Y / cielab->Y0) + 16.0F / 116.0F;
65 }
66 else
67 {
68 cby = (L + 16.0F) / 116.0F;
69 *Y = cielab->Y0 * cby * cby * cby;
70 }
71
72 tmp = (float)a / 256.0F / 500.0F + cby;
73 if (tmp < 0.2069F)
74 *X = cielab->X0 * (tmp - 0.13793F) / 7.787F;
75 else
76 *X = cielab->X0 * tmp * tmp * tmp;
77
78 tmp = cby - (float)b / 256.0F / 200.0F;
79 if (tmp < 0.2069F)
80 *Z = cielab->Z0 * (tmp - 0.13793F) / 7.787F;
81 else
82 *Z = cielab->Z0 * tmp * tmp * tmp;
83}
r l[0]
Definition: byte_order.h:168
#define Z(I)
#define Y(I)
#define L(x)
Definition: resources.c:13
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204

Referenced by DECLAREContigPutFunc(), and TIFFCIELabToXYZ().

◆ TIFFCIELabToRGBInit()

int TIFFCIELabToRGBInit ( TIFFCIELabToRGB cielab,
const TIFFDisplay display,
float refWhite 
)

Definition at line 135 of file tif_color.c.

137{
138 size_t i;
139 double dfGamma;
140
142
143 _TIFFmemcpy(&cielab->display, display, sizeof(TIFFDisplay));
144
145 /* Red */
146 dfGamma = 1.0 / cielab->display.d_gammaR;
147 cielab->rstep =
148 (cielab->display.d_YCR - cielab->display.d_Y0R) / cielab->range;
149 for (i = 0; i <= (size_t)cielab->range; i++)
150 {
151 cielab->Yr2r[i] = cielab->display.d_Vrwr *
152 ((float)pow((double)i / cielab->range, dfGamma));
153 }
154
155 /* Green */
156 dfGamma = 1.0 / cielab->display.d_gammaG;
157 cielab->gstep =
158 (cielab->display.d_YCR - cielab->display.d_Y0R) / cielab->range;
159 for (i = 0; i <= (size_t)cielab->range; i++)
160 {
161 cielab->Yg2g[i] = cielab->display.d_Vrwg *
162 ((float)pow((double)i / cielab->range, dfGamma));
163 }
164
165 /* Blue */
166 dfGamma = 1.0 / cielab->display.d_gammaB;
167 cielab->bstep =
168 (cielab->display.d_YCR - cielab->display.d_Y0R) / cielab->range;
169 for (i = 0; i <= (size_t)cielab->range; i++)
170 {
171 cielab->Yb2b[i] = cielab->display.d_Vrwb *
172 ((float)pow((double)i / cielab->range, dfGamma));
173 }
174
175 /* Init reference white point */
176 cielab->X0 = refWhite[0];
177 cielab->Y0 = refWhite[1];
178 cielab->Z0 = refWhite[2];
179
180 return 0;
181}
unsigned int size_t
Definition: corecrt.h:203
double pow(double x, double y)
Definition: freeldr.c:179
for(i=0;i< ARRAY_SIZE(offsets);i++)
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
float Yb2b[CIELABTORGB_TABLE_RANGE+1]
Definition: tiffio.h:188
float bstep
Definition: tiffio.h:183
TIFFDisplay display
Definition: tiffio.h:185
float rstep
Definition: tiffio.h:183
float gstep
Definition: tiffio.h:183
float Yr2r[CIELABTORGB_TABLE_RANGE+1]
Definition: tiffio.h:186
float Yg2g[CIELABTORGB_TABLE_RANGE+1]
Definition: tiffio.h:187
float d_gammaG
Definition: tiffio.h:153
uint32_t d_Vrwr
Definition: tiffio.h:146
float d_Y0R
Definition: tiffio.h:149
float d_gammaR
Definition: tiffio.h:152
float d_YCR
Definition: tiffio.h:143
uint32_t d_Vrwg
Definition: tiffio.h:147
float d_gammaB
Definition: tiffio.h:154
uint32_t d_Vrwb
Definition: tiffio.h:148
void _TIFFmemcpy(void *d, const void *s, tmsize_t c)
Definition: tif_unix.c:355
#define CIELABTORGB_TABLE_RANGE
Definition: tiffio.h:182
int * display
Definition: x11stubs.c:12

Referenced by initCIELabConversion().

◆ TIFFCIELabToXYZ()

void TIFFCIELabToXYZ ( TIFFCIELabToRGB cielab,
uint32_t  l,
int32_t  a,
int32_t  b,
float X,
float Y,
float Z 
)

Definition at line 43 of file tif_color.c.

45{
46 TIFFCIELab16ToXYZ(cielab, l * 257, a * 256, b * 256, X, Y, Z);
47}
void TIFFCIELab16ToXYZ(TIFFCIELabToRGB *cielab, uint32_t l, int32_t a, int32_t b, float *X, float *Y, float *Z)
Definition: tif_color.c:55

Referenced by DECLAREContigPutFunc().

◆ TIFFXYZToRGB()

void TIFFXYZToRGB ( TIFFCIELabToRGB cielab,
float  X,
float  Y,
float  Z,
uint32_t r,
uint32_t g,
uint32_t b 
)

Definition at line 89 of file tif_color.c.

91{
92 size_t i;
93 float Yr, Yg, Yb;
94 float *matrix = &cielab->display.d_mat[0][0];
95
96 /* Multiply through the matrix to get luminosity values. */
97 Yr = matrix[0] * X + matrix[1] * Y + matrix[2] * Z;
98 Yg = matrix[3] * X + matrix[4] * Y + matrix[5] * Z;
99 Yb = matrix[6] * X + matrix[7] * Y + matrix[8] * Z;
100
101 /* Clip input */
102 Yr = TIFFmax(Yr, cielab->display.d_Y0R);
103 Yg = TIFFmax(Yg, cielab->display.d_Y0G);
104 Yb = TIFFmax(Yb, cielab->display.d_Y0B);
105
106 /* Avoid overflow in case of wrong input values */
107 Yr = TIFFmin(Yr, cielab->display.d_YCR);
108 Yg = TIFFmin(Yg, cielab->display.d_YCG);
109 Yb = TIFFmin(Yb, cielab->display.d_YCB);
110
111 /* Turn luminosity to colour value. */
112 i = (size_t)((Yr - cielab->display.d_Y0R) / cielab->rstep);
113 i = TIFFmin((size_t)cielab->range, i);
114 *r = RINT(cielab->Yr2r[i]);
115
116 i = (size_t)((Yg - cielab->display.d_Y0G) / cielab->gstep);
117 i = TIFFmin((size_t)cielab->range, i);
118 *g = RINT(cielab->Yg2g[i]);
119
120 i = (size_t)((Yb - cielab->display.d_Y0B) / cielab->bstep);
121 i = TIFFmin((size_t)cielab->range, i);
122 *b = RINT(cielab->Yb2b[i]);
123
124 /* Clip output. */
125 *r = TIFFmin(*r, cielab->display.d_Vrwr);
126 *g = TIFFmin(*g, cielab->display.d_Vrwg);
127 *b = TIFFmin(*b, cielab->display.d_Vrwb);
128}
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLuint GLenum matrix
Definition: glext.h:9407
GLboolean GLboolean g
Definition: glext.h:6204
#define Yb
Definition: i386-dis.c:436
float d_mat[3][3]
Definition: tiffio.h:142
float d_YCB
Definition: tiffio.h:145
float d_YCG
Definition: tiffio.h:144
float d_Y0G
Definition: tiffio.h:150
float d_Y0B
Definition: tiffio.h:151
#define RINT(R)
Definition: tif_color.c:85
#define TIFFmax(A, B)
Definition: tiffiop.h:330
#define TIFFmin(A, B)
Definition: tiffiop.h:331

Referenced by DECLAREContigPutFunc().

◆ TIFFYCbCrtoRGB()

void TIFFYCbCrtoRGB ( TIFFYCbCrToRGB ycbcr,
uint32_t  Y,
int32_t  Cb,
int32_t  Cr,
uint32_t r,
uint32_t g,
uint32_t b 
)

Definition at line 199 of file tif_color.c.

201{
202 int32_t i;
203
204 /* XXX: Only 8-bit YCbCr input supported for now */
205 Y = HICLAMP(Y, 255);
206 Cb = CLAMP(Cb, 0, 255);
207 Cr = CLAMP(Cr, 0, 255);
208
209 i = ycbcr->Y_tab[Y] + ycbcr->Cr_r_tab[Cr];
210 *r = CLAMP(i, 0, 255);
211 i = ycbcr->Y_tab[Y] +
212 (int)((ycbcr->Cb_g_tab[Cb] + ycbcr->Cr_g_tab[Cr]) >> SHIFT);
213 *g = CLAMP(i, 0, 255);
214 i = ycbcr->Y_tab[Y] + ycbcr->Cb_b_tab[Cb];
215 *b = CLAMP(i, 0, 255);
216}
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
int * Cr_r_tab
Definition: tiffio.h:172
int32_t * Cb_g_tab
Definition: tiffio.h:175
int32_t * Y_tab
Definition: tiffio.h:176
int * Cb_b_tab
Definition: tiffio.h:173
int32_t * Cr_g_tab
Definition: tiffio.h:174
#define CLAMP(f, min, max)
Definition: tif_color.c:195
#define SHIFT
Definition: tif_color.c:188
#define HICLAMP(f, max)
Definition: tif_color.c:197

Referenced by DECLARESepPutFunc().

◆ TIFFYCbCrToRGBInit()

int TIFFYCbCrToRGBInit ( TIFFYCbCrToRGB ycbcr,
float luma,
float refBlackWhite 
)

Definition at line 251 of file tif_color.c.

252{
253 TIFFRGBValue *clamptab;
254 int i;
255
256#define LumaRed luma[0]
257#define LumaGreen luma[1]
258#define LumaBlue luma[2]
259
260 clamptab =
261 (TIFFRGBValue *)((uint8_t *)ycbcr +
262 TIFFroundup_32(sizeof(TIFFYCbCrToRGB), sizeof(long)));
263 _TIFFmemset(clamptab, 0, 256); /* v < 0 => 0 */
264 ycbcr->clamptab = (clamptab += 256);
265 for (i = 0; i < 256; i++)
266 clamptab[i] = (TIFFRGBValue)i;
267 _TIFFmemset(clamptab + 256, 255, 2 * 256); /* v > 255 => 255 */
268 ycbcr->Cr_r_tab = (int *)(clamptab + 3 * 256);
269 ycbcr->Cb_b_tab = ycbcr->Cr_r_tab + 256;
270 ycbcr->Cr_g_tab = (int32_t *)(ycbcr->Cb_b_tab + 256);
271 ycbcr->Cb_g_tab = ycbcr->Cr_g_tab + 256;
272 ycbcr->Y_tab = ycbcr->Cb_g_tab + 256;
273
274 {
275 float f1 = 2 - 2 * LumaRed;
276 int32_t D1 = FIX(CLAMP(f1, 0.0F, 2.0F));
277 float f2 = LumaRed * f1 / LumaGreen;
278 int32_t D2 = -FIX(CLAMP(f2, 0.0F, 2.0F));
279 float f3 = 2 - 2 * LumaBlue;
280 int32_t D3 = FIX(CLAMP(f3, 0.0F, 2.0F));
281 float f4 = LumaBlue * f3 / LumaGreen;
282 int32_t D4 = -FIX(CLAMP(f4, 0.0F, 2.0F));
283 int x;
284
285#undef LumaBlue
286#undef LumaGreen
287#undef LumaRed
288
289 /*
290 * i is the actual input pixel value in the range 0..255
291 * Cb and Cr values are in the range -128..127 (actually
292 * they are in a range defined by the ReferenceBlackWhite
293 * tag) so there is some range shifting to do here when
294 * constructing tables indexed by the raw pixel data.
295 */
296 for (i = 0, x = -128; i < 256; i++, x++)
297 {
298 int32_t Cr = (int32_t)CLAMPw(Code2V(x, refBlackWhite[4] - 128.0F,
299 refBlackWhite[5] - 128.0F, 127),
300 -128.0F * 32, 128.0F * 32);
301 int32_t Cb = (int32_t)CLAMPw(Code2V(x, refBlackWhite[2] - 128.0F,
302 refBlackWhite[3] - 128.0F, 127),
303 -128.0F * 32, 128.0F * 32);
304
305 ycbcr->Cr_r_tab[i] = (int32_t)((D1 * Cr + ONE_HALF) >> SHIFT);
306 ycbcr->Cb_b_tab[i] = (int32_t)((D3 * Cb + ONE_HALF) >> SHIFT);
307 ycbcr->Cr_g_tab[i] = D2 * Cr;
308 ycbcr->Cb_g_tab[i] = D4 * Cb + ONE_HALF;
309 ycbcr->Y_tab[i] = (int32_t)CLAMPw(
310 Code2V(x + 128, refBlackWhite[0], refBlackWhite[1], 255),
311 -128.0F * 32, 128.0F * 32);
312 }
313 }
314
315 return 0;
316}
unsigned char uint8_t
Definition: stdint.h:33
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
#define int32_t
Definition: nsiface.idl:56
#define f2(x, y, z)
Definition: sha1.c:31
#define f1(x, y, z)
Definition: sha1.c:30
#define f4(x, y, z)
Definition: sha1.c:33
#define f3(x, y, z)
Definition: sha1.c:32
TIFFRGBValue * clamptab
Definition: tiffio.h:171
static float CLAMPw(float v, float vmin, float vmax)
Definition: tif_color.c:220
#define LumaRed
#define LumaBlue
#define FIX(x)
Definition: tif_color.c:189
#define Code2V(c, RB, RW, CR)
Definition: tif_color.c:191
#define ONE_HALF
Definition: tif_color.c:190
#define LumaGreen
void _TIFFmemset(void *p, int v, tmsize_t c)
Definition: tif_unix.c:353
unsigned char TIFFRGBValue
Definition: tiffio.h:138
#define TIFFroundup_32(x, y)
Definition: tiffiop.h:316

Referenced by initYCbCrConversion().