F:/KPlato/koffice/libs/pigment/tests/kis_color_conversions_tester.cpp

Aller à la documentation de ce fichier.
00001 /*
00002  *  Copyright (c) 2005 Adrian Page <adrian@pagenet.plus.com>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 
00019 #include <kunittest/runner.h>
00020 #include <kunittest/module.h>
00021 
00022 #include "kis_color_conversions_tester.h"
00023 #include "kis_color_conversions.h"
00024 
00025 using namespace KUnitTest;
00026 
00027 KUNITTEST_MODULE(kunittest_kis_color_conversions_tester, "Color Conversions Tester");
00028 KUNITTEST_MODULE_REGISTER_TESTER(KoColorConversionsTester);
00029 
00030 void KoColorConversionsTester::allTests()
00031 {
00032     testRGBHSV();
00033     testRGBHSL();
00034 }
00035 
00036 #define EPSILON 1e-6
00037 
00038 void KoColorConversionsTester::testRGBHSV()
00039 {
00040     float r, g, b, h, s, v;
00041 
00042     RGBToHSV(1, 0, 0, &h, &s, &v);
00043     CHECK(h, 0.0f);
00044     CHECK(s, 1.0f);
00045     CHECK(v, 1.0f);
00046 
00047     RGBToHSV(1, 1, 0, &h, &s, &v);
00048     CHECK(h, 60.0f);
00049     CHECK(s, 1.0f);
00050     CHECK(v, 1.0f);
00051 
00052     RGBToHSV(0, 1, 0, &h, &s, &v);
00053     CHECK(h, 120.0f);
00054     CHECK(s, 1.0f);
00055     CHECK(v, 1.0f);
00056 
00057     RGBToHSV(0, 1, 1, &h, &s, &v);
00058     CHECK(h, 180.0f);
00059     CHECK(s, 1.0f);
00060     CHECK(v, 1.0f);
00061 
00062     RGBToHSV(0, 0, 1, &h, &s, &v);
00063     CHECK(h, 240.0f);
00064     CHECK(s, 1.0f);
00065     CHECK(v, 1.0f);
00066 
00067     RGBToHSV(1, 0, 1, &h, &s, &v);
00068     CHECK(h, 300.0f);
00069     CHECK(s, 1.0f);
00070     CHECK(v, 1.0f);
00071 
00072     RGBToHSV(0, 0, 0, &h, &s, &v);
00073     CHECK(h, -1.0f);
00074     CHECK(s, 0.0f);
00075     CHECK(v, 0.0f);
00076 
00077     RGBToHSV(1, 1, 1, &h, &s, &v);
00078     CHECK(h, -1.0f);
00079     CHECK(s, 0.0f);
00080     CHECK(v, 1.0f);
00081 
00082     RGBToHSV(0.5, 0.25, 0.75, &h, &s, &v);
00083     CHECK_TOLERANCE(h, 270.0f, EPSILON);
00084     CHECK_TOLERANCE(s, 0.666667f, EPSILON);
00085     CHECK_TOLERANCE(v, 0.75f, EPSILON);
00086 
00087     HSVToRGB(0, 1, 1, &r, &g, &b);
00088     CHECK(r, 1.0f);
00089     CHECK(g, 0.0f);
00090     CHECK(b, 0.0f);
00091 
00092     HSVToRGB(60, 1, 1, &r, &g, &b);
00093     CHECK(r, 1.0f);
00094     CHECK(g, 1.0f);
00095     CHECK(b, 0.0f);
00096 
00097     HSVToRGB(120, 1, 1, &r, &g, &b);
00098     CHECK(r, 0.0f);
00099     CHECK(g, 1.0f);
00100     CHECK(b, 0.0f);
00101 
00102     HSVToRGB(180, 1, 1, &r, &g, &b);
00103     CHECK(r, 0.0f);
00104     CHECK(g, 1.0f);
00105     CHECK(b, 1.0f);
00106 
00107     HSVToRGB(240, 1, 1, &r, &g, &b);
00108     CHECK(r, 0.0f);
00109     CHECK(g, 0.0f);
00110     CHECK(b, 1.0f);
00111 
00112     HSVToRGB(300, 1, 1, &r, &g, &b);
00113     CHECK(r, 1.0f);
00114     CHECK(g, 0.0f);
00115     CHECK(b, 1.0f);
00116 
00117     HSVToRGB(-1, 0, 0, &r, &g, &b);
00118     CHECK(r, 0.0f);
00119     CHECK(g, 0.0f);
00120     CHECK(b, 0.0f);
00121 
00122     HSVToRGB(-1, 0, 1, &r, &g, &b);
00123     CHECK(r, 1.0f);
00124     CHECK(g, 1.0f);
00125     CHECK(b, 1.0f);
00126 
00127     HSVToRGB(270, 0.666667, 0.75, &r, &g, &b);
00128     CHECK_TOLERANCE(r, 0.5f, EPSILON);
00129     CHECK_TOLERANCE(g, 0.25f, EPSILON);
00130     CHECK_TOLERANCE(b, 0.75f, EPSILON);
00131 }
00132 
00133 void KoColorConversionsTester::testRGBHSL()
00134 {
00135     float r, g, b, h, s, l;
00136 
00137     RGBToHSL(1, 0, 0, &h, &s, &l);
00138     CHECK(h, 360.0f);
00139     CHECK(s, 1.0f);
00140     CHECK(l, 0.5f);
00141 
00142     RGBToHSL(1, 1, 0, &h, &s, &l);
00143     CHECK(h, 60.0f);
00144     CHECK(s, 1.0f);
00145     CHECK(l, 0.5f);
00146 
00147     RGBToHSL(0, 1, 0, &h, &s, &l);
00148     CHECK(h, 120.0f);
00149     CHECK(s, 1.0f);
00150     CHECK(l, 0.5f);
00151 
00152     RGBToHSL(0, 1, 1, &h, &s, &l);
00153     CHECK(h, 180.0f);
00154     CHECK(s, 1.0f);
00155     CHECK(l, 0.5f);
00156 
00157     RGBToHSL(0, 0, 1, &h, &s, &l);
00158     CHECK(h, 240.0f);
00159     CHECK(s, 1.0f);
00160     CHECK(l, 0.5f);
00161 
00162     RGBToHSL(1, 0, 1, &h, &s, &l);
00163     CHECK(h, 300.0f);
00164     CHECK(s, 1.0f);
00165     CHECK(l, 0.5f);
00166 
00167     RGBToHSL(0, 0, 0, &h, &s, &l);
00168     CHECK(h, -1.0f);
00169     CHECK(s, 0.0f);
00170     CHECK(l, 0.0f);
00171 
00172     RGBToHSL(1, 1, 1, &h, &s, &l);
00173     CHECK(h, -1.0f);
00174     CHECK(s, 0.0f);
00175     CHECK(l, 1.0f);
00176 
00177     RGBToHSL(0.5, 0.25, 0.75, &h, &s, &l);
00178     CHECK_TOLERANCE(h, 270.0f, EPSILON);
00179     CHECK_TOLERANCE(s, 0.5f, EPSILON);
00180     CHECK_TOLERANCE(l, 0.5f, EPSILON);
00181 
00182     HSLToRGB(0, 1, 0.5, &r, &g, &b);
00183     CHECK(r, 1.0f);
00184     CHECK(g, 0.0f);
00185     CHECK(b, 0.0f);
00186 
00187     HSLToRGB(60, 1, 0.5, &r, &g, &b);
00188     CHECK(r, 1.0f);
00189     CHECK(g, 1.0f);
00190     CHECK(b, 0.0f);
00191 
00192     HSLToRGB(120, 1, 0.5, &r, &g, &b);
00193     CHECK(r, 0.0f);
00194     CHECK(g, 1.0f);
00195     CHECK(b, 0.0f);
00196 
00197     HSLToRGB(180, 1, 0.5, &r, &g, &b);
00198     CHECK(r, 0.0f);
00199     CHECK(g, 1.0f);
00200     CHECK(b, 1.0f);
00201 
00202     HSLToRGB(240, 1, 0.5, &r, &g, &b);
00203     CHECK(r, 0.0f);
00204     CHECK(g, 0.0f);
00205     CHECK(b, 1.0f);
00206 
00207     HSLToRGB(300, 1, 0.5, &r, &g, &b);
00208     CHECK(r, 1.0f);
00209     CHECK(g, 0.0f);
00210     CHECK(b, 1.0f);
00211 
00212     HSLToRGB(-1, 0, 0, &r, &g, &b);
00213     CHECK(r, 0.0f);
00214     CHECK(g, 0.0f);
00215     CHECK(b, 0.0f);
00216 
00217     HSLToRGB(-1, 0, 1, &r, &g, &b);
00218     CHECK(r, 1.0f);
00219     CHECK(g, 1.0f);
00220     CHECK(b, 1.0f);
00221 
00222     HSLToRGB(270, 0.5, 0.5, &r, &g, &b);
00223     CHECK_TOLERANCE(r, 0.5f, EPSILON);
00224     CHECK_TOLERANCE(g, 0.25f, EPSILON);
00225     CHECK_TOLERANCE(b, 0.75f, EPSILON);
00226 }
00227 

Généré le Wed Nov 22 23:41:13 2006 pour KPlato par  doxygen 1.5.1-p1