Skip to content

Commit 5356e5c

Browse files
committed
Implemented full gamma correction for top LCDs which improves colors noticeably without crushing details in shadows.
The disadvantage is that the gbaGamma, lcdGamma, brightness and contrast settings don't work anymore for now. They will be reimplemented with color profile settings later.
1 parent 67ce019 commit 5356e5c

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

source/arm11/oaf_video.c

+50-2
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,39 @@
4343

4444

4545
static KHandle g_convFinishedEvent = 0;
46+
static const u32 g_topLcdCurveCorrect[73] =
47+
{
48+
// Curve correction from 3DS top LCD gamma to 2.2 gamma for all channels.
49+
// Unfortunately this doesn't fix color temperature but that varies wildly
50+
// for all 2/3DS consoles on the market anyway.
51+
0x01000000, 0x03020102, 0x00060406, 0x01060507,
52+
0x03080608, 0x020B090C, 0x010E0B0F, 0x010F0D10,
53+
0x01110E12, 0x01121014, 0x00141116, 0x00151216,
54+
0x01151317, 0x01171419, 0x0118161B, 0x011A171C,
55+
0x021B191E, 0x001E1B21, 0x011E1C22, 0x01201E23,
56+
0x03211F25, 0x01242329, 0x0226242B, 0x0028272E,
57+
0x0229282E, 0x002B2B31, 0x042C2B32, 0x04303037,
58+
0x0034353C, 0x0535353D, 0x073A3B43, 0x0A41434B,
59+
0x034B4E56, 0x084F525B, 0x0D575B64, 0x03656973,
60+
0x12686D77, 0x017B818A, 0x167C838C, 0x03939AA4,
61+
0x0E979FA8, 0x01A6AFB7, 0x06A9B1B9, 0x01B0B9C0,
62+
0x00B2BBC3, 0x04B4BCC4, 0x00B9C2C9, 0x04BBC3CA,
63+
0x00C1C8CF, 0x00C2CAD0, 0x02C3CBD2, 0x01C7CED5,
64+
0x00C9D1D7, 0x03CBD2D8, 0x00D0D7DC, 0x01D1D8DE,
65+
0x01D4DAE0, 0x00D6DDE2, 0x02D8DEE3, 0x00DCE1E6,
66+
0x01DDE3E7, 0x02E0E5EA, 0x01E4E9ED, 0x02E7EBEF,
67+
0x01EBEFF2, 0x01EEF1F4, 0x00F1F3F6, 0x01F2F5F7,
68+
0x01F5F7F9, 0x01F8F9FB, 0x00FAFCFD, 0x01FCFDFD,
69+
0x00FFFFFF
70+
};
4671

4772

4873

74+
// TODO: Reimplement contrast and brightness in color lut below.
4975
static void adjustGammaTableForGba(void)
5076
{
5177
// Credits for this algo go to Extrems.
52-
const float targetGamma = g_oafConfig.gbaGamma;
78+
/*const float targetGamma = g_oafConfig.gbaGamma;
5379
const float lcdGamma = 1.f / g_oafConfig.lcdGamma;
5480
const float contrast = g_oafConfig.contrast;
5581
const float brightness = g_oafConfig.brightness / contrast;
@@ -65,7 +91,29 @@ static void adjustGammaTableForGba(void)
6591
6692
// Same adjustment for red/green/blue.
6793
*color_lut_data = res<<16 | res<<8 | res;
68-
}
94+
}*/
95+
96+
// Very simple gamma table expansion code.
97+
// Code + hardcoded tables are way smaller than hardcoding the uncompressed tables.
98+
const u32 *encTable = g_topLcdCurveCorrect;
99+
vu32 *const color_lut_data = &getGxRegs()->pdc0.color_lut_data;
100+
u32 decoded = 0;
101+
do
102+
{
103+
// Get table entry and extract the number of linearly increasing entries.
104+
u32 entry = *encTable++;
105+
u32 steps = (entry>>24) + 1;
106+
107+
// Keep track of how many table entries we generated.
108+
decoded += steps;
109+
do
110+
{
111+
// Set gamma table entry and increment.
112+
// Note: Bits 24-31 don't matter so we don't need to mask.
113+
*color_lut_data = entry;
114+
entry += 0x010101;
115+
} while(--steps != 0);
116+
} while(decoded < 256);
69117
}
70118

71119
typedef struct

0 commit comments

Comments
 (0)