明るさ補正処理は非常に簡単です。RGB値にに補正値を加算するだけです。補正値の範囲は最大でも-255から255の範囲になりますが、大半のレタッチソフトでは-100から100の範囲内で選択するものが多いようです。ここで作る関数は-255から255の範囲の補正値を取ることができます。
単純に加算を行った上で出力値を飽和させるだけでもいいのですが、変換テーブルを使うと高速化できるので、変換テーブルを作成します。
procedure Brightness(Bitmap: TBitmap; Value: Integer);
//明るさ補正
var
X, Y: Integer;
pLine: PLine24;
Table: array[Byte]of Byte;
begin
if (Value = 0) or (Value > 255) or (Value < -255) then Exit
Bitmap.PixelFormat := pf24bit;
{ 変換テーブルの作成 }
for Y := 0 to 255 do
begin
X := Y + Value;
if X > 255 then X := 255 else if X < 0 then X := 0;
Table[Y] := X;
end;
{ ピクセルの変換処理 }
for Y := 0 to Bitmap.Height -1 do
begin
pLine := Bitmap.ScanLine[Y];
for X := 0 to Bitmap.Width -1 do
with pLine^[X] do
begin
R := Table[R];
G := Table[G];
B := Table[B];
end;
end;
if Assigned(Bitmap.OnChange) then
Bitmap.OnChange(Bitmap);
end;
|