PNG I/O¶
-
inline ImageBundle<RGB> huira::read_image_png(const fs::path &filepath, bool read_alpha)¶
Reads a PNG file and returns RGB + alpha data.
Convenience overload that reads the file into memory and forwards to the buffer-based implementation.
-
inline ImageBundle<RGB> huira::read_image_png(const unsigned char *data, std::size_t size, bool read_alpha)¶
Reads a PNG from an in-memory buffer and returns RGB + alpha data.
- Parameters:
data – Pointer to the PNG data in memory
size – Size of the data in bytes
read_alpha – Whether to load the alpha channel if present (default: true)
- Returns:
An ImageBundle<RGB> containing the RGB image and an optional alpha image.
-
inline ImageBundle<float> huira::read_image_png_mono(const fs::path &filepath, bool read_alpha)¶
Reads a PNG file and returns mono + alpha data.
Convenience overload that reads the file into memory and forwards to the buffer-based implementation.
-
inline ImageBundle<float> huira::read_image_png_mono(const unsigned char *data, std::size_t size, bool read_alpha)¶
Reads a PNG from an in-memory buffer and returns mono + alpha data.
- Parameters:
data – Pointer to the PNG data in memory
size – Size of the data in bytes
read_alpha – Whether to load the alpha channel if present (default: true)
- Returns:
An ImageBundle<float> containing the mono image and an optional alpha image.
-
inline void huira::write_image_png(const fs::path &filepath, const ImageBundle<RGB> &output_image)¶
Writes an RGB image (with optional alpha) to a PNG file. See the gray overload.
-
inline void huira::write_image_png(const fs::path &filepath, const ImageBundle<float> &output_image)¶
Writes a gray image (with optional alpha) to a PNG file, of 8 or 16 bits per sample (bundle.bit_depth).
Values are written as they are, labelled with the bundle’s color_space (nothing is converted; see linear_to_srgb()). An image with a sensor bit depth, such as a sensor response, is written as the sensor’s digital numbers (DN) unless bundle.scaling is PixelScaling::FullRange: scaled up to the file’s bits by left-bit replication, as the PNG specification recommends, with an sBIT chunk giving the sensor’s bit depth, so that DN = value >> (file bits - sensor bits) exactly (read_image_png() does this); or, for a sensor with more bits than the file, with the lowest bits dropped. Other images are stretched over the file’s range: 1 becomes 255 or 65535. Values that are not finite are written as 0, with a warning.