grafix_toolbox/kit/opengl/utility/
image.rs1pub use {animation::*, atlas::*, vtex::*};
2
3pub type uImage<S> = Image<S, u8>;
4pub type fImage<S> = Image<S, f16>;
5
6#[derive_as_obj(Default, PartialEq)]
7pub struct Image<S, F: TexFmt> {
8 s: Dummy<S>,
9 pub w: u32,
10 pub h: u32,
11 #[cfg_attr(feature = "adv_fs", serde(with = "ser::as_byte_slice"))]
12 pub data: Box<[F]>,
13}
14impl<S: TexSize, F: TexFmt> Tile<F> for Image<S, F> {
15 fn w(&self) -> i32 {
16 i32(self.w)
17 }
18 fn h(&self) -> i32 {
19 i32(self.h)
20 }
21 fn data(&self) -> &[F] {
22 &self.data
23 }
24}
25impl<S: TexSize, F: TexFmt> Image<S, F> {
26 pub fn new<A>(size: A, data: impl Into<Box<[F]>>) -> Self
27 where
28 uVec2: Cast<A>,
29 {
30 let (w, h) = vec2(size);
31 Self { s: Dummy, w, h, data: data.into() }
32 }
33 pub fn cut(&self, _region @ (x1, y1, x2, y2): ulVec4) -> Self {
34 let Self { w, h, ref data, .. } = *self;
35 ASSERT!(
36 _region.gt(0).all() && _region.zw().gt(_region.xy()).all() && _region.zw().sub(_region.xy()).ls((w, h)).all(),
37 "Cutting invalid image region"
38 );
39 let (w, s) = ulVec2((w, S::SIZE));
40 let mut d = vec![];
41 for y in y1..y2 {
42 let b = (y * w + x1) * s;
43 let e = b + (x2 - x1) * s;
44 d.extend_from_slice(&data[b..e]);
45 }
46 let (w, h) = vec2((x2 - x1, y2 - y1));
47 Self { s: Dummy, w, h, data: d.into() }
48 }
49}
50
51mod animation;
52mod atlas;
53mod atlas_pack;
54mod loading;
55mod tex_to_img;
56mod vtex;
57
58use crate::{GL::tex::*, lib::*, math::*};