volmetrics

annotate src/image.cc @ 3:927c29b93009

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