Bug 1684174 - Make qcms_intent an enum. r=aosmond

Differential Revision: https://phabricator.services.mozilla.com/D100448
This commit is contained in:
Jeff Muizelaar 2020-12-24 18:29:04 +00:00
Родитель 1510060a56
Коммит 61d3b2f82d
5 изменённых файлов: 33 добавлений и 25 удалений

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

@ -4,9 +4,9 @@ use libc::{fclose, fopen, fread, free, malloc, FILE};
use crate::{
iccread::*,
qcms_intent,
transform::qcms_data_type,
transform::{qcms_transform, transform_create},
Intent,
};
#[no_mangle]
@ -93,7 +93,7 @@ pub unsafe extern "C" fn qcms_profile_from_memory(
#[no_mangle]
pub unsafe extern "C" fn qcms_profile_get_rendering_intent(
mut profile: *mut qcms_profile,
) -> qcms_intent {
) -> Intent {
return (*profile).rendering_intent;
}
#[no_mangle]
@ -237,7 +237,7 @@ pub extern "C" fn qcms_transform_create(
mut in_type: qcms_data_type,
mut out: &qcms_profile,
mut out_type: qcms_data_type,
mut intent: qcms_intent,
mut intent: Intent,
) -> *mut qcms_transform {
let transform = transform_create(in_0, in_type, out, out_type, intent);
match transform {

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

@ -2,7 +2,7 @@
mod test {
use crate::{
c_bindings::*, iccread::*, transform::qcms_data_type::*, transform::*,
transform_util::lut_inverse_interp16, QCMS_INTENT_DEFAULT, QCMS_INTENT_PERCEPTUAL,
transform_util::lut_inverse_interp16, Intent::QCMS_INTENT_PERCEPTUAL,
};
use libc::c_void;
use std::ptr::null_mut;
@ -558,7 +558,7 @@ mod test {
ty,
&*self.out_profile,
ty,
QCMS_INTENT_DEFAULT,
QCMS_INTENT_PERCEPTUAL,
))
}

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

@ -33,10 +33,7 @@ use crate::{
double_to_s15Fixed16Number,
transform::{get_rgb_colorants, precache_output, set_rgb_colorants},
};
use crate::{
matrix::matrix, qcms_intent, s15Fixed16Number, s15Fixed16Number_to_float,
QCMS_INTENT_PERCEPTUAL,
};
use crate::{matrix::matrix, s15Fixed16Number, s15Fixed16Number_to_float, Intent, Intent::*};
pub static qcms_supports_iccv4: AtomicBool = AtomicBool::new(false);
@ -79,7 +76,7 @@ pub struct qcms_profile {
pub(crate) class_type: u32,
pub(crate) color_space: u32,
pub(crate) pcs: u32,
pub(crate) rendering_intent: qcms_intent,
pub(crate) rendering_intent: Intent,
pub(crate) redColorant: XYZNumber,
pub(crate) blueColorant: XYZNumber,
pub(crate) greenColorant: XYZNumber,
@ -1006,11 +1003,15 @@ fn read_tag_lutType(mut src: &mut mem_source, mut tag: &tag) -> Option<Box<lutTy
}))
}
fn read_rendering_intent(mut profile: &mut qcms_profile, mut src: &mut mem_source) {
profile.rendering_intent = read_u32(src, 64);
match profile.rendering_intent {
0 | 2 | 1 | 3 => {}
let intent = read_u32(src, 64);
profile.rendering_intent = match intent {
x if x == QCMS_INTENT_PERCEPTUAL as u32 => QCMS_INTENT_PERCEPTUAL,
x if x == QCMS_INTENT_RELATIVE_COLORIMETRIC as u32 => QCMS_INTENT_RELATIVE_COLORIMETRIC,
x if x == QCMS_INTENT_SATURATION as u32 => QCMS_INTENT_SATURATION,
x if x == QCMS_INTENT_ABSOLUTE_COLORIMETRIC as u32 => QCMS_INTENT_ABSOLUTE_COLORIMETRIC,
_ => {
invalid_source(src, "unknown rendering intent");
Intent::default()
}
};
}
@ -1438,7 +1439,7 @@ pub unsafe extern "C" fn qcms_data_create_rgb_with_gamma(
write_u32(data, 12, DISPLAY_DEVICE_PROFILE); // profile->class_type
write_u32(data, 16, RGB_SIGNATURE); // profile->color_space
write_u32(data, 20, XYZ_TYPE); // profile->pcs
write_u32(data, 64, QCMS_INTENT_PERCEPTUAL); // profile->rendering_intent
write_u32(data, 64, QCMS_INTENT_PERCEPTUAL as u32); // profile->rendering_intent
write_u32(data, 128, 6); // total tag count
// prepare the result
*mem = data.as_mut_ptr() as *mut libc::c_void;

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

@ -15,15 +15,22 @@
#![feature(raw_ref_op)]
extern crate libc;
#[repr(u32)]
#[derive(Clone, Copy)]
pub enum Intent {
QCMS_INTENT_ABSOLUTE_COLORIMETRIC = 3,
QCMS_INTENT_SATURATION = 2,
QCMS_INTENT_RELATIVE_COLORIMETRIC = 1,
QCMS_INTENT_PERCEPTUAL = 0,
}
pub type qcms_intent = libc::c_uint;
pub const QCMS_INTENT_DEFAULT: qcms_intent = 0;
pub const QCMS_INTENT_MAX: qcms_intent = 3;
pub const QCMS_INTENT_ABSOLUTE_COLORIMETRIC: qcms_intent = 3;
pub const QCMS_INTENT_SATURATION: qcms_intent = 2;
pub const QCMS_INTENT_RELATIVE_COLORIMETRIC: qcms_intent = 1;
pub const QCMS_INTENT_PERCEPTUAL: qcms_intent = 0;
pub const QCMS_INTENT_MIN: qcms_intent = 0;
use Intent::*;
impl Default for Intent {
fn default() -> Self {
QCMS_INTENT_PERCEPTUAL
}
}
pub type s15Fixed16Number = i32;

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

@ -38,8 +38,8 @@ use crate::{
};
use crate::{
iccread::{qcms_CIE_xyY, qcms_CIE_xyYTRIPLE, qcms_profile, RGB_SIGNATURE},
qcms_intent,
transform_util::clamp_float,
Intent,
};
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
use crate::{
@ -1160,7 +1160,7 @@ pub fn transform_create(
mut in_type: qcms_data_type,
mut out: &qcms_profile,
mut out_type: qcms_data_type,
mut intent: qcms_intent,
mut intent: Intent,
) -> Option<Box<qcms_transform>> {
// Ensure the requested input and output types make sense.
let matching_format = match (in_type, out_type) {
@ -1390,7 +1390,7 @@ impl Transform {
input: &qcms_profile,
output: &qcms_profile,
ty: qcms_data_type,
intent: qcms_intent,
intent: Intent,
) -> Option<Self> {
transform_create(input, ty, output, ty, intent).map(|xfm| Transform { ty, xfm })
}