Page MenuHome

TexPaint artefacts after projecting image with alpha
Closed, InvalidPublic


System Information
win7 64

Blender Version
Broken: 2.76 8c84a18

Short description of error
in some cases projected images with alpha cause white lines on borders

Exact steps for others to reproduce the error
open attached .blend
apply image from camera



Event Timeline

item412 (item412) added a project: BF Blender.
item412 (item412) set Type to Bug.
item412 (item412) created this task.
item412 (item412) raised the priority of this task from to Needs Triage by Developer.
Sergey Sharybin (sergey) triaged this task as Confirmed, Medium priority.

Seems like blend function does not take care alpha mode (premul vs. straight) correctly into account.

@Campbell Barton (campbellbarton), @Antony Riakiotakis (psy-fi), will one of you have time to look into this area?

Bastien Montagne (mont29) closed this task as Invalid.
Bastien Montagne (mont29) claimed this task.

Meh… Took me two hours to discover the issue is related to how that picture (12.png) is created, being straight alpha, and how bicubic interpolation works!

Basically, when interpolating points that are just on the edge, we get a mix of 0.0 and 0.5 alpha, and a mix of white and green colors, which gives us a rather transparent whitish green, which is correct result from code point of view.

You get exact same result if you e.g. scale that image in compositor.

So no real bug here, it's just some oddly-colored image and resize algo tricks… Just fill it with green everywhere and you'll be OK!

For the records, the 'solution' to fix would be to convert to premultiplied before doing bicubic interpolation, here is a 'totally not for master) quick and dirty hack:

diff --git a/source/blender/blenlib/intern/math_interp.c b/source/blender/blenlib/intern/math_interp.c
index b45d8b4..a628b3b 100644
--- a/source/blender/blenlib/intern/math_interp.c
+++ b/source/blender/blenlib/intern/math_interp.c
@@ -94,10 +94,7 @@ static void vector_from_byte(const unsigned char *data, float vector[4], int com
                vector[2] = data[2];
        else {
-               vector[0] = data[0];
-               vector[1] = data[1];
-               vector[2] = data[2];
-               vector[3] = data[3];
+               straight_uchar_to_premul_float(vector, data);
@@ -239,10 +236,7 @@ BLI_INLINE void bicubic_interpolation(const unsigned char *byte_buffer, const fl
                        byte_output[2] = (unsigned char)(out[2] + 0.5f);
                else {
-                       byte_output[0] = (unsigned char)(out[0] + 0.5f);
-                       byte_output[1] = (unsigned char)(out[1] + 0.5f);
-                       byte_output[2] = (unsigned char)(out[2] + 0.5f);
-                       byte_output[3] = (unsigned char)(out[3] + 0.5f);
+                       premul_float_to_straight_uchar(byte_output, out);

But I really do not think we want to do this? This is not 'lossless' conversion at all.