glviewvol
view src/image.cc @ 1:cc9e0d8590e2
foo
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 27 Dec 2014 06:32:28 +0200 |
parents | 7bdf40403b9c |
children | 32c4a7160350 |
line source
1 #include <string.h>
2 #include <imago2.h>
3 #include "image.h"
5 Image::Image()
6 {
7 width = height = 0;
8 pixels = 0;
9 }
11 Image::~Image()
12 {
13 delete [] pixels;
14 }
16 bool Image::set_pixels(int x, int y, float *data)
17 {
18 float *new_pixels;
19 try {
20 new_pixels = new float[x * y];
21 }
22 catch(...) {
23 return false;
24 }
26 width = x;
27 height = y;
29 delete [] pixels;
30 pixels = new_pixels;
32 if(data) {
33 memcpy(pixels, data, x * y * sizeof *data);
34 }
35 return true;
36 }
38 bool Image::load(const char *fname)
39 {
40 // TODO dicom loader ... ?
42 int x, y;
43 float *pixels = (float*)img_load_pixels(fname, &x, &y, IMG_FMT_GREYF);
44 if(!pixels) {
45 return false;
46 }
47 bool res = set_pixels(x, y, pixels);
48 img_free_pixels(pixels);
49 return res;
50 }