mirror of
https://github.com/redstrate/Physis.git
synced 2025-05-02 08:47:45 +00:00
We had a few odd dependencies that caused nothing but pain in dependent projects like libphysis. One of these was libunshield (a C library) that our game_install feature used, but to be honest this was the wrong library to put this code. It was really only ever used by Astra, and should live there instead - there's no reason to have it shared between applications (and it's small enough to be copied if *you* need it.) Also that also killed the system-deps dependency which had a significant impact on our build time. Another dependency was replaced: libz-sys. This is replaced by the pure Rust libz-rs (through libz-rs-sys) which should simplify deploying physis without having to worry about manually linking libz or other nonsense. Some leftover copied code from flate2 can also be removed. I also removed the visual_data feature as Astra ended up using it anyway, and the distinction doesn't make much sense now. It was previously to gate some dependencies needed for visual data extraction, but the bitflags and half crates are small. I can look into splitting the crate up into more features if needed later. A dependency that was erroneously included in the refactoring was quote, which has been removed. Also ran cargo fmt, clippy too.
52 lines
1.9 KiB
Rust
52 lines
1.9 KiB
Rust
// SPDX-FileCopyrightText: 2023 Rudolf Kolbe
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
// macro to generate generic block decoder functions
|
|
macro_rules! block_decoder {
|
|
($name: ident, $block_width: expr, $block_height: expr, $raw_block_size: expr, $block_decode_func: expr) => {
|
|
//#[doc = "Decodes a " $name " encoded texture into an image"]
|
|
pub fn $name(
|
|
data: &[u8],
|
|
width: usize,
|
|
height: usize,
|
|
image: &mut [u32],
|
|
) -> Result<(), &'static str> {
|
|
const BLOCK_WIDTH: usize = $block_width;
|
|
const BLOCK_HEIGHT: usize = $block_height;
|
|
const BLOCK_SIZE: usize = BLOCK_WIDTH * BLOCK_HEIGHT;
|
|
let num_blocks_x: usize = (width + BLOCK_WIDTH - 1) / BLOCK_WIDTH;
|
|
let num_blocks_y: usize = (height + BLOCK_WIDTH - 1) / BLOCK_HEIGHT;
|
|
let mut buffer: [u32; BLOCK_SIZE] =
|
|
[crate::bcn::color::color(0, 0, 0, 255); BLOCK_SIZE];
|
|
|
|
if data.len() < num_blocks_x * num_blocks_y * $raw_block_size {
|
|
return Err("Not enough data to decode image!");
|
|
}
|
|
|
|
if image.len() < width * height {
|
|
return Err("Image buffer is too small!");
|
|
}
|
|
|
|
let mut data_offset = 0;
|
|
(0..num_blocks_y).for_each(|by| {
|
|
(0..num_blocks_x).for_each(|bx| {
|
|
$block_decode_func(&data[data_offset..], &mut buffer);
|
|
crate::bcn::color::copy_block_buffer(
|
|
bx,
|
|
by,
|
|
width,
|
|
height,
|
|
BLOCK_WIDTH,
|
|
BLOCK_HEIGHT,
|
|
&buffer,
|
|
image,
|
|
);
|
|
data_offset += $raw_block_size;
|
|
});
|
|
});
|
|
Ok(())
|
|
}
|
|
};
|
|
}
|
|
|
|
pub(crate) use block_decoder;
|