mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-30 07:18:11 +08:00
Create new library Raw-rs including a basic TIFF decoder (#1757)
* add a basic tiff decoder in raw-rs * cargo fmt * add readme and license files * add warning about being in-progress * add testing framework for raw-rs * add new type IFD and rename tag * remove test_each and merge into single test * cargo fmt * make sure images folder stays in git * rename image_length with image_height * change name of test file * Readme changes --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
co-authored by
Keavon Chambers
parent
6d74abb4de
commit
72ccba09af
@@ -0,0 +1,49 @@
|
||||
pub mod decoder;
|
||||
pub mod tiff;
|
||||
|
||||
use std::io::{Read, Seek};
|
||||
use thiserror::Error;
|
||||
use tiff::file::TiffRead;
|
||||
use tiff::tags::{COMPRESSION, SUBIFD};
|
||||
use tiff::{Ifd, TiffError};
|
||||
|
||||
pub struct RawImage {
|
||||
pub data: Vec<u16>,
|
||||
pub width: usize,
|
||||
pub height: usize,
|
||||
}
|
||||
|
||||
pub struct Image<T> {
|
||||
pub data: Vec<T>,
|
||||
pub width: usize,
|
||||
pub height: usize,
|
||||
pub channels: u8,
|
||||
}
|
||||
|
||||
pub fn decode<R: Read + Seek>(reader: &mut R) -> Result<RawImage, DecoderError> {
|
||||
let mut file = TiffRead::new(reader)?;
|
||||
let ifd = Ifd::new_first_ifd(&mut file)?;
|
||||
|
||||
// TODO: This is only for the tests to pass for now. Replace this with the correct implementation when the decoder is complete.
|
||||
let subifd = ifd.get(SUBIFD, &mut file)?;
|
||||
|
||||
Ok(decoder::uncompressed::decode(subifd, &mut file))
|
||||
}
|
||||
|
||||
pub fn process_8bit(image: RawImage) -> Image<u8> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn process_16bit(image: RawImage) -> Image<u16> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum DecoderError {
|
||||
#[error("An error occurred when trying to parse the TIFF format")]
|
||||
TiffError(#[from] TiffError),
|
||||
#[error("An error occurred when converting integer from one type to another")]
|
||||
ConversionError(#[from] std::num::TryFromIntError),
|
||||
#[error("An IO Error ocurred")]
|
||||
IoError(#[from] std::io::Error),
|
||||
}
|
||||
Reference in New Issue
Block a user