밝기(bright), 대비(contrast), 감마(gamma), 색농도(Saturation) 조절
Amount : 강도 0~255
Saturation : 색농도
// contrast
function IntToByte(i: Integer): Byte;
begin
if i > 255 then Result := 255
else
if i < 0 then Result := 0
else
Result := i;
end;
procedure Contrast(var clip: tbitmap; Amount: Integer);
var
p0: pbytearray;
rg, gg, bg, r, g, b, x, y, m: Integer;
begin
for y := 0 to clip.Height - 1 do
begin
p0 := clip.scanline[y];
m := 0;
for x := 0 to clip.Width - 1 do
begin
r := p0[m];
g := p0[m + 1];
b := p0[m + 2];
rg := (Abs(127 - r) * Amount) div 255;
gg := (Abs(127 - g) * Amount) div 255;
bg := (Abs(127 - b) * Amount) div 255;
if r > 127 then
r := r + rg else r := r - rg;
if g > 127 then g := g + gg
else
g := g - gg;
if b > 127 then
b := b + bg
else
b := b - bg;
p0[m] := IntToByte(r);
p0[m + 1] := IntToByte(g);
p0[m + 2] := IntToByte(b);
inc(m, 3);
end;
end;
end;
// bright
procedure Lightness(var clip: tbitmap; Amount: Integer);
var
p0: pbytearray;
r, g, b, x, y, m: Integer;
begin
for y := 0 to clip.Height - 1 do
begin p0 := clip.scanline[y];
m := 0;
for x := 0 to clip.Width - 1 do
begin
r := p0[m];
g := p0[m + 1];
b := p0[m + 2];
p0[m] := IntToByte(r + ((255 - r) * Amount) div 255);
p0[m + 1] := IntToByte(g + ((255 - g) * Amount) div 255);
p0[m + 2] := IntToByte(b + ((255 - b) * Amount) div 255);
inc(m, 3);
end;
end;
end;
// 색농도
procedure Saturation(var clip: tbitmap; Amount: Integer);
var
p0: pbytearray;
Gray, r, g, b, x, y, m: Integer;
begin
for y := 0 to clip.Height - 1 do begin p0 := clip.scanline[y];
m := 0;
for x := 0 to clip.Width - 1 do
begin
r := p0[m];
g := p0[m + 1];
b := p0[m + 2];
Gray := (r + g + b) div 3;
p0[m] := IntToByte(Gray + (((r - Gray) * Amount) div 255));
p0[m + 1] := IntToByte(Gray + (((g - Gray) * Amount) div 255));
p0[m + 2] := IntToByte(Gray + (((b - Gray) * Amount) div 255));
inc(m, 3);
end;
end;
end;
var gatable: array[0..255] of byte;
procedure makegammatable(value: extended);
var
i: byte;
j: integer;
exv: extended;
begin
if value = 1 then begin
for i := 0 to 255 do gatable[i] := i;
end
else
begin
gatable[0] := 0;
for i := 1 to 255 do
begin exv := 255 * exp(value * ln(i / 255)) + 0.5;
j := round(exv);
if j > 255 then j := 255;
gatable[i] := byte(255 and j);
end;
end;
end;
// dbmp : 결과물, sbmp : 원본, ga : 감마값
procedure GCorrection(sbmp, dbmp: Tbitmap; ga: extended);
var
i, j, k: integer; sl, dl: pbytearray;
begin
makegammatable(ga);
k := sbmp.Width * 3 - 1;
for j := 0 to sbmp.Height - 1 do
begin sl := sbmp.ScanLine[j];
dl := dbmp.ScanLine[j];
for i := 0 to k do
dl^[i] := gatable[sl^[i]];
end;
end;
'Delphi Tip > 이미지-영상' 카테고리의 다른 글
이미지의 밝기 / 선명도 조절하기 (0) | 2024.06.18 |
---|---|
TImage에 색상바 그리기 (0) | 2024.06.03 |
폼 배경에 비트맵 넣기 (0) | 2024.04.21 |
BMP에 DPI값 세팅하기 및 알아오기 (0) | 2024.01.26 |
이미지 마우스로 움직이기 (0) | 2024.01.04 |
댓글