[go: up one dir, main page]

Menu

[r140]: / release-3 / tools / main.cpp  Maximize  Restore  History

Download this file

117 lines (95 with data), 3.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/** \file main.cpp
Compare image to reference image
Copyright (C) 2010 Bastian Goldluecke,
<first name>AT<last name>.net
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <assert.h>
#include <qapplication.h>
#include <string>
#include <qimage.h>
using namespace std;
enum console_color {
CONSOLE_DEFAULT = 0,
CONSOLE_RED = 31,
CONSOLE_GREEN = 32,
CONSOLE_YELLOW = 33,
CONSOLE_BLUE = 34,
CONSOLE_MAGENTA = 35,
CONSOLE_CYAN = 36,
CONSOLE_WHITE = 37,
};
void set_console_color( console_color col )
{
cout << "\033[1;" << (int)col << "m";
}
int main( int argc, char **argv )
{
// Application init
QApplication app( argc, argv );
if ( argc != 2 ) {
cout << "reference comparison requires path to reference image as parameter." << endl;
}
string refpath = "./reference_results/";
string outpath = "./out/";
string impath = string(argv[1]).substr( 2 );
cout << " comparing " << impath << " : ";
string refimage = refpath + impath;
string outimage = outpath + impath;
QImage ref( refimage.c_str() );
QImage out( outimage.c_str() );
size_t W = ref.width();
size_t H = ref.height();
if ( W*H==0 ) {
set_console_color( CONSOLE_RED );
cout << "reference image not found or empty." << endl;
set_console_color( CONSOLE_DEFAULT );
return 99;
}
size_t Wo = out.width();
size_t Ho = out.height();
if ( Wo*Ho==0 ) {
set_console_color( CONSOLE_YELLOW );
cout << "output image not found or empty." << endl;
set_console_color( CONSOLE_DEFAULT );
return 98;
}
if ( Wo != W || Ho != H ) {
set_console_color( CONSOLE_RED );
cout << "size mismatch." << endl;
set_console_color( CONSOLE_DEFAULT );
return 97;
}
// compare pixels
for ( size_t y=0; y<H; y++ ) {
for ( size_t x=0; x<W; x++ ) {
QRgb rc = ref.pixel( x,y );
QRgb ro = out.pixel( x,y );
if ( rc != ro ) {
set_console_color( CONSOLE_RED );
cout << "mismatch, ref= ";
cout << qRed(rc) << " " << qBlue(rc) << " " << qGreen( rc ) << " out=";
cout << qRed(ro) << " " << qBlue(ro) << " " << qGreen( ro ) << " (rest ignored).";
cout << endl;
set_console_color( CONSOLE_DEFAULT );
return 1;
}
}
}
set_console_color( CONSOLE_GREEN );
cout << "ok." << endl;
set_console_color( CONSOLE_DEFAULT );
return 0;
}