AGS: Fix allegro mask color

In allegro the mask color has alpha set to 0. We were setting it
to 0xff and that caused comparaison of colors with mask to fail
in some places in the engine, for example causing the check of
whether a given position is on a sprite to fail (it was returning
true for any position inside the sprite bitmap, even if on a
transparent pixel).

See my_getpixel(Bitmap *, int x, int y) in character.cpp that
strips the alpha from the color just for that purpose (it is
called from is_pos_in_sprite()) where the pixel is compared to
the mask color..
This commit is contained in:
Thierry Crozat
2021-03-15 21:03:12 +00:00
parent 30b06ae9de
commit 180d364ebe
2 changed files with 13 additions and 7 deletions
+7 -6
View File
@@ -33,11 +33,6 @@ namespace AGS3 {
int color_conversion;
// For Allegro, paletted sprites always use index 0 as the transparent color,
// and for higher resolution formats uses bright pink RGB 255, 0, 255
#define TRANSPARENT_COLOR(BITMAP) ((BITMAP).format.bytesPerPixel == 1 ? 0 : \
(BITMAP).format.RGBToColor(255, 0, 255))
/*-------------------------------------------------------------------*/
void set_color_conversion(int mode) {
@@ -98,7 +93,13 @@ int bitmap_color_depth(BITMAP *bmp) {
}
int bitmap_mask_color(BITMAP *bmp) {
return TRANSPARENT_COLOR(*bmp);
// For paletted sprites this is 0.
// For other color depths this is bright pink (RGB 255, 0, 255).
// The alpha chanel should be 0.
//if (bmp-format.bytesPerPixel == 1)
// return 0;
//return bmp->format.AGRBToColor(0, 255, 0, 255);
return bmp->getTransparentColor();
}
void blit(const BITMAP *src, BITMAP *dest, int src_x, int src_y, int dst_x, int dst_y, int width, int height) {
+6 -1
View File
@@ -62,7 +62,12 @@ public:
}
uint getTransparentColor() const {
return _owner->getTransparentColor();
// See allegro bitmap_mask_color
// For paletted sprites this is 0.
// For other color depths this is bright pink (RGB 255, 0, 255) with alpha set to 0.
if (format.bytesPerPixel == 1)
return 0;
return format.ARGBToColor(0, 255, 0, 255);
}
int getpixel(int x, int y) const;