2013-01-24 07:02:31 +04:00
|
|
|
#include "imageutils.h"
|
2013-01-31 08:36:12 +04:00
|
|
|
#include <assert.h>
|
2013-01-24 07:02:31 +04:00
|
|
|
#include <string.h>
|
2013-01-26 04:36:55 +04:00
|
|
|
#include <fstream>
|
2013-01-24 07:02:31 +04:00
|
|
|
|
|
|
|
void flip_image(const unsigned char *src, unsigned char *dst, size_t pixelsize, size_t width, size_t height)
|
|
|
|
{
|
2013-01-31 08:22:52 +04:00
|
|
|
assert( src && dst );
|
2013-01-24 07:02:31 +04:00
|
|
|
size_t rowBytes = pixelsize * width;
|
|
|
|
for (size_t i = 0 ; i < height ; i++) {
|
|
|
|
memmove(dst + (height - i - 1) * rowBytes, src + i * rowBytes, rowBytes);
|
|
|
|
}
|
|
|
|
}
|
2013-01-26 04:36:55 +04:00
|
|
|
|
|
|
|
bool write_png(const char *filename, unsigned char *pixels, int width, int height) {
|
2013-01-31 08:22:52 +04:00
|
|
|
assert( filename && pixels );
|
2013-01-27 01:43:06 +04:00
|
|
|
std::ofstream fstream( filename, std::ios::binary );
|
2013-01-26 04:36:55 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|