} \
}while(0)
-#define TRC_IN_u8(rgba_in, rgba_out) do{ \
- if ((source_space->space.trc[0] == source_space->space.trc[1]) && \
- (source_space->space.trc[1] == source_space->space.trc[2])) \
- { \
- const Babl *trc = (void*)source_space->space.trc[0]; \
- _babl_trc_to_linear_buf_u8_generic(trc, rgba_in, rgba_out, 4, 4, 3, samples); \
- } \
- else \
- { \
- unsigned int c; \
- for (c = 0; c < 3; c ++) \
- { \
- const Babl *trc = (void*)source_space->space.trc[c]; \
- _babl_trc_to_linear_buf_u8_generic (trc, rgba_in + c, rgba_out + c, 4, 4, 1, samples); \
- } \
- } \
-}while(0)
-
#define TRC_OUT(rgba_in, rgba_out) do{\
{ \
if ((destination_space->space.trc[0] == destination_space->space.trc[1]) && \
} while(0)
-#define TRC_OUT_u8(rgba_in, rgba_out) do{\
- { \
- if ((destination_space->space.trc[0] == destination_space->space.trc[1]) && \
- (destination_space->space.trc[1] == destination_space->space.trc[2])) \
- { \
- const Babl *trc = (void*)destination_space->space.trc[0]; \
- _babl_trc_from_linear_buf_u8_generic(trc, rgba_in, rgba_out, 4, 4, 3, samples); \
- } \
- else \
- { \
- unsigned int c; \
- for (c = 0; c < 3; c ++) \
- { \
- const Babl *trc = (void*)destination_space->space.trc[c]; \
- _babl_trc_from_linear_buf_u8_generic(trc, rgba_in + c, rgba_out + c, 4, 4, 1, samples); \
- } \
- } \
- }\
-} while(0)
-
-
-
static inline void
universal_nonlinear_rgba_converter (const Babl *conversion,
unsigned char *__restrict__ src_char,
TRC_OUT(rgba_out, rgba_out);
}
-static inline void
-universal_nonlinear_rgba_u8_converter (const Babl *conversion,
- unsigned char *__restrict__ src_char,
- unsigned char *__restrict__ dst_char,
- long samples,
- void *data)
-{
- const Babl *destination_space = conversion->conversion.destination->format.space;
- const Babl *source_space = babl_conversion_get_source_space (conversion);
- float * matrixf = data;
- uint8_t *rgba_in_u8 = (void*)src_char;
- uint8_t *rgba_out_u8 = (void*)dst_char;
- float rgba[4*samples];
- for (int i = 0; i < samples * 4; i+=4)
- {
- rgba_out_u8[i+3] = rgba_in_u8[i+3];
- }
- TRC_IN_u8(rgba_in_u8, rgba);
- babl_matrix_mul_vectorff_buf4 (matrixf, rgba, rgba, samples);
- TRC_OUT_u8(rgba, rgba_out_u8);
-}
-
-
static inline void
universal_rgba_converter (const Babl *conversion,
unsigned char *__restrict__ src_char,
babl_matrix_mul_vectorff_buf4_sse2 (matrixf, rgba_in, rgba_out, samples);
}
-static inline void
-universal_nonlinear_rgba_u8_converter_sse2 (const Babl *conversion,
- unsigned char *__restrict__ src_char,
- unsigned char *__restrict__ dst_char,
- long samples,
- void *data)
-{
- const Babl *source_space = conversion->conversion.source->format.space;
- const Babl *destination_space = conversion->conversion.destination->format.space;
-
- float * matrixf = data;
- uint8_t *rgba_in_u8 = (void*)src_char;
- uint8_t *rgba_out_u8 = (void*)dst_char;
-
- float rgba[4*samples];
-
- for (int i = 0; i < samples*4; i+=4)
- {
- rgba_out_u8[i+3] = rgba_in_u8[i+3];
- }
- TRC_IN_u8(rgba_in_u8, rgba);
-
- babl_matrix_mul_vectorff_buf4_sse2 (matrixf, rgba, rgba, samples);
-
- TRC_OUT_u8(rgba, rgba_out_u8);
-}
-
static inline void
universal_nonlinear_rgb_u8_converter_sse2 (const Babl *conversion,
unsigned char *__restrict__ src_char,
"linear", universal_linear_rgb_nonlinear_converter_sse2,
NULL));
- prep_conversion(babl_conversion_new(
- babl_format_with_space("R'G'B'A u8", space),
- babl_format_with_space("R'G'B'A u8", babl),
- "linear", universal_nonlinear_rgba_u8_converter_sse2,
- NULL));
- prep_conversion(babl_conversion_new(
- babl_format_with_space("R'G'B'A u8", babl),
- babl_format_with_space("R'G'B'A u8", space),
- "linear", universal_nonlinear_rgba_u8_converter_sse2,
- NULL));
-
prep_conversion(babl_conversion_new(
babl_format_with_space("R'G'B' u8", space),
babl_format_with_space("R'G'B' u8", babl),
NULL));
#endif
- prep_conversion(babl_conversion_new(
- babl_format_with_space("R'G'B'A u8", space),
- babl_format_with_space("R'G'B'A u8", babl),
- "linear", universal_nonlinear_rgba_u8_converter,
- NULL));
- prep_conversion(babl_conversion_new(
- babl_format_with_space("R'G'B'A u8", babl),
- babl_format_with_space("R'G'B'A u8", space),
- "linear", universal_nonlinear_rgba_u8_converter,
- NULL));
#if 1
prep_conversion(babl_conversion_new(
babl_format_with_space("R'G'B' u8", space),
trc_db[i].fun_to_linear_buf = _babl_trc_to_linear_buf_generic;
trc_db[i].fun_from_linear_buf = _babl_trc_from_linear_buf_generic;
- trc_db[i].fun_from_linear_buf_u8 = _babl_trc_from_linear_buf_u8_generic;
- trc_db[i].fun_to_linear_buf_u8 = _babl_trc_to_linear_buf_u8_generic;
switch (trc_db[i].type)
{
trc_db[i].fun_from_linear = _babl_trc_linear;
trc_db[i].fun_from_linear_buf = _babl_trc_linear_buf;
trc_db[i].fun_to_linear_buf = _babl_trc_linear_buf;
- //trc_db[i].fun_to_linear_buf_u8 = _babl_trc_linear_buf_u8;
break;
case BABL_TRC_FORMULA_GAMMA:
trc_db[i].fun_to_linear = _babl_trc_gamma_to_linear;
trc_db[i].fun_from_linear = _babl_trc_gamma_from_linear;
trc_db[i].fun_to_linear_buf = _babl_trc_gamma_to_linear_buf;
trc_db[i].fun_from_linear_buf = _babl_trc_gamma_from_linear_buf;
- //trc_db[i].fun_from_linear_buf_u8 = _babl_trc_gamma_from_linear_buf_u8;
trc_db[i].poly_gamma_to_linear_x0 = POLY_GAMMA_X0;
trc_db[i].poly_gamma_to_linear_x1 = POLY_GAMMA_X1;
trc_db[i].fun_to_linear = _babl_trc_srgb_to_linear;
trc_db[i].fun_from_linear = _babl_trc_srgb_from_linear;
trc_db[i].fun_from_linear_buf = _babl_trc_srgb_from_linear_buf;
- //trc_db[i].fun_from_linear_buf_u8 = _babl_trc_srgb_from_linear_buf_u8;
trc_db[i].fun_to_linear_buf = _babl_trc_srgb_to_linear_buf;
break;
case BABL_TRC_LUT:
int out_gap,
int components,
int count);
- void (*fun_to_linear_buf_u8)(const Babl *trc,
- const uint8_t *in,
- float *out,
- int in_gap,
- int out_gap,
- int components,
- int count);
void (*fun_from_linear_buf)(const Babl *trc,
const float *in,
float *out,
int out_gap,
int components,
int count);
- void (*fun_from_linear_buf_u8)(const Babl *trc,
- const float *in,
- uint8_t *out,
- int in_gap,
- int out_gap,
- int components,
- int count);
BablPolynomial poly_gamma_to_linear;
float poly_gamma_to_linear_x0;
float poly_gamma_to_linear_x1;
trc->fun_from_linear_buf (trc_, in, out, in_gap, out_gap, components, count);
}
-static inline void babl_trc_from_linear_buf_u8 (const Babl *trc_,
- const float *in, uint8_t *out,
- int in_gap, int out_gap,
- int components,
- int count)
-{
- BablTRC *trc = (void*)trc_;
- trc->fun_from_linear_buf_u8 (trc_, in, out, in_gap, out_gap, components, count);
-}
-
-static inline void babl_trc_to_linear_buf_u8 (const Babl *trc_,
- const uint8_t *in, float *out,
- int in_gap, int out_gap,
- int components,
- int count)
-{
- BablTRC *trc = (void*)trc_;
- trc->fun_to_linear_buf_u8 (trc_, in, out, in_gap, out_gap, components, count);
-}
-
static inline void babl_trc_to_linear_buf (const Babl *trc_,
const float *in, float *out,
int in_gap, int out_gap,
babl_trc_class_init_generic (void);
-static inline void
-_babl_trc_from_linear_buf_u8_generic (const Babl *trc_,
- const float *__restrict__ in,
- uint8_t *__restrict__ out,
- int in_gap,
- int out_gap,
- int components,
- int count)
-{
- BablTRC *trc = (void*)trc_;
- if (in_gap == out_gap && in_gap == 4 && components == 3)
- {
- for (int i = 0; i < count; i ++)
- for (int c = 0; c < 3; c ++)
- {
- int val = trc->fun_from_linear (trc_, in[4 * i + c]) * 255.0 + 0.5;
- out[4 * i + c] = val > 255 ? 255 : val;
- }
- }
- else
- {
- for (int i = 0; i < count; i ++)
- for (int c = 0; c < components; c ++)
- {
- int val = trc->fun_from_linear (trc_, in[in_gap * i + c]) * 255.0 + 0.5;
- out[out_gap * i + c] = val > 255 ? 255 : 0;
- }
- }
-}
-
-static inline void
-_babl_trc_to_linear_buf_u8_generic (const Babl *trc_,
- const uint8_t *__restrict__ in,
- float *__restrict__ out,
- int in_gap,
- int out_gap,
- int components,
- int count)
-{
- BablTRC *trc = (void*)trc_;
- if (!trc->valid_u8_lut)
- {
- for (int i = 0; i <= 255; i++)
- trc->u8_lut[i] = trc->fun_to_linear (trc_, i/255.0f);
- trc->valid_u8_lut=1;
- }
- if (in_gap == out_gap && in_gap == 4 && components == 3)
- {
- for (int i = 0; i < count; i ++)
- for (int c = 0; c < 3; c ++)
- out[4 * i + c] = trc->u8_lut[in[4 * i + c]];
- }
- else
- {
- for (int i = 0; i < count; i ++)
- for (int c = 0; c < components; c ++)
- out[out_gap * i + c] = trc->u8_lut[in[in_gap * i + c]];
- }
-}
-
-
#endif