Thanks a lot User137! Your tips were very valuable! =)
To achieve the best result I did use the 17 pixels around the current pixel.
Here is the final code :
Code:
procedure BoxBlur(var Texture: zglPTexture);
var
X, Y: Integer;
yLine, xLine, yLine2, yLine3: PByteArray;
data: PByteArray;
realWidth: Integer;
realHeight: Integer;
begin
realWidth := Round(Texture.Width / Texture.U);
realHeight := Round(Texture.Height / Texture.V);
tex_GetData(Texture, data);
for Y := 1 to realHeight - 2 do
begin
yLine := @data[realWidth * (Y) * 4]; // Current Line
yLine2 := @data[realWidth * (Y - 1) * 4]; // Prior Line
yLine3 := @data[realWidth * (Y + 1) * 4]; // Next Line
xLine := @data[realWidth * Y * 4];
for X := 1 to realWidth - 2 do
begin
xLine^[X * 4] := ((xLine^[X * 4] + xLine^[(X - 1) * 4] + xLine^[(X + 1) * 4] + yLine^[(X - 1) * 4] + yLine^[(X + 1) * 4] + yLine2^[(X - 1) * 4] + yLine2^[(X + 1) * 4] + yLine3^[(X - 1) * 4]
+ yLine3^[(X + 1) * 4]) + (xLine^[(X - 2) * 4] + xLine^[(X + 2) * 4] + yLine^[(X - 2) * 4] + yLine^[(X + 2) * 4] + yLine2^[(X - 2) * 4] + yLine2^[(X + 2) * 4] + yLine3^[(X - 2) * 4]
+ yLine3^[(X + 2) * 4])) div 17;
xLine^[X * 4 + 1] := ((xLine^[X * 4 + 1] + xLine^[(X - 1) * 4 + 1] + xLine^[(X + 1) * 4 + 1] + yLine^[(X - 1) * 4 + 1] + yLine^[(X + 1) * 4 + 1] + yLine2^[(X + 1) * 4 + 1] + yLine2^[(X - 1)
* 4 + 1] + yLine3^[(X + 1) * 4 + 1] + yLine3^[(X - 1) * 4 + 1]) + (xLine^[(X - 2) * 4 + 1] + xLine^[(X + 2) * 4 + 1] + yLine^[(X - 2) * 4 + 1] + yLine^[(X + 2) * 4 + 1] + yLine2^[
(X + 2) * 4 + 1] + yLine2^[(X - 2) * 4 + 1] + yLine3^[(X + 2) * 4 + 1] + yLine3^[(X - 2) * 4 + 1])) div 17;
xLine^[X * 4 + 2] := ((xLine^[X * 4 + 2] + xLine^[(X - 1) * 4 + 2] + xLine^[(X + 1) * 4 + 2] + yLine^[(X - 1) * 4 + 2] + yLine^[(X + 1) * 4 + 2] + yLine2^[(X + 1) * 4 + 2] + yLine2^[(X - 1)
* 4 + 2] + yLine3^[(X + 1) * 4 + 2] + yLine3^[(X - 1) * 4 + 2]) + (xLine^[(X - 2) * 4 + 2] + xLine^[(X + 2) * 4 + 2] + yLine^[(X - 2) * 4 + 2] + yLine^[(X + 2) * 4 + 2] + yLine2^[
(X + 2) * 4 + 2] + yLine2^[(X - 2) * 4 + 2] + yLine3^[(X + 2) * 4 + 2] + yLine3^[(X - 2) * 4 + 2])) div 17;
end;
end;
tex_SetData(Texture, data, 0, 0, realWidth, Texture.Height);
FreeMem(data);
end;
Bookmarks