Write clut16
This commit is contained in:
parent
2957305e55
commit
ae47572727
|
@ -1,5 +1,4 @@
|
||||||
use super::types::{Color, Header, PSXImageConverter};
|
use super::types::{Color, PSXImageConverter};
|
||||||
use tool_helper::{Error, Output};
|
|
||||||
|
|
||||||
pub struct RgbImage {
|
pub struct RgbImage {
|
||||||
raw_data: std::vec::IntoIter<u8>,
|
raw_data: std::vec::IntoIter<u8>,
|
||||||
|
@ -83,13 +82,3 @@ impl std::iter::Iterator for RgbaImage {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn encode<T: PSXImageConverter>(image: T, _: Output) -> Result<(), Error> {
|
|
||||||
let width = image.width();
|
|
||||||
let height = image.height();
|
|
||||||
let _header = Header::encode(width, height, 0, 0).ok_or(Error::from_callback(|| {format!("Image size {}, {} needs to be even", width, height)}));
|
|
||||||
|
|
||||||
for _ in image {}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
|
@ -1,11 +1,12 @@
|
||||||
use clap::{Args, ValueEnum};
|
use clap::{Args, ValueEnum};
|
||||||
use image::{DynamicImage, io::Reader as ImageReader};
|
use image::{DynamicImage, io::Reader as ImageReader};
|
||||||
use full16_encoder::{RgbaImage, RgbImage};
|
use color_full16::{RgbaImage, RgbImage};
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
use tool_helper::{Error, Input, Output};
|
use tool_helper::{Error, Input, Output};
|
||||||
|
use types::{Header, PSXImageConverter};
|
||||||
|
|
||||||
mod types;
|
mod types;
|
||||||
mod full16_encoder;
|
mod color_full16;
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
|
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
|
||||||
pub enum ColorDepth {
|
pub enum ColorDepth {
|
||||||
|
@ -21,12 +22,25 @@ pub struct Arguments {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn encode<T: PSXImageConverter>(image: T, mut output: Output) -> Result<(), Error> {
|
||||||
|
let width = image.width();
|
||||||
|
let height = image.height();
|
||||||
|
let header = Header::encode(width, height, 0, 0).ok_or(Error::from_callback(|| {format!("Image size {}, {} needs to be even", width, height)}))?;
|
||||||
|
|
||||||
|
tool_helper::raw::write_generic(&mut output, header)?;
|
||||||
|
for color in image {
|
||||||
|
tool_helper::raw::write_generic(&mut output, color)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn convert_full16(input: Input, output: Output) -> Result<(), Error> {
|
fn convert_full16(input: Input, output: Output) -> Result<(), Error> {
|
||||||
match ImageReader::new(Cursor::new(tool_helper::input_to_vec(input)?)).with_guessed_format()?.decode() {
|
match ImageReader::new(Cursor::new(tool_helper::input_to_vec(input)?)).with_guessed_format()?.decode() {
|
||||||
Ok(image) => {
|
Ok(image) => {
|
||||||
match image {
|
match image {
|
||||||
DynamicImage::ImageRgb8(image) => full16_encoder::encode(RgbImage::new(image), output),
|
DynamicImage::ImageRgb8(image) => encode(RgbImage::new(image), output),
|
||||||
DynamicImage::ImageRgba8(image) => full16_encoder::encode(RgbaImage::new(image), output),
|
DynamicImage::ImageRgba8(image) => encode(RgbaImage::new(image), output),
|
||||||
|
|
||||||
_ => Err(Error::from_text("Only RGB and RGBA images are supported for 16bit encoding".to_owned()))
|
_ => Err(Error::from_text("Only RGB and RGBA images are supported for 16bit encoding".to_owned()))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use std::{boxed::Box, io::{Read, Write}, path::PathBuf};
|
use std::{boxed::Box, io::{Read, Write}, path::PathBuf};
|
||||||
|
|
||||||
pub mod bits;
|
pub mod bits;
|
||||||
|
pub mod raw;
|
||||||
|
|
||||||
pub type Output = Box<dyn Write>;
|
pub type Output = Box<dyn Write>;
|
||||||
pub type Input = Box<dyn Read>;
|
pub type Input = Box<dyn Read>;
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
use super::{Error, Output};
|
||||||
|
|
||||||
|
pub fn write_generic<T>(output: &mut Output, value: T) -> Result<usize, Error> {
|
||||||
|
let raw = unsafe {std::slice::from_raw_parts(&value as *const _ as *const u8, std::mem::size_of_val(&value))};
|
||||||
|
|
||||||
|
Error::try_or_new(output.write(raw))
|
||||||
|
}
|
Loading…
Reference in New Issue