The prototype of Zen Zoom. Made on ubuntu, I guess.
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.
 
 
 
 

75 lines
1.4 KiB

#ifndef BMP_H
#define BMP_H
#include <iostream>
#include <algorithm>
#include <iterator>
namespace bmp {
struct bitmap_file_header {
uint32_t filesize;
uint16_t creator1;
uint16_t creator2;
uint32_t bmp_offset;
template <typename DIBT>
bitmap_file_header(DIBT dib_header):
filesize(dib_header.bytes() + dib_header.header_sz + 12 + 2),
creator1(0),
creator2(0),
bmp_offset(dib_header.header_sz + 12 + 2){}
void write(std::ostream& out) const {
out << "BM";
out.write(reinterpret_cast<const char*>(this), 12);
}
};
struct bitmapcoreheader {
uint32_t header_sz;
uint16_t width;
uint16_t height;
uint16_t nplanes;
uint16_t bitspp;
bitmapcoreheader(int width, int height):
header_sz(sizeof(bitmapcoreheader)),
width(width),
height(height),
nplanes(1),
bitspp(24){}
void write(std::ostream& out) const {
out.write(reinterpret_cast<const char*>(this), header_sz);
}
unsigned int bytes(){
return width*height*bitspp/8;
}
};
template <typename T, typename DIBT = bitmapcoreheader>
struct bitmap {
DIBT dib_header;
bitmap_file_header header;
T const * data;
bitmap(int width, int height):
dib_header(width, height),
header(dib_header),
data(0) {
}
void write(std::ostream& out){
header.write(out);
dib_header.write(out);
std::copy_n((char const *)data, dib_header.bytes(), std::ostream_iterator<char>(out));
}
};
}
#endif // BMP_H