Unity.Texture2D.GetPixel from [url]WWW.texture[/url] incorrect color

The attached texture has a solid RED color 192.

When I use WWW.texture to get the pixel color, it’s returning 187.

I’m attaching a test project to illustrate the issue.

Web player:
http://tagenigma.com/qa/Unity3d/BlendCalc001/BlendCalc001.html

  1. Add the URL to the solid 192 texture.
    http://forum.unity3d.com/files/diffusemapalphablendtechnique2_822.png

  2. Click the Check Red button.

An error will report the color violation.

What must I do to get the correct color?

On the chat someone recommended removing the color profile information. I created this image in Gimp and Paint and added no specific color profile. Should I be using a Unity color profile?

The world depends on having the color show as 192 with GetPixel.

Your help is appreciated.


125982–4714–$blendcalc001_199.zip (472 KB)

Is it an uncompressed texture?
There’s colour inaccuracy with any compressed textures.

I assume textures loaded by URL are not compressed. PNG has built-in compression. I’ll post a texture that’s 0 compression and try that…

Unfortunately the same result 187.

I’ll try saving without a background color and 0 compression.

I know these aren’t compressed because if I tried to load a compressed texture into a Unity GUI element, it crashes. And WWW.textures don’t crash the GUI.

Doh 187.

Consistently broken.

Here’s something visually a little more interesting to test with.

I added an alpha channel of 192. You can click the Check Alpha on this one.

126026--4718--$diffusemapalphablendtechnique4_157.png

It looks like the alpha channel is correct. But the red channel is not.

Like the WWW.texture documentation says, gamma correction is performed on PNG files that have gamma setting stored. If you do not want any correction to happen, do not save the PNG file with gamma information.

I am not saving gamma information in my PNG.

The following dialog shows when saving PNG with GIMP.

126157--4720--$nogamma_552.jpg

Here is with gamma:

And here is without gamma:

Both are doing color correction.

126204--4727--$pnggammayes_crushed_209.png
126204--4727--$pnggammayes_crushed_209.png

Both images actually have gamma value set to 0.45455. I think Gimp implicitly attaches some color profile based on some preferences somewhere (whenever I encounter this, I have to google for that to find where). The difference between the images is that one is in sRGB, and another is in Calibrated RGB color spaces (but both have gamma).

IIRC, when loading the images we do apply gamma correction, but do not do color profile conversion. So both images end up loading the same (since they have the same gamma).

If you want us to improve PNG decoding in the future, file a bug with those images and a project that shows the problem, because problem reports on the forums tend to be forgotten.

Okay well if I’m stuck with color correction here’s how you add a gamma of 1.0 to your image using Gimp.

View->Display Filters

(Opens display filter dialog)

Select Gamma from the available filters and click the arrow to add it to your active filters.

When you add the Gamma filter you can also specify the Gamma amount. In my case it needs to be 1.0.

And then when saving the PNG also save the gamma information.

This should be an image with Gamma set to 1.0.

126204--4727--$pnggammayes_crushed_209.png

Aras.

This is still getting color corrected. What are you using to get the gamma information?

According to Gimp the gamma above should be set to 1.0.

Do I need to set the gamma to 0 to have the color corrector ignore it?

Apparently this display filter thing adds gamma value to the PNG header.

Is there a Unity color profile I can apply to my image?

This time I used:
pngcrush.exe -g 1.0 PngGammaYes.png PngGammaYes_Crushed.png

bah

I’m about ready to use Photoshop!!!

126204--4727--$pnggammayes_crushed_209.png

Creating the PNG in Photoshop by default has the right color.

126204--4727--$pnggammayes_crushed_209.png

JPEG from Gimp loads the right color. But it’s not usable since it would add compression marks and doesn’t have an alpha channel.

Here’s a gimp palette that’s pretty useful for painting the right alpha colors so the texture passes the alpha check.

It goes into your C:\Users{username}.gimp-2.6\palettes folder.

Mark the palette as readonly to prevent accidentally modifying it.

126306–4732–$alpha_intensities_783.zip (397 Bytes)

If gimp is not able to export PNG without the gamma information then you don’t have an option.
but given that it supports photoshop 6 plugins, you might want to give superpng a try

I’m going to try the Abobe 1998 color profile:
http://www.adobe.com/digitalimag/adobergb.html

AdobeRGB1998.icc

126346--4739--$test_alpha_icc_106.png