From 20499319375959991cfb851cf0021cb7bb0b29d2 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Tue, 31 Dec 2019 17:34:34 -0600 Subject: [PATCH] [nostalgia/core] Cleanup color channel conversion --- src/nostalgia/core/gfx.cpp | 22 +++++++++++----------- src/nostalgia/core/gfx.hpp | 14 +++++++------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/nostalgia/core/gfx.cpp b/src/nostalgia/core/gfx.cpp index 3949ffef..9de8d23f 100644 --- a/src/nostalgia/core/gfx.cpp +++ b/src/nostalgia/core/gfx.cpp @@ -141,37 +141,37 @@ static char charMap[128] = { 0, // ~ }; -Color32 toColor32(Color16 nc) { - auto r = ((nc & 0b0000000000011111) >> 0) * 8; - auto g = ((nc & 0b0000001111100000) >> 5) * 8; - auto b = ((nc & 0b0111110000000000) >> 10) * 8; - auto a = 255; +Color32 toColor32(Color16 nc) noexcept { + Color32 r = ((nc & 0b0000000000011111) >> 0) * 8; + Color32 g = ((nc & 0b0000001111100000) >> 5) * 8; + Color32 b = ((nc & 0b0111110000000000) >> 10) * 8; + Color32 a = 255; return a | (b << 8) | (g << 16) | (r << 24); } -uint8_t red32(Color32 c) { +uint8_t red32(Color32 c) noexcept { return (c & 0x000000ff) >> 0; } -uint8_t green32(Color32 c) { +uint8_t green32(Color32 c) noexcept { return (c & 0x0000ff00) >> 8; } -uint8_t blue32(Color32 c) { +uint8_t blue32(Color32 c) noexcept { return (c & 0x00ff0000) >> 16; } -uint8_t red32(Color16 c) { +uint8_t red32(Color16 c) noexcept { return ((c & 0b0000000000011111) >> 0) * 8; } -uint8_t green32(Color16 c) { +uint8_t green32(Color16 c) noexcept { return ((c & 0b0000001111100000) >> 5) * 8; } -uint8_t blue32(Color16 c) { +uint8_t blue32(Color16 c) noexcept { return ((c & 0b0111110000000000) >> 10) * 8; } diff --git a/src/nostalgia/core/gfx.hpp b/src/nostalgia/core/gfx.hpp index fb23b964..04121680 100644 --- a/src/nostalgia/core/gfx.hpp +++ b/src/nostalgia/core/gfx.hpp @@ -69,20 +69,20 @@ ox::Error model(T *io, NostalgiaGraphic *ng) { */ [[nodiscard]] ox::Error loadTileSheet(Context *ctx, TileSheetSpace tss, int section, ox::FileAddress tilesheet, ox::FileAddress palette = nullptr); -[[nodiscard]] Color32 toColor32(Color16 nc); +[[nodiscard]] Color32 toColor32(Color16 nc) noexcept; -[[nodiscard]] uint8_t red32(Color16 c); +[[nodiscard]] uint8_t red32(Color16 c) noexcept; -[[nodiscard]] uint8_t green32(Color16 c); +[[nodiscard]] uint8_t green32(Color16 c) noexcept; -[[nodiscard]] uint8_t blue32(Color16 c); +[[nodiscard]] uint8_t blue32(Color16 c) noexcept; -[[nodiscard]] uint8_t red32(Color32 c); +[[nodiscard]] uint8_t red32(Color32 c) noexcept; -[[nodiscard]] uint8_t green32(Color32 c); +[[nodiscard]] uint8_t green32(Color32 c) noexcept; -[[nodiscard]] uint8_t blue32(Color32 c); +[[nodiscard]] uint8_t blue32(Color32 c) noexcept; void puts(Context *ctx, int column, int row, const char *str);