~ubuntu-branches/ubuntu/trusty/libavg/trusty-proposed

« back to all changes in this revision

Viewing changes to src/graphics/GraphicsTest.cpp

  • Committer: Package Import Robot
  • Author(s): OXullo Intersecans
  • Date: 2011-12-06 22:44:56 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20111206224456-qc7250z3ya1vi8s9
Tags: 1.7.0-0ubuntu1
* New upstream release (LP: #899183)
* Remove patches 0002-libav-0.7.patch, 0003-fglrx-segfault-on-startup.patch
  now merged to upstream
* Remove unnecessary .la files
* Update debian/watch file
* Fix debian/copyright dep-5 compliancy
* Update standards to version 3.9.2
* Add man pages for avg_checktouch, avg_checkvsync, avg_showsvg
* Minor debian/rules enhancement
* Add librsvg2-dev, libgdk-pixbuf2.0-dev to Build-Depends
* Proper transition to dh_python2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//
2
2
//  libavg - Media Playback Engine. 
3
 
//  Copyright (C) 2003-2008 Ulrich von Zadow
 
3
//  Copyright (C) 2003-2011 Ulrich von Zadow
4
4
//
5
5
//  This library is free software; you can redistribute it and/or
6
6
//  modify it under the terms of the GNU Lesser General Public
27
27
#include "../base/Directory.h"
28
28
#include "../base/Exception.h"
29
29
 
30
 
#include <Magick++.h>
31
 
 
32
30
#include <iostream>
33
31
#include <sstream>
34
32
#include <math.h>
65
63
            return FilterGrayscale().apply(pBmp);
66
64
        }
67
65
        return pBmp;
68
 
    } catch (Magick::Exception & ex) {
69
 
        cerr << ex.what() << endl;
 
66
    } catch (Exception & ex) {
 
67
        cerr << ex.getStr() << endl;
70
68
        throw;
71
69
    }
72
70
}
84
82
            default:
85
83
                break;
86
84
        }
87
 
    } catch (Magick::Exception & ex) {
88
 
        cerr << ex.what() << endl;
 
85
    } catch (Exception & ex) {
 
86
        cerr << ex.getStr() << endl;
89
87
        resultBmp.save("resultimages/"+sFName+".png");
90
88
        throw;
91
89
    }
95
93
void GraphicsTest::testEqual(Bitmap& resultBmp, Bitmap& baselineBmp, 
96
94
        const string& sFName, double maxAverage, double maxStdDev)
97
95
{
98
 
    BitmapPtr pDiffBmp = BitmapPtr(resultBmp.subtract(&baselineBmp));
99
 
    double average = pDiffBmp->getAvg();
100
 
    double stdDev = pDiffBmp->getStdDev();
101
 
    if (average > maxAverage || stdDev > maxStdDev) {
102
 
        TEST_FAILED("Error: Decoded image differs from baseline '" << 
103
 
                sFName << "'. average=" << average << ", stdDev=" << stdDev);
104
 
//        resultBmp.dump();
105
 
//        baselineBmp.dump();
 
96
    BitmapPtr pDiffBmp;
 
97
    try {
 
98
        pDiffBmp = resultBmp.subtract(baselineBmp);
 
99
    } catch (Exception& e) {
 
100
        TEST_FAILED("Error: " << e.getStr() << ". File: '" << sFName << "'.");
106
101
        string sResultName = "resultimages/"+sFName;
107
102
        resultBmp.save(sResultName+".png");
108
103
        baselineBmp.save(sResultName+"_baseline.png");
109
 
        BitmapPtr pDiffBmp(resultBmp.subtract(&baselineBmp));
110
 
        pDiffBmp->save(sResultName+"_diff.png");
 
104
    }
 
105
    if (pDiffBmp) {
 
106
        double average = pDiffBmp->getAvg();
 
107
        double stdDev = pDiffBmp->getStdDev();
 
108
        if (average > maxAverage || stdDev > maxStdDev) {
 
109
            TEST_FAILED("Error: Decoded image differs from baseline '" << 
 
110
                    sFName << "'. average=" << average << ", stdDev=" << stdDev);
 
111
    //        resultBmp.dump();
 
112
    //        baselineBmp.dump();
 
113
            string sResultName = "resultimages/"+sFName;
 
114
            resultBmp.save(sResultName+".png");
 
115
            baselineBmp.save(sResultName+"_baseline.png");
 
116
            BitmapPtr pDiffBmp = resultBmp.subtract(baselineBmp);
 
117
            pDiffBmp->save(sResultName+"_diff.png");
 
118
        }
111
119
    }
112
120
}
113
121
 
116
124
{
117
125
    double diff = fabs(resultBmp.getAvg()-baselineBmp.getAvg());
118
126
    if (diff >= epsilon) {
119
 
        cerr << "        Baseline brightness: " << baselineBmp.getAvg()
 
127
        TEST_FAILED("Error: Baseline brightness: " << baselineBmp.getAvg()
120
128
                << ", Result brightness: " << resultBmp.getAvg() << ", difference: " 
121
 
                << diff << endl;
 
129
                << diff);
122
130
    }
123
131
}
124
132