png++  0.2.9
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 >
50  {
51  inline static char const* error_msg();
52  };
53 
54  template<> inline char const*
56  {
57  return "8-bit RGB color space required";
58  }
59 
60  template<> inline char const*
62  {
63  return "16-bit RGB color space required";
64  }
65 
66  template<> inline char const*
68  {
69  return "8-bit RGBA color space required";
70  }
71 
72  template<> inline char const*
74  {
75  return "16-bit RGBA color space required";
76  }
77 
78  template<> inline char const*
80  {
81  return "8-bit Grayscale color space required";
82  }
83 
84  template<> inline char const*
86  {
87  return "1-bit Grayscale color space required";
88  }
89 
90  template<> inline char const*
92  {
93  return "2-bit Grayscale color space required";
94  }
95 
96  template<> inline char const*
98  {
99  return "4-bit Grayscale color space required";
100  }
101 
102  template<> inline char const*
104  {
105  return "16-bit Grayscale color space required";
106  }
107 
108  template<> inline char const*
110  {
111  return "8-bit Gray+Alpha color space required";
112  }
113 
114  template<> inline char const*
116  {
117  return "16-bit Gray+Alpha color space required";
118  }
119 
120  template<> inline char const*
122  {
123  return "8-bit Colormap color space required";
124  }
125 
126  template<> inline char const*
128  {
129  return "1-bit Colormap color space required";
130  }
131 
132  template<> inline char const*
134  {
135  return "2-bit Colormap color space required";
136  }
137 
138  template<> inline char const*
140  {
141  return "4-bit Colormap color space required";
142  }
143 
144  } // namespace detail
145 
154  template< typename pixel >
156  {
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  {
165  }
166  }
167  };
168 
169 } // namespace png
170 
171 #endif // PNGPP_REQUIRE_COLOR_SPACE_HPP_INCLUDED
int get_bit_depth() const
Definition: io_base.hpp:150
Base class for PNG reader/writer classes.
Definition: io_base.hpp:62
Pixel traits class template.
Definition: pixel_traits.hpp:48
void operator()(io_base &io) const
Definition: require_color_space.hpp:159
color_type get_color_type() const
Definition: io_base.hpp:140
pixel_traits< pixel > traits
Definition: require_color_space.hpp:157
static char const * error_msg()
IO transformation class template. Enforces image color space.
Definition: require_color_space.hpp:155
Definition: color.hpp:36
Definition: require_color_space.hpp:49
Exception class to represent runtime errors related to png++ operation.
Definition: error.hpp:57