Save Image node doesn't clamp out-of-range color values

Steps causing the bug to occur

[Original title: Bizarre Alpha Behaviour- including saving PNG with Alpha Corrupt]

  1. Make a composition that uses alpha somehow
  2. Simplest way is to use make radial gradient image and set inside to white and outside to transparent
  3. save image with save image
  4. image is corrupt and horrible
  5. Another related issue is that when using either alpha or any other channel in ShaderToy OR GLSL as a knockout channel, (such as: fragColor = vec4(image.rgb, alpha.a) then the output is horrible.

Have you found a workaround?

No.

Other notes

  • Vuo version: 1.2.1
  • macOS version: OS X 10.9
  • How severely does this bug affect you? Not much; I’m just letting you know about it.

Discovered that Vuo uses premultiplied alpha. Can we get this written up somewhere? (updated severity to match my fix)

Alpha_Issue.zip (666 KB)

Screen Shot 2016-03-04 at 1.43.29 am.jpg

Just to confirm I can get ProRes 4444 (with alpha into Vuo) and it composites beautifully. However I have yet to find a method that allows combining custom alpha channels within Vuo itself. Is this a feature request? I don’t understand why ProRes 4444 would have its alpha respected- but a shader wouldn’t?

Also tested with make linear gradient and setting one level to transparent. Same issue.
alphaTest.png

I also tried with TIFF and it was even more horrid. (screenshot as PNG because Vuo doesn’t like TIFF)
Screen Shot 2016-03-04 at 2.55.13 am.png

UPDATE: fixed my original issue (in respect to replacing alpha from another source). Turns out I was expecting non-pre-multiplied output alpha in Vuo. I changed ShaderToy:

Correct: (premultiplied output)

void main(void)
{
vec2 uv = (gl_FragCoord.xy/iResolution.xy);
vec4 alpha = texture2D(iChannel0, uv);
vec4 image = texture2D(iChannel1, uv);
gl_FragColor = vec4(image.rgb, 1.0)*alpha.a ;
}

Incorrect: (assuming non-premultiplied output)

void main(void)
{
vec2 uv = (gl_FragCoord.xy/iResolution.xy);
vec4 alpha = texture2D(iChannel0, uv);
vec4 image = texture2D(iChannel1, uv);
gl_FragColor = vec4(image.rgb, alpha.a);
}

Still issue with exporting PNG

Sure, we can add info about premultiplied alpha to the docs for Make Image with Shadertoy, the VuoShader type, and Ability to edit GLSL shader code in Vuo Editor.

Besides the lack of documentation, another problem is that, if you use Save Image on a 16bpc image with color values greater than 1 (which would happen if you fail to premultiply), it outputs unexpected colors for those pixels (it wraps them rather than clamping them). I’ve retitled this bug report accordingly.

@alexmitchellmus, in your screenshot, there’s a file called “saved_image.png” open in Preview. Would you mind posting the composition that outputs that image? Wondering how to reproduce it.

1 Like

I will update this post with comp, but before I forget - does Vuo use both non-premultiplied and premultiplied alpha modes? Because if I create a gradient with an alpha it has an alpha channel- same to if I use a ProRes4444 with alpha. But once I process it there is no longer any image.a associated with the pipeline. (Only image.rgb)

This is the image I am wanting to generate (as the example for the bug)

As promised here is the comp. Its exactly what you said, simply output a 16bpc image with alpha to png.

EDIT: Just noticed that the image is different in this screenshot compared to the first. I am using a different GPU - so probably renders incorrectly differently.

alphaissue.vuo (1.95 KB)

If this is going to be fixed, (apart from allowing us to render non-pre-multiplied to PNG) possibly it would be better to not change functionality at all, and simply allow us to see what is the color mode of the output? Such as RGBA / RGB / 8bpc / 16bpc. (in future this may expand to 32 bit, and other color spaces, e.g: HSI, HSL, HSV, Lab, XYZ, YCbCr, YUV)

Here is a comp I made which renders it correctly and the resulting PNG by using pre-multiplying in ShaderToy.

Its a very boring white PNG output (but if you put it into something that is alpha aware its transparent- use Preview or PhotoShop - or even Vuo!)

Sorry in advance for double posting: https://community.vuo.org/t/-/5429/4 however thats a feature request which happened before I learned about what “this” issue really was. (and I am not sure if its a request or a bug anyway)

alphaissue_fix.vuo (2.63 KB)

Screen Shot 2016-03-04 at 4.32.03 pm.jpg

does Vuo use both non-premultiplied and premultiplied alpha modes?

Vuo uses/expects premultiplied alpha throughout the pipeline.

@jstrecker Vuo “expects” pre multiplied alpha- but would I be correct in saying that some nodes can “output” unpremultiplied RGBA?

@alexmitchellmus, actually you are correct, but that’s a bug. See my comment on “Ability to split and combine alpha channel” for more info.

Actually @jstrecker I think that even when I pre-mult (as above) there are strange things going on with save as PNG. Nothing to do with alpha or pre-multiplied values, so I think you must be onto something with the ‘out of range’ values.

Fixed in Vuo 1.2.2.

New docs about premultiplication: http://api.vuo.org/1.2.2/group__WorkingWithGraphics.html