#![allow(unused)]
#![allow(bad_style)]
#![allow(dead_code)]
#![allow(clippy::match_ref_pats)]
#![allow(clippy::unreadable_literal)]
#![allow(clippy::naive_bytecount)]
#![allow(clippy::single_match)]
#![allow(clippy::cognitive_complexity)]
extern crate alloc;
use alloc::{borrow::Cow, format, string::String, vec, vec::Vec};
use bytemuck::*;
use core::{
convert::TryFrom,
mem::{align_of, size_of, size_of_val},
ops::{Index, IndexMut},
};
macro_rules! dump {
($fmt_str:literal, $($n:expr),*) => (if cfg!(debug_assertions) {
$(println!(
concat!("{}:{}> ", stringify!($n), ": ", $fmt_str),
file!(),
line!(),
$n);
)*
});
($($n:expr),*) => (if cfg!(debug_assertions) {
$(println!(
concat!("{}:{}> ",stringify!($n),": {:?}"),
file!(),
line!(),
$n);
)*
});
}
macro_rules! trace {
($msg:literal) => (if cfg!(debug_assertions) {
println!(
concat!("{}:{}> ",$msg),
file!(),
line!(),
);
});
($fmt_str:literal, $($tokens:tt)*) => (if cfg!(debug_assertions) {
println!(
concat!("{}:{}> ",$fmt_str),
file!(),
line!(),
$($tokens)*
);
});
}
#[cfg(feature = "png")]
pub mod inflate;
#[cfg(feature = "png")]
pub mod png;
#[cfg(feature = "png")]
pub mod zlib;
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
#[repr(C)]
pub struct Pal256 {
pub i: u8,
}
unsafe impl Zeroable for Pal256 {}
unsafe impl Pod for Pal256 {}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
#[repr(C)]
pub struct Y8 {
pub y: u8,
}
unsafe impl Zeroable for Y8 {}
unsafe impl Pod for Y8 {}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
#[repr(C)]
pub struct YA8 {
pub y: u8,
pub a: u8,
}
unsafe impl Zeroable for YA8 {}
unsafe impl Pod for YA8 {}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
#[repr(C)]
pub struct RGB8 {
pub r: u8,
pub g: u8,
pub b: u8,
}
unsafe impl Zeroable for RGB8 {}
unsafe impl Pod for RGB8 {}
impl RGB8 {
pub fn as_rgba(self) -> RGBA8 {
RGBA8 {
r:self.r,
g:self.g,
b:self.b,
a: 0xFF,
}
}
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
#[repr(C)]
pub struct RGBA8 {
pub r: u8,
pub g: u8,
pub b: u8,
pub a: u8,
}
unsafe impl Zeroable for RGBA8 {}
unsafe impl Pod for RGBA8 {}
#[derive(Debug, Clone)]
pub struct BitmapRGBA8 {
pub pixels: Vec<RGBA8>,
pub width: usize,
pub height: usize,
}
impl Index<(usize, usize)> for BitmapRGBA8 {
type Output = RGBA8;
#[inline]
fn index(&self, (x, y): (usize, usize)) -> &RGBA8 {
&self.pixels[x + y * self.width]
}
}
impl IndexMut<(usize, usize)> for BitmapRGBA8 {
#[inline]
fn index_mut(&mut self, (x, y): (usize, usize)) -> &mut RGBA8 {
&mut self.pixels[x + y * self.width]
}
}
#[cfg(any(target_pointer_width = "32", target_pointer_width = "64"))]
impl Index<(u32, u32)> for BitmapRGBA8 {
type Output = RGBA8;
#[inline]
fn index(&self, (x, y): (u32, u32)) -> &RGBA8 {
&self[(x as usize, y as usize)]
}
}
#[cfg(any(target_pointer_width = "32", target_pointer_width = "64"))]
impl IndexMut<(u32, u32)> for BitmapRGBA8 {
#[inline]
fn index_mut(&mut self, (x, y): (u32, u32)) -> &mut RGBA8 {
&mut self[(x as usize, y as usize)]
}
}
impl Index<usize> for BitmapRGBA8 {
type Output = [RGBA8];
#[inline]
fn index(&self, y: usize) -> &[RGBA8] {
&self.pixels[y * self.width..self.width]
}
}
impl IndexMut<usize> for BitmapRGBA8 {
#[inline]
fn index_mut(&mut self, y: usize) -> &mut [RGBA8] {
&mut self.pixels[y * self.width..self.width]
}
}
#[cfg(any(target_pointer_width = "32", target_pointer_width = "64"))]
impl Index<u32> for BitmapRGBA8 {
type Output = [RGBA8];
#[inline]
fn index(&self, y: u32) -> &[RGBA8] {
&self[y as usize]
}
}
#[cfg(any(target_pointer_width = "32", target_pointer_width = "64"))]
impl IndexMut<u32> for BitmapRGBA8 {
#[inline]
fn index_mut(&mut self, y: u32) -> &mut [RGBA8] {
&mut self[y as usize]
}
}