claw 1.9.0
 
Loading...
Searching...
No Matches
targa_writer.cpp
Go to the documentation of this file.
1/*
2 CLAW - a C++ Library Absolutely Wonderful
3
4 CLAW is a free library without any particular aim but being useful to
5 anyone.
6
7 Copyright (C) 2005-2011 Julien Jorge
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
23 contact: julien.jorge@stuff-o-matic.com
24*/
31
32#include <claw/exception.hpp>
33
34//********************** targa::writer::file_output_buffer
35//*********************
36
37namespace claw
38{
39 namespace graphic
40 {
48 template <>
51 {
52 m_stream << p.components.blue << p.components.green << p.components.red
53 << p.components.alpha;
54 }
55 }
56}
57
58//************************** targa::writer::writer
59//*****************************
60
66 : m_image(img)
67{}
68
75claw::graphic::targa::writer::writer(const image& img, std::ostream& f,
76 bool rle)
77 : m_image(img)
78{
79 save(f, rle);
80}
81
87void claw::graphic::targa::writer::save(std::ostream& os, bool rle) const
88{
89 header h(m_image.width(), m_image.height());
90
91 if(rle)
92 h.image_type = rle_true_color;
93 else
94 h.image_type = true_color;
95
96 os.write(reinterpret_cast<char*>(&h), sizeof(header));
97
98 if(rle)
99 save_rle_true_color(os);
100 else
101 save_true_color(os);
102
103 footer f;
104 os.write(reinterpret_cast<char*>(&f), sizeof(footer));
105}
106
111void claw::graphic::targa::writer::save_true_color(std::ostream& os) const
112{
113 file_output_buffer<rgba_pixel_8> output_buffer(os);
114
115 for(const_iterator it = m_image.begin(); it != m_image.end(); ++it)
116 output_buffer.order_pixel_bytes(*it);
117}
118
123void claw::graphic::targa::writer::save_rle_true_color(std::ostream& os) const
124{
125 rle32_encoder encoder;
126 rle32_encoder::output_buffer_type output_buffer(os);
127
128 for(unsigned int y = 0; y != m_image.height(); ++y)
129 encoder.encode(m_image[y].begin(), m_image[y].end(), output_buffer);
130}
image()
Constructor. Creates an image without datas.
Definition image.cpp:95
base_iterator< const image, const pixel_type > const_iterator
The type of the iterator to access constant pixels.
Definition image.hpp:203
The type of the output buffer associated with the file when encoding RLE data.
Definition targa.hpp:402
Pixel pixel_type
The type of the pixels in the input buffer.
Definition targa.hpp:405
void order_pixel_bytes(const pixel_type &p)
Write a pixel in the stream and set its value in the good order.
void save(std::ostream &f, bool rle) const
Save the content of the image in a stream.
writer(const image &img)
Constructor.
A simple class to use as exception with string message.
Everything about image structures and processing.
Definition claw.hpp:58
rgba_pixel rgba_pixel_8
A color with 8 bits per component and an alpha channel.
Definition pixel.hpp:126
This is the main namespace.
A class for targa pictures.