1 /*
2  * Copyright (C) 2007 Toni Corvera
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */
18 
19 // $Id: colour.cc 1113 2009-04-09 01:33:39Z  $
20 
21 #include "colour.h"
22 
23 namespace {
24     /*!
25      * \brief Abstract implementation of the output operator
26      * \param T_scalar    Type of the components
27      * \param T_cast_type Components will be casted to this type, if no cast
28      *                    is required, use template<typename,int>print_col()
29      * \param C_max       Full component value
30      */
31     template<typename T_scalar, typename T_cast_type, int C_max>
print_col(std::ostream & os,const T_scalar & r,const T_scalar & g,const T_scalar & b)32     inline std::ostream & print_col(std::ostream & os,
33                                     const T_scalar & r,
34                                     const T_scalar & g,
35                                     const T_scalar & b)
36     {
37         return os << "Col[0.." << C_max << "] ("
38                          << static_cast<T_cast_type>(r) << ", "
39                          << static_cast<T_cast_type>(g) << ", "
40                          << static_cast<T_cast_type>(b) << ")";
41     }
42 
43     /*!
44      * \brief Short-hand of print_col, when no typecast is required.
45      */
46     template<typename T_scalar, int C_max>
print_col(std::ostream & os,const T_scalar & r,const T_scalar & g,const T_scalar & b)47     inline std::ostream & print_col(std::ostream & os,
48                                     const T_scalar & r,
49                                     const T_scalar & g,
50                                     const T_scalar & b)
51     {
52         return print_col<T_scalar, T_scalar, C_max>(os, r,g,b);
53     }
54 }
55 
56 namespace net_outlyer {
57 
58 /////////////////////////////////////////////
59 // Floating point implementations [0..1]
60 /////////////////////////////////////////////
61 
operator <<(std::ostream & os,const colour_type<long double,1> & c)62 std::ostream & operator<<(std::ostream & os, const colour_type<long double,1> & c) {
63     return print_col<long double,1>(os, c.r, c.g, c.b);
64 }
65 
operator <<(std::ostream & os,const colour_type<double,1> & c)66 std::ostream & operator<<(std::ostream & os, const colour_type<double,1> & c) {
67     return print_col<double,1>(os, c.r, c.g, c.b);
68 }
69 
operator <<(std::ostream & os,const colour_type<float,1> & c)70 std::ostream & operator<<(std::ostream & os, const colour_type<float,1> & c) {
71     return print_col<float,1>(os, c.r, c.g, c.b);
72 }
73 
74 /////////////////////////////////////////////
75 // Integer implementations [0..255]
76 /////////////////////////////////////////////
77 
operator <<(std::ostream & os,const colour_type<uint8_t,255> & c)78 std::ostream & operator<<(std::ostream & os, const colour_type<uint8_t,255> & c) {
79     return print_col<uint8_t, int, 255>(os, c.r, c.g, c.b);
80 }
81 
operator <<(std::ostream & os,const colour_type<signed short,255> & c)82 std::ostream & operator<<(std::ostream & os, const colour_type<signed short,255> & c) {
83     return print_col<signed short, 255>(os, c.r, c.g, c.b);
84 }
85 
operator <<(std::ostream & os,const colour_type<unsigned short,255> & c)86 std::ostream & operator<<(std::ostream & os, const colour_type<unsigned short,255> & c) {
87     return print_col<unsigned short, 255>(os, c.r, c.g, c.b);
88 }
89 
operator <<(std::ostream & os,const colour_type<signed int,255> & c)90 std::ostream & operator<<(std::ostream & os, const colour_type<signed int,255> & c) {
91     return print_col<signed int, 255>(os, c.r, c.g, c.b);
92 }
operator <<(std::ostream & os,const colour_type<unsigned int,255> & c)93 std::ostream & operator<<(std::ostream & os, const colour_type<unsigned int,255> & c) {
94     return print_col<unsigned int, 255>(os, c.r, c.g, c.b);
95 }
96 
97 }
98 
99 // vim:set ts=4 et ai:
100