Einzelnen Beitrag anzeigen

bassman

Registriert seit: 8. Apr 2008
18 Beiträge
 
Delphi 2009 Professional
 
#2

Re: Darstellung von Falschfarben

  Alt 25. Jan 2010, 07:57
Hallo KPBecker,

dies brauche ich häufig.
Ich benutze folgende Code um eine Lookup Tabelle zu generieren:

Delphi-Quellcode:
type
  TColorRGB = record
                r, g, b : byte;
              end;

  TColorLUT = Array of TColorRGB;
  
var
  LutScale : Double;

// Farbe zwischen 2 vorgegebenen Farbwerten berechnen
function ColorBetween(C1, C2 : TColor; blend:Real):TColor;
var
   r, g, b : Byte;
   y1, y2 : Byte;
begin
   C1 := ColorToRGB(C1);
   C2 := ColorToRGB(C2);

   y1 := GetRValue(C1);
   y2 := GetRValue(C2);

   r := Round(y1 + (y2-y1)*blend);

   y1 := GetGValue(C1);
   y2 := GetGValue(C2);

   g := Round(y1 + (y2-y1)*blend);

   y1 := GetBValue(C1);
   y2 := GetBValue(C2);

   b := Round(y1 + (y2-y1)*blend);
   Result := RGB(r, g, b);
end;

// Farbe zwischen beliebig vielen vorgegebenen Farbwerten berechnen
function ColorsBetween(colors:array of TColor; blend:Real):TColor;
var
   a : Integer;
   faktor : Real;
begin
   if blend <= 0.0 then
      Result := colors[0]
   else if blend >= 1.0 then
      Result := colors[High(colors)]
   else
   begin
      a := Trunc(High(colors) * blend);
      faktor := 1.0 / High(colors);
      Result := ColorBetween(colors[a], colors[a+1], (blend-(a * faktor)) / faktor);
   end;
end;

function CalcLUT(LUTsize : word; offset : Integer) : TColorLUT;
var
  ii : integer;
  blend : Real;
  clut : TColorLUT;
  col : TColor;
begin
  setlength(clut,LUTsize);
  for ii := 0 to LUTSize-1 do
  begin
    blend := (ii-offset)/LUTsize;
    col := ColorsBetween([clBlack,$00AC0260, clBlue, clAqua, clLime, clYellow, $000080FF, clRed, clBlack], blend);
    clut[ii].r := GetRValue(col);
    clut[ii].g := GetGValue(col);
    clut[ii].b := GetBValue(col);
  end;
  result := clut;
end;
Gruss, Jörn
  Mit Zitat antworten Zitat