Picking Web RGB

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
919
This evening I've been trying to find out what makes the RGB values are so inaccurate, and quiet a bit sometimes and I've come to the conclusion that this is no simple rounding errors. I've also tried to load both premultiplied and non-premultiplied pictures but as this image has no alpha it didn't make any difference whatsoever.

Trying to come up with what it could be, I went through the chain which was the matte standard shader to see if there's any gamma correction or something similar going on. Nothing.

Now I'm kind of stuck why Cerberus gives me these strange numbers? If you plot anything yourself there's absolutely never any problems in reading every bit correctly. But it can't handle anything that have been loaded?

Looking at the testchart..
000000 becomes 00000, fcfcfc becomes fcfcfc which is fine of course
but then we have 7070fc that shows up as 7f58ff
and 208800 as 009107 etc


Screenshot 2021-08-05 at 01.47.21.png


Screenshot 2021-08-05 at 02.01.03.png
 

Attachments

  • Webpicker.zip
    72.5 KB · Views: 18
Last edited:

Phil7

Administrator
CX Code Contributor
3rd Party Tool Dev
Joined
Jun 26, 2017
Messages
643
Did you check your web.png, if all the values are correct? If I open the image inside Firefox, the color I get from the colorpicker doesn't match the numbers.
 

MikeHart

Administrator
Joined
Jun 19, 2017
Messages
3,167
Did you check your web.png, if all the values are correct? If I open the image inside Firefox, the color I get from the colorpicker doesn't match the numbers.
Correct, loading that image into a graphic app gives me different hex values from what is listed in it.
 

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
919
Look how off they are in Cerberus.

In Browsers they are just minor rounding errors. I've noticed that and those rounding-errors are expected.
 

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
919
What I've found can be the issue so far is :

* You can read many people had this problem and it turned out that the GPU wanted commands to be sent to GPU before & after reading of pixels. But these commands are GLES3-only, not a problem with GLES2 I think. I had lots of hope on this one.

* Pre-multiply at load? No nothing like that. Also I avoid alpha so it shouldn't be an issue.

* Shader might process something e.g. gamma? I couldn't get it right, maybe I will try again I see even the matte shader does a lot of things but then again, why do the RGB works perfectly when it is not loaded?

* Datatype (sizes & unsigned/signed issue)? Toughie..

* The issue of /255 vs /256.0 and bit shifting? Maybe a huge step of 32 (which is what you see sometimes) along with 16 8 4 2.1..0 errors can happen depending on the shift and component..


I might've missed checking all of these throughly.. Need to do it again.
 
Last edited:

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
919
I did a sanity check, converting 0-255 into 0.0-1.0 and back to 0-255

Using all the different ways that I could come up with right now.
2 of the 4 ways are perfect.

You can have a picture and read it absolutely perfect what byte it contains.
If you compare only in the realm of bytes (with the included rounding) and never in the realm of floats, you're good.

And I can assure this is also how you can handle readpixels, as long as you don't load the picture it will never fail. It will also give byte-perfect consistent values on all platforms and devices.

So loading a picture in Cerberus creates a mystery.. I'm sure I've missed some stupid little detail.

Code:
        For Local temp:Int = 0 To 255
            Local test:Float = temp/255.0
    '        If Int((test*256.0)) <> temp Then Print "not same" ' 1 wrong
    '        If Floor((test*256.0)) <> temp  Then Print "not same" ' 1 wrong
    '        If Int((test*255.0)) <> temp  Then Print "not same"  ' all 256 value correspond perfectly when converted back to 0-255
    '        If Floor((test*255.0)) <> temp  Then Print "not same" ' all 256 value correspond perfectly when converted back to 0-255
        Next
 
Last edited:

MikeHart

Administrator
Joined
Jun 19, 2017
Messages
3,167
Jimmy, with all respect. But Philipp and I told you that the values you printed on the image are not the values of the colors. And you still insist that it is a problem with cerberus .

Come back with a simple color correct example that is wrong, THEN I might take a look into this.

Reading pixel from a canvas was discussed to death in several topics and noone saw a problem there. So I dare to say, CX works fine, your code is wrong.
 

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
919
Of course, I tested it before I posted and it was spot on with the pickers I used. I used browsers and I used photoshop. I re-saved it a couple of times so that might screw the picture up. I assumed no alpha means no screwup but I can't say no to this..

I'll find a better example before this weekend. But the values are way off even on this example so it will nag the back of my head until then.. My code might be wrong of course. That's what I'm hoping for. But the fact it works 100% when not loading a picture makes me confused. It's some kind of double..

I know how stable Cerberus is when it comes to reading pixels It never got one bit wrong and it behaves the same on all platforms.
 

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
919
I know for sure for instance, that if i make and save a palette picture as a custom format and "draw it using 1x1 rectangles), and load it (from a textfile for instance,and do it manually). It will give perfect result.

But that is not much help to solve the cause of this.
 

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
919
You were right, it was the picture. I'm amazed how it could be +-20h error.
I must've done something when I saved it again in photoshop.

This one works perfectly.
Everything's good :)

And might I add, it's working perfectly.

(their black is $020408 not $000000 like they say)

palette.png
 
Last edited:

Holzchopf

Moderator
3rd Party Module Dev
Tutorial Author
Joined
Jul 31, 2017
Messages
496
I must've done something when I saved it again in photoshop.

Getting perfect color values out of Photoshop can be tricky, due to color profiles. I think it somehow always applies some sort of color "correction" even when you tell it not to (work on a document without color profile). Make a gradient from black to white, copy it to any other image software, copy it back from there to Photoshop... The colors will have shifted a tiny bit. If not, please tell me how you did it.
 

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
919
Getting perfect color values out of Photoshop can be tricky, due to color profiles. I think it somehow always applies some sort of color "correction" even when you tell it not to (work on a document without color profile). Make a gradient from black to white, copy it to any other image software, copy it back from there to Photoshop... The colors will have shifted a tiny bit. If not, please tell me how you did it.
I'm not sure yet but I think I can do it perfectly, I hope I don't have to eat my words so I won't promise anything I will check this up on a few devices and also what techniques I've tried so far before I answer.
 

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
919
One reason why many people experience not being able to read perfect RGBA is the fact you need to shut of dithering in many GPU's before they will behave as you would expect.

In Cerberus, this is super-easy. You add this one line in mojo2's graphics.cxs and you're done!

whypixelsarereadbackwrong.png
 
Top Bottom