gpuray_glsl
annotate src/image.cc @ 5:000017955721
fixed the cone normal
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 11 Nov 2014 20:25:59 +0200 |
parents | |
children |
rev | line source |
---|---|
nuclear@0 | 1 #include <stdio.h> |
nuclear@0 | 2 #include <string.h> |
nuclear@0 | 3 #include <errno.h> |
nuclear@0 | 4 #include "image.h" |
nuclear@0 | 5 #include "material.h" |
nuclear@0 | 6 #include <imago2.h> |
nuclear@0 | 7 |
nuclear@0 | 8 Image::Image() |
nuclear@0 | 9 { |
nuclear@0 | 10 pixels = 0; |
nuclear@0 | 11 xsz = ysz = 0; |
nuclear@0 | 12 } |
nuclear@0 | 13 |
nuclear@0 | 14 Image::Image(int xsz, int ysz) |
nuclear@0 | 15 { |
nuclear@0 | 16 pixels = 0; |
nuclear@0 | 17 set_pixels(xsz, ysz, 0); |
nuclear@0 | 18 } |
nuclear@0 | 19 |
nuclear@0 | 20 Image::~Image() |
nuclear@0 | 21 { |
nuclear@0 | 22 delete [] pixels; |
nuclear@0 | 23 } |
nuclear@0 | 24 |
nuclear@0 | 25 void Image::set_pixels(int xsz, int ysz, const Color *pix) |
nuclear@0 | 26 { |
nuclear@0 | 27 delete [] pixels; |
nuclear@0 | 28 |
nuclear@0 | 29 pixels = new Color[xsz * ysz]; |
nuclear@0 | 30 this->xsz = xsz; |
nuclear@0 | 31 this->ysz = ysz; |
nuclear@0 | 32 |
nuclear@0 | 33 if(pix) { |
nuclear@0 | 34 memcpy(pixels, pix, xsz * ysz * sizeof *pixels); |
nuclear@0 | 35 } |
nuclear@0 | 36 } |
nuclear@0 | 37 |
nuclear@0 | 38 bool Image::load(const char *fname) |
nuclear@0 | 39 { |
nuclear@0 | 40 int xsz, ysz; |
nuclear@0 | 41 Color *img = (Color*)img_load_pixels(fname, &xsz, &ysz, IMG_FMT_RGBF); |
nuclear@0 | 42 if(!img) { |
nuclear@0 | 43 return false; |
nuclear@0 | 44 } |
nuclear@0 | 45 |
nuclear@0 | 46 /* convert the pixels to linear color space */ |
nuclear@0 | 47 for(int i=0; i<xsz*ysz; i++) { |
nuclear@0 | 48 img[i].x = pow(img[i].x, 2.2); |
nuclear@0 | 49 img[i].y = pow(img[i].y, 2.2); |
nuclear@0 | 50 img[i].z = pow(img[i].z, 2.2); |
nuclear@0 | 51 } |
nuclear@0 | 52 |
nuclear@0 | 53 set_pixels(xsz, ysz, img); |
nuclear@0 | 54 img_free_pixels(img); |
nuclear@0 | 55 return true; |
nuclear@0 | 56 } |
nuclear@0 | 57 |
nuclear@0 | 58 |
nuclear@0 | 59 bool Image::save(const char *fname) const |
nuclear@0 | 60 { |
nuclear@0 | 61 if(!pixels) { |
nuclear@0 | 62 return false; |
nuclear@0 | 63 } |
nuclear@0 | 64 |
nuclear@0 | 65 if(img_save_pixels(fname, pixels, xsz, ysz, IMG_FMT_RGBAF) == -1) { |
nuclear@0 | 66 return false; |
nuclear@0 | 67 } |
nuclear@0 | 68 return true; |
nuclear@0 | 69 } |