yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
snes_color_math.h
Go to the documentation of this file.
1#ifndef YAZE_APP_GFX_TYPES_SNES_COLOR_MATH_H_
2#define YAZE_APP_GFX_TYPES_SNES_COLOR_MATH_H_
3
4#include <algorithm>
5#include <cstdint>
6
7namespace yaze::gfx {
8
9// CGADSUB operates on five-bit channels. Half-add divides the unsaturated sum;
10// clamping before the division incorrectly darkens bright water/lighting.
11constexpr uint8_t SnesColorMathChannel(uint8_t main, uint8_t sub, bool subtract,
12 bool half) {
13 int value =
14 subtract ? std::max(0, int(main) - int(sub)) : int(main) + int(sub);
15 if (half)
16 value >>= 1;
17 return static_cast<uint8_t>(std::min(31, value));
18}
19
20constexpr uint8_t ExpandSnesChannel(uint8_t value) {
21 return static_cast<uint8_t>((value << 3) | (value >> 2));
22}
23
24} // namespace yaze::gfx
25#endif // YAZE_APP_GFX_TYPES_SNES_COLOR_MATH_H_
int main(int argc, char **argv)
Definition emu.cc:43
Contains classes for handling graphical data.
constexpr uint8_t SnesColorMathChannel(uint8_t main, uint8_t sub, bool subtract, bool half)
constexpr uint8_t ExpandSnesChannel(uint8_t value)