tikz-gallery-generator

Custum build of stapix for tikz.pablopie.xyz

Commit
39064c5a2acd58e0d676255d9292b44e541f466e
Parent
c4d7345fa81bfa6d451b92dd3b1b2798a6d69df9
Author
Pablo <pablo-pie@riseup.net>
Date

Turned debug asserts into asserts

Diffstats

1 files changed, 16 insertions, 13 deletions

Status Name Changes Insertions Deletions
Modified src/image.rs 2 files changed 16 13
diff --git a/src/image.rs b/src/image.rs
@@ -102,8 +102,8 @@ pub fn parse_and_downsample_jpeg(
   assert_expected_pixels_len(src_width, src_height, 3, pixels.len());
 
   let colorspace = options.jpeg_get_out_colorspace();
-  debug_assert!(colorspace == ColorSpace::YCbCr,
-                "unexpected colorspace when parsing JPEG: {colorspace:?}");
+  assert!(colorspace == ColorSpace::YCbCr,
+          "unexpected colorspace when parsing JPEG: {colorspace:?}");
 
   // ==========================================================================
   let [y] = unsafe {
@@ -188,7 +188,7 @@ pub fn parse_and_downsample_png(
     .colorspace()
     .expect("should already have decoded PNG headers");
 
-  debug_assert!(
+  assert!(
     matches!(
       colorspace,
       ColorSpace::RGB | ColorSpace::RGBA | ColorSpace::Luma | ColorSpace::LumaA
@@ -294,14 +294,13 @@ pub fn encode_webp(img: &Image, output_path: &Path) -> Result<(), ()> {
     let mut config = MaybeUninit::uninit();
     let init = WebPInitConfig(config.as_mut_ptr());
     let mut config: WebPConfig = config.assume_init();
-    debug_assert!(init, "libwebp version mismatch");
+    assert!(init, "libwebp version mismatch");
 
     config.lossless          = 0; // using lossy compression
     config.alpha_compression = 1; // using lossy compression
     config.quality           = WEBP_IMAGE_QUALITY;
 
-    debug_assert!(WebPValidateConfig(&config) != 0,
-                  "WebP config should be valid");
+    assert!(WebPValidateConfig(&config) != 0, "WebP config should be valid");
 
     // ======================================================================
     // NOTE: it makes no sense to re-use ww because WebPMemoryWriterClear(ww)
@@ -315,7 +314,7 @@ pub fn encode_webp(img: &Image, output_path: &Path) -> Result<(), ()> {
     let mut picture = MaybeUninit::uninit();
     let init = WebPPictureInit(picture.as_mut_ptr());
     let mut picture: WebPPicture = picture.assume_init();
-    debug_assert!(init, "libwebp version mismatch");
+    assert!(init, "libwebp version mismatch");
 
 
     picture.width  = img.width  as i32;
@@ -345,8 +344,8 @@ pub fn encode_webp(img: &Image, output_path: &Path) -> Result<(), ()> {
       }
     }
 
-    debug_assert!(WebPPictureIsView(&picture) != 0,
-                  "picture should have been configured as \"view\" by not calling WebPPictureAlloc or any of the \"Import\" routines");
+    assert!(WebPPictureIsView(&picture) != 0,
+            "picture should have been configured as \"view\" by not calling WebPPictureAlloc or any of the \"Import\" routines");
 
     picture.writer     = Some(WebPMemoryWrite);
     picture.custom_ptr = &mut ww as *mut WebPMemoryWriter as _;
@@ -381,7 +380,9 @@ unsafe fn load_and_downsample_channels_linear(
   bps: usize, first_channel_offset: usize,
   target_width: usize, target_height: usize,
 ) -> [Vec<MaybeUninit<u8>>; CHANNELS] {
-  debug_assert!(CHANNELS > 0);
+  if CHANNELS == 0 {
+    panic!("load_and_downsample_channels_linear: CHANNELS is 0");
+  }
 
   let mut result: [Vec<MaybeUninit<u8>>; CHANNELS] = {
     [const { Vec::new() }; CHANNELS]
@@ -434,7 +435,9 @@ unsafe fn load_channels(
   src_width: usize, src_height: usize,
   bps: usize,
 ) -> [Vec<MaybeUninit<u8>>; CHANNELS] {
-  debug_assert!(CHANNELS > 0);
+  if CHANNELS == 0 {
+    panic!("load_and_downsample_channels_linear: CHANNELS is 0");
+  }
 
   let mut result = [const { Vec::new() }; CHANNELS];
 
@@ -609,7 +612,7 @@ fn assert_expected_pixels_len(
   pixels_len: usize,
 ) {
   let expected_pixels_len = width * height * bpp;
-  debug_assert!(
+  assert!(
     pixels_len == expected_pixels_len,
     "unexpected pixel buffer length: expected {width} × {height} × {bpp} = {expected_pixels_len} but got {pixels_len}",
   );
@@ -645,5 +648,5 @@ fn log_webp_memmory_error(e: WebPEncodingError, output_path: &Path) {
 
 fn open_file(path: &Path) -> io::Result<File> {
   File::open(path)
-    .map_err(|e| { errorln!("Could not parse {path:?}: {e}"); e })
+    .map_err(|e| { errorln!("Could not open {path:?}: {e}"); e })
 }