volmetrics
annotate src/volume.cc @ 0:88d390af583f
Image loader
author | Eleni Maria Stea <eleni@mutantstargoat.com> |
---|---|
date | Sat, 11 Jan 2014 17:22:36 +0200 |
parents | |
children | 927c29b93009 |
rev | line source |
---|---|
eleni@0 | 1 #include <imago2.h> |
eleni@0 | 2 |
eleni@0 | 3 #include "image.h" |
eleni@0 | 4 |
eleni@0 | 5 Image::Image() |
eleni@0 | 6 { |
eleni@0 | 7 pixels = 0; |
eleni@0 | 8 width = 0; |
eleni@0 | 9 height = 0; |
eleni@0 | 10 } |
eleni@0 | 11 |
eleni@0 | 12 Image::~Image() |
eleni@0 | 13 { |
eleni@0 | 14 delete [] pixels; |
eleni@0 | 15 } |
eleni@0 | 16 |
eleni@0 | 17 bool Image::load(const char *fname) |
eleni@0 | 18 { |
eleni@0 | 19 int new_width, new_height; |
eleni@0 | 20 float *new_pixels = (float*)img_load_pixels(fname, &new_width, &new_height, IMG_FMT_GREYF); |
eleni@0 | 21 |
eleni@0 | 22 if(!new_pixels) { |
eleni@0 | 23 fprintf(stderr, "Failed to load image: %s\n", fname); |
eleni@0 | 24 return false; |
eleni@0 | 25 } |
eleni@0 | 26 |
eleni@0 | 27 set_pixels(new_pixels, new_width, new_height); |
eleni@0 | 28 img_free_pixels(new_pixels); |
eleni@0 | 29 return true; |
eleni@0 | 30 } |
eleni@0 | 31 |
eleni@0 | 32 float *Image::get_pixels() |
eleni@0 | 33 { |
eleni@0 | 34 return pixels; |
eleni@0 | 35 } |
eleni@0 | 36 |
eleni@0 | 37 const float *Image::get_pixels() const |
eleni@0 | 38 { |
eleni@0 | 39 return pixels; |
eleni@0 | 40 } |
eleni@0 | 41 |
eleni@0 | 42 void Image::set_pixels(const float *pixels, int width, int height) |
eleni@0 | 43 { |
eleni@0 | 44 if(!pixels) |
eleni@0 | 45 return; |
eleni@0 | 46 |
eleni@0 | 47 delete [] this->pixels; |
eleni@0 | 48 |
eleni@0 | 49 this->pixels = new float[width * height]; |
eleni@0 | 50 for(int i=0; i<width * height; i++) { |
eleni@0 | 51 this->pixels[i] = pixels[i]; |
eleni@0 | 52 } |
eleni@0 | 53 this->width = width; |
eleni@0 | 54 this->height = height; |
eleni@0 | 55 } |
eleni@0 | 56 |
eleni@0 | 57 int Image::get_width() const |
eleni@0 | 58 { |
eleni@0 | 59 return width; |
eleni@0 | 60 } |
eleni@0 | 61 |
eleni@0 | 62 int Image::get_height() const |
eleni@0 | 63 { |
eleni@0 | 64 return height; |
eleni@0 | 65 } |