Commit 8ca4c955 authored by estade@chromium.org's avatar estade@chromium.org

Add BGRA output format support to qcms

Define QCMS_OUTPUT_BGRX and add qcms_transform_data_type() api to output
BGR or BGRA format for GRAY, GRAYA, RGB, and RGBA input data.

Update all color transform functions with an output format argument, use
that to select RGBX (the default) or BGRX output format.

Add google.patch: patch of the BGRA output changes against upstream qcms
and add README.chromium details about google.patch. TODO: send the patch
to qcms if accepted for review upstream.

Disable Visual Studio warnings when needed.

BUG=143
TEST=None
AUTHOR=noel@chromium.org
original review = http://codereview.chromium.org/10387099/

Review URL: https://chromiumcodereview.appspot.com/10407113

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@138414 0039d316-1c4b-4281-b951-d872f2087c98
parent d5a4dd65
......@@ -12,4 +12,8 @@ originally based on tinycms, re-written by Mozilla for better security and
performance. This copy is a source-drop from Mozilla on March 13, 2012.
Local Modifications:
Some files only have license headers in the master branch. Added the same license headers to the versions brought down from the 'v4' branch.
Some files only have license headers in the master branch.
- Added the same license headers to the versions brought down from the 'v4'
branch src URL qcms/tree/v4
google.patch
- Add bgra output support. Apply with patch -p1 < google.patch
This diff is collapsed.
......@@ -297,6 +297,11 @@ qcms_bool qcms_profile_is_bogus(qcms_profile *profile)
sum[1] = rY + gY + bY;
sum[2] = rZ + gZ + bZ;
#if defined (_MSC_VER)
#pragma warning(push)
/* Disable double to float truncation warning 4305 */
#pragma warning(disable:4305)
#endif
// Build our target vector (see mozilla bug 460629)
target[0] = 0.96420;
target[1] = 1.00000;
......@@ -310,6 +315,10 @@ qcms_bool qcms_profile_is_bogus(qcms_profile *profile)
tolerance[1] = 0.02;
tolerance[2] = 0.04;
#if defined (_MSC_VER)
/* Restore warnings */
#pragma warning(pop)
#endif
// Compare with our tolerance
for (i = 0; i < 3; ++i) {
if (!(((sum[i] - tolerance[i]) <= target[i]) &&
......
......@@ -102,6 +102,12 @@ typedef enum {
QCMS_DATA_GRAYA_8
} qcms_data_type;
/* Format of the output data for qcms_transform_data_type() */
typedef enum {
QCMS_OUTPUT_RGBX,
QCMS_OUTPUT_BGRX
} qcms_output_type;
/* the names for the following two types are sort of ugly */
typedef struct
{
......@@ -146,6 +152,7 @@ qcms_transform* qcms_transform_create(
void qcms_transform_release(qcms_transform *);
void qcms_transform_data(qcms_transform *transform, void *src, void *dest, size_t length);
void qcms_transform_data_type(qcms_transform *transform, void *src, void *dest, size_t length, qcms_output_type type);
void qcms_enable_iccv4();
......
......@@ -45,6 +45,11 @@ struct precache_output
#define ALIGN __attribute__(( aligned (16) ))
#endif
typedef struct _qcms_format_type {
int r;
int b;
} qcms_format_type;
struct _qcms_transform {
float ALIGN matrix[3][4];
float *input_gamma_table_r;
......@@ -88,7 +93,7 @@ struct _qcms_transform {
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);
void (*transform_fn)(struct _qcms_transform *transform, unsigned char *src, unsigned char *dest, size_t length, struct _qcms_format_type output_format);
};
struct matrix {
......@@ -280,18 +285,22 @@ qcms_bool set_rgb_colorants(qcms_profile *profile, qcms_CIE_xyY white_point, qcm
void qcms_transform_data_rgb_out_lut_sse2(qcms_transform *transform,
unsigned char *src,
unsigned char *dest,
size_t length);
size_t length,
qcms_format_type output_format);
void qcms_transform_data_rgba_out_lut_sse2(qcms_transform *transform,
unsigned char *src,
unsigned char *dest,
size_t length);
size_t length,
qcms_format_type output_format);
void qcms_transform_data_rgb_out_lut_sse1(qcms_transform *transform,
unsigned char *src,
unsigned char *dest,
size_t length);
size_t length,
qcms_format_type output_format);
void qcms_transform_data_rgba_out_lut_sse1(qcms_transform *transform,
unsigned char *src,
unsigned char *dest,
size_t length);
size_t length,
qcms_format_type output_format);
extern qcms_bool qcms_supports_iccv4;
......@@ -87,7 +87,12 @@ typedef unsigned __int64 uint64_t;
#ifdef _WIN64
typedef unsigned __int64 uintptr_t;
#else
#pragma warning(push)
/* Disable benign redefinition of type warning 4142 */
#pragma warning(disable:4142)
typedef unsigned long uintptr_t;
/* Restore warnings */
#pragma warning(pop)
#endif
#elif defined (_AIX)
......
......@@ -34,7 +34,8 @@ static const ALIGN float clampMaxValueX4[4] =
void qcms_transform_data_rgb_out_lut_sse1(qcms_transform *transform,
unsigned char *src,
unsigned char *dest,
size_t length)
size_t length,
qcms_format_type output_format)
{
unsigned int i;
float (*mat)[4] = transform->matrix;
......@@ -70,6 +71,8 @@ void qcms_transform_data_rgb_out_lut_sse1(qcms_transform *transform,
/* working variables */
__m128 vec_r, vec_g, vec_b, result;
const int r_out = output_format.r;
const int b_out = output_format.b;
/* CYA */
if (!length)
......@@ -116,9 +119,9 @@ void qcms_transform_data_rgb_out_lut_sse1(qcms_transform *transform,
src += 3;
/* use calc'd indices to output RGB values */
dest[0] = otdata_r[output[0]];
dest[1] = otdata_g[output[1]];
dest[2] = otdata_b[output[2]];
dest[r_out] = otdata_r[output[0]];
dest[1] = otdata_g[output[1]];
dest[b_out] = otdata_b[output[2]];
dest += 3;
}
......@@ -141,9 +144,9 @@ void qcms_transform_data_rgb_out_lut_sse1(qcms_transform *transform,
result = _mm_movehl_ps(result, result);
*((__m64 *)&output[2]) = _mm_cvtps_pi32(result);
dest[0] = otdata_r[output[0]];
dest[1] = otdata_g[output[1]];
dest[2] = otdata_b[output[2]];
dest[r_out] = otdata_r[output[0]];
dest[1] = otdata_g[output[1]];
dest[b_out] = otdata_b[output[2]];
_mm_empty();
}
......@@ -151,7 +154,8 @@ void qcms_transform_data_rgb_out_lut_sse1(qcms_transform *transform,
void qcms_transform_data_rgba_out_lut_sse1(qcms_transform *transform,
unsigned char *src,
unsigned char *dest,
size_t length)
size_t length,
qcms_format_type output_format)
{
unsigned int i;
float (*mat)[4] = transform->matrix;
......@@ -187,6 +191,8 @@ void qcms_transform_data_rgba_out_lut_sse1(qcms_transform *transform,
/* working variables */
__m128 vec_r, vec_g, vec_b, result;
const int r_out = output_format.r;
const int b_out = output_format.b;
unsigned char alpha;
/* CYA */
......@@ -239,9 +245,9 @@ void qcms_transform_data_rgba_out_lut_sse1(qcms_transform *transform,
src += 4;
/* use calc'd indices to output RGB values */
dest[0] = otdata_r[output[0]];
dest[1] = otdata_g[output[1]];
dest[2] = otdata_b[output[2]];
dest[r_out] = otdata_r[output[0]];
dest[1] = otdata_g[output[1]];
dest[b_out] = otdata_b[output[2]];
dest += 4;
}
......@@ -266,9 +272,9 @@ void qcms_transform_data_rgba_out_lut_sse1(qcms_transform *transform,
result = _mm_movehl_ps(result, result);
*((__m64 *)&output[2]) = _mm_cvtps_pi32(result);
dest[0] = otdata_r[output[0]];
dest[1] = otdata_g[output[1]];
dest[2] = otdata_b[output[2]];
dest[r_out] = otdata_r[output[0]];
dest[1] = otdata_g[output[1]];
dest[b_out] = otdata_b[output[2]];
_mm_empty();
}
......@@ -34,7 +34,8 @@ static const ALIGN float clampMaxValueX4[4] =
void qcms_transform_data_rgb_out_lut_sse2(qcms_transform *transform,
unsigned char *src,
unsigned char *dest,
size_t length)
size_t length,
qcms_format_type output_format)
{
unsigned int i;
float (*mat)[4] = transform->matrix;
......@@ -70,6 +71,8 @@ void qcms_transform_data_rgb_out_lut_sse2(qcms_transform *transform,
/* working variables */
__m128 vec_r, vec_g, vec_b, result;
const int r_out = output_format.r;
const int b_out = output_format.b;
/* CYA */
if (!length)
......@@ -114,9 +117,9 @@ void qcms_transform_data_rgb_out_lut_sse2(qcms_transform *transform,
src += 3;
/* use calc'd indices to output RGB values */
dest[0] = otdata_r[output[0]];
dest[1] = otdata_g[output[1]];
dest[2] = otdata_b[output[2]];
dest[r_out] = otdata_r[output[0]];
dest[1] = otdata_g[output[1]];
dest[b_out] = otdata_b[output[2]];
dest += 3;
}
......@@ -137,15 +140,16 @@ void qcms_transform_data_rgb_out_lut_sse2(qcms_transform *transform,
_mm_store_si128((__m128i*)output, _mm_cvtps_epi32(result));
dest[0] = otdata_r[output[0]];
dest[1] = otdata_g[output[1]];
dest[2] = otdata_b[output[2]];
dest[r_out] = otdata_r[output[0]];
dest[1] = otdata_g[output[1]];
dest[b_out] = otdata_b[output[2]];
}
void qcms_transform_data_rgba_out_lut_sse2(qcms_transform *transform,
unsigned char *src,
unsigned char *dest,
size_t length)
size_t length,
qcms_format_type output_format)
{
unsigned int i;
float (*mat)[4] = transform->matrix;
......@@ -181,6 +185,8 @@ void qcms_transform_data_rgba_out_lut_sse2(qcms_transform *transform,
/* working variables */
__m128 vec_r, vec_g, vec_b, result;
const int r_out = output_format.r;
const int b_out = output_format.b;
unsigned char alpha;
/* CYA */
......@@ -231,9 +237,9 @@ void qcms_transform_data_rgba_out_lut_sse2(qcms_transform *transform,
src += 4;
/* use calc'd indices to output RGB values */
dest[0] = otdata_r[output[0]];
dest[1] = otdata_g[output[1]];
dest[2] = otdata_b[output[2]];
dest[r_out] = otdata_r[output[0]];
dest[1] = otdata_g[output[1]];
dest[b_out] = otdata_b[output[2]];
dest += 4;
}
......@@ -256,7 +262,7 @@ void qcms_transform_data_rgba_out_lut_sse2(qcms_transform *transform,
_mm_store_si128((__m128i*)output, _mm_cvtps_epi32(result));
dest[0] = otdata_r[output[0]];
dest[1] = otdata_g[output[1]];
dest[2] = otdata_b[output[2]];
dest[r_out] = otdata_r[output[0]];
dest[1] = otdata_g[output[1]];
dest[b_out] = otdata_b[output[2]];
}
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment