From 39d3754b1806ea92e1a493bdea8cf820f7db47a4 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Sat, 26 Apr 2025 11:35:10 +0200 Subject: [PATCH] cellVideoOutConvertCursorColor: fix and implement --- rpcs3/Emu/Cell/Modules/cellAvconfExt.cpp | 72 +++++++++++++++++++++++- rpcs3/Emu/Cell/Modules/cellVideoOut.cpp | 2 +- 2 files changed, 70 insertions(+), 4 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/cellAvconfExt.cpp b/rpcs3/Emu/Cell/Modules/cellAvconfExt.cpp index 32b44ccd59..b4508ada5b 100644 --- a/rpcs3/Emu/Cell/Modules/cellAvconfExt.cpp +++ b/rpcs3/Emu/Cell/Modules/cellAvconfExt.cpp @@ -237,17 +237,57 @@ error_code cellAudioInGetDeviceInfo(u32 deviceNumber, u32 deviceIndex, vm::ptr +void convert_cursor_color(const u8* src, u8* dst, s32 num, f32 gamma) +{ + for (s32 i = 0; i < num; i++, src += 4, dst += 4) + { + for (s32 c = 1; c < 4; c++) + { + if constexpr (Is_Float) + { + if constexpr (Range_Limited) + { + const f32 val = (src[c] / 255.0f) * 219.0f + 16.0f; + dst[c] = static_cast(val + 0.5f); + } + else + { + dst[c] = src[c]; + } + } + else + { + f32 val = std::clamp(std::pow(src[c] / 255.0f, gamma), 0.0f, 1.0f); + + if constexpr (Range_Limited) + { + val = val * 219.0f + 16.0f; + } + else + { + val *= 255.0f; + } + + dst[c] = static_cast(val + 0.5f); + } + } + } +} + error_code cellVideoOutConvertCursorColor(u32 videoOut, s32 displaybuffer_format, f32 gamma, s32 source_buffer_format, vm::ptr src_addr, vm::ptr dest_addr, s32 num) { - cellAvconfExt.todo("cellVideoOutConvertCursorColor(videoOut=%d, displaybuffer_format=0x%x, gamma=0x%x, source_buffer_format=0x%x, src_addr=*0x%x, dest_addr=*0x%x, num=0x%x)", videoOut, + cellAvconfExt.warning("cellVideoOutConvertCursorColor(videoOut=%d, displaybuffer_format=0x%x, gamma=%f, source_buffer_format=0x%x, src_addr=*0x%x, dest_addr=*0x%x, num=0x%x)", videoOut, displaybuffer_format, gamma, source_buffer_format, src_addr, dest_addr, num); - if (!dest_addr || num == 0) + if (!src_addr || !dest_addr) { return CELL_VIDEO_OUT_ERROR_ILLEGAL_PARAMETER; } - if (displaybuffer_format > CELL_VIDEO_OUT_BUFFER_COLOR_FORMAT_R16G16B16X16_FLOAT || src_addr) + if (displaybuffer_format < 0 || + displaybuffer_format > CELL_VIDEO_OUT_BUFFER_COLOR_FORMAT_R16G16B16X16_FLOAT || + source_buffer_format != CELL_VIDEO_OUT_BUFFER_COLOR_FORMAT_X8R8G8B8) { return CELL_VIDEO_OUT_ERROR_PARAMETER_OUT_OF_RANGE; } @@ -268,6 +308,32 @@ error_code cellVideoOutConvertCursorColor(u32 videoOut, s32 displaybuffer_format return error; } + const u8* src = reinterpret_cast(src_addr.get_ptr()); + u8* dst = reinterpret_cast(dest_addr.get_ptr()); + + if (displaybuffer_format == CELL_VIDEO_OUT_BUFFER_COLOR_FORMAT_R16G16B16X16_FLOAT) + { + if (*rgbOutputRange == CELL_VIDEO_OUT_RGB_OUTPUT_RANGE_LIMITED) + { + convert_cursor_color(src, dst, num, gamma); + } + else + { + convert_cursor_color(src, dst, num, gamma); + } + } + else + { + if (*rgbOutputRange == CELL_VIDEO_OUT_RGB_OUTPUT_RANGE_LIMITED) + { + convert_cursor_color(src, dst, num, gamma); + } + else + { + convert_cursor_color(src, dst, num, gamma); + } + } + return CELL_OK; } diff --git a/rpcs3/Emu/Cell/Modules/cellVideoOut.cpp b/rpcs3/Emu/Cell/Modules/cellVideoOut.cpp index 330604a34a..e0db365933 100644 --- a/rpcs3/Emu/Cell/Modules/cellVideoOut.cpp +++ b/rpcs3/Emu/Cell/Modules/cellVideoOut.cpp @@ -423,7 +423,7 @@ error_code cellVideoOutGetDeviceInfo(u32 videoOut, u32 deviceIndex, vm::ptr