summaryrefslogtreecommitdiff
path: root/src/imageutils.cc
blob: 3e1f3bcb60db50d148cd98c21eb2b3d83a6c381d (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
25
26
27
#include "imageutils.h"
#include <assert.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)
{
  assert( src && dst );
  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) {
  assert( filename && pixels );
  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;
  }
}

contact: Jan Huwald // Impressum