[Scummvm-git-logs] scummvm master -> 6b08906f25b9258afa320f3bc82f8b7b981270c8
criezy
criezy at scummvm.org
Thu Mar 4 00:21:09 UTC 2021
This automated email contains information about 5 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
e55462f483 AGS: Remove some unused allegro code
eccbde5530 AGS: Implement blender modes
51c9a9eb84 AGS: Remove allegro blender functions
c1295f90d1 AGS: Fix handling of transparency when drawing paletted sprites
6b08906f25 AGS: Remove hack to skip transparent color when blitting to screen
Commit: e55462f483ae0d7bcd021d75dbc6aa751fdd7cdb
https://github.com/scummvm/scummvm/commit/e55462f483ae0d7bcd021d75dbc6aa751fdd7cdb
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2021-03-04T00:19:00Z
Commit Message:
AGS: Remove some unused allegro code
Changed paths:
engines/ags/lib/allegro/color.cpp
engines/ags/lib/allegro/color.h
diff --git a/engines/ags/lib/allegro/color.cpp b/engines/ags/lib/allegro/color.cpp
index 11c090391c..1df4b9c52e 100644
--- a/engines/ags/lib/allegro/color.cpp
+++ b/engines/ags/lib/allegro/color.cpp
@@ -84,16 +84,6 @@ void set_palette_range(const PALETTE p, int from, int to, int retracesync) {
}
}
-void palette_to_rgb8(const PALETTE src, byte dest[PALETTE_SIZE]) {
- byte *pDest = dest;
- for (int i = 0; i < 256; ++i, pDest += 3) {
- pDest[0] = VGA_COLOR_TRANS(src[i].r);
- pDest[1] = VGA_COLOR_TRANS(src[i].g);
- pDest[2] = VGA_COLOR_TRANS(src[i].b);
- }
-}
-
-
int makecol15(int r, int g, int b) {
return (((r >> 3) << _rgb_r_shift_15) |
((g >> 3) << _rgb_g_shift_15) |
@@ -217,30 +207,6 @@ void fade_interpolate(AL_CONST PALETTE source, AL_CONST PALETTE dest, PALETTE ou
warning("TODO: fade_interpolate");
}
-void fade_from_range(AL_CONST PALETTE source, AL_CONST PALETTE dest, int speed, int from, int to) {
- warning("TODO: fade_from_range");
-}
-
-void fade_in_range(AL_CONST PALETTE p, int speed, int from, int to) {
- warning("TODO: fade_in_range");
-}
-
-void fade_out_range(int speed, int from, int to) {
- warning("TODO: fade_out_range");
-}
-
-void fade_from(AL_CONST PALETTE source, AL_CONST PALETTE dest, int speed) {
- warning("TODO: fade_from");
-}
-
-void fade_in(AL_CONST PALETTE p, int speed) {
- warning("TODO: fade_in");
-}
-
-void fade_out(int speed) {
- warning("TODO: fade_out");
-}
-
void select_palette(AL_CONST PALETTE p) {
int c;
@@ -259,31 +225,10 @@ void unselect_palette(void) {
_current_palette[c] = _prev_current_palette[c];
}
-void generate_332_palette(PALETTE pal) {
- warning("TODO: generate_332_palette");
-}
-
-int generate_optimized_palette(BITMAP *image, PALETTE pal, AL_CONST signed char rsvdcols[256]) {
- warning("TODO: generate_optimized_palette");
- return 0;
-}
-
-void set_blender_mode(BLENDER_FUNC b15, BLENDER_FUNC b16, BLENDER_FUNC b24, int r, int g, int b, int a) {
- // TODO: set_blender_mode
-}
-
-void set_blender_mode_ex(BLENDER_FUNC b15, BLENDER_FUNC b16, BLENDER_FUNC b24, BLENDER_FUNC b32, BLENDER_FUNC b15x, BLENDER_FUNC b16x, BLENDER_FUNC b24x, int r, int g, int b, int a) {
- // TODO: set_blender_mode_ex
-}
-
void set_alpha_blender(void) {
trans_blend_alpha = -1;
}
-void set_write_alpha_blender(void) {
- // TODO: set_write_alpha_blender
-}
-
void set_trans_blender(int r, int g, int b, int a) {
trans_blend_alpha = a;
trans_blend_red = r;
@@ -291,55 +236,6 @@ void set_trans_blender(int r, int g, int b, int a) {
trans_blend_blue = b;
}
-void set_add_blender(int r, int g, int b, int a) {
- // TODO: set_add_blender
-}
-
-void set_burn_blender(int r, int g, int b, int a) {
- // TODO: set_burn_blender
-}
-
-void set_color_blender(int r, int g, int b, int a) {
- // TODO: set_color_blender
-}
-
-void set_difference_blender(int r, int g, int b, int a) {
- // TODO: set_difference_blender
-}
-
-void set_dissolve_blender(int r, int g, int b, int a) {
- // TODO: set_dissolve_blender
-}
-
-void set_dodge_blender(int r, int g, int b, int a) {
- // TODO: set_dodge_blender
-}
-
-void set_hue_blender(int r, int g, int b, int a) {
- // TODO: set_hue_blender
-}
-
-void set_invert_blender(int r, int g, int b, int a) {
- // TODO: set_invert_blender
-}
-
-void set_luminance_blender(int r, int g, int b, int a) {
- // TODO: set_luminance_blender
-}
-
-void set_multiply_blender(int r, int g, int b, int a) {
- // TODO: set_multiply_blender
-}
-
-void set_saturation_blender(int r, int g, int b, int a) {
- // TODO: set_saturation_blender
-}
-
-void set_screen_blender(int r, int g, int b, int a) {
- // TODO: set_screen_blender
-}
-
-
/* makecol_depth:
* Converts R, G, and B values (ranging 0-255) to whatever pixel format
* is required by the specified color depth.
@@ -394,28 +290,6 @@ int makeacol_depth(int color_depth, int r, int g, int b, int a) {
return 0;
}
-
-
-/* makecol:
- * Converts R, G, and B values (ranging 0-255) to whatever pixel format
- * is required by the current video mode.
- */
-int makecol(int r, int g, int b) {
- return makecol_depth(_color_depth, r, g, b);
-}
-
-
-
-/* makeacol:
- * Converts R, G, B, and A values (ranging 0-255) to whatever pixel format
- * is required by the current video mode.
- */
-int makeacol(int r, int g, int b, int a) {
- return makeacol_depth(_color_depth, r, g, b, a);
-}
-
-
-
/* getr_depth:
* Extracts the red component (ranging 0-255) from a pixel in the format
* being used by the specified color depth.
@@ -1091,76 +965,4 @@ void create_trans_table(COLOR_MAP *table, AL_CONST PALETTE pal, int r, int g, in
(*callback)(255);
}
-
-
-/* create_color_table:
- * Creates a color mapping table, using a user-supplied callback to blend
- * each pair of colors. Your blend routine will be passed a pointer to the
- * palette and the two colors to be blended (x is the source color, y is
- * the destination), and should return the desired output RGB for this
- * combination. If the callback function is not NULL, it will be called
- * 256 times during the calculation, allowing you to display a progress
- * indicator.
- */
-void create_color_table(COLOR_MAP *table, AL_CONST PALETTE pal, void (*blend)(AL_CONST PALETTE pal, int x, int y, RGB *rgb), void (*callback)(int pos)) {
- int x, y;
- RGB c;
-
- for (x = 0; x < PAL_SIZE; x++) {
- for (y = 0; y < PAL_SIZE; y++) {
- blend(pal, x, y, &c);
-
- if (rgb_map)
- table->data[x][y] = rgb_map->data[c.r >> 1][c.g >> 1][c.b >> 1];
- else
- table->data[x][y] = bestfit_color(pal, c.r, c.g, c.b);
- }
-
- if (callback)
- (*callback)(x);
- }
-}
-
-
-
-/* create_blender_table:
- * Fills the specified color mapping table with lookup data for doing a
- * paletted equivalent of whatever truecolor blender mode is currently
- * selected.
- */
-void create_blender_table(COLOR_MAP *table, AL_CONST PALETTE pal, void (*callback)(int pos)) {
- int x, y, c;
- int r, g, b;
- int r1, g1, b1;
- int r2, g2, b2;
-
- assert(_blender_func24);
-
- for (x = 0; x < PAL_SIZE; x++) {
- for (y = 0; y < PAL_SIZE; y++) {
- r1 = (pal[x].r << 2) | ((pal[x].r & 0x30) >> 4);
- g1 = (pal[x].g << 2) | ((pal[x].g & 0x30) >> 4);
- b1 = (pal[x].b << 2) | ((pal[x].b & 0x30) >> 4);
-
- r2 = (pal[y].r << 2) | ((pal[y].r & 0x30) >> 4);
- g2 = (pal[y].g << 2) | ((pal[y].g & 0x30) >> 4);
- b2 = (pal[y].b << 2) | ((pal[y].b & 0x30) >> 4);
-
- c = _blender_func24(makecol24(r1, g1, b1), makecol24(r2, g2, b2), _blender_alpha);
-
- r = getr24(c);
- g = getg24(c);
- b = getb24(c);
-
- if (rgb_map)
- table->data[x][y] = rgb_map->data[r >> 3][g >> 3][b >> 3];
- else
- table->data[x][y] = bestfit_color(pal, r >> 2, g >> 2, b >> 2);
- }
-
- if (callback)
- (*callback)(x);
- }
-}
-
} // namespace AGS3
diff --git a/engines/ags/lib/allegro/color.h b/engines/ags/lib/allegro/color.h
index af202827f3..cbd9f5388a 100644
--- a/engines/ags/lib/allegro/color.h
+++ b/engines/ags/lib/allegro/color.h
@@ -104,31 +104,19 @@ AL_ARRAY(int, _rgb_scale_6);
AL_FUNC(void, set_color, (int idx, AL_CONST RGB *p));
AL_FUNC(void, set_palette, (AL_CONST PALETTE p));
AL_FUNC(void, set_palette_range, (AL_CONST PALETTE p, int from, int to, int retracesync));
-AL_FUNC(void, palette_to_rgb8, (AL_CONST PALETTE src, byte dest[PALETTE_SIZE]));
AL_FUNC(void, get_color, (int idx, RGB *p));
AL_FUNC(void, get_palette, (PALETTE p));
AL_FUNC(void, get_palette_range, (PALETTE p, int from, int to));
AL_FUNC(void, fade_interpolate, (AL_CONST PALETTE source, AL_CONST PALETTE dest, PALETTE output, int pos, int from, int to));
-AL_FUNC(void, fade_from_range, (AL_CONST PALETTE source, AL_CONST PALETTE dest, int speed, int from, int to));
-AL_FUNC(void, fade_in_range, (AL_CONST PALETTE p, int speed, int from, int to));
-AL_FUNC(void, fade_out_range, (int speed, int from, int to));
-AL_FUNC(void, fade_from, (AL_CONST PALETTE source, AL_CONST PALETTE dest, int speed));
-AL_FUNC(void, fade_in, (AL_CONST PALETTE p, int speed));
-AL_FUNC(void, fade_out, (int speed));
AL_FUNC(void, select_palette, (AL_CONST PALETTE p));
AL_FUNC(void, unselect_palette, (void));
-AL_FUNC(void, generate_332_palette, (PALETTE pal));
-AL_FUNC(int, generate_optimized_palette, (BITMAP *image, PALETTE pal, AL_CONST signed char rsvdcols[256]));
-
AL_FUNC(void, create_rgb_table, (RGB_MAP *table, AL_CONST PALETTE pal, AL_METHOD(void, callback, (int pos))));
AL_FUNC(void, create_light_table, (COLOR_MAP *table, AL_CONST PALETTE pal, int r, int g, int b, AL_METHOD(void, callback, (int pos))));
AL_FUNC(void, create_trans_table, (COLOR_MAP *table, AL_CONST PALETTE pal, int r, int g, int b, AL_METHOD(void, callback, (int pos))));
-AL_FUNC(void, create_color_table, (COLOR_MAP *table, AL_CONST PALETTE pal, AL_METHOD(void, blend, (AL_CONST PALETTE pal, int x, int y, RGB *rgb)), AL_METHOD(void, callback, (int pos))));
-AL_FUNC(void, create_blender_table, (COLOR_MAP *table, AL_CONST PALETTE pal, AL_METHOD(void, callback, (int pos))));
typedef AL_METHOD(unsigned long, BLENDER_FUNC, (unsigned long x, unsigned long y, unsigned long n));
@@ -136,36 +124,18 @@ AL_FUNC(void, set_blender_mode, (BLENDER_FUNC b15, BLENDER_FUNC b16, BLENDER_FUN
AL_FUNC(void, set_blender_mode_ex, (BLENDER_FUNC b15, BLENDER_FUNC b16, BLENDER_FUNC b24, BLENDER_FUNC b32, BLENDER_FUNC b15x, BLENDER_FUNC b16x, BLENDER_FUNC b24x, int r, int g, int b, int a));
AL_FUNC(void, set_alpha_blender, (void));
-AL_FUNC(void, set_write_alpha_blender, (void));
AL_FUNC(void, set_trans_blender, (int r, int g, int b, int a));
-AL_FUNC(void, set_add_blender, (int r, int g, int b, int a));
-AL_FUNC(void, set_burn_blender, (int r, int g, int b, int a));
-AL_FUNC(void, set_color_blender, (int r, int g, int b, int a));
-AL_FUNC(void, set_difference_blender, (int r, int g, int b, int a));
-AL_FUNC(void, set_dissolve_blender, (int r, int g, int b, int a));
-AL_FUNC(void, set_dodge_blender, (int r, int g, int b, int a));
-AL_FUNC(void, set_hue_blender, (int r, int g, int b, int a));
-AL_FUNC(void, set_invert_blender, (int r, int g, int b, int a));
-AL_FUNC(void, set_luminance_blender, (int r, int g, int b, int a));
-AL_FUNC(void, set_multiply_blender, (int r, int g, int b, int a));
-AL_FUNC(void, set_saturation_blender, (int r, int g, int b, int a));
-AL_FUNC(void, set_screen_blender, (int r, int g, int b, int a));
AL_FUNC(void, hsv_to_rgb, (float h, float s, float v, int *r, int *g, int *b));
AL_FUNC(void, rgb_to_hsv, (int r, int g, int b, float *h, float *s, float *v));
AL_FUNC(int, bestfit_color, (AL_CONST PALETTE pal, int r, int g, int b));
-AL_FUNC(int, makecol, (int r, int g, int b));
AL_FUNC(int, makecol8, (int r, int g, int b));
AL_FUNC(int, makecol_depth, (int color_depth, int r, int g, int b));
-AL_FUNC(int, makeacol, (int r, int g, int b, int a));
AL_FUNC(int, makeacol_depth, (int color_depth, int r, int g, int b, int a));
-AL_FUNC(int, makecol15_dither, (int r, int g, int b, int x, int y));
-AL_FUNC(int, makecol16_dither, (int r, int g, int b, int x, int y));
-
AL_FUNC(int, getr, (int c));
AL_FUNC(int, getg, (int c));
AL_FUNC(int, getb, (int c));
Commit: eccbde5530e6f3088766e1f0f9babb1880251007
https://github.com/scummvm/scummvm/commit/eccbde5530e6f3088766e1f0f9babb1880251007
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2021-03-04T00:19:00Z
Commit Message:
AGS: Implement blender modes
Changed paths:
engines/ags/engine/ac/draw.cpp
engines/ags/engine/gfx/ali3dscummvm.cpp
engines/ags/engine/gfx/blender.cpp
engines/ags/engine/gfx/gfx_util.cpp
engines/ags/lib/allegro/color.cpp
engines/ags/lib/allegro/color.h
engines/ags/lib/allegro/surface.cpp
engines/ags/lib/allegro/surface.h
diff --git a/engines/ags/engine/ac/draw.cpp b/engines/ags/engine/ac/draw.cpp
index 2eff167d83..c27fbca371 100644
--- a/engines/ags/engine/ac/draw.cpp
+++ b/engines/ags/engine/ac/draw.cpp
@@ -1540,9 +1540,9 @@ void tint_image(Bitmap *ds, Bitmap *srcimg, int red, int grn, int blu, int light
// when light is being adjusted and when it is not.
// If luminance >= 250, then normal brightness, otherwise darken
if (luminance >= 250)
- set_blender_mode(_myblender_color15, _myblender_color16, _myblender_color32, red, grn, blu, 0);
+ set_blender_mode(kTintBlenderMode, red, grn, blu, 0);
else
- set_blender_mode(_myblender_color15_light, _myblender_color16_light, _myblender_color32_light, red, grn, blu, 0);
+ set_blender_mode(kTintLightBlenderMode, red, grn, blu, 0);
if (light_level >= 100) {
// fully colourised
diff --git a/engines/ags/engine/gfx/ali3dscummvm.cpp b/engines/ags/engine/gfx/ali3dscummvm.cpp
index 69a17bf18e..3d4628bbbf 100644
--- a/engines/ags/engine/gfx/ali3dscummvm.cpp
+++ b/engines/ags/engine/gfx/ali3dscummvm.cpp
@@ -467,7 +467,7 @@ void ALScummVMGraphicsDriver::RenderSpriteBatch(const ALSpriteBatch &batch, Shar
set_alpha_blender();
else
// here _transparency is used as alpha (between 1 and 254)
- set_blender_mode(nullptr, nullptr, _trans_alpha_blender32, 0, 0, 0, bitmap->_transparency);
+ set_blender_mode(kArgbToRgbBlender, 0, 0, 0, bitmap->_transparency);
surface->TransBlendBlt(bitmap->_bmp, drawAtX, drawAtY);
} else {
diff --git a/engines/ags/engine/gfx/blender.cpp b/engines/ags/engine/gfx/blender.cpp
index b800d9bb51..17007d9852 100644
--- a/engines/ags/engine/gfx/blender.cpp
+++ b/engines/ags/engine/gfx/blender.cpp
@@ -157,7 +157,7 @@ unsigned long _myblender_alpha_trans24(unsigned long x, unsigned long y, unsigne
void set_my_trans_blender(int r, int g, int b, int a) {
// use standard allegro 15 and 16 bit blenders, but customize
// the 32-bit one to preserve the alpha channel
- set_blender_mode(_blender_trans15, _blender_trans16, _myblender_alpha_trans24, r, g, b, a);
+ set_blender_mode(kAlphaPreservedBlenderMode, r, g, b, a);
}
// plain copy source to destination
@@ -258,11 +258,11 @@ unsigned long skiptranspixels_blender_alpha16(unsigned long x, unsigned long y,
}
void set_additive_alpha_blender() {
- set_blender_mode(nullptr, nullptr, _additive_alpha_copysrc_blender, 0, 0, 0, 0);
+ set_blender_mode(kAdditiveBlenderMode, 0, 0, 0, 0);
}
void set_argb2argb_blender(int alpha) {
- set_blender_mode(nullptr, nullptr, _argb2argb_blender, 0, 0, 0, alpha);
+ set_blender_mode(kArgbToArgbBlender, 0, 0, 0, alpha);
}
// sets the alpha channel to opaque. used when drawing a non-alpha sprite onto an alpha-sprite
@@ -271,13 +271,11 @@ unsigned long _opaque_alpha_blender(unsigned long x, unsigned long y, unsigned l
}
void set_opaque_alpha_blender() {
- set_blender_mode(nullptr, nullptr, _opaque_alpha_blender, 0, 0, 0, 0);
+ set_blender_mode(kOpaqueBlenderMode, 0, 0, 0, 0);
}
void set_argb2any_blender() {
- set_blender_mode_ex(_blender_black, _blender_black, _blender_black, _argb2argb_blender,
- _blender_alpha15, skiptranspixels_blender_alpha16, _blender_alpha24,
- 0, 0, 0, 0xff); // TODO: do we need to support proper 15- and 24-bit here?
+ set_blender_mode(kArgbToArgbBlender, 0, 0, 0, 0xff);
}
} // namespace AGS3
diff --git a/engines/ags/engine/gfx/gfx_util.cpp b/engines/ags/engine/gfx/gfx_util.cpp
index b1ad9e20d2..301d657592 100644
--- a/engines/ags/engine/gfx/gfx_util.cpp
+++ b/engines/ags/engine/gfx/gfx_util.cpp
@@ -56,19 +56,19 @@ typedef BLENDER_FUNC PfnBlenderCb;
struct BlendModeSetter {
// Blender setter for destination with and without alpha channel;
- // assign null pointer if not supported
- PfnBlenderCb AllAlpha; // src w alpha -> dst w alpha
- PfnBlenderCb AlphaToOpaque; // src w alpha -> dst w/o alpha
- PfnBlenderCb OpaqueToAlpha; // src w/o alpha -> dst w alpha
- PfnBlenderCb OpaqueToAlphaNoTrans; // src w/o alpha -> dst w alpha (opt-ed for no transparency)
- PfnBlenderCb AllOpaque; // src w/o alpha -> dst w/o alpha
+ // assign kRgbToRgbBlender if not supported
+ BlenderMode AllAlpha; // src w alpha -> dst w alpha
+ BlenderMode AlphaToOpaque; // src w alpha -> dst w/o alpha
+ BlenderMode OpaqueToAlpha; // src w/o alpha -> dst w alpha
+ BlenderMode OpaqueToAlphaNoTrans; // src w/o alpha -> dst w alpha (opt-ed for no transparency)
+ BlenderMode AllOpaque; // src w/o alpha -> dst w/o alpha
};
// Array of blender descriptions
-// NOTE: set NULL function pointer to fallback to common image blitting
+// NOTE: set kRgbToRgbBlender to fallback to common image blitting
static const BlendModeSetter BlendModeSets[kNumBlendModes] = {
- { nullptr, nullptr, nullptr, nullptr, nullptr }, // kBlendMode_NoAlpha
- { _argb2argb_blender, _argb2rgb_blender, _rgb2argb_blender, _opaque_alpha_blender, nullptr }, // kBlendMode_Alpha
+ { kRgbToRgbBlender, kRgbToRgbBlender, kRgbToRgbBlender, kRgbToRgbBlender, kRgbToRgbBlender }, // kBlendMode_NoAlpha
+ { kArgbToArgbBlender, kArgbToRgbBlender, kRgbToArgbBlender, kOpaqueBlenderMode, kRgbToRgbBlender }, // kBlendMode_Alpha
// NOTE: add new modes here
};
@@ -76,18 +76,15 @@ bool SetBlender(BlendMode blend_mode, bool dst_has_alpha, bool src_has_alpha, in
if (blend_mode < 0 || blend_mode > kNumBlendModes)
return false;
const BlendModeSetter &set = BlendModeSets[blend_mode];
- PfnBlenderCb blender;
+ BlenderMode blender;
if (dst_has_alpha)
blender = src_has_alpha ? set.AllAlpha :
(blend_alpha == 0xFF ? set.OpaqueToAlphaNoTrans : set.OpaqueToAlpha);
else
blender = src_has_alpha ? set.AlphaToOpaque : set.AllOpaque;
- if (blender) {
- set_blender_mode(nullptr, nullptr, blender, 0, 0, 0, blend_alpha);
- return true;
- }
- return false;
+ set_blender_mode(blender, 0, 0, 0, blend_alpha);
+ return true;
}
void DrawSpriteBlend(Bitmap *ds, const Point &ds_at, Bitmap *sprite,
diff --git a/engines/ags/lib/allegro/color.cpp b/engines/ags/lib/allegro/color.cpp
index 1df4b9c52e..79638b0a05 100644
--- a/engines/ags/lib/allegro/color.cpp
+++ b/engines/ags/lib/allegro/color.cpp
@@ -49,10 +49,11 @@ int _rgb_a_shift_32 = 0;
RGB_MAP *rgb_map;
COLOR_MAP *color_map;
-int trans_blend_alpha = -1;
+int trans_blend_alpha = 0;
int trans_blend_red = 0;
int trans_blend_green = 0;
int trans_blend_blue = 0;
+BlenderMode _blender_mode = kRgbToRgbBlender;
void color::readFromFile(AGS::Shared::Stream *file) {
r = file->ReadByte();
@@ -225,17 +226,22 @@ void unselect_palette(void) {
_current_palette[c] = _prev_current_palette[c];
}
-void set_alpha_blender(void) {
- trans_blend_alpha = -1;
-}
-
-void set_trans_blender(int r, int g, int b, int a) {
+void set_blender_mode(BlenderMode m, int r, int g, int b, int a) {
+ _blender_mode = m;
trans_blend_alpha = a;
trans_blend_red = r;
trans_blend_green = g;
trans_blend_blue = b;
}
+void set_alpha_blender(void) {
+ set_blender_mode(kSourceAlphaBlender, 0, 0, 0, 0);
+}
+
+void set_trans_blender(int r, int g, int b, int a) {
+ set_blender_mode(kRgbToRgbBlender, r, g, b, a);
+}
+
/* makecol_depth:
* Converts R, G, and B values (ranging 0-255) to whatever pixel format
* is required by the specified color depth.
diff --git a/engines/ags/lib/allegro/color.h b/engines/ags/lib/allegro/color.h
index cbd9f5388a..baa4808b17 100644
--- a/engines/ags/lib/allegro/color.h
+++ b/engines/ags/lib/allegro/color.h
@@ -82,6 +82,21 @@ extern int trans_blend_red;
extern int trans_blend_green;
extern int trans_blend_blue;
+enum BlenderMode {
+ kSourceAlphaBlender,
+ kArgbToArgbBlender,
+ kArgbToRgbBlender,
+ kRgbToArgbBlender,
+ kRgbToRgbBlender,
+ kAlphaPreservedBlenderMode,
+ kOpaqueBlenderMode,
+ kAdditiveBlenderMode,
+ kTintBlenderMode,
+ kTintLightBlenderMode
+};
+
+extern BlenderMode _blender_mode;
+
AL_VAR(PALETTE, _current_palette);
extern int _rgb_r_shift_15;
@@ -120,9 +135,7 @@ AL_FUNC(void, create_trans_table, (COLOR_MAP *table, AL_CONST PALETTE pal, int r
typedef AL_METHOD(unsigned long, BLENDER_FUNC, (unsigned long x, unsigned long y, unsigned long n));
-AL_FUNC(void, set_blender_mode, (BLENDER_FUNC b15, BLENDER_FUNC b16, BLENDER_FUNC b24, int r, int g, int b, int a));
-AL_FUNC(void, set_blender_mode_ex, (BLENDER_FUNC b15, BLENDER_FUNC b16, BLENDER_FUNC b24, BLENDER_FUNC b32, BLENDER_FUNC b15x, BLENDER_FUNC b16x, BLENDER_FUNC b24x, int r, int g, int b, int a));
-
+AL_FUNC(void, set_blender_mode, (BlenderMode, int r, int g, int b, int a));
AL_FUNC(void, set_alpha_blender, (void));
AL_FUNC(void, set_trans_blender, (int r, int g, int b, int a));
diff --git a/engines/ags/lib/allegro/surface.cpp b/engines/ags/lib/allegro/surface.cpp
index 58ecc098f0..50a6750246 100644
--- a/engines/ags/lib/allegro/surface.cpp
+++ b/engines/ags/lib/allegro/surface.cpp
@@ -122,12 +122,16 @@ void BITMAP::draw(const BITMAP *srcBitmap, const Common::Rect &srcRect,
byte rDest = 0, gDest = 0, bDest = 0, aDest = 0;
uint32 pal[PALETTE_COUNT];
- if (src.format.bytesPerPixel == 1) {
+ Graphics::PixelFormat srcFormat = src.format;
+ if (srcFormat.bytesPerPixel == 1) {
for (int i = 0; i < PALETTE_COUNT; ++i)
pal[i] = format.RGBToColor(
VGA_COLOR_TRANS(_current_palette[i].r),
VGA_COLOR_TRANS(_current_palette[i].g),
VGA_COLOR_TRANS(_current_palette[i].b));
+ srcFormat = format;
+ // TODO: check if the line below is correct. If it is correct, we can simplify the skipTrans
+ // below as we can use IS_TRANSPARENT() can be used for the 1 bytePerPixel case as well
pal[0] = format.RGBToColor(0xff, 0, 0xff);
}
@@ -150,80 +154,121 @@ void BITMAP::draw(const BITMAP *srcBitmap, const Common::Rect &srcRect,
const byte *srcVal = srcP + xDir * (scaleXCtr / SCALE_THRESHOLD * src.format.bytesPerPixel);
byte *destVal = (byte *)&destP[xCtr * format.bytesPerPixel];
- switch (src.format.bytesPerPixel) {
- case 1:
- if (format.bytesPerPixel == 1) {
- *destVal = *srcVal;
- continue;
- }
- format.colorToARGB(pal[*srcVal], aSrc, rSrc, gSrc, bSrc);
- break;
- case 2:
- src.format.colorToARGB(*(const uint16 *)srcVal, aSrc, rSrc, gSrc, bSrc);
- break;
- case 4:
- src.format.colorToARGB(*(const uint32 *)srcVal, aSrc, rSrc, gSrc, bSrc);
- break;
- default:
- error("Unknown format");
+ if (src.format.bytesPerPixel == 1 && format.bytesPerPixel == 1) {
+ // TODO: Need to skip transparent color if skip_trans is true?
+ //if (!skipTrans || *srcVal != 0)
+ *destVal = *srcVal;
+ continue;
}
+ srcFormat.colorToARGB(getColor(srcVal, src.format.bytesPerPixel, pal), aSrc, rSrc, gSrc, bSrc);
- if (srcAlpha != -1)
- aSrc = srcAlpha;
- if (aSrc == 0)
- aSrc = 0xff;
-
- if (aSrc != 0xff) {
- if (useTint) {
- aDest = 0xff;
- rDest = static_cast<uint8>(tintRed);
- gDest = static_cast<uint8>(tintGreen);
- bDest = static_cast<uint8>(tintBlue);
- } else {
- // Get the pixel at the destination, to check if it's transparent.
- // Transparent pixels can be considered to be 0 alpha
- format.colorToARGB(format.bytesPerPixel == 2 ?
- *(uint16 *)destVal : *(uint32 *)destVal, aDest, rDest, gDest, bDest);
- if (IS_TRANSPARENT(rDest, gDest, bDest))
- aDest = 0;
- }
- } else {
- // Source is opaque, so just treat destination as transparent
- aDest = 0;
+ // FIXME: I had at least one case in Black Cauldron Remake when a screen
+ // clear was all the pink transparent color because blit was called,
+ // and in Allegro, blit doesn't skip transparent pixels. So for now,
+ // I hacked in an extra check to still skip them if blitting to screen
+ if (skipTrans || isScreenDest) {
+ if (src.format.bytesPerPixel == 1) {
+ if (!isScreenDest && *srcVal == 0)
+ continue;
+ } else if (IS_TRANSPARENT(rSrc, gSrc, bSrc))
+ continue;
}
- if (aDest != 0 && aSrc != 0xff) {
- // Alpha blender
- double sAlpha = (double)aSrc / 255.0;
- double dAlpha = (double)aDest / 255.0;
- dAlpha *= (1.0 - sAlpha);
- rDest = static_cast<uint8>((rSrc * sAlpha + rDest * dAlpha) / (sAlpha + dAlpha));
- gDest = static_cast<uint8>((gSrc * sAlpha + gDest * dAlpha) / (sAlpha + dAlpha));
- bDest = static_cast<uint8>((bSrc * sAlpha + bDest * dAlpha) / (sAlpha + dAlpha));
- aDest = static_cast<uint8>(255. * (sAlpha + dAlpha));
- } else {
+ if (srcAlpha == -1) {
+ // This means we don't use blending.
+ aDest = aSrc;
rDest = rSrc;
gDest = gSrc;
bDest = bSrc;
- aDest = aSrc;
+ } else {
+ if (useTint) {
+ rDest = rSrc;
+ gDest = gSrc;
+ bDest = bSrc;
+ aDest = aSrc;
+ rSrc = tintRed;
+ gSrc = tintGreen;
+ bSrc = tintBlue;
+ aSrc = srcAlpha;
+ } else {
+ // TODO: move this to blendPixel to only do it when needed?
+ format.colorToARGB(getColor(destVal, format.bytesPerPixel, nullptr), aDest, rDest, gDest, bDest);
+ }
+ blendPixel(aSrc, rSrc, gSrc, bSrc, aDest, rDest, gDest, bDest, srcAlpha);
}
- // FIXME: I had at least one case in Black Cauldron Remake when a screen
- // clear was all the pink transparent color because blit was called,
- // and in Allegro, blit doesn't skip transparent pixels. So for now,
- // I hacked in an extra check to still skip them if blitting to screen
- if (!IS_TRANSPARENT(rSrc, gSrc, bSrc) || (!skipTrans && !isScreenDest)) {
- uint32 pixel = format.ARGBToColor(aDest, rDest, gDest, bDest);
-
- if (format.bytesPerPixel == 4)
- *(uint32 *)destVal = pixel;
- else
- *(uint16 *)destVal = pixel;
- }
+ uint32 pixel = format.ARGBToColor(aDest, rDest, gDest, bDest);
+ if (format.bytesPerPixel == 4)
+ *(uint32 *)destVal = pixel;
+ else
+ *(uint16 *)destVal = pixel;
}
}
}
+void BITMAP::blendPixel(uint8 aSrc, uint8 rSrc, uint8 gSrc, uint8 bSrc, uint8 &aDest, uint8 &rDest, uint8 &gDest, uint8 &bDest, uint32 alpha) const {
+ if (IS_TRANSPARENT(rDest, gDest, bDest)) {
+ aDest = aSrc;
+ rDest = rSrc;
+ gDest = gSrc;
+ bDest = bSrc;
+ return;
+ }
+ switch(_blender_mode) {
+ case kSourceAlphaBlender:
+ blendSourceAlpha(aSrc, rSrc, gSrc, bSrc, aDest, rDest, gDest, bDest, alpha);
+ break;
+ case kArgbToArgbBlender:
+ blendArgbToArgb(aSrc, rSrc, gSrc, bSrc, aDest, rDest, gDest, bDest, alpha);
+ break;
+ case kArgbToRgbBlender:
+ blendArgbToRgb(aSrc, rSrc, gSrc, bSrc, aDest, rDest, gDest, bDest, alpha);
+ break;
+ case kRgbToArgbBlender:
+ blendRgbToArgb(aSrc, rSrc, gSrc, bSrc, aDest, rDest, gDest, bDest, alpha);
+ break;
+ case kRgbToRgbBlender:
+ blendRgbToRgb(aSrc, rSrc, gSrc, bSrc, aDest, rDest, gDest, bDest, alpha);
+ break;
+ case kAlphaPreservedBlenderMode:
+ blendPreserveAlpha(aSrc, rSrc, gSrc, bSrc, aDest, rDest, gDest, bDest, alpha);
+ break;
+ case kOpaqueBlenderMode:
+ blendOpaque(aSrc, rSrc, gSrc, bSrc, aDest, rDest, gDest, bDest, alpha);
+ break;
+ case kAdditiveBlenderMode:
+ blendAdditiveAlpha(aSrc, rSrc, gSrc, bSrc, aDest, rDest, gDest, bDest, alpha);
+ break;
+ case kTintBlenderMode:
+ blendTintSprite(aSrc, rSrc, gSrc, bSrc, aDest, rDest, gDest, bDest, alpha, false);
+ break;
+ case kTintLightBlenderMode:
+ blendTintSprite(aSrc, rSrc, gSrc, bSrc, aDest, rDest, gDest, bDest, alpha, true);
+ break;
+ }
+}
+
+void BITMAP::blendTintSprite(uint8 aSrc, uint8 rSrc, uint8 gSrc, uint8 bSrc, uint8 &aDest, uint8 &rDest, uint8 &gDest, uint8 &bDest, uint32 alpha, bool light) const {
+ // Used from draw_lit_sprite after set_blender_mode(kTintBlenderMode or kTintLightBlenderMode)
+ // Original blender function: _myblender_color32 and _myblender_color32_light
+ float xh, xs, xv;
+ float yh, ys, yv;
+ int r, g, b;
+ rgb_to_hsv(rSrc, gSrc, bSrc, &xh, &xs, &xv);
+ rgb_to_hsv(rDest, gDest, bDest, &yh, &ys, &yv);
+ if (light) {
+ // adjust luminance
+ yv -= (1.0 - ((float)alpha / 250.0));
+ if (yv < 0.0)
+ yv = 0.0;
+ }
+ hsv_to_rgb(xh, xs, yv, &r, &g, &b);
+ rDest = static_cast<uint8>(r & 0xff);
+ gDest = static_cast<uint8>(g & 0xff);
+ bDest = static_cast<uint8>(b & 0xff);
+ // Preserve value in aDest
+}
+
/*-------------------------------------------------------------------*/
/**
diff --git a/engines/ags/lib/allegro/surface.h b/engines/ags/lib/allegro/surface.h
index 7c7dc1b536..c191f37a10 100644
--- a/engines/ags/lib/allegro/surface.h
+++ b/engines/ags/lib/allegro/surface.h
@@ -102,6 +102,163 @@ public:
const Common::Rect &destRect, bool horizFlip, bool vertFlip,
bool skipTrans, int srcAlpha, int tintRed = -1, int tintGreen = -1,
int tintBlue = -1);
+
+private:
+ // True color blender functions
+ // In Allegro all the blender functions are of the form
+ // unsigned int blender_func(unsigned long x, unsigned long y, unsigned long n)
+ // when x is the sprite color, y the destination color, and n an alpha value
+
+ void blendPixel(uint8 aSrc, uint8 rSrc, uint8 gSrc, uint8 bSrc, uint8 &aDest, uint8 &rDest, uint8 &gDest, uint8 &bDest, uint32 alpha) const;
+
+
+ inline void rgbBlend(uint8 rSrc, uint8 gSrc, uint8 bSrc, uint8 &rDest, uint8 &gDest, uint8 &bDest, uint32 alpha) const {
+ // Original logic has uint32 src and dst colors as RGB888
+ // if (alpha)
+ // ++alpha;
+ // uint32 res = ((src & 0xFF00FF) - (dst & 0xFF00FF)) * alpha / 256 + dst;
+ // dst &= 0x00FF00;
+ // src &= 0x00FF00;
+ // uint32 g = (src - dst) * alpha / 256 + dst;
+ // return (res & 0xFF00FF) | (g & 0x00FF00)
+ double sAlpha = (double)(alpha & 0xff) / 255.0;
+ rDest = static_cast<uint8>(rSrc * sAlpha + rDest * (1. - sAlpha));
+ gDest = static_cast<uint8>(gSrc * sAlpha + gDest * (1. - sAlpha));
+ bDest = static_cast<uint8>(bSrc * sAlpha + bDest * (1. - sAlpha));
+ }
+
+ inline void argbBlend(uint32 aSrc, uint8 rSrc, uint8 gSrc, uint8 bSrc, uint8 &aDest, uint8 &rDest, uint8 &gDest, uint8 &bDest) const {
+ // Original logic has uint32 src and dst colors as ARGB8888
+ // ++src_alpha;
+ // uint32 dst_alpha = geta32(dst);
+ // if (dst_alpha)
+ // ++dst_alpha;
+ // uint32 dst_g = (dst & 0x00FF00) * dst_alpha / 256;
+ // dst = (dst & 0xFF00FF) * dst_alpha / 256;
+ // dst_g = (((src & 0x00FF00) - (dst_g & 0x00FF00)) * src_alpha / 256 + dst_g) & 0x00FF00;
+ // dst = (((src & 0xFF00FF) - (dst & 0xFF00FF)) * src_alpha / 256 + dst) & 0xFF00FF;
+ // dst_alpha = 256 - (256 - src_alpha) * (256 - dst_alpha) / 256;
+ // src_alpha = /* 256 * 256 == */ 0x10000 / dst_alpha;
+ // dst_g = (dst_g * src_alpha / 256) & 0x00FF00;
+ // dst = (dst * src_alpha / 256) & 0xFF00FF;
+ // return dst | dst_g | (--dst_alpha << 24);
+ double sAlpha = (double)(aSrc & 0xff) / 255.0;
+ double dAlpha = (double)aDest / 255.0;
+ dAlpha *= (1.0 - sAlpha);
+ rDest = static_cast<uint8>((rSrc * sAlpha + rDest * dAlpha) / (sAlpha + dAlpha));
+ gDest = static_cast<uint8>((gSrc * sAlpha + gDest * dAlpha) / (sAlpha + dAlpha));
+ bDest = static_cast<uint8>((bSrc * sAlpha + bDest * dAlpha) / (sAlpha + dAlpha));
+ aDest = static_cast<uint8>(255. * (sAlpha + dAlpha));
+ }
+
+ // kRgbToRgbBlender
+ inline void blendRgbToRgb(uint8 aSrc, uint8 rSrc, uint8 gSrc, uint8 bSrc, uint8 &aDest, uint8 &rDest, uint8 &gDest, uint8 &bDest, uint32 alpha) const {
+ // Default mode for set_trans_blender
+ rgbBlend(rSrc, gSrc, bSrc, rDest, gDest, bDest, alpha);
+ // Original doesn't set alpha (so it is 0), but the function is not meant to be used
+ // on bitmap with transparency. Should we set alpha to 0xff?
+ aDest = 0;
+ }
+
+ // kAlphaPreservedBlenderMode
+ inline void blendPreserveAlpha(uint8 aSrc, uint8 rSrc, uint8 gSrc, uint8 bSrc, uint8 &aDest, uint8 &rDest, uint8 &gDest, uint8 &bDest, uint32 alpha) const {
+ // Original blender function: _myblender_alpha_trans24
+ // Like blendRgbToRgb, but result as the same alpha as destColor
+ rgbBlend(rSrc, gSrc, bSrc, rDest, gDest, bDest, alpha);
+ // Preserve value in aDest
+ }
+
+ // kArgbToArgbBlender
+ inline void blendArgbToArgb(uint8 aSrc, uint8 rSrc, uint8 gSrc, uint8 bSrc, uint8 &aDest, uint8 &rDest, uint8 &gDest, uint8 &bDest, uint32 alpha) const {
+ // Original blender functions: _argb2argb_blender
+ if (alpha == 0)
+ alpha = aSrc;
+ else
+ alpha = aSrc * ((alpha & 0xff) + 1) / 256;
+ if (alpha != 0)
+ argbBlend(alpha, rSrc, gSrc, bSrc, aDest, rDest, gDest, bDest);
+ }
+
+ // kRgbToArgbBlender
+ inline void blendRgbToArgb(uint8 aSrc, uint8 rSrc, uint8 gSrc, uint8 bSrc, uint8 &aDest, uint8 &rDest, uint8 &gDest, uint8 &bDest, uint32 alpha) const {
+ // Original blender function: _rgb2argb_blenders
+ if (alpha == 0 || alpha == 0xff) {
+ aDest = 0xff;
+ rDest = rSrc;
+ gDest = gSrc;
+ bDest = bSrc;
+ } else
+ argbBlend(alpha, rSrc, gSrc, bSrc, aDest, rDest, gDest, bDest);
+ }
+
+ // kArgbToRgbBlender
+ inline void blendArgbToRgb(uint8 aSrc, uint8 rSrc, uint8 gSrc, uint8 bSrc, uint8 &aDest, uint8 &rDest, uint8 &gDest, uint8 &bDest, uint32 alpha) const {
+ // Original blender function: _argb2rgb_blender
+ if (alpha == 0)
+ alpha = aSrc;
+ else
+ alpha = aSrc * ((alpha & 0xff) + 1) / 256;
+ rgbBlend(rSrc, gSrc, bSrc, rDest, gDest, bDest, alpha);
+ // Original doesn't set alpha (so it is 0), but the function is not meant to be used
+ // on bitmap with transparency. Should we set alpha to 0xff?
+ aDest = 0;
+ }
+
+ // kOpaqueBlenderMode
+ inline void blendOpaque(uint8 aSrc, uint8 rSrc, uint8 gSrc, uint8 bSrc, uint8 &aDest, uint8 &rDest, uint8 &gDest, uint8 &bDest, uint32 alpha) const {
+ // Original blender function: _opaque_alpha_blender
+ aDest = 0xff;
+ rDest = rSrc;
+ gDest = gSrc;
+ bDest = bSrc;
+ }
+
+ // kSourceAlphaBlender
+ inline void blendSourceAlpha(uint8 aSrc, uint8 rSrc, uint8 gSrc, uint8 bSrc, uint8 &aDest, uint8 &rDest, uint8 &gDest, uint8 &bDest, uint32 alpha) const {
+ // Used after set_alpha_blender
+ // Uses alpha from source. Result is fully opaque
+ // TODO: Understand why the line below is needed. It is not there in the original code.
+ // But without it we have some display issue for example with some text at the start
+ // of Blackwell Deception. We may incorrectly set the alpha on bitmaps in some cases
+ // causing them to be fully transparent when they should not.
+ if (aSrc == 0)
+ aSrc = 0xff;
+ rgbBlend(rSrc, gSrc, bSrc, rDest, gDest, bDest, aSrc);
+ // Original doesn't set alpha (so it is 0), but the function is not meant to be used
+ // on bitmap with transparency. Should we set alpha to 0xff?
+ aDest = 0;
+ }
+
+ // kAdditiveBlenderMode
+ inline void blendAdditiveAlpha(uint8 aSrc, uint8 rSrc, uint8 gSrc, uint8 bSrc, uint8 &aDest, uint8 &rDest, uint8 &gDest, uint8 &bDest, uint32 alpha) const {
+ // Original blender function: _additive_alpha_copysrc_blender
+ rDest = rSrc;
+ gDest = gSrc;
+ bDest = bSrc;
+ uint32 a = (uint32)aSrc + (uint32)aDest;
+ if (a > 0xff)
+ aDest = 0xff;
+ else
+ aDest = static_cast<uint8>(a);
+ }
+
+ // kTintBlenderMode and kTintLightBlenderMode
+ void blendTintSprite(uint8 aSrc, uint8 rSrc, uint8 gSrc, uint8 bSrc, uint8 &aDest, uint8 &rDest, uint8 &gDest, uint8 &bDest, uint32 alpha, bool light) const ;
+
+
+ inline uint32 getColor(const byte *data, byte bpp, uint32* palette) const {
+ switch (bpp) {
+ case 1:
+ assert(palette);
+ return palette[*data];
+ case 2:
+ return *(const uint16 *)data;
+ case 4:
+ return *(const uint32 *)data;
+ default:
+ error("Unknown format");
+ }
+ }
};
/**
Commit: 51c9a9eb84c4c80586c05d88e592f34626e317bb
https://github.com/scummvm/scummvm/commit/51c9a9eb84c4c80586c05d88e592f34626e317bb
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2021-03-04T00:19:00Z
Commit Message:
AGS: Remove allegro blender functions
Blending modes was reimplemented and we no longer need the
original functions.
Changed paths:
R engines/ags/lib/allegro/colblend.cpp
R engines/ags/lib/allegro/colblend.h
engines/ags/engine/gfx/ali3dscummvm.cpp
engines/ags/engine/gfx/blender.cpp
engines/ags/engine/gfx/blender.h
engines/ags/engine/gfx/gfx_util.cpp
engines/ags/lib/allegro.h
engines/ags/lib/allegro/aintern.h
engines/ags/lib/allegro/color.h
engines/ags/lib/allegro/graphics.cpp
engines/ags/module.mk
diff --git a/engines/ags/engine/gfx/ali3dscummvm.cpp b/engines/ags/engine/gfx/ali3dscummvm.cpp
index 3d4628bbbf..fe9253c6a1 100644
--- a/engines/ags/engine/gfx/ali3dscummvm.cpp
+++ b/engines/ags/engine/gfx/ali3dscummvm.cpp
@@ -72,7 +72,6 @@ bool ALScummVMGfxModeList::GetMode(int index, DisplayMode &mode) const {
return false;
}
-unsigned long _trans_alpha_blender32(unsigned long x, unsigned long y, unsigned long n);
RGB faded_out_palette[256];
@@ -713,26 +712,6 @@ void ALScummVMGraphicsDriver::BoxOutEffect(bool blackingOut, int speed, int dela
}
// end fading routines
-// add the alpha values together, used for compositing alpha images
-unsigned long _trans_alpha_blender32(unsigned long x, unsigned long y, unsigned long n) {
- unsigned long res, g;
-
- n = (n * geta32(x)) / 256;
-
- if (n)
- n++;
-
- res = ((x & 0xFF00FF) - (y & 0xFF00FF)) * n / 256 + y;
- y &= 0xFF00;
- x &= 0xFF00;
- g = (x - y) * n / 256 + y;
-
- res &= 0xFF00FF;
- g &= 0xFF00;
-
- return res | g;
-}
-
ALScummVMGraphicsFactory *ALScummVMGraphicsFactory::_factory = nullptr;
diff --git a/engines/ags/engine/gfx/blender.cpp b/engines/ags/engine/gfx/blender.cpp
index 17007d9852..04cd56251c 100644
--- a/engines/ags/engine/gfx/blender.cpp
+++ b/engines/ags/engine/gfx/blender.cpp
@@ -24,239 +24,15 @@
#include "ags/engine/gfx/blender.h"
#include "ags/shared/util/wgt2allg.h"
#include "ags/lib/allegro/color.h"
-#include "ags/lib/allegro/colblend.h"
namespace AGS3 {
-// the allegro "inline" ones are not actually inline, so #define
-// over them to speed it up
-#define getr32(xx) ((xx >> _rgb_r_shift_32) & 0xFF)
-#define getg32(xx) ((xx >> _rgb_g_shift_32) & 0xFF)
-#define getb32(xx) ((xx >> _rgb_b_shift_32) & 0xFF)
-#define geta32(xx) ((xx >> _rgb_a_shift_32) & 0xFF)
-#define makeacol32(r,g,b,a) ((r << _rgb_r_shift_32) | (g << _rgb_g_shift_32) | (b << _rgb_b_shift_32) | (a << _rgb_a_shift_32))
-
-// Take hue and saturation of blend colour, luminance of image
-unsigned long _myblender_color15_light(unsigned long x, unsigned long y, unsigned long n) {
- float xh, xs, xv;
- float yh, ys, yv;
- int r, g, b;
-
- rgb_to_hsv(getr15(x), getg15(x), getb15(x), &xh, &xs, &xv);
- rgb_to_hsv(getr15(y), getg15(y), getb15(y), &yh, &ys, &yv);
-
- // adjust luminance
- yv -= (1.0 - ((float)n / 250.0));
- if (yv < 0.0) yv = 0.0;
-
- hsv_to_rgb(xh, xs, yv, &r, &g, &b);
-
- return makecol15(r, g, b);
-}
-
-// Take hue and saturation of blend colour, luminance of image
-// n is the last parameter passed to draw_lit_sprite
-unsigned long _myblender_color16_light(unsigned long x, unsigned long y, unsigned long n) {
- float xh, xs, xv;
- float yh, ys, yv;
- int r, g, b;
-
- rgb_to_hsv(getr16(x), getg16(x), getb16(x), &xh, &xs, &xv);
- rgb_to_hsv(getr16(y), getg16(y), getb16(y), &yh, &ys, &yv);
-
- // adjust luminance
- yv -= (1.0 - ((float)n / 250.0));
- if (yv < 0.0) yv = 0.0;
-
- hsv_to_rgb(xh, xs, yv, &r, &g, &b);
-
- return makecol16(r, g, b);
-}
-
-// Take hue and saturation of blend colour, luminance of image
-unsigned long _myblender_color32_light(unsigned long x, unsigned long y, unsigned long n) {
- float xh, xs, xv;
- float yh, ys, yv;
- int r, g, b;
-
- rgb_to_hsv(getr32(x), getg32(x), getb32(x), &xh, &xs, &xv);
- rgb_to_hsv(getr32(y), getg32(y), getb32(y), &yh, &ys, &yv);
-
- // adjust luminance
- yv -= (1.0 - ((float)n / 250.0));
- if (yv < 0.0) yv = 0.0;
-
- hsv_to_rgb(xh, xs, yv, &r, &g, &b);
-
- return makeacol32(r, g, b, geta32(y));
-}
-
-// Take hue and saturation of blend colour, luminance of image
-unsigned long _myblender_color15(unsigned long x, unsigned long y, unsigned long n) {
- float xh, xs, xv;
- float yh, ys, yv;
- int r, g, b;
-
- rgb_to_hsv(getr15(x), getg15(x), getb15(x), &xh, &xs, &xv);
- rgb_to_hsv(getr15(y), getg15(y), getb15(y), &yh, &ys, &yv);
-
- hsv_to_rgb(xh, xs, yv, &r, &g, &b);
-
- return makecol15(r, g, b);
-}
-
-// Take hue and saturation of blend colour, luminance of image
-unsigned long _myblender_color16(unsigned long x, unsigned long y, unsigned long n) {
- float xh, xs, xv;
- float yh, ys, yv;
- int r, g, b;
-
- rgb_to_hsv(getr16(x), getg16(x), getb16(x), &xh, &xs, &xv);
- rgb_to_hsv(getr16(y), getg16(y), getb16(y), &yh, &ys, &yv);
-
- hsv_to_rgb(xh, xs, yv, &r, &g, &b);
-
- return makecol16(r, g, b);
-}
-
-// Take hue and saturation of blend colour, luminance of image
-unsigned long _myblender_color32(unsigned long x, unsigned long y, unsigned long n) {
- float xh, xs, xv;
- float yh, ys, yv;
- int r, g, b;
-
- rgb_to_hsv(getr32(x), getg32(x), getb32(x), &xh, &xs, &xv);
- rgb_to_hsv(getr32(y), getg32(y), getb32(y), &yh, &ys, &yv);
-
- hsv_to_rgb(xh, xs, yv, &r, &g, &b);
-
- return makeacol32(r, g, b, geta32(y));
-}
-
-// trans24 blender, but preserve alpha channel from image
-unsigned long _myblender_alpha_trans24(unsigned long x, unsigned long y, unsigned long n) {
- unsigned long res, g, alph;
-
- if (n)
- n++;
-
- alph = y & 0xff000000;
- y &= 0x00ffffff;
-
- res = ((x & 0xFF00FF) - (y & 0xFF00FF)) * n / 256 + y;
- y &= 0xFF00;
- x &= 0xFF00;
- g = (x - y) * n / 256 + y;
-
- res &= 0xFF00FF;
- g &= 0xFF00;
-
- return res | g | alph;
-}
-
void set_my_trans_blender(int r, int g, int b, int a) {
// use standard allegro 15 and 16 bit blenders, but customize
// the 32-bit one to preserve the alpha channel
set_blender_mode(kAlphaPreservedBlenderMode, r, g, b, a);
}
-// plain copy source to destination
-// assign new alpha value as a summ of alphas.
-unsigned long _additive_alpha_copysrc_blender(unsigned long x, unsigned long y, unsigned long n) {
- unsigned long newAlpha = ((x & 0xff000000) >> 24) + ((y & 0xff000000) >> 24);
-
- if (newAlpha > 0xff) newAlpha = 0xff;
-
- return (newAlpha << 24) | (x & 0x00ffffff);
-}
-
-FORCEINLINE unsigned long argb2argb_blend_core(unsigned long src_col, unsigned long dst_col, unsigned long src_alpha) {
- unsigned long dst_g, dst_alpha;
- src_alpha++;
- dst_alpha = geta32(dst_col);
- if (dst_alpha)
- dst_alpha++;
-
- // dst_g now contains the green hue from destination color
- dst_g = (dst_col & 0x00FF00) * dst_alpha / 256;
- // dst_col now contains the red & blue hues from destination color
- dst_col = (dst_col & 0xFF00FF) * dst_alpha / 256;
-
- // res_g now contains the green hue of the pre-final color
- dst_g = (((src_col & 0x00FF00) - (dst_g & 0x00FF00)) * src_alpha / 256 + dst_g) & 0x00FF00;
- // res_rb now contains the red & blue hues of the pre-final color
- dst_col = (((src_col & 0xFF00FF) - (dst_col & 0xFF00FF)) * src_alpha / 256 + dst_col) & 0xFF00FF;
-
- // dst_alpha now contains the final alpha
- // we assume that final alpha will never be zero
- dst_alpha = 256 - (256 - src_alpha) * (256 - dst_alpha) / 256;
- // src_alpha is now the final alpha factor made for being multiplied by,
- // instead of divided by: this makes it possible to use it in faster
- // calculation below
- src_alpha = /* 256 * 256 == */ 0x10000 / dst_alpha;
-
- // setting up final color hues
- dst_g = (dst_g * src_alpha / 256) & 0x00FF00;
- dst_col = (dst_col * src_alpha / 256) & 0xFF00FF;
- return dst_col | dst_g | (--dst_alpha << 24);
-}
-
-// blend source to destination with respect to source and destination alphas;
-// assign new alpha value as a multiplication of translucenses.
-// combined_alpha = front.alpha + back.alpha * (1 - front.alpha);
-// combined_rgb = (front.rgb * front.alpha + back.rgb * (1 - front.alpha) * back.alpha) / combined_alpha;
-unsigned long _argb2argb_blender(unsigned long src_col, unsigned long dst_col, unsigned long src_alpha) {
- if (src_alpha > 0)
- src_alpha = geta32(src_col) * ((src_alpha & 0xFF) + 1) / 256;
- else
- src_alpha = geta32(src_col);
- if (src_alpha == 0)
- return dst_col;
- return argb2argb_blend_core(src_col, dst_col, src_alpha);
-}
-
-unsigned long _rgb2argb_blender(unsigned long src_col, unsigned long dst_col, unsigned long src_alpha) {
- if (src_alpha == 0 || src_alpha == 0xFF)
- return src_col | 0xFF000000;
- return argb2argb_blend_core(src_col | 0xFF000000, dst_col, src_alpha);
-}
-
-unsigned long _argb2rgb_blender(unsigned long src_col, unsigned long dst_col, unsigned long src_alpha) {
- unsigned long res, g;
-
- if (src_alpha > 0)
- src_alpha = geta32(src_col) * ((src_alpha & 0xFF) + 1) / 256;
- else
- src_alpha = geta32(src_col);
- if (src_alpha)
- src_alpha++;
-
- res = ((src_col & 0xFF00FF) - (dst_col & 0xFF00FF)) * src_alpha / 256 + dst_col;
- dst_col &= 0xFF00;
- src_col &= 0xFF00;
- g = (src_col - dst_col) * src_alpha / 256 + dst_col;
-
- res &= 0xFF00FF;
- g &= 0xFF00;
-
- return res | g;
-}
-
-// Based on _blender_alpha16, but keep source pixel if dest is transparent
-unsigned long skiptranspixels_blender_alpha16(unsigned long x, unsigned long y, unsigned long n) {
- unsigned long result;
- if ((y & 0xFFFF) == 0xF81F)
- return x;
- n = geta32(x);
- if (n)
- n = (n + 1) / 8;
- x = makecol16(getr32(x), getg32(x), getb32(x));
- x = (x | (x << 16)) & 0x7E0F81F;
- y = ((y & 0xFFFF) | (y << 16)) & 0x7E0F81F;
- result = ((x - y) * n / 32 + y) & 0x7E0F81F;
- return ((result & 0xFFFF) | (result >> 16));
-}
-
void set_additive_alpha_blender() {
set_blender_mode(kAdditiveBlenderMode, 0, 0, 0, 0);
}
@@ -265,11 +41,6 @@ void set_argb2argb_blender(int alpha) {
set_blender_mode(kArgbToArgbBlender, 0, 0, 0, alpha);
}
-// sets the alpha channel to opaque. used when drawing a non-alpha sprite onto an alpha-sprite
-unsigned long _opaque_alpha_blender(unsigned long x, unsigned long y, unsigned long n) {
- return x | 0xff000000;
-}
-
void set_opaque_alpha_blender() {
set_blender_mode(kOpaqueBlenderMode, 0, 0, 0, 0);
}
diff --git a/engines/ags/engine/gfx/blender.h b/engines/ags/engine/gfx/blender.h
index 45b8fa5468..9277920348 100644
--- a/engines/ags/engine/gfx/blender.h
+++ b/engines/ags/engine/gfx/blender.h
@@ -31,40 +31,9 @@
namespace AGS3 {
-//
-// Allegro's standard alpha blenders result in:
-// - src and dst RGB are combined proportionally to src alpha
-// (src.rgb * src.alpha + dst.rgb * (1 - dst.alpha));
-// - final alpha is zero.
-// This blender is suggested for use with opaque destinations
-// (ones without alpha channel).
-//
-/* Declared in Allegro's color.h:
-void set_alpha_blender();
-*/
-
-unsigned long _myblender_color15(unsigned long x, unsigned long y, unsigned long n);
-unsigned long _myblender_color16(unsigned long x, unsigned long y, unsigned long n);
-unsigned long _myblender_color32(unsigned long x, unsigned long y, unsigned long n);
-unsigned long _myblender_color15_light(unsigned long x, unsigned long y, unsigned long n);
-unsigned long _myblender_color16_light(unsigned long x, unsigned long y, unsigned long n);
-unsigned long _myblender_color32_light(unsigned long x, unsigned long y, unsigned long n);
// Customizable alpha blender that uses the supplied alpha value as src alpha,
// and preserves destination's alpha channel (if there was one);
void set_my_trans_blender(int r, int g, int b, int a);
-// Argb2argb alpha blender combines RGBs proportionally to src alpha, but also
-// applies dst alpha factor to the dst RGB used in the merge;
-// The final alpha is calculated by multiplying two translucences (1 - .alpha).
-// Custom alpha parameter, when not zero, is treated as fraction of source
-// alpha that has to be used in color blending.
-unsigned long _argb2argb_blender(unsigned long src_col, unsigned long dst_col, unsigned long src_alpha);
-// Argb2rgb blender combines RGBs proportionally to src alpha, but discards alpha in the end.
-// It is almost a clone of Allegro's _blender_alpha32, except it also applies optional overall alpha.
-unsigned long _argb2rgb_blender(unsigned long src_col, unsigned long dst_col, unsigned long src_alpha);
-// Rgb2argb blender treats all src pixels as if having opaque alpha.
-unsigned long _rgb2argb_blender(unsigned long src_col, unsigned long dst_col, unsigned long src_alpha);
-// Sets the alpha channel to opaque. Used when drawing a non-alpha sprite onto an alpha-sprite.
-unsigned long _opaque_alpha_blender(unsigned long src_col, unsigned long dst_col, unsigned long src_alpha);
// Additive alpha blender plain copies src over, applying a summ of src and
// dst alpha values.
diff --git a/engines/ags/engine/gfx/gfx_util.cpp b/engines/ags/engine/gfx/gfx_util.cpp
index 301d657592..298079fc2c 100644
--- a/engines/ags/engine/gfx/gfx_util.cpp
+++ b/engines/ags/engine/gfx/gfx_util.cpp
@@ -51,9 +51,6 @@ Bitmap *ConvertBitmap(Bitmap *src, int dst_color_depth) {
return src;
}
-
-typedef BLENDER_FUNC PfnBlenderCb;
-
struct BlendModeSetter {
// Blender setter for destination with and without alpha channel;
// assign kRgbToRgbBlender if not supported
diff --git a/engines/ags/lib/allegro.h b/engines/ags/lib/allegro.h
index ea838a54ea..5bbccaae93 100644
--- a/engines/ags/lib/allegro.h
+++ b/engines/ags/lib/allegro.h
@@ -27,7 +27,6 @@
#include "ags/lib/allegro/alconfig.h"
#include "ags/lib/allegro/base.h"
-#include "ags/lib/allegro/colblend.h"
#include "ags/lib/allegro/color.h"
#include "ags/lib/allegro/config.h"
#include "ags/lib/allegro/draw.h"
diff --git a/engines/ags/lib/allegro/aintern.h b/engines/ags/lib/allegro/aintern.h
index 37ac742507..338805ba04 100644
--- a/engines/ags/lib/allegro/aintern.h
+++ b/engines/ags/lib/allegro/aintern.h
@@ -30,14 +30,6 @@ namespace AGS3 {
extern int _color_depth;
-/* truecolor blending functions */
-AL_VAR(BLENDER_FUNC, _blender_func15);
-AL_VAR(BLENDER_FUNC, _blender_func16);
-AL_VAR(BLENDER_FUNC, _blender_func24);
-AL_VAR(BLENDER_FUNC, _blender_func32);
-
-AL_VAR(int, _blender_alpha);
-
} // namespace AGS3
#endif
diff --git a/engines/ags/lib/allegro/colblend.cpp b/engines/ags/lib/allegro/colblend.cpp
deleted file mode 100644
index 20581c2f21..0000000000
--- a/engines/ags/lib/allegro/colblend.cpp
+++ /dev/null
@@ -1,116 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#include "ags/lib/allegro/colblend.h"
-#include "ags/lib/allegro/color.h"
-
-namespace AGS3 {
-
-unsigned long _blender_black(unsigned long x, unsigned long y, unsigned long n) {
- return 0;
-}
-
-unsigned long _blender_trans15(unsigned long x, unsigned long y, unsigned long n) {
- unsigned long result;
-
- if (n)
- n = (n + 1) / 8;
-
- x = ((x & 0xFFFF) | (x << 16)) & 0x3E07C1F;
- y = ((y & 0xFFFF) | (y << 16)) & 0x3E07C1F;
-
- result = ((x - y) * n / 32 + y) & 0x3E07C1F;
-
- return ((result & 0xFFFF) | (result >> 16));
-}
-
-unsigned long _blender_trans16(unsigned long x, unsigned long y, unsigned long n) {
- unsigned long result;
-
- if (n)
- n = (n + 1) / 8;
-
- x = ((x & 0xFFFF) | (x << 16)) & 0x7E0F81F;
- y = ((y & 0xFFFF) | (y << 16)) & 0x7E0F81F;
-
- result = ((x - y) * n / 32 + y) & 0x7E0F81F;
-
- return ((result & 0xFFFF) | (result >> 16));
-}
-
-unsigned long _blender_alpha15(unsigned long x, unsigned long y, unsigned long n) {
- unsigned long result;
-
- n = geta32(x);
-
- if (n)
- n = (n + 1) / 8;
-
- x = makecol15(getr32(x), getg32(x), getb32(x));
-
- x = (x | (x << 16)) & 0x3E07C1F;
- y = ((y & 0xFFFF) | (y << 16)) & 0x3E07C1F;
-
- result = ((x - y) * n / 32 + y) & 0x3E07C1F;
-
- return ((result & 0xFFFF) | (result >> 16));
-}
-
-unsigned long _blender_alpha16(unsigned long x, unsigned long y, unsigned long n) {
- unsigned long result;
-
- n = geta32(x);
-
- if (n)
- n = (n + 1) / 8;
-
- x = makecol16(getr32(x), getg32(x), getb32(x));
-
- x = (x | (x << 16)) & 0x7E0F81F;
- y = ((y & 0xFFFF) | (y << 16)) & 0x7E0F81F;
-
- result = ((x - y) * n / 32 + y) & 0x7E0F81F;
-
- return ((result & 0xFFFF) | (result >> 16));
-}
-
-unsigned long _blender_alpha24(unsigned long x, unsigned long y, unsigned long n) {
- unsigned long xx = makecol24(getr32(x), getg32(x), getb32(x));
- unsigned long res, g;
-
- n = geta32(x);
-
- if (n)
- n++;
-
- res = ((xx & 0xFF00FF) - (y & 0xFF00FF)) * n / 256 + y;
- y &= 0xFF00;
- xx &= 0xFF00;
- g = (xx - y) * n / 256 + y;
-
- res &= 0xFF00FF;
- g &= 0xFF00;
-
- return res | g;
-}
-
-} // namespace AGS3
diff --git a/engines/ags/lib/allegro/colblend.h b/engines/ags/lib/allegro/colblend.h
deleted file mode 100644
index 60eaea8e32..0000000000
--- a/engines/ags/lib/allegro/colblend.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef AGS_LIB_ALLEGRO_COLBLEND_H
-#define AGS_LIB_ALLEGRO_COLBLEND_H
-
-#include "ags/lib/allegro/alconfig.h"
-
-namespace AGS3 {
-
-extern unsigned long _blender_black(unsigned long x, unsigned long y, unsigned long n);
-
-extern unsigned long _blender_trans15(unsigned long x, unsigned long y, unsigned long n);
-extern unsigned long _blender_trans16(unsigned long x, unsigned long y, unsigned long n);
-
-extern unsigned long _blender_alpha15(unsigned long x, unsigned long y, unsigned long n);
-extern unsigned long _blender_alpha16(unsigned long x, unsigned long y, unsigned long n);
-extern unsigned long _blender_alpha24(unsigned long x, unsigned long y, unsigned long n);
-
-} // namespace AGS3
-
-#endif
diff --git a/engines/ags/lib/allegro/color.h b/engines/ags/lib/allegro/color.h
index baa4808b17..fbbaf23901 100644
--- a/engines/ags/lib/allegro/color.h
+++ b/engines/ags/lib/allegro/color.h
@@ -133,8 +133,6 @@ AL_FUNC(void, create_rgb_table, (RGB_MAP *table, AL_CONST PALETTE pal, AL_METHOD
AL_FUNC(void, create_light_table, (COLOR_MAP *table, AL_CONST PALETTE pal, int r, int g, int b, AL_METHOD(void, callback, (int pos))));
AL_FUNC(void, create_trans_table, (COLOR_MAP *table, AL_CONST PALETTE pal, int r, int g, int b, AL_METHOD(void, callback, (int pos))));
-typedef AL_METHOD(unsigned long, BLENDER_FUNC, (unsigned long x, unsigned long y, unsigned long n));
-
AL_FUNC(void, set_blender_mode, (BlenderMode, int r, int g, int b, int a));
AL_FUNC(void, set_alpha_blender, (void));
AL_FUNC(void, set_trans_blender, (int r, int g, int b, int a));
diff --git a/engines/ags/lib/allegro/graphics.cpp b/engines/ags/lib/allegro/graphics.cpp
index f7b717f69c..518c76a1f4 100644
--- a/engines/ags/lib/allegro/graphics.cpp
+++ b/engines/ags/lib/allegro/graphics.cpp
@@ -27,13 +27,6 @@ namespace AGS3 {
int _color_depth;
-BLENDER_FUNC _blender_func15 = NULL; /* truecolor pixel blender routines */
-BLENDER_FUNC _blender_func16 = NULL;
-BLENDER_FUNC _blender_func24 = NULL;
-BLENDER_FUNC _blender_func32 = NULL;
-
-int _blender_alpha;
-
/* lookup table for scaling 5 bit colors up to 8 bits */
int _rgb_scale_5[32] = {
0, 8, 16, 24, 33, 41, 49, 57,
diff --git a/engines/ags/module.mk b/engines/ags/module.mk
index 128e7451d9..f03ea450fa 100644
--- a/engines/ags/module.mk
+++ b/engines/ags/module.mk
@@ -12,7 +12,6 @@ MODULE_OBJS = \
lib/aastr-0.1.1/aautil.o \
lib/alfont/alfont.o \
lib/allegro.o \
- lib/allegro/colblend.o \
lib/allegro/color.o \
lib/allegro/config.o \
lib/allegro/draw.o \
Commit: c1295f90d1a26d0d42f222f59946eb2427c96b21
https://github.com/scummvm/scummvm/commit/c1295f90d1a26d0d42f222f59946eb2427c96b21
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2021-03-04T00:19:00Z
Commit Message:
AGS: Fix handling of transparency when drawing paletted sprites
One test case for this is Trilby's Note that now render properly.
Changed paths:
engines/ags/lib/allegro/surface.cpp
diff --git a/engines/ags/lib/allegro/surface.cpp b/engines/ags/lib/allegro/surface.cpp
index 50a6750246..570beddf24 100644
--- a/engines/ags/lib/allegro/surface.cpp
+++ b/engines/ags/lib/allegro/surface.cpp
@@ -130,9 +130,10 @@ void BITMAP::draw(const BITMAP *srcBitmap, const Common::Rect &srcRect,
VGA_COLOR_TRANS(_current_palette[i].g),
VGA_COLOR_TRANS(_current_palette[i].b));
srcFormat = format;
- // TODO: check if the line below is correct. If it is correct, we can simplify the skipTrans
- // below as we can use IS_TRANSPARENT() can be used for the 1 bytePerPixel case as well
- pal[0] = format.RGBToColor(0xff, 0, 0xff);
+ // If we are skipping transparency, color 0 is skipped.
+ // Set it to transparent color to simplify the check below.
+ if (skipTrans)
+ pal[0] = format.RGBToColor(0xff, 0, 0xff);
}
for (int destY = destRect.top, yCtr = 0, scaleYCtr = 0; yCtr < destArea.h;
@@ -156,8 +157,8 @@ void BITMAP::draw(const BITMAP *srcBitmap, const Common::Rect &srcRect,
if (src.format.bytesPerPixel == 1 && format.bytesPerPixel == 1) {
// TODO: Need to skip transparent color if skip_trans is true?
- //if (!skipTrans || *srcVal != 0)
- *destVal = *srcVal;
+ if (!skipTrans || *srcVal != 0)
+ *destVal = *srcVal;
continue;
}
srcFormat.colorToARGB(getColor(srcVal, src.format.bytesPerPixel, pal), aSrc, rSrc, gSrc, bSrc);
@@ -166,13 +167,8 @@ void BITMAP::draw(const BITMAP *srcBitmap, const Common::Rect &srcRect,
// clear was all the pink transparent color because blit was called,
// and in Allegro, blit doesn't skip transparent pixels. So for now,
// I hacked in an extra check to still skip them if blitting to screen
- if (skipTrans || isScreenDest) {
- if (src.format.bytesPerPixel == 1) {
- if (!isScreenDest && *srcVal == 0)
- continue;
- } else if (IS_TRANSPARENT(rSrc, gSrc, bSrc))
- continue;
- }
+ if ((skipTrans || isScreenDest) && IS_TRANSPARENT(rSrc, gSrc, bSrc))
+ continue;
if (srcAlpha == -1) {
// This means we don't use blending.
Commit: 6b08906f25b9258afa320f3bc82f8b7b981270c8
https://github.com/scummvm/scummvm/commit/6b08906f25b9258afa320f3bc82f8b7b981270c8
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2021-03-04T00:19:00Z
Commit Message:
AGS: Remove hack to skip transparent color when blitting to screen
The previous commit to fix skipping transparent colors when
drawing a paletted sprite on paletted bitmap seems to have
fixed the original issue.
Changed paths:
engines/ags/lib/allegro/surface.cpp
diff --git a/engines/ags/lib/allegro/surface.cpp b/engines/ags/lib/allegro/surface.cpp
index 570beddf24..8d8c24da92 100644
--- a/engines/ags/lib/allegro/surface.cpp
+++ b/engines/ags/lib/allegro/surface.cpp
@@ -115,7 +115,6 @@ void BITMAP::draw(const BITMAP *srcBitmap, const Common::Rect &srcRect,
const int scaleX = SCALE_THRESHOLD * srcRect.width() / destRect.width();
const int scaleY = SCALE_THRESHOLD * srcRect.height() / destRect.height();
const int xDir = horizFlip ? -1 : 1;
- bool isScreenDest = dynamic_cast<Graphics::Screen *>(_owner);
bool useTint = (tintRed >= 0 && tintGreen >= 0 && tintBlue >= 0);
byte rSrc, gSrc, bSrc, aSrc;
@@ -163,11 +162,7 @@ void BITMAP::draw(const BITMAP *srcBitmap, const Common::Rect &srcRect,
}
srcFormat.colorToARGB(getColor(srcVal, src.format.bytesPerPixel, pal), aSrc, rSrc, gSrc, bSrc);
- // FIXME: I had at least one case in Black Cauldron Remake when a screen
- // clear was all the pink transparent color because blit was called,
- // and in Allegro, blit doesn't skip transparent pixels. So for now,
- // I hacked in an extra check to still skip them if blitting to screen
- if ((skipTrans || isScreenDest) && IS_TRANSPARENT(rSrc, gSrc, bSrc))
+ if (skipTrans && IS_TRANSPARENT(rSrc, gSrc, bSrc))
continue;
if (srcAlpha == -1) {
More information about the Scummvm-git-logs
mailing list