Browse Source

More progress towards automated op fuzzing.

Kestrel 2 months ago
parent
commit
9fa0824ec7
7 changed files with 52 additions and 19 deletions
  1. 4 1
      Cargo.toml
  2. 7 4
      src/colour.rs
  3. 27 8
      src/formats.rs
  4. 4 1
      src/lib.rs
  5. 1 0
      src/op/copy_from.rs
  6. 2 0
      src/op/fuzz.rs
  7. 7 5
      src/op/generate/impls.rs

+ 4 - 1
Cargo.toml

@@ -11,9 +11,12 @@ description = "Optimized software rendering library."
 keywords = ["raster", "render", "paint", "graphics"]
 license = "BSD-4-Clause OR MIT"
 
+[features]
+warnslow = []
+
 # features specification for docs.rs
 [package.metadata.docs.rs]
-features = []
+features = ["warnslow"]
 all-features = true
 
 [dependencies]

+ 7 - 4
src/colour.rs

@@ -79,14 +79,17 @@ impl Colour {
         src_pack: PackedLocation,
         dst_pack: PackedLocation,
     ) {
-        match (src_pack.index(), dst_pack.index()) {
-            (Some(srcindex), Some(dstindex)) => {
+        match (src_pack.index(), dst_pack.index(), dst_pack.clear_index()) {
+            (_,_,Some(clr)) => {
+                dst[clr as usize] = 0;
+            }
+            (Some(srcindex), Some(dstindex), None) => {
                 dst[dstindex as usize] = src[srcindex as usize];
             }
-            (None, Some(dstindex)) => {
+            (None, Some(dstindex), None) => {
                 dst[dstindex as usize] = 255;
             }
-            (_, None) => (),
+            (_, None, None) => (),
         }
     }
 

+ 27 - 8
src/formats.rs

@@ -15,19 +15,38 @@ pub enum PixelFormat {
 pub(crate) const NUM_PIXEL_FORMATS: usize = 7;
 pub(crate) const MAX_PIXEL_WIDTH: usize = 4;
 
+// pub struct PackedLocation(Option<u8>);
 #[derive(Clone, PartialEq, Debug, Default)]
-pub struct PackedLocation(Option<u8>);
+pub enum PackedLocation {
+    #[default]
+    None,
+    Select(u8),
+    Clear(u8)
+}
 
 impl PackedLocation {
     const fn empty() -> Self {
-        Self(None)
+        Self::None
     }
     const fn select_byte(index: u8) -> Self {
-        Self(Some(index))
+        Self::Select(index)
+    }
+    const fn clear_byte(index: u8) -> Self {
+        Self::Clear(index)
     }
 
     pub const fn index(&self) -> Option<u8> {
-        self.0
+        match self {
+            Self::None => None,
+            Self::Select(ndx) => Some(*ndx),
+            Self::Clear(_) => None
+        }
+    }
+    pub const fn clear_index(&self) -> Option<u8> {
+        match self {
+            Self::Clear(ndx) => Some(*ndx),
+            _ => None
+        }
     }
 }
 
@@ -135,10 +154,10 @@ impl PixelFormatSpec for Bgr32 {
 
     const NAME: &'static str = "Bgr32";
 
-    const RED_PACK: PackedLocation = PackedLocation::select_byte(2);
+    const RED_PACK: PackedLocation = PackedLocation::select_byte(0);
     const GREEN_PACK: PackedLocation = PackedLocation::select_byte(1);
-    const BLUE_PACK: PackedLocation = PackedLocation::select_byte(0);
-    const ALPHA_PACK: PackedLocation = PackedLocation::empty();
+    const BLUE_PACK: PackedLocation = PackedLocation::select_byte(2);
+    const ALPHA_PACK: PackedLocation = PackedLocation::clear_byte(3);
 }
 
 /// 24bpp colour densly packed into 24-bit words
@@ -188,7 +207,7 @@ impl PixelFormatSpec for Rgb32 {
     const RED_PACK: PackedLocation = PackedLocation::select_byte(2);
     const GREEN_PACK: PackedLocation = PackedLocation::select_byte(1);
     const BLUE_PACK: PackedLocation = PackedLocation::select_byte(0);
-    const ALPHA_PACK: PackedLocation = PackedLocation::empty();
+    const ALPHA_PACK: PackedLocation = PackedLocation::clear_byte(3);
 }
 
 /// RGBA with 8 bits per channel, stored little-endian

+ 4 - 1
src/lib.rs

@@ -15,12 +15,15 @@ std::compile_error!("kahlo only works on little-endian targets!");
 
 /// Colour-related functionality.
 pub mod colour;
+
+/// Aliased name for Americans
+pub use colour as color;
+
 /// Pixel format definitions.
 pub mod formats;
 
 /// Trait re-exports.
 pub mod prelude {
-    // pub use crate::ops::{AlphaPaintable, Readable, RgbaPaintable, Paintable, Writable};
     pub use crate::bitmap::{BitmapAccess, BitmapMutAccess};
     pub use crate::op::KahloOps;
 }

+ 1 - 0
src/op/copy_from.rs

@@ -85,6 +85,7 @@ fn copy_same_fmt<const WIDTH: usize>(
 ) {
     let read_box = params.0;
     let write_box = PixelBox::from_origin_and_size(params.1, read_box.size());
+
     let Some((read_box, write_box)) = clip_to(
         PixelBox::from_size(read_data.size()),
         PixelBox::from_size(write_data.size()),

+ 2 - 0
src/op/fuzz.rs

@@ -93,6 +93,8 @@ fn test_binary_format<
             &params,
         );
 
+        // XXX: replace with format-aware comparison (aka for bgr32, ignore fourth byte of each word)
+
         if specific_dst_img != generic_dst_img {
             let mut path = std::path::PathBuf::new();
             path.push(env!("CARGO_MANIFEST_DIR"));

+ 7 - 5
src/op/generate/impls.rs

@@ -97,18 +97,20 @@ pub fn dst_point(ctx: &mut Context) -> Option<PixelPoint> {
 
 pub fn dst_area(ctx: &mut Context) -> Option<PixelBox> {
     let mut rng = thread_rng();
-    let src_size = ctx.lookup::<DstSize>()?;
+    let dst_size = ctx.lookup::<DstSize>()?;
+    let p1 = point_in_size(&mut rng, dst_size);
+    let p2 = point_in_size(&mut rng, dst_size);
     Some(PixelBox::new(
-        point_in_size(&mut rng, src_size),
-        point_in_size(&mut rng, src_size),
+        p1.min(p2), p1.max(p2)
     ))
 }
 
 pub fn src_area(ctx: &mut Context) -> Option<PixelBox> {
     let mut rng = thread_rng();
     let src_size = ctx.lookup::<SrcSize>()?;
+    let p1 = point_in_size(&mut rng, src_size);
+    let p2 = point_in_size(&mut rng, src_size);
     Some(PixelBox::new(
-        point_in_size(&mut rng, src_size),
-        point_in_size(&mut rng, src_size),
+        p1.min(p2), p1.max(p2)
     ))
 }