Skip to content

Commit 588e26a

Browse files
take advantage of valuetype
1 parent 3cb47c8 commit 588e26a

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

test/openexr/test.rs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ fn write_rgba1() {
1515

1616
let par = 1.0f32;
1717

18-
let sw_center = Imath_V2f_t::default();
18+
let sw_center = Imath_V2f_t {
19+
x: 0.0f32,
20+
y: 0.0f32,
21+
};
1922
let sw_width = 1.0f32;
2023

2124
let line_order = Imf_LineOrder_INCREASING_Y;
@@ -37,34 +40,27 @@ fn write_rgba1() {
3740
);
3841

3942
// allocate pixel storage
40-
let mut pixels = vec![Imf_Rgba_t::default(); 256 * 128];
43+
let mut pixels = vec![
44+
Imf_Rgba_t {
45+
r: half_t::default(),
46+
g: half_t::default(),
47+
b: half_t::default(),
48+
a: half_t::default()
49+
};
50+
256 * 128
51+
];
4152

4253
// draw a pattern.
4354
for y in 0..height {
4455
for x in 0..width {
4556
let u = x as f32 / width as f32;
4657
let v = y as f32 / height as f32;
4758

48-
let mut r = half_t::default();
49-
let mut g = half_t::default();
50-
let mut b = half_t::default();
51-
let mut a = half_t::default();
52-
53-
half_from_float(&mut r, u);
54-
half_from_float(&mut g, v);
55-
half_from_float(&mut b, 0.0f32);
56-
half_from_float(&mut a, 1.0f32);
57-
58-
// don't try this at home, kids
5959
let pix = &mut pixels[(y * width + x) as usize];
60-
let mut ptr = pix as *mut _ as *mut u8;
61-
ptr.copy_from(&r as *const _ as *const u8, 2);
62-
ptr = ptr.offset(2);
63-
ptr.copy_from(&g as *const _ as *const u8, 2);
64-
ptr = ptr.offset(2);
65-
ptr.copy_from(&b as *const _ as *const u8, 2);
66-
ptr = ptr.offset(2);
67-
ptr.copy_from(&a as *const _ as *const u8, 2);
60+
half_from_float(&mut pix.r, u);
61+
half_from_float(&mut pix.g, v);
62+
half_from_float(&mut pix.b, 0.0f32);
63+
half_from_float(&mut pix.a, 1.0f32);
6864
}
6965
}
7066

0 commit comments

Comments
 (0)