glviewvol
view src/image.cc @ 7:71b479ffb9f7
curve manipulation works
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 30 Dec 2014 17:28:38 +0200 |
parents | cc9e0d8590e2 |
children | 773f89037a35 |
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 void Image::destroy()
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 }