2011-07-27 07:11:19 -07:00
|
|
|
/* vim: set ts=8 sw=8 noexpandtab: */
|
2009-04-07 09:02:11 -07:00
|
|
|
#include "qcms.h"
|
|
|
|
#include "qcmstypes.h"
|
|
|
|
|
2010-06-04 11:48:30 -07:00
|
|
|
/* used as a lookup table for the output transformation.
|
2009-04-07 09:02:11 -07:00
|
|
|
* we refcount them so we only need to have one around per output
|
|
|
|
* profile, instead of duplicating them per transform */
|
|
|
|
struct precache_output
|
|
|
|
{
|
|
|
|
int ref_count;
|
2010-06-04 11:48:30 -07:00
|
|
|
/* We previously used a count of 65536 here but that seems like more
|
|
|
|
* precision than we actually need. By reducing the size we can
|
|
|
|
* improve startup performance and reduce memory usage. ColorSync on
|
|
|
|
* 10.5 uses 4097 which is perhaps because they use a fixed point
|
|
|
|
* representation where 1. is represented by 0x1000. */
|
|
|
|
#define PRECACHE_OUTPUT_SIZE 8192
|
|
|
|
#define PRECACHE_OUTPUT_MAX (PRECACHE_OUTPUT_SIZE-1)
|
|
|
|
uint8_t data[PRECACHE_OUTPUT_SIZE];
|
2009-04-07 09:02:11 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#define ALIGN __declspec(align(16))
|
|
|
|
#else
|
|
|
|
#define ALIGN __attribute__(( aligned (16) ))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct _qcms_transform {
|
|
|
|
float ALIGN matrix[3][4];
|
|
|
|
float *input_gamma_table_r;
|
|
|
|
float *input_gamma_table_g;
|
|
|
|
float *input_gamma_table_b;
|
|
|
|
|
2011-07-27 07:11:19 -07:00
|
|
|
float *input_clut_table_r;
|
|
|
|
float *input_clut_table_g;
|
|
|
|
float *input_clut_table_b;
|
|
|
|
uint16_t input_clut_table_length;
|
|
|
|
float *r_clut;
|
|
|
|
float *g_clut;
|
|
|
|
float *b_clut;
|
|
|
|
uint16_t grid_size;
|
|
|
|
float *output_clut_table_r;
|
|
|
|
float *output_clut_table_g;
|
|
|
|
float *output_clut_table_b;
|
|
|
|
uint16_t output_clut_table_length;
|
|
|
|
|
2009-04-07 09:02:11 -07:00
|
|
|
float *input_gamma_table_gray;
|
|
|
|
|
|
|
|
float out_gamma_r;
|
|
|
|
float out_gamma_g;
|
|
|
|
float out_gamma_b;
|
|
|
|
|
|
|
|
float out_gamma_gray;
|
|
|
|
|
|
|
|
uint16_t *output_gamma_lut_r;
|
|
|
|
uint16_t *output_gamma_lut_g;
|
|
|
|
uint16_t *output_gamma_lut_b;
|
|
|
|
|
|
|
|
uint16_t *output_gamma_lut_gray;
|
|
|
|
|
|
|
|
size_t output_gamma_lut_r_length;
|
|
|
|
size_t output_gamma_lut_g_length;
|
|
|
|
size_t output_gamma_lut_b_length;
|
|
|
|
|
|
|
|
size_t output_gamma_lut_gray_length;
|
|
|
|
|
|
|
|
struct precache_output *output_table_r;
|
|
|
|
struct precache_output *output_table_g;
|
|
|
|
struct precache_output *output_table_b;
|
|
|
|
|
|
|
|
void (*transform_fn)(struct _qcms_transform *transform, unsigned char *src, unsigned char *dest, size_t length);
|
|
|
|
};
|
|
|
|
|
2011-07-27 07:11:19 -07:00
|
|
|
struct matrix {
|
|
|
|
float m[3][3];
|
|
|
|
bool invalid;
|
|
|
|
};
|
2011-08-05 06:49:45 -07:00
|
|
|
|
|
|
|
struct qcms_modular_transform;
|
|
|
|
|
|
|
|
typedef void (*transform_module_fn_t)(struct qcms_modular_transform *transform, float *src, float *dest, size_t length);
|
|
|
|
|
2011-07-27 07:11:19 -07:00
|
|
|
struct qcms_modular_transform {
|
|
|
|
struct matrix matrix;
|
|
|
|
float tx, ty, tz;
|
|
|
|
|
|
|
|
float *input_clut_table_r;
|
|
|
|
float *input_clut_table_g;
|
|
|
|
float *input_clut_table_b;
|
|
|
|
uint16_t input_clut_table_length;
|
|
|
|
float *r_clut;
|
|
|
|
float *g_clut;
|
|
|
|
float *b_clut;
|
|
|
|
uint16_t grid_size;
|
|
|
|
float *output_clut_table_r;
|
|
|
|
float *output_clut_table_g;
|
|
|
|
float *output_clut_table_b;
|
|
|
|
uint16_t output_clut_table_length;
|
|
|
|
|
|
|
|
uint16_t *output_gamma_lut_r;
|
|
|
|
uint16_t *output_gamma_lut_g;
|
|
|
|
uint16_t *output_gamma_lut_b;
|
|
|
|
|
|
|
|
size_t output_gamma_lut_r_length;
|
|
|
|
size_t output_gamma_lut_g_length;
|
|
|
|
size_t output_gamma_lut_b_length;
|
|
|
|
|
2011-08-05 06:49:45 -07:00
|
|
|
transform_module_fn_t transform_module_fn;
|
2011-07-27 07:11:19 -07:00
|
|
|
struct qcms_modular_transform *next_transform;
|
|
|
|
};
|
|
|
|
|
2009-04-07 09:02:11 -07:00
|
|
|
typedef int32_t s15Fixed16Number;
|
|
|
|
typedef uint16_t uInt16Number;
|
2011-07-27 07:11:19 -07:00
|
|
|
typedef uint8_t uInt8Number;
|
2009-04-07 09:02:11 -07:00
|
|
|
|
|
|
|
struct XYZNumber {
|
|
|
|
s15Fixed16Number X;
|
|
|
|
s15Fixed16Number Y;
|
|
|
|
s15Fixed16Number Z;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct curveType {
|
2011-07-27 07:11:19 -07:00
|
|
|
uint32_t type;
|
2009-04-07 09:02:11 -07:00
|
|
|
uint32_t count;
|
2011-07-27 07:11:19 -07:00
|
|
|
float parameter[7];
|
2010-01-20 02:21:19 -08:00
|
|
|
uInt16Number data[];
|
2009-04-07 09:02:11 -07:00
|
|
|
};
|
|
|
|
|
2011-07-27 07:11:19 -07:00
|
|
|
struct lutmABType {
|
|
|
|
uint8_t num_in_channels;
|
|
|
|
uint8_t num_out_channels;
|
|
|
|
// 16 is the upperbound, actual is 0..num_in_channels.
|
|
|
|
uint8_t num_grid_points[16];
|
|
|
|
|
|
|
|
s15Fixed16Number e00;
|
|
|
|
s15Fixed16Number e01;
|
|
|
|
s15Fixed16Number e02;
|
|
|
|
s15Fixed16Number e03;
|
|
|
|
s15Fixed16Number e10;
|
|
|
|
s15Fixed16Number e11;
|
|
|
|
s15Fixed16Number e12;
|
|
|
|
s15Fixed16Number e13;
|
|
|
|
s15Fixed16Number e20;
|
|
|
|
s15Fixed16Number e21;
|
|
|
|
s15Fixed16Number e22;
|
|
|
|
s15Fixed16Number e23;
|
|
|
|
|
|
|
|
// reversed elements (for mBA)
|
|
|
|
bool reversed;
|
|
|
|
|
|
|
|
float *clut_table;
|
|
|
|
struct curveType *a_curves[10];
|
|
|
|
struct curveType *b_curves[10];
|
|
|
|
struct curveType *m_curves[10];
|
|
|
|
float clut_table_data[];
|
|
|
|
};
|
|
|
|
|
|
|
|
/* should lut8Type and lut16Type be different types? */
|
|
|
|
struct lutType { // used by lut8Type/lut16Type (mft2) only
|
2009-04-07 09:02:11 -07:00
|
|
|
uint8_t num_input_channels;
|
|
|
|
uint8_t num_output_channels;
|
|
|
|
uint8_t num_clut_grid_points;
|
|
|
|
|
|
|
|
s15Fixed16Number e00;
|
|
|
|
s15Fixed16Number e01;
|
|
|
|
s15Fixed16Number e02;
|
|
|
|
s15Fixed16Number e10;
|
|
|
|
s15Fixed16Number e11;
|
|
|
|
s15Fixed16Number e12;
|
|
|
|
s15Fixed16Number e20;
|
|
|
|
s15Fixed16Number e21;
|
|
|
|
s15Fixed16Number e22;
|
|
|
|
|
|
|
|
uint16_t num_input_table_entries;
|
|
|
|
uint16_t num_output_table_entries;
|
|
|
|
|
2011-07-27 07:11:19 -07:00
|
|
|
float *input_table;
|
|
|
|
float *clut_table;
|
|
|
|
float *output_table;
|
|
|
|
|
|
|
|
float table_data[];
|
2009-04-07 09:02:11 -07:00
|
|
|
};
|
|
|
|
#if 0
|
2009-04-23 10:38:11 -07:00
|
|
|
/* this is from an intial idea of having the struct correspond to the data in
|
|
|
|
* the file. I decided that it wasn't a good idea.
|
|
|
|
*/
|
2009-04-07 09:02:11 -07:00
|
|
|
struct tag_value {
|
|
|
|
uint32_t type;
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
uint32_t reserved;
|
|
|
|
struct {
|
|
|
|
s15Fixed16Number X;
|
|
|
|
s15Fixed16Number Y;
|
|
|
|
s15Fixed16Number Z;
|
|
|
|
} XYZNumber;
|
|
|
|
} XYZType;
|
|
|
|
};
|
2011-05-10 08:55:39 -07:00
|
|
|
}; // I guess we need to pack this?
|
2009-04-07 09:02:11 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define RGB_SIGNATURE 0x52474220
|
|
|
|
#define GRAY_SIGNATURE 0x47524159
|
2011-07-27 07:11:19 -07:00
|
|
|
#define XYZ_SIGNATURE 0x58595A20
|
|
|
|
#define LAB_SIGNATURE 0x4C616220
|
2009-04-07 09:02:11 -07:00
|
|
|
|
|
|
|
struct _qcms_profile {
|
|
|
|
uint32_t class;
|
|
|
|
uint32_t color_space;
|
2011-07-27 07:11:19 -07:00
|
|
|
uint32_t pcs;
|
2009-04-07 09:02:11 -07:00
|
|
|
qcms_intent rendering_intent;
|
|
|
|
struct XYZNumber redColorant;
|
|
|
|
struct XYZNumber blueColorant;
|
|
|
|
struct XYZNumber greenColorant;
|
|
|
|
struct curveType *redTRC;
|
|
|
|
struct curveType *blueTRC;
|
|
|
|
struct curveType *greenTRC;
|
|
|
|
struct curveType *grayTRC;
|
|
|
|
struct lutType *A2B0;
|
2011-07-27 07:11:19 -07:00
|
|
|
struct lutType *B2A0;
|
|
|
|
struct lutmABType *mAB;
|
|
|
|
struct lutmABType *mBA;
|
|
|
|
struct matrix chromaticAdaption;
|
2009-04-07 09:02:11 -07:00
|
|
|
|
|
|
|
struct precache_output *output_table_r;
|
|
|
|
struct precache_output *output_table_g;
|
|
|
|
struct precache_output *output_table_b;
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#define inline _inline
|
|
|
|
#endif
|
|
|
|
|
2011-07-27 07:11:19 -07:00
|
|
|
/* produces the nearest float to 'a' with a maximum error
|
|
|
|
* of 1/1024 which happens for large values like 0x40000040 */
|
2009-04-07 09:02:11 -07:00
|
|
|
static inline float s15Fixed16Number_to_float(s15Fixed16Number a)
|
|
|
|
{
|
2011-04-07 16:59:12 -07:00
|
|
|
return ((int32_t)a)/65536.f;
|
2009-04-07 09:02:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline s15Fixed16Number double_to_s15Fixed16Number(double v)
|
|
|
|
{
|
|
|
|
return (int32_t)(v*65536);
|
|
|
|
}
|
|
|
|
|
2011-07-27 07:11:19 -07:00
|
|
|
static inline float uInt8Number_to_float(uInt8Number a)
|
|
|
|
{
|
|
|
|
return ((int32_t)a)/255.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline float uInt16Number_to_float(uInt16Number a)
|
|
|
|
{
|
|
|
|
return ((int32_t)a)/65535.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-07 09:02:11 -07:00
|
|
|
void precache_release(struct precache_output *p);
|
2009-04-21 19:21:48 -07:00
|
|
|
qcms_bool set_rgb_colorants(qcms_profile *profile, qcms_CIE_xyY white_point, qcms_CIE_xyYTRIPLE primaries);
|
2009-10-01 11:19:41 -07:00
|
|
|
|
|
|
|
void qcms_transform_data_rgb_out_lut_sse2(qcms_transform *transform,
|
|
|
|
unsigned char *src,
|
|
|
|
unsigned char *dest,
|
|
|
|
size_t length);
|
|
|
|
void qcms_transform_data_rgba_out_lut_sse2(qcms_transform *transform,
|
|
|
|
unsigned char *src,
|
|
|
|
unsigned char *dest,
|
|
|
|
size_t length);
|
|
|
|
void qcms_transform_data_rgb_out_lut_sse1(qcms_transform *transform,
|
|
|
|
unsigned char *src,
|
|
|
|
unsigned char *dest,
|
|
|
|
size_t length);
|
|
|
|
void qcms_transform_data_rgba_out_lut_sse1(qcms_transform *transform,
|
|
|
|
unsigned char *src,
|
|
|
|
unsigned char *dest,
|
|
|
|
size_t length);
|
2011-07-27 07:11:19 -07:00
|
|
|
|
2013-01-15 16:44:43 -08:00
|
|
|
void qcms_transform_data_rgb_out_lut_altivec(qcms_transform *transform,
|
|
|
|
unsigned char *src,
|
|
|
|
unsigned char *dest,
|
|
|
|
size_t length);
|
|
|
|
void qcms_transform_data_rgba_out_lut_altivec(qcms_transform *transform,
|
|
|
|
unsigned char *src,
|
|
|
|
unsigned char *dest,
|
|
|
|
size_t length);
|
|
|
|
|
2011-07-27 07:11:19 -07:00
|
|
|
extern qcms_bool qcms_supports_iccv4;
|
2012-10-03 16:04:25 -07:00
|
|
|
|
2013-03-21 20:09:37 -07:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
|
|
|
|
long __cdecl _InterlockedIncrement(long volatile *);
|
|
|
|
long __cdecl _InterlockedDecrement(long volatile *);
|
|
|
|
#pragma intrinsic(_InterlockedIncrement)
|
|
|
|
#pragma intrinsic(_InterlockedDecrement)
|
|
|
|
|
|
|
|
#define qcms_atomic_increment(x) _InterlockedIncrement((long volatile *)&x)
|
|
|
|
#define qcms_atomic_decrement(x) _InterlockedDecrement((long volatile*)&x)
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define qcms_atomic_increment(x) __sync_add_and_fetch(&x, 1)
|
|
|
|
#define qcms_atomic_decrement(x) __sync_sub_and_fetch(&x, 1)
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2012-10-03 16:04:25 -07:00
|
|
|
#ifdef NATIVE_OUTPUT
|
|
|
|
# define RGB_OUTPUT_COMPONENTS 4
|
|
|
|
# define RGBA_OUTPUT_COMPONENTS 4
|
|
|
|
# ifdef IS_LITTLE_ENDIAN
|
2012-10-14 21:34:52 -07:00
|
|
|
# define OUTPUT_A_INDEX 3
|
|
|
|
# define OUTPUT_R_INDEX 2
|
|
|
|
# define OUTPUT_G_INDEX 1
|
|
|
|
# define OUTPUT_B_INDEX 0
|
2012-10-03 16:04:25 -07:00
|
|
|
# else
|
2012-10-14 21:34:52 -07:00
|
|
|
# define OUTPUT_A_INDEX 0
|
|
|
|
# define OUTPUT_R_INDEX 1
|
|
|
|
# define OUTPUT_G_INDEX 2
|
|
|
|
# define OUTPUT_B_INDEX 3
|
2012-10-03 16:04:25 -07:00
|
|
|
# endif
|
|
|
|
#else
|
|
|
|
# define RGB_OUTPUT_COMPONENTS 3
|
|
|
|
# define RGBA_OUTPUT_COMPONENTS 4
|
|
|
|
# define OUTPUT_R_INDEX 0
|
|
|
|
# define OUTPUT_G_INDEX 1
|
|
|
|
# define OUTPUT_B_INDEX 2
|
|
|
|
# define OUTPUT_A_INDEX 3
|
|
|
|
#endif
|