tinyimg 1.1.1
Lightweight image manipulation library for WebAssembly
Loading...
Searching...
No Matches
codec.h
Go to the documentation of this file.
1
12#pragma once
13
14#include <stddef.h>
15#include <stdint.h>
16
18#include "tinyimg/image.h"
19#include "tinyimg/tinyimg.h"
20#include "tinyimg/util.h"
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
37typedef int (*TinySniffFn)(const uint8_t* buffer, size_t size);
38
47typedef int (*TinyProbeFn)(
48 const uint8_t* buffer, size_t size, TinyImageInfo* info
49);
50
66typedef int (*TinyDecodeFn)(
67 TinyImage* image, const uint8_t* buffer, size_t size,
68 const TinyDecodeOpts* opts
69);
70
80typedef int (*TinyEncodeFn)(
81 const TinyImage* image, const TinyEncodeOpts* opts, TinyWriter* writer
82);
83
103
111
119const TinyCodec* tiny_codec_sniff(const uint8_t* buffer, size_t size);
120
126uint32_t tiny_codec_count(void);
127
134const TinyCodec* tiny_codec_at(uint32_t index);
135
136#pragma region shared helpers
137
155 const TinyDecodeOpts* opts, uint32_t width, uint32_t height,
156 TinyDecodeOpts* out, uint32_t* out_width, uint32_t* out_height
157);
158
170
184 uint8_t* dest, uint8_t dest_channels, const uint8_t* src,
185 uint8_t src_channels
186);
187
196static inline uint8_t tiny_luma(uint8_t r, uint8_t g, uint8_t b) {
197 // 13933 + 46871 + 4732 == 65536, so the sum cannot drift off 255
198 uint32_t sum = 13933u * r + 46871u * g + 4732u * b;
199 return (uint8_t) ((sum + 32768u) >> 16);
200}
201
202#pragma endregion
203
204#ifdef __cplusplus
205}
206#endif
const TinyCodec * tiny_codec_at(uint32_t index)
The registered codec at an index, for enumerating the build's support.
int(*) TinySniffFn(const uint8_t *buffer, size_t size)
Tests whether a buffer looks like this codec's format.
Definition codec.h:37
int tiny_decode_resolve(const TinyDecodeOpts *opts, uint32_t width, uint32_t height, TinyDecodeOpts *out, uint32_t *out_width, uint32_t *out_height)
Clamps decode options against an image's real dimensions.
int(*) TinyEncodeFn(const TinyImage *image, const TinyEncodeOpts *opts, TinyWriter *writer)
Encodes an image into a byte sink.
Definition codec.h:80
uint32_t tiny_codec_count(void)
How many codecs this build registered.
const TinyCodec * tiny_codec_find(TinyImageFormat format)
Finds the codec for a format.
int(*) TinyDecodeFn(TinyImage *image, const uint8_t *buffer, size_t size, const TinyDecodeOpts *opts)
Decodes pixels, honoring the region, scale and channel count asked for.
Definition codec.h:66
const TinyCodec * tiny_codec_sniff(const uint8_t *buffer, size_t size)
Finds the codec whose format a buffer's magic bytes match.
int(*) TinyProbeFn(const uint8_t *buffer, size_t size, TinyImageInfo *info)
Fills in what the header says, decoding no pixels.
Definition codec.h:47
void tiny_pixel_convert(uint8_t *dest, uint8_t dest_channels, const uint8_t *src, uint8_t src_channels)
Writes one source pixel into a destination row, converting channels.
TinyDeflateLevel tiny_encode_level(const TinyEncodeOpts *opts)
The deflate level an encoder's options ask for.
DEFLATE and zlib streams, shared by the PNG and TIFF codecs.
TinyDeflateLevel
How hard the compressor should look for matches.
Definition deflate.h:205
Image processing library utilities.
TinyImageFormat
Image formats supported by TinyImage for conversion and saving.
Definition image.h:32
One container format's implementation.
Definition codec.h:91
TinySniffFn sniff
Definition codec.h:95
TinyProbeFn probe
Definition codec.h:97
TinyEncodeFn encode
Definition codec.h:101
TinyImageFormat format
Definition codec.h:93
TinyDecodeFn decode
Definition codec.h:99
Options a decoder honors when only part of an image is wanted.
Definition image.h:156
Options an encoder honors.
Definition image.h:269
What a format's header says about an image, before any pixel is decoded.
Definition image.h:119
Represents an image with its width, height, and pixel data.
Definition image.h:90
A grow on demand byte sink.
Definition util.h:412
Umbrella header, version and error codes.
Math shims, lookup table builders, checksums and bit level IO.