53 if ( (pattern > 63) || (n > 1) )
55 u_int_8 cnt = 0xC0 | (
u_int_8)n;
56 m_stream.write( reinterpret_cast<char*>(&cnt),
sizeof(u_int_8) );
59 m_stream.write( reinterpret_cast<char*>(&pattern),
sizeof(u_int_8));
115 const unsigned int bytes_per_line = m_image.width() + m_image.width() % 2;
117 write_header(os, bytes_per_line);
118 save_rle_true_color(os, bytes_per_line);
127 void claw::graphic::pcx::writer::write_header
128 ( std::ostream& os,
unsigned int bytes_per_line )
const
138 h.window.x_max = m_image.width() - 1;
139 h.window.y_max = m_image.height() - 1;
140 h.horizontal_dpi = 72;
142 std::fill( h.color_map, h.color_map+16,
rgb_pixel_8(0, 0, 0) );
145 h.bytes_per_line = bytes_per_line;
147 h.screen_size.horizontal = 0;
148 h.screen_size.vertical = 0;
149 std::fill( h.filler, h.filler+54, 0 );
151 os.write( reinterpret_cast<char*>(&h),
sizeof(header) );
160 void claw::graphic::pcx::writer::save_rle_true_color
161 ( std::ostream& os,
unsigned int bytes_per_line )
const
163 std::vector<u_int_8> data(bytes_per_line, 0);
165 rle_pcx_encoder encoder;
166 file_output_buffer output(os);
168 for (
unsigned int y=0; y!=m_image.height(); ++y)
171 for (
unsigned int x=0; x!=m_image.width(); ++x)
172 data[x] = m_image[y][x].components.red;
174 encoder.encode( data.begin(), data.end(), output );
177 for (
unsigned int x=0; x!=m_image.width(); ++x)
178 data[x] = m_image[y][x].components.green;
180 encoder.encode( data.begin(), data.end(), output );
183 for (
unsigned int x=0; x!=m_image.width(); ++x)
184 data[x] = m_image[y][x].components.blue;
186 encoder.encode( data.begin(), data.end(), output );
writer(const image &img)
Constructor.
file_output_buffer(std::ostream &os)
Constructor.
unsigned int min_interesting() const
Get the minimum number of pixels needed for encoding.
unsigned_integer_of_size< 8 >::type u_int_8
An unsigned integer on 8 bits.
u_int_8 pattern_type
The typ of the output patterns.
A class for pcx pictures.
void encode(unsigned int n, pattern_type pattern)
Encode a pixel data.
void save(std::ostream &os) const
Save the content of the image in a stream.
unsigned int max_encodable() const
Get the maximum number of pixel a code can encode.
A class to deal with images.