blob: eaab3b7720b93cd750e5df96e4df5117f7b9997e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
#include "imageutils.h"
#include <string.h>
#include <fstream>
void flip_image(const unsigned char *src, unsigned char *dst, size_t pixelsize, size_t width, size_t height)
{
size_t rowBytes = pixelsize * width;
for (size_t i = 0 ; i < height ; i++) {
memmove(dst + (height - i - 1) * rowBytes, src + i * rowBytes, rowBytes);
}
}
bool write_png(const char *filename, unsigned char *pixels, int width, int height) {
std::ofstream fstream( filename );
if (fstream.is_open()) {
write_png( fstream, pixels, width, height );
fstream.close();
return true;
} else {
std::cerr << "Can't open file " << filename << " for export.";
return false;
}
}
|