1/*
2 * LegacyClonk
3 *
4 * Copyright (c) RedWolf Design
5 * Copyright (c) 2001, Sven2
6 * Copyright (c) 2017-2019, The LegacyClonk Team and contributors
7 *
8 * Distributed under the terms of the ISC license; see accompanying file
9 * "COPYING" for details.
10 *
11 * "Clonk" is a registered trademark of Matthes Bender, used with permission.
12 * See accompanying file "TRADEMARK" for details.
13 *
14 * To redistribute this file separately, substitute the full license texts
15 * for the above references.
16 */
17
18#pragma once
19
20#include "C4Log.h"
21
22#include <cstddef>
23#include <cstdint>
24#include <memory>
25#include <string>
26
27// Reads and writes PNG files
28class CPNGFile
29{
30public:
31 // Creates an object that can be used to write to the specified file.
32 CPNGFile(const std::string &filename, std::uint32_t width, std::uint32_t height, bool useAlpha);
33 // Writes the specified image to the PNG file. Don't use this object after calling.
34 void Encode(const void *pixels);
35
36 // Creates an object that can be used to read the specified file contents.
37 CPNGFile(const void *fileContents, std::size_t fileSize);
38 // Reads the PNG file into the specified buffer. Don't use this object after calling.
39 void Decode(void *pixels);
40
41 ~CPNGFile();
42
43 std::uint32_t Width() const;
44 std::uint32_t Height() const;
45 bool UsesAlpha() const;
46
47 // Use Pimpl so we don't have to include png.h in the header
48private:
49 struct Impl;
50 const std::unique_ptr<Impl> impl;
51};
52
53C4LOGGERCONFIG_NAME_TYPE(CPNGFile);
54