Fix crash in edge case for pixel art.

This commit is contained in:
Joshua Yanovski 2020-07-29 21:10:20 +02:00
parent 56da06f7a3
commit 7e0f4bcbf0

View File

@ -47,7 +47,7 @@ pub fn resize_pixel_art(image: &RgbaImage, new_width: u32, new_height: u32) -> R
for x in 0..new_width { for x in 0..new_width {
// Calculate sampling strategy // Calculate sampling strategy
let xsmin = x as f32 * wratio; let xsmin = x as f32 * wratio;
let xsmax = xsmin + wratio; let xsmax = (xsmin + wratio).min(width as f32);
// Min and max pixels covered // Min and max pixels covered
let xminp = xsmin.floor() as u32; let xminp = xsmin.floor() as u32;
let xmaxp = ((xsmax - EPSILON).ceil() as u32) let xmaxp = ((xsmax - EPSILON).ceil() as u32)
@ -63,7 +63,7 @@ pub fn resize_pixel_art(image: &RgbaImage, new_width: u32, new_height: u32) -> R
for y in 0..new_height { for y in 0..new_height {
// Calculate sampling strategy // Calculate sampling strategy
let ysmin = y as f32 * hratio; let ysmin = y as f32 * hratio;
let ysmax = ysmin + hratio; let ysmax = (ysmin + hratio).min(height as f32);
// Min and max of pixels covered // Min and max of pixels covered
let yminp = ysmin.floor() as u32; let yminp = ysmin.floor() as u32;
let ymaxp = ((ysmax - EPSILON).ceil() as u32) let ymaxp = ((ysmax - EPSILON).ceil() as u32)