volmetrics
view 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 |
line source
1 #include <imago2.h>
3 #include "image.h"
5 Image::Image()
6 {
7 pixels = 0;
8 width = 0;
9 height = 0;
10 }
12 Image::~Image()
13 {
14 delete [] pixels;
15 }
17 bool Image::load(const char *fname)
18 {
19 int new_width, new_height;
20 float *new_pixels = (float*)img_load_pixels(fname, &new_width, &new_height, IMG_FMT_GREYF);
22 if(!new_pixels) {
23 fprintf(stderr, "Failed to load image: %s\n", fname);
24 return false;
25 }
27 set_pixels(new_pixels, new_width, new_height);
28 img_free_pixels(new_pixels);
29 return true;
30 }
32 float *Image::get_pixels()
33 {
34 return pixels;
35 }
37 const float *Image::get_pixels() const
38 {
39 return pixels;
40 }
42 void Image::set_pixels(const float *pixels, int width, int height)
43 {
44 if(!pixels)
45 return;
47 delete [] this->pixels;
49 this->pixels = new float[width * height];
50 for(int i=0; i<width * height; i++) {
51 this->pixels[i] = pixels[i];
52 }
53 this->width = width;
54 this->height = height;
55 }
57 int Image::get_width() const
58 {
59 return width;
60 }
62 int Image::get_height() const
63 {
64 return height;
65 }