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