glviewvol

view src/image.cc @ 15:2a67ea257ac0

makefile fixes for macosx
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 06 Feb 2015 23:47:28 +0200
parents 32c4a7160350
children
line source
1 /*
2 glviewvol is an OpenGL 3D volume data viewer
3 Copyright (C) 2014 John Tsiombikas <nuclear@member.fsf.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include <string.h>
19 #include <imago2.h>
20 #include "image.h"
22 Image::Image()
23 {
24 width = height = 0;
25 pixels = 0;
26 }
28 void Image::destroy()
29 {
30 delete [] pixels;
31 }
33 bool Image::set_pixels(int x, int y, float *data)
34 {
35 float *new_pixels;
36 try {
37 new_pixels = new float[x * y];
38 }
39 catch(...) {
40 return false;
41 }
43 width = x;
44 height = y;
46 delete [] pixels;
47 pixels = new_pixels;
49 if(data) {
50 memcpy(pixels, data, x * y * sizeof *data);
51 }
52 return true;
53 }
55 bool Image::load(const char *fname)
56 {
57 // TODO dicom loader ... ?
59 int x, y;
60 float *pixels = (float*)img_load_pixels(fname, &x, &y, IMG_FMT_GREYF);
61 if(!pixels) {
62 return false;
63 }
64 bool res = set_pixels(x, y, pixels);
65 img_free_pixels(pixels);
66 return res;
67 }