51 float *X,
float *Y,
float *Z)
69 int32_t b,
float *X,
float *Y,
float *Z)
71 float L = (float)l * 100.0f / 65535.0f;
76 *Y = (L * cielab->
Y0) / 903.292f;
77 cby = 7.787f * (*Y / cielab->
Y0) + 16.0f / 116.0f;
81 cby = (L + 16.0f) / 116.0f;
82 *Y = cielab->
Y0 * cby * cby * cby;
85 tmp = (float)a / 256.0f / 500.0f + cby;
87 *X = cielab->
X0 * (tmp - 0.13793f) / 7.787f;
89 *X = cielab->
X0 * tmp * tmp * tmp;
91 tmp = cby - (float)b / 256.0f / 200.0f;
93 *Z = cielab->
Z0 * (tmp - 0.13793f) / 7.787f;
95 *Z = cielab->
Z0 * tmp * tmp * tmp;
108#define RINT(R) ((uint32_t)((R) > 0 ? ((R) + 0.5f) : ((R) - 0.5f)))
113 uint32_t *r, uint32_t *g, uint32_t *b)
120 Yr = matrix[0] * X + matrix[1] * Y + matrix[2] * Z;
121 Yg = matrix[3] * X + matrix[4] * Y + matrix[5] * Z;
122 Yb = matrix[6] * X + matrix[7] * Y + matrix[8] * Z;
176 for (i = 0; i <= (size_t)cielab->
range; i++)
179 ((
float)pow((
double)i / cielab->
range, dfGamma));
186 for (i = 0; i <= (size_t)cielab->
range; i++)
189 ((
float)pow((
double)i / cielab->
range, dfGamma));
196 for (i = 0; i <= (size_t)cielab->
range; i++)
199 ((
float)pow((
double)i / cielab->
range, dfGamma));
203 cielab->
X0 = refWhite[0];
204 cielab->
Y0 = refWhite[1];
205 cielab->
Z0 = refWhite[2];
233#define FIX(x) ((int32_t)((double)(x) * (1L << SHIFT) + 0.5))
241#define ONE_HALF ((int32_t)(1 << (SHIFT - 1)))
258#define Code2V(c, RB, RW, CR) \
259 (((float)((c) - (int32_t)(RB)) * (float)(CR)) / \
260 ((!TIFF_FLOAT_EQ((RW), (RB))) ? ((RW) - (RB)) : 1.0f))
274#define CLAMP(f, min, max) \
275 ((!((f) >= (min))) ? (min) : (f) > (max) ? (max) : (f))
287#define HICLAMP(f, max) ((f) > (max) ? (max) : (f))
290 uint32_t *r, uint32_t *g, uint32_t *b)
296 Cb =
CLAMP(Cb, 0, 255);
297 Cr =
CLAMP(Cr, 0, 255);
300 *r = (uint32_t)
CLAMP(i, 0, 255);
301 i = ycbcr->
Y_tab[Y] +
303 *g = (uint32_t)
CLAMP(i, 0, 255);
305 *b = (uint32_t)
CLAMP(i, 0, 255);
323static float CLAMPw(
float v,
float vmin,
float vmax)
359#define LumaRed luma[0]
360#define LumaGreen luma[1]
361#define LumaBlue luma[2]
366 ycbcr->
clamptab = (clamptab += 256);
367 for (i = 0; i < 256; i++)
370 ycbcr->
Cr_r_tab = (
int *)(clamptab + 3 * 256);
378 int32_t D1 =
FIX(
CLAMP(f1, 0.0f, 2.0f));
380 int32_t D2 = -
FIX(
CLAMP(f2, 0.0f, 2.0f));
382 int32_t D3 =
FIX(
CLAMP(f3, 0.0f, 2.0f));
384 int32_t D4 = -
FIX(
CLAMP(f4, 0.0f, 2.0f));
398 for (i = 0, x = -128; i < 256; i++, x++)
400 int32_t Cr = (int32_t)
CLAMPw(
Code2V(x, refBlackWhite[4] - 128.0f,
401 refBlackWhite[5] - 128.0f, 127),
402 -128.0f * 32, 128.0f * 32);
403 int32_t Cb = (int32_t)
CLAMPw(
Code2V(x, refBlackWhite[2] - 128.0f,
404 refBlackWhite[3] - 128.0f, 127),
405 -128.0f * 32, 128.0f * 32);
412 Code2V(x + 128, refBlackWhite[0], refBlackWhite[1], 255),
413 -128.0f * 32, 128.0f * 32);
void TIFFCIELab16ToXYZ(TIFFCIELabToRGB *cielab, uint32_t l, int32_t a, int32_t b, float *X, float *Y, float *Z)
Convert 16-bit TIFF CIE L*a*b* samples to XYZ.
static float CLAMPw(float v, float vmin, float vmax)
Clamp a finite coefficient to an inclusive interval.
#define LumaRed
Read the red coefficient from the local luma array.
#define LumaBlue
Read the blue coefficient from the local luma array.
#define FIX(x)
Convert a bounded coefficient to fixed-point form.
#define RINT(R)
Round a nonnegative table value to an unsigned channel.
#define Code2V(c, RB, RW, CR)
Scale a code between reference black and white endpoints.
#define CLAMP(f, min, max)
Clamp a value and map NaN to the lower bound.
#define ONE_HALF
Represent a half-unit rounding bias in fixed-point form.
#define SHIFT
Select sixteen fractional bits for YCbCr contributions.
#define LumaGreen
Read the green coefficient from the local luma array.
#define HICLAMP(f, max)
Apply only an upper bound.
#define TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW
Suppress unsigned-overflow instrumentation on supported Clang functions.
#define TIFFroundup_32(x, y)
Round a 32-bit value up to a multiple using the guarded quotient.
#define TIFFmax(A, B)
Select the first operand if it is greater, otherwise the second.
#define TIFFmin(A, B)
Select the first operand if it is smaller, otherwise the second.
TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW void TIFFCIELabToXYZ(TIFFCIELabToRGB *cielab, uint32_t l, int32_t a, int32_t b, float *X, float *Y, float *Z)
Convert 8-bit TIFF CIE L*a*b* samples to XYZ.
void TIFFYCbCrtoRGB(TIFFYCbCrToRGB *ycbcr, uint32_t Y, int32_t Cb, int32_t Cr, uint32_t *r, uint32_t *g, uint32_t *b)
Convert an 8-bit YCbCr sample triplet to clipped RGB.
int TIFFYCbCrToRGBInit(TIFFYCbCrToRGB *ycbcr, float *luma, float *refBlackWhite)
Initialise caller-allocated 8-bit YCbCr conversion tables.
int TIFFCIELabToRGBInit(TIFFCIELabToRGB *cielab, const TIFFDisplay *display, float *refWhite)
Initialise caller-owned CIE Lab conversion tables and reference white.
void TIFFXYZToRGB(TIFFCIELabToRGB *cielab, float X, float Y, float Z, uint32_t *r, uint32_t *g, uint32_t *b)
Convert XYZ tristimulus values to display RGB channels.
unsigned char TIFFRGBValue
Represent an 8-bit RGB channel value.
#define CIELABTORGB_TABLE_RANGE
Define the largest CIE L*a*b*-to-RGB lookup-table index.
void _TIFFmemset(void *p, int v, tmsize_t c)
Fill a byte range with one repeated byte.
void _TIFFmemcpy(void *d, const void *s, tmsize_t c)
Copy a non-overlapping byte range.
Hold CIE L*a*b*-to-RGB conversion parameters and tables.
int range
Largest table index; initialised to CIELABTORGB_TABLE_RANGE.
float Yb2b[CIELABTORGB_TABLE_RANGE+1]
Blue luminance-to-code table, including both endpoints.
float bstep
Blue luminance increment per lookup-table interval. Currently initialised from the red-channel d_YCR/...
float X0
Reference-white X coordinate.
float Z0
Reference-white Z coordinate.
TIFFDisplay display
Inline copy of the display description.
float rstep
Red luminance increment per lookup-table interval.
float gstep
Green luminance increment per lookup-table interval. Currently initialised from the red-channel d_YCR...
float Yr2r[CIELABTORGB_TABLE_RANGE+1]
Red luminance-to-code table, including both endpoints.
float Yg2g[CIELABTORGB_TABLE_RANGE+1]
Green luminance-to-code table, including both endpoints.
float Y0
Reference-white Y coordinate.
Describe the matrix, luminance, and gamma of an RGB display.
float d_mat[3][3]
3 by 3 matrix mapping XYZ to red, green, and blue luminance.
float d_gammaG
Green-channel gamma.
float d_YCB
Blue-channel reference-white luminance.
uint32_t d_Vrwr
Red-channel code value at reference white.
float d_Y0R
Red-channel residual luminance at black.
float d_gammaR
Red-channel gamma.
float d_YCG
Green-channel reference-white luminance.
float d_YCR
Red-channel reference-white luminance.
float d_Y0G
Green-channel residual luminance at black.
float d_Y0B
Blue-channel residual luminance at black.
uint32_t d_Vrwg
Green-channel code value at reference white.
float d_gammaB
Blue-channel gamma.
uint32_t d_Vrwb
Blue-channel code value at reference white.
Hold lookup-table pointers for 8-bit YCbCr-to-RGB conversion.
int * Cr_r_tab
256-entry table of Cr contributions to red.
int32_t * Cb_g_tab
256-entry fixed-point table of Cb contributions to green.
int32_t * Y_tab
256-entry table of scaled luminance contributions.
TIFFRGBValue * clamptab
Biased table pointer for clamping channel results to 0 through 255.
int * Cb_b_tab
256-entry table of Cb contributions to blue.
int32_t * Cr_g_tab
256-entry fixed-point table of Cr contributions to green.
Declare private library state, callbacks, and implementation helpers.