- Main Page
- Namespaces
- Classes
- Files

- File List

# require_color_space.hpp

Go to the documentation of this file.

    00001 /*
    00002  * Copyright (C) 2007,2008   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 detail
    00046     {
    00047
    00048         template< typename pixel >
    00049         struct wrong_color_space
    00050         {
    00051             inline static char const* error_msg();
    00052         };
    00053
    00054         template<> inline char const*
    00055         wrong_color_space< rgb_pixel >::error_msg()
    00056         {
    00057             return "8-bit RGB color space required";
    00058         }
    00059
    00060         template<> inline char const*
    00061         wrong_color_space< rgb_pixel_16 >::error_msg()
    00062         {
    00063             return "16-bit RGB color space required";
    00064         }
    00065
    00066         template<> inline char const*
    00067         wrong_color_space< rgba_pixel >::error_msg()
    00068         {
    00069             return "8-bit RGBA color space required";
    00070         }
    00071
    00072         template<> inline char const*
    00073         wrong_color_space< rgba_pixel_16 >::error_msg()
    00074         {
    00075             return "16-bit RGBA color space required";
    00076         }
    00077
    00078         template<> inline char const*
    00079         wrong_color_space< gray_pixel >::error_msg()
    00080         {
    00081             return "8-bit Grayscale color space required";
    00082         }
    00083
    00084         template<> inline char const*
    00085         wrong_color_space< gray_pixel_1 >::error_msg()
    00086         {
    00087             return "1-bit Grayscale color space required";
    00088         }
    00089
    00090         template<> inline char const*
    00091         wrong_color_space< gray_pixel_2 >::error_msg()
    00092         {
    00093             return "2-bit Grayscale color space required";
    00094         }
    00095
    00096         template<> inline char const*
    00097         wrong_color_space< gray_pixel_4 >::error_msg()
    00098         {
    00099             return "4-bit Grayscale color space required";
    00100         }
    00101
    00102         template<> inline char const*
    00103         wrong_color_space< gray_pixel_16 >::error_msg()
    00104         {
    00105             return "16-bit Grayscale color space required";
    00106         }
    00107
    00108         template<> inline char const*
    00109         wrong_color_space< ga_pixel >::error_msg()
    00110         {
    00111             return "8-bit Gray+Alpha color space required";
    00112         }
    00113
    00114         template<> inline char const*
    00115         wrong_color_space< ga_pixel_16 >::error_msg()
    00116         {
    00117             return "16-bit Gray+Alpha color space required";
    00118         }
    00119
    00120         template<> inline char const*
    00121         wrong_color_space< index_pixel >::error_msg()
    00122         {
    00123             return "8-bit Colormap color space required";
    00124         }
    00125
    00126         template<> inline char const*
    00127         wrong_color_space< index_pixel_1 >::error_msg()
    00128         {
    00129             return "1-bit Colormap color space required";
    00130         }
    00131
    00132         template<> inline char const*
    00133         wrong_color_space< index_pixel_2 >::error_msg()
    00134         {
    00135             return "2-bit Colormap color space required";
    00136         }
    00137
    00138         template<> inline char const*
    00139         wrong_color_space< index_pixel_4 >::error_msg()
    00140         {
    00141             return "4-bit Colormap color space required";
    00142         }
    00143
    00144     } // namespace detail
    00145
    00154     template< typename pixel >
    00155     struct require_color_space
    00156     {
    00157         typedef pixel_traits< pixel > traits;
    00158
    00159         void operator()(io_base& io) const
    00160         {
    00161             if (io.get_color_type() != traits::get_color_type()
    00162                 || io.get_bit_depth() != traits::get_bit_depth())
    00163             {
    00164                 throw error(detail::wrong_color_space< pixel >::error_msg());
    00165             }
    00166         }
    00167     };
    00168
    00169 } // namespace png
    00170
    00171 #endif // PNGPP_REQUIRE_COLOR_SPACE_HPP_INCLUDED