diff options
Diffstat (limited to 'src/imageutils.cc')
-rw-r--r-- | src/imageutils.cc | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/imageutils.cc b/src/imageutils.cc new file mode 100644 index 0000000..133eaf1 --- /dev/null +++ b/src/imageutils.cc @@ -0,0 +1,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, std::ios::binary ); + 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; + } +} + |