Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential issue with setting and getting colours #14

Open
sciguyryan opened this issue May 7, 2019 · 4 comments
Open

Potential issue with setting and getting colours #14

sciguyryan opened this issue May 7, 2019 · 4 comments

Comments

@sciguyryan
Copy link

sciguyryan commented May 7, 2019

Hi there.

I've been unable to track down the source of this issue. It may or may not be within the FastBitmap system or not.

I have tested a few of them and they all give the same result.

Basically I encode a pixel onto a bitmap via the SetPixel method call. Retrieving the colour via the GetPixel appears to give a different result than I would have expected:

[----------------------------(19, (1572, 480))----------------------------]
Before (1)             = Color [A=255, R=128, G=128, B=128]
After (1)                = Color [A=255, R=128, G=129, B=127]
(x, y) = (1572,480)
After (1, written)   = Color [A=255, R=128, G=129, B=127]

Before (2)              = Color [A=255, R=128, G=128, B=128]
After (2)                 = Color [A=255, R=128, G=129, B=129]
(x, y) = (1573,480)
After (2, written)   = Color [A=255, R=128, G=129, B=129]
19 = 00011111

[----------------------------(19, (1572, 480))----------------------------]
Colour (1) Original   = Color [A=255, R=128, G=128, B=128]
Colour (1) Modified = Color [A=255, R=128, G=130, B=128]

Colour (2) Original   = Color [A=255, R=128, G=128, B=128]
Colour (2) Modified = Color [A=255, R=127, G=128, B=129]
19 = 00200101

It's a bit hard to follow but the colours on lines 'After (1, written)' and 'Colour (1) Modified' should match, as should the colours on lines 'After (2, written)' and 'Colour (2) Modified'.

As far as I can tell there isn't anything that can intrinsically go wrong here, so I'm at a loss for what could be causing this issue to appear.

If you've got any ideas, I'd love to hear them!

Cheers.

@LuizZak
Copy link
Owner

LuizZak commented May 7, 2019

Hmm this may be an issue with the way colors are encoded and decoded via System.Drawing.Color. Any chance of trying to encode and decode these pixels as UInt instead and checking that they match? I'll try to build a repro case for this when I get home, maybe I can track this down.

@sciguyryan
Copy link
Author

sciguyryan commented May 8, 2019

Hi Luiz.

Thanks for getting back to me. I swapped the calls out for |bitmap.SetPixel((uint)colour.ToArgb())| and the results appear to be the same.

Then I also swapped out the calls for to GetPixel to |original.GetPixelUInt(original.X, original.Y);| and then converted this result back to a Color object. That appears to give the expected results, but not universally.

After running the system through several iterations, it still appears as though a variance is getting through.

@sciguyryan
Copy link
Author

I've got my working code set up on GitHub, currently as a private repo. If you'd like I'll see if I can add you to it so you can see exactly what I'm doing since it's going to be quite difficult to unpick this via the log entries alone.

I'm wondering if it's something wacky like gamma correction. If it is I've got no idea how to test for that, let alone fix it.

@sciguyryan
Copy link
Author

After doing even more testing on this, the value as written to the pixel doesn't appear to match, what is said to have been written.

According to Paint.net the value written to the pixel is 255, 128, 130, 127 (ARGB) but the value should have been 255, 128, 129, 127 (ARGB) as passed to the function. This is one of the strangest issues I've ever come across as I can find no reason for this to happen, at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants