use super::color::{self, ColorTrait};
use super::geom::{Point, Rectangle};
#[derive(Debug)]
pub struct Config {
pub color_model: color::Model,
pub width: usize,
pub height: usize,
}
pub trait Image {
fn color_model(&self) -> color::Model;
fn bounds(&self) -> &Rectangle;
fn at(&self, x: isize, y: isize) -> color::Color;
fn set(&mut self, x: isize, y: isize, c: &color::Color);
fn opaque(&self) -> bool;
fn stride(&self) -> usize;
fn pix(&self) -> &Vec<u8>;
fn bytes_per_pixel(&self) -> usize;
fn get_pix_mutable(&mut self) -> &mut Vec<u8>;
fn deep_equal(&self, other: &dyn Image) -> bool {
self.color_model() == other.color_model()
&& self.bounds() == other.bounds()
&& self.pix() == other.pix()
}
fn get_line_data(&self, y: isize) -> &[u8] {
let b = self.bounds();
let offset = (y - b.min.y) as usize * self.stride();
&self.pix()[offset..offset + b.dx() * self.bytes_per_pixel()]
}
}
fn pixel_buffer_length(bytes_per_pixel: usize, r: &Rectangle, _image_type_name: &str) -> usize {
bytes_per_pixel * r.dx() * r.dy()
}
#[derive(Debug)]
pub struct RGBA {
pub pix: Vec<u8>,
pub stride: usize,
pub rect: Rectangle,
}
impl Image for RGBA {
fn color_model(&self) -> color::Model {
color::Model::RGBAModel
}
fn bounds(&self) -> &Rectangle {
&self.rect
}
fn opaque(&self) -> bool {
if self.rect.empty() {
return true;
}
let mut i0 = 3;
let mut i1 = self.rect.dx() * 4;
for _y in self.rect.min.y..self.rect.max.y {
let mut i = i0;
while i < i1 {
if self.pix[i] != 0xff {
return false;
}
i += 4;
}
i0 += self.stride;
i1 += self.stride;
}
true
}
fn stride(&self) -> usize {
self.stride
}
fn pix(&self) -> &Vec<u8> {
&self.pix
}
fn get_pix_mutable(&mut self) -> &mut Vec<u8> {
&mut self.pix
}
fn at(&self, x: isize, y: isize) -> color::Color {
color::Color::RGBA(self.rgba_at(x, y))
}
fn set(&mut self, x: isize, y: isize, c: &color::Color) {
if let color::Color::RGBA(c) = c {
self.set_rbga(x, y, c);
} else {
self.set_rbga(x, y, &color::RGBA::new_from(c));
};
}
fn bytes_per_pixel(&self) -> usize {
4
}
}
impl RGBA {
pub fn new(r: &Rectangle) -> Self {
Self {
pix: vec![0; pixel_buffer_length(4, r, "RGBA")],
stride: 4 * r.dx(),
rect: *r,
}
}
pub fn rgba_at(&self, x: isize, y: isize) -> color::RGBA {
if !(Point::new(x, y).inside(&self.rect)) {
return color::RGBA::new(0, 0, 0, 0);
}
let i = self.pix_offset(x, y);
let s = &self.pix[i..i + 4];
color::RGBA::new(s[0], s[1], s[2], s[3])
}
pub fn set_rbga(&mut self, x: isize, y: isize, c: &color::RGBA) {
if !(Point::new(x, y).inside(&self.rect)) {
return;
}
let i = self.pix_offset(x, y);
let s = &mut self.pix[i..i + 4];
s[0] = c.r;
s[1] = c.g;
s[2] = c.b;
s[3] = c.a;
}
pub fn pix_offset(&self, x: isize, y: isize) -> usize {
(y - self.rect.min.y) as usize * self.stride + (x - self.rect.min.x) as usize * 4
}
}
#[derive(Debug)]
pub struct RGBA64 {
pub pix: Vec<u8>,
pub stride: usize,
rect: Rectangle,
}
impl Image for RGBA64 {
fn color_model(&self) -> color::Model {
color::Model::RGBA64Model
}
fn bounds(&self) -> &Rectangle {
&self.rect
}
fn at(&self, x: isize, y: isize) -> color::Color {
color::Color::RGBA64(self.rgba64_at(x, y))
}
fn set(&mut self, x: isize, y: isize, c: &color::Color) {
if let color::Color::RGBA64(c) = c {
self.set_rgba64(x, y, c);
} else {
self.set_rgba64(x, y, &color::RGBA64::new_from(c));
};
}
fn opaque(&self) -> bool {
if self.rect.empty() {
return true;
}
let (mut i0, mut i1) = (6, self.rect.dx() * 8);
for _y in self.rect.min.y..self.rect.max.y {
let mut i = i0;
while i < i1 {
if self.pix[i] != 0xff || self.pix[i + 1] != 0xff {
return false;
}
i += 8;
}
i0 += self.stride;
i1 += self.stride;
}
true
}
fn stride(&self) -> usize {
self.stride
}
fn pix(&self) -> &Vec<u8> {
&self.pix
}
fn get_pix_mutable(&mut self) -> &mut Vec<u8> {
&mut self.pix
}
fn bytes_per_pixel(&self) -> usize {
8
}
}
impl RGBA64 {
pub fn new(r: &Rectangle) -> Self {
Self {
pix: vec![0; pixel_buffer_length(8, r, "RGBA64")],
stride: 8 * r.dx(),
rect: *r,
}
}
pub fn pix_offset(&self, x: isize, y: isize) -> usize {
(y - self.rect.min.y) as usize * self.stride + (x - self.rect.min.x) as usize * 8
}
fn rgba64_at(&self, x: isize, y: isize) -> color::RGBA64 {
if !(Point::new(x, y).inside(&self.rect)) {
return color::RGBA64::new(0, 0, 0, 0);
}
let i = self.pix_offset(x, y);
let s = &self.pix[i..i + 8];
color::RGBA64::new(
((s[0] as u16) << 8) | (s[1] as u16),
((s[2] as u16) << 8) | (s[3] as u16),
((s[4] as u16) << 8) | (s[5] as u16),
((s[6] as u16) << 8) | (s[7] as u16),
)
}
fn set_rgba64(&mut self, x: isize, y: isize, c: &color::RGBA64) {
if !(Point::new(x, y).inside(&self.rect)) {
return;
}
let i = self.pix_offset(x, y);
let s = &mut self.pix[i..i + 8];
s[0] = (c.r >> 8) as u8;
s[1] = c.r as u8;
s[2] = (c.g >> 8) as u8;
s[3] = c.g as u8;
s[4] = (c.b >> 8) as u8;
s[5] = c.b as u8;
s[6] = (c.a >> 8) as u8;
s[7] = c.a as u8;
}
}
#[derive(Debug)]
pub struct NRGBA {
pub pix: Vec<u8>,
pub stride: usize,
pub rect: Rectangle,
}
impl Image for NRGBA {
fn color_model(&self) -> color::Model {
color::Model::NRGBAModel
}
fn bounds(&self) -> &Rectangle {
&self.rect
}
fn opaque(&self) -> bool {
if self.rect.empty() {
return true;
}
let mut i0 = 3;
let mut i1 = self.rect.dx() * 4;
for _y in self.rect.min.y..self.rect.max.y {
let mut i = i0;
while i < i1 {
if self.pix[i] != 0xff {
return false;
}
i += 4;
}
i0 += self.stride;
i1 += self.stride;
}
true
}
fn stride(&self) -> usize {
self.stride
}
fn pix(&self) -> &Vec<u8> {
&self.pix
}
fn get_pix_mutable(&mut self) -> &mut Vec<u8> {
&mut self.pix
}
fn at(&self, x: isize, y: isize) -> color::Color {
color::Color::NRGBA(self.nrgba_at(x, y))
}
fn set(&mut self, x: isize, y: isize, c: &color::Color) {
if let color::Color::NRGBA(c) = c {
self.set_nrgba(x, y, c);
} else {
self.set_nrgba(x, y, &color::NRGBA::new_from(c));
};
}
fn bytes_per_pixel(&self) -> usize {
4
}
}
impl NRGBA {
pub fn new(r: &Rectangle) -> Self {
Self {
pix: vec![0; pixel_buffer_length(4, r, "NRGBA")],
stride: 4 * r.dx(),
rect: *r,
}
}
fn nrgba_at(&self, x: isize, y: isize) -> color::NRGBA {
if !(Point::new(x, y).inside(&self.rect)) {
return color::NRGBA::new(0, 0, 0, 0);
}
let i = self.pix_offset(x, y);
let s = &self.pix[i..i + 4];
color::NRGBA::new(s[0], s[1], s[2], s[3])
}
pub fn pix_offset(&self, x: isize, y: isize) -> usize {
(y - self.rect.min.y) as usize * self.stride + (x - self.rect.min.x) as usize * 4
}
pub fn set_nrgba(&mut self, x: isize, y: isize, c: &color::NRGBA) {
if !(Point::new(x, y).inside(&self.rect)) {
return;
}
let i = self.pix_offset(x, y);
self.pix[i] = c.r;
self.pix[i + 1] = c.g;
self.pix[i + 2] = c.b;
self.pix[i + 3] = c.a;
}
}
#[derive(Debug)]
pub struct NRGBA64 {
pub pix: Vec<u8>,
pub stride: usize,
rect: Rectangle,
}
impl Image for NRGBA64 {
fn color_model(&self) -> color::Model {
color::Model::NRGBA64Model
}
fn bounds(&self) -> &Rectangle {
&self.rect
}
fn set(&mut self, x: isize, y: isize, c: &color::Color) {
if let color::Color::NRGBA64(c) = c {
self.set_nrgba64(x, y, c);
} else {
self.set_nrgba64(x, y, &color::NRGBA64::new_from(c));
};
}
fn stride(&self) -> usize {
self.stride
}
fn pix(&self) -> &Vec<u8> {
&self.pix
}
fn get_pix_mutable(&mut self) -> &mut Vec<u8> {
&mut self.pix
}
fn at(&self, x: isize, y: isize) -> color::Color {
color::Color::NRGBA64(self.nrgba64_at(x, y))
}
fn opaque(&self) -> bool {
if self.rect.empty() {
return true;
}
let (mut i0, mut i1) = (6, self.rect.dx() * 8);
for _y in self.rect.min.y..self.rect.max.y {
let mut i = i0;
while i < i1 {
if self.pix[i] != 0xff || self.pix[i + 1] != 0xff {
return false;
}
i += 8;
}
i0 += self.stride;
i1 += self.stride;
}
true
}
fn bytes_per_pixel(&self) -> usize {
8
}
}
impl NRGBA64 {
pub fn new(r: &Rectangle) -> Self {
Self {
pix: vec![0; pixel_buffer_length(8, r, "NRGBA64")],
stride: 8 * r.dx(),
rect: *r,
}
}
fn set_nrgba64(&mut self, x: isize, y: isize, c: &color::NRGBA64) {
if !(Point::new(x, y).inside(&self.rect)) {
return;
}
let i = self.pix_offset(x, y);
let s = &mut self.pix[i..i + 8];
s[0] = (c.r >> 8) as u8;
s[1] = c.r as u8;
s[2] = (c.g >> 8) as u8;
s[3] = c.g as u8;
s[4] = (c.b >> 8) as u8;
s[5] = c.b as u8;
s[6] = (c.a >> 8) as u8;
s[7] = c.a as u8;
}
pub fn pix_offset(&self, x: isize, y: isize) -> usize {
(y - self.rect.min.y) as usize * self.stride + (x - self.rect.min.x) as usize * 8
}
fn nrgba64_at(&self, x: isize, y: isize) -> color::NRGBA64 {
if !(Point::new(x, y).inside(&self.rect)) {
return color::NRGBA64::new(0, 0, 0, 0);
}
let i = self.pix_offset(x, y);
let s = &self.pix[i..i + 8];
color::NRGBA64::new(
(s[0] as u16) << 8 | (s[1] as u16),
(s[2] as u16) << 8 | (s[3] as u16),
(s[4] as u16) << 8 | (s[5] as u16),
(s[6] as u16) << 8 | (s[7] as u16),
)
}
}
#[derive(Debug)]
pub struct Alpha {
pub pix: Vec<u8>,
pub stride: usize,
rect: Rectangle,
}
impl Image for Alpha {
fn color_model(&self) -> color::Model {
color::Model::AlphaModel
}
fn bounds(&self) -> &Rectangle {
&self.rect
}
fn at(&self, x: isize, y: isize) -> color::Color {
color::Color::Alpha(self.alpha_at(x, y))
}
fn set(&mut self, x: isize, y: isize, c: &color::Color) {
if let color::Color::Alpha(c) = c {
self.set_alpha(x, y, c);
} else {
self.set_alpha(x, y, &color::Alpha::new_from(c));
};
}
fn opaque(&self) -> bool {
if self.rect.empty() {
return true;
}
let (mut i0, mut i1) = (0, self.rect.dx());
for _y in self.rect.min.y..self.rect.max.y {
for i in i0..i1 {
if self.pix[i] != 0xff {
return false;
}
}
i0 += self.stride;
i1 += self.stride;
}
true
}
fn stride(&self) -> usize {
self.stride
}
fn pix(&self) -> &Vec<u8> {
&self.pix
}
fn get_pix_mutable(&mut self) -> &mut Vec<u8> {
&mut self.pix
}
fn bytes_per_pixel(&self) -> usize {
1
}
}
impl Alpha {
pub fn new(r: &Rectangle) -> Self {
Self {
pix: vec![0; pixel_buffer_length(1, r, "Alpha")],
stride: r.dx(),
rect: *r,
}
}
fn alpha_at(&self, x: isize, y: isize) -> color::Alpha {
if !(Point::new(x, y).inside(&self.rect)) {
return color::Alpha::new(0);
}
let i = self.pix_offset(x, y);
color::Alpha::new(self.pix[i])
}
pub fn pix_offset(&self, x: isize, y: isize) -> usize {
(y - self.rect.min.y) as usize * self.stride + (x - self.rect.min.x) as usize
}
fn set_alpha(&mut self, x: isize, y: isize, c: &color::Alpha) {
if !(Point::new(x, y).inside(&self.rect)) {
return;
}
let i = self.pix_offset(x, y);
self.pix[i] = c.a;
}
}
#[derive(Debug)]
pub struct Alpha16 {
pub pix: Vec<u8>,
pub stride: usize,
rect: Rectangle,
}
impl Image for Alpha16 {
fn color_model(&self) -> color::Model {
color::Model::Alpha16Model
}
fn bounds(&self) -> &Rectangle {
&self.rect
}
fn at(&self, x: isize, y: isize) -> color::Color {
color::Color::Alpha16(self.alpha16_at(x, y))
}
fn set(&mut self, x: isize, y: isize, c: &color::Color) {
if let color::Color::Alpha16(c) = c {
self.set_alpha16(x, y, c);
} else {
self.set_alpha16(x, y, &color::Alpha16::new_from(c));
};
}
fn opaque(&self) -> bool {
if self.rect.empty() {
return true;
}
let (mut i0, mut i1) = (0, self.rect.dx() * 2);
for _y in self.rect.min.y..self.rect.max.y {
let mut i = i0;
while i < i1 {
if self.pix[i] != 0xff || self.pix[i + 1] != 0xff {
return false;
}
i += 2;
}
i0 += self.stride;
i1 += self.stride;
}
true
}
fn stride(&self) -> usize {
self.stride
}
fn pix(&self) -> &Vec<u8> {
&self.pix
}
fn get_pix_mutable(&mut self) -> &mut Vec<u8> {
&mut self.pix
}
fn bytes_per_pixel(&self) -> usize {
2
}
}
impl Alpha16 {
pub fn new(r: &Rectangle) -> Self {
Self {
pix: vec![0; pixel_buffer_length(2, r, "Alpha16")],
stride: 2 * r.dx(),
rect: *r,
}
}
fn alpha16_at(&self, x: isize, y: isize) -> color::Alpha16 {
if !(Point::new(x, y).inside(&self.rect)) {
return color::Alpha16::new(0);
}
let i = self.pix_offset(x, y);
color::Alpha16::new((self.pix[i] as u16) << 8 | (self.pix[i + 1] as u16))
}
pub fn pix_offset(&self, x: isize, y: isize) -> usize {
(y - self.rect.min.y) as usize * self.stride + (x - self.rect.min.x) as usize * 2
}
fn set_alpha16(&mut self, x: isize, y: isize, c: &color::Alpha16) {
if !(Point::new(x, y).inside(&self.rect)) {
return;
}
let i = self.pix_offset(x, y);
self.pix[i] = (c.a >> 8) as u8;
self.pix[i + 1] = (c.a) as u8;
}
}
#[derive(Debug)]
pub struct Gray {
pub pix: Vec<u8>,
pub stride: usize,
rect: Rectangle,
}
impl Image for Gray {
fn color_model(&self) -> color::Model {
color::Model::GrayModel
}
fn bounds(&self) -> &Rectangle {
&self.rect
}
fn opaque(&self) -> bool {
true
}
fn stride(&self) -> usize {
self.stride
}
fn pix(&self) -> &Vec<u8> {
&self.pix
}
fn get_pix_mutable(&mut self) -> &mut Vec<u8> {
&mut self.pix
}
fn at(&self, x: isize, y: isize) -> color::Color {
color::Color::Gray(self.gray_at(x, y))
}
fn set(&mut self, x: isize, y: isize, c: &color::Color) {
if let color::Color::Gray(c) = c {
self.set_gray(x, y, c);
} else {
self.set_gray(x, y, &color::Gray::new_from(c));
};
}
fn bytes_per_pixel(&self) -> usize {
1
}
}
impl Gray {
pub fn new(r: &Rectangle) -> Self {
Self {
pix: vec![0; pixel_buffer_length(1, r, "Gray")],
stride: r.dx(),
rect: *r,
}
}
pub fn gray_at(&self, x: isize, y: isize) -> color::Gray {
if !(Point::new(x, y).inside(&self.rect)) {
return color::Gray::new(0);
}
let i = self.pix_offset(x, y);
color::Gray::new(self.pix[i])
}
pub fn pix_offset(&self, x: isize, y: isize) -> usize {
(y - self.rect.min.y) as usize * self.stride + (x - self.rect.min.x) as usize
}
fn set_gray(&mut self, x: isize, y: isize, c: &color::Gray) {
if !(Point::new(x, y).inside(&self.rect)) {
return;
}
let i = self.pix_offset(x, y);
self.pix[i] = c.y;
}
}
#[derive(Debug)]
pub struct Gray16 {
pub pix: Vec<u8>,
pub stride: usize,
rect: Rectangle,
}
impl Image for Gray16 {
fn color_model(&self) -> color::Model {
color::Model::Gray16Model
}
fn bounds(&self) -> &Rectangle {
&self.rect
}
fn opaque(&self) -> bool {
true
}
fn stride(&self) -> usize {
self.stride
}
fn pix(&self) -> &Vec<u8> {
&self.pix
}
fn get_pix_mutable(&mut self) -> &mut Vec<u8> {
&mut self.pix
}
fn at(&self, x: isize, y: isize) -> color::Color {
color::Color::Gray16(self.gray16_at(x, y))
}
fn set(&mut self, x: isize, y: isize, c: &color::Color) {
if let color::Color::Gray16(c) = c {
self.set_gray16(x, y, c);
} else {
self.set_gray16(x, y, &color::Gray16::new_from(c));
};
}
fn bytes_per_pixel(&self) -> usize {
2
}
}
impl Gray16 {
pub fn new(r: &Rectangle) -> Self {
Self {
pix: vec![0; pixel_buffer_length(2, r, "Gray16")],
stride: 2 * r.dx(),
rect: *r,
}
}
pub fn gray16_at(&self, x: isize, y: isize) -> color::Gray16 {
if !(Point::new(x, y).inside(&self.rect)) {
return color::Gray16::new(0);
}
let i = self.pix_offset(x, y);
color::Gray16::new(((self.pix[i] as u16) << 8) | (self.pix[i + 1] as u16))
}
pub fn pix_offset(&self, x: isize, y: isize) -> usize {
(y - self.rect.min.y) as usize * self.stride + (x - self.rect.min.x) as usize * 2
}
fn set_gray16(&mut self, x: isize, y: isize, c: &color::Gray16) {
if !(Point::new(x, y).inside(&self.rect)) {
return;
}
let i = self.pix_offset(x, y);
self.pix[i] = (c.y >> 8) as u8;
self.pix[i + 1] = (c.y) as u8;
}
}
#[derive(Debug)]
pub struct Paletted {
pub pix: Vec<u8>,
pub stride: usize,
rect: Rectangle,
pub(super) palette: color::Palette,
}
impl Image for Paletted {
fn color_model(&self) -> color::Model {
color::Model::Paletted(self.palette.clone())
}
fn bounds(&self) -> &Rectangle {
&self.rect
}
fn at(&self, x: isize, y: isize) -> color::Color {
if self.palette.colors.is_empty() {
return color::Color::new_rgba(0, 0, 0, 0);
}
if !(Point::new(x, y).inside(&self.rect)) {
return self.palette.colors[0];
}
let i = self.pix_offset(x, y);
self.palette.colors[self.pix[i] as usize]
}
fn set(&mut self, x: isize, y: isize, c: &color::Color) {
if !(Point::new(x, y).inside(&self.rect)) {
return;
}
let i = self.pix_offset(x, y);
self.pix[i] = self.palette.index(c) as u8;
}
fn opaque(&self) -> bool {
let mut present = [false; 256];
let (mut i0, mut i1) = (0, self.rect.dx());
for _y in self.rect.min.y..self.rect.max.y {
for c in &self.pix[i0..i1] {
present[*c as usize] = true;
}
i0 += self.stride;
i1 += self.stride;
}
for (i, c) in self.palette.colors.iter().enumerate() {
if !present[i] {
continue;
}
let (_, _, _, a) = c.rgba();
if a != 0xffff {
return false;
}
}
true
}
fn stride(&self) -> usize {
self.stride
}
fn pix(&self) -> &Vec<u8> {
&self.pix
}
fn get_pix_mutable(&mut self) -> &mut Vec<u8> {
&mut self.pix
}
fn bytes_per_pixel(&self) -> usize {
1
}
}
impl Paletted {
pub fn new(r: &Rectangle, p: color::Palette) -> Self {
Self {
pix: vec![0; pixel_buffer_length(1, r, "Paletted")],
stride: r.dx(),
rect: *r,
palette: p,
}
}
pub fn pix_offset(&self, x: isize, y: isize) -> usize {
(y - self.rect.min.y) as usize * self.stride + (x - self.rect.min.x) as usize
}
pub fn color_index_at(&self, x: isize, y: isize) -> u8 {
if !(Point::new(x, y).inside(&self.rect)) {
return 0;
}
let i = self.pix_offset(x, y);
self.pix[i]
}
pub fn set_color_index(&mut self, x: isize, y: isize, index: u8) {
if !Point::new(x, y).inside(&self.rect) {
return;
}
let i = self.pix_offset(x, y);
self.pix[i] = index;
}
}
#[derive(Debug)]
pub enum Img {
Alpha(Alpha),
Alpha16(Alpha16),
Gray(Gray),
Gray16(Gray16),
NRGBA(NRGBA),
NRGBA64(NRGBA64),
Paletted(Paletted),
RGBA(RGBA),
RGBA64(RGBA64),
}
impl Img {
pub fn new_rgba(r: &Rectangle) -> Self {
Self::RGBA(RGBA::new(r))
}
pub fn new_nrgba(r: &Rectangle) -> Self {
Self::NRGBA(NRGBA::new(r))
}
pub fn new_nrgba64(r: &Rectangle) -> Img {
Img::NRGBA64(NRGBA64::new(r))
}
pub fn new_rgba64(r: &Rectangle) -> Img {
Img::RGBA64(RGBA64::new(r))
}
}
impl Image for Img {
fn bytes_per_pixel(&self) -> usize {
match self {
Img::Paletted(img) => img.bytes_per_pixel(),
Img::RGBA(img) => img.bytes_per_pixel(),
Img::NRGBA(img) => img.bytes_per_pixel(),
Img::RGBA64(img) => img.bytes_per_pixel(),
Img::NRGBA64(img) => img.bytes_per_pixel(),
Img::Alpha(img) => img.bytes_per_pixel(),
Img::Alpha16(img) => img.bytes_per_pixel(),
Img::Gray(img) => img.bytes_per_pixel(),
Img::Gray16(img) => img.bytes_per_pixel(),
}
}
fn stride(&self) -> usize {
match self {
Img::Paletted(img) => img.stride(),
Img::RGBA(img) => img.stride(),
Img::NRGBA(img) => img.stride(),
Img::RGBA64(img) => img.stride(),
Img::NRGBA64(img) => img.stride(),
Img::Alpha(img) => img.stride(),
Img::Alpha16(img) => img.stride(),
Img::Gray(img) => img.stride(),
Img::Gray16(img) => img.stride(),
}
}
fn bounds(&self) -> &Rectangle {
match self {
Img::Paletted(img) => img.bounds(),
Img::RGBA(img) => img.bounds(),
Img::NRGBA(img) => img.bounds(),
Img::RGBA64(img) => img.bounds(),
Img::NRGBA64(img) => img.bounds(),
Img::Alpha(img) => img.bounds(),
Img::Alpha16(img) => img.bounds(),
Img::Gray(img) => img.bounds(),
Img::Gray16(img) => img.bounds(),
}
}
fn pix(&self) -> &Vec<u8> {
match self {
Img::Paletted(img) => img.pix(),
Img::RGBA(img) => img.pix(),
Img::NRGBA(img) => img.pix(),
Img::RGBA64(img) => img.pix(),
Img::NRGBA64(img) => img.pix(),
Img::Alpha(img) => img.pix(),
Img::Alpha16(img) => img.pix(),
Img::Gray(img) => img.pix(),
Img::Gray16(img) => img.pix(),
}
}
fn get_pix_mutable(&mut self) -> &mut Vec<u8> {
match self {
Img::Paletted(img) => img.get_pix_mutable(),
Img::RGBA(img) => img.get_pix_mutable(),
Img::NRGBA(img) => img.get_pix_mutable(),
Img::RGBA64(img) => img.get_pix_mutable(),
Img::NRGBA64(img) => img.get_pix_mutable(),
Img::Alpha(img) => img.get_pix_mutable(),
Img::Alpha16(img) => img.get_pix_mutable(),
Img::Gray(img) => img.get_pix_mutable(),
Img::Gray16(img) => img.get_pix_mutable(),
}
}
fn color_model(&self) -> color::Model {
match self {
Img::Paletted(img) => img.color_model(),
Img::RGBA(img) => img.color_model(),
Img::NRGBA(img) => img.color_model(),
Img::RGBA64(img) => img.color_model(),
Img::NRGBA64(img) => img.color_model(),
Img::Alpha(img) => img.color_model(),
Img::Alpha16(img) => img.color_model(),
Img::Gray(img) => img.color_model(),
Img::Gray16(img) => img.color_model(),
}
}
fn at(&self, x: isize, y: isize) -> color::Color {
match self {
Img::Paletted(img) => img.at(x, y),
Img::RGBA(img) => img.at(x, y),
Img::NRGBA(img) => img.at(x, y),
Img::RGBA64(img) => img.at(x, y),
Img::NRGBA64(img) => img.at(x, y),
Img::Alpha(img) => img.at(x, y),
Img::Alpha16(img) => img.at(x, y),
Img::Gray(img) => img.at(x, y),
Img::Gray16(img) => img.at(x, y),
}
}
fn set(&mut self, x: isize, y: isize, c: &color::Color) {
match self {
Img::Paletted(img) => img.set(x, y, c),
Img::RGBA(img) => img.set(x, y, c),
Img::NRGBA(img) => img.set(x, y, c),
Img::RGBA64(img) => img.set(x, y, c),
Img::NRGBA64(img) => img.set(x, y, c),
Img::Alpha(img) => img.set(x, y, c),
Img::Alpha16(img) => img.set(x, y, c),
Img::Gray(img) => img.set(x, y, c),
Img::Gray16(img) => img.set(x, y, c),
}
}
fn opaque(&self) -> bool {
match self {
Img::Paletted(img) => img.opaque(),
Img::RGBA(img) => img.opaque(),
Img::NRGBA(img) => img.opaque(),
Img::RGBA64(img) => img.opaque(),
Img::NRGBA64(img) => img.opaque(),
Img::Alpha(img) => img.opaque(),
Img::Alpha16(img) => img.opaque(),
Img::Gray(img) => img.opaque(),
Img::Gray16(img) => img.opaque(),
}
}
}