Skip to content

Commit d0ab6b7

Browse files
committed
refactor(graphics): const pixel_format_to_rgb_fn
That doesn't change the speed though, code isn't inlined afaict. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
1 parent ca4d1fc commit d0ab6b7

File tree

1 file changed

+37
-21
lines changed

1 file changed

+37
-21
lines changed

crates/ironrdp-graphics/src/color_conversion.rs

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,44 @@ where
2929
}
3030
}
3131

32-
fn pixel_format_to_rgb_fn(format: PixelFormat) -> fn(&[u8]) -> Rgb {
32+
fn xrgb_to_rgb(pixel: &[u8]) -> Rgb {
33+
Rgb {
34+
r: pixel[1],
35+
g: pixel[2],
36+
b: pixel[3],
37+
}
38+
}
39+
40+
fn xbgr_to_rgb(pixel: &[u8]) -> Rgb {
41+
Rgb {
42+
b: pixel[1],
43+
g: pixel[2],
44+
r: pixel[3],
45+
}
46+
}
47+
48+
fn bgrx_to_rgb(pixel: &[u8]) -> Rgb {
49+
Rgb {
50+
b: pixel[0],
51+
g: pixel[1],
52+
r: pixel[2],
53+
}
54+
}
55+
56+
fn rgbx_to_rgb(pixel: &[u8]) -> Rgb {
57+
Rgb {
58+
r: pixel[0],
59+
g: pixel[1],
60+
b: pixel[2],
61+
}
62+
}
63+
64+
const fn pixel_format_to_rgb_fn(format: PixelFormat) -> fn(&[u8]) -> Rgb {
3365
match format {
34-
PixelFormat::ARgb32 | PixelFormat::XRgb32 => |pixel: &[u8]| Rgb {
35-
r: pixel[1],
36-
g: pixel[2],
37-
b: pixel[3],
38-
},
39-
PixelFormat::ABgr32 | PixelFormat::XBgr32 => |pixel: &[u8]| Rgb {
40-
b: pixel[1],
41-
g: pixel[2],
42-
r: pixel[3],
43-
},
44-
PixelFormat::BgrA32 | PixelFormat::BgrX32 => |pixel: &[u8]| Rgb {
45-
b: pixel[0],
46-
g: pixel[1],
47-
r: pixel[2],
48-
},
49-
PixelFormat::RgbA32 | PixelFormat::RgbX32 => |pixel: &[u8]| Rgb {
50-
r: pixel[0],
51-
g: pixel[1],
52-
b: pixel[2],
53-
},
66+
PixelFormat::ARgb32 | PixelFormat::XRgb32 => xrgb_to_rgb,
67+
PixelFormat::ABgr32 | PixelFormat::XBgr32 => xbgr_to_rgb,
68+
PixelFormat::BgrA32 | PixelFormat::BgrX32 => bgrx_to_rgb,
69+
PixelFormat::RgbA32 | PixelFormat::RgbX32 => rgbx_to_rgb,
5470
}
5571
}
5672

0 commit comments

Comments
 (0)