[Scummvm-git-logs] scummvm master -> 9e748e82bbb6a465c365edf5eca83a75579a765f

criezy criezy at scummvm.org
Sun Feb 21 00:10:53 UTC 2021


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
9e748e82bb AGS: Fix draw_lit_sprite implementation


Commit: 9e748e82bbb6a465c365edf5eca83a75579a765f
    https://github.com/scummvm/scummvm/commit/9e748e82bbb6a465c365edf5eca83a75579a765f
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2021-02-21T00:05:27Z

Commit Message:
AGS: Fix draw_lit_sprite implementation

The allegro documentation indicates it is used to tint a sprite by
blending pixels from the given sprite with the color passed to the
last call to set_trans_blender.

Only the true color version is implemented. For 256 color sprites
it should use the global color_map table created using either
create_trans_table or create_light_table.

Changed paths:
    engines/ags/lib/allegro/color.cpp
    engines/ags/lib/allegro/color.h
    engines/ags/lib/allegro/gfx.cpp


diff --git a/engines/ags/lib/allegro/color.cpp b/engines/ags/lib/allegro/color.cpp
index 8da34cb41c..11c090391c 100644
--- a/engines/ags/lib/allegro/color.cpp
+++ b/engines/ags/lib/allegro/color.cpp
@@ -50,6 +50,9 @@ int _rgb_a_shift_32 = 0;
 RGB_MAP *rgb_map;
 COLOR_MAP *color_map;
 int trans_blend_alpha = -1;
+int trans_blend_red = 0;
+int trans_blend_green = 0;
+int trans_blend_blue = 0;
 
 void color::readFromFile(AGS::Shared::Stream *file) {
 	r = file->ReadByte();
@@ -282,8 +285,10 @@ void set_write_alpha_blender(void) {
 }
 
 void set_trans_blender(int r, int g, int b, int a) {
-	assert(r == 0 && g == 0 && b == 0);
 	trans_blend_alpha = a;
+	trans_blend_red = r;
+	trans_blend_green = g;
+	trans_blend_blue = b;
 }
 
 void set_add_blender(int r, int g, int b, int a) {
diff --git a/engines/ags/lib/allegro/color.h b/engines/ags/lib/allegro/color.h
index 870d7d756c..af202827f3 100644
--- a/engines/ags/lib/allegro/color.h
+++ b/engines/ags/lib/allegro/color.h
@@ -78,6 +78,9 @@ AL_VAR(PALETTE, default_palette);
 AL_VAR(RGB_MAP *, rgb_map);
 AL_VAR(COLOR_MAP *, color_map);
 extern int trans_blend_alpha;
+extern int trans_blend_red;
+extern int trans_blend_green;
+extern int trans_blend_blue;
 
 AL_VAR(PALETTE, _current_palette);
 
diff --git a/engines/ags/lib/allegro/gfx.cpp b/engines/ags/lib/allegro/gfx.cpp
index fd88e44c19..58a20993b1 100644
--- a/engines/ags/lib/allegro/gfx.cpp
+++ b/engines/ags/lib/allegro/gfx.cpp
@@ -252,13 +252,36 @@ void draw_lit_sprite(BITMAP *bmp, const BITMAP *sprite, int x, int y, int color)
 	assert(sprite->format.bytesPerPixel == 4 && bmp->format.bytesPerPixel == 4);
 	assert(color >= 0 && color <= 255);
 
-	Graphics::ManagedSurface temp;
-	Graphics::ManagedSurface &src = **sprite;
-	stripAlpha(src, temp);
+	byte rSrc, gSrc, bSrc, aSrc;
+	byte rDest, gDest, bDest;
+	double alpha = (double)color / 255.0;
+
+	for (int yCtr = 0, yp = y; yCtr < sprite->h && yp < bmp->h; ++yCtr, ++yp) {
+		if (yp < 0)
+			continue;
+
+		const uint32 *srcP = (const uint32 *)sprite->getBasePtr(0, yCtr);
+		uint32 *destP = (uint32 *)bmp->getBasePtr(x, yp);
+
+		for (int xCtr = 0, xp = x; xCtr < sprite->w && xp < bmp->w; ++xCtr, ++xp, ++destP, ++srcP) {
+			if (x < 0 || x >= bmp->w)
+				continue;
 
-	bmp->getSurface().transBlitFrom(temp, Common::Rect(0, 0, temp.w, temp.h),
-		Common::Rect(x, y, x + temp.w, y + temp.h), TRANSPARENT_COLOR(*sprite),
-		false, 0, color);
+			// Get the source pixels
+			sprite->format.colorToARGB(*srcP, aSrc, rSrc, gSrc, bSrc);
+
+			if (rSrc == 255 && gSrc == 0 && bSrc == 255)
+				// Skip transparent pixels
+				continue;
+
+			// Blend the two
+			rDest = static_cast<byte>((rSrc * alpha) + (trans_blend_red * (1.0 - alpha)));
+			gDest = static_cast<byte>((gSrc * alpha) + (trans_blend_green * (1.0 - alpha)));
+			bDest = static_cast<byte>((bSrc * alpha) + (trans_blend_blue * (1.0 - alpha)));
+
+			*destP = bmp->format.RGBToColor(rDest, gDest, bDest);
+		}
+	}
 }
 
 void draw_sprite_h_flip(BITMAP *bmp, const BITMAP *sprite, int x, int y) {




More information about the Scummvm-git-logs mailing list