MTL5 -- Matrix Template Library C++ API
mtl:: -- C++20 header-only linear algebra for mixed-precision algorithm design
Loading...
Searching...
No Matches
png.hpp File Reference
#include <array>
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <filesystem>
#include <fstream>
#include <stdexcept>
#include <string>
#include <vector>

Namespaces

namespace  mtl
namespace  mtl::io
namespace  mtl::io::detail

Functions

const std::array< std::uint32_t, 256 > & mtl::io::detail::crc32_table ()
 CRC-32 lookup table (reflected polynomial 0xEDB88320), built once.
std::uint32_t mtl::io::detail::crc32_add (std::uint32_t crc, const std::uint8_t *buf, std::size_t len)
 Fold bytes into a running CRC-32 register (internal, pre-inverted form: start from 0xFFFFFFFF and XOR 0xFFFFFFFF once at the end).
std::uint32_t mtl::io::detail::adler32 (const std::uint8_t *data, std::size_t len)
 Adler-32 (zlib checksum) of a byte buffer.
void mtl::io::detail::put_u32_be (std::vector< std::uint8_t > &v, std::uint32_t x)
std::vector< std::uint8_t > mtl::io::detail::zlib_store (const std::vector< std::uint8_t > &raw)
 Wrap raw bytes into a zlib stream of DEFLATE stored blocks (no compression).
void mtl::io::detail::write_chunk (std::ofstream &os, const char type[4], const std::vector< std::uint8_t > &data)
 Write one PNG chunk: length (BE) + type + data + CRC-32(type+data).
void mtl::io::detail::write_png (const std::filesystem::path &path, const std::uint8_t *pixels, std::size_t w, std::size_t h, int channels)
 Core writer: channels is 1 (grayscale) or 3 (RGB); pixels is row-major, w*h*channels bytes, top row first.
void mtl::io::write_png_gray (const std::filesystem::path &path, const std::uint8_t *pixels, std::size_t w, std::size_t h)
 Write an 8-bit grayscale PNG. pixels is w*h bytes, row-major, top row first.
void mtl::io::write_png_rgb (const std::filesystem::path &path, const std::uint8_t *rgb, std::size_t w, std::size_t h)
 Write an 8-bit RGB PNG. rgb is w*h*3 bytes (R,G,B per pixel), row-major.