Moved color type to different function
This commit is contained in:
parent
814aeef994
commit
3cbb97e5b3
20
src/main.rs
20
src/main.rs
|
@ -145,6 +145,17 @@ fn unfuck_cif_number_fast(number: &str) -> Result<u8> {
|
|||
Ok(number)
|
||||
}
|
||||
|
||||
fn unfuck_color_type(color_type: &str) -> Result<ColorType> {
|
||||
assert_trailing_leading(color_type)?;
|
||||
let mut buf = ArrayString::<18>::new();
|
||||
let split = color_type.split_ascii_whitespace().take(8).collect::<ArrayVec<_, 64>>();
|
||||
|
||||
join_to_arraystring(&split, &mut buf)?;
|
||||
let color_type = *(nummap::COLOR_TYPE_NUMMAP.get(&buf).ok_or_else(|| InvalidSizeError(color_type.to_string()))?);
|
||||
|
||||
Ok(color_type)
|
||||
}
|
||||
|
||||
fn decoder(inputfile: &str, outputfile: &str) -> Result<()> {
|
||||
let infile = File::open(inputfile)?;
|
||||
let outfile = File::create(outputfile)?;
|
||||
|
@ -189,18 +200,13 @@ fn decoder(inputfile: &str, outputfile: &str) -> Result<()> {
|
|||
.ok_or_else(|| InvalidSizeError(size_string.to_string()))?
|
||||
.trim_start(),
|
||||
)?;
|
||||
|
||||
let format = match unfuck_cif_number_fast(
|
||||
let format = unfuck_color_type(
|
||||
size_split[2]
|
||||
.trim_start()
|
||||
.strip_prefix("bitów_na_piksel:")
|
||||
.ok_or_else(|| InvalidSizeError(size_string.to_string()))?
|
||||
.trim_start(),
|
||||
)? {
|
||||
24 => ColorType::Rgb,
|
||||
32 => ColorType::Rgba,
|
||||
_ => return Err(InvalidSizeError(size_string.to_string())),
|
||||
};
|
||||
)?;
|
||||
|
||||
if width == 0 || height == 0 {
|
||||
return Err(NoDataError)
|
||||
|
|
|
@ -1261,3 +1261,8 @@ pub static U8_NUMMAP: Map<&'static str, u8> = phf_map! {
|
|||
"dwieście pięćdziesiąt cztery" => 254,
|
||||
"dwieście pięćdziesiąt pięć" => 255,
|
||||
};
|
||||
|
||||
pub static COLOR_TYPE_NUMMAP: Map<&'static str, png::ColorType> = phf_map! {
|
||||
"dwadzieścia cztery" => png::ColorType::Rgb,
|
||||
"trzydzieści dwa" => png::ColorType::Rgba,
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue