From 180d364ebe5c2e628244f0807dc2ca4ebf087a6d Mon Sep 17 00:00:00 2001 From: Thierry Crozat Date: Mon, 15 Mar 2021 20:16:37 +0000 Subject: [PATCH] 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.. --- engines/ags/lib/allegro/gfx.cpp | 13 +++++++------ engines/ags/lib/allegro/surface.h | 7 ++++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/engines/ags/lib/allegro/gfx.cpp b/engines/ags/lib/allegro/gfx.cpp index b497fac2aa0..9bb2bb5488d 100644 --- a/engines/ags/lib/allegro/gfx.cpp +++ b/engines/ags/lib/allegro/gfx.cpp @@ -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) { diff --git a/engines/ags/lib/allegro/surface.h b/engines/ags/lib/allegro/surface.h index 1a4362f9589..a8558576083 100644 --- a/engines/ags/lib/allegro/surface.h +++ b/engines/ags/lib/allegro/surface.h @@ -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;