From 5df2d1b5f75e0ee2d3fce7131fcee5dc8e1d7cc4 Mon Sep 17 00:00:00 2001 From: archshift Date: Sun, 24 May 2015 12:16:22 -0700 Subject: Move video_core/math.h to common/vector_math.h The file only contained vector manipulation code, and such widely-useable code doesn't belong in video_core. --- src/citra_qt/debugger/graphics_cmdlists.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/citra_qt') diff --git a/src/citra_qt/debugger/graphics_cmdlists.cpp b/src/citra_qt/debugger/graphics_cmdlists.cpp index 804c735a..cabf5fe0 100644 --- a/src/citra_qt/debugger/graphics_cmdlists.cpp +++ b/src/citra_qt/debugger/graphics_cmdlists.cpp @@ -11,10 +11,10 @@ #include #include -#include "video_core/pica.h" -#include "video_core/math.h" +#include "common/vector_math.h" #include "video_core/debug_utils/debug_utils.h" +#include "video_core/pica.h" #include "graphics_cmdlists.h" -- cgit v1.2.3 From 76690392bf8923d7172936836d15e3caebb26cf0 Mon Sep 17 00:00:00 2001 From: archshift Date: Sun, 24 May 2015 12:20:31 -0700 Subject: Move video_core/color.h to common/color.h --- src/citra_qt/debugger/graphics_framebuffer.cpp | 3 +- src/common/CMakeLists.txt | 1 + src/common/color.h | 214 +++++++++++++++++++++++ src/core/hw/gpu.cpp | 2 +- src/video_core/CMakeLists.txt | 1 - src/video_core/color.h | 214 ----------------------- src/video_core/debug_utils/debug_utils.cpp | 2 +- src/video_core/rasterizer.cpp | 2 +- src/video_core/renderer_opengl/gl_rasterizer.cpp | 3 +- 9 files changed, 222 insertions(+), 220 deletions(-) create mode 100644 src/common/color.h delete mode 100644 src/video_core/color.h (limited to 'src/citra_qt') diff --git a/src/citra_qt/debugger/graphics_framebuffer.cpp b/src/citra_qt/debugger/graphics_framebuffer.cpp index e0734459..6bbe7572 100644 --- a/src/citra_qt/debugger/graphics_framebuffer.cpp +++ b/src/citra_qt/debugger/graphics_framebuffer.cpp @@ -9,10 +9,11 @@ #include #include +#include "common/color.h" + #include "core/hw/gpu.h" #include "core/memory.h" -#include "video_core/color.h" #include "video_core/pica.h" #include "video_core/utils.h" diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index d1c306d3..e78f4f14 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -24,6 +24,7 @@ set(HEADERS bit_field.h break_points.h chunk_file.h + color.h common_funcs.h common_paths.h common_types.h diff --git a/src/common/color.h b/src/common/color.h new file mode 100644 index 00000000..422fdc8a --- /dev/null +++ b/src/common/color.h @@ -0,0 +1,214 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "common/common_types.h" +#include "common/swap.h" +#include "common/vector_math.h" + +namespace Color { + +/// Convert a 1-bit color component to 8 bit +inline u8 Convert1To8(u8 value) { + return value * 255; +} + +/// Convert a 4-bit color component to 8 bit +inline u8 Convert4To8(u8 value) { + return (value << 4) | value; +} + +/// Convert a 5-bit color component to 8 bit +inline u8 Convert5To8(u8 value) { + return (value << 3) | (value >> 2); +} + +/// Convert a 6-bit color component to 8 bit +inline u8 Convert6To8(u8 value) { + return (value << 2) | (value >> 4); +} + +/// Convert a 8-bit color component to 1 bit +inline u8 Convert8To1(u8 value) { + return value >> 7; +} + +/// Convert a 8-bit color component to 4 bit +inline u8 Convert8To4(u8 value) { + return value >> 4; +} + +/// Convert a 8-bit color component to 5 bit +inline u8 Convert8To5(u8 value) { + return value >> 3; +} + +/// Convert a 8-bit color component to 6 bit +inline u8 Convert8To6(u8 value) { + return value >> 2; +} + +/** + * Decode a color stored in RGBA8 format + * @param bytes Pointer to encoded source color + * @return Result color decoded as Math::Vec4 + */ +inline const Math::Vec4 DecodeRGBA8(const u8* bytes) { + return { bytes[3], bytes[2], bytes[1], bytes[0] }; +} + +/** + * Decode a color stored in RGB8 format + * @param bytes Pointer to encoded source color + * @return Result color decoded as Math::Vec4 + */ +inline const Math::Vec4 DecodeRGB8(const u8* bytes) { + return { bytes[2], bytes[1], bytes[0], 255 }; +} + +/** + * Decode a color stored in RGB565 format + * @param bytes Pointer to encoded source color + * @return Result color decoded as Math::Vec4 + */ +inline const Math::Vec4 DecodeRGB565(const u8* bytes) { + const u16_le pixel = *reinterpret_cast(bytes); + return { Convert5To8((pixel >> 11) & 0x1F), Convert6To8((pixel >> 5) & 0x3F), + Convert5To8(pixel & 0x1F), 255 }; +} + +/** + * Decode a color stored in RGB5A1 format + * @param bytes Pointer to encoded source color + * @return Result color decoded as Math::Vec4 + */ +inline const Math::Vec4 DecodeRGB5A1(const u8* bytes) { + const u16_le pixel = *reinterpret_cast(bytes); + return { Convert5To8((pixel >> 11) & 0x1F), Convert5To8((pixel >> 6) & 0x1F), + Convert5To8((pixel >> 1) & 0x1F), Convert1To8(pixel & 0x1) }; +} + +/** + * Decode a color stored in RGBA4 format + * @param bytes Pointer to encoded source color + * @return Result color decoded as Math::Vec4 + */ +inline const Math::Vec4 DecodeRGBA4(const u8* bytes) { + const u16_le pixel = *reinterpret_cast(bytes); + return { Convert4To8((pixel >> 12) & 0xF), Convert4To8((pixel >> 8) & 0xF), + Convert4To8((pixel >> 4) & 0xF), Convert4To8(pixel & 0xF) }; +} + +/** + * Decode a depth value stored in D16 format + * @param bytes Pointer to encoded source value + * @return Depth value as an u32 + */ +inline u32 DecodeD16(const u8* bytes) { + return *reinterpret_cast(bytes); +} + +/** + * Decode a depth value stored in D24 format + * @param bytes Pointer to encoded source value + * @return Depth value as an u32 + */ +inline u32 DecodeD24(const u8* bytes) { + return (bytes[2] << 16) | (bytes[1] << 8) | bytes[0]; +} + +/** + * Decode a depth value and a stencil value stored in D24S8 format + * @param bytes Pointer to encoded source values + * @return Resulting values stored as a Math::Vec2 + */ +inline const Math::Vec2 DecodeD24S8(const u8* bytes) { + return { static_cast((bytes[2] << 16) | (bytes[1] << 8) | bytes[0]), bytes[3] }; +} + +/** + * Encode a color as RGBA8 format + * @param color Source color to encode + * @param bytes Destination pointer to store encoded color + */ +inline void EncodeRGBA8(const Math::Vec4& color, u8* bytes) { + bytes[3] = color.r(); + bytes[2] = color.g(); + bytes[1] = color.b(); + bytes[0] = color.a(); +} + +/** + * Encode a color as RGB8 format + * @param color Source color to encode + * @param bytes Destination pointer to store encoded color + */ +inline void EncodeRGB8(const Math::Vec4& color, u8* bytes) { + bytes[2] = color.r(); + bytes[1] = color.g(); + bytes[0] = color.b(); +} + +/** + * Encode a color as RGB565 format + * @param color Source color to encode + * @param bytes Destination pointer to store encoded color + */ +inline void EncodeRGB565(const Math::Vec4& color, u8* bytes) { + *reinterpret_cast(bytes) = (Convert8To5(color.r()) << 11) | + (Convert8To6(color.g()) << 5) | Convert8To5(color.b()); +} + +/** + * Encode a color as RGB5A1 format + * @param color Source color to encode + * @param bytes Destination pointer to store encoded color + */ +inline void EncodeRGB5A1(const Math::Vec4& color, u8* bytes) { + *reinterpret_cast(bytes) = (Convert8To5(color.r()) << 11) | + (Convert8To5(color.g()) << 6) | (Convert8To5(color.b()) << 1) | Convert8To1(color.a()); +} + +/** + * Encode a color as RGBA4 format + * @param color Source color to encode + * @param bytes Destination pointer to store encoded color + */ +inline void EncodeRGBA4(const Math::Vec4& color, u8* bytes) { + *reinterpret_cast(bytes) = (Convert8To4(color.r()) << 12) | + (Convert8To4(color.g()) << 8) | (Convert8To4(color.b()) << 4) | Convert8To4(color.a()); +} + +/** + * Encode a 16 bit depth value as D16 format + * @param value 16 bit source depth value to encode + * @param bytes Pointer where to store the encoded value + */ +inline void EncodeD16(u32 value, u8* bytes) { + *reinterpret_cast(bytes) = value & 0xFFFF; +} + +/** + * Encode a 24 bit depth value as D24 format + * @param value 24 bit source depth value to encode + * @param bytes Pointer where to store the encoded value + */ +inline void EncodeD24(u32 value, u8* bytes) { + bytes[0] = value & 0xFF; + bytes[1] = (value >> 8) & 0xFF; + bytes[2] = (value >> 16) & 0xFF; +} + +/** + * Encode a 24 bit depth and 8 bit stencil values as D24S8 format + * @param depth 24 bit source depth value to encode + * @param stencil 8 bit source stencil value to encode + * @param bytes Pointer where to store the encoded value + */ +inline void EncodeD24S8(u32 depth, u8 stencil, u8* bytes) { + *reinterpret_cast(bytes) = (stencil << 24) | depth; +} + +} // namespace diff --git a/src/core/hw/gpu.cpp b/src/core/hw/gpu.cpp index ed607646..fe93b369 100644 --- a/src/core/hw/gpu.cpp +++ b/src/core/hw/gpu.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include "common/color.h" #include "common/common_types.h" #include "core/arm/arm_interface.h" @@ -22,7 +23,6 @@ #include "video_core/command_processor.h" #include "video_core/utils.h" #include "video_core/video_core.h" -#include "video_core/color.h" namespace GPU { diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt index f50f73b5..5c7f4ae1 100644 --- a/src/video_core/CMakeLists.txt +++ b/src/video_core/CMakeLists.txt @@ -29,7 +29,6 @@ set(HEADERS renderer_opengl/pica_to_gl.h renderer_opengl/renderer_opengl.h clipper.h - color.h command_processor.h gpu_debugger.h hwrasterizer_base.h diff --git a/src/video_core/color.h b/src/video_core/color.h deleted file mode 100644 index 422fdc8a..00000000 --- a/src/video_core/color.h +++ /dev/null @@ -1,214 +0,0 @@ -// Copyright 2014 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#pragma once - -#include "common/common_types.h" -#include "common/swap.h" -#include "common/vector_math.h" - -namespace Color { - -/// Convert a 1-bit color component to 8 bit -inline u8 Convert1To8(u8 value) { - return value * 255; -} - -/// Convert a 4-bit color component to 8 bit -inline u8 Convert4To8(u8 value) { - return (value << 4) | value; -} - -/// Convert a 5-bit color component to 8 bit -inline u8 Convert5To8(u8 value) { - return (value << 3) | (value >> 2); -} - -/// Convert a 6-bit color component to 8 bit -inline u8 Convert6To8(u8 value) { - return (value << 2) | (value >> 4); -} - -/// Convert a 8-bit color component to 1 bit -inline u8 Convert8To1(u8 value) { - return value >> 7; -} - -/// Convert a 8-bit color component to 4 bit -inline u8 Convert8To4(u8 value) { - return value >> 4; -} - -/// Convert a 8-bit color component to 5 bit -inline u8 Convert8To5(u8 value) { - return value >> 3; -} - -/// Convert a 8-bit color component to 6 bit -inline u8 Convert8To6(u8 value) { - return value >> 2; -} - -/** - * Decode a color stored in RGBA8 format - * @param bytes Pointer to encoded source color - * @return Result color decoded as Math::Vec4 - */ -inline const Math::Vec4 DecodeRGBA8(const u8* bytes) { - return { bytes[3], bytes[2], bytes[1], bytes[0] }; -} - -/** - * Decode a color stored in RGB8 format - * @param bytes Pointer to encoded source color - * @return Result color decoded as Math::Vec4 - */ -inline const Math::Vec4 DecodeRGB8(const u8* bytes) { - return { bytes[2], bytes[1], bytes[0], 255 }; -} - -/** - * Decode a color stored in RGB565 format - * @param bytes Pointer to encoded source color - * @return Result color decoded as Math::Vec4 - */ -inline const Math::Vec4 DecodeRGB565(const u8* bytes) { - const u16_le pixel = *reinterpret_cast(bytes); - return { Convert5To8((pixel >> 11) & 0x1F), Convert6To8((pixel >> 5) & 0x3F), - Convert5To8(pixel & 0x1F), 255 }; -} - -/** - * Decode a color stored in RGB5A1 format - * @param bytes Pointer to encoded source color - * @return Result color decoded as Math::Vec4 - */ -inline const Math::Vec4 DecodeRGB5A1(const u8* bytes) { - const u16_le pixel = *reinterpret_cast(bytes); - return { Convert5To8((pixel >> 11) & 0x1F), Convert5To8((pixel >> 6) & 0x1F), - Convert5To8((pixel >> 1) & 0x1F), Convert1To8(pixel & 0x1) }; -} - -/** - * Decode a color stored in RGBA4 format - * @param bytes Pointer to encoded source color - * @return Result color decoded as Math::Vec4 - */ -inline const Math::Vec4 DecodeRGBA4(const u8* bytes) { - const u16_le pixel = *reinterpret_cast(bytes); - return { Convert4To8((pixel >> 12) & 0xF), Convert4To8((pixel >> 8) & 0xF), - Convert4To8((pixel >> 4) & 0xF), Convert4To8(pixel & 0xF) }; -} - -/** - * Decode a depth value stored in D16 format - * @param bytes Pointer to encoded source value - * @return Depth value as an u32 - */ -inline u32 DecodeD16(const u8* bytes) { - return *reinterpret_cast(bytes); -} - -/** - * Decode a depth value stored in D24 format - * @param bytes Pointer to encoded source value - * @return Depth value as an u32 - */ -inline u32 DecodeD24(const u8* bytes) { - return (bytes[2] << 16) | (bytes[1] << 8) | bytes[0]; -} - -/** - * Decode a depth value and a stencil value stored in D24S8 format - * @param bytes Pointer to encoded source values - * @return Resulting values stored as a Math::Vec2 - */ -inline const Math::Vec2 DecodeD24S8(const u8* bytes) { - return { static_cast((bytes[2] << 16) | (bytes[1] << 8) | bytes[0]), bytes[3] }; -} - -/** - * Encode a color as RGBA8 format - * @param color Source color to encode - * @param bytes Destination pointer to store encoded color - */ -inline void EncodeRGBA8(const Math::Vec4& color, u8* bytes) { - bytes[3] = color.r(); - bytes[2] = color.g(); - bytes[1] = color.b(); - bytes[0] = color.a(); -} - -/** - * Encode a color as RGB8 format - * @param color Source color to encode - * @param bytes Destination pointer to store encoded color - */ -inline void EncodeRGB8(const Math::Vec4& color, u8* bytes) { - bytes[2] = color.r(); - bytes[1] = color.g(); - bytes[0] = color.b(); -} - -/** - * Encode a color as RGB565 format - * @param color Source color to encode - * @param bytes Destination pointer to store encoded color - */ -inline void EncodeRGB565(const Math::Vec4& color, u8* bytes) { - *reinterpret_cast(bytes) = (Convert8To5(color.r()) << 11) | - (Convert8To6(color.g()) << 5) | Convert8To5(color.b()); -} - -/** - * Encode a color as RGB5A1 format - * @param color Source color to encode - * @param bytes Destination pointer to store encoded color - */ -inline void EncodeRGB5A1(const Math::Vec4& color, u8* bytes) { - *reinterpret_cast(bytes) = (Convert8To5(color.r()) << 11) | - (Convert8To5(color.g()) << 6) | (Convert8To5(color.b()) << 1) | Convert8To1(color.a()); -} - -/** - * Encode a color as RGBA4 format - * @param color Source color to encode - * @param bytes Destination pointer to store encoded color - */ -inline void EncodeRGBA4(const Math::Vec4& color, u8* bytes) { - *reinterpret_cast(bytes) = (Convert8To4(color.r()) << 12) | - (Convert8To4(color.g()) << 8) | (Convert8To4(color.b()) << 4) | Convert8To4(color.a()); -} - -/** - * Encode a 16 bit depth value as D16 format - * @param value 16 bit source depth value to encode - * @param bytes Pointer where to store the encoded value - */ -inline void EncodeD16(u32 value, u8* bytes) { - *reinterpret_cast(bytes) = value & 0xFFFF; -} - -/** - * Encode a 24 bit depth value as D24 format - * @param value 24 bit source depth value to encode - * @param bytes Pointer where to store the encoded value - */ -inline void EncodeD24(u32 value, u8* bytes) { - bytes[0] = value & 0xFF; - bytes[1] = (value >> 8) & 0xFF; - bytes[2] = (value >> 16) & 0xFF; -} - -/** - * Encode a 24 bit depth and 8 bit stencil values as D24S8 format - * @param depth 24 bit source depth value to encode - * @param stencil 8 bit source stencil value to encode - * @param bytes Pointer where to store the encoded value - */ -inline void EncodeD24S8(u32 depth, u8 stencil, u8* bytes) { - *reinterpret_cast(bytes) = (stencil << 24) | depth; -} - -} // namespace diff --git a/src/video_core/debug_utils/debug_utils.cpp b/src/video_core/debug_utils/debug_utils.cpp index 5392dae2..7b8ab72b 100644 --- a/src/video_core/debug_utils/debug_utils.cpp +++ b/src/video_core/debug_utils/debug_utils.cpp @@ -17,11 +17,11 @@ #include #include "common/assert.h" +#include "common/color.h" #include "common/file_util.h" #include "common/math_util.h" #include "common/vector_math.h" -#include "video_core/color.h" #include "video_core/pica.h" #include "video_core/utils.h" #include "video_core/video_core.h" diff --git a/src/video_core/rasterizer.cpp b/src/video_core/rasterizer.cpp index 6df3a74f..93288be2 100644 --- a/src/video_core/rasterizer.cpp +++ b/src/video_core/rasterizer.cpp @@ -4,6 +4,7 @@ #include +#include "common/color.h" #include "common/common_types.h" #include "common/math_util.h" #include "common/profiler.h" @@ -13,7 +14,6 @@ #include "debug_utils/debug_utils.h" #include "math.h" -#include "color.h" #include "pica.h" #include "rasterizer.h" #include "vertex_shader.h" diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index bacdb717..e33a712c 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -2,10 +2,11 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include "common/color.h" + #include "core/settings.h" #include "core/hw/gpu.h" -#include "video_core/color.h" #include "video_core/pica.h" #include "video_core/utils.h" #include "video_core/renderer_opengl/gl_rasterizer.h" -- cgit v1.2.3