diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/citra_qt/debugger/graphics_framebuffer.cpp | 13 | ||||
| -rw-r--r-- | src/video_core/color.h | 32 | ||||
| -rw-r--r-- | src/video_core/debug_utils/debug_utils.cpp | 32 |
3 files changed, 51 insertions, 26 deletions
diff --git a/src/citra_qt/debugger/graphics_framebuffer.cpp b/src/citra_qt/debugger/graphics_framebuffer.cpp index 4a45027b8..a9e9de652 100644 --- a/src/citra_qt/debugger/graphics_framebuffer.cpp +++ b/src/citra_qt/debugger/graphics_framebuffer.cpp | |||
| @@ -10,6 +10,7 @@ | |||
| 10 | #include <QPushButton> | 10 | #include <QPushButton> |
| 11 | #include <QSpinBox> | 11 | #include <QSpinBox> |
| 12 | 12 | ||
| 13 | #include "video_core/color.h" | ||
| 13 | #include "video_core/pica.h" | 14 | #include "video_core/pica.h" |
| 14 | 15 | ||
| 15 | #include "graphics_framebuffer.hxx" | 16 | #include "graphics_framebuffer.hxx" |
| @@ -259,14 +260,10 @@ void GraphicsFramebufferWidget::OnUpdate() | |||
| 259 | for (unsigned y = 0; y < framebuffer_height; ++y) { | 260 | for (unsigned y = 0; y < framebuffer_height; ++y) { |
| 260 | for (unsigned x = 0; x < framebuffer_width; ++x) { | 261 | for (unsigned x = 0; x < framebuffer_width; ++x) { |
| 261 | u16 value = *(u16*)(((u8*)color_buffer) + x * 2 + y * framebuffer_width * 2); | 262 | u16 value = *(u16*)(((u8*)color_buffer) + x * 2 + y * framebuffer_width * 2); |
| 262 | u8 r = (value >> 11) & 0x1F; | 263 | u8 r = Color::Convert5To8((value >> 11) & 0x1F); |
| 263 | u8 g = (value >> 6) & 0x1F; | 264 | u8 g = Color::Convert5To8((value >> 6) & 0x1F); |
| 264 | u8 b = (value >> 1) & 0x1F; | 265 | u8 b = Color::Convert5To8((value >> 1) & 0x1F); |
| 265 | u8 a = value & 1; | 266 | u8 a = Color::Convert1To8(value & 1); |
| 266 | r = (r << 3) | (r >> 2); | ||
| 267 | g = (g << 3) | (g >> 2); | ||
| 268 | b = (b << 3) | (b >> 2); | ||
| 269 | a *= 255; | ||
| 270 | 267 | ||
| 271 | decoded_image.setPixel(x, y, qRgba(r, g, b, 255/*a*/)); | 268 | decoded_image.setPixel(x, y, qRgba(r, g, b, 255/*a*/)); |
| 272 | } | 269 | } |
diff --git a/src/video_core/color.h b/src/video_core/color.h new file mode 100644 index 000000000..e86ac1265 --- /dev/null +++ b/src/video_core/color.h | |||
| @@ -0,0 +1,32 @@ | |||
| 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 "common/common_types.h" | ||
| 8 | |||
| 9 | namespace Color { | ||
| 10 | |||
| 11 | /// Convert a 1-bit color component to 8 bit | ||
| 12 | static inline u8 Convert1To8(u8 value) { | ||
| 13 | return value * 255; | ||
| 14 | } | ||
| 15 | |||
| 16 | /// Convert a 4-bit color component to 8 bit | ||
| 17 | static inline u8 Convert4To8(u8 value) { | ||
| 18 | return (value << 4) | value; | ||
| 19 | } | ||
| 20 | |||
| 21 | /// Convert a 5-bit color component to 8 bit | ||
| 22 | static inline u8 Convert5To8(u8 value) { | ||
| 23 | return (value << 3) | (value >> 2); | ||
| 24 | } | ||
| 25 | |||
| 26 | /// Convert a 6-bit color component to 8 bit | ||
| 27 | static inline u8 Convert6To8(u8 value) { | ||
| 28 | return (value << 2) | (value >> 4); | ||
| 29 | } | ||
| 30 | |||
| 31 | |||
| 32 | } // namespace | ||
diff --git a/src/video_core/debug_utils/debug_utils.cpp b/src/video_core/debug_utils/debug_utils.cpp index 83d585d16..a494465b9 100644 --- a/src/video_core/debug_utils/debug_utils.cpp +++ b/src/video_core/debug_utils/debug_utils.cpp | |||
| @@ -19,6 +19,7 @@ | |||
| 19 | #include "common/log.h" | 19 | #include "common/log.h" |
| 20 | #include "common/file_util.h" | 20 | #include "common/file_util.h" |
| 21 | 21 | ||
| 22 | #include "video_core/color.h" | ||
| 22 | #include "video_core/math.h" | 23 | #include "video_core/math.h" |
| 23 | #include "video_core/pica.h" | 24 | #include "video_core/pica.h" |
| 24 | 25 | ||
| @@ -359,29 +360,26 @@ const Math::Vec4<u8> LookupTexture(const u8* source, int x, int y, const Texture | |||
| 359 | u8 g = ((source_ptr) >> 6) & 0x1F; | 360 | u8 g = ((source_ptr) >> 6) & 0x1F; |
| 360 | u8 b = (source_ptr >> 1) & 0x1F; | 361 | u8 b = (source_ptr >> 1) & 0x1F; |
| 361 | u8 a = source_ptr & 1; | 362 | u8 a = source_ptr & 1; |
| 362 | return Math::MakeVec<u8>((r << 3) | (r >> 2), (g << 3) | (g >> 2), (b << 3) | (b >> 2), disable_alpha ? 255 : (a * 255)); | 363 | return Math::MakeVec<u8>(Color::Convert5To8(r), Color::Convert5To8(g), |
| 364 | Color::Convert5To8(b), disable_alpha ? 255 : Color::Convert1To8(a)); | ||
| 363 | } | 365 | } |
| 364 | 366 | ||
| 365 | case Regs::TextureFormat::RGB565: | 367 | case Regs::TextureFormat::RGB565: |
| 366 | { | 368 | { |
| 367 | const u16 source_ptr = *(const u16*)(source + offset * 2); | 369 | const u16 source_ptr = *(const u16*)(source + offset * 2); |
| 368 | u8 r = (source_ptr >> 11) & 0x1F; | 370 | u8 r = Color::Convert5To8((source_ptr >> 11) & 0x1F); |
| 369 | u8 g = ((source_ptr) >> 5) & 0x3F; | 371 | u8 g = Color::Convert6To8(((source_ptr) >> 5) & 0x3F); |
| 370 | u8 b = (source_ptr) & 0x1F; | 372 | u8 b = Color::Convert5To8((source_ptr) & 0x1F); |
| 371 | return Math::MakeVec<u8>((r << 3) | (r >> 2), (g << 2) | (g >> 4), (b << 3) | (b >> 2), 255); | 373 | return Math::MakeVec<u8>(r, g, b, 255); |
| 372 | } | 374 | } |
| 373 | 375 | ||
| 374 | case Regs::TextureFormat::RGBA4: | 376 | case Regs::TextureFormat::RGBA4: |
| 375 | { | 377 | { |
| 376 | const u8* source_ptr = source + offset * 2; | 378 | const u8* source_ptr = source + offset * 2; |
| 377 | u8 r = source_ptr[1] >> 4; | 379 | u8 r = Color::Convert4To8(source_ptr[1] >> 4); |
| 378 | u8 g = source_ptr[1] & 0xF; | 380 | u8 g = Color::Convert4To8(source_ptr[1] & 0xF); |
| 379 | u8 b = source_ptr[0] >> 4; | 381 | u8 b = Color::Convert4To8(source_ptr[0] >> 4); |
| 380 | u8 a = source_ptr[0] & 0xF; | 382 | u8 a = Color::Convert4To8(source_ptr[0] & 0xF); |
| 381 | r = (r << 4) | r; | ||
| 382 | g = (g << 4) | g; | ||
| 383 | b = (b << 4) | b; | ||
| 384 | a = (a << 4) | a; | ||
| 385 | return { r, g, b, disable_alpha ? (u8)255 : a }; | 383 | return { r, g, b, disable_alpha ? (u8)255 : a }; |
| 386 | } | 384 | } |
| 387 | 385 | ||
| @@ -418,10 +416,8 @@ const Math::Vec4<u8> LookupTexture(const u8* source, int x, int y, const Texture | |||
| 418 | { | 416 | { |
| 419 | const u8* source_ptr = source + offset; | 417 | const u8* source_ptr = source + offset; |
| 420 | 418 | ||
| 421 | u8 i = ((*source_ptr) & 0xF0) >> 4; | 419 | u8 i = Color::Convert4To8(((*source_ptr) & 0xF0) >> 4); |
| 422 | u8 a = (*source_ptr) & 0xF; | 420 | u8 a = Color::Convert4To8((*source_ptr) & 0xF); |
| 423 | a |= a << 4; | ||
| 424 | i |= i << 4; | ||
| 425 | 421 | ||
| 426 | if (disable_alpha) { | 422 | if (disable_alpha) { |
| 427 | // Show intensity as red, alpha as green | 423 | // Show intensity as red, alpha as green |
| @@ -436,7 +432,7 @@ const Math::Vec4<u8> LookupTexture(const u8* source, int x, int y, const Texture | |||
| 436 | const u8* source_ptr = source + offset / 2; | 432 | const u8* source_ptr = source + offset / 2; |
| 437 | 433 | ||
| 438 | u8 a = (coarse_x % 2) ? ((*source_ptr)&0xF) : (((*source_ptr) & 0xF0) >> 4); | 434 | u8 a = (coarse_x % 2) ? ((*source_ptr)&0xF) : (((*source_ptr) & 0xF0) >> 4); |
| 439 | a |= a << 4; | 435 | a = Color::Convert4To8(a); |
| 440 | 436 | ||
| 441 | if (disable_alpha) { | 437 | if (disable_alpha) { |
| 442 | return { a, a, a, 255 }; | 438 | return { a, a, a, 255 }; |