the big switch from ARGB to RGBA format for 32-bit color pixels

This commit is contained in:
Gered 2023-05-05 18:14:37 -04:00
parent 78d8102a23
commit 3a56926345
32 changed files with 461 additions and 461 deletions

View file

@ -11,7 +11,7 @@ pub struct CoreContext {
pub delta: f32,
pub camera_x: i32,
pub camera_y: i32,
pub transparent_color: ARGB,
pub transparent_color: RGBA,
pub system: System<Standard>,
pub palette: Palette,
pub font: BitmaskFont,

View file

@ -63,7 +63,7 @@ impl TileMap {
tiles: &BitmapAtlas<RgbaBitmap>,
camera_x: i32,
camera_y: i32,
transparent_color: ARGB,
transparent_color: RGBA,
) {
let xt = camera_x / TILE_WIDTH as i32;
let yt = camera_y / TILE_HEIGHT as i32;

View file

@ -7,10 +7,10 @@ pub fn criterion_benchmark(c: &mut Criterion) {
let height = 240;
let mut source = IndexedBitmap::new(width, height).unwrap();
let mut dest = vec![ARGB::default(); (width * height) as usize].into_boxed_slice();
let mut dest = vec![RGBA::default(); (width * height) as usize].into_boxed_slice();
let palette = Palette::new_vga_palette().unwrap();
c.bench_function("deindex_bitmap_pixels", |b| b.iter(|| source.copy_as_argb_to(&mut dest, &palette)));
c.bench_function("deindex_bitmap_pixels", |b| b.iter(|| source.copy_as_rgba_to(&mut dest, &palette)));
c.bench_function("set_pixel", |b| b.iter(|| source.set_pixel(black_box(100), black_box(100), black_box(42))));

View file

@ -6,9 +6,9 @@ pub fn criterion_benchmark(c: &mut Criterion) {
let width = 320;
let height = 240;
const BG_COLOR: ARGB = ARGB::from_rgb([0, 0, 0]);
const SOLID_COLOR: ARGB = ARGB::from_rgb([255, 0, 255]);
const BLEND_COLOR: ARGB = ARGB::from_argb([127, 255, 0, 255]);
const BG_COLOR: RGBA = RGBA::from_rgb([0, 0, 0]);
const SOLID_COLOR: RGBA = RGBA::from_rgb([255, 0, 255]);
const BLEND_COLOR: RGBA = RGBA::from_rgba([255, 0, 255, 127]);
let mut dest = RgbaBitmap::new(width, height).unwrap();

View file

@ -22,10 +22,10 @@ pub fn criterion_benchmark(c: &mut Criterion) {
let texcoord_0_1 = Vector2::new(0.0, 1.0);
let texcoord_1_1 = Vector2::new(1.0, 1.0);
let color = ARGB::from_rgb([255, 255, 255]);
let color_1 = ARGB::from_argb([255, 255, 0, 0]);
let color_2 = ARGB::from_argb([255, 0, 255, 0]);
let color_3 = ARGB::from_argb([255, 0, 0, 255]);
let color = RGBA::from_rgb([255, 255, 255]);
let color_1 = RGBA::from_rgba([255, 0, 0, 255]);
let color_2 = RGBA::from_rgba([0, 255, 0, 255]);
let color_3 = RGBA::from_rgba([0, 0, 255, 255]);
c.bench_function("rgbabitmap_triangle_2d_solid_color", |b| {
let triangle = RgbaTriangle2d::Solid { position: [big_v1, big_v2, big_v3], color };

View file

@ -7,7 +7,7 @@
//! Only a subset of the most common Bitmap drawing operations will be provided here.
use crate::graphics::{
BitmapError, Font, FontRenderOpts, IndexedBitmap, IndexedBlitMethod, Pixel, RgbaBitmap, RgbaBlitMethod, ARGB,
BitmapError, Font, FontRenderOpts, IndexedBitmap, IndexedBlitMethod, Pixel, RgbaBitmap, RgbaBlitMethod, RGBA,
};
use crate::math::Rect;
@ -220,7 +220,7 @@ impl GeneralBitmap for IndexedBitmap {
}
impl GeneralBitmap for RgbaBitmap {
type PixelType = ARGB;
type PixelType = RGBA;
#[inline]
fn new(width: u32, height: u32) -> Result<Self, BitmapError> {

View file

@ -1,6 +1,6 @@
use std::path::Path;
use crate::graphics::{Bitmap, BitmapError, Palette, RgbaBitmap, ARGB};
use crate::graphics::{Bitmap, BitmapError, Palette, RgbaBitmap, RGBA};
mod blit;
mod primitives;
@ -44,14 +44,14 @@ impl IndexedBitmap {
}
/// Copies and converts the entire pixel data from this bitmap to a destination expecting
/// 32-bit ARGB-format pixel data. This can be used to display the contents of the bitmap
/// 32-bit RGBA-format pixel data. This can be used to display the contents of the bitmap
/// on-screen by using an SDL Surface, OpenGL texture, etc as the destination.
///
/// # Arguments
///
/// * `dest`: destination 32-bit ARGB pixel buffer to copy converted pixels to
/// * `dest`: destination 32-bit RGBA pixel buffer to copy converted pixels to
/// * `palette`: the 256 colour palette to use during pixel conversion
pub fn copy_as_argb_to(&self, dest: &mut [ARGB], palette: &Palette) {
pub fn copy_as_rgba_to(&self, dest: &mut [RGBA], palette: &Palette) {
for (src, dest) in self.pixels().iter().zip(dest.iter_mut()) {
*dest = palette[*src];
}
@ -67,7 +67,7 @@ impl IndexedBitmap {
/// returns: `RgbaBitmap`
pub fn to_rgba(&self, palette: &Palette) -> RgbaBitmap {
let mut output = RgbaBitmap::new(self.width, self.height).unwrap();
self.copy_as_argb_to(output.pixels_mut(), palette);
self.copy_as_rgba_to(output.pixels_mut(), palette);
output
}
}

View file

@ -7,7 +7,7 @@ use std::path::Path;
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use thiserror::Error;
use crate::graphics::{Bitmap, IndexedBitmap, Palette, PaletteError, PaletteFormat, Pixel, RgbaBitmap, ARGB};
use crate::graphics::{Bitmap, IndexedBitmap, Palette, PaletteError, PaletteFormat, Pixel, RgbaBitmap, RGBA};
use crate::utils::ReadFixedLengthByteArray;
const PNG_HEADER: [u8; 8] = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];
@ -319,8 +319,8 @@ impl ScanlinePixelConverter<u8> for ScanlineBuffer {
}
}
impl ScanlinePixelConverter<ARGB> for ScanlineBuffer {
fn read_pixel(&mut self, x: usize, palette: &Option<Palette>) -> Result<ARGB, PngError> {
impl ScanlinePixelConverter<RGBA> for ScanlineBuffer {
fn read_pixel(&mut self, x: usize, palette: &Option<Palette>) -> Result<RGBA, PngError> {
let offset = x * self.bpp;
match self.format {
ColorFormat::IndexedColor => {
@ -337,20 +337,20 @@ impl ScanlinePixelConverter<ARGB> for ScanlineBuffer {
let r = self.current[offset];
let g = self.current[offset + 1];
let b = self.current[offset + 2];
Ok(ARGB::from_rgb([r, g, b]))
Ok(RGBA::from_rgb([r, g, b]))
}
ColorFormat::RGBA => {
let r = self.current[offset];
let g = self.current[offset + 1];
let b = self.current[offset + 2];
let a = self.current[offset + 3];
Ok(ARGB::from_argb([a, r, g, b]))
Ok(RGBA::from_rgba([r, g, b, a]))
}
_ => Err(PngError::BadFile(format!("Unsupported color format for this PixelReader: {:?}", self.format))),
}
}
fn write_pixel(&mut self, x: usize, pixel: ARGB) -> Result<(), PngError> {
fn write_pixel(&mut self, x: usize, pixel: RGBA) -> Result<(), PngError> {
let offset = x * self.bpp;
match self.format {
ColorFormat::RGB => {
@ -614,7 +614,7 @@ mod tests {
use claim::*;
use tempfile::TempDir;
use crate::tests::{load_raw_argb, load_raw_indexed};
use crate::tests::{load_raw_indexed, load_raw_rgba};
use super::*;
@ -635,7 +635,7 @@ mod tests {
#[test]
pub fn loads_indexed_256_color_to_rgba_destination() -> Result<(), PngError> {
let ref_bytes = load_raw_argb(test_file(Path::new("indexed_8_rgba.bin")).as_path())?;
let ref_bytes = load_raw_rgba(test_file(Path::new("indexed_8_rgba.bin")).as_path())?;
let (bmp, palette) = RgbaBitmap::load_png_file(test_file(Path::new("indexed_8.png")).as_path())?;
assert!(palette.is_some());
assert_eq!(ref_bytes, bmp.pixels);
@ -644,7 +644,7 @@ mod tests {
#[test]
pub fn loads_rgb_color() -> Result<(), PngError> {
let ref_bytes = load_raw_argb(test_file(Path::new("rgb.bin")).as_path())?;
let ref_bytes = load_raw_rgba(test_file(Path::new("rgb.bin")).as_path())?;
let (bmp, palette) = RgbaBitmap::load_png_file(test_file(Path::new("rgb.png")).as_path())?;
assert!(palette.is_none());
assert_eq!(ref_bytes, bmp.pixels);
@ -653,7 +653,7 @@ mod tests {
#[test]
pub fn loads_rgba_color() -> Result<(), PngError> {
let ref_bytes = load_raw_argb(test_file(Path::new("rgba.bin")).as_path())?;
let ref_bytes = load_raw_rgba(test_file(Path::new("rgba.bin")).as_path())?;
let (bmp, palette) = RgbaBitmap::load_png_file(test_file(Path::new("rgba.png")).as_path())?;
assert!(palette.is_none());
assert_eq!(ref_bytes, bmp.pixels);
@ -662,7 +662,7 @@ mod tests {
#[test]
pub fn loads_filter_0() -> Result<(), PngError> {
let ref_bytes = load_raw_argb(test_file(Path::new("filter_0_rgb.bin")).as_path())?;
let ref_bytes = load_raw_rgba(test_file(Path::new("filter_0_rgb.bin")).as_path())?;
let (bmp, palette) = RgbaBitmap::load_png_file(test_file(Path::new("filter_0_rgb.png")).as_path())?;
assert!(palette.is_none());
assert_eq!(ref_bytes, bmp.pixels);
@ -671,7 +671,7 @@ mod tests {
#[test]
pub fn loads_filter_1() -> Result<(), PngError> {
let ref_bytes = load_raw_argb(test_file(Path::new("filter_1_rgb.bin")).as_path())?;
let ref_bytes = load_raw_rgba(test_file(Path::new("filter_1_rgb.bin")).as_path())?;
let (bmp, palette) = RgbaBitmap::load_png_file(test_file(Path::new("filter_1_rgb.png")).as_path())?;
assert!(palette.is_none());
assert_eq!(ref_bytes, bmp.pixels);
@ -680,7 +680,7 @@ mod tests {
#[test]
pub fn loads_filter_2() -> Result<(), PngError> {
let ref_bytes = load_raw_argb(test_file(Path::new("filter_2_rgb.bin")).as_path())?;
let ref_bytes = load_raw_rgba(test_file(Path::new("filter_2_rgb.bin")).as_path())?;
let (bmp, palette) = RgbaBitmap::load_png_file(test_file(Path::new("filter_2_rgb.png")).as_path())?;
assert!(palette.is_none());
assert_eq!(ref_bytes, bmp.pixels);
@ -689,7 +689,7 @@ mod tests {
#[test]
pub fn loads_filter_3() -> Result<(), PngError> {
let ref_bytes = load_raw_argb(test_file(Path::new("filter_3_rgb.bin")).as_path())?;
let ref_bytes = load_raw_rgba(test_file(Path::new("filter_3_rgb.bin")).as_path())?;
let (bmp, palette) = RgbaBitmap::load_png_file(test_file(Path::new("filter_3_rgb.png")).as_path())?;
assert!(palette.is_none());
assert_eq!(ref_bytes, bmp.pixels);
@ -698,7 +698,7 @@ mod tests {
#[test]
pub fn loads_filter_4() -> Result<(), PngError> {
let ref_bytes = load_raw_argb(test_file(Path::new("filter_4_rgb.bin")).as_path())?;
let ref_bytes = load_raw_rgba(test_file(Path::new("filter_4_rgb.bin")).as_path())?;
let (bmp, palette) = RgbaBitmap::load_png_file(test_file(Path::new("filter_4_rgb.png")).as_path())?;
assert!(palette.is_none());
assert_eq!(ref_bytes, bmp.pixels);
@ -722,12 +722,12 @@ mod tests {
#[test]
pub fn loads_larger_rgb_images() -> Result<(), PngError> {
let ref_bytes = load_raw_argb(test_file(Path::new("large_1_rgba.bin")).as_path())?;
let ref_bytes = load_raw_rgba(test_file(Path::new("large_1_rgba.bin")).as_path())?;
let (bmp, palette) = RgbaBitmap::load_png_file(test_file(Path::new("large_1_rgb.png")).as_path())?;
assert!(palette.is_none());
assert_eq!(ref_bytes, bmp.pixels);
let ref_bytes = load_raw_argb(test_file(Path::new("large_2_rgba.bin")).as_path())?;
let ref_bytes = load_raw_rgba(test_file(Path::new("large_2_rgba.bin")).as_path())?;
let (bmp, palette) = RgbaBitmap::load_png_file(test_file(Path::new("large_2_rgb.png")).as_path())?;
assert!(palette.is_none());
assert_eq!(ref_bytes, bmp.pixels);
@ -805,7 +805,7 @@ mod tests {
pub fn load_and_save_rgb_color() -> Result<(), PngError> {
let tmp_dir = TempDir::new()?;
let ref_bytes = load_raw_argb(test_file(Path::new("rgb.bin")).as_path())?;
let ref_bytes = load_raw_rgba(test_file(Path::new("rgb.bin")).as_path())?;
let (bmp, palette) = RgbaBitmap::load_png_file(test_file(Path::new("rgb.png")).as_path())?;
assert_eq!(32, bmp.width());
@ -830,7 +830,7 @@ mod tests {
// first image
let ref_bytes = load_raw_argb(test_file(Path::new("large_1_rgba.bin")).as_path())?;
let ref_bytes = load_raw_rgba(test_file(Path::new("large_1_rgba.bin")).as_path())?;
let (bmp, palette) = RgbaBitmap::load_png_file(test_file(Path::new("large_1_rgb.png")).as_path())?;
assert_eq!(320, bmp.width());
@ -848,7 +848,7 @@ mod tests {
// second image
let ref_bytes = load_raw_argb(test_file(Path::new("large_2_rgba.bin")).as_path())?;
let ref_bytes = load_raw_rgba(test_file(Path::new("large_2_rgba.bin")).as_path())?;
let (bmp, palette) = RgbaBitmap::load_png_file(test_file(Path::new("large_2_rgb.png")).as_path())?;
assert_eq!(320, bmp.width());

View file

@ -1,6 +1,6 @@
use crate::graphics::{
clip_blit, per_pixel_blit, per_pixel_flipped_blit, per_pixel_rotozoom_blit, BitmapAtlas, BlendFunction, RgbaBitmap,
ARGB,
RGBA,
};
use crate::math::Rect;
@ -8,7 +8,7 @@ use crate::math::Rect;
pub enum RgbaBlitMethod {
/// Solid blit, no transparency or other per-pixel adjustments.
Solid,
SolidTinted(ARGB),
SolidTinted(RGBA),
SolidBlended(BlendFunction),
/// Same as [RgbaBlitMethod::Solid] but the drawn image can also be flipped horizontally
/// and/or vertically.
@ -19,7 +19,7 @@ pub enum RgbaBlitMethod {
SolidFlippedTinted {
horizontal_flip: bool,
vertical_flip: bool,
tint_color: ARGB,
tint_color: RGBA,
},
SolidFlippedBlended {
horizontal_flip: bool,
@ -27,30 +27,30 @@ pub enum RgbaBlitMethod {
blend: BlendFunction,
},
/// Transparent blit, the specified source color pixels are skipped.
Transparent(ARGB),
Transparent(RGBA),
TransparentTinted {
transparent_color: ARGB,
tint_color: ARGB,
transparent_color: RGBA,
tint_color: RGBA,
},
TransparentBlended {
transparent_color: ARGB,
transparent_color: RGBA,
blend: BlendFunction,
},
/// Same as [RgbaBlitMethod::Transparent] but the drawn image can also be flipped horizontally
/// and/or vertically.
TransparentFlipped {
transparent_color: ARGB,
transparent_color: RGBA,
horizontal_flip: bool,
vertical_flip: bool,
},
TransparentFlippedTinted {
transparent_color: ARGB,
transparent_color: RGBA,
horizontal_flip: bool,
vertical_flip: bool,
tint_color: ARGB,
tint_color: RGBA,
},
TransparentFlippedBlended {
transparent_color: ARGB,
transparent_color: RGBA,
horizontal_flip: bool,
vertical_flip: bool,
blend: BlendFunction,
@ -58,15 +58,15 @@ pub enum RgbaBlitMethod {
/// Same as [RgbaBlitMethod::Transparent] except that the visible pixels on the destination are all
/// drawn using the same color.
TransparentSingle {
transparent_color: ARGB,
draw_color: ARGB,
transparent_color: RGBA,
draw_color: RGBA,
},
/// Combination of [RgbaBlitMethod::TransparentFlipped] and [RgbaBlitMethod::TransparentSingle].
TransparentFlippedSingle {
transparent_color: ARGB,
transparent_color: RGBA,
horizontal_flip: bool,
vertical_flip: bool,
draw_color: ARGB,
draw_color: RGBA,
},
/// Rotozoom blit, works the same as [RgbaBlitMethod::Solid] except that rotation and scaling is
/// performed.
@ -79,7 +79,7 @@ pub enum RgbaBlitMethod {
angle: f32,
scale_x: f32,
scale_y: f32,
tint_color: ARGB,
tint_color: RGBA,
},
RotoZoomBlended {
angle: f32,
@ -92,20 +92,20 @@ pub enum RgbaBlitMethod {
angle: f32,
scale_x: f32,
scale_y: f32,
transparent_color: ARGB,
transparent_color: RGBA,
},
RotoZoomTransparentTinted {
angle: f32,
scale_x: f32,
scale_y: f32,
transparent_color: ARGB,
tint_color: ARGB,
transparent_color: RGBA,
tint_color: RGBA,
},
RotoZoomTransparentBlended {
angle: f32,
scale_x: f32,
scale_y: f32,
transparent_color: ARGB,
transparent_color: RGBA,
blend: BlendFunction,
},
}
@ -117,7 +117,7 @@ impl RgbaBitmap {
src_region: &Rect,
dest_x: i32,
dest_y: i32,
tint_color: ARGB,
tint_color: RGBA,
) {
per_pixel_blit(
self, //
@ -183,7 +183,7 @@ impl RgbaBitmap {
dest_y: i32,
horizontal_flip: bool,
vertical_flip: bool,
tint_color: ARGB,
tint_color: RGBA,
) {
per_pixel_flipped_blit(
self, //
@ -205,8 +205,8 @@ impl RgbaBitmap {
src_region: &Rect,
dest_x: i32,
dest_y: i32,
transparent_color: ARGB,
tint_color: ARGB,
transparent_color: RGBA,
tint_color: RGBA,
) {
per_pixel_blit(
self, //
@ -228,7 +228,7 @@ impl RgbaBitmap {
src_region: &Rect,
dest_x: i32,
dest_y: i32,
transparent_color: ARGB,
transparent_color: RGBA,
blend: BlendFunction,
) {
per_pixel_blit(
@ -251,10 +251,10 @@ impl RgbaBitmap {
src_region: &Rect,
dest_x: i32,
dest_y: i32,
transparent_color: ARGB,
transparent_color: RGBA,
horizontal_flip: bool,
vertical_flip: bool,
tint_color: ARGB,
tint_color: RGBA,
) {
per_pixel_flipped_blit(
self, //
@ -278,7 +278,7 @@ impl RgbaBitmap {
src_region: &Rect,
dest_x: i32,
dest_y: i32,
transparent_color: ARGB,
transparent_color: RGBA,
horizontal_flip: bool,
vertical_flip: bool,
blend: BlendFunction,
@ -308,7 +308,7 @@ impl RgbaBitmap {
angle: f32,
scale_x: f32,
scale_y: f32,
tint_color: ARGB,
tint_color: RGBA,
) {
per_pixel_rotozoom_blit(
self, //
@ -362,8 +362,8 @@ impl RgbaBitmap {
angle: f32,
scale_x: f32,
scale_y: f32,
transparent_color: ARGB,
tint_color: ARGB,
transparent_color: RGBA,
tint_color: RGBA,
) {
per_pixel_rotozoom_blit(
self, //
@ -391,7 +391,7 @@ impl RgbaBitmap {
angle: f32,
scale_x: f32,
scale_y: f32,
transparent_color: ARGB,
transparent_color: RGBA,
blend: BlendFunction,
) {
per_pixel_rotozoom_blit(

View file

@ -1,7 +1,7 @@
use byteorder::ReadBytesExt;
use std::path::Path;
use crate::graphics::{Bitmap, BitmapError, Palette, ARGB};
use crate::graphics::{Bitmap, BitmapError, Palette, RGBA};
mod blit;
mod primitives;
@ -11,7 +11,7 @@ pub use blit::*;
pub use primitives::*;
pub use triangles::*;
pub type RgbaBitmap = Bitmap<ARGB>;
pub type RgbaBitmap = Bitmap<RGBA>;
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum RgbaPixelFormat {
@ -29,7 +29,7 @@ impl RgbaBitmap {
///
/// returns: `Result<Bitmap, BitmapError>`
pub fn new(width: u32, height: u32) -> Result<Self, BitmapError> {
Self::internal_new(width, height, ARGB::from_rgb([0, 0, 0]))
Self::internal_new(width, height, RGBA::from_rgb([0, 0, 0]))
}
pub fn from_bytes<T: ReadBytesExt>(
@ -38,7 +38,7 @@ impl RgbaBitmap {
format: RgbaPixelFormat,
reader: &mut T,
) -> Result<Self, BitmapError> {
let mut bitmap = Self::internal_new(width, height, ARGB::from_rgb([0, 0, 0]))?;
let mut bitmap = Self::internal_new(width, height, RGBA::from_rgb([0, 0, 0]))?;
for pixel in bitmap.pixels_mut().iter_mut() {
*pixel = match format {
RgbaPixelFormat::RGBA => {
@ -46,14 +46,14 @@ impl RgbaBitmap {
let g = reader.read_u8()?;
let b = reader.read_u8()?;
let a = reader.read_u8()?;
ARGB::from_argb([a, r, g, b])
RGBA::from_rgba([r, g, b, a])
}
RgbaPixelFormat::ARGB => {
let a = reader.read_u8()?;
let r = reader.read_u8()?;
let g = reader.read_u8()?;
let b = reader.read_u8()?;
ARGB::from_argb([a, r, g, b])
RGBA::from_rgba([r, g, b, a])
}
};
}

View file

@ -1,10 +1,10 @@
use crate::graphics::{BlendFunction, RgbaBitmap, ARGB};
use crate::graphics::{BlendFunction, RgbaBitmap, RGBA};
impl RgbaBitmap {
/// Sets the pixel at the given coordinates using a blended color via the specified blend function
/// If the coordinates lie outside of the bitmaps clipping region, no pixels will be changed.
#[inline]
pub fn set_blended_pixel(&mut self, x: i32, y: i32, color: ARGB, blend: BlendFunction) {
pub fn set_blended_pixel(&mut self, x: i32, y: i32, color: RGBA, blend: BlendFunction) {
self.set_custom_pixel(
x, //
y,
@ -16,7 +16,7 @@ impl RgbaBitmap {
/// The coordinates are not checked for validity, so it is up to you to ensure they lie within the
/// bounds of the bitmap.
#[inline]
pub unsafe fn set_blended_pixel_unchecked(&mut self, x: i32, y: i32, color: ARGB, blend: BlendFunction) {
pub unsafe fn set_blended_pixel_unchecked(&mut self, x: i32, y: i32, color: RGBA, blend: BlendFunction) {
self.set_custom_pixel_unchecked(
x, //
y,
@ -26,7 +26,7 @@ impl RgbaBitmap {
/// Draws a line from x1,y1 to x2,y2 by blending the drawn pixels using the given blend function.
#[inline]
pub fn blended_line(&mut self, x1: i32, y1: i32, x2: i32, y2: i32, color: ARGB, blend: BlendFunction) {
pub fn blended_line(&mut self, x1: i32, y1: i32, x2: i32, y2: i32, color: RGBA, blend: BlendFunction) {
self.line_custom(
x1, //
y1,
@ -39,7 +39,7 @@ impl RgbaBitmap {
/// Draws a horizontal line from x1,y to x2,y by blending the drawn pixels using the given
/// blend function.
#[inline]
pub fn blended_horiz_line(&mut self, x1: i32, x2: i32, y: i32, color: ARGB, blend: BlendFunction) {
pub fn blended_horiz_line(&mut self, x1: i32, x2: i32, y: i32, color: RGBA, blend: BlendFunction) {
self.horiz_line_custom(
x1, //
x2,
@ -51,7 +51,7 @@ impl RgbaBitmap {
/// Draws a vertical line from x,y1 to x,y2 by blending the drawn pixels using the given blend
/// function.
#[inline]
pub fn blended_vert_line(&mut self, x: i32, y1: i32, y2: i32, color: ARGB, blend: BlendFunction) {
pub fn blended_vert_line(&mut self, x: i32, y1: i32, y2: i32, color: RGBA, blend: BlendFunction) {
self.vert_line_custom(
x, //
y1,
@ -64,7 +64,7 @@ impl RgbaBitmap {
/// drawn, assuming they are specifying the top-left and bottom-right corners respectively.
/// The box is drawn by blending the drawn pixels using the given blend function.
#[inline]
pub fn blended_rect(&mut self, x1: i32, y1: i32, x2: i32, y2: i32, color: ARGB, blend: BlendFunction) {
pub fn blended_rect(&mut self, x1: i32, y1: i32, x2: i32, y2: i32, color: RGBA, blend: BlendFunction) {
self.rect_custom(
x1, //
y1,
@ -78,7 +78,7 @@ impl RgbaBitmap {
/// drawn, assuming they are specifying the top-left and bottom-right corners respectively. The
/// filled box is draw by blending the drawn pixels using the given blend function.
#[inline]
pub fn blended_filled_rect(&mut self, x1: i32, y1: i32, x2: i32, y2: i32, color: ARGB, blend: BlendFunction) {
pub fn blended_filled_rect(&mut self, x1: i32, y1: i32, x2: i32, y2: i32, color: RGBA, blend: BlendFunction) {
self.filled_rect_custom(
x1, //
y1,

View file

@ -1,26 +1,26 @@
use std::simd;
use crate::graphics::{edge_function, per_pixel_triangle_2d, BlendFunction, RgbaBitmap, ARGB};
use crate::graphics::{edge_function, per_pixel_triangle_2d, BlendFunction, RgbaBitmap, RGBA};
use crate::math::Vector2;
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum RgbaTriangle2d<'a> {
Solid {
position: [Vector2; 3], //
color: ARGB,
color: RGBA,
},
SolidBlended {
position: [Vector2; 3], //
color: ARGB,
color: RGBA,
blend: BlendFunction,
},
SolidMultiColor {
position: [Vector2; 3], //
color: [ARGB; 3],
color: [RGBA; 3],
},
SolidMultiColorBlended {
position: [Vector2; 3], //
color: [ARGB; 3],
color: [RGBA; 3],
blend: BlendFunction,
},
SolidTextured {
@ -31,26 +31,26 @@ pub enum RgbaTriangle2d<'a> {
SolidTexturedColored {
position: [Vector2; 3], //
texcoord: [Vector2; 3],
color: ARGB,
color: RGBA,
bitmap: &'a RgbaBitmap,
},
SolidTexturedColoredBlended {
position: [Vector2; 3], //
texcoord: [Vector2; 3],
color: ARGB,
color: RGBA,
bitmap: &'a RgbaBitmap,
blend: BlendFunction,
},
SolidTexturedMultiColored {
position: [Vector2; 3], //
texcoord: [Vector2; 3],
color: [ARGB; 3],
color: [RGBA; 3],
bitmap: &'a RgbaBitmap,
},
SolidTexturedMultiColoredBlended {
position: [Vector2; 3], //
texcoord: [Vector2; 3],
color: [ARGB; 3],
color: [RGBA; 3],
bitmap: &'a RgbaBitmap,
blend: BlendFunction,
},
@ -58,7 +58,7 @@ pub enum RgbaTriangle2d<'a> {
position: [Vector2; 3], //
texcoord: [Vector2; 3],
bitmap: &'a RgbaBitmap,
tint: ARGB,
tint: RGBA,
},
SolidTexturedBlended {
position: [Vector2; 3], //
@ -69,7 +69,7 @@ pub enum RgbaTriangle2d<'a> {
}
impl RgbaBitmap {
pub fn solid_triangle_2d(&mut self, positions: &[Vector2; 3], color: ARGB) {
pub fn solid_triangle_2d(&mut self, positions: &[Vector2; 3], color: RGBA) {
per_pixel_triangle_2d(
self, //
positions[0],
@ -79,7 +79,7 @@ impl RgbaBitmap {
)
}
pub fn solid_blended_triangle_2d(&mut self, positions: &[Vector2; 3], color: ARGB, blend: BlendFunction) {
pub fn solid_blended_triangle_2d(&mut self, positions: &[Vector2; 3], color: RGBA, blend: BlendFunction) {
per_pixel_triangle_2d(
self, //
positions[0],
@ -89,7 +89,7 @@ impl RgbaBitmap {
)
}
pub fn solid_multicolor_triangle_2d(&mut self, positions: &[Vector2; 3], colors: &[ARGB; 3]) {
pub fn solid_multicolor_triangle_2d(&mut self, positions: &[Vector2; 3], colors: &[RGBA; 3]) {
let area = simd::f32x4::splat(edge_function(positions[0], positions[1], positions[2]));
let color1 = colors[0].0.cast();
let color2 = colors[1].0.cast();
@ -105,7 +105,7 @@ impl RgbaBitmap {
+ simd::f32x4::splat(w2) * color3)
/ area)
.cast();
*dest_pixels = ARGB(color)
*dest_pixels = RGBA(color)
},
)
}
@ -113,7 +113,7 @@ impl RgbaBitmap {
pub fn solid_multicolor_blended_triangle_2d(
&mut self,
positions: &[Vector2; 3],
colors: &[ARGB; 3],
colors: &[RGBA; 3],
blend: BlendFunction,
) {
let area = simd::f32x4::splat(edge_function(positions[0], positions[1], positions[2]));
@ -131,7 +131,7 @@ impl RgbaBitmap {
+ simd::f32x4::splat(w2) * color3)
/ area)
.cast();
*dest_pixels = blend.blend(ARGB(color), *dest_pixels)
*dest_pixels = blend.blend(RGBA(color), *dest_pixels)
},
)
}
@ -160,7 +160,7 @@ impl RgbaBitmap {
&mut self,
positions: &[Vector2; 3],
texcoords: &[Vector2; 3],
color: ARGB,
color: RGBA,
bitmap: &Self,
) {
let area = simd::f32x2::splat(edge_function(positions[0], positions[1], positions[2]));
@ -187,7 +187,7 @@ impl RgbaBitmap {
&mut self,
positions: &[Vector2; 3],
texcoords: &[Vector2; 3],
color: ARGB,
color: RGBA,
bitmap: &Self,
blend: BlendFunction,
) {
@ -216,7 +216,7 @@ impl RgbaBitmap {
&mut self,
positions: &[Vector2; 3],
texcoords: &[Vector2; 3],
colors: &[ARGB; 3],
colors: &[RGBA; 3],
bitmap: &Self,
) {
let area = simd::f32x4::splat(edge_function(positions[0], positions[1], positions[2]));
@ -241,7 +241,7 @@ impl RgbaBitmap {
let color = ((w0 * color1 + w1 * color2 + w2 * color3) / area).cast::<u8>();
let texcoord = (w0 * texcoord1 + w1 * texcoord2 + w2 * texcoord3) / area;
let texel = bitmap.sample_at(texcoord[0], texcoord[1]);
*dest_pixels = texel * ARGB(color)
*dest_pixels = texel * RGBA(color)
},
)
}
@ -250,7 +250,7 @@ impl RgbaBitmap {
&mut self,
positions: &[Vector2; 3],
texcoords: &[Vector2; 3],
colors: &[ARGB; 3],
colors: &[RGBA; 3],
bitmap: &Self,
blend: BlendFunction,
) {
@ -276,7 +276,7 @@ impl RgbaBitmap {
let color = ((w0 * color1 + w1 * color2 + w2 * color3) / area).cast::<u8>();
let texcoord = (w0 * texcoord1 + w1 * texcoord2 + w2 * texcoord3) / area;
let texel = bitmap.sample_at(texcoord[0], texcoord[1]);
let src = texel * ARGB(color);
let src = texel * RGBA(color);
*dest_pixels = blend.blend(src, *dest_pixels)
},
)
@ -287,7 +287,7 @@ impl RgbaBitmap {
positions: &[Vector2; 3],
texcoords: &[Vector2; 3],
bitmap: &Self,
tint: ARGB,
tint: RGBA,
) {
let area = simd::f32x2::splat(edge_function(positions[0], positions[1], positions[2]));
let texcoord1 = simd::f32x2::from_array([texcoords[0].x, texcoords[0].y]);

View file

@ -7,30 +7,30 @@ use crate::utils::{ReadType, WriteType};
// these colours are taken from the default VGA palette
pub const COLOR_BLACK: ARGB = ARGB::from_rgb([0, 0, 0]);
pub const COLOR_BLUE: ARGB = ARGB::from_rgb([0, 0, 170]);
pub const COLOR_GREEN: ARGB = ARGB::from_rgb([0, 170, 0]);
pub const COLOR_CYAN: ARGB = ARGB::from_rgb([0, 170, 170]);
pub const COLOR_RED: ARGB = ARGB::from_rgb([170, 0, 0]);
pub const COLOR_MAGENTA: ARGB = ARGB::from_rgb([170, 0, 170]);
pub const COLOR_BROWN: ARGB = ARGB::from_rgb([170, 85, 0]);
pub const COLOR_LIGHT_GRAY: ARGB = ARGB::from_rgb([170, 170, 170]);
pub const COLOR_DARK_GRAY: ARGB = ARGB::from_rgb([85, 85, 85]);
pub const COLOR_BRIGHT_BLUE: ARGB = ARGB::from_rgb([85, 85, 255]);
pub const COLOR_BRIGHT_GREEN: ARGB = ARGB::from_rgb([85, 255, 85]);
pub const COLOR_BRIGHT_CYAN: ARGB = ARGB::from_rgb([85, 255, 255]);
pub const COLOR_BRIGHT_RED: ARGB = ARGB::from_rgb([255, 85, 85]);
pub const COLOR_BRIGHT_MAGENTA: ARGB = ARGB::from_rgb([255, 85, 255]);
pub const COLOR_BRIGHT_YELLOW: ARGB = ARGB::from_rgb([255, 255, 85]);
pub const COLOR_BRIGHT_WHITE: ARGB = ARGB::from_rgb([255, 255, 255]);
pub const COLOR_BLACK: RGBA = RGBA::from_rgb([0, 0, 0]);
pub const COLOR_BLUE: RGBA = RGBA::from_rgb([0, 0, 170]);
pub const COLOR_GREEN: RGBA = RGBA::from_rgb([0, 170, 0]);
pub const COLOR_CYAN: RGBA = RGBA::from_rgb([0, 170, 170]);
pub const COLOR_RED: RGBA = RGBA::from_rgb([170, 0, 0]);
pub const COLOR_MAGENTA: RGBA = RGBA::from_rgb([170, 0, 170]);
pub const COLOR_BROWN: RGBA = RGBA::from_rgb([170, 85, 0]);
pub const COLOR_LIGHT_GRAY: RGBA = RGBA::from_rgb([170, 170, 170]);
pub const COLOR_DARK_GRAY: RGBA = RGBA::from_rgb([85, 85, 85]);
pub const COLOR_BRIGHT_BLUE: RGBA = RGBA::from_rgb([85, 85, 255]);
pub const COLOR_BRIGHT_GREEN: RGBA = RGBA::from_rgb([85, 255, 85]);
pub const COLOR_BRIGHT_CYAN: RGBA = RGBA::from_rgb([85, 255, 255]);
pub const COLOR_BRIGHT_RED: RGBA = RGBA::from_rgb([255, 85, 85]);
pub const COLOR_BRIGHT_MAGENTA: RGBA = RGBA::from_rgb([255, 85, 255]);
pub const COLOR_BRIGHT_YELLOW: RGBA = RGBA::from_rgb([255, 255, 85]);
pub const COLOR_BRIGHT_WHITE: RGBA = RGBA::from_rgb([255, 255, 255]);
// TODO: probably should name these better, after i do much more reading on the subject :-)
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum BlendFunction {
Blend,
BlendSourceWithAlpha(u8),
TintedBlend(ARGB),
MultipliedBlend(ARGB),
TintedBlend(RGBA),
MultipliedBlend(RGBA),
}
impl BlendFunction {
@ -44,7 +44,7 @@ impl BlendFunction {
/// * `dest`: the destination color to blend the source color over
///
/// returns: the blended color
pub fn blend(&self, src: ARGB, dest: ARGB) -> ARGB {
pub fn blend(&self, src: RGBA, dest: RGBA) -> RGBA {
use BlendFunction::*;
match self {
Blend => src.blend(dest),
@ -86,24 +86,24 @@ pub trait ColorsAsBytes {
}
/// Unpacked 32-bit color represented as individual 8-bit color components where the components are in the
/// order alpha, red, green, blue.
/// order red, green, blue, alpha.
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Default)]
#[repr(transparent)]
pub struct ARGB(pub simd::u8x4);
pub struct RGBA(pub simd::u8x4);
impl ARGB {
impl RGBA {
pub const SIZE: usize = std::mem::size_of::<Self>();
/// Returns a color value composed of the provided ARGB color components.
/// Returns a color value composed of the provided RGBA color components.
///
/// # Arguments
///
/// * `argb`: the 4 color components (0-255) in the order: alpha, red, green, blue
/// * `rgba`: the 4 color components (0-255) in the order: red, green, blue, alpha
///
/// returns: the composed color value
#[inline]
pub const fn from_argb(argb: [u8; 4]) -> Self {
ARGB(simd::u8x4::from_array(argb))
pub const fn from_rgba(rgba: [u8; 4]) -> Self {
RGBA(simd::u8x4::from_array(rgba))
}
/// Returns a color value composed of the provided RGB color components. Substitutes a value of 255 for the
@ -116,41 +116,31 @@ impl ARGB {
/// returns: the composed color value
#[inline]
pub const fn from_rgb(rgb: [u8; 3]) -> Self {
ARGB(simd::u8x4::from_array([255, rgb[0], rgb[1], rgb[2]]))
}
/// Returns the current alpha component value (0-255) of this color.
#[inline]
pub const fn a(&self) -> u8 {
self.0.to_array()[0]
RGBA(simd::u8x4::from_array([rgb[0], rgb[1], rgb[2], 255]))
}
/// Returns the current red component value (0-255) of this color.
#[inline]
pub const fn r(&self) -> u8 {
self.0.to_array()[1]
self.0.to_array()[0]
}
/// Returns the current green component value (0-255) of this color.
#[inline]
pub const fn g(&self) -> u8 {
self.0.to_array()[2]
self.0.to_array()[1]
}
/// Returns the current blue component value (0-255) of this color.
#[inline]
pub const fn b(&self) -> u8 {
self.0.to_array()[3]
self.0.to_array()[2]
}
/// Sets the alpha component value of this color leaving the other components in the color unchanged.
///
/// # Arguments
///
/// * `value`: the new alpha component value to be set (0-255)
/// Returns the current alpha component value (0-255) of this color.
#[inline]
pub fn set_a(&mut self, value: u8) {
self.0[0] = value
pub const fn a(&self) -> u8 {
self.0.to_array()[3]
}
/// Sets the red component value of this color leaving the other components in the color unchanged.
@ -160,7 +150,7 @@ impl ARGB {
/// * `value`: the new red component value to be set (0-255)
#[inline]
pub fn set_r(&mut self, value: u8) {
self.0[1] = value
self.0[0] = value
}
/// Sets the green component value of this color leaving the other components in the color unchanged.
@ -170,7 +160,7 @@ impl ARGB {
/// * `value`: the new green component value to be set (0-255)
#[inline]
pub fn set_g(&mut self, value: u8) {
self.0[2] = value
self.0[1] = value
}
/// Sets the blue component value of this color leaving the other components in the color unchanged.
@ -180,10 +170,20 @@ impl ARGB {
/// * `value`: the new blue component value to be set (0-255)
#[inline]
pub fn set_b(&mut self, value: u8) {
self.0[2] = value
}
/// Sets the alpha component value of this color leaving the other components in the color unchanged.
///
/// # Arguments
///
/// * `value`: the new alpha component value to be set (0-255)
#[inline]
pub fn set_a(&mut self, value: u8) {
self.0[3] = value
}
/// Returns an array with all of this color's ARGB components, in the order: alpha, red, green, blue.
/// Returns an array with all of this color's RGBA components, in the order: red, green, blue, alpha.
#[inline]
pub const fn to_array(&self) -> [u8; 4] {
self.0.to_array()
@ -193,7 +193,7 @@ impl ARGB {
fn blend_components(strength: u8, src: Self, dest: Self) -> Self {
let strength = simd::u16x4::splat(strength as u16);
let max = simd::u16x4::splat(255);
ARGB((((src.0.cast() * strength) + (dest.0.cast() * (max - strength))) / max).cast())
RGBA((((src.0.cast() * strength) + (dest.0.cast() * (max - strength))) / max).cast())
}
/// Alpha blends two colors together, using this color as the source color and the other provided color as the
@ -206,12 +206,12 @@ impl ARGB {
/// returns: the blended color result
#[inline]
pub fn blend(&self, dest: Self) -> Self {
ARGB::blend_components(self.a(), *self, dest)
RGBA::blend_components(self.a(), *self, dest)
}
/// Alpha blends two colors together, where the alpha value used to blend the colors is derived from the given
/// alpha value multiplied with the source color's alpha component. This allows for more flexibility versus the
/// [`ARGB::blend`] method allowing direct control over how transparent the source color is when blended over
/// [`RGBA::blend`] method allowing direct control over how transparent the source color is when blended over
/// top of the destination. The blend is performed using this color as the source color and the other provided
/// color as the destination color.
///
@ -227,7 +227,7 @@ impl ARGB {
#[inline]
pub fn blend_with_alpha(&self, dest: Self, alpha: u8) -> Self {
let alpha = ((alpha as u16 * self.a() as u16) / 255) as u8;
let mut blended = ARGB::blend_components(alpha, *self, dest);
let mut blended = RGBA::blend_components(alpha, *self, dest);
blended.set_a(alpha);
blended
}
@ -245,7 +245,7 @@ impl ARGB {
pub fn tint(&self, mut tint: Self) -> Self {
let strength = tint.a();
tint.set_a(self.a());
ARGB::blend_components(strength, tint, *self)
RGBA::blend_components(strength, tint, *self)
}
/// Linearly interpolates between this color and another color.
@ -258,7 +258,7 @@ impl ARGB {
/// returns: the interpolated color result
#[inline]
pub fn lerp(&self, other: Self, t: f32) -> Self {
ARGB((self.0.cast() + (other.0 - self.0).cast() * simd::f32x4::splat(t)).cast())
RGBA((self.0.cast() + (other.0 - self.0).cast() * simd::f32x4::splat(t)).cast())
}
/// Calculates this color's luminance, returned as a value between 0.0 and 1.0.
@ -277,18 +277,18 @@ impl ARGB {
}
}
impl Mul for ARGB {
type Output = ARGB;
impl Mul for RGBA {
type Output = RGBA;
/// Multiplies two colors together, returning the result. The multiplication is performed by individually
/// multiplying each color component using the formula `(component * component) / 255`.
#[inline]
fn mul(self, rhs: Self) -> Self::Output {
ARGB(((self.0.cast::<u32>() * rhs.0.cast::<u32>()) / simd::u32x4::splat(255)).cast())
RGBA(((self.0.cast::<u32>() * rhs.0.cast::<u32>()) / simd::u32x4::splat(255)).cast())
}
}
impl MulAssign for ARGB {
impl MulAssign for RGBA {
/// Multiplies two colors together, assigning the result of the multiplication to this color. The multiplication is
/// performed by individually multiplying each color component using the formula `(component * component) / 255`.
#[inline]
@ -297,64 +297,64 @@ impl MulAssign for ARGB {
}
}
impl From<u32> for ARGB {
/// Returns a color value constructed by unpacking ARGB color components from the given u32 value. The u32 value
/// provided is parsed assuming the following locations of each color component: 0xAARRGGBB.
impl From<u32> for RGBA {
/// Returns a color value constructed by unpacking RGBA color components from the given u32 value. The u32 value
/// provided is parsed assuming the following locations of each color component: 0xRRGGBBAA.
#[inline]
fn from(value: u32) -> Self {
ARGB::from_argb([
((value & 0xff000000) >> 24) as u8, // a
((value & 0x00ff0000) >> 16) as u8, // r
((value & 0x0000ff00) >> 8) as u8, // g
(value & 0x000000ff) as u8, // b
RGBA::from_rgba([
((value & 0xff000000) >> 24) as u8, // r
((value & 0x00ff0000) >> 16) as u8, // g
((value & 0x0000ff00) >> 8) as u8, // b
(value & 0x000000ff) as u8, // a
])
}
}
impl From<ARGB> for u32 {
/// Returns a u32 containing packed ARGB color components from this color. The returned u32 value contains the
/// color components packed in format 0xAARRGGBB.
impl From<RGBA> for u32 {
/// Returns a u32 containing packed RGBA color components from this color. The returned u32 value contains the
/// color components packed in format 0xRRGGBBAA.
#[inline]
fn from(value: ARGB) -> Self {
(value.b() as u32) // b
+ ((value.g() as u32) << 8) // g
+ ((value.r() as u32) << 16) // r
+ ((value.a() as u32) << 24) // a
fn from(value: RGBA) -> Self {
(value.a() as u32) // a
+ ((value.b() as u32) << 8) // b
+ ((value.g() as u32) << 16) // g
+ ((value.r() as u32) << 24) // r
}
}
impl From<ARGBf> for ARGB {
/// Converts a [`ARGBf`] color to an equivalent [`ARGB`] color value.
impl From<RGBAf> for RGBA {
/// Converts a [`RGBAf`] color to an equivalent [`RGBA`] color value.
#[inline]
fn from(value: ARGBf) -> Self {
ARGB::from_argb([
(value.a() * 255.0) as u8,
fn from(value: RGBAf) -> Self {
RGBA::from_rgba([
(value.r() * 255.0) as u8,
(value.g() * 255.0) as u8,
(value.b() * 255.0) as u8,
(value.a() * 255.0) as u8,
])
}
}
impl BytesAsColors<ARGB> for [u8] {
impl BytesAsColors<RGBA> for [u8] {
#[inline]
unsafe fn as_colors(&self) -> &[ARGB] {
unsafe fn as_colors(&self) -> &[RGBA] {
std::slice::from_raw_parts(
self.as_ptr() as *const ARGB, //
self.len() / std::mem::size_of::<ARGB>(),
self.as_ptr() as *const RGBA, //
self.len() / std::mem::size_of::<RGBA>(),
)
}
#[inline]
unsafe fn as_colors_mut(&mut self) -> &mut [ARGB] {
unsafe fn as_colors_mut(&mut self) -> &mut [RGBA] {
std::slice::from_raw_parts_mut(
self.as_mut_ptr() as *mut ARGB, //
self.len() / std::mem::size_of::<ARGB>(),
self.as_mut_ptr() as *mut RGBA, //
self.len() / std::mem::size_of::<RGBA>(),
)
}
}
impl ColorsAsBytes for [ARGB] {
impl ColorsAsBytes for [RGBA] {
#[inline]
fn as_bytes(&self) -> &[u8] {
unsafe {
@ -376,19 +376,19 @@ impl ColorsAsBytes for [ARGB] {
}
}
impl std::fmt::Debug for ARGB {
impl std::fmt::Debug for RGBA {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "0x{:02x}{:02x}{:02x}{:02x}", self.a(), self.r(), self.g(), self.b())
write!(f, "0x{:02x}{:02x}{:02x}{:02x}", self.r(), self.g(), self.b(), self.a())
}
}
impl std::fmt::Display for ARGB {
impl std::fmt::Display for RGBA {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "0x{:02x}{:02x}{:02x}{:02x}", self.a(), self.r(), self.g(), self.b())
write!(f, "0x{:02x}{:02x}{:02x}{:02x}", self.r(), self.g(), self.b(), self.a())
}
}
impl WriteType for ARGB {
impl WriteType for RGBA {
type ErrorType = std::io::Error;
#[inline]
@ -398,33 +398,33 @@ impl WriteType for ARGB {
}
}
impl ReadType for ARGB {
impl ReadType for RGBA {
type OutputType = Self;
type ErrorType = std::io::Error;
#[inline]
fn read<T: ReadBytesExt>(reader: &mut T) -> Result<Self::OutputType, Self::ErrorType> {
Ok(ARGB::from_argb([reader.read_u8()?, reader.read_u8()?, reader.read_u8()?, reader.read_u8()?]))
Ok(RGBA::from_rgba([reader.read_u8()?, reader.read_u8()?, reader.read_u8()?, reader.read_u8()?]))
}
}
/// Unpacked 32-bit color represented as individual normalized f32 color components (0.0 to 1.0) where the
/// components are in the order alpha, red, green, blue.
/// components are in the order red, green, blue, alpha.
#[derive(Copy, Clone, PartialEq, PartialOrd, Default)]
#[repr(transparent)]
pub struct ARGBf(pub simd::f32x4);
pub struct RGBAf(pub simd::f32x4);
impl ARGBf {
/// Returns a color value composed of the provided ARGB color components.
impl RGBAf {
/// Returns a color value composed of the provided RGBA color components.
///
/// # Arguments
///
/// * `argb`: the 4 color components (0.0 to 1.0) in the order: alpha, red, green, blue
/// * `rgba`: the 4 color components (0.0 to 1.0) in the order: red, green, blue, alpha
///
/// returns: the composed color value
#[inline]
pub const fn from_argb(argb: [f32; 4]) -> Self {
ARGBf(simd::f32x4::from_array(argb))
pub const fn from_rgba(rgba: [f32; 4]) -> Self {
RGBAf(simd::f32x4::from_array(rgba))
}
/// Returns a color value composed of the provided RGB color components. Substitutes a value of 1.0 for the
@ -437,41 +437,31 @@ impl ARGBf {
/// returns: the composed color value
#[inline]
pub const fn from_rgb(rgb: [f32; 3]) -> Self {
ARGBf(simd::f32x4::from_array([1.0, rgb[0], rgb[1], rgb[2]]))
}
/// Returns the current alpha component value (0.0 to 1.0) of this color.
#[inline]
pub const fn a(&self) -> f32 {
self.0.to_array()[0]
RGBAf(simd::f32x4::from_array([rgb[0], rgb[1], rgb[2], 1.0]))
}
/// Returns the current red component value (0.0 to 1.0) of this color.
#[inline]
pub const fn r(&self) -> f32 {
self.0.to_array()[1]
self.0.to_array()[0]
}
/// Returns the current green component value (0.0 to 1.0) of this color.
#[inline]
pub const fn g(&self) -> f32 {
self.0.to_array()[2]
self.0.to_array()[1]
}
/// Returns the current blue component value (0.0 to 1.0) of this color.
#[inline]
pub const fn b(&self) -> f32 {
self.0.to_array()[3]
self.0.to_array()[2]
}
/// Sets the alpha component value of this color leaving the other components in the color unchanged.
///
/// # Arguments
///
/// * `value`: the new alpha component value to be set (0.0 to 1.0)
/// Returns the current alpha component value (0.0 to 1.0) of this color.
#[inline]
pub fn set_a(&mut self, value: f32) {
self.0[0] = value
pub const fn a(&self) -> f32 {
self.0.to_array()[3]
}
/// Sets the red component value of this color leaving the other components in the color unchanged.
@ -481,7 +471,7 @@ impl ARGBf {
/// * `value`: the new red component value to be set (0.0 to 1.0)
#[inline]
pub fn set_r(&mut self, value: f32) {
self.0[1] = value
self.0[0] = value
}
/// Sets the green component value of this color leaving the other components in the color unchanged.
@ -491,7 +481,7 @@ impl ARGBf {
/// * `value`: the new green component value to be set (0.0 to 1.0)
#[inline]
pub fn set_g(&mut self, value: f32) {
self.0[2] = value
self.0[1] = value
}
/// Sets the blue component value of this color leaving the other components in the color unchanged.
@ -501,52 +491,62 @@ impl ARGBf {
/// * `value`: the new blue component value to be set (0.0 to 1.0)
#[inline]
pub fn set_b(&mut self, value: f32) {
self.0[2] = value
}
/// Sets the alpha component value of this color leaving the other components in the color unchanged.
///
/// # Arguments
///
/// * `value`: the new alpha component value to be set (0.0 to 1.0)
#[inline]
pub fn set_a(&mut self, value: f32) {
self.0[3] = value
}
/// Returns an array with all of this color's ARGB components, in the order: alpha, red, green, blue.
/// Returns an array with all of this color's RGBA components, in the order: red, green, blue, alpha.
#[inline]
pub const fn to_array(&self) -> [f32; 4] {
self.0.to_array()
}
}
impl From<u32> for ARGBf {
/// Returns a color value constructed by unpacking ARGB color components from the given u32 value. The u32 value
/// provided is parsed assuming the following locations of each color component: 0xAARRGGBB.
impl From<u32> for RGBAf {
/// Returns a color value constructed by unpacking RGBA color components from the given u32 value. The u32 value
/// provided is parsed assuming the following locations of each color component: 0xRRGGBBAA.
#[inline]
fn from(value: u32) -> Self {
ARGBf::from_argb([
((value & 0xff000000) >> 24) as f32 / 255.0, // a
((value & 0x00ff0000) >> 16) as f32 / 255.0, // r
((value & 0x0000ff00) >> 8) as f32 / 255.0, // g
(value & 0x000000ff) as f32 / 255.0, // b
RGBAf::from_rgba([
((value & 0xff000000) >> 24) as f32 / 255.0, // r
((value & 0x00ff0000) >> 16) as f32 / 255.0, // g
((value & 0x0000ff00) >> 8) as f32 / 255.0, // b
(value & 0x000000ff) as f32 / 255.0, // a
])
}
}
impl From<ARGB> for ARGBf {
/// Converts a [`ARGBf`] color to an equivalent [`ARGB`] color value.
impl From<RGBA> for RGBAf {
/// Converts a [`RGBAf`] color to an equivalent [`RGBA`] color value.
#[inline]
fn from(value: ARGB) -> Self {
ARGBf::from_argb([
value.a() as f32 / 255.0,
fn from(value: RGBA) -> Self {
RGBAf::from_rgba([
value.r() as f32 / 255.0,
value.g() as f32 / 255.0,
value.b() as f32 / 255.0,
value.a() as f32 / 255.0,
])
}
}
impl std::fmt::Debug for ARGBf {
impl std::fmt::Debug for RGBAf {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "ARGBf32x4({}, {}, {}, {})", self.a(), self.r(), self.g(), self.b())
write!(f, "RGBAf({}, {}, {}, {})", self.r(), self.g(), self.b(), self.a())
}
}
impl std::fmt::Display for ARGBf {
impl std::fmt::Display for RGBAf {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{{A={}, R={}, G={}, B={}}}", self.a(), self.r(), self.g(), self.b())
write!(f, "{{R={}, G={}, B={}, A={}}}", self.r(), self.g(), self.b(), self.a())
}
}
@ -593,122 +593,122 @@ mod tests {
use crate::math::NearlyEqual;
#[test]
fn argb() {
let mut color = ARGB(simd::u8x4::from_array([0x11, 0x22, 0x33, 0x44]));
assert_eq!(color.a(), 0x11);
assert_eq!(color.r(), 0x22);
assert_eq!(color.g(), 0x33);
assert_eq!(color.b(), 0x44);
fn rgba() {
let mut color = RGBA(simd::u8x4::from_array([0x11, 0x22, 0x33, 0x44]));
assert_eq!(color.r(), 0x11);
assert_eq!(color.g(), 0x22);
assert_eq!(color.b(), 0x33);
assert_eq!(color.a(), 0x44);
assert_eq!(color.to_array(), [0x11, 0x22, 0x33, 0x44]);
color.set_a(0x55);
assert_eq!(color.to_array(), [0x55, 0x22, 0x33, 0x44]);
assert_eq!(color.to_array(), [0x11, 0x22, 0x33, 0x55]);
color.set_r(0x66);
assert_eq!(color.to_array(), [0x55, 0x66, 0x33, 0x44]);
assert_eq!(color.to_array(), [0x66, 0x22, 0x33, 0x55]);
color.set_g(0x77);
assert_eq!(color.to_array(), [0x55, 0x66, 0x77, 0x44]);
assert_eq!(color.to_array(), [0x66, 0x77, 0x33, 0x55]);
color.set_b(0x88);
assert_eq!(color.to_array(), [0x55, 0x66, 0x77, 0x88]);
assert_eq!(color.to_array(), [0x66, 0x77, 0x88, 0x55]);
let color = ARGB::from_argb([0x11, 0x22, 0x33, 0x44]);
let color = RGBA::from_rgba([0x11, 0x22, 0x33, 0x44]);
assert_eq!(color.to_array(), [0x11, 0x22, 0x33, 0x44]);
let color = ARGB::from_rgb([0x11, 0x22, 0x33]);
assert_eq!(color.to_array(), [0xff, 0x11, 0x22, 0x33]);
let color = RGBA::from_rgb([0x11, 0x22, 0x33]);
assert_eq!(color.to_array(), [0x11, 0x22, 0x33, 0xff]);
let color: ARGB = 0x11223344.into();
let color: RGBA = 0x11223344.into();
assert_eq!(color.to_array(), [0x11, 0x22, 0x33, 0x44]);
let other = ARGBf::from_argb([0.5, 0.1, 0.2, 0.3]);
let color: ARGB = other.into();
assert_eq!(color.to_array(), [0x7f, 0x19, 0x33, 0x4c]);
let other = RGBAf::from_rgba([0.1, 0.2, 0.3, 0.5]);
let color: RGBA = other.into();
assert_eq!(color.to_array(), [0x19, 0x33, 0x4c, 0x7f]);
let color = ARGB::from_argb([0x11, 0x22, 0x33, 0x44]);
let color = RGBA::from_rgba([0x11, 0x22, 0x33, 0x44]);
assert_eq!(0x11223344u32, color.into())
}
#[test]
fn argb_multiplication() {
assert_eq!([0xff, 0x11, 0x22, 0x33], (ARGB::from(0xffffffff) * ARGB::from(0xff112233)).to_array());
assert_eq!([0xff, 0x11, 0x22, 0x33], (ARGB::from(0xff112233) * ARGB::from(0xffffffff)).to_array());
assert_eq!([0x7f, 0x03, 0x00, 0x14], (ARGB::from(0x7f330066) * ARGB::from(0xff112233)).to_array());
assert_eq!([0x7f, 0x03, 0x00, 0x14], (ARGB::from(0xff112233) * ARGB::from(0x7f330066)).to_array());
fn rgba_multiplication() {
assert_eq!([0x11, 0x22, 0x33, 0xff], (RGBA::from(0xffffffff) * RGBA::from(0x112233ff)).to_array());
assert_eq!([0x11, 0x22, 0x33, 0xff], (RGBA::from(0x112233ff) * RGBA::from(0xffffffff)).to_array());
assert_eq!([0x03, 0x00, 0x14, 0x7f], (RGBA::from(0x3300667f) * RGBA::from(0x112233ff)).to_array());
assert_eq!([0x03, 0x00, 0x14, 0x7f], (RGBA::from(0x112233ff) * RGBA::from(0x3300667f)).to_array());
let mut color = ARGB::from(0xffffffff);
color *= ARGB::from(0xff112233);
assert_eq!([0xff, 0x11, 0x22, 0x33], color.to_array());
let mut color = ARGB::from(0xff112233);
color *= ARGB::from(0xffffffff);
assert_eq!([0xff, 0x11, 0x22, 0x33], color.to_array());
let mut color = ARGB::from(0x7f330066);
color *= ARGB::from(0xff112233);
assert_eq!([0x7f, 0x03, 0x00, 0x14], color.to_array());
let mut color = ARGB::from(0xff112233);
color *= ARGB::from(0x7f330066);
assert_eq!([0x7f, 0x03, 0x00, 0x14], color.to_array());
let mut color = RGBA::from(0xffffffff);
color *= RGBA::from(0x112233ff);
assert_eq!([0x11, 0x22, 0x33, 0xff], color.to_array());
let mut color = RGBA::from(0x112233ff);
color *= RGBA::from(0xffffffff);
assert_eq!([0x11, 0x22, 0x33, 0xff], color.to_array());
let mut color = RGBA::from(0x3300667f);
color *= RGBA::from(0x112233ff);
assert_eq!([0x03, 0x00, 0x14, 0x7f], color.to_array());
let mut color = RGBA::from(0x112233ff);
color *= RGBA::from(0x3300667f);
assert_eq!([0x03, 0x00, 0x14, 0x7f], color.to_array());
}
#[test]
fn argb_lerping() {
assert_eq!([0x7f, 0x11, 0x22, 0x33], (ARGB::from(0x7f112233).lerp(ARGB::from(0xffaabbcc), 0.0).to_array()));
assert_eq!([0xbf, 0x5d, 0x6e, 0x7f], (ARGB::from(0x7f112233).lerp(ARGB::from(0xffaabbcc), 0.5).to_array()));
assert_eq!([0xff, 0xaa, 0xbb, 0xcc], (ARGB::from(0x7f112233).lerp(ARGB::from(0xffaabbcc), 1.0).to_array()));
fn rgba_lerping() {
assert_eq!([0x11, 0x22, 0x33, 0x7f], (RGBA::from(0x1122337f).lerp(RGBA::from(0xaabbccff), 0.0).to_array()));
assert_eq!([0x5d, 0x6e, 0x7f, 0xbf], (RGBA::from(0x1122337f).lerp(RGBA::from(0xaabbccff), 0.5).to_array()));
assert_eq!([0xaa, 0xbb, 0xcc, 0xff], (RGBA::from(0x1122337f).lerp(RGBA::from(0xaabbccff), 1.0).to_array()));
}
#[test]
#[rustfmt::skip]
fn argb_blending() {
fn rgba_blending() {
// TODO: for .blend(), is this really the behaviour we want? the output value's alpha
// is blended, but the source color's alpha is what is ultimately used to control
// the blend operation. what is best here? the output RGB color looks correct at
// any rate, just not sure what the proper output alpha component *should* be in
// all cases.
assert_eq!([0xff, 0x11, 0x22, 0x33], ARGB::from(0xff112233).blend(ARGB::from(0xff555555)).to_array());
assert_eq!([0xbf, 0x33, 0x3b, 0x44], ARGB::from(0x7f112233).blend(ARGB::from(0xff555555)).to_array());
assert_eq!([0xff, 0x55, 0x55, 0x55], ARGB::from(0x00112233).blend(ARGB::from(0xff555555)).to_array());
assert_eq!([0x11, 0x22, 0x33, 0xff], RGBA::from(0x112233ff).blend(RGBA::from(0x555555ff)).to_array());
assert_eq!([0x33, 0x3b, 0x44, 0xbf], RGBA::from(0x1122337f).blend(RGBA::from(0x555555ff)).to_array());
assert_eq!([0x55, 0x55, 0x55, 0xff], RGBA::from(0x11223300).blend(RGBA::from(0x555555ff)).to_array());
assert_eq!([0xff, 0x11, 0x22, 0x33], ARGB::from(0xff112233).blend(ARGB::from(0x7f555555)).to_array());
assert_eq!([0x7f, 0x33, 0x3b, 0x44], ARGB::from(0x7f112233).blend(ARGB::from(0x7f555555)).to_array());
assert_eq!([0x7f, 0x55, 0x55, 0x55], ARGB::from(0x00112233).blend(ARGB::from(0x7f555555)).to_array());
assert_eq!([0x11, 0x22, 0x33, 0xff], RGBA::from(0x112233ff).blend(RGBA::from(0x5555557f)).to_array());
assert_eq!([0x33, 0x3b, 0x44, 0x7f], RGBA::from(0x1122337f).blend(RGBA::from(0x5555557f)).to_array());
assert_eq!([0x55, 0x55, 0x55, 0x7f], RGBA::from(0x11223300).blend(RGBA::from(0x5555557f)).to_array());
assert_eq!([0xff, 0x11, 0x22, 0x33], ARGB::from(0xff112233).blend_with_alpha(ARGB::from(0xff555555), 255).to_array());
assert_eq!([0x7f, 0x33, 0x3b, 0x44], ARGB::from(0x7f112233).blend_with_alpha(ARGB::from(0xff555555), 255).to_array());
assert_eq!([0x00, 0x55, 0x55, 0x55], ARGB::from(0x00112233).blend_with_alpha(ARGB::from(0xff555555), 255).to_array());
assert_eq!([0x11, 0x22, 0x33, 0xff], RGBA::from(0x112233ff).blend_with_alpha(RGBA::from(0x555555ff), 255).to_array());
assert_eq!([0x33, 0x3b, 0x44, 0x7f], RGBA::from(0x1122337f).blend_with_alpha(RGBA::from(0x555555ff), 255).to_array());
assert_eq!([0x55, 0x55, 0x55, 0x00], RGBA::from(0x11223300).blend_with_alpha(RGBA::from(0x555555ff), 255).to_array());
assert_eq!([0xff, 0x11, 0x22, 0x33], ARGB::from(0xff112233).blend_with_alpha(ARGB::from(0x7f555555), 255).to_array());
assert_eq!([0x7f, 0x33, 0x3b, 0x44], ARGB::from(0x7f112233).blend_with_alpha(ARGB::from(0x7f555555), 255).to_array());
assert_eq!([0x00, 0x55, 0x55, 0x55], ARGB::from(0x00112233).blend_with_alpha(ARGB::from(0x7f555555), 255).to_array());
assert_eq!([0x11, 0x22, 0x33, 0xff], RGBA::from(0x112233ff).blend_with_alpha(RGBA::from(0x5555557f), 255).to_array());
assert_eq!([0x33, 0x3b, 0x44, 0x7f], RGBA::from(0x1122337f).blend_with_alpha(RGBA::from(0x5555557f), 255).to_array());
assert_eq!([0x55, 0x55, 0x55, 0x00], RGBA::from(0x11223300).blend_with_alpha(RGBA::from(0x5555557f), 255).to_array());
assert_eq!([0x80, 0x32, 0x3b, 0x43], ARGB::from(0xff112233).blend_with_alpha(ARGB::from(0xff555555), 128).to_array());
assert_eq!([0x3f, 0x44, 0x48, 0x4c], ARGB::from(0x7f112233).blend_with_alpha(ARGB::from(0xff555555), 128).to_array());
assert_eq!([0x00, 0x55, 0x55, 0x55], ARGB::from(0x00112233).blend_with_alpha(ARGB::from(0xff555555), 128).to_array());
assert_eq!([0x32, 0x3b, 0x43, 0x80], RGBA::from(0x112233ff).blend_with_alpha(RGBA::from(0x555555ff), 128).to_array());
assert_eq!([0x44, 0x48, 0x4c, 0x3f], RGBA::from(0x1122337f).blend_with_alpha(RGBA::from(0x555555ff), 128).to_array());
assert_eq!([0x55, 0x55, 0x55, 0x00], RGBA::from(0x11223300).blend_with_alpha(RGBA::from(0x555555ff), 128).to_array());
assert_eq!([0x00, 0x55, 0x55, 0x55], ARGB::from(0xff112233).blend_with_alpha(ARGB::from(0xff555555), 0).to_array());
assert_eq!([0x00, 0x55, 0x55, 0x55], ARGB::from(0x7f112233).blend_with_alpha(ARGB::from(0xff555555), 0).to_array());
assert_eq!([0x00, 0x55, 0x55, 0x55], ARGB::from(0x00112233).blend_with_alpha(ARGB::from(0xff555555), 0).to_array());
assert_eq!([0x55, 0x55, 0x55, 0x00], RGBA::from(0x112233ff).blend_with_alpha(RGBA::from(0x555555ff), 0).to_array());
assert_eq!([0x55, 0x55, 0x55, 0x00], RGBA::from(0x1122337f).blend_with_alpha(RGBA::from(0x555555ff), 0).to_array());
assert_eq!([0x55, 0x55, 0x55, 0x00], RGBA::from(0x11223300).blend_with_alpha(RGBA::from(0x555555ff), 0).to_array());
}
#[test]
fn argb_tinting() {
assert_eq!([0xff, 0x11, 0x22, 0x33], ARGB::from(0xffffffff).tint(ARGB::from(0xff112233)).to_array());
assert_eq!([0xff, 0x88, 0x90, 0x99], ARGB::from(0xffffffff).tint(ARGB::from(0x7f112233)).to_array());
assert_eq!([0xff, 0xff, 0xff, 0xff], ARGB::from(0xffffffff).tint(ARGB::from(0x00112233)).to_array());
fn rgba_tinting() {
assert_eq!([0x11, 0x22, 0x33, 0xff], RGBA::from(0xffffffff).tint(RGBA::from(0x112233ff)).to_array());
assert_eq!([0x88, 0x90, 0x99, 0xff], RGBA::from(0xffffffff).tint(RGBA::from(0x1122337f)).to_array());
assert_eq!([0xff, 0xff, 0xff, 0xff], RGBA::from(0xffffffff).tint(RGBA::from(0x11223300)).to_array());
}
#[test]
fn argb_bytes_to_colors_casting() {
fn rgba_bytes_to_colors_casting() {
let mut bytes =
[0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff];
[0xff, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff];
let colors = unsafe { bytes.as_colors() };
assert_eq!(
colors,
[
ARGB::from_argb([0xff, 0xff, 0x00, 0x00]),
ARGB::from_argb([0xff, 0x00, 0xff, 0x00]),
ARGB::from_argb([0xff, 0x00, 0x00, 0xff]),
ARGB::from_argb([0xff, 0xff, 0x00, 0xff]),
RGBA::from_rgba([0xff, 0x00, 0x00, 0xff]),
RGBA::from_rgba([0x00, 0xff, 0x00, 0xff]),
RGBA::from_rgba([0x00, 0x00, 0xff, 0xff]),
RGBA::from_rgba([0xff, 0x00, 0xff, 0xff]),
]
);
@ -716,26 +716,26 @@ mod tests {
assert_eq!(
colors,
[
ARGB::from_argb([0xff, 0xff, 0x00, 0x00]),
ARGB::from_argb([0xff, 0x00, 0xff, 0x00]),
ARGB::from_argb([0xff, 0x00, 0x00, 0xff]),
ARGB::from_argb([0xff, 0xff, 0x00, 0xff]),
RGBA::from_rgba([0xff, 0x00, 0x00, 0xff]),
RGBA::from_rgba([0x00, 0xff, 0x00, 0xff]),
RGBA::from_rgba([0x00, 0x00, 0xff, 0xff]),
RGBA::from_rgba([0xff, 0x00, 0xff, 0xff]),
]
);
// bytes slice which is NOT an exact multiple of 4
let mut bytes = [
0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0x7f, 0x7f,
0xff, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7f, 0x7f,
];
let colors = unsafe { bytes.as_colors() };
assert_eq!(
colors,
[
ARGB::from_argb([0xff, 0xff, 0x00, 0x00]),
ARGB::from_argb([0xff, 0x00, 0xff, 0x00]),
ARGB::from_argb([0xff, 0x00, 0x00, 0xff]),
ARGB::from_argb([0xff, 0xff, 0x00, 0xff]),
RGBA::from_rgba([0xff, 0x00, 0x00, 0xff]),
RGBA::from_rgba([0x00, 0xff, 0x00, 0xff]),
RGBA::from_rgba([0x00, 0x00, 0xff, 0xff]),
RGBA::from_rgba([0xff, 0x00, 0xff, 0xff]),
]
);
@ -743,68 +743,68 @@ mod tests {
assert_eq!(
colors,
[
ARGB::from_argb([0xff, 0xff, 0x00, 0x00]),
ARGB::from_argb([0xff, 0x00, 0xff, 0x00]),
ARGB::from_argb([0xff, 0x00, 0x00, 0xff]),
ARGB::from_argb([0xff, 0xff, 0x00, 0xff]),
RGBA::from_rgba([0xff, 0x00, 0x00, 0xff]),
RGBA::from_rgba([0x00, 0xff, 0x00, 0xff]),
RGBA::from_rgba([0x00, 0x00, 0xff, 0xff]),
RGBA::from_rgba([0xff, 0x00, 0xff, 0xff]),
]
);
}
#[test]
fn argb_colors_to_bytes_casting() {
fn rgba_colors_to_bytes_casting() {
let mut colors = [
ARGB::from_argb([0xff, 0xff, 0x00, 0x00]),
ARGB::from_argb([0xff, 0x00, 0xff, 0x00]),
ARGB::from_argb([0xff, 0x00, 0x00, 0xff]),
ARGB::from_argb([0xff, 0xff, 0x00, 0xff]),
RGBA::from_rgba([0xff, 0x00, 0x00, 0xff]),
RGBA::from_rgba([0x00, 0xff, 0x00, 0xff]),
RGBA::from_rgba([0x00, 0x00, 0xff, 0xff]),
RGBA::from_rgba([0xff, 0x00, 0xff, 0xff]),
];
let bytes = colors.as_bytes();
assert_eq!(
bytes,
[0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff]
[0xff, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff]
);
let bytes = colors.as_bytes_mut();
assert_eq!(
bytes,
[0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff]
[0xff, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff]
);
}
#[test]
fn argbf() {
let mut color = ARGBf(simd::f32x4::from_array([0.5, 0.1, 0.2, 0.3]));
assert_eq!(color.a(), 0.5);
fn rgbaf() {
let mut color = RGBAf(simd::f32x4::from_array([0.1, 0.2, 0.3, 0.5]));
assert_eq!(color.r(), 0.1);
assert_eq!(color.g(), 0.2);
assert_eq!(color.b(), 0.3);
assert_eq!(color.to_array(), [0.5, 0.1, 0.2, 0.3]);
assert_eq!(color.a(), 0.5);
assert_eq!(color.to_array(), [0.1, 0.2, 0.3, 0.5]);
color.set_a(1.0);
assert_eq!(color.to_array(), [1.0, 0.1, 0.2, 0.3]);
assert_eq!(color.to_array(), [0.1, 0.2, 0.3, 1.0]);
color.set_r(0.4);
assert_eq!(color.to_array(), [1.0, 0.4, 0.2, 0.3]);
assert_eq!(color.to_array(), [0.4, 0.2, 0.3, 1.0]);
color.set_g(0.5);
assert_eq!(color.to_array(), [1.0, 0.4, 0.5, 0.3]);
assert_eq!(color.to_array(), [0.4, 0.5, 0.3, 1.0]);
color.set_b(0.6);
assert_eq!(color.to_array(), [1.0, 0.4, 0.5, 0.6]);
assert_eq!(color.to_array(), [0.4, 0.5, 0.6, 1.0]);
let color = ARGBf::from_argb([0.5, 0.1, 0.2, 0.3]);
assert_eq!(color.to_array(), [0.5, 0.1, 0.2, 0.3]);
let color = RGBAf::from_rgba([0.1, 0.2, 0.3, 0.5]);
assert_eq!(color.to_array(), [0.1, 0.2, 0.3, 0.5]);
let color = ARGBf::from_rgb([0.1, 0.2, 0.3]);
assert_eq!(color.to_array(), [1.0, 0.1, 0.2, 0.3]);
let color = RGBAf::from_rgb([0.1, 0.2, 0.3]);
assert_eq!(color.to_array(), [0.1, 0.2, 0.3, 1.0]);
let color: ARGBf = 0x7f19334c.into();
let color: RGBAf = 0x19334c7f.into();
assert!(color.a().nearly_equal(0.5, 0.01));
assert!(color.r().nearly_equal(0.1, 0.01));
assert!(color.g().nearly_equal(0.2, 0.01));
assert!(color.b().nearly_equal(0.3, 0.01));
let other = ARGB::from_argb([0x7f, 0x19, 0x33, 0x4c]);
let color: ARGBf = other.into();
let other = RGBA::from_rgba([0x19, 0x33, 0x4c, 0x7f]);
let color: RGBAf = other.into();
assert!(color.a().nearly_equal(0.5, 0.01));
assert!(color.r().nearly_equal(0.1, 0.01));
assert!(color.g().nearly_equal(0.2, 0.01));

View file

@ -7,7 +7,7 @@ use std::path::Path;
use byteorder::{ReadBytesExt, WriteBytesExt};
use thiserror::Error;
use crate::graphics::{IndexedBitmap, ARGB};
use crate::graphics::{IndexedBitmap, RGBA};
use crate::utils::abs_diff;
const NUM_COLORS: usize = 256;
@ -29,16 +29,16 @@ fn to_6bit(value: u8) -> u8 {
}
// vga bios (0-63) format
fn read_palette_6bit<T: ReadBytesExt>(reader: &mut T, num_colors: usize) -> Result<[ARGB; NUM_COLORS], PaletteError> {
fn read_palette_6bit<T: ReadBytesExt>(reader: &mut T, num_colors: usize) -> Result<[RGBA; NUM_COLORS], PaletteError> {
if num_colors > NUM_COLORS {
return Err(PaletteError::OutOfRange(num_colors));
}
let mut colors = [ARGB::from_argb([255, 0, 0, 0]); NUM_COLORS];
let mut colors = [RGBA::from_rgba([0, 0, 0, 255]); NUM_COLORS];
for i in 0..num_colors {
let r = reader.read_u8()?;
let g = reader.read_u8()?;
let b = reader.read_u8()?;
let color = ARGB::from_rgb([from_6bit(r), from_6bit(g), from_6bit(b)]);
let color = RGBA::from_rgb([from_6bit(r), from_6bit(g), from_6bit(b)]);
colors[i] = color;
}
Ok(colors)
@ -46,7 +46,7 @@ fn read_palette_6bit<T: ReadBytesExt>(reader: &mut T, num_colors: usize) -> Resu
fn write_palette_6bit<T: WriteBytesExt>(
writer: &mut T,
colors: &[ARGB; NUM_COLORS],
colors: &[RGBA; NUM_COLORS],
num_colors: usize,
) -> Result<(), PaletteError> {
if num_colors > NUM_COLORS {
@ -61,16 +61,16 @@ fn write_palette_6bit<T: WriteBytesExt>(
}
// normal (0-255) format
fn read_palette_8bit<T: ReadBytesExt>(reader: &mut T, num_colors: usize) -> Result<[ARGB; NUM_COLORS], PaletteError> {
fn read_palette_8bit<T: ReadBytesExt>(reader: &mut T, num_colors: usize) -> Result<[RGBA; NUM_COLORS], PaletteError> {
if num_colors > NUM_COLORS {
return Err(PaletteError::OutOfRange(num_colors));
}
let mut colors = [ARGB::from_argb([255, 0, 0, 0]); NUM_COLORS];
let mut colors = [RGBA::from_rgba([0, 0, 0, 255]); NUM_COLORS];
for i in 0..num_colors {
let r = reader.read_u8()?;
let g = reader.read_u8()?;
let b = reader.read_u8()?;
let color = ARGB::from_rgb([r, g, b]);
let color = RGBA::from_rgb([r, g, b]);
colors[i] = color;
}
Ok(colors)
@ -78,7 +78,7 @@ fn read_palette_8bit<T: ReadBytesExt>(reader: &mut T, num_colors: usize) -> Resu
fn write_palette_8bit<T: WriteBytesExt>(
writer: &mut T,
colors: &[ARGB; NUM_COLORS],
colors: &[RGBA; NUM_COLORS],
num_colors: usize,
) -> Result<(), PaletteError> {
if num_colors > NUM_COLORS {
@ -112,18 +112,18 @@ pub enum PaletteFormat {
/// colors are all stored individually as 32-bit packed values in the format 0xAARRGGBB.
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Palette {
colors: [ARGB; NUM_COLORS],
colors: [RGBA; NUM_COLORS],
}
impl Palette {
/// Creates a new Palette with all black colors.
pub fn new() -> Palette {
Palette { colors: [ARGB::from_rgb([0, 0, 0]); NUM_COLORS] }
Palette { colors: [RGBA::from_rgb([0, 0, 0]); NUM_COLORS] }
}
/// Creates a new Palette with all initial colors having the RGB values specified.
pub fn new_with_default(r: u8, g: u8, b: u8) -> Palette {
Palette { colors: [ARGB::from_rgb([r, g, b]); NUM_COLORS] }
Palette { colors: [RGBA::from_rgb([r, g, b]); NUM_COLORS] }
}
/// Creates a new Palette, pre-loaded with the default VGA BIOS colors.
@ -327,7 +327,7 @@ impl Palette {
}
if modified {
self.colors[color as usize] = ARGB::from_rgb([r, g, b]);
self.colors[color as usize] = RGBA::from_rgb([r, g, b]);
}
(target_r == r) && (target_g == g) && (target_b == b)
@ -472,7 +472,7 @@ impl Palette {
}
impl Index<u8> for Palette {
type Output = ARGB;
type Output = RGBA;
#[inline]
fn index(&self, index: u8) -> &Self::Output {
@ -506,11 +506,11 @@ mod tests {
#[test]
fn get_and_set_colors() {
let mut palette = Palette::new();
assert_eq!(ARGB::from_rgb([0, 0, 0]), palette[0]);
assert_eq!(ARGB::from_rgb([0, 0, 0]), palette[1]);
assert_eq!(RGBA::from_rgb([0, 0, 0]), palette[0]);
assert_eq!(RGBA::from_rgb([0, 0, 0]), palette[1]);
palette[0] = 0x11223344.into();
assert_eq!(ARGB::from(0x11223344), palette[0]);
assert_eq!(ARGB::from_rgb([0, 0, 0]), palette[1]);
assert_eq!(RGBA::from(0x11223344), palette[0]);
assert_eq!(RGBA::from_rgb([0, 0, 0]), palette[1]);
}
fn assert_ega_colors(palette: &Palette) {

View file

@ -21,7 +21,7 @@ mod tests {
use std::io::{BufReader, Read};
use std::path::{Path, PathBuf};
use crate::graphics::ARGB;
use crate::graphics::RGBA;
use crate::utils::ReadType;
#[allow(dead_code)]
@ -46,12 +46,12 @@ mod tests {
Ok(buffer.into_boxed_slice())
}
pub fn load_raw_argb(bin_file: &Path) -> Result<Box<[ARGB]>, io::Error> {
pub fn load_raw_rgba(bin_file: &Path) -> Result<Box<[RGBA]>, io::Error> {
let f = File::open(bin_file)?;
let mut reader = BufReader::new(f);
let mut buffer = Vec::new();
loop {
buffer.push(match ARGB::read(&mut reader) {
buffer.push(match RGBA::read(&mut reader) {
Ok(value) => value,
Err(err) if err.kind() == io::ErrorKind::UnexpectedEof => break,
Err(err) => return Err(err),

View file

@ -1,6 +1,6 @@
use thiserror::Error;
use crate::graphics::{ColorsAsBytes, IndexedBitmap, Palette, RgbaBitmap, ARGB};
use crate::graphics::{ColorsAsBytes, IndexedBitmap, Palette, RgbaBitmap, RGBA};
pub fn calculate_logical_screen_size(window_width: u32, window_height: u32, scale_factor: u32) -> (u32, u32) {
let logical_width = (window_width as f32 / scale_factor as f32).ceil() as u32;
@ -23,7 +23,7 @@ pub enum SdlFramebufferError {
pub struct SdlFramebuffer {
sdl_texture: sdl2::render::Texture,
sdl_texture_pitch: usize,
intermediate_texture: Option<Box<[ARGB]>>,
intermediate_texture: Option<Box<[RGBA]>>,
}
// TODO: i'm not totally happy with this implementation. i don't like the two display methods and how the caller
@ -45,7 +45,7 @@ impl SdlFramebuffer {
return Err(SdlFramebufferError::SDLError(error.to_string()));
}
let format = sdl2::pixels::PixelFormatEnum::BGRA8888;
let format = sdl2::pixels::PixelFormatEnum::ABGR8888;
let sdl_texture =
match canvas.create_texture_streaming(Some(format), logical_screen_width, logical_screen_height) {
@ -60,7 +60,7 @@ impl SdlFramebuffer {
// bitmaps, not 32-bit RGBA pixels, so this temporary buffer is where we convert the final
// application framebuffer to 32-bit RGBA pixels before it is uploaded to the SDL texture
let texture_pixels_size = (logical_screen_width * logical_screen_height) as usize;
Some(vec![ARGB::default(); texture_pixels_size].into_boxed_slice())
Some(vec![RGBA::default(); texture_pixels_size].into_boxed_slice())
} else {
None
};
@ -78,7 +78,7 @@ impl SdlFramebuffer {
"Calls to display_indexed_bitmap should only occur on SdlFramebuffers with an intermediate_texture",
);
src.copy_as_argb_to(intermediate_texture, palette);
src.copy_as_rgba_to(intermediate_texture, palette);
let texture_pixels = intermediate_texture.as_bytes();
if let Err(error) = self.sdl_texture.update(None, texture_pixels, self.sdl_texture_pitch) {

View file

@ -1,4 +1,4 @@
use crate::graphics::{ColorsAsBytes, GeneralBitmap, GeneralBlitMethod, IndexedBitmap, RgbaBitmap, ARGB};
use crate::graphics::{ColorsAsBytes, GeneralBitmap, GeneralBlitMethod, IndexedBitmap, RgbaBitmap, RGBA};
use crate::math::Rect;
use crate::system::Mouse;
@ -241,22 +241,22 @@ impl DefaultMouseCursorBitmaps<RgbaBitmap> for CustomMouseCursor<RgbaBitmap> {
fn get_default() -> MouseCursorBitmap<RgbaBitmap> {
#[rustfmt::skip]
const CURSOR_PIXELS: [u8; DEFAULT_MOUSE_CURSOR_WIDTH * DEFAULT_MOUSE_CURSOR_HEIGHT * 4] = [
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff,
0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff,
0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff,
0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff,
0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff,
0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff,
0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff
];
let mut cursor =
@ -267,7 +267,7 @@ impl DefaultMouseCursorBitmaps<RgbaBitmap> for CustomMouseCursor<RgbaBitmap> {
cursor,
hotspot_x: DEFAULT_MOUSE_CURSOR_HOTSPOT_X,
hotspot_y: DEFAULT_MOUSE_CURSOR_HOTSPOT_Y,
transparent_color: ARGB::from(0xffff00ff),
transparent_color: RGBA::from_rgba([255, 0, 255, 255]),
}
}
}

File diff suppressed because one or more lines are too long

Binary file not shown.

Binary file not shown.

View file

@ -5,24 +5,24 @@ use helpers::test_assets_file;
pub mod helpers;
const LIGHTER_BACKGROUND: ARGB = ARGB::from_rgb([0x2c, 0x30, 0x41]);
const LIGHTER_BACKGROUND: RGBA = RGBA::from_rgb([0x2c, 0x30, 0x41]);
pub const COLOR_BLACK_HALF_ALPHA: ARGB = ARGB::from_argb([0x7f, 0x00, 0x00, 0x00]);
pub const COLOR_BLUE_HALF_ALPHA: ARGB = ARGB::from_argb([0x7f, 0x00, 0x00, 0xaa]);
pub const COLOR_GREEN_HALF_ALPHA: ARGB = ARGB::from_argb([0x7f, 0x00, 0xaa, 0x00]);
pub const COLOR_CYAN_HALF_ALPHA: ARGB = ARGB::from_argb([0x7f, 0x00, 0xaa, 0xaa]);
pub const COLOR_RED_HALF_ALPHA: ARGB = ARGB::from_argb([0x7f, 0xaa, 0x00, 0x00]);
pub const COLOR_MAGENTA_HALF_ALPHA: ARGB = ARGB::from_argb([0x7f, 0xaa, 0x00, 0xaa]);
pub const COLOR_BROWN_HALF_ALPHA: ARGB = ARGB::from_argb([0x7f, 0xaa, 0x55, 0x00]);
pub const COLOR_LIGHT_GRAY_HALF_ALPHA: ARGB = ARGB::from_argb([0x7f, 0xaa, 0xaa, 0xaa]);
pub const COLOR_DARK_GRAY_HALF_ALPHA: ARGB = ARGB::from_argb([0x7f, 0x55, 0x55, 0x55]);
pub const COLOR_BRIGHT_BLUE_HALF_ALPHA: ARGB = ARGB::from_argb([0x7f, 0x55, 0x55, 0xff]);
pub const COLOR_BRIGHT_GREEN_HALF_ALPHA: ARGB = ARGB::from_argb([0x7f, 0x55, 0xff, 0x55]);
pub const COLOR_BRIGHT_CYAN_HALF_ALPHA: ARGB = ARGB::from_argb([0x7f, 0x55, 0xff, 0xff]);
pub const COLOR_BRIGHT_RED_HALF_ALPHA: ARGB = ARGB::from_argb([0x7f, 0xff, 0x55, 0x55]);
pub const COLOR_BRIGHT_MAGENTA_HALF_ALPHA: ARGB = ARGB::from_argb([0x7f, 0xff, 0x55, 0xff]);
pub const COLOR_BRIGHT_YELLOW_HALF_ALPHA: ARGB = ARGB::from_argb([0x7f, 0xff, 0xff, 0x55]);
pub const COLOR_BRIGHT_WHITE_HALF_ALPHA: ARGB = ARGB::from_argb([0x7f, 0xff, 0xff, 0xff]);
pub const COLOR_BLACK_HALF_ALPHA: RGBA = RGBA::from_rgba([0x00, 0x00, 0x00, 0x7f]);
pub const COLOR_BLUE_HALF_ALPHA: RGBA = RGBA::from_rgba([0x00, 0x00, 0xaa, 0x7f]);
pub const COLOR_GREEN_HALF_ALPHA: RGBA = RGBA::from_rgba([0x00, 0xaa, 0x00, 0x7f]);
pub const COLOR_CYAN_HALF_ALPHA: RGBA = RGBA::from_rgba([0x00, 0xaa, 0xaa, 0x7f]);
pub const COLOR_RED_HALF_ALPHA: RGBA = RGBA::from_rgba([0xaa, 0x00, 0x00, 0x7f]);
pub const COLOR_MAGENTA_HALF_ALPHA: RGBA = RGBA::from_rgba([0xaa, 0x00, 0xaa, 0x7f]);
pub const COLOR_BROWN_HALF_ALPHA: RGBA = RGBA::from_rgba([0xaa, 0x55, 0x00, 0x7f]);
pub const COLOR_LIGHT_GRAY_HALF_ALPHA: RGBA = RGBA::from_rgba([0xaa, 0xaa, 0xaa, 0x7f]);
pub const COLOR_DARK_GRAY_HALF_ALPHA: RGBA = RGBA::from_rgba([0x55, 0x55, 0x55, 0x7f]);
pub const COLOR_BRIGHT_BLUE_HALF_ALPHA: RGBA = RGBA::from_rgba([0x55, 0x55, 0xff, 0x7f]);
pub const COLOR_BRIGHT_GREEN_HALF_ALPHA: RGBA = RGBA::from_rgba([0x55, 0xff, 0x55, 0x7f]);
pub const COLOR_BRIGHT_CYAN_HALF_ALPHA: RGBA = RGBA::from_rgba([0x55, 0xff, 0xff, 0x7f]);
pub const COLOR_BRIGHT_RED_HALF_ALPHA: RGBA = RGBA::from_rgba([0xff, 0x55, 0x55, 0x7f]);
pub const COLOR_BRIGHT_MAGENTA_HALF_ALPHA: RGBA = RGBA::from_rgba([0xff, 0x55, 0xff, 0x7f]);
pub const COLOR_BRIGHT_YELLOW_HALF_ALPHA: RGBA = RGBA::from_rgba([0xff, 0xff, 0x55, 0x7f]);
pub const COLOR_BRIGHT_WHITE_HALF_ALPHA: RGBA = RGBA::from_rgba([0xff, 0xff, 0xff, 0x7f]);
const SCREEN_WIDTH: u32 = 320;
const SCREEN_HEIGHT: u32 = 240;
@ -83,7 +83,7 @@ fn pixel_addressing() {
let mut i = 0;
for _y in 0..16 {
for _x in 0..16 {
*pixels = ARGB::from_rgb([i, i, i]);
*pixels = RGBA::from_rgb([i, i, i]);
i = i.wrapping_add(1);
pixels = pixels.offset(1);
}
@ -636,10 +636,10 @@ fn generate_bitmap_with_varied_alpha(width: i32, height: i32) -> RgbaBitmap {
let mut bitmap = RgbaBitmap::new(width as u32, height as u32).unwrap();
bitmap.clear(0.into()); // alpha=0
let color1 = ARGB::from_argb([0x33, 0x00, 0x00, 0xaa]);
let color2 = ARGB::from_argb([0x66, 0x00, 0xaa, 0x00]);
let color3 = ARGB::from_argb([0x99, 0x00, 0xaa, 0xaa]);
let color4 = ARGB::from_argb([0xcc, 0xaa, 0x00, 0x00]);
let color1 = RGBA::from_rgba([0x00, 0x00, 0xaa, 0x33]);
let color2 = RGBA::from_rgba([0x00, 0xaa, 0x00, 0x66]);
let color3 = RGBA::from_rgba([0x00, 0xaa, 0xaa, 0x99]);
let color4 = RGBA::from_rgba([0xaa, 0x00, 0x00, 0xcc]);
bitmap.filled_rect(0, 0, x_third, y_third, color1);
bitmap.filled_rect(x_third * 2 + 1, y_third * 2 + 1, width - 1, height - 1, color2);
@ -656,12 +656,12 @@ fn generate_solid_bitmap_with_varied_alpha(width: i32, height: i32) -> RgbaBitma
let y_third = height / 3;
let mut bitmap = RgbaBitmap::new(width as u32, height as u32).unwrap();
bitmap.clear(ARGB::from_argb([255, 0, 0, 0]));
bitmap.clear(RGBA::from_rgba([0, 0, 0, 255]));
let color1 = ARGB::from_argb([0x33, 0x00, 0x00, 0xaa]);
let color2 = ARGB::from_argb([0x66, 0x00, 0xaa, 0x00]);
let color3 = ARGB::from_argb([0x99, 0x00, 0xaa, 0xaa]);
let color4 = ARGB::from_argb([0xcc, 0xaa, 0x00, 0x00]);
let color1 = RGBA::from_rgba([0x00, 0x00, 0xaa, 0x33]);
let color2 = RGBA::from_rgba([0x00, 0xaa, 0x00, 0x66]);
let color3 = RGBA::from_rgba([0x00, 0xaa, 0xaa, 0x99]);
let color4 = RGBA::from_rgba([0xaa, 0x00, 0x00, 0xcc]);
bitmap.filled_rect(0, 0, x_third, y_third, color1);
bitmap.filled_rect(x_third * 2 + 1, y_third * 2 + 1, width - 1, height - 1, color2);
@ -756,7 +756,7 @@ fn solid_tinted_blits() {
let bmp21 = generate_bitmap(21, 21);
let bmp3 = generate_bitmap(3, 3);
let method = SolidTinted(ARGB::from_argb([127, 155, 242, 21]));
let method = SolidTinted(RGBA::from_rgba([155, 242, 21, 127]));
let x = 40;
let y = 20;
@ -961,7 +961,7 @@ fn solid_flipped_tinted_blits() {
let bmp = generate_bitmap(16, 16);
let tint_color = ARGB::from_argb([127, 155, 242, 21]);
let tint_color = RGBA::from_rgba([155, 242, 21, 127]);
let x = 40;
let y = 20;
@ -1100,7 +1100,7 @@ fn transparent_blits() {
let bmp21 = generate_bitmap(21, 21);
let bmp3 = generate_bitmap(3, 3);
let method = Transparent(ARGB::from_rgb([0, 0, 0]));
let method = Transparent(RGBA::from_rgb([0, 0, 0]));
let x = 40;
let y = 20;
@ -1172,8 +1172,8 @@ fn transparent_tinted_blits() {
let bmp3 = generate_bitmap(3, 3);
let method = TransparentTinted {
transparent_color: ARGB::from_rgb([0, 0, 0]),
tint_color: ARGB::from_argb([127, 155, 242, 21]),
transparent_color: RGBA::from_rgb([0, 0, 0]),
tint_color: RGBA::from_rgba([155, 242, 21, 127]),
};
let x = 40;
@ -1244,7 +1244,7 @@ fn blended_transparent_blits() {
let bmp21 = generate_solid_bitmap_with_varied_alpha(21, 21);
let bmp3 = generate_solid_bitmap_with_varied_alpha(3, 3);
let method = TransparentBlended { transparent_color: ARGB::from_argb([255, 0, 0, 0]), blend: BlendFunction::Blend };
let method = TransparentBlended { transparent_color: RGBA::from_rgba([0, 0, 0, 255]), blend: BlendFunction::Blend };
let x = 40;
let y = 20;
@ -1311,7 +1311,7 @@ fn transparent_flipped_blits() {
let mut screen = setup();
screen.clear(LIGHTER_BACKGROUND);
let transparent_color = ARGB::from_rgb([0, 0, 0]);
let transparent_color = RGBA::from_rgb([0, 0, 0]);
let bmp = generate_bitmap(16, 16);
@ -1380,8 +1380,8 @@ fn transparent_flipped_tinted_blits() {
let mut screen = setup();
screen.clear(LIGHTER_BACKGROUND);
let transparent_color = ARGB::from_rgb([0, 0, 0]);
let tint_color = ARGB::from_argb([127, 155, 242, 21]);
let transparent_color = RGBA::from_rgb([0, 0, 0]);
let tint_color = RGBA::from_rgba([155, 242, 21, 127]);
let bmp = generate_bitmap(16, 16);
@ -1451,7 +1451,7 @@ fn blended_transparent_flipped_blits() {
let bmp = generate_solid_bitmap_with_varied_alpha(16, 16);
let transparent_color = ARGB::from_argb([255, 0, 0, 0]);
let transparent_color = RGBA::from_rgba([0, 0, 0, 255]);
let blend = BlendFunction::Blend;
let x = 40;
@ -1519,7 +1519,7 @@ fn transparent_single_blits() {
let mut screen = setup();
screen.clear(LIGHTER_BACKGROUND);
let transparent_color = ARGB::from_rgb([0, 0, 0]);
let transparent_color = RGBA::from_rgb([0, 0, 0]);
let bmp = generate_bitmap(16, 16);
@ -1592,7 +1592,7 @@ fn transparent_flipped_single_blits() {
let mut screen = setup();
screen.clear(LIGHTER_BACKGROUND);
let transparent_color = ARGB::from_rgb([0, 0, 0]);
let transparent_color = RGBA::from_rgb([0, 0, 0]);
let bmp = generate_bitmap(16, 16);
@ -1731,7 +1731,7 @@ fn rotozoom_tinted_blits() {
let bmp = generate_bitmap(16, 16);
let tint_color = ARGB::from_argb([127, 155, 242, 21]);
let tint_color = RGBA::from_rgba([155, 242, 21, 127]);
let x = 40;
let y = 20;
@ -1869,7 +1869,7 @@ fn rotozoom_transparent_blits() {
let mut screen = setup();
screen.clear(LIGHTER_BACKGROUND);
let transparent_color = ARGB::from_rgb([0, 0, 0]);
let transparent_color = RGBA::from_rgb([0, 0, 0]);
let bmp = generate_bitmap(16, 16);
@ -1940,8 +1940,8 @@ fn rotozoom_transparent_tinted_blits() {
let mut screen = setup();
screen.clear(LIGHTER_BACKGROUND);
let transparent_color = ARGB::from_rgb([0, 0, 0]);
let tint_color = ARGB::from_argb([127, 155, 242, 21]);
let transparent_color = RGBA::from_rgb([0, 0, 0]);
let tint_color = RGBA::from_rgba([155, 242, 21, 127]);
let bmp = generate_bitmap(16, 16);
@ -2013,7 +2013,7 @@ fn blended_rotozoom_transparent_blits() {
let bmp = generate_solid_bitmap_with_varied_alpha(16, 16);
let transparent_color = ARGB::from_argb([255, 0, 0, 0]);
let transparent_color = RGBA::from_rgba([0, 0, 0, 255]);
let blend = BlendFunction::Blend;
let x = 40;
@ -2110,34 +2110,34 @@ fn blend_function_tinted_blend() {
let bmp_solid_with_varied_alpha = generate_solid_bitmap_with_varied_alpha(32, 32);
let bmp_with_varied_alpha = generate_bitmap_with_varied_alpha(32, 32);
let method = RgbaBlitMethod::SolidBlended(BlendFunction::TintedBlend(ARGB::from_argb([255, 155, 242, 21])));
let method = RgbaBlitMethod::SolidBlended(BlendFunction::TintedBlend(RGBA::from_rgba([155, 242, 21, 255])));
screen.blit(method.clone(), &bmp_solid, 10, 5);
screen.blit(method.clone(), &bmp_solid_with_varied_alpha, 100, 5);
screen.blit(method.clone(), &bmp_with_varied_alpha, 200, 5);
let method = RgbaBlitMethod::SolidBlended(BlendFunction::TintedBlend(ARGB::from_argb([127, 155, 242, 21])));
let method = RgbaBlitMethod::SolidBlended(BlendFunction::TintedBlend(RGBA::from_rgba([155, 242, 21, 127])));
screen.blit(method.clone(), &bmp_solid, 10, 40);
screen.blit(method.clone(), &bmp_solid_with_varied_alpha, 100, 40);
screen.blit(method.clone(), &bmp_with_varied_alpha, 200, 40);
let method = RgbaBlitMethod::SolidBlended(BlendFunction::TintedBlend(ARGB::from_argb([0, 155, 242, 21])));
let method = RgbaBlitMethod::SolidBlended(BlendFunction::TintedBlend(RGBA::from_rgba([155, 242, 21, 0])));
screen.blit(method.clone(), &bmp_solid, 10, 75);
screen.blit(method.clone(), &bmp_solid_with_varied_alpha, 100, 75);
screen.blit(method.clone(), &bmp_with_varied_alpha, 200, 75);
//////
let method = RgbaBlitMethod::SolidBlended(BlendFunction::TintedBlend(ARGB::from_argb([255, 155, 242, 21])));
let method = RgbaBlitMethod::SolidBlended(BlendFunction::TintedBlend(RGBA::from_rgba([155, 242, 21, 255])));
screen.blit(method.clone(), &bmp_solid, 10, 125);
screen.blit(method.clone(), &bmp_solid_with_varied_alpha, 100, 125);
screen.blit(method.clone(), &bmp_with_varied_alpha, 200, 125);
let method = RgbaBlitMethod::SolidBlended(BlendFunction::TintedBlend(ARGB::from_argb([127, 155, 242, 21])));
let method = RgbaBlitMethod::SolidBlended(BlendFunction::TintedBlend(RGBA::from_rgba([155, 242, 21, 127])));
screen.blit(method.clone(), &bmp_solid, 10, 160);
screen.blit(method.clone(), &bmp_solid_with_varied_alpha, 100, 160);
screen.blit(method.clone(), &bmp_with_varied_alpha, 200, 160);
let method = RgbaBlitMethod::SolidBlended(BlendFunction::TintedBlend(ARGB::from_argb([0, 155, 242, 21])));
let method = RgbaBlitMethod::SolidBlended(BlendFunction::TintedBlend(RGBA::from_rgba([155, 242, 21, 0])));
screen.blit(method.clone(), &bmp_solid, 10, 195);
screen.blit(method.clone(), &bmp_solid_with_varied_alpha, 100, 195);
screen.blit(method.clone(), &bmp_with_varied_alpha, 200, 195);
@ -2204,34 +2204,34 @@ fn blend_function_multiplied_blend() {
let bmp_solid_with_varied_alpha = generate_solid_bitmap_with_varied_alpha(32, 32);
let bmp_with_varied_alpha = generate_bitmap_with_varied_alpha(32, 32);
let method = RgbaBlitMethod::SolidBlended(BlendFunction::MultipliedBlend(ARGB::from_argb([255, 242, 29, 81])));
let method = RgbaBlitMethod::SolidBlended(BlendFunction::MultipliedBlend(RGBA::from_rgba([242, 29, 81, 255])));
screen.blit(method.clone(), &bmp_solid, 10, 5);
screen.blit(method.clone(), &bmp_solid_with_varied_alpha, 100, 5);
screen.blit(method.clone(), &bmp_with_varied_alpha, 200, 5);
let method = RgbaBlitMethod::SolidBlended(BlendFunction::MultipliedBlend(ARGB::from_argb([127, 242, 29, 81])));
let method = RgbaBlitMethod::SolidBlended(BlendFunction::MultipliedBlend(RGBA::from_rgba([242, 29, 81, 127])));
screen.blit(method.clone(), &bmp_solid, 10, 40);
screen.blit(method.clone(), &bmp_solid_with_varied_alpha, 100, 40);
screen.blit(method.clone(), &bmp_with_varied_alpha, 200, 40);
let method = RgbaBlitMethod::SolidBlended(BlendFunction::MultipliedBlend(ARGB::from_argb([0, 242, 29, 81])));
let method = RgbaBlitMethod::SolidBlended(BlendFunction::MultipliedBlend(RGBA::from_rgba([242, 29, 81, 0])));
screen.blit(method.clone(), &bmp_solid, 10, 75);
screen.blit(method.clone(), &bmp_solid_with_varied_alpha, 100, 75);
screen.blit(method.clone(), &bmp_with_varied_alpha, 200, 75);
//////
let method = RgbaBlitMethod::SolidBlended(BlendFunction::MultipliedBlend(ARGB::from_argb([255, 242, 29, 81])));
let method = RgbaBlitMethod::SolidBlended(BlendFunction::MultipliedBlend(RGBA::from_rgba([242, 29, 81, 255])));
screen.blit(method.clone(), &bmp_solid, 10, 125);
screen.blit(method.clone(), &bmp_solid_with_varied_alpha, 100, 125);
screen.blit(method.clone(), &bmp_with_varied_alpha, 200, 125);
let method = RgbaBlitMethod::SolidBlended(BlendFunction::MultipliedBlend(ARGB::from_argb([127, 242, 29, 81])));
let method = RgbaBlitMethod::SolidBlended(BlendFunction::MultipliedBlend(RGBA::from_rgba([242, 29, 81, 127])));
screen.blit(method.clone(), &bmp_solid, 10, 160);
screen.blit(method.clone(), &bmp_solid_with_varied_alpha, 100, 160);
screen.blit(method.clone(), &bmp_with_varied_alpha, 200, 160);
let method = RgbaBlitMethod::SolidBlended(BlendFunction::MultipliedBlend(ARGB::from_argb([0, 242, 29, 81])));
let method = RgbaBlitMethod::SolidBlended(BlendFunction::MultipliedBlend(RGBA::from_rgba([242, 29, 81, 0])));
screen.blit(method.clone(), &bmp_solid, 10, 195);
screen.blit(method.clone(), &bmp_solid_with_varied_alpha, 100, 195);
screen.blit(method.clone(), &bmp_with_varied_alpha, 200, 195);
@ -2490,15 +2490,15 @@ fn get_quad(
let positions_2 = [top_left, bottom_right, top_right];
let texcoords_1 = [Vector2::new(0.0, 0.0), Vector2::new(0.0, 1.0), Vector2::new(1.0, 1.0)];
let texcoords_2 = [Vector2::new(0.0, 0.0), Vector2::new(1.0, 1.0), Vector2::new(1.0, 0.0)];
let single_color = ARGB::from_argb([128, 255, 0, 255]);
let colors_1 = [ARGB::from_rgb([255, 0, 0]), ARGB::from_rgb([0, 255, 0]), ARGB::from_rgb([0, 0, 255])];
let colors_2 = [ARGB::from_rgb([255, 0, 0]), ARGB::from_rgb([0, 0, 255]), ARGB::from_rgb([255, 255, 255])];
let tint_color = ARGB::from_argb([128, 192, 47, 160]);
let single_color = RGBA::from_rgba([255, 0, 255, 128]);
let colors_1 = [RGBA::from_rgb([255, 0, 0]), RGBA::from_rgb([0, 255, 0]), RGBA::from_rgb([0, 0, 255])];
let colors_2 = [RGBA::from_rgb([255, 0, 0]), RGBA::from_rgb([0, 0, 255]), RGBA::from_rgb([255, 255, 255])];
let tint_color = RGBA::from_rgba([192, 47, 160, 128]);
match mode {
TriangleType::Solid => [
RgbaTriangle2d::Solid { position: positions_1, color: ARGB::from_rgb([255, 0, 255]) },
RgbaTriangle2d::Solid { position: positions_2, color: ARGB::from_rgb([255, 0, 255]) },
RgbaTriangle2d::Solid { position: positions_1, color: RGBA::from_rgb([255, 0, 255]) },
RgbaTriangle2d::Solid { position: positions_2, color: RGBA::from_rgb([255, 0, 255]) },
],
TriangleType::SolidBlended => [
RgbaTriangle2d::SolidBlended { position: positions_1, color: single_color, blend: BlendFunction::Blend },

View file

@ -24,7 +24,7 @@ pub fn load_raw_indexed(bin_file: &Path) -> Result<Box<[u8]>, io::Error> {
Ok(buffer.into_boxed_slice())
}
pub fn load_raw_argb(bin_file: &Path) -> Result<Box<[u32]>, io::Error> {
pub fn load_raw_rgba(bin_file: &Path) -> Result<Box<[u32]>, io::Error> {
let f = File::open(bin_file)?;
let mut reader = BufReader::new(f);
let mut buffer = Vec::new();

View file

@ -22,7 +22,7 @@ mod system_resources_standard;
use ggdt::prelude::*;
const BACKGROUND_COLOR: ARGB = ARGB::from_rgb([0x2c, 0x30, 0x41]);
const BACKGROUND_COLOR: RGBA = RGBA::from_rgb([0x2c, 0x30, 0x41]);
fn draw_base_screen<BitmapType>(
dest: &mut BitmapType,

View file

@ -27,8 +27,8 @@ fn simple_main_loop(mut system: System<Standard>) {
draw_base_screen(
&mut system.res.video,
ARGB::from_rgb([32, 32, 32]),
ARGB::from_rgb([44, 44, 44]),
RGBA::from_rgb([32, 32, 32]),
RGBA::from_rgb([44, 44, 44]),
COLOR_BRIGHT_WHITE,
COLOR_BRIGHT_RED,
);

View file

@ -1,4 +1,4 @@
use ggdt::graphics::{BlendFunction, RgbaBitmap, RgbaPixelFormat, ARGB};
use ggdt::graphics::{BlendFunction, RgbaBitmap, RgbaPixelFormat, RGBA};
use ggdt::math::{Rect, Vector2};
use imgui::internal::RawWrapper;
@ -67,9 +67,9 @@ impl Renderer {
Vector2::new(v3.uv[0], v3.uv[1]),
],
&[
ARGB::from_argb([v2.col[3], v2.col[0], v2.col[1], v2.col[2]]),
ARGB::from_argb([v1.col[3], v1.col[0], v1.col[1], v1.col[2]]),
ARGB::from_argb([v3.col[3], v3.col[0], v3.col[1], v3.col[2]]),
RGBA::from_rgba([v2.col[0], v2.col[1], v2.col[2], v2.col[3]]),
RGBA::from_rgba([v1.col[0], v1.col[1], v1.col[2], v1.col[3]]),
RGBA::from_rgba([v3.col[0], v3.col[1], v3.col[2], v3.col[3]]),
],
bitmap,
BlendFunction::Blend,