Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[rust] Drop the unused RGBA ingestion path

laurensprieme55edf57caf7
diff --git a/rust/crates/ml/src/scan/scanner.rs b/rust/crates/ml/src/scan/scanner.rs
index 0a3af0430c..258c6d33c3 100644
--- a/rust/crates/ml/src/scan/scanner.rs
+++ b/rust/crates/ml/src/scan/scanner.rs
@@ -6,7 +6,7 @@ use super::detection::{detect_document_quad, extract_document, resize_for_max_pi
use super::geometry::{ImageSize, Quad};
use super::mask::Mask;
use super::segmentation::{MASK_SIDE, Segmenter};
-use super::yuv::{PlaneLayout, bgra_to_bgr, rgba_to_bgr, yuv420_to_bgr};
+use super::yuv::{PlaneLayout, bgra_to_bgr, yuv420_to_bgr};
use crate::cv::image::ImageU8;
const DEFAULT_MAX_PIXELS: u32 = 2_000_000;
@@ -81,19 +81,6 @@ impl ScannerSession {
Ok(Mask::from_probmap(probmap, MASK_SIDE, MASK_SIDE))
}
- pub fn live_detect_rgba(
- &self,
- rgba: &[u8],
- width: u32,
- height: u32,
- rotation_degrees: i32,
- ) -> Result<Option<Quad>, ScanError> {
- let bgr =
- rgba_to_bgr(rgba, to_i32(width)?, to_i32(height)?).map_err(ScanError::InvalidInput)?;
- let frame = ImageSize::new(bgr.width as f64, bgr.height as f64);
- self.live_detect(&bgr, frame, rotation_degrees)
- }
-
pub fn live_detect_bgra(
&self,
bgra: &[u8],
diff --git a/rust/crates/ml/src/scan/yuv.rs b/rust/crates/ml/src/scan/yuv.rs
index 3f1ddfaa5a..2b1a5df4f4 100644
--- a/rust/crates/ml/src/scan/yuv.rs
+++ b/rust/crates/ml/src/scan/yuv.rs
@@ -210,26 +210,6 @@ pub(crate) fn bgra_to_bgr(
ImageU8::new(width, height, 3, out)
}
-pub(crate) fn rgba_to_bgr(rgba: &[u8], width: i32, height: i32) -> Result<ImageU8, String> {
- if width <= 0 || height <= 0 {
- return Err(format!("invalid frame size {width}x{height}"));
- }
- let expected = width as usize * height as usize * 4;
- if rgba.len() != expected {
- return Err(format!(
- "RGBA buffer has {} bytes, expected {expected} for {width}x{height}",
- rgba.len()
- ));
- }
- let mut out = vec![0u8; width as usize * height as usize * 3];
- for (dst, src) in out.chunks_exact_mut(3).zip(rgba.chunks_exact(4)) {
- dst[0] = src[2];
- dst[1] = src[1];
- dst[2] = src[0];
- }
- ImageU8::new(width, height, 3, out)
-}
-
#[cfg(test)]
mod tests {
use super::*;
@@ -563,12 +543,4 @@ mod tests {
assert!(bgra_to_bgr(&padded, -8, 2, 2).is_err());
assert!(bgra_to_bgr(&padded, stride as i32, 0, 2).is_err());
}
-
- #[test]
- fn rgba_to_bgr_drops_alpha_and_reverses_channels() {
- let rgba = vec![1u8, 2, 3, 255, 10, 20, 30, 0];
- let bgr = rgba_to_bgr(&rgba, 2, 1).expect("conversion");
- assert_eq!(bgr.data, vec![3, 2, 1, 30, 20, 10]);
- assert!(rgba_to_bgr(&rgba, 3, 1).is_err());
- }
}