require_color_space.hpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2007   Alex Shulgin
00003  *
00004  * This file is part of png++ the C++ wrapper for libpng.  Png++ is free
00005  * software; the exact copying conditions are as follows:
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions are met:
00009  *
00010  * 1. Redistributions of source code must retain the above copyright notice,
00011  * this list of conditions and the following disclaimer.
00012  *
00013  * 2. Redistributions in binary form must reproduce the above copyright
00014  * notice, this list of conditions and the following disclaimer in the
00015  * documentation and/or other materials provided with the distribution.
00016  *
00017  * 3. The name of the author may not be used to endorse or promote products
00018  * derived from this software without specific prior written permission.
00019  *
00020  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00021  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00022  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
00023  * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00024  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
00025  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00026  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00027  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00028  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00029  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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     } // unnamed namespace
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 } // namespace png
00125 
00126 #endif // PNGPP_REQUIRE_COLOR_SPACE_HPP_INCLUDED

Generated on Sun Jul 8 19:33:00 2007 for png++ by  doxygen 1.5.2