カラーバランス

カラーバランスはRGB各輝度に対して加算/減算を行うだけでできます。明るさ補正のときと似た感じですが、RGBごとに別の補正値が必要になります。
明るさ補正のときと違い、カラーバランスの補正値は-255から255の範囲をとります。後はコードを見てください。

procedure ColorBalance(Bitmap: TBitmap; RValue, GValue, BValue: Integer);
//カラーバランス
  function _ChkVal(Value: Integer): Boolean;
  begin
    Result := (Value < -255) or (Value > 255);
  end;
var
  X, Y, xR, xG, xB: Integer;
  pLine: PLine24;
begin
  { 補正値のチェック }
  if (RValue = 0) and (GValue = 0) and (BValue = 0) then Exit;
  if _ChkVal(RValue) or _ChkVal(GValue) or _ChkVal(BValue) then Exit;

  for Y := 0 to Bitmap.Height -1 do
  begin
    pLine := Bitmap.ScanLine[Y];
    for X := 0 to Bitmap.Width -1 do
    begin
      with pLine^[X] do
      begin
        { 補正後の値を計算 }
        xR := R + RValue;
        xG := G + GValue;
        xB := B + BValue;
        { Byteの範囲に飽和する }
        if xR > 255 then xR := 255 else if xR < 0 then xR := 0;
        if xG > 255 then xG := 255 else if xG < 0 then xG := 0;
        if xB > 255 then xB := 255 else if xB < 0 then xB := 0;
        { 現在のピクセル内容を変更 }
        R := xR;
        G := xG;
        B := xB;
      end;
    end;
  end;
  if Assigned(Bitmap.OnChange) then
    Bitmap.OnChange(Bitmap);
end;

Copyright 2001 Rinka Kouzuki All Rights Reserved.