From 3f58cb978fa0ec8ed3a8c2fa16d4e1491d440327 Mon Sep 17 00:00:00 2001 From: James Tabor Date: Sat, 29 Dec 2007 06:39:06 +0000 Subject: [PATCH] Fix set device gamma ramp. Now we test the range of the ramp. svn path=/trunk/; revision=31486 --- .../win32/win32k/include/intddraw.h | 2 +- .../subsystems/win32/win32k/ntddraw/dxeng.c | 4 +- reactos/subsystems/win32/win32k/objects/icm.c | 47 +++++++++++++++---- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/reactos/subsystems/win32/win32k/include/intddraw.h b/reactos/subsystems/win32/win32k/include/intddraw.h index c6954efc56f..792b70ddd1c 100644 --- a/reactos/subsystems/win32/win32k/include/intddraw.h +++ b/reactos/subsystems/win32/win32k/include/intddraw.h @@ -123,6 +123,6 @@ typedef BOOL (NTAPI *PGD_ENGUNLOCKDIRECTDRAWSURFACE)(PDD_SURFACE_LOCAL); /* Gammaramp internal prototype */ BOOL FASTCALL IntGetDeviceGammaRamp(HDEV hPDev, PGAMMARAMP Ramp); -BOOL FASTCALL IntSetDeviceGammaRamp(HDEV hPDev, PGAMMARAMP Ramp); +BOOL FASTCALL IntSetDeviceGammaRamp(HDEV hPDev, PGAMMARAMP Ramp, BOOL); #endif /* _INT_W32k_DDRAW */ diff --git a/reactos/subsystems/win32/win32k/ntddraw/dxeng.c b/reactos/subsystems/win32/win32k/ntddraw/dxeng.c index 2c82222a2fb..e2654e2603d 100644 --- a/reactos/subsystems/win32/win32k/ntddraw/dxeng.c +++ b/reactos/subsystems/win32/win32k/ntddraw/dxeng.c @@ -303,9 +303,9 @@ DWORD DxEngUnreferenceHdev(DWORD x1) * *--*/ BOOL -DxEngSetDeviceGammaRamp(HDEV hPDev, PGAMMARAMP Ramp, BOOL Unuse) +DxEngSetDeviceGammaRamp(HDEV hPDev, PGAMMARAMP Ramp, BOOL Test) { - return IntSetDeviceGammaRamp(hPDev, Ramp); + return IntSetDeviceGammaRamp(hPDev, Ramp, Test); } /************************************************************************/ diff --git a/reactos/subsystems/win32/win32k/objects/icm.c b/reactos/subsystems/win32/win32k/objects/icm.c index d113978f88c..ba70e646567 100644 --- a/reactos/subsystems/win32/win32k/objects/icm.c +++ b/reactos/subsystems/win32/win32k/objects/icm.c @@ -245,11 +245,17 @@ UpdateDeviceGammaRamp( HDEV hPDev ) return FALSE; } +// +// ICM registry subkey sets internal brightness range, gamma range is 128 or +// 256 when icm is init. +INT IcmGammaRangeSet = 128; // <- make it global + BOOL FASTCALL -IntSetDeviceGammaRamp(HDEV hPDev, PGAMMARAMP Ramp) +IntSetDeviceGammaRamp(HDEV hPDev, PGAMMARAMP Ramp, BOOL Test) { - BOOL Ret = FALSE; + WORD IcmGR, i, R, G, B; + BOOL Ret = FALSE, TstPeak; PGDIDEVICE pGDev = (PGDIDEVICE) hPDev; if (!hPDev) return FALSE; @@ -274,15 +280,40 @@ IntSetDeviceGammaRamp(HDEV hPDev, PGAMMARAMP Ramp) if (pGDev->flFlags & PDEV_GAMMARAMP_TABLE) if (RtlCompareMemory( pGDev->pvGammaRamp, Ramp, sizeof(GAMMARAMP)) == sizeof(GAMMARAMP)) return TRUE; - + // Verify Ramp is inside range. + IcmGR = -IcmGammaRangeSet; + TstPeak = (Test == FALSE); + for (i = 0; i < 256; i++) + { + R = Ramp->Red[i] / 256; + G = Ramp->Green[i] / 256; + B = Ramp->Blue[i] / 256; + if ( R >= IcmGR) + { + if ( R <= IcmGammaRangeSet + i) + { + if ( G >= IcmGR && + (G <= IcmGammaRangeSet + i) && + B >= IcmGR && + (B <= IcmGammaRangeSet + i) ) continue; + } + } + if (Test) return Ret; // Don't set and return. + // No test override, check max range + if (TstPeak) + { + if ( R != (IcmGR * 256) || + G != (IcmGR * 256) || + B != (IcmGR * 256) ) TstPeak = FALSE; // W/i range. + } + } + // ReactOS allocates a ramp even if it is 8BPP and Palette only. + // This way we have a record of the change in memory. if (!pGDev->pvGammaRamp && !(pGDev->flFlags & PDEV_GAMMARAMP_TABLE)) { // If the above is true and we have nothing allocated, create it. pGDev->pvGammaRamp = ExAllocatePoolWithTag(PagedPool, sizeof(GAMMARAMP), TAG_GDIICM); pGDev->flFlags |= PDEV_GAMMARAMP_TABLE; } - // - // Need to adjust the input Ramp with internal brightness before copy. - // ICM subkey sets internal brightness, gamma range 128 or 256 during icm init. RtlCopyMemory( pGDev->pvGammaRamp, Ramp, sizeof(GAMMARAMP)); Ret = UpdateDeviceGammaRamp(hPDev); @@ -290,7 +321,7 @@ IntSetDeviceGammaRamp(HDEV hPDev, PGAMMARAMP Ramp) return Ret; } else - return FALSE; + return Ret; } BOOL @@ -341,7 +372,7 @@ NtGdiSetDeviceGammaRamp(HDC hDC, return FALSE; } - Ret = IntSetDeviceGammaRamp((HDEV)dc->pPDev, SafeRamp); + Ret = IntSetDeviceGammaRamp((HDEV)dc->pPDev, SafeRamp, TRUE); DC_UnlockDc(dc); ExFreePool(SafeRamp); return Ret;