glviewvol
annotate 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 |
rev | line source |
---|---|
nuclear@1 | 1 #include <string.h> |
nuclear@0 | 2 #include <imago2.h> |
nuclear@0 | 3 #include "image.h" |
nuclear@0 | 4 |
nuclear@0 | 5 Image::Image() |
nuclear@0 | 6 { |
nuclear@0 | 7 width = height = 0; |
nuclear@0 | 8 pixels = 0; |
nuclear@0 | 9 } |
nuclear@0 | 10 |
nuclear@0 | 11 Image::~Image() |
nuclear@0 | 12 { |
nuclear@0 | 13 delete [] pixels; |
nuclear@0 | 14 } |
nuclear@0 | 15 |
nuclear@0 | 16 bool Image::set_pixels(int x, int y, float *data) |
nuclear@0 | 17 { |
nuclear@0 | 18 float *new_pixels; |
nuclear@0 | 19 try { |
nuclear@0 | 20 new_pixels = new float[x * y]; |
nuclear@0 | 21 } |
nuclear@0 | 22 catch(...) { |
nuclear@0 | 23 return false; |
nuclear@0 | 24 } |
nuclear@0 | 25 |
nuclear@0 | 26 width = x; |
nuclear@0 | 27 height = y; |
nuclear@0 | 28 |
nuclear@0 | 29 delete [] pixels; |
nuclear@0 | 30 pixels = new_pixels; |
nuclear@0 | 31 |
nuclear@0 | 32 if(data) { |
nuclear@0 | 33 memcpy(pixels, data, x * y * sizeof *data); |
nuclear@0 | 34 } |
nuclear@0 | 35 return true; |
nuclear@0 | 36 } |
nuclear@0 | 37 |
nuclear@0 | 38 bool Image::load(const char *fname) |
nuclear@0 | 39 { |
nuclear@0 | 40 // TODO dicom loader ... ? |
nuclear@0 | 41 |
nuclear@0 | 42 int x, y; |
nuclear@1 | 43 float *pixels = (float*)img_load_pixels(fname, &x, &y, IMG_FMT_GREYF); |
nuclear@0 | 44 if(!pixels) { |
nuclear@0 | 45 return false; |
nuclear@0 | 46 } |
nuclear@0 | 47 bool res = set_pixels(x, y, pixels); |
nuclear@0 | 48 img_free_pixels(pixels); |
nuclear@0 | 49 return res; |
nuclear@0 | 50 } |