diff --git a/enne2engine/sdl2_wrapper.py b/enne2engine/sdl2_wrapper.py index cf9a2a4..05e1c47 100644 --- a/enne2engine/sdl2_wrapper.py +++ b/enne2engine/sdl2_wrapper.py @@ -70,30 +70,6 @@ class SDL2Wrapper(IsometricGeometry, SDL2Gui): dstrect=(x, y, srcrect[2], srcrect[3]), srcrect=srcrect) return (frame + 1) % total_frames - def make_non_transparent_pixels_black(self, surface): - width = surface.w - height = surface.h - - # Blocca la surface per l'accesso diretto ai pixel - sdl2.SDL_LockSurface(surface) - - # Itera attraverso i pixel e modifica quelli non trasparenti - u32_pixels = ctypes.cast(surface.pixels, ctypes.POINTER(ctypes.c_uint32)) - for y in range(height): - for x in range(width): - pixel = u32_pixels[y * width + x] - if pixel & 0xFF000000 != 0: - u32_pixels[y * width + x] = 0xFF000000 - # Sblocca la surface - sdl2.SDL_UnlockSurface(surface) - - # Crea una nuova texture dalla surface modificata - new_texture = self.factory.from_surface(surface) - - # Libera la surface temporanea - sdl2.SDL_FreeSurface(surface) - - return new_texture def create_background(self, map, spritesheet_name): self.surface_width = round(self.cell_size * len(map[0]) * math.sqrt(2)) diff --git a/fg.png b/fg.png new file mode 100644 index 0000000..42f333f Binary files /dev/null and b/fg.png differ diff --git a/final_image.png b/final_image.png new file mode 100644 index 0000000..71ca6eb Binary files /dev/null and b/final_image.png differ diff --git a/shadow.py b/shadow.py new file mode 100644 index 0000000..f19ad05 --- /dev/null +++ b/shadow.py @@ -0,0 +1,62 @@ +from PIL import ImageOps, Image, ImageFilter + +FG_IMG_PATH = "fg.png" + +BG_IMG_PATH = "bg.jpeg" + +def load_image(path): + + """Load an image using PIL.""" + + return Image.open(path) + +def extract_alpha(image): + + """Extract the alpha channel from an image.""" + + return image.split()[-1] + +def create_shadow_from_alpha(alpha, blur_radius): + + """Create a shadow based on a blurred version of the alpha channel.""" + + alpha_blur = alpha.filter(ImageFilter.BoxBlur(blur_radius)) + + shadow = Image.new(mode="RGB", size=alpha_blur.size) + + shadow.putalpha(alpha_blur) + + return shadow + +def composite_images(fg, shadow): + + """Composite the shadow and foreground onto the background.""" + + shadow.paste(fg, (-5, 4), fg) + + return shadow + +if __name__ == "__main__": + + + # Load the images + + fg = load_image(FG_IMG_PATH) + + # Create the shadow based on the alpha channel of the foreground + + alpha = extract_alpha(fg) + + shadow = create_shadow_from_alpha(alpha, blur_radius=1) + + # Composite the shadow and foreground onto the background + + final_image = composite_images(fg, shadow) + + # Display the final image (optional) + + final_image.show() + + # Save the final image + + final_image.save(f"final_image.png") \ No newline at end of file