refinery
RAW file processor
|
00001 #ifndef _REFINERY_COLOR_H 00002 #define _REFINERY_COLOR_H 00003 00004 #include <cstddef> 00005 00006 namespace refinery { 00007 00008 template<typename T> struct RGBColor; 00009 00031 template<typename T, std::size_t NFrom, std::size_t NTo> 00032 class ColorConverter { 00033 T mMatrix[NTo][NFrom]; 00034 00035 public: 00042 template<typename U> ColorConverter(const U (&matrix)[NTo][NFrom]) 00043 { 00044 for (unsigned int i = 0; i < NTo; i++) { 00045 for (unsigned int j = 0; j < NFrom; j++) { 00046 mMatrix[i][j] = static_cast<T>(matrix[i][j]); 00047 } 00048 } 00049 } 00050 00059 template<typename U, typename V> void convert(const U (&in)[NFrom], V (&out)[NTo]) 00060 { 00061 for (unsigned int i = 0; i < NTo; i++) { 00062 out[i] = static_cast<V>(0); 00063 } 00064 00065 for (unsigned int i = 0; i < NFrom; i++) { 00066 for (unsigned int j = 0; j < NTo; j++) { 00067 out[j] += mMatrix[j][i] * in[i]; 00068 } 00069 } 00070 } 00071 00085 template<typename U, typename V> void convert(const U (&in)[NFrom - 1], V (&out)[NTo]) 00086 { 00087 for (unsigned int i = 0; i < NTo; i++) { 00088 out[i] = static_cast<V>(0); 00089 } 00090 00091 for (unsigned int i = 0; i < NFrom - 1; i++) { 00092 for (unsigned int j = 0; j < NTo; j++) { 00093 out[j] += mMatrix[j][i] * in[i]; 00094 } 00095 } 00096 } 00097 }; 00098 00099 } // namespace refinery 00100 00101 #endif /* _REFINERY_COLOR_H */