include/mgba-util/png-io.h (view raw)
1/* Copyright (c) 2013-2014 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#ifndef PNG_IO_H
7#define PNG_IO_H
8
9#include <mgba-util/common.h>
10
11CXX_GUARD_START
12
13#ifdef USE_PNG
14
15// png.h defines its own version of restrict which conflicts with mGBA's.
16#ifdef restrict
17#undef restrict
18#endif
19#include <png.h>
20
21struct VFile;
22
23enum {
24 PNG_HEADER_BYTES = 8
25};
26
27png_structp PNGWriteOpen(struct VFile* source);
28png_infop PNGWriteHeader(png_structp png, unsigned width, unsigned height);
29png_infop PNGWriteHeaderA(png_structp png, unsigned width, unsigned height);
30png_infop PNGWriteHeader8(png_structp png, unsigned width, unsigned height);
31bool PNGWritePalette(png_structp png, png_infop info, const uint32_t* palette, unsigned entries);
32bool PNGWritePixels(png_structp png, unsigned width, unsigned height, unsigned stride, const void* pixels);
33bool PNGWritePixelsA(png_structp png, unsigned width, unsigned height, unsigned stride, const void* pixels);
34bool PNGWritePixels8(png_structp png, unsigned width, unsigned height, unsigned stride, const void* pixels);
35bool PNGWriteCustomChunk(png_structp png, const char* name, size_t size, void* data);
36void PNGWriteClose(png_structp png, png_infop info);
37
38typedef int (*ChunkHandler)(png_structp, png_unknown_chunkp);
39
40bool isPNG(struct VFile* source);
41png_structp PNGReadOpen(struct VFile* source, unsigned offset);
42bool PNGInstallChunkHandler(png_structp png, void* context, ChunkHandler handler, const char* chunkName);
43bool PNGReadHeader(png_structp png, png_infop info);
44bool PNGReadPixels(png_structp png, png_infop info, void* pixels, unsigned width, unsigned height, unsigned stride);
45bool PNGReadPixelsA(png_structp png, png_infop info, void* pixels, unsigned width, unsigned height, unsigned stride);
46bool PNGReadPixels8(png_structp png, png_infop info, void* pixels, unsigned width, unsigned height, unsigned stride);
47bool PNGIgnorePixels(png_structp png, png_infop info);
48bool PNGReadFooter(png_structp png, png_infop end);
49void PNGReadClose(png_structp png, png_infop info, png_infop end);
50
51#endif
52
53CXX_GUARD_END
54
55#endif