claw
1.9.0
Toggle main menu visibility
Loading...
Searching...
No Matches
png.hpp
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
#ifndef __CLAW_PNG_HPP__
31
#define __CLAW_PNG_HPP__
32
33
#include <
claw/graphic/image.hpp
>
34
35
#include <iostream>
36
#include <png.h>
37
#include <setjmp.h>
38
#include <string>
39
#include <zlib.h>
40
41
namespace
claw
42
{
43
namespace
graphic
44
{
49
class
png
:
public
image
50
{
51
public
:
56
class
reader
57
{
58
// classes that need to be accessible from png callbacks.
59
public
:
64
struct
source_manager
65
{
66
public
:
67
source_manager
(std::istream& is);
68
69
void
read
(png_bytep data, png_size_t length);
70
71
private
:
73
std::istream& m_input;
74
75
};
// struct source_manager
76
77
public
:
78
reader
(
image
& img);
79
reader
(
image
& img, std::istream& f);
80
81
void
load
(std::istream& f);
82
83
private
:
84
void
read_from_file(std::istream& f);
85
void
check_if_png(png_structp png_ptr, std::istream& f)
const
;
86
87
void
read_image(png_structp png_ptr, png_infop info_ptr);
88
void
read_sequential_image(png_structp png_ptr, png_infop info_ptr);
89
void
read_interlaced_image(png_structp png_ptr, png_infop info_ptr,
90
unsigned
int
passes);
91
92
void
copy_pixel_line(png_byte color_type, png_bytep data,
93
unsigned
int
y);
94
95
void
create_read_structures(png_structp& png_ptr,
96
png_infop& info_ptr)
const
;
97
98
private
:
100
image
& m_image;
101
104
static
const
unsigned
int
s_rgba_pixel_size;
105
106
};
// class reader
107
112
class
writer
113
{
114
public
:
118
struct
options
119
{
120
public
:
122
enum
compression_level
123
{
124
no_compression = Z_NO_COMPRESSION,
125
best_speed = Z_BEST_SPEED,
126
best_compression = Z_BEST_COMPRESSION,
127
default_compression = Z_DEFAULT_COMPRESSION
128
};
// enum compression_level
129
131
enum
interlace_type
132
{
134
none
= PNG_INTERLACE_NONE,
135
138
adam7
= PNG_INTERLACE_ADAM7
139
};
// enum interlace_type
140
141
public
:
142
options
();
143
options
(
compression_level
compression_level_,
144
interlace_type
interlace_);
145
146
public
:
148
compression_level
compression
;
149
151
interlace_type
interlace
;
152
153
};
// struct options
154
155
// classes that need to be accessible from png callbacks.
156
161
struct
target_manager
162
{
163
public
:
164
target_manager
(std::ostream& os);
165
166
void
write
(png_bytep data, png_size_t length);
167
void
flush
();
168
169
private
:
171
std::ostream& m_output;
172
173
};
// struct target_manager
174
175
public
:
176
writer
(
const
image
& img);
177
writer
(
const
image
& img, std::ostream& f,
178
const
options
& opt =
options
());
179
180
void
save
(std::ostream& f,
const
options
& opt =
options
())
const
;
181
182
private
:
183
void
set_options(png_structp png_ptr, png_infop info_ptr,
184
const
options
& opt)
const
;
185
void
save_image(png_structp png_ptr, png_infop info_ptr)
const
;
186
187
void
copy_pixel_line(png_bytep data,
unsigned
int
y)
const
;
188
189
void
create_write_structures(png_structp& png_ptr,
190
png_infop& info_ptr)
const
;
191
192
private
:
194
const
image
& m_image;
195
198
static
const
unsigned
int
s_rgba_pixel_size;
199
200
};
// class writer
201
202
public
:
203
png
(
unsigned
int
w,
unsigned
int
h);
204
png
(
const
image
& that);
205
png
(std::istream& f);
206
207
void
save
(std::ostream& os,
208
const
writer::options
& opt =
writer::options
())
const
;
209
210
};
// class png
211
}
212
}
213
214
#endif
// __CLAW_PNG_HPP__
claw::graphic::image::image
image()
Constructor. Creates an image without datas.
Definition
image.cpp:95
claw::graphic::png::reader::load
void load(std::istream &f)
Load an image from a png file.
Definition
png_reader.cpp:100
claw::graphic::png::reader::reader
reader(image &img)
Constructor.
Definition
png_reader.cpp:80
claw::graphic::png::writer::save
void save(std::ostream &f, const options &opt=options()) const
Save the image in a PNG file.
Definition
png_writer.cpp:139
claw::graphic::png::writer::writer
writer(const image &img)
Constructor.
Definition
png_writer.cpp:117
claw::graphic::png::png
png(unsigned int w, unsigned int h)
Constructor. Creates an empty image.
Definition
png.cpp:38
claw::graphic::png::save
void save(std::ostream &os, const writer::options &opt=writer::options()) const
Save the image.
Definition
png.cpp:64
image.hpp
A class to deal with images.
claw::graphic
Everything about image structures and processing.
Definition
claw.hpp:58
claw
This is the main namespace.
Definition
application.hpp:50
claw::graphic::png::reader::source_manager::read
void read(png_bytep data, png_size_t length)
Read data from the input stream.
Definition
png_reader.cpp:68
claw::graphic::png::reader::source_manager::source_manager
source_manager(std::istream &is)
Constructor.
Definition
png_reader.cpp:57
claw::graphic::png::writer::options
Parameters of the writing algorithm.
Definition
png.hpp:119
claw::graphic::png::writer::options::compression
compression_level compression
Compression level to use in the saved stream.
Definition
png.hpp:148
claw::graphic::png::writer::options::interlace
interlace_type interlace
Interlace method to apply to the saved image.
Definition
png.hpp:151
claw::graphic::png::writer::options::interlace_type
interlace_type
The algorithm to use to interlace the saved image.
Definition
png.hpp:132
claw::graphic::png::writer::options::none
@ none
Saved image won't be interaced.
Definition
png.hpp:134
claw::graphic::png::writer::options::adam7
@ adam7
Saved image will be interlaced using the Adam7 algorithm.
Definition
png.hpp:138
claw::graphic::png::writer::options::compression_level
compression_level
Compression level in the interlaced image.
Definition
png.hpp:123
claw::graphic::png::writer::options::options
options()
Default constructor.
Definition
png_writer.cpp:95
claw::graphic::png::writer::target_manager::flush
void flush()
Flush the output stream.
Definition
png_writer.cpp:87
claw::graphic::png::writer::target_manager::write
void write(png_bytep data, png_size_t length)
Write data in the ouput stream.
Definition
png_writer.cpp:78
claw::graphic::png::writer::target_manager::target_manager
target_manager(std::ostream &os)
Constructor.
Definition
png_writer.cpp:67
lib
graphic
include
claw
graphic
png.hpp
Generated by
1.17.0