37 lines
1.5 KiB
C
37 lines
1.5 KiB
C
// Part of JoeyLib, Copyright (c) 2026 Scott Duensing, under the MIT License.
|
|
// See LICENSE.md for license information.
|
|
// SPDX-License-Identifier: MIT
|
|
//
|
|
// toolZlib.h - DEFLATE for the JoeyLib host tools: inflate (raw, zlib and
|
|
// gzip wrappers -- PNG IDAT, .vgz files, Tiled's compressed layers) and a
|
|
// zlib-wrapped deflate (PNG output). Self-contained C99, no zlib needed.
|
|
|
|
#ifndef TOOL_ZLIB_H
|
|
#define TOOL_ZLIB_H
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
|
|
typedef enum ToolZlibFormatE {
|
|
TOOL_ZLIB_RAW = 0, // a bare DEFLATE stream
|
|
TOOL_ZLIB_ZLIB, // RFC 1950: 2-byte header, Adler-32 trailer
|
|
TOOL_ZLIB_GZIP, // RFC 1952: gzip member, CRC-32 trailer
|
|
TOOL_ZLIB_AUTO // gzip if it starts 1F 8B, else zlib
|
|
} ToolZlibFormatE;
|
|
|
|
// Adler-32 and CRC-32 (the PNG / gzip polynomial), each continuing from
|
|
// `seed` (1 and 0 to start).
|
|
uint32_t toolAdler32(uint32_t seed, const uint8_t *data, size_t len);
|
|
uint32_t toolCrc32(uint32_t seed, const uint8_t *data, size_t len);
|
|
|
|
// Inflate `in` (format `fmt`) into a malloc'd buffer at *out, its length at
|
|
// *outLen. Checks the wrapper's checksum. Returns false (and frees nothing it
|
|
// did not make) on a bad stream.
|
|
bool toolInflate(const uint8_t *in, size_t inLen, ToolZlibFormatE fmt, uint8_t **out, size_t *outLen);
|
|
|
|
// Deflate `in` into a malloc'd zlib stream at *out (LZ77 with fixed Huffman
|
|
// codes: small and fast, not the smallest).
|
|
bool toolDeflateZlib(const uint8_t *in, size_t inLen, uint8_t **out, size_t *outLen);
|
|
|
|
#endif
|