Closed xaguzman closed 7 years ago
The reason why you're seeing everything pass is because the alpha channel is 0xff in the pixels you're getting from the image. So, in the case of a black pixel, the the value of pixel would be 0xff000000. In your test, you're shifting pixel right by 8, which would become 0x00ff0000, the same value as RED. So, why are you doing the shift in your test?
It's a code port I'm doing, I did try before to do it without the shifting but it would give me pretty far away values from the hex ones I'm trying to compare against...
This is the exact color comparison:
const int RED = 0xff0000;
int pixel = image.getPixel(x, y);
int pix = (pixel >> 8).toUnsigned(32) & 0xffffff;
if (pix == RED){
....
}
It's far easier to read it in hex for color comparison, thus why I'm trying to accomplish the masking like this. Do you have any suggestion?
The channels encoded in pixel are in ABGR order. So the shift is nocking off the red channel and moving alpha into blues spot, blue into greens, and green into reds.
So, the actual color you have stored in RED is blue=0xff, and 0x00 for alpha, green and red. The color red with no transparency would actually be 0xff0000ff. Are you testing if the pixel color is exactly red? In that case, just test with == and no shift. Do you want to check a specific channel of pixel? There are functions in the image library for getRed, getGreen, getBlue and getAlpha, which will extract the specific channel from pixel. If that's what you're trying to do, then the test would be getRed(pixel) == 0xff.
Forgive me if I'm not understanding your problem correctly.
On Mon, Jan 23, 2017, 4:17 PM Xavier Guzman notifications@github.com wrote:
It's a code port I'm doing, I did try before to do it without the shifting but it would give me pretty far away values from the hex ones I'm trying to compare against...
This is the exact color comparison:
const int RED = 0xff0000;
int pixel = image.getPixel(x, y);int pix = (pixel >> 8).toUnsigned(32) & 0xffffff; if (pix == RED){ .... }
It's far easier to read it in hex for color comparison, thus why I'm trying to accomplish the masking like this. Do you have any suggestion?
— You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/brendan-duncan/image/issues/46#issuecomment-274661160, or mute the thread https://github.com/notifications/unsubscribe-auth/ADeS8yGmr3GSwqNBSjkNM513aMbmomlVks5rVUMmgaJpZM4Lrnks .
Sweet...somehow i skipped that the format is ABGR :) I assumed it was RGBA so my comparison was all off!
Thanks :)
Awesome, glad that got worked out.
On Mon, Jan 23, 2017, 7:00 PM Xavier Guzman notifications@github.com wrote:
Sweet...somehow i skipped that the format is ABGR :) I assumed it was RGBA so my comparison was all off!
Thanks :)
— You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/brendan-duncan/image/issues/46#issuecomment-274688052, or mute the thread https://github.com/notifications/unsubscribe-auth/ADeS89pXykWfNe9WBAFGZpHuxNlXgYq4ks5rVWldgaJpZM4Lrnks .
I have been unable to compare the colors of the getPixel method successfully to some hex numbers constants I defined.
The source is a standard PNG image without transparency. I have just been getting false results doing the following:
However, even black dots are printing RED PIXEL in the console with this approach.
Am I doing it the wrong way?