Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
orbclient
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
8
Issues
8
List
Boards
Labels
Service Desk
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
redox-os
orbclient
Commits
cdf9d19d
Commit
cdf9d19d
authored
Feb 06, 2018
by
robbycerantola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
image_fast benchmark
parent
f9e8df2c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
113 deletions
+18
-113
Cargo.toml
Cargo.toml
+1
-1
examples/image.rs
examples/image.rs
+17
-22
src/lib.rs
src/lib.rs
+0
-2
src/renderer.rs
src/renderer.rs
+0
-88
No files found.
Cargo.toml
View file @
cdf9d19d
...
...
@@ -14,8 +14,8 @@ keywords = [
]
[dependencies]
rayon
=
"0.9"
time
=
"*"
[features]
default
=
[]
no_std
=
[]
...
...
examples/image.rs
View file @
cdf9d19d
...
...
@@ -18,35 +18,30 @@ fn main() {
window
.set
(
Color
::
rgb
(
255
,
255
,
255
));
//create image data : a green square
let
data
=
vec!
[
Color
::
rgba
(
100
,
200
,
10
,
2
);
200000
];
let
data2
=
vec!
[
Color
::
rgba
(
200
,
100
,
10
,
2
);
200000
];
let
data
=
vec!
[
Color
::
rgba
(
100
,
200
,
10
,
2
0
);
200000
];
let
data2
=
vec!
[
Color
::
rgba
(
200
,
100
,
10
,
2
0
);
200000
];
//draw image sequentially
//draw image benchmarking
println!
(
"Benchmarking implementations to draw an image on window:"
);
let
mut
t
=
time
::
now
();
for
_
i
in
1
..
TIMES
{
window
.image
(
10
,
10
,
500
,
400
,
&
data
[
..
]);
}
println!
(
"image {:?}"
,
time
::
now
()
-
t
);
//draw image parallelizing
t
=
time
::
now
();
for
_
i
in
1
..
TIMES
{
window
.image_par
(
20
,
20
,
500
,
400
,
&
data
[
..
]);
}
println!
(
"image_par {:?}"
,
time
::
now
()
-
t
);
t
=
time
::
now
();
for
_
i
in
1
..
TIMES
{
window
.image_fast
(
30
,
30
,
500
,
400
,
&
data
[
..
]);
for
_
i
in
0
..
TIMES
{
window
.image
(
10
,
10
,
500
,
400
,
&
data
[
..
]);
}
println!
(
"image_fast {:?}"
,
time
::
now
()
-
t
);
let
mut
t2
=
time
::
now
();
let
dt
=
(
t2
-
t
)
/
TIMES
;
println!
(
" image {:?}"
,
dt
);
t
=
time
::
now
();
for
_
i
in
1
..
TIMES
{
window
.image_
very
fast
(
40
,
40
,
500
,
400
,
&
data2
[
..
]);
for
_
i
in
0
..
TIMES
{
window
.image_fast
(
40
,
40
,
500
,
400
,
&
data2
[
..
]);
}
println!
(
"image_veryfast{:?}"
,
time
::
now
()
-
t
);
t2
=
time
::
now
();
let
dt2
=
(
t2
-
t
)
/
TIMES
;
println!
(
"image_fast {:?}"
,
dt2
);
println!
(
"-------------------------"
);
println!
(
"difference {:?}"
,
dt
-
dt2
);
window
.sync
();
'events
:
loop
{
...
...
src/lib.rs
View file @
cdf9d19d
...
...
@@ -12,8 +12,6 @@ extern crate alloc;
#[cfg(not(feature=
"no_std"
))]
extern
crate
core
;
extern
crate
rayon
;
pub
static
FONT
:
&
'static
[
u8
]
=
include_bytes!
(
"../res/unifont.font"
);
pub
use
color
::
Color
;
...
...
src/renderer.rs
View file @
cdf9d19d
use
core
::
cmp
;
use
rayon
::
prelude
::
*
;
use
FONT
;
use
color
::
Color
;
use
graphicspath
::
GraphicsPath
;
use
graphicspath
::
PointType
;
use
std
::
sync
::{
Arc
,
Mutex
};
#[cfg(target_arch
=
"x86"
)]
#[inline(always)]
#[cold]
...
...
@@ -310,96 +307,11 @@ pub trait Renderer {
}
}
//VERY SLOW parallel implementation !
fn
image_par
(
&
mut
self
,
start_x
:
i32
,
start_y
:
i32
,
w
:
u32
,
_
h
:
u32
,
image_data
:
&
[
Color
])
{
let
window_w
=
self
.width
()
as
usize
;
let
window_len
=
self
.data
()
.len
();
let
data
=
Arc
::
new
(
Mutex
::
new
(
self
.data_mut
()));
let
w
=
w
as
usize
;
(
0
..
image_data
.len
())
.into_par_iter
()
.map
(|
i
|
{
let
y0
=
i
/
w
;
let
y
=
y0
+
start_y
as
usize
;
let
x
=
start_x
as
usize
+
i
-
(
y0
*
w
)
;
let
window_index
=
y
*
window_w
+
x
;
if
window_index
<=
window_len
{
let
new
=
image_data
[
i
]
.data
;
let
alpha
=
(
new
>>
24
)
&
0xFF
;
if
alpha
>
0
{
let
old
=
unsafe
{
&
mut
data
.lock
()
.unwrap
()[
window_index
]
.data
};
if
alpha
>=
255
{
*
old
=
new
;
}
else
{
let
n_r
=
(((
new
>>
16
)
&
0xFF
)
*
alpha
)
>>
8
;
let
n_g
=
(((
new
>>
8
)
&
0xFF
)
*
alpha
)
>>
8
;
let
n_b
=
((
new
&
0xFF
)
*
alpha
)
>>
8
;
let
n_alpha
=
255
-
alpha
;
let
o_a
=
(((
*
old
>>
24
)
&
0xFF
)
*
n_alpha
)
>>
8
;
let
o_r
=
(((
*
old
>>
16
)
&
0xFF
)
*
n_alpha
)
>>
8
;
let
o_g
=
(((
*
old
>>
8
)
&
0xFF
)
*
n_alpha
)
>>
8
;
let
o_b
=
((
*
old
&
0xFF
)
*
n_alpha
)
>>
8
;
*
old
=
((
o_a
<<
24
)
|
(
o_r
<<
16
)
|
(
o_g
<<
8
)
|
o_b
)
+
((
alpha
<<
24
)
|
(
n_r
<<
16
)
|
(
n_g
<<
8
)
|
n_b
);
}
}
}
})
.count
();
}
fn
image_fast
(
&
mut
self
,
start_x
:
i32
,
start_y
:
i32
,
w
:
u32
,
_
h
:
u32
,
image_data
:
&
[
Color
])
{
let
window_w
=
self
.width
()
as
usize
;
let
window_len
=
self
.data
()
.len
();
let
data
=
self
.data_mut
();
let
w
=
w
as
usize
;
(
0
..
image_data
.len
())
.map
(|
i
|
{
let
y0
=
i
/
w
;
let
y
=
y0
+
start_y
as
usize
;
let
x
=
start_x
as
usize
+
i
-
(
y0
*
w
)
;
let
window_index
=
y
*
window_w
+
x
;
if
window_index
<=
window_len
{
let
new
=
image_data
[
i
]
.data
;
let
alpha
=
(
new
>>
24
)
&
0xFF
;
if
alpha
>
0
{
let
old
=
unsafe
{
&
mut
data
[
window_index
]
.data
};
if
alpha
>=
255
{
*
old
=
new
;
}
else
{
let
n_r
=
(((
new
>>
16
)
&
0xFF
)
*
alpha
)
>>
8
;
let
n_g
=
(((
new
>>
8
)
&
0xFF
)
*
alpha
)
>>
8
;
let
n_b
=
((
new
&
0xFF
)
*
alpha
)
>>
8
;
let
n_alpha
=
255
-
alpha
;
let
o_a
=
(((
*
old
>>
24
)
&
0xFF
)
*
n_alpha
)
>>
8
;
let
o_r
=
(((
*
old
>>
16
)
&
0xFF
)
*
n_alpha
)
>>
8
;
let
o_g
=
(((
*
old
>>
8
)
&
0xFF
)
*
n_alpha
)
>>
8
;
let
o_b
=
((
*
old
&
0xFF
)
*
n_alpha
)
>>
8
;
*
old
=
((
o_a
<<
24
)
|
(
o_r
<<
16
)
|
(
o_g
<<
8
)
|
o_b
)
+
((
alpha
<<
24
)
|
(
n_r
<<
16
)
|
(
n_g
<<
8
)
|
n_b
);
}
}
}
})
.count
();
}
fn
image_veryfast
(
&
mut
self
,
start_x
:
i32
,
start_y
:
i32
,
w
:
u32
,
_
h
:
u32
,
image_data
:
&
[
Color
])
{
let
window_w
=
self
.width
()
as
usize
;
let
window_len
=
self
.data
()
.len
();
let
data
=
self
.data_mut
();
let
w
=
w
as
usize
;
let
start_x
=
start_x
as
usize
;
let
start_y
=
start_y
as
usize
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment