nk 1.0.0
C++ Numerical Computing Runtime
Loading...
Searching...
No Matches
toolboxes/image/include/nk/image/io/io.hpp
Go to the documentation of this file.
1
3// toolboxes/image/include/nk/image/io/io.hpp
4//
5// Autonomous, zero-dependency in-tree image disk I/O (PNG, JPEG, BMP,
6// TGA, PNM, TIFF/BigTIFF).
7//
8// imread returns an H × W (grayscale) or H × W × 3 / 4 (color)
9// uint8 or uint16 array, preserving full scientific 16-bit depth.
10
11#pragma once
12
13#include <cstdint>
14#include <memory_resource>
15#include <nk/value/value.hpp>
16#include <string>
17#include <utility>
18#include <vector>
19
20namespace nk::image {
21
24
25
40Value imread(const std::string &path,
41 std::pmr::memory_resource *mr = nullptr);
42
61void imwrite(const Value &A, const std::string &path,
62 std::pmr::memory_resource *mr = nullptr);
63
71std::string imwriteToBytes(const Value &A, const std::string &ext,
72 std::pmr::memory_resource *mr = nullptr);
73
90Value imfinfo(const std::string &path,
91 std::pmr::memory_resource *mr = nullptr);
92
98Value imfinfoFromBytes(const std::string &bytes, const std::string &filename,
99 std::pmr::memory_resource *mr = nullptr);
100
120Value readTiff(const std::string &path,
121 std::pmr::memory_resource *mr = nullptr);
122
125Value readTiff(const std::string &path, std::uint32_t page,
126 std::pmr::memory_resource *mr = nullptr);
127
130Value readTiff(std::vector<std::uint8_t> buf, std::uint32_t page,
131 std::pmr::memory_resource *mr = nullptr);
132std::pair<Value, Value>
133readTiffWithMap(std::vector<std::uint8_t> buf, std::uint32_t page,
134 std::pmr::memory_resource *mr = nullptr);
135
141std::pair<Value, Value>
142readTiffWithMap(const std::string &path, std::uint32_t page,
143 std::pmr::memory_resource *mr = nullptr);
144
149void peekTiff(const std::string &path,
150 std::uint32_t &W,
151 std::uint32_t &H,
152 std::uint16_t &bits,
153 std::uint16_t &channels);
154
157void peekTiff(const std::vector<std::uint8_t> &buf,
158 std::uint32_t &W,
159 std::uint32_t &H,
160 std::uint16_t &bits,
161 std::uint16_t &channels);
162
165std::uint32_t tiffNumPages(const std::string &path);
166
179void writeTiff(const Value &A, const std::string &path,
180 const std::string &compression = "none",
181 bool appendMode = false);
182
191std::vector<std::uint8_t>
193 const std::string &compression = "none",
194 const std::vector<std::uint8_t> *existing = nullptr);
195
196
198} // namespace nk::image
Core MATLAB-compatible multidimensional array and scalar value type.
Definition value.hpp:61
std::uint32_t tiffNumPages(const std::string &path)
Count the number of IFDs (pages) in a TIFF file.
Value imfinfo(const std::string &path, std::pmr::memory_resource *mr=nullptr)
Read image header metadata without decoding pixels (S = imfinfo(path)).
std::vector< std::uint8_t > writeTiffToBytes(const Value &A, const std::string &compression="none", const std::vector< std::uint8_t > *existing=nullptr)
Buffer form — encode A to a TIFF byte vector (the engine entry writes these through the VFS).
Value imfinfoFromBytes(const std::string &bytes, const std::string &filename, std::pmr::memory_resource *mr=nullptr)
imfinfo from already-loaded bytes (the engine entry feeds these from the VFS so it works on the virtu...
void peekTiff(const std::string &path, std::uint32_t &W, std::uint32_t &H, std::uint16_t &bits, std::uint16_t &channels)
Peek a TIFF file's first-IFD metadata without decoding pixels.
void writeTiff(const Value &A, const std::string &path, const std::string &compression="none", bool appendMode=false)
Write A to path as a baseline TIFF.
std::string imwriteToBytes(const Value &A, const std::string &ext, std::pmr::memory_resource *mr=nullptr)
Encode an image to in-memory bytes (companion to imwrite).
void imwrite(const Value &A, const std::string &path, std::pmr::memory_resource *mr=nullptr)
Write an image to disk (imwrite(A, path)).
Value imread(const std::string &path, std::pmr::memory_resource *mr=nullptr)
Read an image from disk (A = imread(path)).
Value readTiff(const std::string &path, std::pmr::memory_resource *mr=nullptr)
Minimal TIFF reader for the formats stb doesn't decode.