00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef PNGPP_REQUIRE_COLOR_SPACE_HPP_INCLUDED
00032 #define PNGPP_REQUIRE_COLOR_SPACE_HPP_INCLUDED
00033
00034 #include "error.hpp"
00035 #include "rgb_pixel.hpp"
00036 #include "rgba_pixel.hpp"
00037 #include "gray_pixel.hpp"
00038 #include "ga_pixel.hpp"
00039 #include "index_pixel.hpp"
00040 #include "io_base.hpp"
00041
00042 namespace png
00043 {
00044
00045 namespace
00046 {
00047
00048 template< typename pixel >
00049 struct wrong_color_space
00050 {
00051 static char const* error_msg;
00052 };
00053
00054 template<> char const* wrong_color_space< rgb_pixel >::error_msg =
00055 "RGB color space required";
00056
00057 template<> char const* wrong_color_space< rgb_pixel_16 >::error_msg =
00058 "16-bit RGB color space required";
00059
00060 template<> char const* wrong_color_space< rgba_pixel >::error_msg =
00061 "RGBA color space required";
00062
00063 template<> char const* wrong_color_space< rgba_pixel_16 >::error_msg =
00064 "16-bit RGBA color space required";
00065
00066 template<> char const* wrong_color_space< gray_pixel >::error_msg =
00067 "Grayscale color space required";
00068
00069 template<> char const* wrong_color_space< gray_pixel_1 >::error_msg =
00070 "1-bit Grayscale color space required";
00071
00072 template<> char const* wrong_color_space< gray_pixel_2 >::error_msg =
00073 "2-bit Grayscale color space required";
00074
00075 template<> char const* wrong_color_space< gray_pixel_4 >::error_msg =
00076 "4-bit Grayscale color space required";
00077
00078 template<> char const* wrong_color_space< gray_pixel_16 >::error_msg =
00079 "16-bit Grayscale color space required";
00080
00081 template<> char const* wrong_color_space< ga_pixel >::error_msg =
00082 "Gray+Alpha color space required";
00083
00084 template<> char const* wrong_color_space< ga_pixel_16 >::error_msg =
00085 "16-bit Gray+Alpha color space required";
00086
00087 template<> char const* wrong_color_space< index_pixel >::error_msg =
00088 "Colormap color space required";
00089
00090 template<> char const* wrong_color_space< index_pixel_1 >::error_msg =
00091 "1-bit Colormap color space required";
00092
00093 template<> char const* wrong_color_space< index_pixel_2 >::error_msg =
00094 "1-bit Colormap color space required";
00095
00096 template<> char const* wrong_color_space< index_pixel_4 >::error_msg =
00097 "1-bit Colormap color space required";
00098
00099 }
00100
00109 template< typename pixel >
00110 struct require_color_space
00111 {
00112 typedef pixel_traits< pixel > traits;
00113
00114 void operator()(io_base& io) const
00115 {
00116 if (io.get_color_type() != traits::get_color_type()
00117 || io.get_bit_depth() != traits::get_bit_depth())
00118 {
00119 throw error(wrong_color_space< pixel >::error_msg);
00120 }
00121 }
00122 };
00123
00124 }
00125
00126 #endif // PNGPP_REQUIRE_COLOR_SPACE_HPP_INCLUDED