Get correct color values from .png in VEX with rawcolormap()

   2733   3   1
User Avatar
Member
4 posts
Joined: June 2014
Offline
Hi everybody,

I am trying to get un-altered raw color values from a RGBA .png file using the rawcolormap() vex function but it appears that I can only get pre-multiplied color values from .png. When using .tif this does not seem to be a problem. Does anybody know why this is and how to work around the problem?

Here is my VEX code:

// Even though this is not be true for input images in sRGB color space we assume all input images to be 
// in linear color space. This is to prevent Houdini's gamma conversion from sRGB to linear color space 
// so that all color information is an unaltered pass-through.
vector4 rgba = rawcolormap(chs("texture_map"), U, V, "srccolorspace", "linear");

v@Cd.x = rgba.r;
v@Cd.y = rgba.g;
v@Cd.z = rgba.b;
@Alpha = rgba.a;
User Avatar
Member
8238 posts
Joined: Sept. 2011
Offline
Don't png files optionally store the values pre-multiplied?
User Avatar
Member
4 posts
Joined: June 2014
Offline
Thank you for your reply. According to the .png specification it should be standardized to “unassociated” alpha.

“The color values stored for a pixel are not affected by the alpha value assigned to the pixel. This rule is sometimes called ”unassociated“ or ”non-premultiplied" alpha. (Another common technique is to store sample values premultiplied by the alpha fraction; in effect, such an image is already composited against a black background. PNG does not use premultiplied alpha.)

Oddly enough:
Opening the images in mplay also shows premultiplied color valus on pixel inspection while opening images in other applications I have tested (Photoshop, Gimp) show unpremultiplied values. Also, on top of the premultiplication, the color values shown in mplay I can only replicate by assuming the sRGB input image with a gamma of 2.2 is in linear color space and then applying a gamma conversion to sRGB again (twice).
Edited by off_by_one - Feb. 19, 2020 10:03:59

Attachments:
unpremultplied_png_houdini.png (102.5 KB)

User Avatar
Member
4 posts
Joined: June 2014
Offline
After some further testing I am still struggling with this. I have found a workaround by first loading the texture in a cop network with the file cop which has a “leave unpremultiplied” option and then referencing the file cop as texture in the attrib wrangle.

Is there no such option available in VEX to avoid the detour through a cop network?

Also with a function named “rawcolormap” would the expectation not be to receive unpremultiplied values by default as it is less destructive?

Thanks

Attachments:
file_unpremultiplied.png (64.2 KB)

  • Quick Links