Created
May 23, 2013 01:36
-
-
Save valexey/5632213 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with Ada.Text_IO; use Ada.Text_IO; | |
with Ada.Float_Text_IO; use Ada.Float_Text_IO; | |
with Ada.Real_Time; use Ada.Real_Time; | |
with Interfaces; use Interfaces; | |
procedure Main is | |
package Duration_IO is new Ada.Text_IO.Fixed_IO(Duration); use Duration_IO; | |
width : constant integer := 640; | |
height : constant integer := 480; | |
N : constant integer := 13; | |
frames : constant integer := 1000; | |
type Color is (Red, Green, Blue); | |
type Frame is array (0 .. (width*height*3-1)) of Unsigned_8; | |
function Index(x, y: Integer; c : Color) return Integer is | |
begin | |
return width*y*3+x*3+Color'Pos(c); | |
end index; | |
procedure Blur(a : in Frame; b : out Frame) is | |
begin | |
for y in 1..height-2 loop | |
for x in 1..width-2 loop | |
for c in Color'Range loop | |
b(index(x,y,c)) := Unsigned_8((Integer(a(index(x,y-1,c))) + | |
Integer(a(index(x,y+1,c))) + | |
Integer(a(index(x-1,y,c))) + | |
Integer(a(index(x+1,y,c))) )/4); | |
end loop; | |
end loop; | |
end loop; | |
end Blur; | |
a1 : Frame; | |
a2 : Frame; | |
time_begin : Time; | |
time_elapsed : Duration; | |
begin | |
time_begin := Clock; | |
for nn in 1..frames loop -- | |
for i in 1..N loop | |
Blur(a1, a2); | |
Blur(a2, a1); | |
end loop; | |
end loop; | |
time_elapsed := To_Duration(Clock - time_begin); | |
Put("BlurGNAT: fps = "); Put(Float(frames)/Float(time_elapsed)); | |
Put(" time = "); Put(time_elapsed); | |
Put_Line(" sec"); | |
end Main; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment