Saving jpg as fits

Hi all

For an application I am writing I have the need to convert a jpg image into fits format.
I have some code that saves an image array coming from an ASCOM Driver that works without any issues, so I know the writing of the fits file is not the problem.

However I just can’t figure out how to convert the jpg data so that it can be stuffed into a fits file. I’ve been trying various things over the last few days, like converting the image data to grayscale, extracting just the red channel etc, but whatever image data I write into the fits file ends up as not being readable. Apps such as SGP always say that it’s an invalid file format.

So I was wondering if anyone could maybe provide a hint on how I could achieve this? SGP can do this, so I know it must be possible, but I just haven’t figured out how to.

Cheers for any pointers or hints.
Martin

Martin,

a short detour might be (if it’s the same jpg) to use the ascom v2 camera simulator. You can specify a jpg as image and download it via ascom interface. I guess SGPRo is using some libraries for handling of jpg.

Michel

Hi Michel

Thanks for the idea, very interesting! I didn’t know you could specify a source image for the simulator.
I think it might still be a problem though, as the image will be color and possibly 32bits, while the FITS that is coming from the cameras is usually only 16 bits. I will give this some thought and maybe try it out.

Thanks again for the idea!
Cheers
Martin

The camera simulator handles the colour issues, if you specify a monochrome camera that’s what you get. Try it.

Also the source is available in the ASCOM sourceforge repository, that will have clues for reading a jpeg image and outputting a fits one.