Skip to content

Commit

Permalink
Colorspace Handler: Add new functions for 16-bit to 18-bit and 32-bit…
Browse files Browse the repository at this point in the history
… color conversion, now respecting the 16-bit color's alpha bit.

- ColorspaceConvert5551To8888()
- ColorspaceConvert5551To6665()
- ColorspaceConvertBuffer5551To8888()
- ColorspaceConvertBuffer5551To6665()
- Also rename the existing 16-bit color conversion functions to help further distinguish the functions from one another.
  • Loading branch information
rogerman committed Jul 15, 2024
1 parent 4b0805e commit 586aea5
Show file tree
Hide file tree
Showing 29 changed files with 1,686 additions and 787 deletions.
6 changes: 3 additions & 3 deletions desmume/src/FIFO.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Copyright 2006 yopyop
Copyright 2007 shash
Copyright 2007-2023 DeSmuME team
Copyright 2007-2024 DeSmuME team
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -489,11 +489,11 @@ void DISP_FIFOrecv_LineOpaque(u32 *__restrict dst)
}
else if (OUTPUTFORMAT == NDSColorFormat_BGR666_Rev)
{
ColorspaceConvertBuffer555To6665Opaque<false, false, BESwapDst>((u16 *)(disp_fifo.buf + disp_fifo.head), dst, GPU_FRAMEBUFFER_NATIVE_WIDTH);
ColorspaceConvertBuffer555xTo6665Opaque<false, false, BESwapDst>((u16 *)(disp_fifo.buf + disp_fifo.head), dst, GPU_FRAMEBUFFER_NATIVE_WIDTH);
}
else if (OUTPUTFORMAT == NDSColorFormat_BGR888_Rev)
{
ColorspaceConvertBuffer555To8888Opaque<false, false, BESwapDst>((u16 *)(disp_fifo.buf + disp_fifo.head), dst, GPU_FRAMEBUFFER_NATIVE_WIDTH);
ColorspaceConvertBuffer555xTo8888Opaque<false, false, BESwapDst>((u16 *)(disp_fifo.buf + disp_fifo.head), dst, GPU_FRAMEBUFFER_NATIVE_WIDTH);
}

_DISP_FIFOrecv_LineAdvance();
Expand Down
32 changes: 16 additions & 16 deletions desmume/src/GPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Copyright (C) 2006 yopyop
Copyright (C) 2006-2007 Theo Berkau
Copyright (C) 2007 shash
Copyright (C) 2008-2023 DeSmuME team
Copyright (C) 2008-2024 DeSmuME team
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -1032,12 +1032,12 @@ void GPUEngineBase::_TransitionLineNativeToCustom(GPUEngineCompositorInfo &compI
{
if ( (compInfo.line.widthCustom == GPU_FRAMEBUFFER_NATIVE_WIDTH) && (compInfo.line.renderCount == 1) )
{
ColorspaceConvertBuffer555To6665Opaque<false, false, BESwapDst>((u16 *)compInfo.target.lineColorHeadNative, (u32 *)compInfo.target.lineColorHeadCustom, GPU_FRAMEBUFFER_NATIVE_WIDTH);
ColorspaceConvertBuffer555xTo6665Opaque<false, false, BESwapDst>((u16 *)compInfo.target.lineColorHeadNative, (u32 *)compInfo.target.lineColorHeadCustom, GPU_FRAMEBUFFER_NATIVE_WIDTH);
}
else
{
u32 *workingNativeBuffer32 = this->_targetDisplay->GetWorkingNativeBuffer32();
ColorspaceConvertBuffer555To6665Opaque<false, false, BESwapDst>((u16 *)compInfo.target.lineColorHeadNative, workingNativeBuffer32 + compInfo.line.blockOffsetNative, GPU_FRAMEBUFFER_NATIVE_WIDTH);
ColorspaceConvertBuffer555xTo6665Opaque<false, false, BESwapDst>((u16 *)compInfo.target.lineColorHeadNative, workingNativeBuffer32 + compInfo.line.blockOffsetNative, GPU_FRAMEBUFFER_NATIVE_WIDTH);
CopyLineExpandHinted<0x3FFF, true, false, false, 4>(compInfo.line, workingNativeBuffer32 + compInfo.line.blockOffsetNative, compInfo.target.lineColorHeadCustom);
}
break;
Expand All @@ -1047,12 +1047,12 @@ void GPUEngineBase::_TransitionLineNativeToCustom(GPUEngineCompositorInfo &compI
{
if ( (compInfo.line.widthCustom == GPU_FRAMEBUFFER_NATIVE_WIDTH) && (compInfo.line.renderCount == 1) )
{
ColorspaceConvertBuffer555To8888Opaque<false, false, BESwapDst>((u16 *)compInfo.target.lineColorHeadNative, (u32 *)compInfo.target.lineColorHeadCustom, GPU_FRAMEBUFFER_NATIVE_WIDTH);
ColorspaceConvertBuffer555xTo8888Opaque<false, false, BESwapDst>((u16 *)compInfo.target.lineColorHeadNative, (u32 *)compInfo.target.lineColorHeadCustom, GPU_FRAMEBUFFER_NATIVE_WIDTH);
}
else
{
u32 *workingNativeBuffer32 = this->_targetDisplay->GetWorkingNativeBuffer32();
ColorspaceConvertBuffer555To8888Opaque<false, false, BESwapDst>((u16 *)compInfo.target.lineColorHeadNative, workingNativeBuffer32 + compInfo.line.blockOffsetNative, GPU_FRAMEBUFFER_NATIVE_WIDTH);
ColorspaceConvertBuffer555xTo8888Opaque<false, false, BESwapDst>((u16 *)compInfo.target.lineColorHeadNative, workingNativeBuffer32 + compInfo.line.blockOffsetNative, GPU_FRAMEBUFFER_NATIVE_WIDTH);
CopyLineExpandHinted<0x3FFF, true, false, false, 4>(compInfo.line, workingNativeBuffer32 + compInfo.line.blockOffsetNative, compInfo.target.lineColorHeadCustom);
}
break;
Expand Down Expand Up @@ -3729,7 +3729,7 @@ void GPUEngineA::_RenderLine_DisplayCaptureCustom(const IOREG_DISPCAPCNT &DISPCA
{
if (OUTPUTFORMAT == NDSColorFormat_BGR888_Rev)
{
ColorspaceConvertBuffer555To8888Opaque<false, false, BESwapDst>(this->_fifoLine16, (u32 *)srcBPtr, GPU_FRAMEBUFFER_NATIVE_WIDTH);
ColorspaceConvertBuffer555xTo8888Opaque<false, false, BESwapDst>(this->_fifoLine16, (u32 *)srcBPtr, GPU_FRAMEBUFFER_NATIVE_WIDTH);
}

this->_RenderLine_DispCapture_Copy<OUTPUTFORMAT, 1, CAPTURELENGTH, true, false>(lineInfo, srcBPtr, dstCustomPtr, captureLengthExt);
Expand All @@ -3755,7 +3755,7 @@ void GPUEngineA::_RenderLine_DisplayCaptureCustom(const IOREG_DISPCAPCNT &DISPCA
else
{
u32 *workingNativeBuffer32 = this->_targetDisplay->GetWorkingNativeBuffer32();
ColorspaceConvertBuffer555To8888Opaque<false, false, BESwapNone>((u16 *)srcAPtr, workingNativeBuffer32 + lineInfo.blockOffsetNative, GPU_FRAMEBUFFER_NATIVE_WIDTH);
ColorspaceConvertBuffer555xTo8888Opaque<false, false, BESwapNone>((u16 *)srcAPtr, workingNativeBuffer32 + lineInfo.blockOffsetNative, GPU_FRAMEBUFFER_NATIVE_WIDTH);
CopyLineExpandHinted<0x3FFF, true, false, false, 4>(lineInfo, workingNativeBuffer32 + lineInfo.blockOffsetNative, this->_captureWorkingA32);
srcAPtr = this->_captureWorkingA32;
}
Expand All @@ -3772,7 +3772,7 @@ void GPUEngineA::_RenderLine_DisplayCaptureCustom(const IOREG_DISPCAPCNT &DISPCA
{
if ((OUTPUTFORMAT == NDSColorFormat_BGR888_Rev) && (DISPCAPCNT.SrcB != 0))
{
ColorspaceConvertBuffer555To8888Opaque<false, false, BESwapDst>(this->_fifoLine16, (u32 *)srcBPtr, GPU_FRAMEBUFFER_NATIVE_WIDTH);
ColorspaceConvertBuffer555xTo8888Opaque<false, false, BESwapDst>(this->_fifoLine16, (u32 *)srcBPtr, GPU_FRAMEBUFFER_NATIVE_WIDTH);
}

CopyLineExpandHinted<0x3FFF, true, false, false, 4>(lineInfo, srcBPtr, this->_captureWorkingB32);
Expand Down Expand Up @@ -3919,7 +3919,7 @@ void GPUEngineA::_RenderLine_DisplayCapture(const GPUEngineCompositorInfo &compI
{
if (willReadNativeVRAM)
{
ColorspaceConvertBuffer555To8888Opaque<false, false, BESwapDst>(vramNative16, (u32 *)vramCustom32, GPU_FRAMEBUFFER_NATIVE_WIDTH);
ColorspaceConvertBuffer555xTo8888Opaque<false, false, BESwapDst>(vramNative16, (u32 *)vramCustom32, GPU_FRAMEBUFFER_NATIVE_WIDTH);
}
}

Expand Down Expand Up @@ -4435,7 +4435,7 @@ void GPUEngineA::_HandleDisplayModeVRAM(const GPUEngineLineInfo &lineInfo)
{
const u16 *src = (u16 *)this->_VRAMCustomBlockPtr[DISPCNT.VRAM_Block] + lineInfo.blockOffsetCustom;
u32 *dst = (u32 *)customBuffer + lineInfo.blockOffsetCustom;
ColorspaceConvertBuffer555To6665Opaque<false, false, BESwapSrcDst>(src, dst, lineInfo.pixelCount);
ColorspaceConvertBuffer555xTo6665Opaque<false, false, BESwapSrcDst>(src, dst, lineInfo.pixelCount);
break;
}

Expand Down Expand Up @@ -5780,11 +5780,11 @@ void GPUSubsystem::_ConvertAndUpscaleForLoadstate(const NDSDisplayID displayID,
switch (this->_display[displayID]->GetColorFormat())
{
case NDSColorFormat_BGR666_Rev:
ColorspaceConvertBuffer555To6665Opaque<false, false, BESwapDst>(src, working, GPU_FRAMEBUFFER_NATIVE_WIDTH * GPU_FRAMEBUFFER_NATIVE_HEIGHT);
ColorspaceConvertBuffer555xTo6665Opaque<false, false, BESwapDst>(src, working, GPU_FRAMEBUFFER_NATIVE_WIDTH * GPU_FRAMEBUFFER_NATIVE_HEIGHT);
break;

case NDSColorFormat_BGR888_Rev:
ColorspaceConvertBuffer555To8888Opaque<false, false, BESwapDst>(src, working, GPU_FRAMEBUFFER_NATIVE_WIDTH * GPU_FRAMEBUFFER_NATIVE_HEIGHT);
ColorspaceConvertBuffer555xTo8888Opaque<false, false, BESwapDst>(src, working, GPU_FRAMEBUFFER_NATIVE_WIDTH * GPU_FRAMEBUFFER_NATIVE_HEIGHT);
break;

default:
Expand Down Expand Up @@ -6212,11 +6212,11 @@ void NDSDisplay::ResolveLinesDisplayedNative()
{
if (this->_customColorFormat == NDSColorFormat_BGR888_Rev)
{
ColorspaceConvertBuffer555To8888Opaque<false, false, BESwapDst>(src, working, GPU_FRAMEBUFFER_NATIVE_WIDTH);
ColorspaceConvertBuffer555xTo8888Opaque<false, false, BESwapDst>(src, working, GPU_FRAMEBUFFER_NATIVE_WIDTH);
}
else
{
ColorspaceConvertBuffer555To6665Opaque<false, false, BESwapDst>(src, working, GPU_FRAMEBUFFER_NATIVE_WIDTH);
ColorspaceConvertBuffer555xTo6665Opaque<false, false, BESwapDst>(src, working, GPU_FRAMEBUFFER_NATIVE_WIDTH);
}

CopyLineExpandHinted<0x3FFF, true, false, false, 4>(lineInfo, working, dst);
Expand Down Expand Up @@ -6256,7 +6256,7 @@ void NDSDisplay::ResolveFramebufferToCustom(NDSDisplayInfo &mutableInfo)
{
case NDSColorFormat_BGR666_Rev:
case NDSColorFormat_BGR888_Rev:
ColorspaceConvertBuffer555To8888Opaque<false, false, BESwapDst>(src, working, GPU_FRAMEBUFFER_NATIVE_WIDTH * GPU_FRAMEBUFFER_NATIVE_HEIGHT);
ColorspaceConvertBuffer555xTo8888Opaque<false, false, BESwapDst>(src, working, GPU_FRAMEBUFFER_NATIVE_WIDTH * GPU_FRAMEBUFFER_NATIVE_HEIGHT);
break;

default:
Expand Down Expand Up @@ -6298,7 +6298,7 @@ void NDSDisplay::ResolveFramebufferToCustom(NDSDisplayInfo &mutableInfo)

case NDSColorFormat_BGR666_Rev:
case NDSColorFormat_BGR888_Rev:
ColorspaceConvertBuffer555To8888Opaque<false, false, BESwapDst>(this->_nativeBuffer16, (u32 *)this->_customBuffer, GPU_FRAMEBUFFER_NATIVE_WIDTH * GPU_FRAMEBUFFER_NATIVE_HEIGHT);
ColorspaceConvertBuffer555xTo8888Opaque<false, false, BESwapDst>(this->_nativeBuffer16, (u32 *)this->_customBuffer, GPU_FRAMEBUFFER_NATIVE_WIDTH * GPU_FRAMEBUFFER_NATIVE_HEIGHT);
break;
}
}
Expand Down
58 changes: 29 additions & 29 deletions desmume/src/GPU_Operations_AVX2.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2021-2023 DeSmuME team
Copyright (C) 2021-2024 DeSmuME team
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -1128,13 +1128,13 @@ FORCEINLINE void PixelOperation_AVX2::_copy16(GPUEngineCompositorInfo &compInfo,

if (OUTPUTFORMAT == NDSColorFormat_BGR666_Rev)
{
ColorspaceConvert555To6665Opaque_AVX2<false>(src0, src32[0], src32[1]);
ColorspaceConvert555To6665Opaque_AVX2<false>(src1, src32[2], src32[3]);
ColorspaceConvert555xTo6665Opaque_AVX2<false>(src0, src32[0], src32[1]);
ColorspaceConvert555xTo6665Opaque_AVX2<false>(src1, src32[2], src32[3]);
}
else
{
ColorspaceConvert555To8888Opaque_AVX2<false>(src0, src32[0], src32[1]);
ColorspaceConvert555To8888Opaque_AVX2<false>(src1, src32[2], src32[3]);
ColorspaceConvert555xTo8888Opaque_AVX2<false>(src0, src32[0], src32[1]);
ColorspaceConvert555xTo8888Opaque_AVX2<false>(src1, src32[2], src32[3]);
}

_mm256_store_si256( (v256u32 *)compInfo.target.lineColor32 + 0, src32[0] );
Expand Down Expand Up @@ -1205,13 +1205,13 @@ FORCEINLINE void PixelOperation_AVX2::_copyMask16(GPUEngineCompositorInfo &compI

if (OUTPUTFORMAT == NDSColorFormat_BGR666_Rev)
{
ColorspaceConvert555To6665Opaque_AVX2<false>(src0, src32[0], src32[1]);
ColorspaceConvert555To6665Opaque_AVX2<false>(src1, src32[2], src32[3]);
ColorspaceConvert555xTo6665Opaque_AVX2<false>(src0, src32[0], src32[1]);
ColorspaceConvert555xTo6665Opaque_AVX2<false>(src1, src32[2], src32[3]);
}
else
{
ColorspaceConvert555To8888Opaque_AVX2<false>(src0, src32[0], src32[1]);
ColorspaceConvert555To8888Opaque_AVX2<false>(src1, src32[2], src32[3]);
ColorspaceConvert555xTo8888Opaque_AVX2<false>(src0, src32[0], src32[1]);
ColorspaceConvert555xTo8888Opaque_AVX2<false>(src1, src32[2], src32[3]);
}

passMask16[0] = _mm256_permute4x64_epi64(passMask16[0], 0xD8);
Expand Down Expand Up @@ -1304,13 +1304,13 @@ FORCEINLINE void PixelOperation_AVX2::_brightnessUp16(GPUEngineCompositorInfo &c

if (OUTPUTFORMAT == NDSColorFormat_BGR666_Rev)
{
ColorspaceConvert555XTo666X_AVX2<false>(src0, dst[0], dst[1]);
ColorspaceConvert555XTo666X_AVX2<false>(src1, dst[2], dst[3]);
ColorspaceConvert555xTo666x_AVX2<false>(src0, dst[0], dst[1]);
ColorspaceConvert555xTo666x_AVX2<false>(src1, dst[2], dst[3]);
}
else
{
ColorspaceConvert555XTo888X_AVX2<false>(src0, dst[0], dst[1]);
ColorspaceConvert555XTo888X_AVX2<false>(src1, dst[2], dst[3]);
ColorspaceConvert555xTo888x_AVX2<false>(src0, dst[0], dst[1]);
ColorspaceConvert555xTo888x_AVX2<false>(src1, dst[2], dst[3]);
}

const v256u32 alphaBits = (OUTPUTFORMAT == NDSColorFormat_BGR666_Rev) ? _mm256_set1_epi32(0x1F000000) : _mm256_set1_epi32(0xFF000000);
Expand Down Expand Up @@ -1377,13 +1377,13 @@ FORCEINLINE void PixelOperation_AVX2::_brightnessUpMask16(GPUEngineCompositorInf

if (OUTPUTFORMAT == NDSColorFormat_BGR666_Rev)
{
ColorspaceConvert555XTo666X_AVX2<false>(src0, src32[0], src32[1]);
ColorspaceConvert555XTo666X_AVX2<false>(src1, src32[2], src32[3]);
ColorspaceConvert555xTo666x_AVX2<false>(src0, src32[0], src32[1]);
ColorspaceConvert555xTo666x_AVX2<false>(src1, src32[2], src32[3]);
}
else
{
ColorspaceConvert555XTo888X_AVX2<false>(src0, src32[0], src32[1]);
ColorspaceConvert555XTo888X_AVX2<false>(src1, src32[2], src32[3]);
ColorspaceConvert555xTo888x_AVX2<false>(src0, src32[0], src32[1]);
ColorspaceConvert555xTo888x_AVX2<false>(src1, src32[2], src32[3]);
}

passMask16[0] = _mm256_permute4x64_epi64(passMask16[0], 0xD8);
Expand Down Expand Up @@ -1471,13 +1471,13 @@ FORCEINLINE void PixelOperation_AVX2::_brightnessDown16(GPUEngineCompositorInfo

if (OUTPUTFORMAT == NDSColorFormat_BGR666_Rev)
{
ColorspaceConvert555XTo666X_AVX2<false>(src0, dst[0], dst[1]);
ColorspaceConvert555XTo666X_AVX2<false>(src1, dst[2], dst[3]);
ColorspaceConvert555xTo666x_AVX2<false>(src0, dst[0], dst[1]);
ColorspaceConvert555xTo666x_AVX2<false>(src1, dst[2], dst[3]);
}
else
{
ColorspaceConvert555XTo888X_AVX2<false>(src0, dst[0], dst[1]);
ColorspaceConvert555XTo888X_AVX2<false>(src1, dst[2], dst[3]);
ColorspaceConvert555xTo888x_AVX2<false>(src0, dst[0], dst[1]);
ColorspaceConvert555xTo888x_AVX2<false>(src1, dst[2], dst[3]);
}

const v256u32 alphaBits = _mm256_set1_epi32((OUTPUTFORMAT == NDSColorFormat_BGR666_Rev) ? 0x1F000000 : 0xFF000000);
Expand Down Expand Up @@ -1544,13 +1544,13 @@ FORCEINLINE void PixelOperation_AVX2::_brightnessDownMask16(GPUEngineCompositorI

if (OUTPUTFORMAT == NDSColorFormat_BGR666_Rev)
{
ColorspaceConvert555XTo666X_AVX2<false>(src0, src32[0], src32[1]);
ColorspaceConvert555XTo666X_AVX2<false>(src1, src32[2], src32[3]);
ColorspaceConvert555xTo666x_AVX2<false>(src0, src32[0], src32[1]);
ColorspaceConvert555xTo666x_AVX2<false>(src1, src32[2], src32[3]);
}
else
{
ColorspaceConvert555XTo888X_AVX2<false>(src0, src32[0], src32[1]);
ColorspaceConvert555XTo888X_AVX2<false>(src1, src32[2], src32[3]);
ColorspaceConvert555xTo888x_AVX2<false>(src0, src32[0], src32[1]);
ColorspaceConvert555xTo888x_AVX2<false>(src1, src32[2], src32[3]);
}

passMask16[0] = _mm256_permute4x64_epi64(passMask16[0], 0xD8);
Expand Down Expand Up @@ -1674,13 +1674,13 @@ FORCEINLINE void PixelOperation_AVX2::_unknownEffectMask16(GPUEngineCompositorIn
}
else if (OUTPUTFORMAT == NDSColorFormat_BGR666_Rev)
{
ColorspaceConvert555XTo666X_AVX2<false>(src0, tmpSrc[0], tmpSrc[1]);
ColorspaceConvert555XTo666X_AVX2<false>(src1, tmpSrc[2], tmpSrc[3]);
ColorspaceConvert555xTo666x_AVX2<false>(src0, tmpSrc[0], tmpSrc[1]);
ColorspaceConvert555xTo666x_AVX2<false>(src1, tmpSrc[2], tmpSrc[3]);
}
else
{
ColorspaceConvert555XTo888X_AVX2<false>(src0, tmpSrc[0], tmpSrc[1]);
ColorspaceConvert555XTo888X_AVX2<false>(src1, tmpSrc[2], tmpSrc[3]);
ColorspaceConvert555xTo888x_AVX2<false>(src0, tmpSrc[0], tmpSrc[1]);
ColorspaceConvert555xTo888x_AVX2<false>(src1, tmpSrc[2], tmpSrc[3]);
}

switch (compInfo.renderState.colorEffect)
Expand Down
Loading

0 comments on commit 586aea5

Please sign in to comment.