Skip to content

Commit

Permalink
Bug 1677309 - Make qcms_profile_precache_output_transform safe. r=aos…
Browse files Browse the repository at this point in the history
…mond

There's a couple of formatting cleanups too.

Differential Revision: https://phabricator.services.mozilla.com/D97080
  • Loading branch information
jrmuizel committed Nov 14, 2020
1 parent 93d2a8d commit 4267034
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion gfx/qcms/fuzz/fuzz_targets/fuzz_target_qcms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extern crate libc;
// Firefox calls this on the display profile to increase performance.
// Skip with low probability to increase coverage.
if (size % 15) != 0 {
qcms_profile_precache_output_transform(dst_profile);
qcms_profile_precache_output_transform(&mut *dst_profile);
}

let transform =
Expand Down
8 changes: 4 additions & 4 deletions gfx/qcms/src/gtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ mod test {
};
let D65 = unsafe { qcms_white_point_sRGB() };
let other = unsafe { qcms_profile_create_rgb_with_gamma(D65, Rec709Primaries, 2.2) };
unsafe { qcms_profile_precache_output_transform(other) };
unsafe { qcms_profile_precache_output_transform(&mut *other) };

let transform = unsafe {
qcms_transform_create(
Expand Down Expand Up @@ -214,7 +214,7 @@ mod test {
fn gray_alpha() {
let sRGB_profile = unsafe { crate::iccread::qcms_profile_sRGB() };
let other = unsafe { qcms_profile_create_gray_with_gamma(2.2) };
unsafe { qcms_profile_precache_output_transform(other) };
unsafe { qcms_profile_precache_output_transform(&mut *other) };

let transform = unsafe {
qcms_transform_create(
Expand Down Expand Up @@ -302,7 +302,7 @@ mod test {
let srgb_profile = unsafe { qcms_profile_sRGB() };
assert_ne!(srgb_profile, std::ptr::null_mut());

unsafe { qcms_profile_precache_output_transform(srgb_profile) };
unsafe { qcms_profile_precache_output_transform(&mut *srgb_profile) };

let intent = unsafe { qcms_profile_get_rendering_intent(profile) };
let transform = unsafe {
Expand Down Expand Up @@ -687,7 +687,7 @@ mod test {
}

unsafe fn PrecacheOutput(&mut self) {
qcms_profile_precache_output_transform(self.out_profile);
qcms_profile_precache_output_transform(&mut *self.out_profile);
self.precache = true;
}
unsafe fn TransformPrecache(&mut self) {
Expand Down
2 changes: 1 addition & 1 deletion gfx/qcms/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,7 @@ fn compute_whitepoint_adaption(mut X: f32, mut Y: f32, mut Z: f32) -> matrix {
);
}
#[no_mangle]
pub unsafe 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 qcms_profile) {
/* we only support precaching on rgb profiles */
if (*profile).color_space != 0x52474220 {
return;
Expand Down
14 changes: 4 additions & 10 deletions gfx/qcms/src/transform_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,7 @@ pub fn lut_interp_linear16(mut input_value: u16, mut table: &[u16]) -> 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 */
fn lut_interp_linear_precache_output(
mut input_value: u32,
mut table: &[u16]
) -> u8 {
fn lut_interp_linear_precache_output(mut input_value: u32, mut table: &[u16]) -> u8 {
/* Start scaling input_value to the length of the array: PRECACHE_OUTPUT_MAX*(length-1).
* We'll divide out the PRECACHE_OUTPUT_MAX next */
let mut value: u32 = input_value * (table.len() - 1) as libc::c_uint;
Expand All @@ -114,7 +111,7 @@ fn lut_interp_linear_precache_output(
/* the table values range from 0..65535 */
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 */
/* 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;
Expand Down Expand Up @@ -391,17 +388,14 @@ fn compute_precache_pow(output: &mut [u8; PRECACHE_OUTPUT_SIZE], mut gamma: f32)
v = v + 1
}
}
pub fn compute_precache_lut(
mut output: &mut [u8; PRECACHE_OUTPUT_SIZE],
mut table: &[u16],
) {
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
}
}
pub fn compute_precache_linear(mut output: &mut[u8; PRECACHE_OUTPUT_SIZE]) {
pub fn compute_precache_linear(mut output: &mut [u8; PRECACHE_OUTPUT_SIZE]) {
let mut v: u32 = 0;
while v < PRECACHE_OUTPUT_SIZE as u32 {
//XXX: round?
Expand Down

0 comments on commit 4267034

Please sign in to comment.