glviewvol

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/image.cc	Sat Dec 27 02:35:58 2014 +0200
     1.3 @@ -0,0 +1,49 @@
     1.4 +#include <imago2.h>
     1.5 +#include "image.h"
     1.6 +
     1.7 +Image::Image()
     1.8 +{
     1.9 +	width = height = 0;
    1.10 +	pixels = 0;
    1.11 +}
    1.12 +
    1.13 +Image::~Image()
    1.14 +{
    1.15 +	delete [] pixels;
    1.16 +}
    1.17 +
    1.18 +bool Image::set_pixels(int x, int y, float *data)
    1.19 +{
    1.20 +	float *new_pixels;
    1.21 +	try {
    1.22 +		new_pixels = new float[x * y];
    1.23 +	}
    1.24 +	catch(...) {
    1.25 +		return false;
    1.26 +	}
    1.27 +
    1.28 +	width = x;
    1.29 +	height = y;
    1.30 +
    1.31 +	delete [] pixels;
    1.32 +	pixels = new_pixels;
    1.33 +
    1.34 +	if(data) {
    1.35 +		memcpy(pixels, data, x * y * sizeof *data);
    1.36 +	}
    1.37 +	return true;
    1.38 +}
    1.39 +
    1.40 +bool Image::load(const char *fname)
    1.41 +{
    1.42 +	// TODO dicom loader ... ?
    1.43 +
    1.44 +	int x, y;
    1.45 +	float *pixels = img_load_pixels(fname, &x, &y, IMG_FMT_GREYF);
    1.46 +	if(!pixels) {
    1.47 +		return false;
    1.48 +	}
    1.49 +	bool res = set_pixels(x, y, pixels);
    1.50 +	img_free_pixels(pixels);
    1.51 +	return res;
    1.52 +}