Skip to content

Commit 7f866af

Browse files
committed
fmt
1 parent 36bc2f9 commit 7f866af

File tree

2 files changed

+37
-31
lines changed

2 files changed

+37
-31
lines changed

src/icon.rs

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -265,36 +265,43 @@ impl Icon {
265265
// EXPAND and ALPHA do not expand grayscale images into RGBA. We can just do this manually.
266266
match info.color_type {
267267
ColorType::GrayscaleAlpha => {
268-
if rgba_buf.len() as u32 != info.width * info.height * 2 {
269-
return Err(DmiError::Generic(String::from("GrayscaleAlpha buffer length mismatch")));
270-
}
271-
let mut new_buf = Vec::with_capacity((info.width * info.height * 4) as usize);
272-
for chunk in rgba_buf.chunks(2) {
273-
let gray = chunk[0];
274-
let alpha = chunk[1];
275-
new_buf.push(gray);
276-
new_buf.push(gray);
277-
new_buf.push(gray);
278-
new_buf.push(alpha);
279-
}
280-
rgba_buf = new_buf;
281-
}
282-
ColorType::Grayscale => {
283-
if rgba_buf.len() as u32 != info.width * info.height {
284-
return Err(DmiError::Generic(String::from("Grayscale buffer length mismatch")));
285-
}
286-
let mut new_buf = Vec::with_capacity((info.width * info.height * 4) as usize);
287-
for gray in rgba_buf {
288-
new_buf.push(gray);
289-
new_buf.push(gray);
290-
new_buf.push(gray);
291-
new_buf.push(255);
292-
}
293-
rgba_buf = new_buf;
294-
}
268+
if rgba_buf.len() as u32 != info.width * info.height * 2 {
269+
return Err(DmiError::Generic(String::from(
270+
"GrayscaleAlpha buffer length mismatch",
271+
)));
272+
}
273+
let mut new_buf = Vec::with_capacity((info.width * info.height * 4) as usize);
274+
for chunk in rgba_buf.chunks(2) {
275+
let gray = chunk[0];
276+
let alpha = chunk[1];
277+
new_buf.push(gray);
278+
new_buf.push(gray);
279+
new_buf.push(gray);
280+
new_buf.push(alpha);
281+
}
282+
rgba_buf = new_buf;
283+
}
284+
ColorType::Grayscale => {
285+
if rgba_buf.len() as u32 != info.width * info.height {
286+
return Err(DmiError::Generic(String::from(
287+
"Grayscale buffer length mismatch",
288+
)));
289+
}
290+
let mut new_buf = Vec::with_capacity((info.width * info.height * 4) as usize);
291+
for gray in rgba_buf {
292+
new_buf.push(gray);
293+
new_buf.push(gray);
294+
new_buf.push(gray);
295+
new_buf.push(255);
296+
}
297+
rgba_buf = new_buf;
298+
}
295299
ColorType::Rgba => {}
296300
_ => {
297-
return Err(DmiError::Generic(format!("Unsupported ColorType (must be RGBA or convertible to RGBA): {:#?}", info.color_type)));
301+
return Err(DmiError::Generic(format!(
302+
"Unsupported ColorType (must be RGBA or convertible to RGBA): {:#?}",
303+
info.color_type
304+
)));
298305
}
299306
}
300307

tests/dmi_ops.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::path::PathBuf;
44

55
#[test]
66
fn load_and_save_dmi() {
7-
87
let mut load_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
98
load_path.push("tests/resources/empty.dmi");
109
let load_file =
@@ -13,8 +12,8 @@ fn load_and_save_dmi() {
1312

1413
let mut load_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
1514
load_path.push("tests/resources/greyscale_alpha.dmi");
16-
let load_file =
17-
File::open(load_path.as_path()).unwrap_or_else(|_| panic!("No greyscale_alpha dmi: {load_path:?}"));
15+
let load_file = File::open(load_path.as_path())
16+
.unwrap_or_else(|_| panic!("No greyscale_alpha dmi: {load_path:?}"));
1817
let _ = Icon::load(&load_file).expect("Unable to greyscale_alpha dmi");
1918

2019
let mut load_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));

0 commit comments

Comments
 (0)