[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Issue with pygame.mask



else if ((abs((((the_color & rmask) >> rshift) << rloss) - r) < tr) &
                       (abs((((the_color & gmask) >> gshift) << gloss)
- g) < tg) &
                       (abs((((the_color & bmask) >> bshift) << bloss)
- b) < tb)) {
                /* this pixel is within the threshold of the color. */
                bitmask_setbit(m, x, y);

I wrote the top comment but I didn't need perfect matching at the
time.  I just dug through the source and found what is going on for
real.  It seem that I was right except you don't get to include the
endpoints.

You are right that a 0 threshold will do nothing.  The default
threshold = (0,0,0,255) won't do anything.  I retested that statement
because that doesn't seem right but that is how it is.

On Mon, May 14, 2012 at 7:01 AM, Peter Finlayson <frnknstn@xxxxxxxxxxx> wrote:
> On 14/05/2012 10:24, Greg Ewing wrote:
>>
>> The third comment about that function here seems to explain
>> what's happening:
>
>
> The third comment is incorrect, the topmost closer to what I have found by
> testing.
>
> The function (as I expected, and as testing shows) works kind of like the
> magic wand in some image editing software: it takes a color and a threshold,
> and returns a mask containing all the pixels with color values that are
> within that threshold of the supplied color. (I have updated my test prog to
> highlight that.)
>
> However, there appears to be an off-by-one error in the function: a
> threshold of zero, to my mind, should match only the exact color, and a
> threshold of (255,255,255) should match all colors regardless of the base
> color.
>
> Instead, a threshold of zero matches nothing, and it is impossible to match
> all the colors.
>
> Before I go digging into the PyGame code to see if I can fix this, I wanted
> to check if this is actually a bug, or if it is by design. I guess if there
> is nobody here knows, I will have to hit the code :)
>
> Regards
> Peter Finlayson