Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Delphi Gamma - Control (https://www.delphipraxis.net/23165-gamma-control.html)

THE MATRIX 29. Mai 2004 23:45


Gamma - Control
 
Liste der Anhänge anzeigen (Anzahl: 1)
Hi @ll
ich hab mal google durchstöbert und das forum aber nicht wirklich fündig geworden :(

Ich habe ein C++ und ein VB Source gefunden der die GAMMA-CONTROL macht

Delphi-Quellcode:
void CGammaSlider::SetGamma(float Gamma)
{
   WORD ramp[256*3];

   for(int i = 0; i < 256; i++) {
      ramp[i] = ramp[i+256] = ramp[i+512] =
      (WORD)min(65535, max(0, pow((i+1) / 256.0, Gamma) * 65535 + 0.5));
   }

    SetDeviceGammaRamp(::GetDC(NULL), ramp);
}
das ist der C++ Source Code
ich hab das mal wiefolg übersetzt ( c++ ist nicht sooo mein ding ;) )
Delphi-Quellcode:
procedure SetGamma(var Gamma: Double);
Var
Ramp: array[0 .. 255, 0 .. 2] of double;
nVal: double;
I: integer;
begin
 For I:= 0 To 255 do
  begin
   nVal:= ((((I + 1) / 256) * (1 / Gamma)) * 65535 + 0.5);
   Ramp[I, 0]:= nVal;
   Ramp[I, 1]:= nVal;
   Ramp[I, 2]:= nVal;
 end;
SetDeviceGammaRamp(GetDC(0), Ramp);
end;
Jedoch ändert sich mein Gamma gar nicht , wenn ich das setgamma aufrufe ( natürlich mit werten )
setgamma(20) z.b.

Ich hoffe hier sind ein paar die das vielleicht besser übersetzten können,damit es funktioniert - oder ob ich über ne function fürs SetDeviceGammaRamp genen muss , welches im moment in der windows.pas ist jedoch auch in der gdi32 ...

So ich pack an Anhang das C++ Compilte programm damit ihr seht das es funktioniert
Hoffe mir kann jemand helfen ! :cheers:

Muetze1 30. Mai 2004 00:45

Re: Gamma - Control
 
Moin!

Mal schnell neu übersetzt...

Delphi-Quellcode:
Procedure SetGamma(Const AGamma : Double);
Var
  Ramp : Array[256*3] of Word;
  i : Integer;
  nVal : Word;
Begin
  For i := 0 To 255 Do
  Begin
    nVal := Word( Min(65535, Max(0, Power( (i+1) / 256, AGamma) * 65535 + 0.5)) );
    Ramp[000+i] := nVal;
    Ramp[256+i] := nVal;
    Ramp[512+i] := nVal;
  End;
  SetDeviceGammaRamp(GetDC(0), Ramp);
End;
(direkt hier eingegeben, nix ausgetestet)

MfG
Muetze1

THE MATRIX 30. Mai 2004 09:19

Re: Gamma - Control
 
So hatte ich das auch zuerst probiert
aber er erkennt die Array dekleration nicht dann das POWER , Min und Max kp was das zu tun hat :)
Ich pack mal kompletten C-source hier rein



Delphi-Quellcode:
#include "stdafx.h"
#include "GammaSlider.h"
#include <math.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define MIN_POS    0
#define MAX_POS    40
#define POS_FACTOR 10.0

#define REG_SECTION "GammaSlider"
#define REG_ENTRY  "Settings"

/*===========================================================================

@mfunc CGammaSlider - Constructor

===========================================================================*/
CGammaSlider::CGammaSlider()
{
}



/*===========================================================================

@mfunc ~CGammaSlider - Destructor

===========================================================================*/
CGammaSlider::~CGammaSlider()
{
    Restore();
}



/*===========================================================================

@mfunc OnDestroy - See MFC

===========================================================================*/
void CGammaSlider::OnDestroy()
{
    SaveSettings();

   CSliderCtrl::OnDestroy();
}



BEGIN_MESSAGE_MAP(CGammaSlider, CSliderCtrl)
   //{{AFX_MSG_MAP(CGammaSlider)
   ON_WM_HSCROLL_REFLECT()
   ON_WM_DESTROY()
   //}}AFX_MSG_MAP
END_MESSAGE_MAP()



/*===========================================================================

@mfunc PreSubclassWindow - See MFC

===========================================================================*/
void CGammaSlider::PreSubclassWindow()
{
   if (!GetDeviceGammaRamp(::GetDC(NULL), m_RampSaved))
   {
      TRACE("WARNING: Cannot initialize DeviceGammaRamp.\n");
      EnableWindow(FALSE);
   }
   else
   {
      SetRange(MIN_POS, MAX_POS);
      SetTicFreq(5);
        LoadSettings();
    }

   CSliderCtrl::PreSubclassWindow();
}



/*===========================================================================

@mfunc GetGammaPos - Get current gamma average (Originaly for RGB input)

===========================================================================*/
int CGammaSlider::GetGammaPos()
{
   float rgb[3] = {1.0, 1.0, 1.0};

   for (int i = 0; i < 3; i++) {

      float Csum       = 0.0;
      int  Ccount   = 0;
      int  min      = 256 * i;
      int  max      = min + 256;

      for (int j = min; j < max; j++) {

         if (j != 0 && m_RampSaved[j] != 0 && m_RampSaved[j] != 65536)
         {
            double B = (j % 256) / 256.0;
            double A = m_RampSaved[j] / 65536.0;
            float C = (float)(log(A) / log(B));

            Csum += C;
            Ccount++;
         }
      }

      rgb[i] = Csum / Ccount;
   }

   return (int)(MAX_POS-(rgb[0] * POS_FACTOR));
}



/*===========================================================================

@mfunc HScroll   - Refelction

@parm nSBCode   - Reflection code

@parm nPos      - Poition value

===========================================================================*/
void CGammaSlider::HScroll(UINT nSBCode, UINT nPos)
{
   if (nSBCode == SB_THUMBTRACK || nSBCode == TB_LINEDOWN ||
      nSBCode == TB_LINEUP || nSBCode == TB_TOP)
   {
      SetGamma((float)((MAX_POS-nPos) / POS_FACTOR));
   }
}



/*===========================================================================

@mfunc SetGamma - Set current gamma average (Originaly for RGB input)

@parm Gamma - Gamma value

===========================================================================*/
void CGammaSlider::SetGamma(float Gamma)
{
   WORD ramp[256*3];

   for(int i = 0; i < 256; i++) {
      ramp[i] = ramp[i+256] = ramp[i+512] =
      (WORD)min(65535, max(0, pow((i+1) / 256.0, Gamma) * 65535 + 0.5));
   }

    SetDeviceGammaRamp(::GetDC(NULL), ramp);
}



/*===========================================================================

@mfunc LoadSettings - Load current state

===========================================================================*/
void CGammaSlider::LoadSettings()
{
    int nPos = AfxGetApp()->GetProfileInt(REG_SECTION, REG_ENTRY, GetGammaPos());

    SetPos(nPos);
   SetGamma((float)((MAX_POS-((nPos == MAX_POS) ? MAX_POS-3 : nPos)) / POS_FACTOR));
}



/*===========================================================================

@mfunc SaveSettings - Save current state

===========================================================================*/
void CGammaSlider::SaveSettings()
{
    AfxGetApp()->WriteProfileInt(REG_SECTION, REG_ENTRY, GetPos());
}



/*===========================================================================

@mfunc RestoreGamma - Restore saved gamma

===========================================================================*/
void CGammaSlider::RestoreGamma()
{
    SetPos(GetGammaPos());
    Restore();
}



/*===========================================================================

@mfunc Restore - Restore saved gamma

===========================================================================*/
void CGammaSlider::Restore()
{
   if (!SetDeviceGammaRamp(::GetDC(NULL), m_RampSaved))
      TRACE("WARNING: Cannot restore DeviceGammaRamp.\n");
}
So ... Hab das auch im VBBasic hier und mal mit nem VBtoDelphi convertieren lassen aber da lief gar nichts von :'(


Also wer noch ideen hat bitte posten - BiT THX

THE MATRIX 30. Mai 2004 19:22

Re: Gamma - Control
 
So habs hinbekommen


Delphi-Quellcode:
type
  TGammaRamp = packed record
    R : array[0..255] of word;
    G : array[0..255] of word;
    B : array[0..255] of word;
  end;
zum ändern das Gammas

Delphi-Quellcode:
procedure TForm1.BarGammaChange(Sender: TObject);
var
  v, i: Integer;
  adjustedRamp: TGammaRamp;
begin
Caption := Format('%.1f', [barGamma.Position/10]);
 for i := 0 to 255 do
  begin
    v := Round(255 * Power(i/255, barGamma.Position/10));
    if v > 255 then v := 255;
    adjustedRamp.R[i] := v shl 8;
    adjustedRamp.G[i] := v shl 8;
    adjustedRamp.B[i] := v shl 8;
  end;
 SetDeviceGammaRamp(getdc(0), adjustedRamp);
end;
und am Besten vorher das GAMMA speichern ( was vorher war )

GetDeviceGammaRamp(GetDC(0), OldGamma);

OldGamma muss dann TGAMMARAMP sein ;)

So Endlich kann ich meine GRAKA wieder auf 1.0 stellen wenn mir nen Game gecrashed ist :] *fettSmile*

Phantom1 30. Mai 2004 20:45

Re: Gamma - Control
 
ich hab den code mal probiert, leider tut sich bei mir garnix. warscheinlich funktioniert es bei ATI (radeon9700) grafikkarten etwas anders als bei nvidia.

THE MATRIX 30. Mai 2004 22:58

Re: Gamma - Control
 
Liste der Anhänge anzeigen (Anzahl: 1)
Hier mal mein compiltes wenns geht auch ich source auch noch hoch probiers mal.

Muetze1 31. Mai 2004 00:14

Re: Gamma - Control
 
Moin!

Ich habe eine Radeon 9600 und der Regler in der EXE bewirkt.... nix. Keine Reaktion, nix.

Wäre vielleicht mal gut, wenn du den Rückgabewert der GDI Funktion abfragen würdest und mit ShowMessage(SysErrorMessage(GetLastError)); im Fehlerfall mal den Grund ausgibst...

MfG
Muetze1

dizzy 31. Mai 2004 00:23

Re: Gamma - Control
 
GF4 Ti4400 ...und läuft!

Muetze1 31. Mai 2004 00:31

Re: Gamma - Control
 
Moin!

Zitat:

Zitat von MSDN
SetDeviceGammaRamp succeeds only for devices with drivers that support downloadable gamma ramps in hardware

MSDN SetDeviceGammaRamp

MfG
Muetze1

Phantom1 31. Mai 2004 06:28

Re: Gamma - Control
 
Zitat:

Zitat von Muetze1
Zitat:

Zitat von MSDN
SetDeviceGammaRamp succeeds only for devices with drivers that support downloadable gamma ramps in hardware


Schade eigentlich. Gibt's für ATI Grafikkarten keine andere möglichkeit?


Alle Zeitangaben in WEZ +1. Es ist jetzt 20:06 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz