Debian Codegraph @

bitmap/NewBitmap.h

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Descent Developers
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #ifndef DESCENT3_NEWBITMAP_H
20 #define DESCENT3_NEWBITMAP_H
21
22 #include <cstdint>
23 #include <memory>
24
25 enum class PixelDataFormat {
26 Unknown,
27 RGBA32
28 };
29
30 class NewBitmap {
31 private:
32 uint32_t _w, _h;
33 PixelDataFormat _format;
34 bool _flippedY;
35 std::unique_ptr<uint8_t[]> _data;
36
37 static std::unique_ptr<uint8_t[]> allocateData(uint32_t w, uint32_t h, PixelDataFormat format);
38
39 [[nodiscard]] uint32_t getStride() const;
40
41 public:
42 /// Creates a new bitmap of size "w * h" and the specified format. Will allocate enough memory to store it.
43 NewBitmap(uint32_t w, uint32_t h, PixelDataFormat format, bool flippedY = false);
44
45 void getSize(uint32_t &w, uint32_t &h) const {
46 w = _w;
47 h = _h;
48 }
49
50 /// @returns raw pointer to image data
51 [[nodiscard]] uint8_t *getData() const { return _data.get(); }
52
53 /// @returns number of components for the bitmap format (i.e. 4 for "RGBA")
54 [[nodiscard]] uint32_t getNumComponents() const;
55
56 /// @returns true on success, false otherwise
57 bool saveAsPNG(const char* filePath);
58 };
59
60 #endif // DESCENT3_NEWBITMAP_H