Re: [AD] getpixel conflict with alpha blended sprites

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


> OK, what about this patch?

Mostly ok.

> Possible caveats: the comparisons assume 2's complement arithmetic for
> optimization (what is our policy there?),

Do you know of any modern CPU that does not use 2's complement arithmetic?
I think you are allowed to use any of its properties in your code (at least 
as long as Allegro is concerned).

+AL_INLINE(int, is_inside_clip, (BITMAP *bmp, int x, int y, int clip),
+{
+   ASSERT(bmp);
+
+   if (clip)
+      return ((unsigned)(x-bmp->cl)) < (unsigned)(bmp->cr-bmp->cl)
+	     && ((unsigned)(y-bmp->ct)) < (unsigned)(bmp->cb-bmp->ct);
+   else
+      return ((unsigned)x) < bmp->w && ((unsigned)y) < bmp->h;
+})

Two remarks:
- the code in the 'if' arm assumes than bmp->cl <= bmp->cr; this will no 
longer be true,
- this will give 'comparison between signed and unsigned' warnings for the 
code in the 'else' arm.

> and the function name may not be optimal.

Yes, I think it could be better too.  In particular, 'clip' shouldn't appear 
since you can specify not to take it into account.

> Plus Eric sent a patch for a new clipping API just as I was going to press
> "Send", and I haven't checked if the two patches collide.

You're indeed not very lucky :-)  They do collide.  The function should 
return 0 when the clipping rectangle is "reversed".

-- 
Eric Botcazou




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/