Bug 1551084 - Part 1. Minor reworking of QCMS to allow C files to compile as C++. r=miko

Differential Revision: https://phabricator.services.mozilla.com/D30818
This commit is contained in:
Andrew Osmond 2019-05-09 14:29:07 -04:00
parent 042a189a68
commit 244d1f67b8
11 changed files with 75 additions and 39 deletions

View File

@ -24,7 +24,15 @@
#ifndef _QCMS_CHAIN_H
#define _QCMS_CHAIN_H
#ifdef __cplusplus
extern "C" {
#endif
// Generates and returns a 3D LUT with lutSize^3 samples using the provided src/dest.
float* qcms_chain_transform(qcms_profile *in, qcms_profile *out, float *src, float *dest, size_t lutSize);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -77,7 +77,7 @@ struct mem_source
{
const unsigned char *buf;
size_t size;
qcms_bool valid;
bool valid;
const char *invalid_reason;
};
@ -195,8 +195,8 @@ static void check_profile_version(struct mem_source *src)
static void read_class_signature(qcms_profile *profile, struct mem_source *mem)
{
profile->class = read_u32(mem, 12);
switch (profile->class) {
profile->class_type = read_u32(mem, 12);
switch (profile->class_type) {
case DISPLAY_DEVICE_PROFILE:
case INPUT_DEVICE_PROFILE:
case OUTPUT_DEVICE_PROFILE:
@ -269,7 +269,7 @@ static struct tag_index read_tag_table(qcms_profile *profile, struct mem_source
// Checks a profile for obvious inconsistencies and returns
// true if the profile looks bogus and should probably be
// ignored.
qcms_bool qcms_profile_is_bogus(qcms_profile *profile)
bool qcms_profile_is_bogus(qcms_profile *profile)
{
float sum[3], target[3], tolerance[3];
float rX, rY, rZ, gX, gY, gZ, bX, bY, bZ;
@ -926,7 +926,7 @@ qcms_profile* qcms_profile_create_rgb_with_gamma(
qcms_profile_release(profile);
return NO_MEM_PROFILE;
}
profile->class = DISPLAY_DEVICE_PROFILE;
profile->class_type = DISPLAY_DEVICE_PROFILE;
profile->rendering_intent = QCMS_INTENT_PERCEPTUAL;
profile->color_space = RGB_SIGNATURE;
profile->pcs = XYZ_SIGNATURE;
@ -956,7 +956,7 @@ qcms_profile* qcms_profile_create_rgb_with_table(
qcms_profile_release(profile);
return NO_MEM_PROFILE;
}
profile->class = DISPLAY_DEVICE_PROFILE;
profile->class_type = DISPLAY_DEVICE_PROFILE;
profile->rendering_intent = QCMS_INTENT_PERCEPTUAL;
profile->color_space = RGB_SIGNATURE;
profile->pcs = XYZ_SIGNATURE;
@ -1094,8 +1094,8 @@ qcms_profile* qcms_profile_from_memory(const void *mem, size_t size)
profile->chromaticAdaption.invalid = true; //Signal the data is not present
}
if (profile->class == DISPLAY_DEVICE_PROFILE || profile->class == INPUT_DEVICE_PROFILE ||
profile->class == OUTPUT_DEVICE_PROFILE || profile->class == COLOR_SPACE_PROFILE) {
if (profile->class_type == DISPLAY_DEVICE_PROFILE || profile->class_type == INPUT_DEVICE_PROFILE ||
profile->class_type == OUTPUT_DEVICE_PROFILE || profile->class_type == COLOR_SPACE_PROFILE) {
if (profile->color_space == RGB_SIGNATURE) {
if (find_tag(index, TAG_A2B0)) {
if (read_u32(src, find_tag(index, TAG_A2B0)->offset) == LUT8_TYPE ||
@ -1405,7 +1405,7 @@ void qcms_data_create_rgb_with_gamma(qcms_CIE_xyY white_point, qcms_CIE_xyYTRIPL
* PCS illumiant field. Likewise mandatory profile tags are omitted.
*/
write_u32(data, 0, length); // the total length of this memory
write_u32(data, 12, DISPLAY_DEVICE_PROFILE); // profile->class
write_u32(data, 12, DISPLAY_DEVICE_PROFILE); // profile->class_type
write_u32(data, 16, RGB_SIGNATURE); // profile->color_space
write_u32(data, 20, XYZ_SIGNATURE); // profile->pcs
write_u32(data, 64, QCMS_INTENT_PERCEPTUAL); // profile->rendering_intent

View File

@ -24,6 +24,10 @@
#ifndef _QCMS_MATRIX_H
#define _QCMS_MATRIX_H
#ifdef __cplusplus
extern "C" {
#endif
struct vector {
float v[3];
};
@ -36,4 +40,8 @@ struct matrix matrix_invert(struct matrix mat);
struct matrix matrix_invalid(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -40,8 +40,8 @@ if use_sse1:
SOURCES['transform-sse1.c'].flags += CONFIG['SSE_FLAGS']
if use_sse2:
SOURCES += ['transform-sse2.c']
SOURCES['transform-sse2.c'].flags += CONFIG['SSE2_FLAGS']
SOURCES += ['transform-sse2.cpp']
SOURCES['transform-sse2.cpp'].flags += CONFIG['SSE2_FLAGS']
if use_altivec:
SOURCES += ['transform-altivec.c']

View File

@ -82,8 +82,7 @@ typedef enum {
#endif
#include <stdio.h>
typedef int qcms_bool;
#include <stdbool.h>
struct _qcms_transform;
typedef struct _qcms_transform qcms_transform;
@ -155,7 +154,7 @@ void qcms_data_from_unicode_path(const wchar_t *path, void **mem, size_t *size);
qcms_profile* qcms_profile_sRGB(void);
void qcms_profile_release(qcms_profile *profile);
qcms_bool qcms_profile_is_bogus(qcms_profile *profile);
bool qcms_profile_is_bogus(qcms_profile *profile);
qcms_intent qcms_profile_get_rendering_intent(qcms_profile *profile);
icColorSpaceSignature qcms_profile_get_color_space(qcms_profile *profile);

View File

@ -1,7 +1,14 @@
/* vim: set ts=8 sw=8 noexpandtab: */
#ifndef QCMS_INT_H
#define QCMS_INT_H
#include "qcms.h"
#include "qcmstypes.h"
#ifdef __cplusplus
extern "C" {
#endif
/* used as a lookup table for the output transformation.
* we refcount them so we only need to have one around per output
* profile, instead of duplicating them per transform */
@ -204,7 +211,7 @@ struct tag_value {
#define LAB_SIGNATURE 0x4C616220
struct _qcms_profile {
uint32_t class;
uint32_t class_type;
uint32_t color_space;
uint32_t pcs;
qcms_intent rendering_intent;
@ -254,8 +261,8 @@ static inline float uInt16Number_to_float(uInt16Number a)
void precache_release(struct precache_output *p);
qcms_bool set_rgb_colorants(qcms_profile *profile, qcms_CIE_xyY white_point, qcms_CIE_xyYTRIPLE primaries);
qcms_bool get_rgb_colorants(struct matrix *colorants, qcms_CIE_xyY white_point, qcms_CIE_xyYTRIPLE primaries);
bool set_rgb_colorants(qcms_profile *profile, qcms_CIE_xyY white_point, qcms_CIE_xyYTRIPLE primaries);
bool get_rgb_colorants(struct matrix *colorants, qcms_CIE_xyY white_point, qcms_CIE_xyYTRIPLE primaries);
void qcms_transform_data_rgb_out_lut_sse2(qcms_transform *transform,
unsigned char *src,
@ -283,7 +290,7 @@ void qcms_transform_data_rgba_out_lut_altivec(qcms_transform *transform,
unsigned char *dest,
size_t length);
extern qcms_bool qcms_supports_iccv4;
extern bool qcms_supports_iccv4;
#ifdef _MSC_VER
@ -325,3 +332,9 @@ long __cdecl _InterlockedDecrement(long volatile *);
# define OUTPUT_B_INDEX 2
# define OUTPUT_A_INDEX 3
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,6 +1,11 @@
#ifndef QCMS_TYPES_H
#define QCMS_TYPES_H
#ifdef __cplusplus
extern "C" {
#endif
#if !defined(IS_LITTLE_ENDIAN) && !defined(IS_BIG_ENDIAN)
#if BYTE_ORDER == LITTLE_ENDIAN
#define IS_LITTLE_ENDIAN
#elif BYTE_ORDER == BIG_ENDIAN
@ -16,6 +21,7 @@
#ifdef __OS2__
#define IS_LITTLE_ENDIAN
#endif
#endif
#if !defined(IS_LITTLE_ENDIAN) && !defined(IS_BIG_ENDIAN)
#error Unknown endianess
@ -44,8 +50,10 @@ typedef unsigned long uintptr_t;
# include <stdint.h>
#endif
typedef qcms_bool bool;
#define true 1
#define false 0
#include <stdbool.h>
#ifdef __cplusplus
}
#endif
#endif

View File

@ -51,7 +51,7 @@
#include <asm/cputable.h>
#include <link.h>
static inline qcms_bool have_altivec() {
static inline bool have_altivec() {
static int available = -1;
int new_avail = 0;
ElfW(auxv_t) auxv;
@ -88,7 +88,7 @@ out:
* rip-off from ffmpeg AltiVec detection code.
* this code also appears on Apple's AltiVec pages.
*/
static inline qcms_bool have_altivec() {
static inline bool have_altivec() {
int sels[2] = {CTL_HW, HW_VECTORUNIT};
static int available = -1;
size_t len = sizeof(available);
@ -291,7 +291,7 @@ static struct matrix adapt_matrix_to_D50(struct matrix r, qcms_CIE_xyY source_wh
return matrix_multiply(Bradford, r);
}
qcms_bool set_rgb_colorants(qcms_profile *profile, qcms_CIE_xyY white_point, qcms_CIE_xyYTRIPLE primaries)
bool set_rgb_colorants(qcms_profile *profile, qcms_CIE_xyY white_point, qcms_CIE_xyYTRIPLE primaries)
{
struct matrix colorants;
colorants = build_RGB_to_XYZ_transfer_matrix(white_point, primaries);
@ -316,7 +316,7 @@ qcms_bool set_rgb_colorants(qcms_profile *profile, qcms_CIE_xyY white_point, qcm
return true;
}
qcms_bool get_rgb_colorants(struct matrix *colorants, qcms_CIE_xyY white_point, qcms_CIE_xyYTRIPLE primaries)
bool get_rgb_colorants(struct matrix *colorants, qcms_CIE_xyY white_point, qcms_CIE_xyYTRIPLE primaries)
{
*colorants = build_RGB_to_XYZ_transfer_matrix(white_point, primaries);
*colorants = adapt_matrix_to_D50(*colorants, white_point);
@ -920,7 +920,7 @@ static struct precache_output *precache_reference(struct precache_output *p)
static struct precache_output *precache_create()
{
struct precache_output *p = malloc(sizeof(struct precache_output));
struct precache_output *p = (struct precache_output*)malloc(sizeof(struct precache_output));
if (p)
p->ref_count = 1;
return p;
@ -942,7 +942,7 @@ static qcms_transform *transform_alloc(void)
if (!posix_memalign(&allocated_memory, 16, sizeof(qcms_transform))) {
/* Doing a memset to initialise all bits to 'zero'*/
memset(allocated_memory, 0, sizeof(qcms_transform));
t = allocated_memory;
t = (qcms_transform*)allocated_memory;
return t;
} else {
return NULL;
@ -956,7 +956,7 @@ static void transform_free(qcms_transform *t)
static qcms_transform *transform_alloc(void)
{
/* transform needs to be aligned on a 16byte boundrary */
char *original_block = calloc(sizeof(qcms_transform) + sizeof(void*) + 16, 1);
char *original_block = (char *)calloc(sizeof(qcms_transform) + sizeof(void*) + 16, 1);
/* make room for a pointer to the block returned by calloc */
void *transform_start = original_block + sizeof(void*);
/* align transform_start */
@ -1173,8 +1173,8 @@ qcms_transform* qcms_transform_precacheLUT_float(qcms_transform *transform, qcms
float* dest = NULL;
float* lut = NULL;
src = malloc(lutSize*sizeof(float));
dest = malloc(lutSize*sizeof(float));
src = (float*)malloc(lutSize*sizeof(float));
dest = (float*)malloc(lutSize*sizeof(float));
if (src && dest) {
/* Prepare a list of points we want to sample */
@ -1415,10 +1415,10 @@ __attribute__((__force_align_arg_pointer__))
#endif
void qcms_transform_data(qcms_transform *transform, void *src, void *dest, size_t length)
{
transform->transform_fn(transform, src, dest, length);
transform->transform_fn(transform, (unsigned char*)src, (unsigned char*)dest, length);
}
qcms_bool qcms_supports_iccv4;
bool qcms_supports_iccv4;
void qcms_enable_iccv4()
{
qcms_supports_iccv4 = true;

View File

@ -389,7 +389,7 @@ void compute_precache_linear(uint8_t *output)
}
}
qcms_bool compute_precache(struct curveType *trc, uint8_t *output)
bool compute_precache(struct curveType *trc, uint8_t *output)
{
if (trc->type == PARAMETRIC_CURVE_TYPE) {

View File

@ -27,6 +27,10 @@
#include <stdlib.h>
#include <math.h>
#ifdef __cplusplus
extern "C" {
#endif
#define CLU(table,x,y,z) table[(x*len + y*x_len + z*xy_len)*3]
//XXX: could use a bettername
@ -88,12 +92,7 @@ void build_output_lut(struct curveType *trc,
uint16_t **output_gamma_lut, size_t *output_gamma_lut_length);
struct matrix matrix_invert(struct matrix mat);
qcms_bool compute_precache(struct curveType *trc, uint8_t *output);
// Tested by GTest
#ifdef __cplusplus
extern "C" {
#endif
bool compute_precache(struct curveType *trc, uint8_t *output);
uint16_fract_t lut_inverse_interp16(uint16_t Value, uint16_t LutTable[], int length);

View File

@ -8,6 +8,7 @@
#include "mozilla/ArrayUtils.h"
#include "qcms.h"
#include "qcmsint.h"
#include "transform_util.h"
const size_t allGBSize = 1 * 256 * 256 * 4;