The JPEG file format is one of the most common formats for storing and transferring images, recognized by almost all image rendering and processing programs. In particular, because of its lossy compression algorithm, JPEG files can have low volumes, making it used heavily on the internet. For more on this file format, and a comparison with others, please see Recognized file formats.
For scientific purposes, the lossy compression and very limited dynamic range (8-bit integers) make JPEG very unattractive for storing of valuable data.
However, because of its commonality, it will inevitably be needed in some situations.
The functions here can be used to read and write JPEG images into Gnuastro’s Generic data container (gal_data_t
).
If the JPEG file has more than one color channel, each channel is treated as a separate node in a list of datasets (see List of gal_data_t
).
int
(char *name
)
¶Return 1
if name
has a JPEG suffix.
This can be used to make sure that a given input file is JPEG.
See gal_jpeg_suffix_is_jpeg
for a list of recognized suffixes.
int
(char *name
)
¶Return 1
if suffix
is a recognized JPEG suffix.
The recognized suffixes are .jpg
, .JPG
, .jpeg
, .JPEG
, .jpe
, .jif
, .jfif
and .jfi
.
gal_data_t *
(char *filename
, size_t minmapsize
, int quietmmap
)
¶Read the JPEG file filename
and return the contents as gal_data_t
.
If the directory’s image contains multiple colors/channels, the output will be a list with one node per color/channel (see List of gal_data_t
).
void
(gal_data_t *in
, char *filename
, uint8_t quality
, float widthincm
)
¶Write the given dataset (in
) into filename (a JPEG file).
If in
is a list, then each node in the list will be a color channel, therefore there can only be 1, 3 or 4 nodes in the list.
If the number of nodes is different, then this function will abort the program with a message describing the cause.
The lossy JPEG compression level can be set through quality
which is a value between 0 and 100 (inclusive, 100 being the best quality).
The display width of the JPEG file in units of centimeters (to suggest to viewers/users, only a meta-data) can be set through widthincm
.
GNU Astronomy Utilities 0.23 manual, July 2024.