winit-core: move icon
This commit is contained in:
parent
a491c2abed
commit
cbb29ab526
8 changed files with 60 additions and 39 deletions
|
|
@ -1,7 +1,18 @@
|
|||
#![allow(clippy::assertions_on_constants)]
|
||||
|
||||
use super::*;
|
||||
use crate::icon::{Pixel, RgbaIcon, PIXEL_SIZE};
|
||||
use crate::icon::RgbaIcon;
|
||||
|
||||
pub(crate) const PIXEL_SIZE: usize = mem::size_of::<Pixel>();
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct Pixel {
|
||||
pub(crate) r: u8,
|
||||
pub(crate) g: u8,
|
||||
pub(crate) b: u8,
|
||||
pub(crate) a: u8,
|
||||
}
|
||||
|
||||
impl Pixel {
|
||||
pub fn to_packed_argb(&self) -> Cardinal {
|
||||
|
|
@ -18,19 +29,17 @@ impl Pixel {
|
|||
}
|
||||
}
|
||||
|
||||
impl RgbaIcon {
|
||||
pub(crate) fn to_cardinals(&self) -> Vec<Cardinal> {
|
||||
assert_eq!(self.rgba.len() % PIXEL_SIZE, 0);
|
||||
let pixel_count = self.rgba.len() / PIXEL_SIZE;
|
||||
assert_eq!(pixel_count, (self.width * self.height) as usize);
|
||||
let mut data = Vec::with_capacity(pixel_count);
|
||||
data.push(self.width as Cardinal);
|
||||
data.push(self.height as Cardinal);
|
||||
let pixels = self.rgba.as_ptr() as *const Pixel;
|
||||
for pixel_index in 0..pixel_count {
|
||||
let pixel = unsafe { &*pixels.add(pixel_index) };
|
||||
data.push(pixel.to_packed_argb());
|
||||
}
|
||||
data
|
||||
pub(crate) fn rgba_to_cardinals(icon: &RgbaIcon) -> Vec<Cardinal> {
|
||||
assert_eq!(icon.buffer().len() % PIXEL_SIZE, 0);
|
||||
let pixel_count = icon.buffer().len() / PIXEL_SIZE;
|
||||
assert_eq!(pixel_count, (icon.width() * icon.height()) as usize);
|
||||
let mut data = Vec::with_capacity(pixel_count);
|
||||
data.push(icon.width() as Cardinal);
|
||||
data.push(icon.height() as Cardinal);
|
||||
let pixels = icon.buffer().as_ptr() as *const Pixel;
|
||||
for pixel_index in 0..pixel_count {
|
||||
let pixel = unsafe { &*pixels.add(pixel_index) };
|
||||
data.push(pixel.to_packed_argb());
|
||||
}
|
||||
data
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue