cronodragon
14-11-2007, 04:25 AM
You might know the classic GetPixel() function, now I want to make a function that retrieves the intermediate color from a floating-point coordinate. This is what I'm doing:
function im_cImage.GetInterPixel(
X, Y: Single
): cr_rARGB;
var
X0, Y0, X1, Y1: Integer;
FX, FY: Single;
C10, C01, C11: cr_rARGB;
begin
X0 := Trunc(X);
Y0 := Trunc(Y);
FX := X-X0;
FY := Y-Y0;
if FX < 0.5 then
begin
X1 := X0;
X0 := X1-1;
FX := FX+0.5;
end else
begin
X1 := X0+1;
FX := FX-0.5;
end;
if FY < 0.5 then
begin
Y1 := Y0;
Y0 := Y1-1;
FY := FY+0.5;
end else
begin
Y1 := Y0+1;
FY := FY-0.5;
end;
C10 := cr_Interpolate(GetPixel(X0, Y0), GetPixel(X1, Y0), FX);
C01 := cr_Interpolate(GetPixel(X0, Y0), GetPixel(X0, Y1), FY);
C11 := cr_Interpolate(GetPixel(X0, Y0), GetPixel(X1, Y1),
cm_Distance(0, 0, FX, FY));
// ... what should I do next? ...
end;
When I first started had the idea of blending those 3 colors (C10, C01 and C11), but now I'm not sure if those should be interpolated (and how), to get the right color. Any ideas? :?
function im_cImage.GetInterPixel(
X, Y: Single
): cr_rARGB;
var
X0, Y0, X1, Y1: Integer;
FX, FY: Single;
C10, C01, C11: cr_rARGB;
begin
X0 := Trunc(X);
Y0 := Trunc(Y);
FX := X-X0;
FY := Y-Y0;
if FX < 0.5 then
begin
X1 := X0;
X0 := X1-1;
FX := FX+0.5;
end else
begin
X1 := X0+1;
FX := FX-0.5;
end;
if FY < 0.5 then
begin
Y1 := Y0;
Y0 := Y1-1;
FY := FY+0.5;
end else
begin
Y1 := Y0+1;
FY := FY-0.5;
end;
C10 := cr_Interpolate(GetPixel(X0, Y0), GetPixel(X1, Y0), FX);
C01 := cr_Interpolate(GetPixel(X0, Y0), GetPixel(X0, Y1), FY);
C11 := cr_Interpolate(GetPixel(X0, Y0), GetPixel(X1, Y1),
cm_Distance(0, 0, FX, FY));
// ... what should I do next? ...
end;
When I first started had the idea of blending those 3 colors (C10, C01 and C11), but now I'm not sure if those should be interpolated (and how), to get the right color. Any ideas? :?