bootchk / resynthesizer

Suite of gimp plugins for texture synthesis
GNU General Public License v3.0
1.43k stars 163 forks source link

Render Texture from layer with Tranparency Channel #104

Closed imsamuka closed 2 years ago

imsamuka commented 2 years ago

The python_fu_render_texture always fails when creating a texture from a layer with Transparency Channel. It generates a completely transparent image.

bootchk commented 2 years ago

Yes, I confirm this is reproducible on a recent Flatpak Gimp and Flatpak Resynthesizer.

Now I need to study whether there is a test case that previously passed, or just never tested and reported.

Then study why the code behaves like that.

I remember struggling to specify and code how the Resynthesizer should handle transparency. It certainly is more user friendly if it handles transparency without extra steps. Without the workaround of first deleting the alpha channel.

I suppose it is a valid use case though.

bootchk commented 2 years ago

Thanks for reporting.

I fixed it and added a test case. Apparently I never tested the case.

I agree that the issue is a defect. However, it is easy to work around: just remove the alpha channel from the output (the color channels are correct.)

Existing users probably won't want to reinstall just to get this bug fix. Instead of a complete reinstall, you can just copy the fixed Python plugin "plugin-render-texture.py" to the proper place.

Note that the resynthesizer engine does not synthesize the alpha channel, in the sense that it constructs new alpha values by searching. The alpha channel of the output image (the target) is the same after the engine runs. In this case, the target is a new image first created by a plugin that erroneously created all pixels transparent. Then the resynthesizer engine left the alpha channel alone.

If there is a use case for the resynthesizer engine synthesizing the alpha channel, I would be glad to consider implementing it. The very first resynthesizer did treat the alpha channel differently.

The error in the code was that the plugin created the new layer with opacity parameter: 100%. However, that is the opacity of the layer, which is a distinct from the opacity of the pixels. In another words, the new layers had all RGBA channels zero, which is totally transparent. The fix was to fill the new image with white, which also changes each pixel to opaque. Then the engine synthesizes new color channels, leaving the alpha channel all opaque.

imsamuka commented 2 years ago

Thank you very much for the fix, and the detailed explanation