зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1677382 - Make qcms_transform_create safe. r=aosmond
Tack on a little clean up in compute_whitepoint_adaption Differential Revision: https://phabricator.services.mozilla.com/D97097
This commit is contained in:
Родитель
8ece49dbf8
Коммит
6e6d1d327a
|
@ -1174,12 +1174,9 @@ 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 init = matrix {
|
||||
m: [[p, 0., 0.], [0., y, 0.], [0., 0., b]],
|
||||
invalid: false,
|
||||
};
|
||||
init
|
||||
let mut white_adaption = matrix {
|
||||
m: [[p, 0., 0.], [0., y, 0.], [0., 0., b]],
|
||||
invalid: false,
|
||||
};
|
||||
return matrix_multiply(
|
||||
bradford_matrix_inv,
|
||||
|
@ -1238,7 +1235,7 @@ 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 */
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn qcms_transform_precacheLUT_float(
|
||||
mut transform: *mut qcms_transform,
|
||||
mut transform: Box<qcms_transform>,
|
||||
mut in_0: &qcms_profile,
|
||||
mut out: &qcms_profile,
|
||||
mut samples: i32,
|
||||
|
@ -1306,10 +1303,10 @@ pub unsafe extern "C" fn qcms_transform_precacheLUT_float(
|
|||
if lut.is_null() {
|
||||
return 0 as *mut qcms_transform;
|
||||
}
|
||||
return transform;
|
||||
return Box::into_raw(transform);
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn qcms_transform_create(
|
||||
pub extern "C" fn qcms_transform_create(
|
||||
mut in_0: &qcms_profile,
|
||||
mut in_type: qcms_data_type,
|
||||
mut out: &qcms_profile,
|
||||
|
@ -1335,10 +1332,7 @@ pub unsafe extern "C" fn qcms_transform_create(
|
|||
debug_assert!(false, "input/output type");
|
||||
return 0 as *mut qcms_transform;
|
||||
}
|
||||
let mut transform: *mut qcms_transform = transform_alloc();
|
||||
if transform.is_null() {
|
||||
return 0 as *mut qcms_transform;
|
||||
}
|
||||
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()
|
||||
|
@ -1362,10 +1356,9 @@ pub unsafe extern "C" fn qcms_transform_create(
|
|||
// TODO For transforming small data sets of about 200x200 or less
|
||||
// precaching should be avoided.
|
||||
let mut result: *mut qcms_transform =
|
||||
qcms_transform_precacheLUT_float(transform, in_0, out, 33, in_type);
|
||||
unsafe { qcms_transform_precacheLUT_float(transform, in_0, out, 33, in_type) };
|
||||
if result.is_null() {
|
||||
debug_assert!(false, "precacheLUT failed");
|
||||
qcms_transform_release(transform);
|
||||
return 0 as *mut qcms_transform;
|
||||
}
|
||||
return result;
|
||||
|
@ -1376,7 +1369,6 @@ pub unsafe extern "C" fn qcms_transform_create(
|
|||
(*transform).output_table_b = Some(Arc::clone((*out).output_table_b.as_ref().unwrap()));
|
||||
} else {
|
||||
if (*out).redTRC.is_none() || (*out).greenTRC.is_none() || (*out).blueTRC.is_none() {
|
||||
qcms_transform_release(transform);
|
||||
return 0 as *mut qcms_transform;
|
||||
}
|
||||
(*transform).output_gamma_lut_r = Some(build_output_lut((*out).redTRC.as_deref().unwrap()));
|
||||
|
@ -1389,7 +1381,6 @@ pub unsafe extern "C" fn qcms_transform_create(
|
|||
|| (*transform).output_gamma_lut_g.is_none()
|
||||
|| (*transform).output_gamma_lut_b.is_none()
|
||||
{
|
||||
qcms_transform_release(transform);
|
||||
return 0 as *mut qcms_transform;
|
||||
}
|
||||
}
|
||||
|
@ -1458,7 +1449,6 @@ pub unsafe extern "C" fn qcms_transform_create(
|
|||
|| (*transform).input_gamma_table_g.is_none()
|
||||
|| (*transform).input_gamma_table_b.is_none()
|
||||
{
|
||||
qcms_transform_release(transform);
|
||||
return 0 as *mut qcms_transform;
|
||||
}
|
||||
/* build combined colorant matrix */
|
||||
|
@ -1467,7 +1457,6 @@ pub unsafe extern "C" fn qcms_transform_create(
|
|||
let mut out_matrix: matrix = build_colorant_matrix(out);
|
||||
out_matrix = matrix_invert(out_matrix);
|
||||
if out_matrix.invalid {
|
||||
qcms_transform_release(transform);
|
||||
return 0 as *mut qcms_transform;
|
||||
}
|
||||
let mut result_0: matrix = matrix_multiply(out_matrix, in_matrix);
|
||||
|
@ -1477,7 +1466,6 @@ pub unsafe extern "C" fn qcms_transform_create(
|
|||
let mut j: libc::c_uint = 0;
|
||||
while j < 3 {
|
||||
if result_0.m[i as usize][j as usize] != result_0.m[i as usize][j as usize] {
|
||||
qcms_transform_release(transform);
|
||||
return 0 as *mut qcms_transform;
|
||||
}
|
||||
j = j + 1
|
||||
|
@ -1498,7 +1486,6 @@ pub unsafe extern "C" fn qcms_transform_create(
|
|||
} else if (*in_0).color_space == 0x47524159 {
|
||||
(*transform).input_gamma_table_gray = build_input_gamma_table((*in_0).grayTRC.as_deref());
|
||||
if (*transform).input_gamma_table_gray.is_none() {
|
||||
qcms_transform_release(transform);
|
||||
return 0 as *mut qcms_transform;
|
||||
}
|
||||
if precache {
|
||||
|
@ -1534,11 +1521,10 @@ pub unsafe extern "C" fn qcms_transform_create(
|
|||
}
|
||||
} else {
|
||||
debug_assert!(false, "unexpected colorspace");
|
||||
qcms_transform_release(transform);
|
||||
return 0 as *mut qcms_transform;
|
||||
}
|
||||
debug_assert!((*transform).transform_fn.is_some());
|
||||
return transform;
|
||||
return Box::into_raw(transform);
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn qcms_transform_data(
|
||||
|
|
Загрузка…
Ссылка в новой задаче