glviewvol

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