nuclear@1: #include nuclear@0: #include nuclear@0: #include "image.h" nuclear@0: nuclear@0: Image::Image() nuclear@0: { nuclear@0: width = height = 0; nuclear@0: pixels = 0; nuclear@0: } nuclear@0: nuclear@0: Image::~Image() nuclear@0: { nuclear@0: delete [] pixels; nuclear@0: } nuclear@0: nuclear@0: bool Image::set_pixels(int x, int y, float *data) nuclear@0: { nuclear@0: float *new_pixels; nuclear@0: try { nuclear@0: new_pixels = new float[x * y]; nuclear@0: } nuclear@0: catch(...) { nuclear@0: return false; nuclear@0: } nuclear@0: nuclear@0: width = x; nuclear@0: height = y; nuclear@0: nuclear@0: delete [] pixels; nuclear@0: pixels = new_pixels; nuclear@0: nuclear@0: if(data) { nuclear@0: memcpy(pixels, data, x * y * sizeof *data); nuclear@0: } nuclear@0: return true; nuclear@0: } nuclear@0: nuclear@0: bool Image::load(const char *fname) nuclear@0: { nuclear@0: // TODO dicom loader ... ? nuclear@0: nuclear@0: int x, y; nuclear@1: float *pixels = (float*)img_load_pixels(fname, &x, &y, IMG_FMT_GREYF); nuclear@0: if(!pixels) { nuclear@0: return false; nuclear@0: } nuclear@0: bool res = set_pixels(x, y, pixels); nuclear@0: img_free_pixels(pixels); nuclear@0: return res; nuclear@0: }