Bug 1684534 - Rename matrix and qcms_profile types. r=aosmond

Differential Revision: https://phabricator.services.mozilla.com/D100551
This commit is contained in:
Jeff Muizelaar 2020-12-30 18:44:37 +00:00
Родитель 7f7cf34bf9
Коммит 1e96a1abb4
8 изменённых файлов: 119 добавлений и 126 удалений

Просмотреть файл

@ -5,7 +5,7 @@ use libc::{fclose, fopen, fread, free, malloc, memset, FILE};
use crate::{
double_to_s15Fixed16Number,
iccread::*,
matrix::matrix,
matrix::Matrix,
transform::get_rgb_colorants,
transform::qcms_data_type,
transform::{qcms_transform, transform_create},
@ -13,8 +13,8 @@ use crate::{
};
#[no_mangle]
pub extern "C" fn qcms_profile_sRGB() -> *mut qcms_profile {
let profile = qcms_profile::new_sRGB();
pub extern "C" fn qcms_profile_sRGB() -> *mut Profile {
let profile = Profile::new_sRGB();
Box::into_raw(profile)
}
@ -29,14 +29,9 @@ pub unsafe extern "C" fn qcms_profile_create_rgb_with_gamma_set(
mut redGamma: f32,
mut greenGamma: f32,
mut blueGamma: f32,
) -> *mut qcms_profile {
let profile = qcms_profile::new_rgb_with_gamma_set(
white_point,
primaries,
redGamma,
greenGamma,
blueGamma,
);
) -> *mut Profile {
let profile =
Profile::new_rgb_with_gamma_set(white_point, primaries, redGamma, greenGamma, blueGamma);
match profile {
Some(profile) => Box::into_raw(profile),
None => null_mut(),
@ -44,8 +39,8 @@ pub unsafe extern "C" fn qcms_profile_create_rgb_with_gamma_set(
}
#[no_mangle]
pub unsafe extern "C" fn qcms_profile_create_gray_with_gamma(mut gamma: f32) -> *mut qcms_profile {
let profile = qcms_profile::new_gray_with_gamma(gamma);
pub unsafe extern "C" fn qcms_profile_create_gray_with_gamma(mut gamma: f32) -> *mut Profile {
let profile = Profile::new_gray_with_gamma(gamma);
Box::into_raw(profile)
}
@ -54,7 +49,7 @@ pub unsafe extern "C" fn qcms_profile_create_rgb_with_gamma(
mut white_point: qcms_CIE_xyY,
mut primaries: qcms_CIE_xyYTRIPLE,
mut gamma: f32,
) -> *mut qcms_profile {
) -> *mut Profile {
qcms_profile_create_rgb_with_gamma_set(white_point, primaries, gamma, gamma, gamma)
}
@ -64,9 +59,9 @@ pub unsafe extern "C" fn qcms_profile_create_rgb_with_table(
mut primaries: qcms_CIE_xyYTRIPLE,
mut table: *const u16,
mut num_entries: i32,
) -> *mut qcms_profile {
) -> *mut Profile {
let table = slice::from_raw_parts(table, num_entries as usize);
let profile = qcms_profile::new_rgb_with_table(white_point, primaries, table);
let profile = Profile::new_rgb_with_table(white_point, primaries, table);
match profile {
Some(profile) => Box::into_raw(profile),
None => null_mut(),
@ -78,9 +73,9 @@ pub unsafe extern "C" fn qcms_profile_create_rgb_with_table(
pub unsafe extern "C" fn qcms_profile_from_memory(
mut mem: *const libc::c_void,
mut size: usize,
) -> *mut qcms_profile {
) -> *mut Profile {
let mem = slice::from_raw_parts(mem as *const libc::c_uchar, size);
let profile = qcms_profile::new_from_slice(mem);
let profile = Profile::new_from_slice(mem);
match profile {
Some(profile) => Box::into_raw(profile),
None => null_mut(),
@ -88,16 +83,16 @@ pub unsafe extern "C" fn qcms_profile_from_memory(
}
#[no_mangle]
pub extern "C" fn qcms_profile_get_rendering_intent(profile: &qcms_profile) -> Intent {
pub extern "C" fn qcms_profile_get_rendering_intent(profile: &Profile) -> Intent {
profile.rendering_intent
}
#[no_mangle]
pub extern "C" fn qcms_profile_get_color_space(profile: &qcms_profile) -> icColorSpaceSignature {
pub extern "C" fn qcms_profile_get_color_space(profile: &Profile) -> icColorSpaceSignature {
profile.color_space
}
#[no_mangle]
pub unsafe extern "C" fn qcms_profile_release(mut profile: *mut qcms_profile) {
pub unsafe extern "C" fn qcms_profile_release(mut profile: *mut Profile) {
drop(Box::from_raw(profile));
}
unsafe extern "C" fn qcms_data_from_file(
@ -153,23 +148,21 @@ unsafe extern "C" fn qcms_data_from_file(
}
#[no_mangle]
pub unsafe extern "C" fn qcms_profile_from_file(mut file: *mut FILE) -> *mut qcms_profile {
pub unsafe extern "C" fn qcms_profile_from_file(mut file: *mut FILE) -> *mut Profile {
let mut length: usize = 0;
let mut profile: *mut qcms_profile;
let mut profile: *mut Profile;
let mut data: *mut libc::c_void = std::ptr::null_mut::<libc::c_void>();
qcms_data_from_file(file, &mut data, &mut length);
if data.is_null() || length == 0 {
return std::ptr::null_mut::<qcms_profile>();
return std::ptr::null_mut::<Profile>();
}
profile = qcms_profile_from_memory(data, length);
free(data);
profile
}
#[no_mangle]
pub unsafe extern "C" fn qcms_profile_from_path(
mut path: *const libc::c_char,
) -> *mut qcms_profile {
let mut profile: *mut qcms_profile = std::ptr::null_mut::<qcms_profile>();
pub unsafe extern "C" fn qcms_profile_from_path(mut path: *const libc::c_char) -> *mut Profile {
let mut profile: *mut Profile = std::ptr::null_mut::<Profile>();
let mut file = fopen(path, b"rb\x00" as *const u8 as *const libc::c_char);
if !file.is_null() {
profile = qcms_profile_from_file(file);
@ -225,9 +218,9 @@ pub unsafe extern "C" fn qcms_data_from_unicode_path(
#[no_mangle]
pub extern "C" fn qcms_transform_create(
mut in_0: &qcms_profile,
mut in_0: &Profile,
mut in_type: qcms_data_type,
mut out: &qcms_profile,
mut out: &Profile,
mut out_type: qcms_data_type,
mut intent: Intent,
) -> *mut qcms_transform {
@ -253,7 +246,7 @@ pub unsafe extern "C" fn qcms_data_create_rgb_with_gamma(
let mut tag_table_offset: usize;
let mut tag_data_offset: usize;
let mut data: *mut libc::c_void;
let mut colorants: matrix = matrix {
let mut colorants: Matrix = Matrix {
m: [[0.; 3]; 3],
invalid: false,
};
@ -364,8 +357,8 @@ pub unsafe extern "C" fn qcms_transform_data(
);
}
pub use crate::iccread::qcms_profile;
pub use crate::iccread::qcms_profile_is_bogus;
pub use crate::iccread::Profile as qcms_profile;
pub use crate::iccread::{icSigGrayData, icSigRgbData};
pub use crate::transform::{
qcms_enable_iccv4, qcms_profile_precache_output_transform, qcms_transform_release,

Просмотреть файл

@ -24,8 +24,8 @@ use crate::{
iccread::LAB_SIGNATURE,
iccread::RGB_SIGNATURE,
iccread::XYZ_SIGNATURE,
iccread::{lutType, lutmABType, qcms_profile},
matrix::{matrix, matrix_invert},
iccread::{lutType, lutmABType, Profile},
matrix::{matrix_invert, Matrix},
s15Fixed16Number_to_float,
transform_util::clamp_float,
transform_util::{
@ -36,7 +36,7 @@ use crate::{
#[derive(Clone, Default)]
pub struct qcms_modular_transform {
pub matrix: matrix,
pub matrix: Matrix,
pub tx: f32,
pub ty: f32,
pub tz: f32,
@ -67,8 +67,8 @@ fn lerp(mut a: f32, mut b: f32, mut t: f32) -> f32 {
a * (1.0 - t) + b * t
}
fn build_lut_matrix(mut lut: Option<&lutType>) -> matrix {
let mut result: matrix = matrix {
fn build_lut_matrix(mut lut: Option<&lutType>) -> Matrix {
let mut result: Matrix = Matrix {
m: [[0.; 3]; 3],
invalid: false,
};
@ -89,8 +89,8 @@ fn build_lut_matrix(mut lut: Option<&lutType>) -> matrix {
}
result
}
fn build_mAB_matrix(lut: &lutmABType) -> matrix {
let mut result: matrix = matrix {
fn build_mAB_matrix(lut: &lutmABType) -> Matrix {
let mut result: Matrix = Matrix {
m: [[0.; 3]; 3],
invalid: false,
};
@ -490,7 +490,7 @@ fn transform_module_matrix_translate(
mut src: &[f32],
mut dest: &mut [f32],
) {
let mut mat: matrix = matrix {
let mut mat: Matrix = Matrix {
m: [[0.; 3]; 3],
invalid: false,
};
@ -527,7 +527,7 @@ fn transform_module_matrix(
mut src: &[f32],
mut dest: &mut [f32],
) {
let mut mat: matrix = matrix {
let mut mat: Matrix = Matrix {
m: [[0.; 3]; 3],
invalid: false,
};
@ -748,7 +748,7 @@ fn modular_transform_create_lut(mut lut: &lutType) -> Option<Box<qcms_modular_tr
None
}
fn modular_transform_create_input(mut in_0: &qcms_profile) -> Option<Box<qcms_modular_transform>> {
fn modular_transform_create_input(mut in_0: &Profile) -> Option<Box<qcms_modular_transform>> {
let mut first_transform = None;
let mut next_transform = &mut first_transform;
if in_0.A2B0.is_some() {
@ -819,7 +819,7 @@ fn modular_transform_create_input(mut in_0: &qcms_profile) -> Option<Box<qcms_mo
}
first_transform
}
fn modular_transform_create_output(mut out: &qcms_profile) -> Option<Box<qcms_modular_transform>> {
fn modular_transform_create_output(mut out: &Profile) -> Option<Box<qcms_modular_transform>> {
let mut first_transform = None;
let mut next_transform = &mut first_transform;
if out.B2A0.is_some() {
@ -944,8 +944,8 @@ remove_next:
}
*/
fn modular_transform_create(
mut in_0: &qcms_profile,
mut out: &qcms_profile,
mut in_0: &Profile,
mut out: &Profile,
) -> Option<Box<qcms_modular_transform>> {
let mut first_transform = None;
let mut next_transform = &mut first_transform;
@ -1018,8 +1018,8 @@ fn modular_transform_data(
}
pub fn chain_transform(
mut in_0: &qcms_profile,
mut out: &qcms_profile,
mut in_0: &Profile,
mut out: &Profile,
mut src: Vec<f32>,
mut dest: Vec<f32>,
mut lutSize: usize,

Просмотреть файл

@ -497,8 +497,8 @@ mod gtest {
}
struct QcmsProfileTest {
in_profile: *mut qcms_profile,
out_profile: *mut qcms_profile,
in_profile: *mut Profile,
out_profile: *mut Profile,
transform: *mut qcms_transform,
input: Vec<u8>,
@ -782,7 +782,7 @@ mod gtest {
}
}
fn profile_from_path(file: &str) -> *mut qcms_profile {
fn profile_from_path(file: &str) -> *mut Profile {
use std::io::Read;
let mut path = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
path.push("profiles");

Просмотреть файл

@ -27,7 +27,7 @@ use std::{
};
use crate::transform::{precache_output, set_rgb_colorants};
use crate::{matrix::matrix, s15Fixed16Number, s15Fixed16Number_to_float, Intent, Intent::*};
use crate::{matrix::Matrix, s15Fixed16Number, s15Fixed16Number_to_float, Intent, Intent::*};
pub static qcms_supports_iccv4: AtomicBool = AtomicBool::new(false);
@ -66,7 +66,7 @@ pub const LAB_SIGNATURE: u32 = 0x4C616220;
#[repr(C)]
#[derive(Default)]
pub struct qcms_profile {
pub struct Profile {
pub(crate) class_type: u32,
pub(crate) color_space: u32,
pub(crate) pcs: u32,
@ -82,7 +82,7 @@ pub struct qcms_profile {
pub(crate) B2A0: Option<Box<lutType>>,
pub(crate) mAB: Option<Box<lutmABType>>,
pub(crate) mBA: Option<Box<lutmABType>>,
pub(crate) chromaticAdaption: matrix,
pub(crate) chromaticAdaption: Matrix,
pub(crate) output_table_r: Option<Arc<precache_output>>,
pub(crate) output_table_g: Option<Arc<precache_output>>,
pub(crate) output_table_b: Option<Arc<precache_output>>,
@ -308,7 +308,7 @@ const COLOR_SPACE_PROFILE: u32 = 0x73706163; // 'spac'
const ABSTRACT_PROFILE: u32 = 0x61627374; // 'abst'
const NAMED_COLOR_PROFILE: u32 = 0x6e6d636c; // 'nmcl'
fn read_class_signature(mut profile: &mut qcms_profile, mut mem: &mut mem_source) {
fn read_class_signature(mut profile: &mut Profile, mut mem: &mut mem_source) {
profile.class_type = read_u32(mem, 12);
match profile.class_type {
DISPLAY_DEVICE_PROFILE
@ -320,7 +320,7 @@ fn read_class_signature(mut profile: &mut qcms_profile, mut mem: &mut mem_source
}
};
}
fn read_color_space(mut profile: &mut qcms_profile, mut mem: &mut mem_source) {
fn read_color_space(mut profile: &mut Profile, mut mem: &mut mem_source) {
profile.color_space = read_u32(mem, 16);
match profile.color_space {
RGB_SIGNATURE | GRAY_SIGNATURE => {}
@ -329,7 +329,7 @@ fn read_color_space(mut profile: &mut qcms_profile, mut mem: &mut mem_source) {
}
};
}
fn read_pcs(mut profile: &mut qcms_profile, mut mem: &mut mem_source) {
fn read_pcs(mut profile: &mut Profile, mut mem: &mut mem_source) {
profile.pcs = read_u32(mem, 20);
match profile.pcs {
XYZ_SIGNATURE | LAB_SIGNATURE => {}
@ -338,7 +338,7 @@ fn read_pcs(mut profile: &mut qcms_profile, mut mem: &mut mem_source) {
}
};
}
fn read_tag_table(mut profile: &mut qcms_profile, mut mem: &mut mem_source) -> Vec<tag> {
fn read_tag_table(mut profile: &mut Profile, mut mem: &mut mem_source) -> Vec<tag> {
let count = read_u32(mem, 128);
if count > MAX_TAG_COUNT {
invalid_source(mem, "max number of tags exceeded");
@ -432,7 +432,7 @@ authorization from SunSoft Inc.
// true if the profile looks bogus and should probably be
// ignored.
#[no_mangle]
pub extern "C" fn qcms_profile_is_bogus(mut profile: &mut qcms_profile) -> bool {
pub extern "C" fn qcms_profile_is_bogus(mut profile: &mut Profile) -> bool {
let mut sum: [f32; 3] = [0.; 3];
let mut target: [f32; 3] = [0.; 3];
let mut tolerance: [f32; 3] = [0.; 3];
@ -552,9 +552,9 @@ fn read_tag_s15Fixed16ArrayType(
mut src: &mut mem_source,
mut index: &tag_index,
mut tag_id: u32,
) -> matrix {
) -> Matrix {
let mut tag = find_tag(index, tag_id);
let mut matrix: matrix = matrix {
let mut matrix: Matrix = Matrix {
m: [[0.; 3]; 3],
invalid: false,
};
@ -991,7 +991,7 @@ fn read_tag_lutType(mut src: &mut mem_source, mut tag: &tag) -> Option<Box<lutTy
output_table,
}))
}
fn read_rendering_intent(mut profile: &mut qcms_profile, mut src: &mut mem_source) {
fn read_rendering_intent(mut profile: &mut Profile, mut src: &mut mem_source) {
let intent = read_u32(src, 64);
profile.rendering_intent = match intent {
x if x == QCMS_INTENT_PERCEPTUAL as u32 => QCMS_INTENT_PERCEPTUAL,
@ -1004,8 +1004,8 @@ fn read_rendering_intent(mut profile: &mut qcms_profile, mut src: &mut mem_sourc
}
};
}
fn profile_create() -> Box<qcms_profile> {
Box::new(qcms_profile::default())
fn profile_create() -> Box<Profile> {
Box::new(Profile::default())
}
/* build sRGB gamma table */
/* based on cmsBuildParametricGamma() */
@ -1122,7 +1122,7 @@ pub extern "C" fn qcms_white_point_sRGB() -> qcms_CIE_xyY {
white_point_from_temp(6504)
}
impl qcms_profile {
impl Profile {
//XXX: it would be nice if we had a way of ensuring
// everything in a profile was initialized regardless of how it was created
//XXX: should this also be taking a black_point?
@ -1131,7 +1131,7 @@ impl qcms_profile {
mut white_point: qcms_CIE_xyY,
mut primaries: qcms_CIE_xyYTRIPLE,
table: &[u16],
) -> Option<Box<qcms_profile>> {
) -> Option<Box<Profile>> {
let mut profile = profile_create();
//XXX: should store the whitepoint
if !set_rgb_colorants(&mut profile, white_point, primaries) {
@ -1146,7 +1146,7 @@ impl qcms_profile {
profile.pcs = XYZ_TYPE;
Some(profile)
}
pub fn new_sRGB() -> Box<qcms_profile> {
pub fn new_sRGB() -> Box<Profile> {
let Rec709Primaries = qcms_CIE_xyYTRIPLE {
red: {
qcms_CIE_xyY {
@ -1173,10 +1173,10 @@ impl qcms_profile {
let D65 = qcms_white_point_sRGB();
let table = build_sRGB_gamma_table(1024);
qcms_profile::new_rgb_with_table(D65, Rec709Primaries, &table).unwrap()
Profile::new_rgb_with_table(D65, Rec709Primaries, &table).unwrap()
}
pub fn new_gray_with_gamma(gamma: f32) -> Box<qcms_profile> {
pub fn new_gray_with_gamma(gamma: f32) -> Box<Profile> {
let mut profile = profile_create();
profile.grayTRC = Some(curve_from_gamma(gamma));
@ -1193,7 +1193,7 @@ impl qcms_profile {
mut redGamma: f32,
mut greenGamma: f32,
mut blueGamma: f32,
) -> Option<Box<qcms_profile>> {
) -> Option<Box<Profile>> {
let mut profile = profile_create();
//XXX: should store the whitepoint
@ -1210,7 +1210,7 @@ impl qcms_profile {
Some(profile)
}
pub fn new_from_slice(mem: &[u8]) -> Option<Box<qcms_profile>> {
pub fn new_from_slice(mem: &[u8]) -> Option<Box<Profile>> {
let mut length: u32;
let mut source: mem_source = mem_source {
buf: mem,

Просмотреть файл

@ -56,7 +56,7 @@ mod matrix;
mod transform;
pub use iccread::qcms_CIE_xyY as CIE_xyY;
pub use iccread::qcms_CIE_xyYTRIPLE as CIE_xyYTRIPLE;
pub use iccread::qcms_profile as Profile;
pub use iccread::Profile;
pub use transform::qcms_data_type as DataType;
pub use transform::Transform;
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]

Просмотреть файл

@ -23,19 +23,19 @@
#[repr(C)]
#[derive(Copy, Clone, Default)]
pub struct matrix {
pub struct Matrix {
pub m: [[f32; 3]; 3],
pub invalid: bool,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct vector {
pub struct Vector {
pub v: [f32; 3],
}
pub fn matrix_eval(mut mat: matrix, mut v: vector) -> vector {
let mut result: vector = vector { v: [0.; 3] };
pub fn matrix_eval(mut mat: Matrix, mut v: Vector) -> Vector {
let mut result: Vector = Vector { v: [0.; 3] };
result.v[0] = mat.m[0][0] * v.v[0] + mat.m[0][1] * v.v[1] + mat.m[0][2] * v.v[2];
result.v[1] = mat.m[1][0] * v.v[0] + mat.m[1][1] * v.v[1] + mat.m[1][2] * v.v[2];
result.v[2] = mat.m[2][0] * v.v[0] + mat.m[2][1] * v.v[1] + mat.m[2][2] * v.v[2];
@ -43,7 +43,7 @@ pub fn matrix_eval(mut mat: matrix, mut v: vector) -> vector {
}
//XXX: should probably pass by reference and we could
//probably reuse this computation in matrix_invert
pub fn matrix_det(mut mat: matrix) -> f32 {
pub fn matrix_det(mut mat: Matrix) -> f32 {
let mut det: f32 = mat.m[0][0] * mat.m[1][1] * mat.m[2][2]
+ mat.m[0][1] * mat.m[1][2] * mat.m[2][0]
+ mat.m[0][2] * mat.m[1][0] * mat.m[2][1]
@ -56,8 +56,8 @@ pub fn matrix_det(mut mat: matrix) -> f32 {
/* lcms uses gauss-jordan elimination with partial pivoting which is
* less efficient and not as numerically stable. See Mathematics for
* Game Programmers. */
pub fn matrix_invert(mut mat: matrix) -> matrix {
let mut dest_mat: matrix = matrix {
pub fn matrix_invert(mut mat: Matrix) -> Matrix {
let mut dest_mat: Matrix = Matrix {
m: [[0.; 3]; 3],
invalid: false,
};
@ -94,8 +94,8 @@ pub fn matrix_invert(mut mat: matrix) -> matrix {
}
dest_mat
}
pub fn matrix_identity() -> matrix {
let mut i: matrix = matrix {
pub fn matrix_identity() -> Matrix {
let mut i: Matrix = Matrix {
m: [[0.; 3]; 3],
invalid: false,
};
@ -111,15 +111,15 @@ pub fn matrix_identity() -> matrix {
i.invalid = false;
i
}
pub fn matrix_invalid() -> matrix {
let mut inv: matrix = matrix_identity();
pub fn matrix_invalid() -> Matrix {
let mut inv: Matrix = matrix_identity();
inv.invalid = true;
inv
}
/* from pixman */
/* MAT3per... */
pub fn matrix_multiply(mut a: matrix, mut b: matrix) -> matrix {
let mut result: matrix = matrix {
pub fn matrix_multiply(mut a: Matrix, mut b: Matrix) -> Matrix {
let mut result: Matrix = Matrix {
m: [[0.; 3]; 3],
invalid: false,
};

Просмотреть файл

@ -37,7 +37,7 @@ use crate::{
},
};
use crate::{
iccread::{qcms_CIE_xyY, qcms_CIE_xyYTRIPLE, qcms_profile, GRAY_SIGNATURE, RGB_SIGNATURE},
iccread::{qcms_CIE_xyY, qcms_CIE_xyYTRIPLE, Profile, GRAY_SIGNATURE, RGB_SIGNATURE},
transform_util::clamp_float,
Intent,
};
@ -220,17 +220,17 @@ fn clamp_u8(mut v: f32) -> u8 {
fn build_RGB_to_XYZ_transfer_matrix(
mut white: qcms_CIE_xyY,
mut primrs: qcms_CIE_xyYTRIPLE,
) -> matrix {
let mut primaries: matrix = matrix {
) -> Matrix {
let mut primaries: Matrix = Matrix {
m: [[0.; 3]; 3],
invalid: false,
};
let mut result: matrix = matrix {
let mut result: Matrix = Matrix {
m: [[0.; 3]; 3],
invalid: false,
};
let mut white_point: vector = vector { v: [0.; 3] };
let mut white_point: Vector = Vector { v: [0.; 3] };
let mut xn: f64 = white.x;
let mut yn: f64 = white.y;
@ -257,11 +257,11 @@ fn build_RGB_to_XYZ_transfer_matrix(
white_point.v[0] = (xn / yn) as f32;
white_point.v[1] = 1.;
white_point.v[2] = ((1.0f64 - xn - yn) / yn) as f32;
let mut primaries_invert: matrix = matrix_invert(primaries);
let mut primaries_invert: Matrix = matrix_invert(primaries);
if primaries_invert.invalid {
return matrix_invalid();
}
let mut coefs: vector = matrix_eval(primaries_invert, white_point);
let mut coefs: Vector = matrix_eval(primaries_invert, white_point);
result.m[0][0] = (coefs.v[0] as f64 * xr) as f32;
result.m[0][1] = (coefs.v[1] as f64 * xg) as f32;
result.m[0][2] = (coefs.v[2] as f64 * xb) as f32;
@ -298,19 +298,19 @@ fn xyY2XYZ(mut source: qcms_CIE_xyY) -> CIE_XYZ {
fn compute_chromatic_adaption(
mut source_white_point: CIE_XYZ,
mut dest_white_point: CIE_XYZ,
mut chad: matrix,
) -> matrix {
let mut cone_source_XYZ: vector = vector { v: [0.; 3] };
mut chad: Matrix,
) -> Matrix {
let mut cone_source_XYZ: Vector = Vector { v: [0.; 3] };
let mut cone_dest_XYZ: vector = vector { v: [0.; 3] };
let mut cone_dest_XYZ: Vector = Vector { v: [0.; 3] };
let mut cone: matrix = matrix {
let mut cone: Matrix = Matrix {
m: [[0.; 3]; 3],
invalid: false,
};
let mut tmp: matrix = chad;
let mut chad_inv: matrix = matrix_invert(tmp);
let mut tmp: Matrix = chad;
let mut chad_inv: Matrix = matrix_invert(tmp);
if chad_inv.invalid {
return matrix_invalid();
}
@ -321,8 +321,8 @@ fn compute_chromatic_adaption(
cone_dest_XYZ.v[1] = dest_white_point.Y as f32;
cone_dest_XYZ.v[2] = dest_white_point.Z as f32;
let mut cone_source_rgb: vector = matrix_eval(chad, cone_source_XYZ);
let mut cone_dest_rgb: vector = matrix_eval(chad, cone_dest_XYZ);
let mut cone_source_rgb: Vector = matrix_eval(chad, cone_source_XYZ);
let mut cone_dest_rgb: Vector = matrix_eval(chad, cone_dest_XYZ);
cone.m[0][0] = cone_dest_rgb.v[0] / cone_source_rgb.v[0];
cone.m[0][1] = 0.;
cone.m[0][2] = 0.;
@ -339,9 +339,9 @@ fn compute_chromatic_adaption(
/* from lcms: cmsAdaptionMatrix */
// Returns the final chrmatic adaptation from illuminant FromIll to Illuminant ToIll
// Bradford is assumed
fn adaption_matrix(mut source_illumination: CIE_XYZ, mut target_illumination: CIE_XYZ) -> matrix {
let mut lam_rigg: matrix = {
let mut init = matrix {
fn adaption_matrix(mut source_illumination: CIE_XYZ, mut target_illumination: CIE_XYZ) -> Matrix {
let mut lam_rigg: Matrix = {
let mut init = Matrix {
m: [
[0.8951, 0.2664, -0.1614],
[-0.7502, 1.7135, 0.0367],
@ -354,24 +354,24 @@ fn adaption_matrix(mut source_illumination: CIE_XYZ, mut target_illumination: CI
compute_chromatic_adaption(source_illumination, target_illumination, lam_rigg)
}
/* from lcms: cmsAdaptMatrixToD50 */
fn adapt_matrix_to_D50(mut r: matrix, mut source_white_pt: qcms_CIE_xyY) -> matrix {
fn adapt_matrix_to_D50(mut r: Matrix, mut source_white_pt: qcms_CIE_xyY) -> Matrix {
if source_white_pt.y == 0.0f64 {
return matrix_invalid();
}
let mut Dn: CIE_XYZ = xyY2XYZ(source_white_pt);
let mut Bradford: matrix = adaption_matrix(Dn, D50_XYZ);
let mut Bradford: Matrix = adaption_matrix(Dn, D50_XYZ);
if Bradford.invalid {
return matrix_invalid();
}
matrix_multiply(Bradford, r)
}
pub(crate) fn set_rgb_colorants(
mut profile: &mut qcms_profile,
mut profile: &mut Profile,
mut white_point: qcms_CIE_xyY,
mut primaries: qcms_CIE_xyYTRIPLE,
) -> bool {
let mut colorants: matrix = build_RGB_to_XYZ_transfer_matrix(white_point, primaries);
let mut colorants: Matrix = build_RGB_to_XYZ_transfer_matrix(white_point, primaries);
colorants = adapt_matrix_to_D50(colorants, white_point);
if colorants.invalid {
return false;
@ -389,7 +389,7 @@ pub(crate) fn set_rgb_colorants(
true
}
pub(crate) fn get_rgb_colorants(
mut colorants: &mut matrix,
mut colorants: &mut Matrix,
mut white_point: qcms_CIE_xyY,
mut primaries: qcms_CIE_xyYTRIPLE,
) -> bool {
@ -1010,7 +1010,7 @@ pub unsafe extern "C" fn qcms_transform_release(mut t: *mut qcms_transform) {
drop(t)
}
const bradford_matrix: matrix = matrix {
const bradford_matrix: Matrix = Matrix {
m: [
[0.8951, 0.2664, -0.1614],
[-0.7502, 1.7135, 0.0367],
@ -1019,7 +1019,7 @@ const bradford_matrix: matrix = matrix {
invalid: false,
};
const bradford_matrix_inv: matrix = matrix {
const bradford_matrix_inv: Matrix = Matrix {
m: [
[0.9869929, -0.1470543, 0.1599627],
[0.4323053, 0.5183603, 0.0492912],
@ -1029,7 +1029,7 @@ const bradford_matrix_inv: matrix = matrix {
};
// See ICCv4 E.3
fn compute_whitepoint_adaption(mut X: f32, mut Y: f32, mut Z: f32) -> matrix {
fn compute_whitepoint_adaption(mut X: f32, mut Y: f32, mut Z: f32) -> Matrix {
let mut p: f32 = (0.96422 * bradford_matrix.m[0][0]
+ 1.000 * bradford_matrix.m[1][0]
+ 0.82521 * bradford_matrix.m[2][0])
@ -1042,7 +1042,7 @@ fn compute_whitepoint_adaption(mut X: f32, mut Y: f32, mut Z: f32) -> matrix {
+ 1.000 * bradford_matrix.m[1][2]
+ 0.82521 * bradford_matrix.m[2][2])
/ (X * bradford_matrix.m[0][2] + Y * bradford_matrix.m[1][2] + Z * bradford_matrix.m[2][2]);
let mut white_adaption = matrix {
let mut white_adaption = Matrix {
m: [[p, 0., 0.], [0., y, 0.], [0., 0., b]],
invalid: false,
};
@ -1052,7 +1052,7 @@ fn compute_whitepoint_adaption(mut X: f32, mut Y: f32, mut Z: f32) -> matrix {
)
}
#[no_mangle]
pub extern "C" fn qcms_profile_precache_output_transform(mut profile: &mut qcms_profile) {
pub extern "C" fn qcms_profile_precache_output_transform(mut profile: &mut Profile) {
/* we only support precaching on rgb profiles */
if profile.color_space != RGB_SIGNATURE {
return;
@ -1102,8 +1102,8 @@ pub extern "C" fn qcms_profile_precache_output_transform(mut profile: &mut qcms_
/* Replace the current transformation with a LUT transformation using a given number of sample points */
fn transform_precacheLUT_float(
mut transform: Box<qcms_transform>,
mut in_0: &qcms_profile,
mut out: &qcms_profile,
mut in_0: &Profile,
mut out: &Profile,
mut samples: i32,
mut in_type: qcms_data_type,
) -> Option<Box<qcms_transform>> {
@ -1146,9 +1146,9 @@ fn transform_precacheLUT_float(
}
pub fn transform_create(
mut in_0: &qcms_profile,
mut in_0: &Profile,
mut in_type: qcms_data_type,
mut out: &qcms_profile,
mut out: &Profile,
mut out_type: qcms_data_type,
mut intent: Intent,
) -> Option<Box<qcms_transform>> {
@ -1269,13 +1269,13 @@ pub fn transform_create(
}
/* build combined colorant matrix */
let mut in_matrix: matrix = build_colorant_matrix(in_0);
let mut out_matrix: matrix = build_colorant_matrix(out);
let mut in_matrix: Matrix = build_colorant_matrix(in_0);
let mut out_matrix: Matrix = build_colorant_matrix(out);
out_matrix = matrix_invert(out_matrix);
if out_matrix.invalid {
return None;
}
let mut result_0: matrix = matrix_multiply(out_matrix, in_matrix);
let mut result_0: Matrix = matrix_multiply(out_matrix, in_matrix);
/* check for NaN values in the matrix and bail if we find any */
let mut i: u32 = 0;
while i < 3 {
@ -1348,8 +1348,8 @@ pub struct Transform {
impl Transform {
pub fn new(
input: &qcms_profile,
output: &qcms_profile,
input: &Profile,
output: &Profile,
ty: qcms_data_type,
intent: Intent,
) -> Option<Self> {

Просмотреть файл

@ -22,10 +22,10 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
use crate::{
iccread::{curveType, qcms_profile},
iccread::{curveType, Profile},
s15Fixed16Number_to_float,
};
use crate::{matrix::matrix, transform::PRECACHE_OUTPUT_MAX, transform::PRECACHE_OUTPUT_SIZE};
use crate::{matrix::Matrix, transform::PRECACHE_OUTPUT_MAX, transform::PRECACHE_OUTPUT_SIZE};
//XXX: could use a bettername
pub type uint16_fract_t = u16;
@ -227,8 +227,8 @@ pub(crate) fn build_input_gamma_table(mut TRC: Option<&curveType>) -> Option<Vec
Some(gamma_table)
}
pub fn build_colorant_matrix(mut p: &qcms_profile) -> matrix {
let mut result: matrix = matrix {
pub fn build_colorant_matrix(mut p: &Profile) -> Matrix {
let mut result: Matrix = Matrix {
m: [[0.; 3]; 3],
invalid: false,
};