Bug 1684192 - Make some profile creation functions infallible. r=aosmond
authorJeff Muizelaar <jmuizelaar@mozilla.com>
Fri, 25 Dec 2020 01:21:20 +0000
changeset 561800 6ce47338a4634b41041840ed5ee2dc368d87247a
parent 561799 10487bde26d342ad1cfc02a67c33698243c09329
child 561801 52eb1fa54b88e2a8d127e4a30ba9adb783a3b32a
push id133397
push userjmuizelaar@mozilla.com
push dateTue, 29 Dec 2020 14:10:29 +0000
treeherderautoland@6ce47338a463 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaosmond
bugs1684192
milestone86.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1684192 - Make some profile creation functions infallible. r=aosmond Differential Revision: https://phabricator.services.mozilla.com/D100454
gfx/qcms/src/c_bindings.rs
gfx/qcms/src/gtest.rs
gfx/qcms/src/iccread.rs
--- a/gfx/qcms/src/c_bindings.rs
+++ b/gfx/qcms/src/c_bindings.rs
@@ -7,20 +7,17 @@ use crate::{
     transform::qcms_data_type,
     transform::{qcms_transform, transform_create},
     Intent,
 };
 
 #[no_mangle]
 pub extern "C" fn qcms_profile_sRGB() -> *mut qcms_profile {
     let profile = qcms_profile::new_sRGB();
-    match profile {
-        Some(profile) => Box::into_raw(profile),
-        None => null_mut(),
-    }
+    Box::into_raw(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?
 /* similar to CGColorSpaceCreateCalibratedRGB */
 #[no_mangle]
 pub unsafe extern "C" fn qcms_profile_create_rgb_with_gamma_set(
@@ -41,20 +38,17 @@ pub unsafe extern "C" fn qcms_profile_cr
         Some(profile) => Box::into_raw(profile),
         None => null_mut(),
     }
 }
 
 #[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);
-    match profile {
-        Some(profile) => Box::into_raw(profile),
-        None => null_mut(),
-    }
+    Box::into_raw(profile)
 }
 
 #[no_mangle]
 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 {
--- a/gfx/qcms/src/gtest.rs
+++ b/gfx/qcms/src/gtest.rs
@@ -852,18 +852,18 @@ mod test {
             qcms_transform_release(transform);
             qcms_profile_release(input);
             qcms_profile_release(output);
         }
     }
 
     #[test]
     fn identity() {
-        let p1 = crate::Profile::new_sRGB().unwrap();
-        let p2 = crate::Profile::new_sRGB().unwrap();
+        let p1 = crate::Profile::new_sRGB();
+        let p2 = crate::Profile::new_sRGB();
         let mut xfm = crate::Transform::new(
             &p1,
             &p2,
             crate::DataType::DATA_RGB_8,
             crate::Intent::default(),
         )
         .unwrap();
         let mut data = [4, 30, 80];
--- a/gfx/qcms/src/iccread.rs
+++ b/gfx/qcms/src/iccread.rs
@@ -1151,17 +1151,17 @@ impl qcms_profile {
         profile.blueTRC = Some(curve_from_table(table));
         profile.greenTRC = Some(curve_from_table(table));
         profile.class_type = DISPLAY_DEVICE_PROFILE;
         profile.rendering_intent = QCMS_INTENT_PERCEPTUAL;
         profile.color_space = RGB_SIGNATURE;
         profile.pcs = XYZ_TYPE;
         return Some(profile);
     }
-    pub fn new_sRGB() -> Option<Box<qcms_profile>> {
+    pub fn new_sRGB() -> Box<qcms_profile> {
         let Rec709Primaries = qcms_CIE_xyYTRIPLE {
             red: {
                 qcms_CIE_xyY {
                     x: 0.6400f64,
                     y: 0.3300f64,
                     Y: 1.0f64,
                 }
             },
@@ -1178,28 +1178,28 @@ impl qcms_profile {
                     y: 0.0600f64,
                     Y: 1.0f64,
                 }
             },
         };
         let D65 = qcms_white_point_sRGB();
         let table = build_sRGB_gamma_table(1024);
 
-        qcms_profile::new_rgb_with_table(D65, Rec709Primaries, &table)
+        qcms_profile::new_rgb_with_table(D65, Rec709Primaries, &table).unwrap()
     }
 
-    pub fn new_gray_with_gamma(gamma: f32) -> Option<Box<qcms_profile>> {
+    pub fn new_gray_with_gamma(gamma: f32) -> Box<qcms_profile> {
         let mut profile = profile_create();
 
         profile.grayTRC = Some(curve_from_gamma(gamma));
         profile.class_type = DISPLAY_DEVICE_PROFILE;
         profile.rendering_intent = QCMS_INTENT_PERCEPTUAL;
         profile.color_space = GRAY_SIGNATURE;
         profile.pcs = XYZ_TYPE;
-        Some(profile)
+        profile
     }
 
     pub fn new_rgb_with_gamma_set(
         mut white_point: qcms_CIE_xyY,
         mut primaries: qcms_CIE_xyYTRIPLE,
         mut redGamma: f32,
         mut greenGamma: f32,
         mut blueGamma: f32,