JPEG I/O¶
-
inline ImageBundle<RGB> huira::read_image_jpeg(const fs::path &filepath)¶
Reads a JPEG file and returns its RGB data.
Convenience overload that reads the file into memory and forwards to the buffer-based implementation.
- Parameters:
filepath – Path to the JPEG file to read
- Returns:
An ImageBundle<RGB> containing the RGB image.
-
inline ImageBundle<RGB> huira::read_image_jpeg(const unsigned char *data, std::size_t size)¶
Reads a JPEG from an in-memory buffer and returns its RGB data.
The values are returned as stored, in [0, 1], labelled sRGB (color_space), which JPEG images are by convention; nothing is converted (see srgb_to_linear()). Grayscale JPEGs are promoted to RGB by TurboJPEG during decompression.
- Parameters:
data – Pointer to the JPEG data in memory
size – Size of the data in bytes
- Returns:
An ImageBundle<RGB> containing the RGB image.
-
inline ImageBundle<float> huira::read_image_jpeg_mono(const fs::path &filepath)¶
Reads a JPEG file and returns mono data.
Convenience overload that reads the file into memory and forwards to the buffer-based implementation.
- Parameters:
filepath – Path to the JPEG file to read
- Returns:
An ImageBundle<float> containing the mono image.
-
inline ImageBundle<float> huira::read_image_jpeg_mono(const unsigned char *data, std::size_t size)¶
Reads a JPEG from an in-memory buffer and returns mono data.
The values are returned as stored (decoded to gray), labelled sRGB; nothing is converted.
- Parameters:
data – Pointer to the JPEG data in memory
size – Size of the data in bytes
- Returns:
An ImageBundle<float> containing the mono image.
-
inline void huira::write_image_jpeg(const fs::path &filepath, const ImageBundle<float> &output_image, int quality)¶
Writes a mono image to an 8-bit JPEG file. See the RGB overload.
Convenience overload that promotes a mono image to RGB before writing.
- Parameters:
filepath – Path where the JPEG file will be written
output_image – An ImageBundle<float> with the mono image to write
quality – JPEG compression quality (1-100, default 95)
-
inline void huira::write_image_jpeg(const fs::path &filepath, const ImageBundle<RGB> &output_image, int quality)¶
Writes an RGB image to an 8-bit JPEG file.
Values in [0, 1] are stretched over 0 to 255 and compressed using TurboJPEG; nothing is converted, and JPEG files are taken to be sRGB, so convert a linear image with linear_to_srgb() first for it to display correctly. JPEG is lossy and 8-bit, so it is for pictures: a sensor’s digital numbers are not kept (use FITS, PNG or TIFF for those). Values that are not finite are written as 0, with a warning. The function automatically creates necessary directories.
- Parameters:
filepath – Path where the JPEG file will be written
output_image – An ImageBundle<RGB> with the RGB image to write
quality – JPEG compression quality (1-100, default 95)
- Throws:
std::runtime_error – if the file cannot be created, the image is empty, quality is invalid, or if any error occurs during writing