Lo siento Delphius, pero no encuentro donde puede estar el error en tu código. Pero mirando tu código, me entraron ganas de hacer teclear algo de código yo. Espero que no te moleste que lo ponga por aquí:
Código Delphi
[-]
type
TRGB = array[1..3] of Byte;
PRGB = ^TRGB;
TFila = array[1..3] of TRGB;
PFila = ^TFila;
const
Filtro : array[1..3,1..3] of Integer =
(
(10,10,10),
(10,10,10),
(10,10,10)
);
procedure Filtrar(Img: TPicture);
var
Bitmap: TBitmap;
P1,P2,P3,P4: PByte;
i,j,k,t: Integer;
begin
Bitmap:= TBitmap.Create;
try
Bitmap.Width:= Img.Width;
Bitmap.Height:= Img.Height;
Bitmap.Canvas.Draw(0,0,Img.Graphic);
if not (Img.Graphic is TBitmap) then
Img.Assign(Bitmap);
Img.Bitmap.PixelFormat:= pf24bit;
Bitmap.PixelFormat:= pf24bit;
t:= 0;
for i:= 1 to 3 do
for j:= 1 to 3 do
inc(t,filtro[i,j]);
for j:= 0 to Bitmap.Height - 3 do
begin
P1:= Bitmap.ScanLine[j];
P2:= Bitmap.ScanLine[j+1];
P3:= Bitmap.ScanLine[j+2];
P4:= Img.Bitmap.ScanLine[j+1];
for i:= 0 to Bitmap.Width - 3 do
begin
for k:= 1 to 3 do
begin
PFila(P4)[2][k]:=
(
(PFila(P1)[1][k]*Filtro[1,1]) +
(PFila(P1)[2][k]*Filtro[1,2]) +
(PFila(P1)[3][k]*Filtro[1,3]) +
(PFila(P2)[1][k]*Filtro[2,1]) +
(PFila(P2)[2][k]*Filtro[2,2]) +
(PFila(P2)[3][k]*Filtro[2,3]) +
(PFila(P3)[1][k]*Filtro[3,1]) +
(PFila(P3)[2][k]*Filtro[3,2]) +
(PFila(P3)[3][k]*Filtro[3,3])
) div t;
end;
inc(P1,Sizeof(TRGB));
inc(P2,Sizeof(TRGB));
inc(P3,Sizeof(TRGB));
inc(P4,Sizeof(TRGB));
end;
end;
finally
Bitmap.Free;
end;
end;
Por ejemplo, si tenemos una imagen cargada en un TImage:
Código Delphi
[-]
Filtrar(Image1.Picture);
Image1.Refresh;