move color encoding functions to GVMEncoder header
This commit is contained in:
@@ -8,22 +8,6 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
static uint16_t encode_rgb565(uint8_t r, uint8_t g, uint8_t b) {
|
||||
return ((r << 8) & 0xF800) | ((g << 3) & 0x07E0) | ((b >> 3) & 0x001F);
|
||||
}
|
||||
|
||||
static uint16_t encode_rgb5a3(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
|
||||
if ((a & 0xE0) == 0xE0) {
|
||||
return 0x8000 | ((r << 7) & 0x7C00) | ((g << 2) & 0x03E0) | ((b >> 3) & 0x001F);
|
||||
} else {
|
||||
return ((a << 7) & 0x7000) | ((r << 4) & 0x0F00) | (g & 0x00F0) | ((b >> 4) & 0x000F);
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t encode_argb8888(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
|
||||
return (a << 24) | (r << 16) | (g << 8) | b;
|
||||
}
|
||||
|
||||
struct GVMFileEntry {
|
||||
be_uint16_t file_num;
|
||||
pstring<TextEncoding::ASCII, 0x1C> name;
|
||||
|
||||
@@ -20,3 +20,40 @@ enum class GVRDataFormat : uint8_t {
|
||||
};
|
||||
|
||||
std::string encode_gvm(const Image& img, GVRDataFormat data_format);
|
||||
|
||||
constexpr uint16_t encode_rgb565(uint8_t r, uint8_t g, uint8_t b) {
|
||||
return ((r << 8) & 0xF800) | ((g << 3) & 0x07E0) | ((b >> 3) & 0x001F);
|
||||
}
|
||||
|
||||
constexpr uint16_t encode_rgb5a3(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
|
||||
if ((a & 0xE0) == 0xE0) {
|
||||
return 0x8000 | ((r << 7) & 0x7C00) | ((g << 2) & 0x03E0) | ((b >> 3) & 0x001F);
|
||||
} else {
|
||||
return ((a << 7) & 0x7000) | ((r << 4) & 0x0F00) | (g & 0x00F0) | ((b >> 4) & 0x000F);
|
||||
}
|
||||
}
|
||||
|
||||
constexpr uint32_t encode_argb8888(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
|
||||
return (a << 24) | (r << 16) | (g << 8) | b;
|
||||
}
|
||||
|
||||
constexpr uint16_t encode_xrgb8888_to_xrgb1555(uint32_t xrgb8888) {
|
||||
// In: rrrrrrrrggggggggbbbbbbbbaaaaaaaa
|
||||
// Out: -rrrrrgggggbbbbb
|
||||
return ((xrgb8888 >> 9) & 0x7C00) | ((xrgb8888 >> 6) & 0x03E0) | ((xrgb8888 >> 3) & 0x001F);
|
||||
}
|
||||
|
||||
constexpr uint32_t encode_rgbx8888_to_xrgb1555(uint16_t rgbx8888) {
|
||||
// In: rrrrrrrrggggggggbbbbbbbbxxxxxxxx
|
||||
// Out: -rrrrrgggggbbbbb
|
||||
return ((rgbx8888 >> 17) & 0x7C00) | ((rgbx8888 >> 14) & 0x03E0) | ((rgbx8888 >> 11) & 0x001F);
|
||||
}
|
||||
|
||||
constexpr uint32_t decode_xrgb1555_to_rgba8888(uint16_t xrgb1555) {
|
||||
// In: -rrrrrgggggbbbbb
|
||||
// Out: rrrrrrrrggggggggbbbbbbbbaaaaaaaa (a is always FF)
|
||||
return ((xrgb1555 << 17) & 0xF8000000) | ((xrgb1555 << 12) & 0x07000000) |
|
||||
((xrgb1555 << 14) & 0x00F80000) | ((xrgb1555 << 9) & 0x00070000) |
|
||||
((xrgb1555 << 11) & 0x0000F800) | ((xrgb1555 << 6) & 0x00000700) |
|
||||
0x000000FF;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
#include "ChatCommands.hh"
|
||||
#include "Compression.hh"
|
||||
#include "GVMEncoder.hh"
|
||||
#include "Loggers.hh"
|
||||
#include "PSOProtocol.hh"
|
||||
#include "ReceiveCommands.hh"
|
||||
@@ -36,10 +37,6 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
static constexpr uint16_t encode_xrgb1555(uint32_t xrgb8888) {
|
||||
return ((xrgb8888 >> 9) & 0x7C00) | ((xrgb8888 >> 6) & 0x03E0) | ((xrgb8888 >> 3) & 0x001F);
|
||||
}
|
||||
|
||||
struct HandlerResult {
|
||||
enum class Type {
|
||||
FORWARD = 0,
|
||||
@@ -1053,7 +1050,7 @@ static HandlerResult C_GXB_61(shared_ptr<ProxyServer::LinkedSession> ses, uint16
|
||||
modified = true;
|
||||
}
|
||||
if (!ses->challenge_rank_title_override.empty()) {
|
||||
pd.records.challenge.title_color = encode_xrgb1555(ses->challenge_rank_color_override);
|
||||
pd.records.challenge.title_color = encode_xrgb8888_to_xrgb1555(ses->challenge_rank_color_override);
|
||||
pd.records.challenge.rank_title.encode(ses->challenge_rank_title_override, ses->language());
|
||||
}
|
||||
|
||||
@@ -1090,7 +1087,7 @@ static HandlerResult C_GXB_61(shared_ptr<ProxyServer::LinkedSession> ses, uint16
|
||||
modified = true;
|
||||
}
|
||||
if (!ses->challenge_rank_title_override.empty()) {
|
||||
pd->records.challenge.stats.title_color = encode_xrgb1555(ses->challenge_rank_color_override);
|
||||
pd->records.challenge.stats.title_color = encode_xrgb8888_to_xrgb1555(ses->challenge_rank_color_override);
|
||||
pd->records.challenge.rank_title.encode(ses->challenge_rank_title_override, ses->language());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user