forked from Chlumsky/msdfgen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsave-png.cpp
More file actions
65 lines (55 loc) · 2.71 KB
/
save-png.cpp
File metadata and controls
65 lines (55 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "save-png.h"
#include <cstring>
#include <lodepng.h>
#include "../core/pixel-conversion.hpp"
namespace msdfgen {
bool savePng(const BitmapConstRef<byte, 1> &bitmap, const char *filename) {
std::vector<byte> pixels(bitmap.width*bitmap.height);
for (int y = 0; y < bitmap.height; ++y)
memcpy(&pixels[bitmap.width*y], bitmap(0, bitmap.height-y-1), bitmap.width);
return !lodepng::encode(filename, pixels, bitmap.width, bitmap.height, LCT_GREY);
}
bool savePng(const BitmapConstRef<byte, 3> &bitmap, const char *filename) {
std::vector<byte> pixels(3*bitmap.width*bitmap.height);
for (int y = 0; y < bitmap.height; ++y)
memcpy(&pixels[3*bitmap.width*y], bitmap(0, bitmap.height-y-1), 3*bitmap.width);
return !lodepng::encode(filename, pixels, bitmap.width, bitmap.height, LCT_RGB);
}
bool savePng(const BitmapConstRef<byte, 4> &bitmap, const char *filename) {
std::vector<byte> pixels(4*bitmap.width*bitmap.height);
for (int y = 0; y < bitmap.height; ++y)
memcpy(&pixels[4*bitmap.width*y], bitmap(0, bitmap.height-y-1), 4*bitmap.width);
return !lodepng::encode(filename, pixels, bitmap.width, bitmap.height, LCT_RGBA);
}
bool savePng(const BitmapConstRef<float, 1> &bitmap, const char *filename) {
std::vector<byte> pixels(bitmap.width*bitmap.height);
std::vector<byte>::iterator it = pixels.begin();
for (int y = bitmap.height-1; y >= 0; --y)
for (int x = 0; x < bitmap.width; ++x)
*it++ = pixelFloatToByte(*bitmap(x, y));
return !lodepng::encode(filename, pixels, bitmap.width, bitmap.height, LCT_GREY);
}
bool savePng(const BitmapConstRef<float, 3> &bitmap, const char *filename) {
std::vector<byte> pixels(3*bitmap.width*bitmap.height);
std::vector<byte>::iterator it = pixels.begin();
for (int y = bitmap.height-1; y >= 0; --y)
for (int x = 0; x < bitmap.width; ++x) {
*it++ = pixelFloatToByte(bitmap(x, y)[0]);
*it++ = pixelFloatToByte(bitmap(x, y)[1]);
*it++ = pixelFloatToByte(bitmap(x, y)[2]);
}
return !lodepng::encode(filename, pixels, bitmap.width, bitmap.height, LCT_RGB);
}
bool savePng(const BitmapConstRef<float, 4> &bitmap, const char *filename) {
std::vector<byte> pixels(4*bitmap.width*bitmap.height);
std::vector<byte>::iterator it = pixels.begin();
for (int y = bitmap.height-1; y >= 0; --y)
for (int x = 0; x < bitmap.width; ++x) {
*it++ = pixelFloatToByte(bitmap(x, y)[0]);
*it++ = pixelFloatToByte(bitmap(x, y)[1]);
*it++ = pixelFloatToByte(bitmap(x, y)[2]);
*it++ = pixelFloatToByte(bitmap(x, y)[3]);
}
return !lodepng::encode(filename, pixels, bitmap.width, bitmap.height, LCT_RGBA);
}
}