00001 #ifndef IMAGEUTIL_HEADER_
00002 #define IMAGEUTIL_HEADER_
00003
00004 #include "headers.h"
00005
00006 #include <QColor>
00007
00008 namespace Color {
00009 extern const Real RGBCoeffs[][4]
00010 , YCbCrCoeffs[][4];
00011
00013 std::vector<Real> getPSNR(const QImage &a,const QImage &b);
00014
00016 inline Real getColor( QRgb color, const Real *koefs ) {
00017 return koefs[3] + std::ldexp( Real(0.5) + qRed(color)*Real(koefs[0])
00018 + qGreen(color)*Real(koefs[1]) + qBlue(color)*Real(koefs[2]), -8 );
00019 }
00020
00022 inline QRgb getColor( const Real (*coeffs)[4], const Real *planes ) {
00023 Real rgb[3]= {0,0,0};
00024 for (int i=0; i<3; ++i) {
00025 const Real *cLine= coeffs[i];
00026 Real col= planes[i]+cLine[3];
00027 for (int c=0; c<3; ++c)
00028 rgb[c]+= col*cLine[c];
00029 }
00030 typedef Float2int<8,Real> Conv;
00031 return qRgb( Conv::convertCheck(rgb[0]), Conv::convertCheck(rgb[1])
00032 , Conv::convertCheck(rgb[2]) );
00033 }
00034
00036 inline int getGray(QRgb color) {
00037 return Float2int<8,Real>::convert( getColor( color, YCbCrCoeffs[0] ) );
00038 }
00039
00040 }
00041
00042 #endif