Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions benches/decompress.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use criterion::{criterion_group, criterion_main, Criterion};
use fitsrs::Pixels;
use fitsrs::hdu::data::bintable::{self, data::BinaryTableData};

fn criterion_benchmark_decompression(c: &mut Criterion) {
let mut group = c.benchmark_group("decompression");
Expand Down Expand Up @@ -34,9 +34,22 @@ fn decompress(filename: &str) {
if let HDU::XBinaryTable(hdu) = hdu {
let width = hdu.get_header().get_parsed::<usize>("ZNAXIS1").unwrap();
let height = hdu.get_header().get_parsed::<usize>("ZNAXIS2").unwrap();
let pixels = hdu_list.get_data(&hdu).collect::<Vec<_>>();

assert!(width * height == pixels.len());
match hdu_list.get_data(&hdu) {
BinaryTableData::TileCompressed(bintable::tile_compressed::pixels::Pixels::U8(
pixels,
)) => assert!(width * height == pixels.count()),
BinaryTableData::TileCompressed(
bintable::tile_compressed::pixels::Pixels::I16(pixels),
) => assert!(width * height == pixels.count()),
BinaryTableData::TileCompressed(
bintable::tile_compressed::pixels::Pixels::I32(pixels),
) => assert!(width * height == pixels.count()),
BinaryTableData::TileCompressed(
bintable::tile_compressed::pixels::Pixels::F32(pixels),
) => assert!(width * height == pixels.count()),
_ => unreachable!(),
}
}
}
}
Expand All @@ -57,7 +70,7 @@ fn read_image() {
let width = hdu.get_header().get_parsed::<usize>("NAXIS1").unwrap();
let height = hdu.get_header().get_parsed::<usize>("NAXIS2").unwrap();
let pixels = match hdu_list.get_data(&hdu).pixels() {
Pixels::I16(it) => it.count(),
fitsrs::hdu::data::image::Pixels::I16(it) => it.count(),
_ => unreachable!(),
};

Expand Down
25 changes: 18 additions & 7 deletions src/hdu/data/bintable/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ where
}
}

use super::tile_compressed::TileCompressedData;
#[derive(Debug)]
pub enum BinaryTableData<R> {
Table(TableData<R>),
TileCompressed(TileCompressedData<R>),
TileCompressed(Pixels<R>),
}

/*
impl<R> Iterator for BinaryTableData<R>
where
R: Debug + Seek + Read,
Expand All @@ -47,26 +47,32 @@ where
}
}
}
*/

use super::tile_compressed::pixels::Pixels;
impl<R> BinaryTableData<R>
where
R: Debug + Read,
{
fn new(reader: R, header: &Header<BinTable>, start_pos: u64) -> Self {
let ctx = header.get_xtension();

let data = TableData::new(reader, header, start_pos);

if let Some(tile_compressed) = &ctx.z_image {
BinaryTableData::TileCompressed(TileCompressedData::new(header, data, tile_compressed))
BinaryTableData::TileCompressed(Pixels::new(data, header, tile_compressed))
} else {
BinaryTableData::Table(data)
}
}

pub fn table_data(self) -> TableData<R> {
match self {
BinaryTableData::TileCompressed(tile) => tile.table_data(),
BinaryTableData::TileCompressed(pixels) => match pixels {
Pixels::U8(pixels) => pixels.row_it.table_data(),
Pixels::I16(pixels) => pixels.row_it.table_data(),
Pixels::I32(pixels) => pixels.row_it.table_data(),
Pixels::F32(pixels) => pixels.row_it.table_data(),
},
BinaryTableData::Table(table) => table,
}
}
Expand All @@ -75,8 +81,13 @@ where
impl<R> BinaryTableData<R> {
pub fn row_iter(self) -> TableRowData<R> {
match self {
Self::Table(table) => TableRowData::new(table),
Self::TileCompressed(TileCompressedData { row_it, .. }) => row_it,
BinaryTableData::TileCompressed(pixels) => match pixels {
Pixels::U8(pixels) => pixels.row_it,
Pixels::I16(pixels) => pixels.row_it,
Pixels::I32(pixels) => pixels.row_it,
Pixels::F32(pixels) => pixels.row_it,
},
BinaryTableData::Table(table) => table.row_iter(),
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/hdu/data/bintable/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#![allow(clippy::upper_case_acronyms)]

pub mod data;
pub mod dithering;
pub mod rice;
pub mod row;
pub mod tile_compressed;

pub use data::BinaryTableData;
pub use data::TableData;
pub use row::TableRowData;

Expand Down
Loading