63 f.write(
reinterpret_cast<char*
>(&h),
sizeof(
header));
72void claw::graphic::bitmap::writer::save_data(std::ostream& f)
const
75 unsigned int buffer_size = m_image.width() * 3;
78 if(buffer_size % 4 != 0)
79 buffer_size += 4 - buffer_size % 4;
81 char* buffer =
new char[buffer_size];
83 for(line = m_image.height(); line > 0;)
86 pixel32_to_pixel24(buffer, m_image[line]);
87 f.write(buffer, buffer_size);
98void claw::graphic::bitmap::writer::pixel32_to_pixel24(
99 char* dest,
const scanline& src)
const
101 unsigned int i24 = 0;
102 scanline::const_iterator
first(src.begin());
103 scanline::const_iterator last(src.end());
107 dest[i24++] =
first->components.blue;
108 dest[i24++] =
first->components.green;
109 dest[i24++] =
first->components.red;
117void claw::graphic::bitmap::writer::init_header(header& h)
const
119 unsigned int adjusted_line = m_image.width() * 3;
121 if(m_image.width() % 4 != 0)
122 adjusted_line += 4 - m_image.width() % 4;
127 h.file_size = adjusted_line * m_image.height() +
sizeof(h);
131 h.data_offset =
sizeof(h);
133 h.header_size = 0x28;
135 h.width = m_image.width();
136 h.height = m_image.height();
139 h.compression = BMP_COMPRESSION_RGB;
140 h.image_size = adjusted_line * m_image.height();
144 h.importants_colors = 0;
A class for bitmap pictures.
Fuction object to get the first element of a std::pair.
writer(const image &img)
Constructor.
void save(std::ostream &f) const
Save the bitmap in a file.
image()
Constructor. Creates an image without datas.