TIFF I/O

Reading

inline ImageBundle<RGB> huira::read_image_tiff_rgb(const fs::path &filepath, bool read_alpha)

Reads a TIFF file and returns RGB + optional alpha data.

Convenience overload that reads the file into memory and forwards to the buffer-based implementation.

inline ImageBundle<RGB> huira::read_image_tiff_rgb(const unsigned char *data, std::size_t size, bool read_alpha)

Reads a TIFF from an in-memory buffer and returns RGB + optional alpha data.

Interprets the TIFF data as RGB color:

  • 1-channel: promoted to RGB (equal values in all channels)

  • 3-channel: interpreted as RGB directly

  • 4-channel with alpha: RGB + separate alpha

  • Other channel counts: throws an error

Parameters:
  • data – Pointer to the TIFF data in memory

  • size – Size of the data in bytes

  • read_alpha – If false, alpha channel is not extracted even if present

Returns:

An ImageBundle<RGB> containing the RGB image and an optional alpha image.

inline ImageBundle<float> huira::read_image_tiff_mono(const fs::path &filepath, bool read_alpha)

Reads a TIFF file and returns mono + optional alpha data.

Convenience overload that reads the file into memory and forwards to the buffer-based implementation.

inline ImageBundle<float> huira::read_image_tiff_mono(const unsigned char *data, std::size_t size, bool read_alpha)

Reads a TIFF from an in-memory buffer and returns mono + optional alpha data.

Interprets the TIFF data as single-channel:

  • 1-channel: returned directly

  • 3-channel: averaged to mono

  • Other channel counts (excluding alpha): throws an error

Parameters:
  • data – Pointer to the TIFF data in memory

  • size – Size of the data in bytes

  • read_alpha – If false, alpha channel is not extracted even if present

Returns:

An ImageBundle<float> containing the mono image and an optional alpha image.

Writing

inline void huira::write_image_tiff(const fs::path &filepath, const ImageBundle<RGB> &bundle, const std::string &description, const std::string &artist)

Writes an RGB image to a TIFF file, of 8 or 16 bits per sample (bundle.bit_depth), with optional metadata.

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: as they are (a 12-bit sensor’s 0 to 4095, in 16 bits), with the MaxSampleValue tag giving the largest (4095), which read_image_tiff_rgb() and read_image_tiff_mono() use to normalize them back; or, for a sensor with more bits than the file, with the lowest bits dropped. Other images are stretched over the file’s range, rounded: 1 becomes 255 or 65535. Values that are not finite are written as 0, with a warning. Nothing is converted between color encodings (see linear_to_srgb()).

Parameters:
  • filepath – Output file path

  • bundle – An ImageBundle<RGB> containing the image to write

  • description – Optional image description metadata

  • artist – Optional artist metadata

inline void huira::write_image_tiff(const fs::path &filepath, const ImageBundle<float> &bundle, const std::string &description, const std::string &artist)

Writes a monochrome image to a TIFF file with optional metadata. See the RGB overload.

template<IsSpectral TSpectral>
inline void huira::write_image_tiff(const fs::path &filepath, const ImageBundle<TSpectral> &bundle, const std::string &description, const std::string &artist)

Writes a spectral image to a TIFF file by converting to mono: the mean of its channels.