My old project for strange attractors
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 

88 lines
1.4 KiB

//
// libpng.hpp
// AwesomeAttract0r
//
// Created by Joshua Moerman on 10/24/11.
// Copyright 2011 Vadovas. All rights reserved.
//
#ifndef AwesomeAttract0r_libpng_hpp
#define AwesomeAttract0r_libpng_hpp
#ifndef __APPLE__
#include <png++/png.hpp>
#else
#warning PNG++ is not yet supported (will save as bmp)
#include "bmp.hpp"
namespace png {
struct rgb_pixel{
char* data;
char red, green, blue;
rgb_pixel(char* d)
: data(d)
, red(0)
, green(0)
, blue(0)
{}
rgb_pixel(unsigned int r, unsigned int g, unsigned int b)
: data(0)
, red(r)
, green(g)
, blue(b)
{}
void operator=(rgb_pixel const & rh){
data[0] = rh.blue;
data[1] = rh.green;
data[2] = rh.red;
}
};
struct row{
char * data;
row(char* d)
: data(d)
{}
rgb_pixel operator[](unsigned int c){return rgb_pixel(data + c*3);}
};
template <typename T>
struct image{
bmp::bitmap<char> bitmap;
char * data;
unsigned int width;
unsigned int height;
image(unsigned int w, unsigned int h)
: bitmap(w, h)
, data(0)
, width(w)
, height(h)
{
data = new char[width*height*3];
bitmap.data = data;
}
~image(){
delete[] data;
}
row operator[](unsigned int r){return row(data + r*height*3);}
void write(std::string const & filename){
bitmap.write(filename);
}
private:
image(image const &);
image & operator=(image const &);
};
}
#endif
#endif