refactored some stuff made some typedefs
This commit is contained in:
parent
3867fa0e1b
commit
fee9865553
3 changed files with 31 additions and 25 deletions
|
@ -97,18 +97,18 @@ namespace bmp {
|
|||
{};
|
||||
|
||||
template <typename P = pixel_formats::bgr, typename CT = default_color_table<P>>
|
||||
struct bitmap_stream {
|
||||
struct ostream {
|
||||
typedef P pixel;
|
||||
typedef CT color_table;
|
||||
|
||||
bitmap_stream() = delete;
|
||||
bitmap_stream(bitmap_stream const &) = delete;
|
||||
bitmap_stream & operator=(bitmap_stream const &) = delete;
|
||||
ostream() = delete;
|
||||
ostream(ostream const &) = delete;
|
||||
ostream & operator=(ostream const &) = delete;
|
||||
|
||||
// TODO: make this template on class level?
|
||||
// You can't use them in a ctor without template argument deduction...
|
||||
template <typename DIBT = bitmapcoreheader>
|
||||
bitmap_stream(uint16_t width, uint16_t height, std::string filename)
|
||||
ostream(uint16_t width, uint16_t height, std::string filename)
|
||||
: file(filename.c_str())
|
||||
, width(width)
|
||||
, height(height)
|
||||
|
@ -126,7 +126,7 @@ namespace bmp {
|
|||
ct.write(file);
|
||||
}
|
||||
|
||||
bitmap_stream& operator<<(pixel const & p){
|
||||
ostream& operator<<(pixel const & p){
|
||||
if (y >= height) throw std::out_of_range("Writing BMP image out of bounds.");
|
||||
|
||||
file.write((char const *)&p, sizeof(pixel));
|
||||
|
@ -149,6 +149,9 @@ namespace bmp {
|
|||
uint16_t x;
|
||||
uint16_t y;
|
||||
};
|
||||
|
||||
typedef ostream<> colored_ostream;
|
||||
typedef ostream<pixel_formats::gray> gray_ostream;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include <algorithm>
|
||||
|
||||
template <typename ImageType>
|
||||
void test(std::string filename){
|
||||
void xor_color(std::string filename){
|
||||
size_t size = 512;
|
||||
ImageType image(size, size, filename);
|
||||
|
||||
|
@ -29,7 +29,7 @@ void test(std::string filename){
|
|||
}
|
||||
|
||||
template <typename ImageType>
|
||||
void test2(std::string filename){
|
||||
void xor_grad(std::string filename){
|
||||
size_t size = 256;
|
||||
ImageType image(size, size, filename);
|
||||
|
||||
|
@ -48,7 +48,7 @@ inline double nice_rand(){
|
|||
}
|
||||
|
||||
template <typename ImageType>
|
||||
void test3(std::string filename){
|
||||
void noise(std::string filename){
|
||||
size_t size = 256;
|
||||
|
||||
ImageType image(size, size, filename);
|
||||
|
@ -58,7 +58,7 @@ void test3(std::string filename){
|
|||
}
|
||||
|
||||
template <typename ImageType>
|
||||
void test4(std::string filename){
|
||||
void automata(std::string filename){
|
||||
size_t width = 1024;
|
||||
size_t height = 768;
|
||||
|
||||
|
@ -79,16 +79,16 @@ void test4(std::string filename){
|
|||
}
|
||||
|
||||
int main(int argc, const char * argv[]){
|
||||
test<png::png_stream<>>("test.png");
|
||||
test<bmp::bitmap_stream<>>("test.bmp");
|
||||
xor_color<png::colored_ostream>("xor_color.png");
|
||||
xor_color<bmp::colored_ostream>("xor_color.bmp");
|
||||
|
||||
test2<png::png_stream<pixel_formats::gray>>("test_gray.png");
|
||||
test2<bmp::bitmap_stream<pixel_formats::gray>>("test_gray.bmp");
|
||||
xor_grad<png::gray_ostream>("xor_grad.png");
|
||||
xor_grad<bmp::gray_ostream>("xor_grad.bmp");
|
||||
|
||||
test3<png::png_stream<pixel_formats::gray>>("test_3.png");
|
||||
test3<bmp::bitmap_stream<pixel_formats::gray>>("test_3.bmp");
|
||||
noise<png::gray_ostream>("noise.png");
|
||||
noise<bmp::gray_ostream>("noise.bmp");
|
||||
|
||||
test4<png::png_stream<pixel_formats::gray>>("test_4.png");
|
||||
test4<bmp::bitmap_stream<pixel_formats::gray>>("test_4.bmp");
|
||||
automata<png::gray_ostream>("automata.png");
|
||||
automata<bmp::gray_ostream>("automata.bmp");
|
||||
}
|
||||
|
||||
|
|
|
@ -29,14 +29,14 @@ namespace png{
|
|||
}
|
||||
|
||||
template <typename P = pixel_formats::rgb>
|
||||
struct png_stream{
|
||||
struct ostream{
|
||||
typedef P pixel;
|
||||
|
||||
png_stream() = delete;
|
||||
png_stream(png_stream const &) = delete;
|
||||
png_stream & operator=(png_stream const &) = delete;
|
||||
ostream() = delete;
|
||||
ostream(ostream const &) = delete;
|
||||
ostream & operator=(ostream const &) = delete;
|
||||
|
||||
png_stream(uint32_t width, uint32_t height, std::string filename)
|
||||
ostream(uint32_t width, uint32_t height, std::string filename)
|
||||
: fp(0)
|
||||
, png_ptr(0)
|
||||
, info_ptr(0)
|
||||
|
@ -61,14 +61,14 @@ namespace png{
|
|||
png_write_info(png_ptr, info_ptr);
|
||||
}
|
||||
|
||||
~png_stream(){
|
||||
~ostream(){
|
||||
// NOTE: the pnglib already checks for us whether all pixels are written
|
||||
png_write_end(png_ptr, info_ptr);
|
||||
png_destroy_info_struct(png_ptr, &info_ptr);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
png_stream& operator<<(pixel const & p){
|
||||
ostream& operator<<(pixel const & p){
|
||||
row[x] = p;
|
||||
++x;
|
||||
if(x >= row.size()){
|
||||
|
@ -87,6 +87,9 @@ namespace png{
|
|||
std::vector<pixel> row;
|
||||
uint32_t x;
|
||||
};
|
||||
|
||||
typedef ostream<> colored_ostream;
|
||||
typedef ostream<pixel_formats::gray> gray_ostream;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Reference in a new issue