Wrong alpha color used in Image resizing

Godot Version

v3.6.stable.official [de2f0f147]
v4.4.stable.official [4c311cbee]

Question

When I resize an Image object with alpha channel, there are artifact colors being introduced along the border of the image. These do not seem to match the clear_color defined in the project. Looks like it’s using black instead.

I reproduced the same behavior on Godot 3.6 and 4.4.I understand that color information needs to be interpolated but for pixels with alpha and no color information there should either be no RGB information used OR at least allow us to select a color to use as a fill-in placeholder. This happens with both INTERPOLATE_LANCZOS and INTERPOLATE_CUBIC
Godot 3 code:

func _ready():
	draw_hexagon()
	yield(VisualServer, "frame_post_draw")
	var buf := $ViewportContainer/Viewport.get_texture().get_data() as Image
	#buf.convert(Image.FORMAT_RGBA8)
	buf.save_png("res://assets/resources/base-tile-mask-double.png")
	buf.resize(256,256, Image.INTERPOLATE_LANCZOS)
	buf.save_png("res://assets/resources/base-tile-mask-double-half.png")

Godot 4 code:


func _ready():
	draw_hexagon()
	await RenderingServer.frame_post_draw 
	var buf := $SubViewportContainer/SubViewport.get_texture().get_image() as Image
	#buf.convert(Image.FORMAT_RGBA8)
	buf.save_png("res://2dtest/base-tile-mask-double.png")
	buf.resize(256,256, Image.INTERPOLATE_LANCZOS)
	buf.save_png("res://2dtest/base-tile-mask-double-half.png")

Notice the gray outline on the smaller hexagon:



What’s the background color in the image itself? PNG stores full color values for each pixel, including pixels that are completely transparent.

I have in the past (though not on Godot, admittedly) run into cases where the texture mag filter has wound up pulling in the color channels from completely transparent texels. That can lead to results like you see here.

Edit: My guess would be your image has black in the alpha’d away areas. If you make it so the entire image is white and just varies in alpha, it might fix this.

I am aware of how PNG file format works. The original image is not a PNG.
Please notice in the code, this image was not generated with a black background outside of Godot. The image was grabbed from a viewport.
It is an OpenGL texture format GL_RGBA32F where there are four components, each a 16-bit “half-precision” floating-point value. (FORMAT_RGBAH = 15)

Looks like it is the case that the image has a black bacground (or Godot assumes those transparent pixels are black). Black is not set as the clear color in Godot. I also tried setting an environment background color in the viewport and neither worked. That black is coming from somewhere else.

I opened a bug report against Godot. Resizing RGBA images should not use RGB pixel information for pixels without an RGB color. · Issue #12006 · godotengine/godot-proposals · GitHub

Fair enough; my point was more about the potential for color channels behind transparent alpha values causing scaling artifacts, I admit I kind of wandered into the weeds about what tool you used to generate it.