claw
1.9.0
Toggle main menu visibility
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
*/
30
#include <
claw/graphic/targa.hpp
>
31
32
#include <
claw/exception.hpp
>
33
34
//********************** targa::writer::file_output_buffer
35
//*********************
36
37
namespace
claw
38
{
39
namespace
graphic
40
{
48
template
<>
49
void
targa::writer::file_output_buffer
<
50
claw::graphic::rgba_pixel_8
>
::order_pixel_bytes
(
const
pixel_type
& p)
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
65
claw::graphic::targa::writer::writer
(
const
image
& img)
66
: m_image(img)
67
{}
68
75
claw::graphic::targa::writer::writer
(
const
image
& img, std::ostream& f,
76
bool
rle)
77
: m_image(img)
78
{
79
save
(f, rle);
80
}
81
87
void
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
111
void
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
123
void
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
}
claw::graphic::image::image
image()
Constructor. Creates an image without datas.
Definition
image.cpp:95
claw::graphic::image::const_iterator
base_iterator< const image, const pixel_type > const_iterator
The type of the iterator to access constant pixels.
Definition
image.hpp:203
claw::graphic::targa::file_structure::footer
Footer of a targa file.
Definition
targa.hpp:150
claw::graphic::targa::file_structure::header
Header of a targa file.
Definition
targa.hpp:77
claw::graphic::targa::file_structure::header::image_type
char image_type
Image type.
Definition
targa.hpp:88
claw::graphic::targa::writer::file_output_buffer
The type of the output buffer associated with the file when encoding RLE data.
Definition
targa.hpp:402
claw::graphic::targa::writer::file_output_buffer::pixel_type
Pixel pixel_type
The type of the pixels in the input buffer.
Definition
targa.hpp:405
claw::graphic::targa::writer::file_output_buffer::order_pixel_bytes
void order_pixel_bytes(const pixel_type &p)
Write a pixel in the stream and set its value in the good order.
claw::graphic::targa::writer::save
void save(std::ostream &f, bool rle) const
Save the content of the image in a stream.
Definition
targa_writer.cpp:87
claw::graphic::targa::writer::writer
writer(const image &img)
Constructor.
Definition
targa_writer.cpp:65
exception.hpp
A simple class to use as exception with string message.
claw::graphic
Everything about image structures and processing.
Definition
claw.hpp:58
claw::graphic::rgba_pixel_8
rgba_pixel rgba_pixel_8
A color with 8 bits per component and an alpha channel.
Definition
pixel.hpp:126
claw
This is the main namespace.
Definition
application.hpp:50
targa.hpp
A class for targa pictures.
lib
graphic
src
claw
graphic
targa_writer.cpp
Generated by
1.17.0