1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157:
| unit gammaramp; interface
uses windows;
CONST NULL = 0;
type
LPVOID = Pointer; PVOID = array[0..2] of array [0..255] of word; Type_SetDeviceGammaRamp = function(DC:HDC; lpRamp:LPVOID):boolean; stdcall;
PgammaRamp = ^TGammaRamp; TGammaRamp = class(TObject) protected hGDI32:HMODULE; hScreenDC:HDC; pGetDeviceGammaRamp,pSetDeviceGammaRamp: Type_SetDeviceGammaRamp; public function LoadLib:boolean; procedure FreeLib; function LoadLibraryIfNeeded:boolean; function SetDeviceGammaRamp(DC:HDC; lpRamp:LPVOID):boolean; function GetDeviceGammaRamp(DC:HDC; lpRamp:LPVOID):boolean; function SetBrightness(dc:HDC; wBrightness:WORD):boolean; constructor Create; destructor Destroy; virtual; end;
implementation
Constructor TGammaramp.Create; begin hGDI32 := NULL; hScreenDC := NULL; end;
function TGammaRamp.LoadLib:boolean; begin result := FALSE; FreeLib; hGDI32 := LoadLibrary('gdi32.dll'); if (hGDI32 <> NULL) then begin
@pGetDeviceGammaRamp :=GetProcAddress(hGDI32, 'GetDeviceGammaRamp'); @pSetDeviceGammaRamp :=GetProcAddress(hGDI32, 'SetDeviceGammaRamp'); if (@pGetDeviceGammaRamp = nil) or (@pSetDeviceGammaRamp = nil) then FreeLib() else result := TRUE; end; end;
procedure TGammaRamp.FreeLib; begin if (hGDI32 <> NULL) then begin FreeLibrary(hGDI32); hGDI32 := NULL; end; end;
function TGammaRamp.LoadLibraryIfNeeded:boolean; begin result := FALSE; if (hGDI32 = NULL) then LoadLib(); if (@pGetDeviceGammaRamp <> Nil) and (@pSetDeviceGammaRamp <> Nil) then result:=true; end;
function TGammaRamp.SetDeviceGammaRamp(DC:HDC; lpRamp:LPVOID):boolean; begin if (LoadLibraryIfNeeded) then result:= pSetDeviceGammaRamp(DC, lpRamp) else result := FALSE; end;
function TGammaRamp.GetDeviceGammaRamp(DC:HDC; lpRamp:LPVOID):boolean; begin if (LoadLibraryIfNeeded) then result:= pGetDeviceGammaRamp(DC, lpRamp) else result := FALSE; end;
function TGammaRamp.SetBrightness(DC:HDC;wBrightness: WORD):boolean;
var hGammaDC : HDC; GammaArray: PVOID; iIndex, iArrayValue: integer; begin result := FALSE; if (DC = NULL) then hGammaDC := GetDC(NULL); if (hGammaDC <> NULL) then begin for iIndex := 0 to 255 do begin iArrayValue := iIndex * (wBrightness + 128); if (iArrayValue > 65535) then iArrayValue := 65535; GammaArray[0,iIndex] := WORD(iArrayValue); GammaArray[1,iIndex] := WORD(iArrayValue); GammaArray[2,iIndex] := WORD(iArrayValue); end; result := SetDeviceGammaRamp(hGammaDC, @GammaArray); end; if (DC = NULL) then ReleaseDC(NULL, hGammaDC); end;
destructor TGammaRamp.Destroy; begin FreeLib; inherited; end;
initialization
finalization
end. |