diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/common/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/common/color.h | 271 |
2 files changed, 0 insertions, 272 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 5d781cd77..aeaf8e81f 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt | |||
| @@ -108,7 +108,6 @@ add_library(common STATIC | |||
| 108 | bit_util.h | 108 | bit_util.h |
| 109 | cityhash.cpp | 109 | cityhash.cpp |
| 110 | cityhash.h | 110 | cityhash.h |
| 111 | color.h | ||
| 112 | common_funcs.h | 111 | common_funcs.h |
| 113 | common_paths.h | 112 | common_paths.h |
| 114 | common_types.h | 113 | common_types.h |
diff --git a/src/common/color.h b/src/common/color.h deleted file mode 100644 index bbcac858e..000000000 --- a/src/common/color.h +++ /dev/null | |||
| @@ -1,271 +0,0 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <cstring> | ||
| 8 | |||
| 9 | #include "common/common_types.h" | ||
| 10 | #include "common/swap.h" | ||
| 11 | #include "common/vector_math.h" | ||
| 12 | |||
| 13 | namespace Common::Color { | ||
| 14 | |||
| 15 | /// Convert a 1-bit color component to 8 bit | ||
| 16 | [[nodiscard]] constexpr u8 Convert1To8(u8 value) { | ||
| 17 | return value * 255; | ||
| 18 | } | ||
| 19 | |||
| 20 | /// Convert a 4-bit color component to 8 bit | ||
| 21 | [[nodiscard]] constexpr u8 Convert4To8(u8 value) { | ||
| 22 | return (value << 4) | value; | ||
| 23 | } | ||
| 24 | |||
| 25 | /// Convert a 5-bit color component to 8 bit | ||
| 26 | [[nodiscard]] constexpr u8 Convert5To8(u8 value) { | ||
| 27 | return (value << 3) | (value >> 2); | ||
| 28 | } | ||
| 29 | |||
| 30 | /// Convert a 6-bit color component to 8 bit | ||
| 31 | [[nodiscard]] constexpr u8 Convert6To8(u8 value) { | ||
| 32 | return (value << 2) | (value >> 4); | ||
| 33 | } | ||
| 34 | |||
| 35 | /// Convert a 8-bit color component to 1 bit | ||
| 36 | [[nodiscard]] constexpr u8 Convert8To1(u8 value) { | ||
| 37 | return value >> 7; | ||
| 38 | } | ||
| 39 | |||
| 40 | /// Convert a 8-bit color component to 4 bit | ||
| 41 | [[nodiscard]] constexpr u8 Convert8To4(u8 value) { | ||
| 42 | return value >> 4; | ||
| 43 | } | ||
| 44 | |||
| 45 | /// Convert a 8-bit color component to 5 bit | ||
| 46 | [[nodiscard]] constexpr u8 Convert8To5(u8 value) { | ||
| 47 | return value >> 3; | ||
| 48 | } | ||
| 49 | |||
| 50 | /// Convert a 8-bit color component to 6 bit | ||
| 51 | [[nodiscard]] constexpr u8 Convert8To6(u8 value) { | ||
| 52 | return value >> 2; | ||
| 53 | } | ||
| 54 | |||
| 55 | /** | ||
| 56 | * Decode a color stored in RGBA8 format | ||
| 57 | * @param bytes Pointer to encoded source color | ||
| 58 | * @return Result color decoded as Common::Vec4<u8> | ||
| 59 | */ | ||
| 60 | [[nodiscard]] inline Common::Vec4<u8> DecodeRGBA8(const u8* bytes) { | ||
| 61 | return {bytes[3], bytes[2], bytes[1], bytes[0]}; | ||
| 62 | } | ||
| 63 | |||
| 64 | /** | ||
| 65 | * Decode a color stored in RGB8 format | ||
| 66 | * @param bytes Pointer to encoded source color | ||
| 67 | * @return Result color decoded as Common::Vec4<u8> | ||
| 68 | */ | ||
| 69 | [[nodiscard]] inline Common::Vec4<u8> DecodeRGB8(const u8* bytes) { | ||
| 70 | return {bytes[2], bytes[1], bytes[0], 255}; | ||
| 71 | } | ||
| 72 | |||
| 73 | /** | ||
| 74 | * Decode a color stored in RG8 (aka HILO8) format | ||
| 75 | * @param bytes Pointer to encoded source color | ||
| 76 | * @return Result color decoded as Common::Vec4<u8> | ||
| 77 | */ | ||
| 78 | [[nodiscard]] inline Common::Vec4<u8> DecodeRG8(const u8* bytes) { | ||
| 79 | return {bytes[1], bytes[0], 0, 255}; | ||
| 80 | } | ||
| 81 | |||
| 82 | /** | ||
| 83 | * Decode a color stored in RGB565 format | ||
| 84 | * @param bytes Pointer to encoded source color | ||
| 85 | * @return Result color decoded as Common::Vec4<u8> | ||
| 86 | */ | ||
| 87 | [[nodiscard]] inline Common::Vec4<u8> DecodeRGB565(const u8* bytes) { | ||
| 88 | u16_le pixel; | ||
| 89 | std::memcpy(&pixel, bytes, sizeof(pixel)); | ||
| 90 | return {Convert5To8((pixel >> 11) & 0x1F), Convert6To8((pixel >> 5) & 0x3F), | ||
| 91 | Convert5To8(pixel & 0x1F), 255}; | ||
| 92 | } | ||
| 93 | |||
| 94 | /** | ||
| 95 | * Decode a color stored in RGB5A1 format | ||
| 96 | * @param bytes Pointer to encoded source color | ||
| 97 | * @return Result color decoded as Common::Vec4<u8> | ||
| 98 | */ | ||
| 99 | [[nodiscard]] inline Common::Vec4<u8> DecodeRGB5A1(const u8* bytes) { | ||
| 100 | u16_le pixel; | ||
| 101 | std::memcpy(&pixel, bytes, sizeof(pixel)); | ||
| 102 | return {Convert5To8((pixel >> 11) & 0x1F), Convert5To8((pixel >> 6) & 0x1F), | ||
| 103 | Convert5To8((pixel >> 1) & 0x1F), Convert1To8(pixel & 0x1)}; | ||
| 104 | } | ||
| 105 | |||
| 106 | /** | ||
| 107 | * Decode a color stored in RGBA4 format | ||
| 108 | * @param bytes Pointer to encoded source color | ||
| 109 | * @return Result color decoded as Common::Vec4<u8> | ||
| 110 | */ | ||
| 111 | [[nodiscard]] inline Common::Vec4<u8> DecodeRGBA4(const u8* bytes) { | ||
| 112 | u16_le pixel; | ||
| 113 | std::memcpy(&pixel, bytes, sizeof(pixel)); | ||
| 114 | return {Convert4To8((pixel >> 12) & 0xF), Convert4To8((pixel >> 8) & 0xF), | ||
| 115 | Convert4To8((pixel >> 4) & 0xF), Convert4To8(pixel & 0xF)}; | ||
| 116 | } | ||
| 117 | |||
| 118 | /** | ||
| 119 | * Decode a depth value stored in D16 format | ||
| 120 | * @param bytes Pointer to encoded source value | ||
| 121 | * @return Depth value as an u32 | ||
| 122 | */ | ||
| 123 | [[nodiscard]] inline u32 DecodeD16(const u8* bytes) { | ||
| 124 | u16_le data; | ||
| 125 | std::memcpy(&data, bytes, sizeof(data)); | ||
| 126 | return data; | ||
| 127 | } | ||
| 128 | |||
| 129 | /** | ||
| 130 | * Decode a depth value stored in D24 format | ||
| 131 | * @param bytes Pointer to encoded source value | ||
| 132 | * @return Depth value as an u32 | ||
| 133 | */ | ||
| 134 | [[nodiscard]] inline u32 DecodeD24(const u8* bytes) { | ||
| 135 | return (bytes[2] << 16) | (bytes[1] << 8) | bytes[0]; | ||
| 136 | } | ||
| 137 | |||
| 138 | /** | ||
| 139 | * Decode a depth value and a stencil value stored in D24S8 format | ||
| 140 | * @param bytes Pointer to encoded source values | ||
| 141 | * @return Resulting values stored as a Common::Vec2 | ||
| 142 | */ | ||
| 143 | [[nodiscard]] inline Common::Vec2<u32> DecodeD24S8(const u8* bytes) { | ||
| 144 | return {static_cast<u32>((bytes[2] << 16) | (bytes[1] << 8) | bytes[0]), bytes[3]}; | ||
| 145 | } | ||
| 146 | |||
| 147 | /** | ||
| 148 | * Encode a color as RGBA8 format | ||
| 149 | * @param color Source color to encode | ||
| 150 | * @param bytes Destination pointer to store encoded color | ||
| 151 | */ | ||
| 152 | inline void EncodeRGBA8(const Common::Vec4<u8>& color, u8* bytes) { | ||
| 153 | bytes[3] = color.r(); | ||
| 154 | bytes[2] = color.g(); | ||
| 155 | bytes[1] = color.b(); | ||
| 156 | bytes[0] = color.a(); | ||
| 157 | } | ||
| 158 | |||
| 159 | /** | ||
| 160 | * Encode a color as RGB8 format | ||
| 161 | * @param color Source color to encode | ||
| 162 | * @param bytes Destination pointer to store encoded color | ||
| 163 | */ | ||
| 164 | inline void EncodeRGB8(const Common::Vec4<u8>& color, u8* bytes) { | ||
| 165 | bytes[2] = color.r(); | ||
| 166 | bytes[1] = color.g(); | ||
| 167 | bytes[0] = color.b(); | ||
| 168 | } | ||
| 169 | |||
| 170 | /** | ||
| 171 | * Encode a color as RG8 (aka HILO8) format | ||
| 172 | * @param color Source color to encode | ||
| 173 | * @param bytes Destination pointer to store encoded color | ||
| 174 | */ | ||
| 175 | inline void EncodeRG8(const Common::Vec4<u8>& color, u8* bytes) { | ||
| 176 | bytes[1] = color.r(); | ||
| 177 | bytes[0] = color.g(); | ||
| 178 | } | ||
| 179 | /** | ||
| 180 | * Encode a color as RGB565 format | ||
| 181 | * @param color Source color to encode | ||
| 182 | * @param bytes Destination pointer to store encoded color | ||
| 183 | */ | ||
| 184 | inline void EncodeRGB565(const Common::Vec4<u8>& color, u8* bytes) { | ||
| 185 | const u16_le data = | ||
| 186 | (Convert8To5(color.r()) << 11) | (Convert8To6(color.g()) << 5) | Convert8To5(color.b()); | ||
| 187 | |||
| 188 | std::memcpy(bytes, &data, sizeof(data)); | ||
| 189 | } | ||
| 190 | |||
| 191 | /** | ||
| 192 | * Encode a color as RGB5A1 format | ||
| 193 | * @param color Source color to encode | ||
| 194 | * @param bytes Destination pointer to store encoded color | ||
| 195 | */ | ||
| 196 | inline void EncodeRGB5A1(const Common::Vec4<u8>& color, u8* bytes) { | ||
| 197 | const u16_le data = (Convert8To5(color.r()) << 11) | (Convert8To5(color.g()) << 6) | | ||
| 198 | (Convert8To5(color.b()) << 1) | Convert8To1(color.a()); | ||
| 199 | |||
| 200 | std::memcpy(bytes, &data, sizeof(data)); | ||
| 201 | } | ||
| 202 | |||
| 203 | /** | ||
| 204 | * Encode a color as RGBA4 format | ||
| 205 | * @param color Source color to encode | ||
| 206 | * @param bytes Destination pointer to store encoded color | ||
| 207 | */ | ||
| 208 | inline void EncodeRGBA4(const Common::Vec4<u8>& color, u8* bytes) { | ||
| 209 | const u16 data = (Convert8To4(color.r()) << 12) | (Convert8To4(color.g()) << 8) | | ||
| 210 | (Convert8To4(color.b()) << 4) | Convert8To4(color.a()); | ||
| 211 | |||
| 212 | std::memcpy(bytes, &data, sizeof(data)); | ||
| 213 | } | ||
| 214 | |||
| 215 | /** | ||
| 216 | * Encode a 16 bit depth value as D16 format | ||
| 217 | * @param value 16 bit source depth value to encode | ||
| 218 | * @param bytes Pointer where to store the encoded value | ||
| 219 | */ | ||
| 220 | inline void EncodeD16(u32 value, u8* bytes) { | ||
| 221 | const u16_le data = static_cast<u16>(value); | ||
| 222 | std::memcpy(bytes, &data, sizeof(data)); | ||
| 223 | } | ||
| 224 | |||
| 225 | /** | ||
| 226 | * Encode a 24 bit depth value as D24 format | ||
| 227 | * @param value 24 bit source depth value to encode | ||
| 228 | * @param bytes Pointer where to store the encoded value | ||
| 229 | */ | ||
| 230 | inline void EncodeD24(u32 value, u8* bytes) { | ||
| 231 | bytes[0] = value & 0xFF; | ||
| 232 | bytes[1] = (value >> 8) & 0xFF; | ||
| 233 | bytes[2] = (value >> 16) & 0xFF; | ||
| 234 | } | ||
| 235 | |||
| 236 | /** | ||
| 237 | * Encode a 24 bit depth and 8 bit stencil values as D24S8 format | ||
| 238 | * @param depth 24 bit source depth value to encode | ||
| 239 | * @param stencil 8 bit source stencil value to encode | ||
| 240 | * @param bytes Pointer where to store the encoded value | ||
| 241 | */ | ||
| 242 | inline void EncodeD24S8(u32 depth, u8 stencil, u8* bytes) { | ||
| 243 | bytes[0] = depth & 0xFF; | ||
| 244 | bytes[1] = (depth >> 8) & 0xFF; | ||
| 245 | bytes[2] = (depth >> 16) & 0xFF; | ||
| 246 | bytes[3] = stencil; | ||
| 247 | } | ||
| 248 | |||
| 249 | /** | ||
| 250 | * Encode a 24 bit depth value as D24X8 format (32 bits per pixel with 8 bits unused) | ||
| 251 | * @param depth 24 bit source depth value to encode | ||
| 252 | * @param bytes Pointer where to store the encoded value | ||
| 253 | * @note unused bits will not be modified | ||
| 254 | */ | ||
| 255 | inline void EncodeD24X8(u32 depth, u8* bytes) { | ||
| 256 | bytes[0] = depth & 0xFF; | ||
| 257 | bytes[1] = (depth >> 8) & 0xFF; | ||
| 258 | bytes[2] = (depth >> 16) & 0xFF; | ||
| 259 | } | ||
| 260 | |||
| 261 | /** | ||
| 262 | * Encode an 8 bit stencil value as X24S8 format (32 bits per pixel with 24 bits unused) | ||
| 263 | * @param stencil 8 bit source stencil value to encode | ||
| 264 | * @param bytes Pointer where to store the encoded value | ||
| 265 | * @note unused bits will not be modified | ||
| 266 | */ | ||
| 267 | inline void EncodeX24S8(u8 stencil, u8* bytes) { | ||
| 268 | bytes[3] = stencil; | ||
| 269 | } | ||
| 270 | |||
| 271 | } // namespace Common::Color | ||