PNG 8bit and 16bit loads differently in compositor #102484

Open
opened 2022-11-13 22:43:33 +01:00 by Michael Soluyanov · 10 comments

System Information
Operating system: Linux-5.15.0-52-generic-x86_64-with-glibc2.35 64 Bits
Graphics card: NVIDIA GeForce GTX 1070/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 470.141.03

Blender Version
Broken: version: 3.3.0, branch: master, commit date: 2022-09-06 15:39, hash: 0759f671ce
version: 3.5.0 Alpha, branch: master, commit date: 2022-11-13 20:19, hash: dc513a0af8c0
Since 2.92

Short description of error
I've saved one render in EXR PNG and PNG16.

EXR is good for image compositing, so that we know that it has pre-multiplied alpha. If we load it into compositor, it shows correct results, and we can note that alpha setting in image node is premultiplied by default.

image.png

But we can say what image is straight, so that Blender multiply RGB channels by alpha:

image.png

PNG16 we know has straight alpha. Blender indicates that and set alpha setting to straight by default. So that we lost glowing effect, as expected.

image.png

We can force image to be pre-multiplied by switching the setting. And in this case we can see the white border around cubes as an artifact of, shall we say, "de-premultiplication" as expected:

image.png

Now load PNG8. It loads as premultiplied even alpha setting is straight by default:

image.png

So we know that PNG8 has straight alpha. And Blender shows it as straight alpha correctly. But what is incorrect, the image itself. In fact, Blender makes "de-premultiplication" under the hood and PNG8 with alpha set to straight displays as pre-multiplied. And we can be convinced of that by changing alpha to premultiplied revealing double "de-premultiplication" (One from loading image and one because of PNG specification) or double dividing original pixels by alpha:

image.png

So in order to get correct representation of PNG8 we need to add additional alpha convert step:

image.png

So looks like this hidden "de-premultiplication" process is made for image texturing (see: https://developer.blender.org/T99701). I don't know that's happening under the hood, but it looks like that in texturing PNG's functions as straight, even then the whole "pipeline" uses pre-multiplied. So somewhere in the past someone decided to make PNG8 for texturing and PNG16 for compositing by doing this weird thing under the hood, and making this headache for future us, so that we struggle with different PNG's in one application.

Exact steps for others to reproduce the error
Images for testing:

test.png

test16.png

test.exr

**System Information** Operating system: Linux-5.15.0-52-generic-x86_64-with-glibc2.35 64 Bits Graphics card: NVIDIA GeForce GTX 1070/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 470.141.03 **Blender Version** Broken: version: 3.3.0, branch: master, commit date: 2022-09-06 15:39, hash: `0759f671ce` version: 3.5.0 Alpha, branch: master, commit date: 2022-11-13 20:19, hash: `dc513a0af8c0` Since 2.92 **Short description of error** I've saved one render in EXR PNG and PNG16. EXR is good for image compositing, so that we know that it has pre-multiplied alpha. If we load it into compositor, it shows correct results, and we can note that alpha setting in image node is premultiplied by default. ![image.png](https://archive.blender.org/developer/F13859779/image.png) But we can say what image is straight, so that Blender multiply RGB channels by alpha: ![image.png](https://archive.blender.org/developer/F13859783/image.png) PNG16 we know has straight alpha. Blender indicates that and set alpha setting to straight by default. So that we lost glowing effect, as expected. ![image.png](https://archive.blender.org/developer/F13859793/image.png) We can force image to be pre-multiplied by switching the setting. And in this case we can see the white border around cubes as an artifact of, shall we say, "de-premultiplication" as expected: ![image.png](https://archive.blender.org/developer/F13859799/image.png) Now load PNG8. It loads as premultiplied even alpha setting is straight by default: ![image.png](https://archive.blender.org/developer/F13859807/image.png) So we know that PNG8 has straight alpha. And Blender shows it as straight alpha correctly. But what is incorrect, the image itself. In fact, Blender makes "de-premultiplication" under the hood and PNG8 with alpha set to straight displays as pre-multiplied. And we can be convinced of that by changing alpha to premultiplied revealing double "de-premultiplication" (One from loading image and one because of PNG specification) or double dividing original pixels by alpha: ![image.png](https://archive.blender.org/developer/F13859822/image.png) So in order to get correct representation of PNG8 we need to add additional alpha convert step: ![image.png](https://archive.blender.org/developer/F13859826/image.png) So looks like this hidden "de-premultiplication" process is made for image texturing (see: https://developer.blender.org/T99701). I don't know that's happening under the hood, but it looks like that in texturing PNG's functions as straight, even then the whole "pipeline" uses pre-multiplied. So somewhere in the past someone decided to make PNG8 for texturing and PNG16 for compositing by doing this weird thing under the hood, and making this headache for future us, so that we struggle with different PNG's in one application. **Exact steps for others to reproduce the error** Images for testing: ![test.png](https://archive.blender.org/developer/F13859844/test.png) ![test16.png](https://archive.blender.org/developer/F13859845/test16.png) ![test.exr](https://archive.blender.org/developer/F13859842/test.exr)
Author
Member

Added subscriber: @crantisz

Added subscriber: @crantisz
Member

Added subscriber: @EAW

Added subscriber: @EAW
Member

I can confirm. It appears that 8bit png images have been displayed in the compositor backdrop without the straight to premultiplied conversion since 2.92.
2.91.2 displayed correctly in the compositor backdrop, but then displayed incorrectly in the image editor when viewed through the viewer node.

2.90.1
#99701 2.90.1.png
2.91.2
#99701 2.91.2.png
2.92.0
#99701 2.92.0.png

I can confirm. It appears that 8bit png images have been displayed in the compositor backdrop without the straight to premultiplied conversion since 2.92. 2.91.2 displayed correctly in the compositor backdrop, but then displayed incorrectly in the image editor when viewed through the viewer node. 2.90.1 ![#99701 2.90.1.png](https://archive.blender.org/developer/F13909315/T99701_2.90.1.png) 2.91.2 ![#99701 2.91.2.png](https://archive.blender.org/developer/F13909317/T99701_2.91.2.png) 2.92.0 ![#99701 2.92.0.png](https://archive.blender.org/developer/F13909318/T99701_2.92.0.png)
Member

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'
Member

Added subscriber: @Jeroen-Bakker

Added subscriber: @Jeroen-Bakker
Member

I think there are multiple level of color mess going on here. Seems like the compositor input image node doesn't apply the correct alpha association here. IMO when input image is straight the alpha should be used as a mask and the glow should be masked out.

The viewer and results seems to be correct in that case as the input colors have not been mask and are therefore part of the working color space of the compositor. In 2.92 the backdrop is able to show the pure emissive colors and therefore and wasn't able to show them at all in 2.91 and older versions. In 2.90 the pure emissive colors were introduced in the image editor.

Perhaps the introduction of pure emissive colors shows an error that already existed in blender before, but wasn't able to show it to the user.

Tagging the Compositing module as I believe the error is there.

I think there are multiple level of color mess going on here. Seems like the compositor input image node doesn't apply the correct alpha association here. IMO when input image is straight the alpha should be used as a mask and the glow should be masked out. The viewer and results seems to be correct in that case as the input colors have not been mask and are therefore part of the working color space of the compositor. In 2.92 the backdrop is able to show the pure emissive colors and therefore and wasn't able to show them at all in 2.91 and older versions. In 2.90 the pure emissive colors were introduced in the image editor. Perhaps the introduction of pure emissive colors shows an error that already existed in blender before, but wasn't able to show it to the user. Tagging the Compositing module as I believe the error is there.

Added subscriber: @Sergey

Added subscriber: @Sergey

There is also seems to be missing conversion of alpha association in the PNG reader for the 16bit code path. The internal floating point buffer is expected to be premultiplied. A deeper look is needed.

There is also seems to be missing conversion of alpha association in the PNG reader for the 16bit code path. The internal floating point buffer is expected to be premultiplied. A deeper look is needed.
Bastien Montagne added this to the Core project 2023-02-09 15:42:54 +01:00
Bastien Montagne removed this from the Core project 2023-02-09 18:20:29 +01:00
Philipp Oeser removed the
Interest
VFX & Video
label 2023-02-10 09:31:28 +01:00

The PNG reader seems to be correct now.

So the remaining aspect is that the Image operation only performs color space conversion, but not alpha association conversion.

The PNG reader seems to be correct now. So the remaining aspect is that the Image operation only performs color space conversion, but not alpha association conversion.
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
5 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#102484
No description provided.