Skip to content

Improve tile compressed pixel access API#38

Merged
bmatthieu3 merged 3 commits intomasterfrom
tile-compressed-pixel-access-api
Aug 26, 2025
Merged

Improve tile compressed pixel access API#38
bmatthieu3 merged 3 commits intomasterfrom
tile-compressed-pixel-access-api

Conversation

@bmatthieu3
Copy link
Collaborator

Linked to #37

BinaryTableData is an enum that contains 2 variants:

  • The TableData containing tabular data
  • The TileCompressed variant containing Pixels data. Pixels is an enum that can contain U8, I16, I32, F32 uncompressed pixels. You get an iterator on the uncompressed native u8, i16, i32, f32 pixel values.

@Fingel - here is a api I achieved to provide. There is still a match to do because binary table can also contain real tabular data and not only tile compressed pixel data (haha). For such tabular data (the BinaryTableData::TableData), a pixels method has no sense.

 let img_bytes = match hdu_list.get_data(&hdu) {
    BinaryTableData::TileCompressed(Pixels::I16(pixels)) => pixels
        .map(|v| (((v as f32) / vmax) * 255.0) as u8)
        .collect::<Vec<_>>(),
    BinaryTableData::TileCompressed(Pixels::I32(pixels)) => pixels
        .map(|v| (((v as f32) / vmax) * 255.0) as u8)
        .collect::<Vec<_>>(),
    BinaryTableData::TileCompressed(Pixels::F32(pixels)) => pixels
        .map(|v| ((v / vmax) * 255.0) as u8)
        .collect::<Vec<_>>(),
    BinaryTableData::TableData(data) => unreachable!(),
};

I do not achieve big performance improving. Still a ~10% speedup which is reasonable but I would have thought I would gain more.

BinaryTableData is an enum that contains 2 variants:
* The TableData traditional API
* The TileCompressed variant containing Pixels data. Pixels is an enum that can contain U8, I16, I32, F32 uncompressed pixels. You get an iterator over the uncompressed native u8, i16, i32, f32 pixels.
@bmatthieu3 bmatthieu3 linked an issue Aug 25, 2025 that may be closed by this pull request
@Fingel
Copy link
Contributor

Fingel commented Aug 25, 2025

This looks good! I will test this out tonight once the kid is asleep. I like the API.

@bmatthieu3
Copy link
Collaborator Author

@Fingel - Ok nice, if it is ok for you I can merge it.

@Fingel
Copy link
Contributor

Fingel commented Aug 26, 2025

It works great!
image

@bmatthieu3 bmatthieu3 merged commit 681272a into master Aug 26, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bulk access image data from binary tables

2 participants