mirror of
https://github.com/FranLMSP/pokemon_sprite_decompress.git
synced 2024-11-23 09:31:33 +00:00
Fix overflow handling when calculating the offsets
This commit is contained in:
parent
97540975c7
commit
2ed903261c
@ -111,8 +111,9 @@ impl Buffer {
|
||||
// sprite in a box of 7 * 7 tiles
|
||||
// vertical offset = 7 - height
|
||||
// horizontal offset = ((7 - width) / 2) + (1/2) -> then round the result down
|
||||
self.vertical_offset = if width > MAX_SPRITE_SIZE {255 - width} else {MAX_SPRITE_SIZE - width};
|
||||
let res = (((MAX_SPRITE_SIZE as f32 - height as f32) / 2.0) + (1.0 / 2.0)) as f32;
|
||||
self.vertical_offset = if width > MAX_SPRITE_SIZE {255 - width + MAX_SPRITE_SIZE} else {MAX_SPRITE_SIZE - width};
|
||||
let height_substraction: u8 = if width > MAX_SPRITE_SIZE {255 - height + MAX_SPRITE_SIZE} else {MAX_SPRITE_SIZE - height};
|
||||
let res = ((height_substraction as f32 / 2.0) + (1.0 / 2.0)) as f32;
|
||||
self.horizontal_offset = res.floor() as u8;
|
||||
// We need 3 bitplanes, the first and second ones are where the
|
||||
// decompressed bytes will be, which are 7 x 7 each.
|
||||
|
Loading…
Reference in New Issue
Block a user