TexPaint artefacts after projecting image with alpha #46750

Closed
opened 2015-11-12 16:24:30 +01:00 by item412 · 8 comments

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

757fb4524426fcb5b37e4cd00c3d2eb7.gif

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

projTest.blend

**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 ![757fb4524426fcb5b37e4cd00c3d2eb7.gif](https://archive.blender.org/developer/F254157/757fb4524426fcb5b37e4cd00c3d2eb7.gif) **Exact steps for others to reproduce the error** open attached .blend apply image from camera [projTest.blend](https://archive.blender.org/developer/F254159/projTest.blend)
Author

Changed status to: 'Open'

Changed status to: 'Open'
Author

Added subscriber: @item412

Added subscriber: @item412

Added subscribers: @Psy-Fi, @ideasman42, @Sergey

Added subscribers: @Psy-Fi, @ideasman42, @Sergey

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

@ideasman42, @Psy-Fi, will one of you have time to look into this area?

Seems like blend function does not take care alpha mode (premul vs. straight) correctly into account. @ideasman42, @Psy-Fi, will one of you have time to look into this area?

Added subscriber: @mont29

Added subscriber: @mont29

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'
Bastien Montagne self-assigned this 2016-01-22 15:23:00 +01:00

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!

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.

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.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#46750
No description provided.