Bug 1684486 - Run cargo clippy on qcms. r=aosmond

Differential Revision: https://phabricator.services.mozilla.com/D100539
This commit is contained in:
Jeff Muizelaar 2020-12-29 23:27:47 +00:00
Родитель bfbacfb6a4
Коммит 16a7eb6412
10 изменённых файлов: 271 добавлений и 301 удалений

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

@ -52,7 +52,7 @@ pub unsafe extern "C" fn qcms_profile_create_rgb_with_gamma(
mut primaries: qcms_CIE_xyYTRIPLE,
mut gamma: f32,
) -> *mut qcms_profile {
return qcms_profile_create_rgb_with_gamma_set(white_point, primaries, gamma, gamma, gamma);
qcms_profile_create_rgb_with_gamma_set(white_point, primaries, gamma, gamma, gamma)
}
#[no_mangle]
@ -86,11 +86,11 @@ pub unsafe extern "C" fn qcms_profile_from_memory(
#[no_mangle]
pub extern "C" fn qcms_profile_get_rendering_intent(profile: &qcms_profile) -> Intent {
return profile.rendering_intent;
profile.rendering_intent
}
#[no_mangle]
pub extern "C" fn qcms_profile_get_color_space(profile: &qcms_profile) -> icColorSpaceSignature {
return profile.color_space;
profile.color_space
}
#[no_mangle]
@ -107,7 +107,7 @@ unsafe extern "C" fn qcms_data_from_file(
let mut read_length: usize;
let mut length_be: be32 = 0;
let mut data: *mut libc::c_void;
*mem = 0 as *mut libc::c_void;
*mem = std::ptr::null_mut::<libc::c_void>();
*size = 0;
if fread(
&mut length_be as *mut be32 as *mut libc::c_void,
@ -135,7 +135,7 @@ unsafe extern "C" fn qcms_data_from_file(
(length as libc::c_ulong - ::std::mem::size_of::<be32>() as libc::c_ulong) as u32;
/* read the rest profile */
read_length = fread(
(data as *mut libc::c_uchar).offset(::std::mem::size_of::<be32>() as isize)
(data as *mut libc::c_uchar).add(::std::mem::size_of::<be32>())
as *mut libc::c_void,
1,
remaining_length as usize,
@ -154,26 +154,26 @@ unsafe extern "C" fn qcms_data_from_file(
pub unsafe extern "C" fn qcms_profile_from_file(mut file: *mut FILE) -> *mut qcms_profile {
let mut length: usize = 0;
let mut profile: *mut qcms_profile;
let mut data: *mut libc::c_void = 0 as *mut libc::c_void;
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 0 as *mut qcms_profile;
return std::ptr::null_mut::<qcms_profile>();
}
profile = qcms_profile_from_memory(data, length);
free(data);
return profile;
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 = 0 as *mut qcms_profile;
let mut profile: *mut qcms_profile = std::ptr::null_mut::<qcms_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);
fclose(file);
}
return profile;
profile
}
#[no_mangle]
pub unsafe extern "C" fn qcms_data_from_path(
@ -181,7 +181,7 @@ pub unsafe extern "C" fn qcms_data_from_path(
mut mem: *mut *mut libc::c_void,
mut size: *mut usize,
) {
*mem = 0 as *mut libc::c_void;
*mem = std::ptr::null_mut::<libc::c_void>();
*size = 0;
let file = fopen(path, b"rb\x00" as *const u8 as *const libc::c_char);
if !file.is_null() {

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

@ -64,7 +64,7 @@ pub type transform_module_fn_t =
#[inline]
fn lerp(mut a: f32, mut b: f32, mut t: f32) -> f32 {
return a * (1.0 - t) + b * t;
a * (1.0 - t) + b * t
}
fn build_lut_matrix(mut lut: Option<&lutType>) -> matrix {
@ -87,7 +87,7 @@ fn build_lut_matrix(mut lut: Option<&lutType>) -> matrix {
result.m = Default::default();
result.invalid = true
}
return result;
result
}
fn build_mAB_matrix(lut: &lutmABType) -> matrix {
let mut result: matrix = matrix {
@ -106,7 +106,7 @@ fn build_mAB_matrix(lut: &lutmABType) -> matrix {
result.m[2][2] = s15Fixed16Number_to_float(lut.e22);
result.invalid = false;
return result;
result
}
//Based on lcms cmsLab2XYZ
fn f(t: f32) -> f32 {
@ -556,7 +556,7 @@ fn transform_module_matrix(
}
}
fn modular_transform_alloc() -> Option<Box<qcms_modular_transform>> {
return Some(Box::new(Default::default()));
Some(Box::new(Default::default()))
}
fn modular_transform_release(mut t: Option<Box<qcms_modular_transform>>) {
// destroy a list of transforms non-recursively
@ -582,7 +582,7 @@ fn reverse_transform(
mut transform: Option<Box<qcms_modular_transform>>,
) -> Option<Box<qcms_modular_transform>> {
let mut prev_transform = None;
while !transform.is_none() {
while transform.is_some() {
let mut next_transform = std::mem::replace(
&mut transform.as_mut().unwrap().next_transform,
prev_transform,
@ -590,25 +590,21 @@ fn reverse_transform(
prev_transform = transform;
transform = next_transform
}
return prev_transform;
prev_transform
}
fn modular_transform_create_mAB(mut lut: &lutmABType) -> Option<Box<qcms_modular_transform>> {
let mut first_transform = None;
let mut next_transform = &mut first_transform;
let mut transform;
if !lut.a_curves[0].is_none() {
if lut.a_curves[0].is_some() {
let mut clut_length: usize;
// If the A curve is present this also implies the
// presence of a CLUT.
if lut.clut_table.is_none() {
return None;
}
lut.clut_table.as_ref()?;
// Prepare A curve.
transform = modular_transform_alloc();
if transform.is_none() {
return None;
}
transform.as_ref()?;
transform.as_mut().unwrap().input_clut_table_r =
build_input_gamma_table(lut.a_curves[0].as_deref());
transform.as_mut().unwrap().input_clut_table_g =
@ -627,9 +623,7 @@ fn modular_transform_create_mAB(mut lut: &lutmABType) -> Option<Box<qcms_modular
// Prepare CLUT
transform = modular_transform_alloc();
if transform.is_none() {
return None;
}
transform.as_ref()?;
clut_length = (lut.num_grid_points[0] as usize).pow(3) * 3;
assert_eq!(clut_length, lut.clut_table.as_ref().unwrap().len());
@ -639,14 +633,12 @@ fn modular_transform_create_mAB(mut lut: &lutmABType) -> Option<Box<qcms_modular
next_transform = append_transform(transform, next_transform);
}
if !lut.m_curves[0].is_none() {
if lut.m_curves[0].is_some() {
// M curve imples the presence of a Matrix
// Prepare M curve
transform = modular_transform_alloc();
if transform.is_none() {
return None;
}
transform.as_ref()?;
transform.as_mut().unwrap().input_clut_table_r =
build_input_gamma_table(lut.m_curves[0].as_deref());
transform.as_mut().unwrap().input_clut_table_g =
@ -658,9 +650,7 @@ fn modular_transform_create_mAB(mut lut: &lutmABType) -> Option<Box<qcms_modular
// Prepare Matrix
transform = modular_transform_alloc();
if transform.is_none() {
return None;
}
transform.as_ref()?;
transform.as_mut().unwrap().matrix = build_mAB_matrix(lut);
if transform.as_mut().unwrap().matrix.invalid {
return None;
@ -672,12 +662,10 @@ fn modular_transform_create_mAB(mut lut: &lutmABType) -> Option<Box<qcms_modular
next_transform = append_transform(transform, next_transform);
}
if !lut.b_curves[0].is_none() {
if lut.b_curves[0].is_some() {
// Prepare B curve
transform = modular_transform_alloc();
if transform.is_none() {
return None;
}
transform.as_ref()?;
transform.as_mut().unwrap().input_clut_table_r =
build_input_gamma_table(lut.b_curves[0].as_deref());
transform.as_mut().unwrap().input_clut_table_g =
@ -696,7 +684,7 @@ fn modular_transform_create_mAB(mut lut: &lutmABType) -> Option<Box<qcms_modular
// is reversed
first_transform = reverse_transform(first_transform)
}
return first_transform;
first_transform
}
fn modular_transform_create_lut(mut lut: &lutType) -> Option<Box<qcms_modular_transform>> {
@ -709,14 +697,14 @@ fn modular_transform_create_lut(mut lut: &lutType) -> Option<Box<qcms_modular_tr
let mut in_curves: *mut f32;
let mut out_curves: *mut f32;
let mut transform = modular_transform_alloc();
if !transform.is_none() {
if transform.is_some() {
transform.as_mut().unwrap().matrix = build_lut_matrix(Some(lut));
if !transform.as_mut().unwrap().matrix.invalid {
transform.as_mut().unwrap().transform_module_fn = Some(transform_module_matrix);
next_transform = append_transform(transform, next_transform);
// Prepare input curves
transform = modular_transform_alloc();
if !transform.is_none() {
if transform.is_some() {
transform.as_mut().unwrap().input_clut_table_r =
Some(lut.input_table[0..lut.num_input_table_entries as usize].to_vec());
transform.as_mut().unwrap().input_clut_table_g = Some(
@ -757,20 +745,20 @@ fn modular_transform_create_lut(mut lut: &lutType) -> Option<Box<qcms_modular_tr
}
}
modular_transform_release(first_transform);
return None;
None
}
fn modular_transform_create_input(mut in_0: &qcms_profile) -> Option<Box<qcms_modular_transform>> {
let mut first_transform = None;
let mut next_transform = &mut first_transform;
if !in_0.A2B0.is_none() {
if in_0.A2B0.is_some() {
let mut lut_transform = modular_transform_create_lut(in_0.A2B0.as_deref().unwrap());
if lut_transform.is_none() {
return None;
} else {
append_transform(lut_transform, next_transform);
}
} else if !in_0.mAB.is_none()
} else if in_0.mAB.is_some()
&& (*in_0.mAB.as_deref().unwrap()).num_in_channels as i32 == 3
&& (*in_0.mAB.as_deref().unwrap()).num_out_channels as i32 == 3
{
@ -804,15 +792,15 @@ fn modular_transform_create_input(mut in_0: &qcms_profile) -> Option<Box<qcms_mo
if transform.is_none() {
return None;
} else {
transform.as_mut().unwrap().matrix.m[0][0] = 1. / 1.999969482421875;
transform.as_mut().unwrap().matrix.m[0][0] = 1. / 1.999_969_5;
transform.as_mut().unwrap().matrix.m[0][1] = 0.0;
transform.as_mut().unwrap().matrix.m[0][2] = 0.0;
transform.as_mut().unwrap().matrix.m[1][0] = 0.0;
transform.as_mut().unwrap().matrix.m[1][1] = 1. / 1.999969482421875;
transform.as_mut().unwrap().matrix.m[1][1] = 1. / 1.999_969_5;
transform.as_mut().unwrap().matrix.m[1][2] = 0.0;
transform.as_mut().unwrap().matrix.m[2][0] = 0.0;
transform.as_mut().unwrap().matrix.m[2][1] = 0.0;
transform.as_mut().unwrap().matrix.m[2][2] = 1. / 1.999969482421875;
transform.as_mut().unwrap().matrix.m[2][2] = 1. / 1.999_969_5;
transform.as_mut().unwrap().matrix.invalid = false;
transform.as_mut().unwrap().transform_module_fn = Some(transform_module_matrix);
next_transform = append_transform(transform, next_transform);
@ -834,14 +822,14 @@ fn modular_transform_create_input(mut in_0: &qcms_profile) -> Option<Box<qcms_mo
fn modular_transform_create_output(mut out: &qcms_profile) -> Option<Box<qcms_modular_transform>> {
let mut first_transform = None;
let mut next_transform = &mut first_transform;
if !out.B2A0.is_none() {
if out.B2A0.is_some() {
let mut lut_transform = modular_transform_create_lut(out.B2A0.as_deref().unwrap());
if lut_transform.is_none() {
return None;
} else {
append_transform(lut_transform, next_transform);
}
} else if !out.mBA.is_none()
} else if out.mBA.is_some()
&& (*out.mBA.as_deref().unwrap()).num_in_channels as i32 == 3
&& (*out.mBA.as_deref().unwrap()).num_out_channels as i32 == 3
{
@ -851,7 +839,7 @@ fn modular_transform_create_output(mut out: &qcms_profile) -> Option<Box<qcms_mo
} else {
append_transform(lut_transform_0, next_transform);
}
} else if !out.redTRC.is_none() && !out.greenTRC.is_none() && !out.blueTRC.is_none() {
} else if out.redTRC.is_some() && out.greenTRC.is_some() && out.blueTRC.is_some() {
let mut transform = modular_transform_alloc();
if transform.is_none() {
return None;
@ -863,15 +851,15 @@ fn modular_transform_create_output(mut out: &qcms_profile) -> Option<Box<qcms_mo
if transform.is_none() {
return None;
} else {
transform.as_mut().unwrap().matrix.m[0][0] = 1.999969482421875;
transform.as_mut().unwrap().matrix.m[0][0] = 1.999_969_5;
transform.as_mut().unwrap().matrix.m[0][1] = 0.0;
transform.as_mut().unwrap().matrix.m[0][2] = 0.0;
transform.as_mut().unwrap().matrix.m[1][0] = 0.0;
transform.as_mut().unwrap().matrix.m[1][1] = 1.999969482421875;
transform.as_mut().unwrap().matrix.m[1][1] = 1.999_969_5;
transform.as_mut().unwrap().matrix.m[1][2] = 0.0;
transform.as_mut().unwrap().matrix.m[2][0] = 0.0;
transform.as_mut().unwrap().matrix.m[2][1] = 0.0;
transform.as_mut().unwrap().matrix.m[2][2] = 1.999969482421875;
transform.as_mut().unwrap().matrix.m[2][2] = 1.999_969_5;
transform.as_mut().unwrap().matrix.invalid = false;
transform.as_mut().unwrap().transform_module_fn = Some(transform_module_matrix);
next_transform = append_transform(transform, next_transform);
@ -963,9 +951,7 @@ fn modular_transform_create(
let mut next_transform = &mut first_transform;
if in_0.color_space == RGB_SIGNATURE {
let mut rgb_to_pcs = modular_transform_create_input(in_0);
if rgb_to_pcs.is_none() {
return None;
}
rgb_to_pcs.as_ref()?;
next_transform = append_transform(rgb_to_pcs, next_transform);
} else {
debug_assert!(false, "input color space not supported");
@ -974,9 +960,7 @@ fn modular_transform_create(
if in_0.pcs == LAB_SIGNATURE && out.pcs == XYZ_SIGNATURE {
let mut lab_to_pcs = modular_transform_alloc();
if lab_to_pcs.is_none() {
return None;
}
lab_to_pcs.as_ref()?;
lab_to_pcs.as_mut().unwrap().transform_module_fn = Some(transform_module_LAB_to_XYZ);
next_transform = append_transform(lab_to_pcs, next_transform);
}
@ -994,18 +978,14 @@ fn modular_transform_create(
if in_0.pcs == XYZ_SIGNATURE && out.pcs == LAB_SIGNATURE {
let mut pcs_to_lab = modular_transform_alloc();
if pcs_to_lab.is_none() {
return None;
}
pcs_to_lab.as_ref()?;
pcs_to_lab.as_mut().unwrap().transform_module_fn = Some(transform_module_XYZ_to_LAB);
next_transform = append_transform(pcs_to_lab, next_transform);
}
if out.color_space == RGB_SIGNATURE {
let mut pcs_to_rgb = modular_transform_create_output(out);
if pcs_to_rgb.is_none() {
return None;
}
pcs_to_rgb.as_ref()?;
append_transform(pcs_to_rgb, next_transform);
} else {
debug_assert!(false, "output color space not supported");
@ -1013,7 +993,7 @@ fn modular_transform_create(
// Not Completed
//return qcms_modular_transform_reduce(first_transform);
return first_transform;
first_transform
}
fn modular_transform_data(
mut transform: Option<&qcms_modular_transform>,
@ -1021,7 +1001,7 @@ fn modular_transform_data(
mut dest: Vec<f32>,
mut len: usize,
) -> Option<Vec<f32>> {
while !transform.is_none() {
while transform.is_some() {
// Keep swaping src/dest when performing a transform to use less memory.
let transform_fn: transform_module_fn_t = transform.unwrap().transform_module_fn;
transform
@ -1034,7 +1014,7 @@ fn modular_transform_data(
transform = transform.unwrap().next_transform.as_deref();
}
// The results end up in the src buffer because of the switching
return Some(src);
Some(src)
}
pub fn chain_transform(
@ -1045,10 +1025,10 @@ pub fn chain_transform(
mut lutSize: usize,
) -> Option<Vec<f32>> {
let mut transform_list = modular_transform_create(in_0, out);
if !transform_list.is_none() {
if transform_list.is_some() {
let mut lut = modular_transform_data(transform_list.as_deref(), src, dest, lutSize / 3);
modular_transform_release(transform_list);
return lut;
}
return None;
None
}

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

@ -549,7 +549,7 @@ mod test {
qcms_transform_release(self.transform)
}
self.transform = transform;
!(self.transform == null_mut())
self.transform != null_mut()
}
unsafe fn SetTransformForType(&mut self, ty: qcms_data_type) -> bool {
@ -630,16 +630,16 @@ mod test {
unsafe fn VerifyOutput(&self, buf: &[u8]) -> bool {
match self.storage_type {
DATA_RGB_8 => return CmpRgbBuffer(buf, &self.output, self.pixels),
DATA_RGBA_8 => return CmpRgbaBuffer(buf, &self.output, self.pixels),
DATA_BGRA_8 => return CmpBgraBuffer(buf, &self.output, self.pixels),
DATA_RGB_8 => CmpRgbBuffer(buf, &self.output, self.pixels),
DATA_RGBA_8 => CmpRgbaBuffer(buf, &self.output, self.pixels),
DATA_BGRA_8 => CmpBgraBuffer(buf, &self.output, self.pixels),
_ => unreachable!("Unknown type!"),
}
}
unsafe fn ProduceVerifyOutput(&mut self, trans_fn: transform_fn_t) -> bool {
self.ProduceOutput(trans_fn);
return self.VerifyOutput(&self.reference);
self.VerifyOutput(&self.reference)
}
unsafe fn PrecacheOutput(&mut self) {

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

@ -197,12 +197,12 @@ struct mem_source<'a> {
pub type uInt8Number = u8;
#[inline]
fn uInt8Number_to_float(mut a: uInt8Number) -> f32 {
return a as i32 as f32 / 255.0;
a as i32 as f32 / 255.0
}
#[inline]
fn uInt16Number_to_float(mut a: uInt16Number) -> f32 {
return a as i32 as f32 / 65535.0;
a as i32 as f32 / 65535.0
}
fn cpu_to_be32(mut v: u32) -> be32 {
@ -227,41 +227,41 @@ fn read_u32(mut mem: &mut mem_source, mut offset: usize) -> u32 {
* mem->size is guaranteed to be > 4 */
if offset > mem.buf.len() - 4 {
invalid_source(mem, "Invalid offset");
return 0;
0
} else {
let k = unsafe {
std::ptr::read_unaligned(mem.buf.as_ptr().offset(offset as isize) as *const be32)
std::ptr::read_unaligned(mem.buf.as_ptr().add(offset) as *const be32)
};
return be32_to_cpu(k);
be32_to_cpu(k)
}
}
fn read_u16(mut mem: &mut mem_source, mut offset: usize) -> u16 {
if offset > mem.buf.len() - 2 {
invalid_source(mem, "Invalid offset");
return 0u16;
0u16
} else {
let k = unsafe {
std::ptr::read_unaligned(mem.buf.as_ptr().offset(offset as isize) as *const be16)
std::ptr::read_unaligned(mem.buf.as_ptr().add(offset) as *const be16)
};
return be16_to_cpu(k);
be16_to_cpu(k)
}
}
fn read_u8(mut mem: &mut mem_source, mut offset: usize) -> u8 {
if offset > mem.buf.len() - 1 {
invalid_source(mem, "Invalid offset");
return 0u8;
0u8
} else {
return unsafe { *(mem.buf.as_ptr().offset(offset as isize) as *mut u8) };
unsafe { *(mem.buf.as_ptr().add(offset) as *mut u8) }
}
}
fn read_s15Fixed16Number(mut mem: &mut mem_source, mut offset: usize) -> s15Fixed16Number {
return read_u32(mem, offset) as s15Fixed16Number;
read_u32(mem, offset) as s15Fixed16Number
}
fn read_uInt8Number(mut mem: &mut mem_source, mut offset: usize) -> uInt8Number {
return read_u8(mem, offset);
read_u8(mem, offset)
}
fn read_uInt16Number(mut mem: &mut mem_source, mut offset: usize) -> uInt16Number {
return read_u16(mem, offset);
read_u16(mem, offset)
}
fn write_u32(mut mem: &mut [u8], mut offset: usize, mut value: u32) {
if offset <= mem.len() - std::mem::size_of_val(&value) {
@ -269,7 +269,7 @@ fn write_u32(mut mem: &mut [u8], mut offset: usize, mut value: u32) {
}
let mem = mem.as_mut_ptr();
unsafe {
std::ptr::write_unaligned(mem.offset(offset as isize) as *mut u32, cpu_to_be32(value));
std::ptr::write_unaligned(mem.add(offset) as *mut u32, cpu_to_be32(value));
}
}
fn write_u16(mut mem: &mut [u8], mut offset: usize, mut value: u16) {
@ -278,7 +278,7 @@ fn write_u16(mut mem: &mut [u8], mut offset: usize, mut value: u16) {
}
let mem = mem.as_mut_ptr();
unsafe {
std::ptr::write_unaligned(mem.offset(offset as isize) as *mut u16, cpu_to_be16(value));
std::ptr::write_unaligned(mem.add(offset) as *mut u16, cpu_to_be16(value));
}
}
@ -461,10 +461,10 @@ pub extern "C" fn qcms_profile_is_bogus(mut profile: &mut qcms_profile) -> bool
if profile.color_space != RGB_SIGNATURE {
return false;
}
if !profile.A2B0.is_none()
|| !profile.B2A0.is_none()
|| !profile.mAB.is_none()
|| !profile.mBA.is_none()
if profile.A2B0.is_some()
|| profile.B2A0.is_some()
|| profile.mAB.is_some()
|| profile.mBA.is_some()
{
return false;
}
@ -500,7 +500,7 @@ pub extern "C" fn qcms_profile_is_bogus(mut profile: &mut qcms_profile) -> bool
{
return true;
}
i = i + 1
i += 1
}
if !cfg!(target_os = "macos") {
negative = (rX < 0.)
@ -526,7 +526,7 @@ pub extern "C" fn qcms_profile_is_bogus(mut profile: &mut qcms_profile) -> bool
return true;
}
// All Good
return false;
false
}
const TAG_bXYZ: u32 = 0x6258595a;
@ -581,14 +581,14 @@ fn read_tag_s15Fixed16ArrayType(
matrix.m[(i as i32 / 3) as usize][(i as i32 % 3) as usize] = s15Fixed16Number_to_float(
read_s15Fixed16Number(src, (offset + 8 + (i as i32 * 4) as libc::c_uint) as usize),
);
i = i + 1
i += 1
}
matrix.invalid = false
} else {
matrix.invalid = true;
invalid_source(src, "missing sf32tag");
}
return matrix;
matrix
}
fn read_tag_XYZType(mut src: &mut mem_source, mut index: &tag_index, mut tag_id: u32) -> XYZNumber {
let mut num: XYZNumber = {
@ -608,7 +608,7 @@ fn read_tag_XYZType(mut src: &mut mem_source, mut index: &tag_index, mut tag_id:
} else {
invalid_source(src, "missing xyztag");
}
return num;
num
}
// Read the tag at a given offset rather then the tag_index.
// This method is used when reading mAB tags where nested curveType are
@ -639,7 +639,7 @@ fn read_curveType(
table.push(read_u16(src, (offset + 12 + i * 2) as usize));
}
*len = 12 + count * 2;
return Some(Box::new(curveType::Curve(table)));
Some(Box::new(curveType::Curve(table)))
} else {
count = read_u16(src, (offset + 8) as usize) as u32;
if count > 4 {
@ -661,7 +661,7 @@ fn read_curveType(
invalid_source(src, "parametricCurve definition causes division by zero");
}
}
return Some(Box::new(curveType::Parametric(params)));
Some(Box::new(curveType::Parametric(params)))
}
}
fn read_tag_curveType(
@ -676,7 +676,7 @@ fn read_tag_curveType(
} else {
invalid_source(src, "missing curvetag");
}
return None;
None
}
// arbitrary
fn read_nested_curveType(
@ -695,10 +695,10 @@ fn read_nested_curveType(
invalid_source(src, "invalid nested curveType curve");
break;
} else {
channel_offset = channel_offset + tag_len;
channel_offset += tag_len;
// 4 byte aligned
if tag_len % 4 != 0 {
channel_offset = channel_offset + (4 - tag_len % 4)
channel_offset += 4 - tag_len % 4
}
i += 1
}
@ -745,36 +745,36 @@ fn read_tag_lutmABType(mut src: &mut mem_source, mut tag: &tag) -> Option<Box<lu
// Convert offsets relative to the tag to relative to the profile
// preserve zero for optional fields
if a_curve_offset != 0 {
a_curve_offset = a_curve_offset + offset
a_curve_offset += offset
}
if clut_offset != 0 {
clut_offset = clut_offset + offset
clut_offset += offset
}
if m_curve_offset != 0 {
m_curve_offset = m_curve_offset + offset
m_curve_offset += offset
}
if matrix_offset != 0 {
matrix_offset = matrix_offset + offset
matrix_offset += offset
}
if b_curve_offset != 0 {
b_curve_offset = b_curve_offset + offset
b_curve_offset += offset
}
if clut_offset != 0 {
debug_assert!(num_in_channels as i32 == 3);
// clut_size can not overflow since lg(256^num_in_channels) = 24 bits.
i = 0;
while i < num_in_channels as libc::c_uint {
clut_size = clut_size * read_u8(src, (clut_offset + i) as usize) as libc::c_uint;
clut_size *= read_u8(src, (clut_offset + i) as usize) as libc::c_uint;
if clut_size == 0 {
invalid_source(src, "bad clut_size");
}
i = i + 1
i += 1
}
} else {
clut_size = 0
}
// 24bits * 3 won't overflow either
clut_size = clut_size * num_out_channels as libc::c_uint;
clut_size *= num_out_channels as libc::c_uint;
if clut_size > 500000 {
return None;
}
@ -788,7 +788,7 @@ fn read_tag_lutmABType(mut src: &mut mem_source, mut tag: &tag) -> Option<Box<lu
if lut.num_grid_points[i as usize] as i32 == 0 {
invalid_source(src, "bad grid_points");
}
i = i + 1
i += 1
}
}
// Reverse the processing of transformation elements for mBA type.
@ -847,7 +847,7 @@ fn read_tag_lutmABType(mut src: &mut mem_source, mut tag: &tag) -> Option<Box<lu
if !src.valid {
return None;
}
return Some(lut);
Some(lut)
}
fn read_tag_lutType(mut src: &mut mem_source, mut tag: &tag) -> Option<Box<lutType>> {
let mut offset: u32 = tag.offset;
@ -982,8 +982,8 @@ fn read_tag_lutType(mut src: &mut mem_source, mut tag: &tag) -> Option<Box<lutTy
}
}
Some(Box::new(lutType {
num_input_table_entries: num_input_table_entries,
num_output_table_entries: num_output_table_entries,
num_input_table_entries,
num_output_table_entries,
num_input_channels: in_chan,
num_output_channels: out_chan,
num_clut_grid_points: grid_points,
@ -1056,18 +1056,18 @@ fn build_sRGB_gamma_table(mut num_entries: i32) -> Vec<u16> {
}
table.push(output.floor() as u16);
}
return table;
table
}
fn curve_from_table(mut table: &[u16]) -> Box<curveType> {
return Box::new(curveType::Curve(table.to_vec()));
Box::new(curveType::Curve(table.to_vec()))
}
fn float_to_u8Fixed8Number(mut a: f32) -> u16 {
if a > 255.0 + 255.0 / 256f32 {
return 0xffffu16;
0xffffu16
} else if a < 0.0 {
return 0u16;
0u16
} else {
return (a * 256.0 + 0.5).floor() as u16;
(a * 256.0 + 0.5).floor() as u16
}
}
@ -1125,11 +1125,11 @@ fn white_point_from_temp(mut temp_K: i32) -> qcms_CIE_xyY {
white_point.x = x;
white_point.y = y;
white_point.Y = 1.0f64;
return white_point;
white_point
}
#[no_mangle]
pub extern "C" fn qcms_white_point_sRGB() -> qcms_CIE_xyY {
return white_point_from_temp(6504);
white_point_from_temp(6504)
}
impl qcms_profile {
@ -1154,7 +1154,7 @@ impl qcms_profile {
profile.rendering_intent = QCMS_INTENT_PERCEPTUAL;
profile.color_space = RGB_SIGNATURE;
profile.pcs = XYZ_TYPE;
return Some(profile);
Some(profile)
}
pub fn new_sRGB() -> Box<qcms_profile> {
let Rec709Primaries = qcms_CIE_xyYTRIPLE {
@ -1316,9 +1316,7 @@ impl qcms_profile {
}
} else if profile.color_space == GRAY_SIGNATURE {
profile.grayTRC = read_tag_curveType(src, &index, TAG_kTRC);
if profile.grayTRC.is_none() {
return None;
}
profile.grayTRC.as_ref()?;
} else {
debug_assert!(false, "read_color_space protects against entering here");
return None;
@ -1363,7 +1361,7 @@ pub unsafe extern "C" fn qcms_data_create_rgb_with_gamma(
if mem.is_null() || size.is_null() {
return;
}
*mem = 0 as *mut libc::c_void;
*mem = std::ptr::null_mut::<libc::c_void>();
*size = 0;
/*
* total length = icc profile header(128) + tag count(4) +
@ -1413,9 +1411,9 @@ pub unsafe extern "C" fn qcms_data_create_rgb_with_gamma(
tag_data_offset + 16,
double_to_s15Fixed16Number(colorants.m[2][index as usize] as f64) as u32,
);
tag_table_offset = tag_table_offset + 12;
tag_data_offset = tag_data_offset + 20;
index = index + 1
tag_table_offset += 12;
tag_data_offset += 20;
index += 1
}
// Part2 : write rTRC, gTRC and bTRC
index = 0;
@ -1429,9 +1427,9 @@ pub unsafe extern "C" fn qcms_data_create_rgb_with_gamma(
// reserved 4 bytes.
write_u32(data, tag_data_offset + 8, 1); // count
write_u16(data, tag_data_offset + 12, float_to_u8Fixed8Number(gamma));
tag_table_offset = tag_table_offset + 12;
tag_data_offset = tag_data_offset + 16;
index = index + 1
tag_table_offset += 12;
tag_data_offset += 16;
index += 1
}
/* Part3 : write profile header
*

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

@ -38,12 +38,12 @@ pub(crate) type s15Fixed16Number = i32;
* of 1/1024 which happens for large values like 0x40000040 */
#[inline]
fn s15Fixed16Number_to_float(mut a: s15Fixed16Number) -> f32 {
return a as f32 / 65536.0;
a as f32 / 65536.0
}
#[inline]
fn double_to_s15Fixed16Number(mut v: f64) -> s15Fixed16Number {
return (v * 65536f64) as i32;
(v * 65536f64) as i32
}
pub mod c_bindings;

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

@ -39,7 +39,7 @@ pub fn matrix_eval(mut mat: matrix, mut v: vector) -> vector {
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];
return result;
result
}
//XXX: should probably pass by reference and we could
//probably reuse this computation in matrix_invert
@ -50,7 +50,7 @@ pub fn matrix_det(mut mat: matrix) -> f32 {
- mat.m[0][0] * mat.m[1][2] * mat.m[2][1]
- mat.m[0][1] * mat.m[1][0] * mat.m[2][2]
- mat.m[0][2] * mat.m[1][1] * mat.m[2][0];
return det;
det
}
/* from pixman and cairo and Mathematics for Game Programmers */
/* lcms uses gauss-jordan elimination with partial pivoting which is
@ -92,7 +92,7 @@ pub fn matrix_invert(mut mat: matrix) -> matrix {
}
j += 1
}
return dest_mat;
dest_mat
}
pub fn matrix_identity() -> matrix {
let mut i: matrix = matrix {
@ -109,12 +109,12 @@ pub fn matrix_identity() -> matrix {
i.m[2][1] = 0.;
i.m[2][2] = 1.;
i.invalid = false;
return i;
i
}
pub fn matrix_invalid() -> matrix {
let mut inv: matrix = matrix_identity();
inv.invalid = true;
return inv;
inv
}
/* from pixman */
/* MAT3per... */
@ -142,5 +142,5 @@ pub fn matrix_multiply(mut a: matrix, mut b: matrix) -> matrix {
dy += 1
}
result.invalid = a.invalid as i32 != 0 || b.invalid as i32 != 0;
return result;
result
}

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

@ -203,11 +203,11 @@ impl GrayFormat for GrayAlpha {
#[inline]
fn clamp_u8(mut v: f32) -> u8 {
if v > 255. {
return 255;
255
} else if v < 0. {
return 0;
0
} else {
return (v + 0.5).floor() as u8;
(v + 0.5).floor() as u8
}
}
@ -278,7 +278,7 @@ fn build_RGB_to_XYZ_transfer_matrix(
result.m[2][1] = (coefs.v[1] as f64 * (1.0f64 - xg - yg)) as f32;
result.m[2][2] = (coefs.v[2] as f64 * (1.0f64 - xb - yb)) as f32;
result.invalid = primaries_invert.invalid;
return result;
result
}
/* CIE Illuminant D50 */
const D50_XYZ: CIE_XYZ = CIE_XYZ {
@ -297,7 +297,7 @@ fn xyY2XYZ(mut source: qcms_CIE_xyY) -> CIE_XYZ {
dest.X = source.x / source.y * source.Y;
dest.Y = source.Y;
dest.Z = (1f64 - source.x - source.y) / source.y * source.Y;
return dest;
dest
}
/* from lcms: ComputeChromaticAdaption */
// Compute chromatic adaption matrix using chad as cone matrix
@ -340,7 +340,7 @@ fn compute_chromatic_adaption(
cone.m[2][2] = cone_dest_rgb.v[2] / cone_source_rgb.v[2];
cone.invalid = false;
// Normalize
return matrix_multiply(chad_inv, matrix_multiply(cone, chad));
matrix_multiply(chad_inv, matrix_multiply(cone, chad))
}
/* from lcms: cmsAdaptionMatrix */
// Returns the final chrmatic adaptation from illuminant FromIll to Illuminant ToIll
@ -357,7 +357,7 @@ fn adaption_matrix(mut source_illumination: CIE_XYZ, mut target_illumination: CI
};
init
};
return compute_chromatic_adaption(source_illumination, target_illumination, lam_rigg);
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 {
@ -370,7 +370,7 @@ fn adapt_matrix_to_D50(mut r: matrix, mut source_white_pt: qcms_CIE_xyY) -> matr
if Bradford.invalid {
return matrix_invalid();
}
return matrix_multiply(Bradford, r);
matrix_multiply(Bradford, r)
}
pub(crate) fn set_rgb_colorants(
mut profile: &mut qcms_profile,
@ -392,7 +392,7 @@ pub(crate) fn set_rgb_colorants(
profile.blueColorant.X = double_to_s15Fixed16Number(colorants.m[0][2] as f64);
profile.blueColorant.Y = double_to_s15Fixed16Number(colorants.m[1][2] as f64);
profile.blueColorant.Z = double_to_s15Fixed16Number(colorants.m[2][2] as f64);
return true;
true
}
pub(crate) fn get_rgb_colorants(
mut colorants: &mut matrix,
@ -401,7 +401,7 @@ pub(crate) fn get_rgb_colorants(
) -> bool {
*colorants = build_RGB_to_XYZ_transfer_matrix(white_point, primaries);
*colorants = adapt_matrix_to_D50(*colorants, white_point);
return if colorants.invalid { true } else { false };
colorants.invalid
}
/* Alpha is not corrected.
A rationale for this is found in Alvy Ray's "Should Alpha Be Nonlinear If
@ -446,14 +446,14 @@ unsafe extern "C" fn qcms_transform_data_gray_template_lut<I: GrayFormat, F: For
linear as f64,
&(*transform).output_gamma_lut_b.as_ref().unwrap(),
);
*dest.offset(F::kRIndex as isize) = clamp_u8(out_device_r * 255f32);
*dest.offset(F::kGIndex as isize) = clamp_u8(out_device_g * 255f32);
*dest.offset(F::kBIndex as isize) = clamp_u8(out_device_b * 255f32);
*dest.add(F::kRIndex) = clamp_u8(out_device_r * 255f32);
*dest.add(F::kGIndex) = clamp_u8(out_device_g * 255f32);
*dest.add(F::kBIndex) = clamp_u8(out_device_b * 255f32);
if F::kAIndex != 0xff {
*dest.offset(F::kAIndex as isize) = alpha
*dest.add(F::kAIndex) = alpha
}
dest = dest.offset(components as isize);
i = i + 1
i += 1
}
}
unsafe extern "C" fn qcms_transform_data_gray_out_lut(
@ -528,14 +528,14 @@ unsafe extern "C" fn qcms_transform_data_gray_template_precache<I: GrayFormat, F
let mut linear: f32 = *input_gamma_table_gray.offset(device as isize);
/* we could round here... */
let mut gray: u16 = (linear * PRECACHE_OUTPUT_MAX as f32) as u16;
*dest.offset(F::kRIndex as isize) = (output_table_r).data[gray as usize];
*dest.offset(F::kGIndex as isize) = (output_table_g).data[gray as usize];
*dest.offset(F::kBIndex as isize) = (output_table_b).data[gray as usize];
*dest.add(F::kRIndex) = (output_table_r).data[gray as usize];
*dest.add(F::kGIndex) = (output_table_g).data[gray as usize];
*dest.add(F::kBIndex) = (output_table_b).data[gray as usize];
if F::kAIndex != 0xff {
*dest.offset(F::kAIndex as isize) = alpha
*dest.add(F::kAIndex) = alpha
}
dest = dest.offset(components as isize);
i = i + 1
i += 1
}
}
unsafe extern "C" fn qcms_transform_data_gray_out_precache(
@ -595,12 +595,12 @@ unsafe extern "C" fn qcms_transform_data_template_lut_precache<F: Format>(
let mut mat: *const [f32; 4] = (*transform).matrix.as_ptr();
let mut i: libc::c_uint = 0;
while (i as usize) < length {
let mut device_r: libc::c_uchar = *src.offset(F::kRIndex as isize);
let mut device_g: libc::c_uchar = *src.offset(F::kGIndex as isize);
let mut device_b: libc::c_uchar = *src.offset(F::kBIndex as isize);
let mut device_r: libc::c_uchar = *src.add(F::kRIndex);
let mut device_g: libc::c_uchar = *src.add(F::kGIndex);
let mut device_b: libc::c_uchar = *src.add(F::kBIndex);
let mut alpha: libc::c_uchar = 0;
if F::kAIndex != 0xff {
alpha = *src.offset(F::kAIndex as isize)
alpha = *src.add(F::kAIndex)
}
src = src.offset(components as isize);
@ -624,14 +624,14 @@ unsafe extern "C" fn qcms_transform_data_template_lut_precache<F: Format>(
let mut r: u16 = (out_linear_r * PRECACHE_OUTPUT_MAX as f32) as u16;
let mut g: u16 = (out_linear_g * PRECACHE_OUTPUT_MAX as f32) as u16;
let mut b: u16 = (out_linear_b * PRECACHE_OUTPUT_MAX as f32) as u16;
*dest.offset(F::kRIndex as isize) = (output_table_r).data[r as usize];
*dest.offset(F::kGIndex as isize) = (output_table_g).data[g as usize];
*dest.offset(F::kBIndex as isize) = (output_table_b).data[b as usize];
*dest.add(F::kRIndex) = (output_table_r).data[r as usize];
*dest.add(F::kGIndex) = (output_table_g).data[g as usize];
*dest.add(F::kBIndex) = (output_table_b).data[b as usize];
if F::kAIndex != 0xff {
*dest.offset(F::kAIndex as isize) = alpha
*dest.add(F::kAIndex) = alpha
}
dest = dest.offset(components as isize);
i = i + 1
i += 1
}
}
#[no_mangle]
@ -719,7 +719,7 @@ static void qcms_transform_data_clut(const qcms_transform *transform, const unsi
}
*/
fn int_div_ceil(mut value: i32, mut div: i32) -> i32 {
return (value + div - 1) / div;
(value + div - 1) / div
}
// Using lcms' tetra interpolation algorithm.
unsafe extern "C" fn qcms_transform_data_tetra_clut_template<F: Format>(
@ -754,12 +754,12 @@ unsafe extern "C" fn qcms_transform_data_tetra_clut_template<F: Format>(
let mut clut_b: f32;
let mut i: libc::c_uint = 0;
while (i as usize) < length {
let mut in_r: libc::c_uchar = *src.offset(F::kRIndex as isize);
let mut in_g: libc::c_uchar = *src.offset(F::kGIndex as isize);
let mut in_b: libc::c_uchar = *src.offset(F::kBIndex as isize);
let mut in_r: libc::c_uchar = *src.add(F::kRIndex);
let mut in_g: libc::c_uchar = *src.add(F::kGIndex);
let mut in_b: libc::c_uchar = *src.add(F::kBIndex);
let mut in_a: libc::c_uchar = 0;
if F::kAIndex != 0xff {
in_a = *src.offset(F::kAIndex as isize)
in_a = *src.add(F::kAIndex)
}
src = src.offset(components as isize);
let mut linear_r: f32 = in_r as i32 as f32 / 255.0;
@ -883,14 +883,14 @@ unsafe extern "C" fn qcms_transform_data_tetra_clut_template<F: Format>(
clut_r = c0_r + c1_r * rx + c2_r * ry + c3_r * rz;
clut_g = c0_g + c1_g * rx + c2_g * ry + c3_g * rz;
clut_b = c0_b + c1_b * rx + c2_b * ry + c3_b * rz;
*dest.offset(F::kRIndex as isize) = clamp_u8(clut_r * 255.0);
*dest.offset(F::kGIndex as isize) = clamp_u8(clut_g * 255.0);
*dest.offset(F::kBIndex as isize) = clamp_u8(clut_b * 255.0);
*dest.add(F::kRIndex) = clamp_u8(clut_r * 255.0);
*dest.add(F::kGIndex) = clamp_u8(clut_g * 255.0);
*dest.add(F::kBIndex) = clamp_u8(clut_b * 255.0);
if F::kAIndex != 0xff {
*dest.offset(F::kAIndex as isize) = in_a
*dest.add(F::kAIndex) = in_a
}
dest = dest.offset(components as isize);
i = i + 1
i += 1
}
}
unsafe extern "C" fn qcms_transform_data_tetra_clut_rgb(
@ -931,12 +931,12 @@ unsafe extern "C" fn qcms_transform_data_template_lut<F: Format>(
let input_gamma_table_g = (*transform).input_gamma_table_g.as_ref().unwrap().as_ptr();
let input_gamma_table_b = (*transform).input_gamma_table_b.as_ref().unwrap().as_ptr();
while (i as usize) < length {
let mut device_r: libc::c_uchar = *src.offset(F::kRIndex as isize);
let mut device_g: libc::c_uchar = *src.offset(F::kGIndex as isize);
let mut device_b: libc::c_uchar = *src.offset(F::kBIndex as isize);
let mut device_r: libc::c_uchar = *src.add(F::kRIndex);
let mut device_g: libc::c_uchar = *src.add(F::kGIndex);
let mut device_b: libc::c_uchar = *src.add(F::kBIndex);
let mut alpha: libc::c_uchar = 0;
if F::kAIndex != 0xff {
alpha = *src.offset(F::kAIndex as isize)
alpha = *src.add(F::kAIndex)
}
src = src.offset(components as isize);
@ -968,14 +968,14 @@ unsafe extern "C" fn qcms_transform_data_template_lut<F: Format>(
out_linear_b as f64,
(*transform).output_gamma_lut_b.as_ref().unwrap(),
);
*dest.offset(F::kRIndex as isize) = clamp_u8(out_device_r * 255f32);
*dest.offset(F::kGIndex as isize) = clamp_u8(out_device_g * 255f32);
*dest.offset(F::kBIndex as isize) = clamp_u8(out_device_b * 255f32);
*dest.add(F::kRIndex) = clamp_u8(out_device_r * 255f32);
*dest.add(F::kGIndex) = clamp_u8(out_device_g * 255f32);
*dest.add(F::kBIndex) = clamp_u8(out_device_b * 255f32);
if F::kAIndex != 0xff {
*dest.offset(F::kAIndex as isize) = alpha
*dest.add(F::kAIndex) = alpha
}
dest = dest.offset(components as isize);
i = i + 1
i += 1
}
}
#[no_mangle]
@ -1052,10 +1052,10 @@ fn compute_whitepoint_adaption(mut X: f32, mut Y: f32, mut Z: f32) -> matrix {
m: [[p, 0., 0.], [0., y, 0.], [0., 0., b]],
invalid: false,
};
return matrix_multiply(
matrix_multiply(
bradford_matrix_inv,
matrix_multiply(white_adaption, bradford_matrix),
);
)
}
#[no_mangle]
pub extern "C" fn qcms_profile_precache_output_transform(mut profile: &mut qcms_profile) {
@ -1065,11 +1065,11 @@ pub extern "C" fn qcms_profile_precache_output_transform(mut profile: &mut qcms_
}
if qcms_supports_iccv4.load(Ordering::Relaxed) {
/* don't precache since we will use the B2A LUT */
if !profile.B2A0.is_none() {
if profile.B2A0.is_some() {
return;
}
/* don't precache since we will use the mBA LUT */
if !profile.mBA.is_none() {
if profile.mBA.is_some() {
return;
}
}
@ -1148,7 +1148,7 @@ fn transform_precacheLUT_float(
return None;
}
return Some(transform);
Some(transform)
}
pub fn transform_create(
@ -1163,14 +1163,8 @@ pub fn transform_create(
(DATA_RGB_8, DATA_RGB_8) => true,
(DATA_RGBA_8, DATA_RGBA_8) => true,
(DATA_BGRA_8, DATA_BGRA_8) => true,
(DATA_GRAY_8, out_type) => match out_type {
DATA_RGB_8 | DATA_RGBA_8 | DATA_BGRA_8 => true,
_ => false,
},
(DATA_GRAYA_8, out_type) => match out_type {
DATA_RGBA_8 | DATA_BGRA_8 => true,
_ => false,
},
(DATA_GRAY_8, out_type) => matches!(out_type, DATA_RGB_8 | DATA_RGBA_8 | DATA_BGRA_8),
(DATA_GRAYA_8, out_type) => matches!(out_type, DATA_RGBA_8 | DATA_BGRA_8),
_ => false,
};
if !matching_format {
@ -1179,19 +1173,19 @@ pub fn transform_create(
}
let mut transform: Box<qcms_transform> = Box::new(Default::default());
let mut precache: bool = false;
if !out.output_table_r.is_none()
&& !out.output_table_g.is_none()
&& !out.output_table_b.is_none()
if out.output_table_r.is_some()
&& out.output_table_g.is_some()
&& out.output_table_b.is_some()
{
precache = true
}
// This precache assumes RGB_SIGNATURE (fails on GRAY_SIGNATURE, for instance)
if qcms_supports_iccv4.load(Ordering::Relaxed) as i32 != 0
&& (in_type == DATA_RGB_8 || in_type == DATA_RGBA_8 || in_type == DATA_BGRA_8)
&& (!in_0.A2B0.is_none()
|| !out.B2A0.is_none()
|| !in_0.mAB.is_none()
|| !out.mAB.is_none())
&& (in_0.A2B0.is_some()
|| out.B2A0.is_some()
|| in_0.mAB.is_some()
|| out.mAB.is_some())
{
// Precache the transformation to a CLUT 33x33x33 in size.
// 33 is used by many profiles and works well in pratice.
@ -1301,9 +1295,9 @@ pub fn transform_create(
if result_0.m[i as usize][j as usize] != result_0.m[i as usize][j as usize] {
return None;
}
j = j + 1
j += 1
}
i = i + 1
i += 1
}
/* store the results in column major mode
* this makes doing the multiplication with sse easier */
@ -1318,9 +1312,7 @@ pub fn transform_create(
transform.matrix[2][2] = result_0.m[2][2]
} else if in_0.color_space == GRAY_SIGNATURE {
transform.input_gamma_table_gray = build_input_gamma_table(in_0.grayTRC.as_deref());
if transform.input_gamma_table_gray.is_none() {
return None;
}
transform.input_gamma_table_gray.as_ref()?;
if precache {
if out_type == DATA_RGB_8 {
transform.transform_fn = Some(qcms_transform_data_gray_out_precache)
@ -1357,7 +1349,7 @@ pub fn transform_create(
return None;
}
debug_assert!(transform.transform_fn.is_some());
return Some(transform);
Some(transform)
}
#[no_mangle]
pub unsafe extern "C" fn qcms_transform_data(

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

@ -84,24 +84,24 @@ unsafe extern "C" fn qcms_transform_data_template_lut_avx<F: Format>(
/* If there are at least 2 pixels, then we can load their components into
a single 256-bit register for processing. */
if length > 1 {
vec_r0 = _mm_broadcast_ss(&*igtbl_r.offset(*src.offset(F::kRIndex as isize) as isize));
vec_g0 = _mm_broadcast_ss(&*igtbl_g.offset(*src.offset(F::kGIndex as isize) as isize));
vec_b0 = _mm_broadcast_ss(&*igtbl_b.offset(*src.offset(F::kBIndex as isize) as isize));
vec_r0 = _mm_broadcast_ss(&*igtbl_r.offset(*src.add(F::kRIndex) as isize));
vec_g0 = _mm_broadcast_ss(&*igtbl_g.offset(*src.add(F::kGIndex) as isize));
vec_b0 = _mm_broadcast_ss(&*igtbl_b.offset(*src.add(F::kBIndex) as isize));
vec_r1 = _mm_broadcast_ss(
&*igtbl_r.offset(*src.offset((F::kRIndex + components as usize) as isize) as isize),
&*igtbl_r.offset(*src.add(F::kRIndex + components as usize) as isize),
);
vec_g1 = _mm_broadcast_ss(
&*igtbl_g.offset(*src.offset((F::kGIndex + components as usize) as isize) as isize),
&*igtbl_g.offset(*src.add(F::kGIndex + components as usize) as isize),
);
vec_b1 = _mm_broadcast_ss(
&*igtbl_b.offset(*src.offset((F::kBIndex + components as usize) as isize) as isize),
&*igtbl_b.offset(*src.add(F::kBIndex + components as usize) as isize),
);
vec_r = _mm256_insertf128_ps(_mm256_castps128_ps256(vec_r0), vec_r1, 1);
vec_g = _mm256_insertf128_ps(_mm256_castps128_ps256(vec_g0), vec_g1, 1);
vec_b = _mm256_insertf128_ps(_mm256_castps128_ps256(vec_b0), vec_b1, 1);
if F::kAIndex != 0xff {
alpha1 = *src.offset(F::kAIndex as isize);
alpha2 = *src.offset((F::kAIndex + components as usize) as isize)
alpha1 = *src.add(F::kAIndex);
alpha2 = *src.add(F::kAIndex + components as usize)
}
}
/* If there are at least 4 pixels, then we can iterate and preload the
@ -115,10 +115,10 @@ unsafe extern "C" fn qcms_transform_data_template_lut_avx<F: Format>(
vec_b = _mm256_mul_ps(vec_b, mat2);
/* store alpha for these pixels; load alpha for next two */
if F::kAIndex != 0xff {
*dest.offset(F::kAIndex as isize) = alpha1;
*dest.offset((F::kAIndex + components as usize) as isize) = alpha2;
alpha1 = *src.offset(F::kAIndex as isize);
alpha2 = *src.offset((F::kAIndex + components as usize) as isize)
*dest.add(F::kAIndex) = alpha1;
*dest.add(F::kAIndex + components as usize) = alpha2;
alpha1 = *src.add(F::kAIndex);
alpha2 = *src.add(F::kAIndex + components as usize)
}
/* crunch, crunch, crunch */
vec_r = _mm256_add_ps(vec_r, _mm256_add_ps(vec_g, vec_b));
@ -128,33 +128,33 @@ unsafe extern "C" fn qcms_transform_data_template_lut_avx<F: Format>(
/* store calc'd output tables indices */
_mm256_store_si256(output as *mut __m256i, _mm256_cvtps_epi32(result));
/* load gamma values for next loop while store completes */
vec_r0 = _mm_broadcast_ss(&*igtbl_r.offset(*src.offset(F::kRIndex as isize) as isize));
vec_g0 = _mm_broadcast_ss(&*igtbl_g.offset(*src.offset(F::kGIndex as isize) as isize));
vec_b0 = _mm_broadcast_ss(&*igtbl_b.offset(*src.offset(F::kBIndex as isize) as isize));
vec_r0 = _mm_broadcast_ss(&*igtbl_r.offset(*src.add(F::kRIndex) as isize));
vec_g0 = _mm_broadcast_ss(&*igtbl_g.offset(*src.add(F::kGIndex) as isize));
vec_b0 = _mm_broadcast_ss(&*igtbl_b.offset(*src.add(F::kBIndex) as isize));
vec_r1 = _mm_broadcast_ss(
&*igtbl_r.offset(*src.offset((F::kRIndex + components as usize) as isize) as isize),
&*igtbl_r.offset(*src.add(F::kRIndex + components as usize) as isize),
);
vec_g1 = _mm_broadcast_ss(
&*igtbl_g.offset(*src.offset((F::kGIndex + components as usize) as isize) as isize),
&*igtbl_g.offset(*src.add(F::kGIndex + components as usize) as isize),
);
vec_b1 = _mm_broadcast_ss(
&*igtbl_b.offset(*src.offset((F::kBIndex + components as usize) as isize) as isize),
&*igtbl_b.offset(*src.add(F::kBIndex + components as usize) as isize),
);
vec_r = _mm256_insertf128_ps(_mm256_castps128_ps256(vec_r0), vec_r1, 1);
vec_g = _mm256_insertf128_ps(_mm256_castps128_ps256(vec_g0), vec_g1, 1);
vec_b = _mm256_insertf128_ps(_mm256_castps128_ps256(vec_b0), vec_b1, 1);
/* use calc'd indices to output RGB values */
*dest.offset(F::kRIndex as isize) = *otdata_r.offset(*output.offset(0isize) as isize);
*dest.offset(F::kGIndex as isize) = *otdata_g.offset(*output.offset(1isize) as isize);
*dest.offset(F::kBIndex as isize) = *otdata_b.offset(*output.offset(2isize) as isize);
*dest.offset((F::kRIndex + components as usize) as isize) =
*dest.add(F::kRIndex) = *otdata_r.offset(*output.offset(0isize) as isize);
*dest.add(F::kGIndex) = *otdata_g.offset(*output.offset(1isize) as isize);
*dest.add(F::kBIndex) = *otdata_b.offset(*output.offset(2isize) as isize);
*dest.add(F::kRIndex + components as usize) =
*otdata_r.offset(*output.offset(4isize) as isize);
*dest.offset((F::kGIndex + components as usize) as isize) =
*dest.add(F::kGIndex + components as usize) =
*otdata_g.offset(*output.offset(5isize) as isize);
*dest.offset((F::kBIndex + components as usize) as isize) =
*dest.add(F::kBIndex + components as usize) =
*otdata_b.offset(*output.offset(6isize) as isize);
dest = dest.offset((2 * components) as isize);
length = length - 2
length -= 2
}
/* There are 0-3 pixels remaining. If there are 2-3 remaining, then we know
we have already populated the necessary registers to start the transform. */
@ -163,46 +163,46 @@ unsafe extern "C" fn qcms_transform_data_template_lut_avx<F: Format>(
vec_g = _mm256_mul_ps(vec_g, mat1);
vec_b = _mm256_mul_ps(vec_b, mat2);
if F::kAIndex != 0xff {
*dest.offset(F::kAIndex as isize) = alpha1;
*dest.offset((F::kAIndex + components as usize) as isize) = alpha2
*dest.add(F::kAIndex) = alpha1;
*dest.add(F::kAIndex + components as usize) = alpha2
}
vec_r = _mm256_add_ps(vec_r, _mm256_add_ps(vec_g, vec_b));
vec_r = _mm256_max_ps(min, vec_r);
vec_r = _mm256_min_ps(max, vec_r);
result = _mm256_mul_ps(vec_r, scale);
_mm256_store_si256(output as *mut __m256i, _mm256_cvtps_epi32(result));
*dest.offset(F::kRIndex as isize) = *otdata_r.offset(*output.offset(0isize) as isize);
*dest.offset(F::kGIndex as isize) = *otdata_g.offset(*output.offset(1isize) as isize);
*dest.offset(F::kBIndex as isize) = *otdata_b.offset(*output.offset(2isize) as isize);
*dest.offset((F::kRIndex + components as usize) as isize) =
*dest.add(F::kRIndex) = *otdata_r.offset(*output.offset(0isize) as isize);
*dest.add(F::kGIndex) = *otdata_g.offset(*output.offset(1isize) as isize);
*dest.add(F::kBIndex) = *otdata_b.offset(*output.offset(2isize) as isize);
*dest.add(F::kRIndex + components as usize) =
*otdata_r.offset(*output.offset(4isize) as isize);
*dest.offset((F::kGIndex + components as usize) as isize) =
*dest.add(F::kGIndex + components as usize) =
*otdata_g.offset(*output.offset(5isize) as isize);
*dest.offset((F::kBIndex + components as usize) as isize) =
*dest.add(F::kBIndex + components as usize) =
*otdata_b.offset(*output.offset(6isize) as isize);
src = src.offset((2 * components) as isize);
dest = dest.offset((2 * components) as isize);
length = length - 2
length -= 2
}
/* There may be 0-1 pixels remaining. */
if length == 1 {
vec_r0 = _mm_broadcast_ss(&*igtbl_r.offset(*src.offset(F::kRIndex as isize) as isize));
vec_g0 = _mm_broadcast_ss(&*igtbl_g.offset(*src.offset(F::kGIndex as isize) as isize));
vec_b0 = _mm_broadcast_ss(&*igtbl_b.offset(*src.offset(F::kBIndex as isize) as isize));
vec_r0 = _mm_broadcast_ss(&*igtbl_r.offset(*src.add(F::kRIndex) as isize));
vec_g0 = _mm_broadcast_ss(&*igtbl_g.offset(*src.add(F::kGIndex) as isize));
vec_b0 = _mm_broadcast_ss(&*igtbl_b.offset(*src.add(F::kBIndex) as isize));
vec_r0 = _mm_mul_ps(vec_r0, _mm256_castps256_ps128(mat0));
vec_g0 = _mm_mul_ps(vec_g0, _mm256_castps256_ps128(mat1));
vec_b0 = _mm_mul_ps(vec_b0, _mm256_castps256_ps128(mat2));
if F::kAIndex != 0xff {
*dest.offset(F::kAIndex as isize) = *src.offset(F::kAIndex as isize)
*dest.add(F::kAIndex) = *src.add(F::kAIndex)
}
vec_r0 = _mm_add_ps(vec_r0, _mm_add_ps(vec_g0, vec_b0));
vec_r0 = _mm_max_ps(_mm256_castps256_ps128(min), vec_r0);
vec_r0 = _mm_min_ps(_mm256_castps256_ps128(max), vec_r0);
vec_r0 = _mm_mul_ps(vec_r0, _mm256_castps256_ps128(scale));
_mm_store_si128(output as *mut __m128i, _mm_cvtps_epi32(vec_r0));
*dest.offset(F::kRIndex as isize) = *otdata_r.offset(*output.offset(0isize) as isize);
*dest.offset(F::kGIndex as isize) = *otdata_g.offset(*output.offset(1isize) as isize);
*dest.offset(F::kBIndex as isize) = *otdata_b.offset(*output.offset(2isize) as isize)
*dest.add(F::kRIndex) = *otdata_r.offset(*output.offset(0isize) as isize);
*dest.add(F::kGIndex) = *otdata_g.offset(*output.offset(1isize) as isize);
*dest.add(F::kBIndex) = *otdata_b.offset(*output.offset(2isize) as isize)
};
}
#[no_mangle]

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

@ -68,13 +68,13 @@ unsafe extern "C" fn qcms_transform_data_template_lut_sse2<F: Format>(
return;
}
/* one pixel is handled outside of the loop */
length = length - 1;
length -= 1;
/* setup for transforming 1st pixel */
vec_r = _mm_load_ss(&*igtbl_r.offset(*src.offset(F::kRIndex as isize) as isize));
vec_g = _mm_load_ss(&*igtbl_g.offset(*src.offset(F::kGIndex as isize) as isize));
vec_b = _mm_load_ss(&*igtbl_b.offset(*src.offset(F::kBIndex as isize) as isize));
vec_r = _mm_load_ss(&*igtbl_r.offset(*src.add(F::kRIndex) as isize));
vec_g = _mm_load_ss(&*igtbl_g.offset(*src.add(F::kGIndex) as isize));
vec_b = _mm_load_ss(&*igtbl_b.offset(*src.add(F::kBIndex) as isize));
if F::kAIndex != 0xff {
alpha = *src.offset(F::kAIndex as isize)
alpha = *src.add(F::kAIndex)
}
src = src.offset(components as isize);
let mut i: libc::c_uint = 0;
@ -89,8 +89,8 @@ unsafe extern "C" fn qcms_transform_data_template_lut_sse2<F: Format>(
vec_b = _mm_mul_ps(vec_b, mat2);
/* store alpha for this pixel; load alpha for next */
if F::kAIndex != 0xff {
*dest.offset(F::kAIndex as isize) = alpha;
alpha = *src.offset(F::kAIndex as isize)
*dest.add(F::kAIndex) = alpha;
alpha = *src.add(F::kAIndex)
}
/* crunch, crunch, crunch */
vec_r = _mm_add_ps(vec_r, _mm_add_ps(vec_g, vec_b));
@ -100,16 +100,16 @@ unsafe extern "C" fn qcms_transform_data_template_lut_sse2<F: Format>(
/* store calc'd output tables indices */
_mm_store_si128(output as *mut __m128i, _mm_cvtps_epi32(result));
/* load gamma values for next loop while store completes */
vec_r = _mm_load_ss(&*igtbl_r.offset(*src.offset(F::kRIndex as isize) as isize));
vec_g = _mm_load_ss(&*igtbl_g.offset(*src.offset(F::kGIndex as isize) as isize));
vec_b = _mm_load_ss(&*igtbl_b.offset(*src.offset(F::kBIndex as isize) as isize));
vec_r = _mm_load_ss(&*igtbl_r.offset(*src.add(F::kRIndex) as isize));
vec_g = _mm_load_ss(&*igtbl_g.offset(*src.add(F::kGIndex) as isize));
vec_b = _mm_load_ss(&*igtbl_b.offset(*src.add(F::kBIndex) as isize));
src = src.offset(components as isize);
/* use calc'd indices to output RGB values */
*dest.offset(F::kRIndex as isize) = *otdata_r.offset(*output.offset(0isize) as isize);
*dest.offset(F::kGIndex as isize) = *otdata_g.offset(*output.offset(1isize) as isize);
*dest.offset(F::kBIndex as isize) = *otdata_b.offset(*output.offset(2isize) as isize);
*dest.add(F::kRIndex) = *otdata_r.offset(*output.offset(0isize) as isize);
*dest.add(F::kGIndex) = *otdata_g.offset(*output.offset(1isize) as isize);
*dest.add(F::kBIndex) = *otdata_b.offset(*output.offset(2isize) as isize);
dest = dest.offset(components as isize);
i = i + 1
i += 1
}
/* handle final (maybe only) pixel */
vec_r = _mm_shuffle_ps(vec_r, vec_r, 0);
@ -119,16 +119,16 @@ unsafe extern "C" fn qcms_transform_data_template_lut_sse2<F: Format>(
vec_g = _mm_mul_ps(vec_g, mat1);
vec_b = _mm_mul_ps(vec_b, mat2);
if F::kAIndex != 0xff {
*dest.offset(F::kAIndex as isize) = alpha
*dest.add(F::kAIndex) = alpha
}
vec_r = _mm_add_ps(vec_r, _mm_add_ps(vec_g, vec_b));
vec_r = _mm_max_ps(min, vec_r);
vec_r = _mm_min_ps(max, vec_r);
result = _mm_mul_ps(vec_r, scale);
_mm_store_si128(output as *mut __m128i, _mm_cvtps_epi32(result));
*dest.offset(F::kRIndex as isize) = *otdata_r.offset(*output.offset(0isize) as isize);
*dest.offset(F::kGIndex as isize) = *otdata_g.offset(*output.offset(1isize) as isize);
*dest.offset(F::kBIndex as isize) = *otdata_b.offset(*output.offset(2isize) as isize);
*dest.add(F::kRIndex) = *otdata_r.offset(*output.offset(0isize) as isize);
*dest.add(F::kGIndex) = *otdata_g.offset(*output.offset(1isize) as isize);
*dest.add(F::kBIndex) = *otdata_b.offset(*output.offset(2isize) as isize);
}
#[no_mangle]
pub unsafe extern "C" fn qcms_transform_data_rgb_out_lut_sse2(

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

@ -35,7 +35,7 @@ fn u8Fixed8Number_to_float(mut x: u16) -> f32 {
// 0x0000 = 0.
// 0x0100 = 1.
// 0xffff = 255 + 255/256
return (x as i32 as f64 / 256.0f64) as f32;
(x as i32 as f64 / 256.0f64) as f32
}
#[inline]
pub fn clamp_float(mut a: f32) -> f32 {
@ -51,19 +51,19 @@ pub fn clamp_float(mut a: f32) -> f32 {
for most consumers.
*/
if a > 1. {
return 1.;
1.
} else if a >= 0. {
return a;
a
} else {
// a < 0 or a is NaN
return 0.;
0.
}
}
/* value must be a value between 0 and 1 */
//XXX: is the above a good restriction to have?
// the output range of this functions is 0..1
pub fn lut_interp_linear(mut input_value: f64, mut table: &[u16]) -> f32 {
input_value = input_value * (table.len() - 1) as f64;
input_value *= (table.len() - 1) as f64;
let mut upper: i32 = input_value.ceil() as i32;
let mut lower: i32 = input_value.floor() as i32;
@ -71,7 +71,7 @@ pub fn lut_interp_linear(mut input_value: f64, mut table: &[u16]) -> f32 {
+ (table[lower as usize] as f64 * (upper as f64 - input_value)))
as f32;
/* scale the value */
return value * (1.0 / 65535.0);
value * (1.0 / 65535.0)
}
/* same as above but takes and returns a uint16_t value representing a range from 0..1 */
#[no_mangle]
@ -86,7 +86,7 @@ pub fn lut_interp_linear16(mut input_value: u16, mut table: &[u16]) -> u16 {
value = (table[upper as usize] as u32 * interp
+ table[lower as usize] as u32 * (65535 - interp))
/ 65535;
return value as u16;
value as u16
}
/* same as above but takes an input_value from 0..PRECACHE_OUTPUT_MAX
* and returns a uint8_t value representing a range from 0..1 */
@ -105,14 +105,14 @@ fn lut_interp_linear_precache_output(mut input_value: u32, mut table: &[u16]) ->
value = table[upper as usize] as libc::c_uint * interp
+ table[lower as usize] as libc::c_uint * (PRECACHE_OUTPUT_MAX as libc::c_uint - interp); // 0..(65535*PRECACHE_OUTPUT_MAX)
/* round and scale */
value = value + (PRECACHE_OUTPUT_MAX * 65535 / 255 / 2) as libc::c_uint; // scale to 0..255
value = value / (PRECACHE_OUTPUT_MAX * 65535 / 255) as libc::c_uint;
return value as u8;
value += (PRECACHE_OUTPUT_MAX * 65535 / 255 / 2) as libc::c_uint; // scale to 0..255
value /= (PRECACHE_OUTPUT_MAX * 65535 / 255) as libc::c_uint;
value as u8
}
/* value must be a value between 0 and 1 */
//XXX: is the above a good restriction to have?
pub fn lut_interp_linear_float(mut value: f32, mut table: &[f32]) -> f32 {
value = value * (table.len() - 1) as f32;
value *= (table.len() - 1) as f32;
let mut upper: i32 = value.ceil() as i32;
let mut lower: i32 = value.floor() as i32;
@ -120,7 +120,7 @@ pub fn lut_interp_linear_float(mut value: f32, mut table: &[f32]) -> f32 {
value = (table[upper as usize] as f64 * (1.0f64 - (upper as f32 - value) as f64)
+ (table[lower as usize] * (upper as f32 - value)) as f64) as f32;
/* scale the value */
return value;
value
}
fn compute_curve_gamma_table_type1(mut gamma_table: &mut Vec<f32>, mut gamma: u16) {
let mut gamma_float: f32 = u8Fixed8Number_to_float(gamma);
@ -226,7 +226,7 @@ pub(crate) fn build_input_gamma_table(mut TRC: Option<&curveType>) -> Option<Vec
},
}
return Some(gamma_table);
Some(gamma_table)
}
pub fn build_colorant_matrix(mut p: &qcms_profile) -> matrix {
let mut result: matrix = matrix {
@ -243,7 +243,7 @@ pub fn build_colorant_matrix(mut p: &qcms_profile) -> matrix {
result.m[2][1] = s15Fixed16Number_to_float(p.greenColorant.Z);
result.m[2][2] = s15Fixed16Number_to_float(p.blueColorant.Z);
result.invalid = false;
return result;
result
}
/* The following code is copied nearly directly from lcms.
* I think it could be much better. For example, Argyll seems to have better code in
@ -337,7 +337,7 @@ pub fn lut_inverse_interp16(mut Value: u16, mut LutTable: &[u16]) -> uint16_frac
if f >= 65535.0f64 {
return 0xffffu16;
}
return (f + 0.5f64).floor() as uint16_fract_t;
(f + 0.5f64).floor() as uint16_fract_t
}
/*
The number of entries needed to invert a lookup table should not
@ -361,7 +361,7 @@ fn invert_lut(mut table: &[u16], mut out_length: i32) -> Vec<u16> {
let mut input: uint16_fract_t = (x + 0.5f64).floor() as uint16_fract_t;
output.push(lut_inverse_interp16(input, table));
}
return output;
output
}
fn compute_precache_pow(output: &mut [u8; PRECACHE_OUTPUT_SIZE], mut gamma: f32) {
let mut v: u32 = 0;
@ -369,14 +369,14 @@ fn compute_precache_pow(output: &mut [u8; PRECACHE_OUTPUT_SIZE], mut gamma: f32)
//XXX: don't do integer/float conversion... and round?
output[v as usize] =
(255.0f64 * (v as f64 / PRECACHE_OUTPUT_MAX as f64).powf(gamma as f64)) as u8;
v = v + 1
v += 1
}
}
pub fn compute_precache_lut(mut output: &mut [u8; PRECACHE_OUTPUT_SIZE], mut table: &[u16]) {
let mut v: u32 = 0;
while v < PRECACHE_OUTPUT_SIZE as u32 {
output[v as usize] = lut_interp_linear_precache_output(v, table);
v = v + 1
v += 1
}
}
pub fn compute_precache_linear(mut output: &mut [u8; PRECACHE_OUTPUT_SIZE]) {
@ -384,7 +384,7 @@ pub fn compute_precache_linear(mut output: &mut [u8; PRECACHE_OUTPUT_SIZE]) {
while v < PRECACHE_OUTPUT_SIZE as u32 {
//XXX: round?
output[v as usize] = (v / (PRECACHE_OUTPUT_SIZE / 256) as libc::c_uint) as u8;
v = v + 1
v += 1
}
}
pub(crate) fn compute_precache(
@ -401,7 +401,7 @@ pub(crate) fn compute_precache(
let mut i: u16 = 0u16;
while (i as i32) < 256 {
gamma_table_uint[i as usize] = (gamma_table[i as usize] * 65535f32) as u16;
i = i + 1
i += 1
}
//XXX: the choice of a minimum of 256 here is not backed by any theory,
// measurement or data, howeve r it is what lcms uses.
@ -432,7 +432,7 @@ pub(crate) fn compute_precache(
}
}
}
return true;
true
}
fn build_linear_table(mut length: i32) -> Vec<u16> {
let mut output = Vec::with_capacity(length as usize);
@ -441,7 +441,7 @@ fn build_linear_table(mut length: i32) -> Vec<u16> {
let mut input: uint16_fract_t = (x + 0.5f64).floor() as uint16_fract_t;
output.push(input);
}
return output;
output
}
fn build_pow_table(mut gamma: f32, mut length: i32) -> Vec<u16> {
let mut output = Vec::with_capacity(length as usize);
@ -451,7 +451,7 @@ fn build_pow_table(mut gamma: f32, mut length: i32) -> Vec<u16> {
let mut result: uint16_fract_t = (x * 65535.0f64 + 0.5f64).floor() as uint16_fract_t;
output.push(result);
}
return output;
output
}
pub(crate) fn build_output_lut(mut trc: &curveType) -> Vec<u16> {
@ -463,10 +463,10 @@ pub(crate) fn build_output_lut(mut trc: &curveType) -> Vec<u16> {
for i in 0..256 {
output.push((gamma_table[i as usize] * 65535f32) as u16);
}
return output;
output
}
curveType::Curve(data) => {
return match data.len() {
match data.len() {
0 => build_linear_table(4096),
1 => {
let mut gamma = 1. / u8Fixed8Number_to_float(data[0]);
@ -481,7 +481,7 @@ pub(crate) fn build_output_lut(mut trc: &curveType) -> Vec<u16> {
}
invert_lut(data, output_gamma_lut_length as i32)
}
};
}
}
}
}