aboutsummaryrefslogtreecommitdiff
path: root/src/render/composite.rs
blob: 99950f16fc4e5d398e0daeca5b5d9bf7525c20d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use image::ImageBuffer;
use image::Rgba;
pub const REGION_SIZE: usize = 16 * 8;
pub const CHUNK_HEIGHT: usize = 320;
pub const CHUNK_SIZE: usize = 16;

pub fn image_buffer_blit(
    target: &mut ImageBuffer<Rgba<u8>, Vec<u8>>,
    source: &ImageBuffer<Rgba<u8>, Vec<u8>>,
    offset: (u32, u32),
) {
    for (x, y, source_pixel) in source.enumerate_pixels() {
        let target_pixel = target.get_pixel_mut(x + offset.0, y + offset.1);
        let sa = source_pixel.0[3] as u16;
        let new_pixel = Rgba::from([
            ((target_pixel.0[0] as u16 * (255 - sa)) / 255 + (source_pixel.0[0] as u16 * sa) / 255)
                as u8,
            ((target_pixel.0[1] as u16 * (255 - sa)) / 255 + (source_pixel.0[1] as u16 * sa) / 255)
                as u8,
            ((target_pixel.0[2] as u16 * (255 - sa)) / 255 + (source_pixel.0[2] as u16 * sa) / 255)
                as u8,
            255 - (((255 - target_pixel.0[3] as u16) * (255 - sa)) / 255) as u8,
        ]);
        *target_pixel = new_pixel;
    }
}

// pub fn isometric_coord_mapping(x: i32, y: i32, z: i32) -> (u32, u32) {
//     // const BASE_X: i32 = 1016;
//     const BASE_X: i32 = (SEG_SIZE as i32 * 8) - 8;
//     const BASE_Y: i32 = 2040;

//     const XDIFF: (i32, i32) = (-8, 4);
//     const ZDIFF: (i32, i32) = (8, 4);
//     const YDIFF: (i32, i32) = (0, -8);

//     let diff = (
//         XDIFF.0 * x + YDIFF.0 * y + ZDIFF.0 * z,
//         XDIFF.1 * x + YDIFF.1 * y + ZDIFF.1 * z,
//     );

//     let coords = (BASE_X + diff.0, BASE_Y + diff.1);

//     (coords.0 as u32, coords.1 as u32)
// }