Debian Codegraph @

bitmap/NewBitmap.cpp

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
20 #include "NewBitmap.h"cxx . . $ `<file>/bitmap/NewBitmap.h`/
21 #include "pserror.h"cxx . . $ `<file>/misc/pserror.h`/
22
23 #include <stb_image_write.h>cxx . . $ `<file>/third_party/stb/stb_image_write.h`/
24
25 NewBitmapcxx . . $ NewBitmap#::NewBitmapcxx . . $ NewBitmap#NewBitmap(3853f9d062b56d84).(uint32_tcxx . . $ uint32_t# w, uint32_tcxx . . $ uint32_t# h, PixelDataFormatcxx . . $ PixelDataFormat# format, bool flippedY)
26 : _wcxx . . $ NewBitmap#_w.(w), _hcxx . . $ NewBitmap#_h.(h), _formatcxx . . $ NewBitmap#_format.(format), _flippedYcxx . . $ NewBitmap#_flippedY.(flippedY), _datacxx . . $ NewBitmap#_data.(allocateDatacxx . . $ NewBitmap#allocateData(5310126d2cce5494).(w, h, format)) {
27 ASSERTcxx . . $ `misc/pserror.h:246:9`!(_data.get());
28 }
29
30 std::unique_ptrcxx . . $ std/unique_ptr#<uint8_tcxx . . $ uint8_t#[]> NewBitmapcxx . . $ NewBitmap#::allocateDatacxx . . $ NewBitmap#allocateData(5310126d2cce5494).(uint32_tcxx . . $ uint32_t# w, uint32_tcxx . . $ uint32_t# h, PixelDataFormatcxx . . $ PixelDataFormat# format) {
31 switch (format) {
32 case PixelDataFormatcxx . . $ PixelDataFormat#::RGBA32cxx . . $ PixelDataFormat#RGBA32.: return std::make_uniquecxx . . $ std/make_unique(dfd06a9f52fea874).<uint8_tcxx . . $ uint8_t#[]>(w * h * 4);
33 default: return nullptrcxx . . $ std/unique_ptr#unique_ptr(6d988fd07f070dfc).;
34 }
35 }
36
37 uint32_tcxx . . $ uint32_t# NewBitmapcxx . . $ NewBitmap#::getNumComponentscxx . . $ NewBitmap#getNumComponents(ddd8539a2fcdd4ce).() const {
38 switch (_formatcxx . . $ NewBitmap#_format.) {
39 case PixelDataFormatcxx . . $ PixelDataFormat#::RGBA32cxx . . $ PixelDataFormat#RGBA32.: return 4;
40 default: return 0;
41 }
42 }
43
44 uint32_tcxx . . $ uint32_t# NewBitmapcxx . . $ NewBitmap#::getStridecxx . . $ NewBitmap#getStride(ddd8539a2fcdd4ce).() const {
45 switch (_formatcxx . . $ NewBitmap#_format.) {
46 case PixelDataFormatcxx . . $ PixelDataFormat#::RGBA32cxx . . $ PixelDataFormat#RGBA32.: return _wcxx . . $ NewBitmap#_w. * 4;
47 default: return 0;
48 }
49 }
50
51 bool NewBitmapcxx . . $ NewBitmap#::saveAsPNGcxx . . $ NewBitmap#saveAsPNG(c5f7da30cbc0f4e9).(const char *filePath) {
52 // TODO: Support more formats? stb_write supports at least RGB and RGBA
53 ASSERTcxx . . $ `misc/pserror.h:246:9`!(_format == PixelDataFormat::RGBA32);
54
55 stbi_flip_vertically_on_write(_flippedYcxx . . $ NewBitmap#_flippedY.);
56 return stbi_write_png(filePath, _wcxx . . $ NewBitmap#_w., _hcxx . . $ NewBitmap#_h., getNumComponentscxx . . $ NewBitmap#getNumComponents(ddd8539a2fcdd4ce).(), _datacxx . . $ NewBitmap#_data..getcxx . . $ std/unique_ptr#get(ea7391e9eeeaf20e).(), getStridecxx . . $ NewBitmap#getStride(ddd8539a2fcdd4ce).()) == 0;
57 }