splitting picture into individual unicode parts
This commit is contained in:
parent
d7c2435fdd
commit
9b14bced87
2 changed files with 40 additions and 9 deletions
|
|
@ -1,10 +1,6 @@
|
|||
use std::{
|
||||
fs::OpenOptions,
|
||||
io::{BufWriter, Write},
|
||||
path::Path,
|
||||
};
|
||||
use std::path::Path;
|
||||
|
||||
use image::{DynamicImage, GenericImage, ImageReader};
|
||||
use image::{DynamicImage, ImageReader};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct BWImage {
|
||||
|
|
|
|||
41
src/main.rs
41
src/main.rs
|
|
@ -3,7 +3,6 @@ use std::path::Path;
|
|||
|
||||
mod image_wrapper;
|
||||
use image_wrapper::BWImage;
|
||||
use sff::FileDescOut;
|
||||
mod sff;
|
||||
|
||||
/// Iterates over a directory which shall contain images named by their number in the font.
|
||||
|
|
@ -39,7 +38,7 @@ fn load_font_dir<P: AsRef<Path>>(dir_with_images: P) -> HashMap<u32, BWImage> {
|
|||
map
|
||||
}
|
||||
|
||||
fn image_table_split<P, Q>(
|
||||
fn image_split_table<P, Q>(
|
||||
src_image: P,
|
||||
dst_dir: Q,
|
||||
start_number: usize,
|
||||
|
|
@ -73,6 +72,35 @@ fn image_table_split<P, Q>(
|
|||
}
|
||||
}
|
||||
|
||||
/// Image should contain all characters in a line.
|
||||
fn image_split_individual<P, Q>(
|
||||
src_image: P,
|
||||
dst_dir: Q,
|
||||
numbers: &[usize],
|
||||
width_per_elem: usize,
|
||||
height_per_elem: usize,
|
||||
) where
|
||||
P: AsRef<Path>,
|
||||
Q: AsRef<Path>,
|
||||
{
|
||||
let src_img = image::ImageReader::open(src_image)
|
||||
.unwrap()
|
||||
.decode()
|
||||
.unwrap();
|
||||
assert!(src_img.width() as usize == numbers.len() * width_per_elem);
|
||||
assert!(src_img.height() as usize == height_per_elem);
|
||||
for (col, number_count) in numbers.iter().copied().enumerate() {
|
||||
let img = src_img.crop_imm(
|
||||
(col * width_per_elem) as u32,
|
||||
0,
|
||||
width_per_elem as u32,
|
||||
height_per_elem as u32,
|
||||
);
|
||||
let file_name = format!("{}.png", number_count);
|
||||
img.save(dst_dir.as_ref().join(file_name)).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
struct TableRange {
|
||||
start: u32,
|
||||
|
|
@ -99,7 +127,14 @@ fn sorted_numbers_into_ranges(sorted_numbers: &[u32]) -> Vec<TableRange> {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
image_table_split("res/test.png", "font", 32, 6, 16, 8, 18);
|
||||
image_split_table("res/ascii.png", "font", 32, 6, 16, 8, 18);
|
||||
image_split_individual(
|
||||
"res/german.png",
|
||||
"font",
|
||||
&[0x00e4, 0x00c4, 0x00f6, 0x00d6, 0x00fc, 0x00dc, 0x00df][..],
|
||||
8,
|
||||
18,
|
||||
);
|
||||
let map = load_font_dir("font");
|
||||
let mut sorted_keys: Vec<u32> = map.keys().copied().collect();
|
||||
sorted_keys.sort();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue