diff --git a/ggdt/src/graphics/bitmap/rgb/blit.rs b/ggdt/src/graphics/bitmap/rgb/blit.rs index a4983af..fde308e 100644 --- a/ggdt/src/graphics/bitmap/rgb/blit.rs +++ b/ggdt/src/graphics/bitmap/rgb/blit.rs @@ -146,7 +146,7 @@ impl RgbaBitmap { dest_x, dest_y, |src_pixels, dest_pixels| { - *dest_pixels = blend.blend(*src_pixels, *dest_pixels); + *dest_pixels = blend.blend_1u32(*src_pixels, *dest_pixels); }, ); } @@ -170,7 +170,7 @@ impl RgbaBitmap { horizontal_flip, vertical_flip, |src_pixels, dest_pixels| { - *dest_pixels = blend.blend(*src_pixels, *dest_pixels); + *dest_pixels = blend.blend_1u32(*src_pixels, *dest_pixels); }, ); } @@ -239,7 +239,7 @@ impl RgbaBitmap { dest_y, |src_pixels, dest_pixels| { if *src_pixels != transparent_color { - *dest_pixels = blend.blend(*src_pixels, *dest_pixels); + *dest_pixels = blend.blend_1u32(*src_pixels, *dest_pixels); } }, ); @@ -293,7 +293,7 @@ impl RgbaBitmap { vertical_flip, |src_pixels, dest_pixels| { if *src_pixels != transparent_color { - *dest_pixels = blend.blend(*src_pixels, *dest_pixels); + *dest_pixels = blend.blend_1u32(*src_pixels, *dest_pixels); } }, ); @@ -347,7 +347,7 @@ impl RgbaBitmap { scale_y, |src_pixel, dest_bitmap, draw_x, draw_y| { if let Some(dest_pixel) = dest_bitmap.get_pixel(draw_x, draw_y) { - dest_bitmap.set_pixel(draw_x, draw_y, blend.blend(src_pixel, dest_pixel)) + dest_bitmap.set_pixel(draw_x, draw_y, blend.blend_1u32(src_pixel, dest_pixel)) } }, ); @@ -406,7 +406,7 @@ impl RgbaBitmap { |src_pixel, dest_bitmap, draw_x, draw_y| { if transparent_color != src_pixel { if let Some(dest_pixel) = dest_bitmap.get_pixel(draw_x, draw_y) { - dest_bitmap.set_pixel(draw_x, draw_y, blend.blend(src_pixel, dest_pixel)) + dest_bitmap.set_pixel(draw_x, draw_y, blend.blend_1u32(src_pixel, dest_pixel)) } } }, diff --git a/ggdt/src/graphics/bitmap/rgb/primitives.rs b/ggdt/src/graphics/bitmap/rgb/primitives.rs index 8ab0cf8..a4d91ad 100644 --- a/ggdt/src/graphics/bitmap/rgb/primitives.rs +++ b/ggdt/src/graphics/bitmap/rgb/primitives.rs @@ -8,7 +8,7 @@ impl RgbaBitmap { self.set_custom_pixel( x, // y, - |dest_color| blend.blend(color, dest_color), + |dest_color| blend.blend_1u32(color, dest_color), ); } @@ -20,7 +20,7 @@ impl RgbaBitmap { self.set_custom_pixel_unchecked( x, // y, - |dest_color| blend.blend(color, dest_color), + |dest_color| blend.blend_1u32(color, dest_color), ); } @@ -31,7 +31,7 @@ impl RgbaBitmap { y1, x2, y2, - |dest_color| blend.blend(color, dest_color), + |dest_color| blend.blend_1u32(color, dest_color), ); } @@ -42,7 +42,7 @@ impl RgbaBitmap { x1, // x2, y, - |dest_color| blend.blend(color, dest_color), + |dest_color| blend.blend_1u32(color, dest_color), ); } @@ -53,7 +53,7 @@ impl RgbaBitmap { x, // y1, y2, - |dest_color| blend.blend(color, dest_color), + |dest_color| blend.blend_1u32(color, dest_color), ); } @@ -66,7 +66,7 @@ impl RgbaBitmap { y1, x2, y2, - |dest_color| blend.blend(color, dest_color), + |dest_color| blend.blend_1u32(color, dest_color), ); } @@ -79,7 +79,7 @@ impl RgbaBitmap { y1, x2, y2, - |dest_color| blend.blend(color, dest_color), + |dest_color| blend.blend_1u32(color, dest_color), ); } } diff --git a/ggdt/src/graphics/bitmap/rgb/triangles.rs b/ggdt/src/graphics/bitmap/rgb/triangles.rs index e56bf51..0cdb35f 100644 --- a/ggdt/src/graphics/bitmap/rgb/triangles.rs +++ b/ggdt/src/graphics/bitmap/rgb/triangles.rs @@ -86,7 +86,7 @@ impl RgbaBitmap { positions[0], positions[1], positions[2], - |dest_pixels, _w0, _w1, _w2| *dest_pixels = blend.blend(color, *dest_pixels), + |dest_pixels, _w0, _w1, _w2| *dest_pixels = blend.blend_1u32(color, *dest_pixels), ) } @@ -129,7 +129,7 @@ impl RgbaBitmap { let r = ((w0 * r1 as f32 + w1 * r2 as f32 + w2 * r3 as f32) / area) as u8; let g = ((w0 * g1 as f32 + w1 * g2 as f32 + w2 * g3 as f32) / area) as u8; let b = ((w0 * b1 as f32 + w1 * b2 as f32 + w2 * b3 as f32) / area) as u8; - *dest_pixels = blend.blend(to_argb32([a, r, g, b]), *dest_pixels) + *dest_pixels = blend.blend_1u32(to_argb32([a, r, g, b]), *dest_pixels) }, ) } @@ -188,7 +188,7 @@ impl RgbaBitmap { let u = (w0 * texcoords[0].x + w1 * texcoords[1].x + w2 * texcoords[2].x) / area; let v = (w0 * texcoords[0].y + w1 * texcoords[1].y + w2 * texcoords[2].y) / area; let src = multiply_argb32(bitmap.sample_at(u, v), color); - *dest_pixels = blend.blend(src, *dest_pixels) + *dest_pixels = blend.blend_1u32(src, *dest_pixels) }, ) } @@ -245,7 +245,7 @@ impl RgbaBitmap { let u = (w0 * texcoords[0].x + w1 * texcoords[1].x + w2 * texcoords[2].x) / area; let v = (w0 * texcoords[0].y + w1 * texcoords[1].y + w2 * texcoords[2].y) / area; let src = multiply_argb32(bitmap.sample_at(u, v), to_argb32([a, r, g, b])); - *dest_pixels = blend.blend(src, *dest_pixels) + *dest_pixels = blend.blend_1u32(src, *dest_pixels) }, ) } @@ -287,7 +287,7 @@ impl RgbaBitmap { |dest_pixels, w0, w1, w2| { let u = (w0 * texcoords[0].x + w1 * texcoords[1].x + w2 * texcoords[2].x) / area; let v = (w0 * texcoords[0].y + w1 * texcoords[1].y + w2 * texcoords[2].y) / area; - *dest_pixels = blend.blend(bitmap.sample_at(u, v), *dest_pixels); + *dest_pixels = blend.blend_1u32(bitmap.sample_at(u, v), *dest_pixels); }, ) } diff --git a/ggdt/src/graphics/color.rs b/ggdt/src/graphics/color.rs index 8b0bab7..4b1411b 100644 --- a/ggdt/src/graphics/color.rs +++ b/ggdt/src/graphics/color.rs @@ -52,7 +52,7 @@ impl BlendFunction { /// * `dest`: the destination color to blend the source color over /// /// returns: the blended color - pub fn blend(&self, src: Color1u32, dest: Color1u32) -> Color1u32 { + pub fn blend_1u32(&self, src: Color1u32, dest: Color1u32) -> Color1u32 { use BlendFunction::*; match self { Blend => blend_argb32(src, dest), @@ -67,6 +67,23 @@ impl BlendFunction { } } } + + #[inline] + pub fn blend_4u8(&self, src: Color4u8, dest: Color4u8) -> Color4u8 { + use BlendFunction::*; + match self { + Blend => blend_argb(src, dest), + BlendSourceWithAlpha(opacity) => blend_argb_source_by(src, dest, *opacity), + TintedBlend(tint) => { + let tinted = tint_argb(src, from_argb32(*tint)); + blend_argb(tinted, dest) + } + MultipliedBlend(color) => { + let multiplied = multiply_argb(src, from_argb32(*color)); + blend_argb(multiplied, dest) + } + } + } } /// Packs a set of individual ARGB components to a packed 32-bit color value.