forked from chocolate-doom/chocolate-doom
-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
factor out all truecolor blending functions into their own source file
- Loading branch information
1 parent
5a3e8ef
commit a6560de
Showing
7 changed files
with
160 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// | ||
// Copyright(C) 1993-1996 Id Software, Inc. | ||
// Copyright(C) 2005-2014 Simon Howard | ||
// Copyright(C) 2015-2024 Fabian Greffrath | ||
// | ||
// 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. | ||
// | ||
// DESCRIPTION: | ||
// [crispy] Truecolor rendering | ||
// | ||
|
||
#include "config.h" | ||
|
||
#ifdef CRISPY_TRUECOLOR | ||
|
||
#include "crispy.h" | ||
#include "i_truecolor.h" | ||
|
||
const uint32_t (*blendfunc) (const uint32_t fg, const uint32_t bg) = I_BlendOverTranmap; | ||
|
||
typedef union | ||
{ | ||
uint32_t i; | ||
struct { | ||
uint8_t b; | ||
uint8_t g; | ||
uint8_t r; | ||
uint8_t a; | ||
}; | ||
} tcuint32_t; | ||
|
||
const uint32_t I_BlendAdd (const uint32_t bg_i, const uint32_t fg_i) | ||
{ | ||
tcuint32_t bg, fg, ret; | ||
|
||
bg.i = bg_i; | ||
fg.i = fg_i; | ||
|
||
ret.a = 0xFFU; | ||
ret.r = MIN(bg.r + fg.r, 0xFFU); | ||
ret.g = MIN(bg.g + fg.g, 0xFFU); | ||
ret.b = MIN(bg.b + fg.b, 0xFFU); | ||
|
||
return ret.i; | ||
} | ||
|
||
const uint32_t I_BlendDark (const uint32_t bg_i, const int d) | ||
{ | ||
tcuint32_t bg, ret; | ||
|
||
bg.i = bg_i; | ||
|
||
ret.a = 0xFFU; | ||
ret.r = (bg.r * d) >> 8; | ||
ret.g = (bg.g * d) >> 8; | ||
ret.b = (bg.b * d) >> 8; | ||
|
||
return ret.i; | ||
} | ||
|
||
const uint32_t I_BlendOver (const uint32_t bg_i, const uint32_t fg_i, const int amount) | ||
{ | ||
tcuint32_t bg, fg, ret; | ||
|
||
bg.i = bg_i; | ||
fg.i = fg_i; | ||
|
||
ret.a = 0xFFU; | ||
ret.r = (amount * fg.r + (0XFFU - amount) * bg.r) >> 8; | ||
ret.g = (amount * fg.g + (0XFFU - amount) * bg.g) >> 8; | ||
ret.b = (amount * fg.b + (0XFFU - amount) * bg.b) >> 8; | ||
|
||
return ret.i; | ||
} | ||
|
||
// [crispy] TRANMAP blending emulation, used for Doom | ||
const uint32_t I_BlendOverTranmap (const uint32_t bg, const uint32_t fg) | ||
{ | ||
return I_BlendOver(bg, fg, 0xA8); // 168 (66% opacity) | ||
} | ||
|
||
// [crispy] TINTTAB blending emulation, used for Heretic and Hexen | ||
const uint32_t I_BlendOverTinttab (const uint32_t bg, const uint32_t fg) | ||
{ | ||
return I_BlendOver(bg, fg, 0x60); // 96 (38% opacity) | ||
} | ||
|
||
// [crispy] More opaque ("Alt") TINTTAB blending emulation, used for Hexen's MF_ALTSHADOW drawing | ||
const uint32_t I_BlendOverAltTinttab (const uint32_t bg, const uint32_t fg) | ||
{ | ||
return I_BlendOver(bg, fg, 0x8E); // 142 (56% opacity) | ||
} | ||
|
||
// [crispy] More opaque XLATAB blending emulation, used for Strife | ||
const uint32_t I_BlendOverXlatab (const uint32_t bg, const uint32_t fg) | ||
{ | ||
return I_BlendOver(bg, fg, 0xC0); // 192 (75% opacity) | ||
} | ||
|
||
// [crispy] Less opaque ("Alt") XLATAB blending emulation, used for Strife | ||
const uint32_t I_BlendOverAltXlatab (const uint32_t bg, const uint32_t fg) | ||
{ | ||
return I_BlendOver(bg, fg, 0x40); // 64 (25% opacity) | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// | ||
// Copyright(C) 1993-1996 Id Software, Inc. | ||
// Copyright(C) 2005-2014 Simon Howard | ||
// Copyright(C) 2015-2024 Fabian Greffrath | ||
// | ||
// 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. | ||
// | ||
// DESCRIPTION: | ||
// [crispy] Truecolor rendering | ||
// | ||
|
||
#ifndef __I_TRUECOLOR__ | ||
#define __I_TRUECOLOR__ | ||
|
||
#include "config.h" | ||
|
||
#ifdef CRISPY_TRUECOLOR | ||
|
||
#include <stdint.h> | ||
|
||
extern const uint32_t (*blendfunc) (const uint32_t fg, const uint32_t bg); | ||
|
||
const uint32_t I_BlendAdd (const uint32_t bg_i, const uint32_t fg_i); | ||
const uint32_t I_BlendDark (const uint32_t bg_i, const int d); | ||
const uint32_t I_BlendOver (const uint32_t bg_i, const uint32_t fg_i, const int amount); | ||
|
||
const uint32_t I_BlendOverTranmap (const uint32_t bg, const uint32_t fg); | ||
const uint32_t I_BlendOverTinttab (const uint32_t bg, const uint32_t fg); | ||
const uint32_t I_BlendOverAltTinttab (const uint32_t bg, const uint32_t fg); | ||
const uint32_t I_BlendOverXlatab (const uint32_t bg, const uint32_t fg); | ||
const uint32_t I_BlendOverAltXlatab (const uint32_t bg, const uint32_t fg); | ||
|
||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters