summaryrefslogtreecommitdiff
path: root/ui/bmp_texture.gd
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2025-01-14 14:38:52 +0100
committerDaniel Weipert <git@mail.dweipert.de>2025-01-14 14:38:52 +0100
commite8f03c4d6a94aa16b3587bdce525cf0cf7c6c6c3 (patch)
treed8d5a78a0872b86c3b40089e465120883669542b /ui/bmp_texture.gd
parentb75cc72c4e10bd652330b6d2bd99f3fd9129a3b3 (diff)
next commit
Diffstat (limited to 'ui/bmp_texture.gd')
-rw-r--r--ui/bmp_texture.gd24
1 files changed, 15 insertions, 9 deletions
diff --git a/ui/bmp_texture.gd b/ui/bmp_texture.gd
index 54bf37b..8a90983 100644
--- a/ui/bmp_texture.gd
+++ b/ui/bmp_texture.gd
@@ -3,17 +3,23 @@ extends ImageTexture
static func from_texture(texture: Texture2D, background_colors: Array[Color]) -> ImageTexture:
- var image: Image = texture.get_image()
- image.convert(Image.FORMAT_RGBA8)
-
- for x in image.get_width():
- for y in image.get_height():
- for color in background_colors:
- if image.get_pixel(x, y).is_equal_approx(color):
- image.set_pixel(x, y, Color.TRANSPARENT)
- break
+ var image: Image = convert_image(texture.get_image(), background_colors)
var image_texture := ImageTexture.new()
image_texture.set_image(image)
return image_texture
+
+
+static func convert_image(image: Image, background_colors: Array[Color]) -> Image:
+ var converted_image := image.duplicate()
+ converted_image.convert(Image.FORMAT_RGBA8)
+
+ for x in converted_image.get_width():
+ for y in converted_image.get_height():
+ for color in background_colors:
+ if converted_image.get_pixel(x, y).is_equal_approx(color):
+ converted_image.set_pixel(x, y, Color.TRANSPARENT)
+ break
+
+ return converted_image