diff --git a/ImageStreams/bmp.hpp b/ImageStreams/bmp.hpp index 6708743..1f49a54 100644 --- a/ImageStreams/bmp.hpp +++ b/ImageStreams/bmp.hpp @@ -97,18 +97,18 @@ namespace bmp { {}; template > - 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 - 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 gray_ostream; } #endif diff --git a/ImageStreams/main.cpp b/ImageStreams/main.cpp index ab2a082..cb0aafa 100644 --- a/ImageStreams/main.cpp +++ b/ImageStreams/main.cpp @@ -17,7 +17,7 @@ #include template -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 -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 -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 -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>("test.png"); - test>("test.bmp"); + xor_color("xor_color.png"); + xor_color("xor_color.bmp"); - test2>("test_gray.png"); - test2>("test_gray.bmp"); + xor_grad("xor_grad.png"); + xor_grad("xor_grad.bmp"); - test3>("test_3.png"); - test3>("test_3.bmp"); + noise("noise.png"); + noise("noise.bmp"); - test4>("test_4.png"); - test4>("test_4.bmp"); + automata("automata.png"); + automata("automata.bmp"); } diff --git a/ImageStreams/png.hpp b/ImageStreams/png.hpp index df407a3..bb5f904 100644 --- a/ImageStreams/png.hpp +++ b/ImageStreams/png.hpp @@ -29,14 +29,14 @@ namespace png{ } template - 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 row; uint32_t x; }; + + typedef ostream<> colored_ostream; + typedef ostream gray_ostream; } #endif