glviewvol

view src/image.cc @ 0:7bdf40403b9c

dicom viewer project underway
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 27 Dec 2014 02:35:58 +0200
parents
children cc9e0d8590e2
line source
1 #include <imago2.h>
2 #include "image.h"
4 Image::Image()
5 {
6 width = height = 0;
7 pixels = 0;
8 }
10 Image::~Image()
11 {
12 delete [] pixels;
13 }
15 bool Image::set_pixels(int x, int y, float *data)
16 {
17 float *new_pixels;
18 try {
19 new_pixels = new float[x * y];
20 }
21 catch(...) {
22 return false;
23 }
25 width = x;
26 height = y;
28 delete [] pixels;
29 pixels = new_pixels;
31 if(data) {
32 memcpy(pixels, data, x * y * sizeof *data);
33 }
34 return true;
35 }
37 bool Image::load(const char *fname)
38 {
39 // TODO dicom loader ... ?
41 int x, y;
42 float *pixels = img_load_pixels(fname, &x, &y, IMG_FMT_GREYF);
43 if(!pixels) {
44 return false;
45 }
46 bool res = set_pixels(x, y, pixels);
47 img_free_pixels(pixels);
48 return res;
49 }