mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Implement preliminary version of "reverse" feature
Not hooked to all RGBGFX flags yet, but good enough for most use cases (and as a base for future development, should I need to `reset --hard`.) TODOs marked appropriately.
This commit is contained in:
@@ -20,6 +20,9 @@
|
||||
#include "gfx/rgba.hpp"
|
||||
|
||||
struct Options {
|
||||
uint8_t reversedWidth = 0; // -r, in pixels
|
||||
bool reverse() const { return reversedWidth != 0; }
|
||||
|
||||
bool useColorCurve = false; // -C
|
||||
bool fixInput = false; // -f
|
||||
bool allowMirroring = false; // -m
|
||||
@@ -36,7 +39,7 @@ struct Options {
|
||||
} palSpecType = NO_SPEC; // -c
|
||||
std::vector<std::array<Rgba, 4>> palSpec{};
|
||||
uint8_t bitDepth = 2; // -d
|
||||
std::array<uint32_t, 4> inputSlice{0, 0, 0, 0}; // -L
|
||||
std::array<uint32_t, 4> inputSlice{0, 0, 0, 0}; // -L (margins in clockwise order, like CSS)
|
||||
std::array<uint16_t, 2> maxNbTiles{UINT16_MAX, 0}; // -N
|
||||
uint8_t nbPalettes = 8; // -n
|
||||
std::string output{}; // -o
|
||||
@@ -84,4 +87,12 @@ struct Palette {
|
||||
uint8_t size() const;
|
||||
};
|
||||
|
||||
static constexpr uint8_t flip(uint8_t byte) {
|
||||
// To flip all the bits, we'll flip both nibbles, then each nibble half, etc.
|
||||
byte = (byte & 0b0000'1111) << 4 | (byte & 0b1111'0000) >> 4;
|
||||
byte = (byte & 0b0011'0011) << 2 | (byte & 0b1100'1100) >> 2;
|
||||
byte = (byte & 0b0101'0101) << 1 | (byte & 0b1010'1010) >> 1;
|
||||
return byte;
|
||||
}
|
||||
|
||||
#endif /* RGBDS_GFX_MAIN_HPP */
|
||||
|
||||
14
include/gfx/reverse.hpp
Normal file
14
include/gfx/reverse.hpp
Normal file
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* This file is part of RGBDS.
|
||||
*
|
||||
* Copyright (c) 2022, Eldred Habert and RGBDS contributors.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#ifndef RGBDS_GFX_REVERSE_HPP
|
||||
#define RGBDS_GFX_REVERSE_HPP
|
||||
|
||||
void reverse();
|
||||
|
||||
#endif /* RGBDS_GFX_REVERSE_HPP */
|
||||
@@ -17,13 +17,23 @@ struct Rgba {
|
||||
uint8_t blue;
|
||||
uint8_t alpha;
|
||||
|
||||
Rgba(uint8_t r, uint8_t g, uint8_t b, uint8_t a) : red(r), green(g), blue(b), alpha(a) {}
|
||||
constexpr Rgba(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
|
||||
: red(r), green(g), blue(b), alpha(a) {}
|
||||
/**
|
||||
* Constructs the color from a "packed" RGBA representation (0xRRGGBBAA)
|
||||
*/
|
||||
explicit Rgba(uint32_t rgba = 0)
|
||||
explicit constexpr Rgba(uint32_t rgba = 0)
|
||||
: red(rgba >> 24), green(rgba >> 16), blue(rgba >> 8), alpha(rgba) {}
|
||||
|
||||
static constexpr Rgba fromCGBColor(uint16_t cgbColor) {
|
||||
constexpr auto _5to8 = [](uint8_t fiveBpp) -> uint8_t {
|
||||
fiveBpp &= 0b11111; // For caller's convenience
|
||||
return fiveBpp << 3 | fiveBpp >> 2;
|
||||
};
|
||||
return {_5to8(cgbColor), _5to8(cgbColor >> 5), _5to8(cgbColor >> 10),
|
||||
(uint8_t)(cgbColor & 0x8000 ? 0x00 : 0xFF)};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns this RGBA as a 32-bit number that can be printed in hex (`%08x`) to yield its CSS
|
||||
* representation
|
||||
|
||||
Reference in New Issue
Block a user