mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Implement more features and fix bugs
This commit is contained in:
@@ -23,9 +23,14 @@ struct Rgba {
|
||||
Rgba(uint8_t r, uint8_t g, uint8_t b, uint8_t a) : red(r), green(g), blue(b), alpha(a) {}
|
||||
Rgba(uint32_t rgba) : red(rgba), green(rgba >> 8), blue(rgba >> 16), alpha(rgba >> 24) {}
|
||||
|
||||
operator uint32_t() const {
|
||||
operator uint32_t() const { return toCSS(); }
|
||||
/**
|
||||
* Returns this RGBA as a 32-bit number that can be printed in hex (`%08x`) to yield its CSS
|
||||
* representation
|
||||
*/
|
||||
uint32_t toCSS() const {
|
||||
auto shl = [](uint8_t val, unsigned shift) { return static_cast<uint32_t>(val) << shift; };
|
||||
return shl(red, 0) | shl(green, 8) | shl(blue, 16) | shl(alpha, 24);
|
||||
return shl(red, 24) | shl(green, 16) | shl(blue, 8) | shl(alpha, 0);
|
||||
}
|
||||
bool operator!=(Rgba const &other) const {
|
||||
return static_cast<uint32_t>(*this) != static_cast<uint32_t>(other);
|
||||
@@ -39,12 +44,15 @@ struct Rgba {
|
||||
*/
|
||||
static constexpr uint16_t transparent = 0b1'00000'00000'00000;
|
||||
|
||||
static constexpr uint8_t transparency_threshold = 5; // TODO: adjust this
|
||||
/**
|
||||
* All alpha values strictly below this will be considered transparent
|
||||
*/
|
||||
static constexpr uint8_t opacity_threshold = 0xF0; // TODO: adjust this
|
||||
/**
|
||||
* Computes the equivalent CGB color, respects the color curve depending on options
|
||||
*/
|
||||
uint16_t cgbColor() const {
|
||||
if (alpha > 0xFF - transparency_threshold)
|
||||
if (alpha < opacity_threshold)
|
||||
return transparent;
|
||||
if (options.useColorCurve) {
|
||||
assert(!"TODO");
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
#include <array>
|
||||
#include <filesystem>
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "helpers.h"
|
||||
@@ -27,7 +28,7 @@ struct Options {
|
||||
uint8_t nbPalettes = 8; // TODO
|
||||
uint8_t nbColorsPerPal = 0; // TODO; 0 means "auto" = 1 << bitDepth;
|
||||
std::array<uint8_t, 2> baseTileIDs{0, 0}; // TODO
|
||||
std::array<uint16_t, 2> maxNbTiles{384, 0}; // TODO
|
||||
std::array<uint16_t, 2> maxNbTiles{UINT16_MAX, 0}; // TODO
|
||||
std::filesystem::path tilemap{}; // -t, -T
|
||||
std::filesystem::path attrmap{}; // -a, -A
|
||||
std::filesystem::path palettes{}; // -p, -P
|
||||
@@ -35,6 +36,9 @@ struct Options {
|
||||
std::filesystem::path input{}; // positional arg
|
||||
|
||||
format_(printf, 2, 3) void verbosePrint(char const *fmt, ...) const;
|
||||
uint8_t maxPalSize() const {
|
||||
return nbColorsPerPal;
|
||||
} // TODO: minus 1 when transparency is active
|
||||
};
|
||||
|
||||
extern Options options;
|
||||
|
||||
Reference in New Issue
Block a user