function TForm1.GetB(const Color: TColor): Byte;
begin
Result:=(Color shr 16) and $FF
end;
function TForm1.GetG(const Color: TColor): Byte;
begin
Result:=(Color shr 8) and $FF
end;
function TForm1.GetR(const Color: TColor): Byte;
begin
Result:=Color and $FF
end;
procedure TForm1.ChangeLuma(Image: TImage; const Rate: Double);
var
y, u, v: array [0..351, 0..287] of SmallInt;
r, g, b: array [0..351, 0..287] of Byte;
i, j: Integer;
Color: TColor;
temp: Double;
begin
for i:=0 to Image.Width-1 do
for j:=0 to Image.Height-1 do
begin
Color:=Image.Canvas.Pixels[i, j];
r[i, j]:=GetR(Color);
g[i, j]:=GetG(Color);
b[i, j]:=GetB(Color);
y[i, j]:=Round((r[i, j]*0.299+g[i, j]*0.587+b[i, j]*0.114)*10);
u[i, j]:=Round((r[i, j]*0.596-g[i, j]*0.275-b[i, j]*0.321)*10);
v[i, j]:=Round((r[i, j]*0.212-g[i, j]*0.523+b[i, j]*0.311)*10)
end;
for i:=0 to Image.Width-1 do
for j:=0 to Image.Height-1 do
begin
y[i, j]:=Round(Rate*y[i, j]);
temp:=(y[i, j]+u[i, j]*0.956+v[i, j]*0.621)/10;
if temp<0 then
r[i, j]:=0
else if temp>255 then
r[i, j]:=255
else
r[i, j]:=Round(temp);
temp:=(y[i, j]-u[i, j]*0.272-v[i, j]*0.647)/10;
if temp<0 then
g[i, j]:=0
else if temp>255 then
g[i, j]:=255
else
g[i, j]:=Round(temp);
temp:=(y[i, j]-u[i, j]*1.105+v[i, j]*1.702)/10;
if temp<0 then
b[i, j]:=0
else if temp>255 then
b[i, j]:=255
else
b[i, j]:=Round(temp);
Color:=b[i, j];
Color:=Color shl 8+g[i, j];
Color:=Color shl 8+r[i, j];
Image.Canvas.Pixels[i, j]:=Color
end
end;
不要被yuv误解,它不是yuv图象.