51 u_int_8 cnt = 0xC0 | (u_int_8)n;
52 m_stream.write(
reinterpret_cast<char*
>(&cnt),
sizeof(u_int_8));
55 m_stream.write(
reinterpret_cast<char*
>(&
pattern),
sizeof(u_int_8));
101 const unsigned int bytes_per_line = m_image.width() + m_image.width() % 2;
103 write_header(os, bytes_per_line);
104 save_rle_true_color(os, bytes_per_line);
112void claw::graphic::pcx::writer::write_header(
113 std::ostream& os,
unsigned int bytes_per_line)
const
123 h.window.x_max = m_image.width() - 1;
124 h.window.y_max = m_image.height() - 1;
125 h.horizontal_dpi = 72;
127 std::fill(h.color_map, h.color_map + 16,
rgb_pixel_8(0, 0, 0));
130 h.bytes_per_line = bytes_per_line;
132 h.screen_size.horizontal = 0;
133 h.screen_size.vertical = 0;
134 std::fill(h.filler, h.filler + 54, 0);
136 os.write(
reinterpret_cast<char*
>(&h),
sizeof(header));
144void claw::graphic::pcx::writer::save_rle_true_color(
145 std::ostream& os,
unsigned int bytes_per_line)
const
147 std::vector<u_int_8> data(bytes_per_line, 0);
149 rle_pcx_encoder encoder;
150 file_output_buffer output(os);
152 for(
unsigned int y = 0; y != m_image.height(); ++y)
155 for(
unsigned int x = 0; x != m_image.width(); ++x)
156 data[x] = m_image[y][x].components.red;
158 encoder.encode(data.begin(), data.end(), output);
161 for(
unsigned int x = 0; x != m_image.width(); ++x)
162 data[x] = m_image[y][x].components.green;
164 encoder.encode(data.begin(), data.end(), output);
167 for(
unsigned int x = 0; x != m_image.width(); ++x)
168 data[x] = m_image[y][x].components.blue;
170 encoder.encode(data.begin(), data.end(), output);
image()
Constructor. Creates an image without datas.
unsigned int max_encodable() const
Get the maximum number of pixel a code can encode.
void encode(unsigned int n, pattern_type pattern)
Encode a pixel data.
unsigned int min_interesting() const
Get the minimum number of pixels needed for encoding.
file_output_buffer(std::ostream &os)
Constructor.
u_int_8 pattern_type
The typ of the output patterns.
void save(std::ostream &os) const
Save the content of the image in a stream.
writer(const image &img)
Constructor.
rgb_pixel rgb_pixel_8
A color with 8 bits per component.
Here are the design patterns.
A class for pcx pictures.