From 698c0d9dda3d218e8569da2433c3315d95d19226 Mon Sep 17 00:00:00 2001 From: Thinkofname Date: Thu, 7 Apr 2016 20:39:48 +0100 Subject: [PATCH] Support old style skins --- src/render/mod.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/render/mod.rs b/src/render/mod.rs index b296619..818609d 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -869,13 +869,41 @@ impl TextureManager { let mut file = fs::File::create(cache_path).unwrap(); file.write_all(&buf).unwrap(); } - let img = match image::load_from_memory(&buf) { + let mut img = match image::load_from_memory(&buf) { Ok(val) => val, Err(_) => { reply.send((hash, None)).unwrap(); continue; } }; + let (_, height) = img.dimensions(); + if height == 32 { + // Needs changing to the new format + let mut new = image::DynamicImage::new_rgba8(64, 64); + new.copy_from(&img, 0, 0); + new.copy_from(&img.sub_image(0, 16, 16, 16), 16, 48); + new.copy_from(&img.sub_image(40, 16, 16, 16), 32, 48); + img = new; + } + // Block transparent pixels in blacklisted areas + let blacklist = [ + // X, Y, W, H + (0, 0, 32, 16), + (16, 16, 24, 16), + (0, 16, 16, 16), + (16, 48, 16, 16), + (32, 48, 16, 16), + (40, 16, 16, 16), + ]; + for bl in blacklist.into_iter() { + for x in bl.0 .. (bl.0 + bl.2) { + for y in bl.1 .. (bl.1 + bl.3) { + let mut col = img.get_pixel(x, y); + col.data[3] = 255; + img.put_pixel(x, y, col); + } + } + } reply.send((hash, Some(img))).unwrap(); } }