png++: require_color_space.hpp Source File

png++ 0.2.9

- Main Page
- Namespaces
- Classes
- Files

- File List

require_color_space.hpp
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2007,2008 Alex Shulgin
3 *
4 * This file is part of png++ the C++ wrapper for libpng. PNG++ is free
5 * software; the exact copying conditions are as follows:
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * 3. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
23 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
25 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31 #ifndef PNGPP_REQUIRE_COLOR_SPACE_HPP_INCLUDED
32 #define PNGPP_REQUIRE_COLOR_SPACE_HPP_INCLUDED
33
34 #include "error.hpp"
35 #include "rgb_pixel.hpp"
36 #include "rgba_pixel.hpp"
37 #include "gray_pixel.hpp"
38 #include "ga_pixel.hpp"
39 #include "index_pixel.hpp"
40 #include "io_base.hpp"
41
42 namespace png
43 {
44
45 namespace detail
46 {
47
48 template< typename pixel >
49 struct wrong_color_space
50 {
51 inline static char const* error_msg();
52 };
53
54 template<> inline char const*
55 wrong_color_space< rgb_pixel >::error_msg()
56 {
57 return "8-bit RGB color space required";
58 }
59
60 template<> inline char const*
61 wrong_color_space< rgb_pixel_16 >::error_msg()
62 {
63 return "16-bit RGB color space required";
64 }
65
66 template<> inline char const*
67 wrong_color_space< rgba_pixel >::error_msg()
68 {
69 return "8-bit RGBA color space required";
70 }
71
72 template<> inline char const*
73 wrong_color_space< rgba_pixel_16 >::error_msg()
74 {
75 return "16-bit RGBA color space required";
76 }
77
78 template<> inline char const*
79 wrong_color_space< gray_pixel >::error_msg()
80 {
81 return "8-bit Grayscale color space required";
82 }
83
84 template<> inline char const*
85 wrong_color_space< gray_pixel_1 >::error_msg()
86 {
87 return "1-bit Grayscale color space required";
88 }
89
90 template<> inline char const*
91 wrong_color_space< gray_pixel_2 >::error_msg()
92 {
93 return "2-bit Grayscale color space required";
94 }
95
96 template<> inline char const*
97 wrong_color_space< gray_pixel_4 >::error_msg()
98 {
99 return "4-bit Grayscale color space required";
100 }
101
102 template<> inline char const*
103 wrong_color_space< gray_pixel_16 >::error_msg()
104 {
105 return "16-bit Grayscale color space required";
106 }
107
108 template<> inline char const*
109 wrong_color_space< ga_pixel >::error_msg()
110 {
111 return "8-bit Gray+Alpha color space required";
112 }
113
114 template<> inline char const*
115 wrong_color_space< ga_pixel_16 >::error_msg()
116 {
117 return "16-bit Gray+Alpha color space required";
118 }
119
120 template<> inline char const*
121 wrong_color_space< index_pixel >::error_msg()
122 {
123 return "8-bit Colormap color space required";
124 }
125
126 template<> inline char const*
127 wrong_color_space< index_pixel_1 >::error_msg()
128 {
129 return "1-bit Colormap color space required";
130 }
131
132 template<> inline char const*
133 wrong_color_space< index_pixel_2 >::error_msg()
134 {
135 return "2-bit Colormap color space required";
136 }
137
138 template<> inline char const*
139 wrong_color_space< index_pixel_4 >::error_msg()
140 {
141 return "4-bit Colormap color space required";
142 }
143
144 } // namespace detail
145
154 template< typename pixel >
155 struct require_color_space
156 {
157 typedef pixel_traits< pixel > traits;
158
159 void operator()(io_base& io) const
160 {
161 if (io.get_color_type() != traits::get_color_type()
162 || io.get_bit_depth() != traits::get_bit_depth())
163 {
164 throw error(detail::wrong_color_space< pixel >::error_msg());
165 }
166 }
167 };
168
169 } // namespace png
170
171 #endif // PNGPP_REQUIRE_COLOR_SPACE_HPP_INCLUDED
io_base.hpp
gray_pixel.hpp
png::io_base::get_bit_depth
int get_bit_depth() const
Definition: io_base.hpp:150
png::io_base
Base class for PNG reader/writer classes.
Definition: io_base.hpp:62
index_pixel.hpp
png::pixel_traits
Pixel traits class template.
Definition: pixel_traits.hpp:48
png::require_color_space::operator()
void operator()(io_base &io) const
Definition: require_color_space.hpp:159
png::io_base::get_color_type
color_type get_color_type() const
Definition: io_base.hpp:140
png::require_color_space::traits
pixel_traits< pixel > traits
Definition: require_color_space.hpp:157
rgb_pixel.hpp
png::detail::wrong_color_space::error_msg
static char const * error_msg()
png::require_color_space
IO transformation class template. Enforces image color space.
Definition: require_color_space.hpp:155
error.hpp
rgba_pixel.hpp
png
Definition: color.hpp:36
png::detail::wrong_color_space
Definition: require_color_space.hpp:49
ga_pixel.hpp
png::error
Exception class to represent runtime errors related to png++ operation.
Definition: error.hpp:57