Writing: adjusted label names and formatting of Fisher-and-Saupe table.
[fic.git] / imageUtil.h
blobf2e9b6a1e57a9cfcc14409db2beaffdbdb6d4729
1 #ifndef IMAGEUTIL_HEADER_
2 #define IMAGEUTIL_HEADER_
4 #include "headers.h"
6 #include <QColor>
8 namespace Color {
9 extern const Real RGBCoeffs[][4] /// RGB color coefficients
10 , YCbCrCoeffs[][4]; ///< YCbCr color coefficients
12 /** Computes PSNRs between two images for gray, red, green and blue */
13 std::vector<Real> getPSNR(const QImage &a,const QImage &b);
15 /** Computes the amount of a color (coefficients as a parameter) in RGB */
16 inline Real getColor( QRgb color, const Real *koefs ) {
17 return koefs[3] + std::ldexp( Real(0.5) + qRed(color)*Real(koefs[0])
18 + qGreen(color)*Real(koefs[1]) + qBlue(color)*Real(koefs[2]), -8 );
21 /** Converts color from a model (coefficients as a parameter) to RGB */
22 inline QRgb getColor( const Real (*coeffs)[4], const Real *planes ) {
23 Real rgb[3]= {0,0,0};
24 for (int i=0; i<3; ++i) {
25 const Real *cLine= coeffs[i];
26 Real col= planes[i]+cLine[3];
27 for (int c=0; c<3; ++c)
28 rgb[c]+= col*cLine[c];
30 typedef Float2int<8,Real> Conv;
31 return qRgb( Conv::convertCheck(rgb[0]), Conv::convertCheck(rgb[1])
32 , Conv::convertCheck(rgb[2]) );
35 /** Computes the gray level of a QRgb color in 0-255 interval */
36 inline int getGray(QRgb color) {
37 return Float2int<8,Real>::convert( getColor( color, YCbCrCoeffs[0] ) );
40 } // Color namespace
42 #endif