Switch to sRGBA everywhere
This commit is contained in:
parent
859fdb4bfe
commit
1e73c01845
6 changed files with 52 additions and 44 deletions
|
|
@ -1,15 +1,15 @@
|
|||
use image::RgbImage;
|
||||
use palette::Srgb;
|
||||
use image::RgbaImage;
|
||||
use palette::{blend::Compose, Srgba};
|
||||
|
||||
use crate::{color, Rect, Vec2};
|
||||
|
||||
pub struct View<'a> {
|
||||
area: Rect,
|
||||
buffer: &'a mut RgbImage,
|
||||
buffer: &'a mut RgbaImage,
|
||||
}
|
||||
|
||||
impl<'a> View<'a> {
|
||||
pub fn new(buffer: &'a mut RgbImage) -> Self {
|
||||
pub fn new(buffer: &'a mut RgbaImage) -> Self {
|
||||
let size = Vec2::from_u32(buffer.width(), buffer.height());
|
||||
let area = Rect::from_nw(Vec2::ZERO, size);
|
||||
Self { area, buffer }
|
||||
|
|
@ -35,22 +35,30 @@ impl<'a> View<'a> {
|
|||
pos + self.area.corner_nw()
|
||||
}
|
||||
|
||||
pub fn get(&self, pos: Vec2) -> Option<Srgb> {
|
||||
pub fn get(&self, pos: Vec2) -> Option<Srgba> {
|
||||
let (x, y) = self.pos_to_buffer_pos(pos).to_u32();
|
||||
let pixel = self.buffer.get_pixel_checked(x, y)?;
|
||||
Some(color::from_image_rgb(*pixel))
|
||||
Some(color::from_image_color(*pixel))
|
||||
}
|
||||
|
||||
pub fn set(&mut self, pos: Vec2, color: Srgb) {
|
||||
pub fn set(&mut self, pos: Vec2, color: Srgba) {
|
||||
let (x, y) = self.pos_to_buffer_pos(pos).to_u32();
|
||||
if let Some(pixel) = self.buffer.get_pixel_mut_checked(x, y) {
|
||||
*pixel = color::to_image_rgb(color);
|
||||
let below = color::from_image_color(*pixel);
|
||||
*pixel = color::to_image_color(color.atop(below));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn replace(&mut self, pos: Vec2, color: Srgba) {
|
||||
let (x, y) = self.pos_to_buffer_pos(pos).to_u32();
|
||||
if let Some(pixel) = self.buffer.get_pixel_mut_checked(x, y) {
|
||||
*pixel = color::to_image_color(color);
|
||||
}
|
||||
}
|
||||
|
||||
// More complicated drawing primitives
|
||||
|
||||
pub fn rect(&mut self, area: Rect, color: Srgb) {
|
||||
pub fn rect(&mut self, area: Rect, color: Srgba) {
|
||||
let nw = area.corner_nw();
|
||||
let se = area.corner_se();
|
||||
for y in nw.y..=se.y {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue