Haven't tested it, but should fix half of the spacing tests
This commit is contained in:
parent
05bff33438
commit
ba089c87c9
25
src/main.rs
25
src/main.rs
|
@ -1,6 +1,6 @@
|
|||
use std::{env, io, process};
|
||||
use std::fs::File;
|
||||
use std::io::{BufRead, BufReader, BufWriter};
|
||||
use std::io::{BufRead, BufReader, BufWriter, Lines};
|
||||
use arrayvec::{ArrayString, ArrayVec};
|
||||
use png::{BitDepth, ColorType, EncodingError};
|
||||
use thiserror::Error;
|
||||
|
@ -69,6 +69,15 @@ fn join_to_arraystring<const C: usize>(elems: &[&str], str: &mut ArrayString<C>)
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn lines_read_noempty<T: BufRead>(lines: &mut Lines<T>) -> Result<Option<String>> {
|
||||
while let Some(s) = lines.next().transpose()? {
|
||||
if !s.is_empty() {
|
||||
return Ok(Some(s))
|
||||
}
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
fn unfuck_cif_number(number: &str) -> Result<u32> {
|
||||
let mut buf = ArrayString::<2048>::new();
|
||||
let split = number.split_whitespace().collect::<ArrayVec<_, 64>>();
|
||||
|
@ -141,14 +150,14 @@ fn decoder(inputfile: &str, outputfile: &str) -> Result<()> {
|
|||
return Err(InvalidSizeError(size_string.to_string()))
|
||||
}
|
||||
|
||||
let width = unfuck_cif_number(size_split[0].trim().strip_prefix("szerokość:")
|
||||
.ok_or_else(|| InvalidSizeError(size_string.to_string()))?.trim())?;
|
||||
let height = unfuck_cif_number(size_split[1].trim().strip_prefix("wysokość:")
|
||||
.ok_or_else(|| InvalidSizeError(size_string.to_string()))?.trim())?;
|
||||
let width = unfuck_cif_number(size_split[0].trim_start().strip_prefix("szerokość:")
|
||||
.ok_or_else(|| InvalidSizeError(size_string.to_string()))?.trim_start())?;
|
||||
let height = unfuck_cif_number(size_split[1].trim_start().strip_prefix("wysokość:")
|
||||
.ok_or_else(|| InvalidSizeError(size_string.to_string()))?.trim_start())?;
|
||||
|
||||
let format = match unfuck_cif_number_fast(
|
||||
size_split[2].trim().strip_prefix("bitów_na_piksel:")
|
||||
.ok_or_else(|| InvalidSizeError(size_string.to_string()))?.trim()
|
||||
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,
|
||||
|
@ -190,7 +199,7 @@ fn decoder(inputfile: &str, outputfile: &str) -> Result<()> {
|
|||
return Err(InvalidPixelError(first.to_string()))
|
||||
}
|
||||
for px in px_split {
|
||||
pixmap.push(unfuck_cif_number_fast(px.trim())?);
|
||||
pixmap.push(unfuck_cif_number_fast(px.trim_start())?);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue