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.vector4rgba = 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;
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).
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?