39 template<
typename Pixel >
40 claw::graphic::targa::reader::file_input_buffer<Pixel>::file_input_buffer
42 : buffered_istream<std::istream>(f)
61 template<
typename Pixel >
62 claw::graphic::targa::reader::mapped_file_input_buffer<Pixel>::
63 mapped_file_input_buffer
64 ( std::istream& f,
const color_palette32& p )
65 : buffered_istream<std::istream>(f), m_palette(p)
85 template<
typename InputBuffer>
86 claw::graphic::targa::reader::rle_targa_output_buffer<InputBuffer>::
87 rle_targa_output_buffer( image& img,
bool up_down,
bool left_right )
88 : m_image(img), m_x_inc(left_right ? 1 : -1), m_y_inc(up_down ? 1 : -1)
93 m_y = m_image.height() - 1;
98 m_x = m_image.width() - 1;
107 template<
typename InputBuffer>
108 void claw::graphic::targa::reader::rle_targa_output_buffer<InputBuffer>::fill
111 assert( (
int)(m_x + m_x_inc * n) >= -1 );
112 assert( m_x + m_x_inc * n <= m_image.width() );
114 const int bound = (int)m_x + m_x_inc * n;
117 for ( ; x != bound; x += m_x_inc )
118 m_image[m_y][x] = pattern;
129 template<
typename InputBuffer>
130 void claw::graphic::targa::reader::rle_targa_output_buffer<InputBuffer>::copy
131 (
unsigned int n, input_buffer_type& buffer )
133 assert( (
int)(m_x + m_x_inc * n) >= -1 );
134 assert( m_x + m_x_inc * n <= m_image.width() );
136 const int bound = (int)m_x + m_x_inc * n;
139 for ( ; x != bound; x += m_x_inc )
140 m_image[m_y][x] = buffer.get_pixel();
149 template<
typename InputBuffer>
150 bool claw::graphic::targa::reader::rle_targa_output_buffer<InputBuffer>::
153 return ( (
int)m_y == -1 ) || ( m_y == m_image.height() );
165 template<
typename InputBuffer>
167 claw::graphic::targa::reader::rle_targa_output_buffer<InputBuffer>::
168 adjust_position(
int x)
172 m_x = m_image.width() - 1;
175 else if (x >= (
int)m_image.width())
196 template<
typename InputBuffer,
typename OutputBuffer >
198 claw::graphic::targa::reader::rle_targa_decoder<InputBuffer, OutputBuffer>::
199 read_mode( input_buffer_type& input, output_buffer_type& output )
201 this->m_mode = this->stop;
202 bool ok = !output.completed();
204 if ( ok && (input.remaining() < 1) )
205 ok = input.read_more(1);
209 char key = input.get_next();
211 this->m_count = (key & 0x7F) + 1;
215 this->m_mode = this->compressed;
216 this->m_pattern = input.get_pixel();
219 this->m_mode = this->raw;
236 template<
typename Pixel>
237 void claw::graphic::targa::reader::load_color_mapped_raw
238 (
const header& h, std::istream& f,
const color_palette32& palette )
243 typedef mapped_file_input_buffer<Pixel> input_buffer_type;
245 rle_targa_output_buffer<input_buffer_type> output
246 ( m_image, h.image_specification.up_down_oriented(),
247 h.image_specification.left_right_oriented() );
248 input_buffer_type input(f, palette);
250 for (
unsigned int i=0; i!=m_image.height(); ++i )
251 output.copy( m_image.width(), input );
262 template<
typename Decoder>
263 void claw::graphic::targa::reader::decompress_rle_color_mapped
264 (
const header& h, std::istream& f,
const color_palette32& palette )
267 typename Decoder::output_buffer_type output_buffer
268 (m_image, h.image_specification.up_down_oriented(),
269 h.image_specification.left_right_oriented() );
270 typename Decoder::input_buffer_type input_buffer(f, palette);
272 decoder.decode(input_buffer, output_buffer);
282 template<
typename Pixel>
283 void claw::graphic::targa::reader::load_true_color_raw
284 (
const header& h, std::istream& f )
286 assert(!h.color_map);
291 typedef file_input_buffer<Pixel> input_buffer_type;
293 rle_targa_output_buffer<input_buffer_type> output
294 ( m_image, h.image_specification.up_down_oriented(),
295 h.image_specification.left_right_oriented() );
296 input_buffer_type input(f);
298 for (
unsigned int i=0; i!=m_image.height(); ++i )
299 output.copy( m_image.width(), input );
309 template<
typename Decoder>
310 void claw::graphic::targa::reader::decompress_rle_true_color
311 (
const header& h, std::istream& f )
313 assert(!h.color_map);
316 typename Decoder::output_buffer_type output_buffer
317 (m_image, h.image_specification.up_down_oriented(),
318 h.image_specification.left_right_oriented() );
319 typename Decoder::input_buffer_type input_buffer(f);
321 decoder.decode(input_buffer, output_buffer);
330 template<
typename Pixel>
331 void claw::graphic::targa::reader::load_palette_content
332 ( std::istream& f, color_palette32& palette )
const
334 file_input_buffer<Pixel> input(f);
336 for (
unsigned int i=0; i!=palette.size(); ++i)
337 palette[i] = input.get_pixel();