From 6b1af0a943e668637a7853d93ee3671ad6692ef8 Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Wed, 3 Apr 2019 15:49:51 +0200 Subject: [PATCH] Fix transparency bug --- assets/textures/grass.png | Bin 0 -> 2970 bytes build.rs | 25 +++++++++++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) create mode 100644 assets/textures/grass.png diff --git a/assets/textures/grass.png b/assets/textures/grass.png new file mode 100644 index 0000000000000000000000000000000000000000..6dfc320d9e3da32ef8fd41b4c9ebbc572b3e00c5 GIT binary patch literal 2970 zcmV;L3uW|)P) zaB^>EX>4U6ba`-PAZ2)IW&i+q+O3yslI1E6g#WXOSpqL1SPmc*F*}&$&xen@`fez)bkIYm`4(C7r_V6!`oN^CUw71b(j@xC|f z58HYFmc4EAx%~QnRlqP|yplscC6&l;zq1rpP)3+{RRvLb`L^7t|)!G%|AaVGiv+a{XyIC7ZweW5# zzC%2BbX-9BL8Eahf5N>!=iuyYal@Fw=HlETjg&##Q%#m;@^qf-PMamxe6n)QdFS%9 z^`d#?{g6`cnLI1>SSTH?Hmntz^VeF^Gw*oj+o?0NC3@z>V2L;Wa)#eE{x9d(K<-z% zDP1t3K79zzSJN!xGIxLJ1tG~_Oy$A%Il~vN-;YadfkAm-?rd2Qt9KthzgT-&{h77&3v++ZT6$T#jMb-~ zerJtl)o(+jYbSC!gRxu_jO%3pLFda^?5Wm#nY*0DkqHXPu$JVKW9c#mgY~2=p1!#I z&fMSf7Nq_o-twQA3zxe82Xo<4_cHfa-hRWH%_pOjhoBpU7t>fAV>>eI>N(?Fz07pf z&fFqpt)<#VtSgONeMS~3Uh1wq=*>^wqI;HpSDwOgIX;urY}SXT(O|)JiSS-~rpreQ zgXiAPE|nNlUv^d<7eO4cOW7+#(PY(it~Ld7szo%Pwki8vI@>tbchkKc^Dqb~T;Ws2 z#;Kjr*vwp*zx5+}nxqkRDLATaD{Hszr&WPD7KR~fxZ!wI! zpT3zib{F<3(WD&!J}A*7m(|U3R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^r!U+m8^c5D;6#yg@AQz!tPPMxNfWd^ID#Ubo zI$jUK0npI{s<2U?--V_aV!gTsz=sx~&2yO&?k>SWd;oX|&^K&sBSMG|fR-VsV*2Tb zD+EAa0+hU!Btqo$0Eok#6gKiuR8P1=d>}53aYOPDHsqG3xf?Ir-VgPiH{xY&z_EQ7 zb+w%g#{=r(n9ojLizm{ejdUJQXTXaBiNSssRN9E!MSRlnHv0qt#K+5n3_$?^83pJQ zB8KGm5P|~EpuY>+b(K>Wq3LUBSV09{L^vn`#t?_iBSLt RgbaImage { @@ -20,12 +20,15 @@ fn superpose(image: &RgbaImage, superposition: &RgbaImage) -> RgbaImage { fn main() { create_dir_all("assets/textures-generated").unwrap(); - let background = image::open("assets/textures/grass/background.png").unwrap().to_rgba(); - let border = image::open("assets/textures/grass/border.png").unwrap().to_rgba(); - let corner_horiz = image::open("assets/textures/grass/corner-horiz.png").unwrap().to_rgba(); - let corner_vert = image::open("assets/textures/grass/corner-vert.png").unwrap().to_rgba(); - let corner_inside = image::open("assets/textures/grass/corner-inside.png").unwrap().to_rgba(); - let corner_outside = image::open("assets/textures/grass/corner-outside.png").unwrap().to_rgba(); + let mut texture = image::open("assets/textures/grass.png").unwrap().to_rgba(); + let background = texture.sub_image(0, 0, 32, 32).to_image(); + let border = texture.sub_image(32, 0, 32, 32).to_image(); + let corner_horiz = texture.sub_image(32 * 2 , 0, 32, 32).to_image(); + let corner_vert = texture.sub_image(32 * 3, 0, 32, 32).to_image(); + let corner_inside = texture.sub_image(32 * 4, 0, 32, 32).to_image(); + let corner_outside = texture.sub_image(32 * 5, 0, 32, 32).to_image(); + let mut background_color = texture.sub_image(32 * 6, 0, 32, 32); + let background_color = background_color.get_pixel_mut(0, 0); let mut vec = vec![]; @@ -181,10 +184,12 @@ fn main() { for (index, image) in vec.into_iter().enumerate() { for y in 0 .. image.width() { for x in 0 .. image.height() { - *output.get_pixel_mut(x + 32 * index as u32, y) = *background.get_pixel(x, y); let new_pixel = image.get_pixel(x, y); - if new_pixel[3] > 0 { - *output.get_pixel_mut(x + 32 * index as u32, y) = *new_pixel; + if new_pixel != background_color { + *output.get_pixel_mut(x + 32 * index as u32, y) = *background.get_pixel(x, y); + if new_pixel[3] > 0 { + *output.get_pixel_mut(x + 32 * index as u32, y) = *new_pixel; + } } } }