Skip to content

feat(fits): add fits image read support#442

Merged
Tom94 merged 2 commits into
Tom94:masterfrom
cek:fits-support-cfitsio
May 7, 2026
Merged

feat(fits): add fits image read support#442
Tom94 merged 2 commits into
Tom94:masterfrom
cek:fits-support-cfitsio

Conversation

@cek

@cek cek commented May 5, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@cek cek force-pushed the fits-support-cfitsio branch from cfeef96 to 3beb53e Compare May 5, 2026 19:00
@Tom94

Tom94 commented May 5, 2026

Copy link
Copy Markdown
Owner

Oh wow, that was fast. Thanks a bunch!

On a quick test, I have to enable -DUSE_PTHREADS=ON to not run into race conditions when loading a folder full of test images. A bit annoying, because it'll need https://github.com/jwinarske/pthreads4w looped in just for MSVC, but eh, it's a small enough dependency and the cmake tame enough to add_subdirectory(pthreads4w EXCLUDE_FROM_ALL), I reckon.

(Alternatively, we could fork cfitsio and implement Windows-native mutexes behind some ifdefs. On a quick grep, pthreads isn't actually used in many places and relatively well isolated. But still seems more trouble than going with pthreads4w. :p)

@cek

cek commented May 5, 2026

Copy link
Copy Markdown
Contributor Author

Ah, yes, I should have remembered that cfitsio maintains a pile of global state. I did stress test loading using a couple folders full of images, but it seems I just got lucky.

It's a relatively small change to give cfitsio the option of using C11's <threads.h> instead of pthreads -- see here. But of course forking has costs. Maybe I should see if the cfitsio folks are interested in an MR...

In any case, I'll leave it to you to decide which is the lesser evil: forking cfitsio, or relying on pthreads4w.

@Tom94

Tom94 commented May 6, 2026

Copy link
Copy Markdown
Owner

Nice, C11 threads are even better! Since you already got them working, let's just go with the fork. That'll also let us get rid of the unistd dance and ExternalProject_Add, which I'd prefer avoiding if possible. (Existing uses of ExternalProject_Add are projects with much more complex-to-disentangle CMake-side issues, sadly.)

Half of tev's dependencies already are forks because of various CMake idiosyncrasies (and in some cases similar fixups like the pthreads one here), so no harm maintaining another -- especially with such a small patch on top of upstream. Heck, tev's linux HDR support is a huge divergence from upstream GLFW. 😅

@cek cek force-pushed the fits-support-cfitsio branch 4 times, most recently from 04d6075 to f37a9f1 Compare May 6, 2026 16:26
@cek

cek commented May 6, 2026

Copy link
Copy Markdown
Contributor Author

I've updated the MR to use a fork of cfitsio that includes CMakeLists.txt changes that allow it to be included as a subproject via add_subdirectory(), removes the unistd.h issue, and adds C11 threads as an option (enabled on WIN32 only after realizing macOS support was only added quite recently).

You'll obviously want your own cfitsio fork if this lands.

I'll see if the cfitsio project is interested in cmake or C11 threads MRs, but I suspect that's a long shot.

@Tom94 Tom94 force-pushed the fits-support-cfitsio branch from f37a9f1 to 44ece7e Compare May 7, 2026 05:08
@Tom94 Tom94 force-pushed the fits-support-cfitsio branch from 44ece7e to 831f5e9 Compare May 7, 2026 05:27
@Tom94 Tom94 merged commit d646db0 into Tom94:master May 7, 2026
3 of 7 checks passed
@Tom94

Tom94 commented May 7, 2026

Copy link
Copy Markdown
Owner

Thank you again -- and sorry for this whole thing having dragged on for as long as it has. Really appreciate the contribution!

@cek

cek commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

No problem, good to get it done in a way that best serves the project.

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.

2 participants