Writing - finished to the printed version.
[fic.git] / imageUtil.cpp
bloba3735a73f19f39cc6c51b3238c76d169c5a32c3f
1 #include "imageUtil.h"
3 #include <QImage>
5 using namespace std;
6 namespace Color {
7 const Real
8 YCbCrCoeffs[][4]= {
9 { 0.299, 0.587, 0.114, 0 },
10 {-0.168736, -0.331264, 0.5, 0.5 },
11 { 0.5, -0.418688, -0.081312, 0.5 },
13 { 1, 1, 1, 0 },
14 { 0, -0.34414, 1.772, -0.5 },
15 { 1.402, -0.71414, 0, -0.5 }
17 RGBCoeffs[][4]= {
18 {1,0,0,0}, {0,1,0,0}, {0,0,1,0},
19 {1,0,0,0}, {0,1,0,0}, {0,0,1,0}
22 vector<Real> getPSNR(const QImage &a,const QImage &b) {
23 int width= a.width(), height= a.height();
24 int x, y;
25 QRgb *line1, *line2;
26 long sum, sumR, sumG, sumB;
27 sum= sumR= sumG= sumB= 0;
28 for (y=0; y<height; ++y) { /// \todo using walkers instead?
29 line1= (QRgb*)a.scanLine(y);
30 line2= (QRgb*)b.scanLine(y);
31 for (x=0; x<width; ++x) {
32 sum+= sqr( getGray(line1[x]) - getGray(line2[x]) );
33 sumR+= sqr( qRed(line1[x]) - qRed(line2[x]) );
34 sumG+= sqr( qGreen(line1[x]) - qGreen(line2[x]) );
35 sumB+= sqr( qBlue(line1[x]) - qBlue(line2[x]) );
38 vector<Real> result(4);
39 result[0]= sumR;
40 result[1]= sumG;
41 result[2]= sumB;
42 result[3]= sum;
43 Real mul= Real(width*height) * Real(sqr(255));
44 for (vector<Real>::iterator it=result.begin(); it!=result.end(); ++it)
45 *it= Real(10) * log10(mul / *it);
46 return result;
49 } // Color namespace