conworlds

diff src/image.cc @ 2:879194e4b1f0

fixed line-endings
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 25 Apr 2014 05:44:09 +0300
parents b326d53321f7
children
line diff
     1.1 --- a/src/image.cc	Fri Apr 25 05:43:26 2014 +0300
     1.2 +++ b/src/image.cc	Fri Apr 25 05:44:09 2014 +0300
     1.3 @@ -1,94 +1,94 @@
     1.4 -#include <string.h>
     1.5 -#include "imago2.h"
     1.6 -#include "image.h"
     1.7 -
     1.8 -Image::Image()
     1.9 -{
    1.10 -	pixels = 0;
    1.11 -	own_pixels = true;
    1.12 -	width = height = 0;
    1.13 -}
    1.14 -
    1.15 -Image::~Image()
    1.16 -{
    1.17 -	destroy();
    1.18 -}
    1.19 -
    1.20 -Image::Image(const Image &img)
    1.21 -{
    1.22 -	pixels = 0;
    1.23 -	own_pixels = false;
    1.24 -
    1.25 -	create(img.width, img.height, img.pixels);
    1.26 -}
    1.27 -
    1.28 -Image &Image::operator =(const Image &img)
    1.29 -{
    1.30 -	if(this != &img) {
    1.31 -		destroy();
    1.32 -		create(img.width, img.height, img.pixels);
    1.33 -	}
    1.34 -	return *this;
    1.35 -}
    1.36 -
    1.37 -void Image::create(int xsz, int ysz, unsigned char *pixels)
    1.38 -{
    1.39 -	destroy();
    1.40 -
    1.41 -	this->pixels = new unsigned char[xsz * ysz * 4];
    1.42 -	if(pixels) {
    1.43 -		memcpy(this->pixels, pixels, xsz * ysz * 4);
    1.44 -	} else {
    1.45 -		memset(this->pixels, 0, xsz * ysz * 4);
    1.46 -	}
    1.47 -	width = xsz;
    1.48 -	height = ysz;
    1.49 -	own_pixels = true;
    1.50 -}
    1.51 -
    1.52 -void Image::destroy()
    1.53 -{
    1.54 -	if(own_pixels) {
    1.55 -		delete [] pixels;
    1.56 -	}
    1.57 -	pixels = 0;
    1.58 -	width = height = 0;
    1.59 -	own_pixels = true;
    1.60 -}
    1.61 -
    1.62 -int Image::get_width() const
    1.63 -{
    1.64 -	return width;
    1.65 -}
    1.66 -
    1.67 -int Image::get_height() const
    1.68 -{
    1.69 -	return height;
    1.70 -}
    1.71 -
    1.72 -void Image::set_pixels(int xsz, int ysz, unsigned char *pixels)
    1.73 -{
    1.74 -	destroy();
    1.75 -
    1.76 -	this->pixels = pixels;
    1.77 -	width = xsz;
    1.78 -	height = ysz;
    1.79 -	own_pixels = false;
    1.80 -}
    1.81 -
    1.82 -unsigned char *Image::get_pixels() const
    1.83 -{
    1.84 -	return pixels;
    1.85 -}
    1.86 -
    1.87 -bool Image::load(const char *fname)
    1.88 -{
    1.89 -	int xsz, ysz;
    1.90 -	unsigned char *pix = (unsigned char*)img_load_pixels(fname, &xsz, &ysz);
    1.91 -	if(!pix) {
    1.92 -		return false;
    1.93 -	}
    1.94 -
    1.95 -	create(xsz, ysz, pix);
    1.96 -	return true;
    1.97 -}
    1.98 \ No newline at end of file
    1.99 +#include <string.h>
   1.100 +#include "imago2.h"
   1.101 +#include "image.h"
   1.102 +
   1.103 +Image::Image()
   1.104 +{
   1.105 +	pixels = 0;
   1.106 +	own_pixels = true;
   1.107 +	width = height = 0;
   1.108 +}
   1.109 +
   1.110 +Image::~Image()
   1.111 +{
   1.112 +	destroy();
   1.113 +}
   1.114 +
   1.115 +Image::Image(const Image &img)
   1.116 +{
   1.117 +	pixels = 0;
   1.118 +	own_pixels = false;
   1.119 +
   1.120 +	create(img.width, img.height, img.pixels);
   1.121 +}
   1.122 +
   1.123 +Image &Image::operator =(const Image &img)
   1.124 +{
   1.125 +	if(this != &img) {
   1.126 +		destroy();
   1.127 +		create(img.width, img.height, img.pixels);
   1.128 +	}
   1.129 +	return *this;
   1.130 +}
   1.131 +
   1.132 +void Image::create(int xsz, int ysz, unsigned char *pixels)
   1.133 +{
   1.134 +	destroy();
   1.135 +
   1.136 +	this->pixels = new unsigned char[xsz * ysz * 4];
   1.137 +	if(pixels) {
   1.138 +		memcpy(this->pixels, pixels, xsz * ysz * 4);
   1.139 +	} else {
   1.140 +		memset(this->pixels, 0, xsz * ysz * 4);
   1.141 +	}
   1.142 +	width = xsz;
   1.143 +	height = ysz;
   1.144 +	own_pixels = true;
   1.145 +}
   1.146 +
   1.147 +void Image::destroy()
   1.148 +{
   1.149 +	if(own_pixels) {
   1.150 +		delete [] pixels;
   1.151 +	}
   1.152 +	pixels = 0;
   1.153 +	width = height = 0;
   1.154 +	own_pixels = true;
   1.155 +}
   1.156 +
   1.157 +int Image::get_width() const
   1.158 +{
   1.159 +	return width;
   1.160 +}
   1.161 +
   1.162 +int Image::get_height() const
   1.163 +{
   1.164 +	return height;
   1.165 +}
   1.166 +
   1.167 +void Image::set_pixels(int xsz, int ysz, unsigned char *pixels)
   1.168 +{
   1.169 +	destroy();
   1.170 +
   1.171 +	this->pixels = pixels;
   1.172 +	width = xsz;
   1.173 +	height = ysz;
   1.174 +	own_pixels = false;
   1.175 +}
   1.176 +
   1.177 +unsigned char *Image::get_pixels() const
   1.178 +{
   1.179 +	return pixels;
   1.180 +}
   1.181 +
   1.182 +bool Image::load(const char *fname)
   1.183 +{
   1.184 +	int xsz, ysz;
   1.185 +	unsigned char *pix = (unsigned char*)img_load_pixels(fname, &xsz, &ysz);
   1.186 +	if(!pix) {
   1.187 +		return false;
   1.188 +	}
   1.189 +
   1.190 +	create(xsz, ysz, pix);
   1.191 +	return true;
   1.192 +}