Refactoring: layColor -> tlColor

This commit is contained in:
Matthias Koefferlein
2022-05-30 23:21:32 +02:00
parent 84cf60dbb7
commit 62bbef53ac
91 changed files with 555 additions and 555 deletions
-219
View File
@@ -1,219 +0,0 @@
/*
KLayout Layout Viewer
Copyright (C) 2006-2022 Matthias Koefferlein
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 2 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, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "layColor.h"
#include "tlUnitTest.h"
#if defined(HAVE_QT)
#include <QColor>
#endif
TEST(1)
{
EXPECT_EQ (lay::Color ().is_valid (), false);
EXPECT_EQ (lay::Color ().to_string (), "");
EXPECT_EQ (lay::Color ().rgb (), 0x00000000);
#if defined(HAVE_QT)
EXPECT_EQ (QColor ().isValid (), false);
EXPECT_EQ (tl::to_string (QColor ().name ()), "#000000"); // why?
EXPECT_EQ (QColor ().rgb (), 0xff000000);
#endif
}
TEST(2)
{
EXPECT_EQ (lay::Color (0x102030).is_valid (), true);
EXPECT_EQ (lay::Color (0x102030).to_string (), "#102030");
EXPECT_EQ (lay::Color (0x102030).rgb (), 0xff102030);
#if defined(HAVE_QT)
EXPECT_EQ (QColor (0x102030).isValid (), true);
EXPECT_EQ (tl::to_string (QColor (0x102030).name ()), "#102030");
EXPECT_EQ (QColor (0x102030).rgb (), 0xff102030);
#endif
}
TEST(3)
{
EXPECT_EQ (lay::Color (std::string ()).is_valid (), false);
EXPECT_EQ (lay::Color ("#102030").is_valid (), true);
EXPECT_EQ (lay::Color ("#102030").to_string (), "#102030");
EXPECT_EQ (lay::Color ("#102030").rgb (), 0xff102030);
EXPECT_EQ (lay::Color ("102030").is_valid (), true);
EXPECT_EQ (lay::Color ("102030").to_string (), "#102030");
EXPECT_EQ (lay::Color ("102030").rgb (), 0xff102030);
#if defined(HAVE_QT)
EXPECT_EQ (QColor (tl::to_qstring ("#102030")).isValid (), true);
EXPECT_EQ (tl::to_string (QColor (tl::to_qstring ("#102030")).name ()), "#102030");
EXPECT_EQ (QColor (tl::to_qstring ("#102030")).rgb (), 0xff102030);
#endif
}
TEST(4)
{
EXPECT_EQ (lay::Color ("#123").is_valid (), true);
EXPECT_EQ (lay::Color ("#123").to_string (), "#112233");
EXPECT_EQ (lay::Color ("#123").rgb (), 0xff112233);
}
TEST(5)
{
EXPECT_EQ (lay::Color ("#80102030").is_valid (), true);
EXPECT_EQ (lay::Color ("#80102030").alpha (), 128);
EXPECT_EQ (lay::Color ("#80102030").red (), 16);
EXPECT_EQ (lay::Color ("#80102030").green (), 32);
EXPECT_EQ (lay::Color ("#80102030").blue (), 48);
EXPECT_EQ (lay::Color ("#80102030").to_string (), "#80102030");
EXPECT_EQ (lay::Color ("#80102030").rgb (), 0x80102030);
#if defined(HAVE_QT) && QT_VERSION >= 0x50000
// no alpha support in Qt
EXPECT_EQ (QColor (tl::to_qstring ("#80102030")).isValid (), true);
EXPECT_EQ (tl::to_string (QColor (tl::to_qstring ("#80102030")).name ()), "#102030");
EXPECT_EQ (QColor (tl::to_qstring ("#80102030")).rgb (), 0xff102030);
#endif
}
TEST(6)
{
EXPECT_EQ (lay::Color ("#8123").is_valid (), true);
EXPECT_EQ (lay::Color ("#8123").to_string (), "#88112233");
EXPECT_EQ (lay::Color ("#8123").rgb (), 0x88112233);
}
TEST(7)
{
EXPECT_EQ (lay::Color (16, 32, 48, 128).is_valid (), true);
EXPECT_EQ (lay::Color (16, 32, 48, 128).to_string (), "#80102030");
EXPECT_EQ (lay::Color (16, 32, 48, 128).rgb (), 0x80102030);
#if defined(HAVE_QT)
// no alpha support in Qt
EXPECT_EQ (QColor (16, 32, 48, 128).isValid (), true);
EXPECT_EQ (tl::to_string (QColor (16, 32, 48, 128).name ()), "#102030");
EXPECT_EQ (QColor (16, 32, 48, 128).rgb (), 0xff102030);
#endif
}
TEST(8)
{
unsigned int h, s, v;
int ih, is, iv;
lay::Color c = lay::Color (16, 32, 48);
c.get_hsv (h, s, v);
EXPECT_EQ (h, 210);
EXPECT_EQ (s, 170);
EXPECT_EQ (v, 48);
EXPECT_EQ (lay::Color::from_hsv (h, s, v).to_string (), "#102030");
#if defined(HAVE_QT)
QColor qc = QColor (16, 32, 48);
qc.getHsv (&ih, &is, &iv);
EXPECT_EQ (ih, 210);
EXPECT_EQ (is, 170);
EXPECT_EQ (iv, 48);
#endif
c = lay::Color (32, 16, 48);
c.get_hsv (h, s, v);
EXPECT_EQ (h, 270);
EXPECT_EQ (s, 170);
EXPECT_EQ (v, 48);
EXPECT_EQ (lay::Color::from_hsv (h, s, v).to_string (), "#201030");
#if defined(HAVE_QT)
qc = QColor (32, 16, 48);
qc.getHsv (&ih, &is, &iv);
EXPECT_EQ (ih, 270);
EXPECT_EQ (is, 170);
EXPECT_EQ (iv, 48);
#endif
c = lay::Color (32, 48, 16);
c.get_hsv (h, s, v);
EXPECT_EQ (h, 90);
EXPECT_EQ (s, 170);
EXPECT_EQ (v, 48);
EXPECT_EQ (lay::Color::from_hsv (h, s, v).to_string (), "#203010");
#if defined(HAVE_QT)
qc = QColor (32, 48, 16);
qc.getHsv (&ih, &is, &iv);
EXPECT_EQ (ih, 90);
EXPECT_EQ (is, 170);
EXPECT_EQ (iv, 48);
#endif
c = lay::Color (48, 32, 16);
c.get_hsv (h, s, v);
EXPECT_EQ (h, 30);
EXPECT_EQ (s, 170);
EXPECT_EQ (v, 48);
EXPECT_EQ (lay::Color::from_hsv (h, s, v).to_string (), "#302010");
#if defined(HAVE_QT)
qc = QColor (48, 32, 16);
qc.getHsv (&ih, &is, &iv);
EXPECT_EQ (ih, 30);
EXPECT_EQ (is, 170);
EXPECT_EQ (iv, 48);
#endif
c = lay::Color (48, 16, 32);
c.get_hsv (h, s, v);
EXPECT_EQ (h, 330);
EXPECT_EQ (s, 170);
EXPECT_EQ (v, 48);
EXPECT_EQ (lay::Color::from_hsv (h, s, v).to_string (), "#301020");
#if defined(HAVE_QT)
qc = QColor (48, 16, 32);
qc.getHsv (&ih, &is, &iv);
EXPECT_EQ (ih, 330);
EXPECT_EQ (is, 170);
EXPECT_EQ (iv, 48);
#endif
c = lay::Color (16, 48, 32);
c.get_hsv (h, s, v);
EXPECT_EQ (h, 150);
EXPECT_EQ (s, 170);
EXPECT_EQ (v, 48);
EXPECT_EQ (lay::Color::from_hsv (h, s, v).to_string (), "#103020");
#if defined(HAVE_QT)
qc = QColor (16, 48, 32);
qc.getHsv (&ih, &is, &iv);
EXPECT_EQ (ih, 150);
EXPECT_EQ (is, 170);
EXPECT_EQ (iv, 48);
#endif
}
@@ -38,7 +38,7 @@ static bool compare_images (const QImage &qimg, const std::string &au)
if (qimg2.width () == (int) qimg.width () && qimg2.height () == (int) qimg.height ()) {
for (int j = 0; j < qimg.height (); ++j) {
for (int i = 0; i < qimg.width (); ++i) {
if (((const lay::color_t *) qimg.scanLine (j))[i] != ((const lay::color_t *) qimg2.scanLine (j))[i]) {
if (((const tl::color_t *) qimg.scanLine (j))[i] != ((const tl::color_t *) qimg2.scanLine (j))[i]) {
return false;
}
}
@@ -87,7 +87,7 @@ TEST(1)
lay::PixelBuffer img (15, 25);
EXPECT_EQ (img.width (), 15);
EXPECT_EQ (img.height (), 25);
EXPECT_EQ (img.stride (), 15 * sizeof (lay::color_t));
EXPECT_EQ (img.stride (), 15 * sizeof (tl::color_t));
EXPECT_EQ (img.transparent (), false);
img.set_transparent (true);
@@ -159,11 +159,11 @@ TEST(1)
EXPECT_EQ (img4.scan_line (5)[8], 0xff102030);
// other constructors
EXPECT_EQ (compare_images (lay::PixelBuffer (img4.width (), img4.height (), (const lay::color_t *) img4.data ()), img4), true);
EXPECT_EQ (compare_images (lay::PixelBuffer (img4.width (), img4.height (), (const lay::color_t *) img4.data (), img4.stride ()), img4), true);
EXPECT_EQ (compare_images (lay::PixelBuffer (img4.width (), img4.height (), (const tl::color_t *) img4.data ()), img4), true);
EXPECT_EQ (compare_images (lay::PixelBuffer (img4.width (), img4.height (), (const tl::color_t *) img4.data (), img4.stride ()), img4), true);
lay::color_t *dnew = new lay::color_t [ img4.width () * img4.height () * sizeof (lay::color_t) ];
memcpy (dnew, (const lay::color_t *) img4.data (), img4.width () * img4.height () * sizeof (lay::color_t));
tl::color_t *dnew = new tl::color_t [ img4.width () * img4.height () * sizeof (tl::color_t) ];
memcpy (dnew, (const tl::color_t *) img4.data (), img4.width () * img4.height () * sizeof (tl::color_t));
EXPECT_EQ (compare_images (lay::PixelBuffer (img4.width (), img4.height (), dnew), img4), true);
}
-1
View File
@@ -10,7 +10,6 @@ SOURCES = \
layAnnotationShapes.cc \
layBitmap.cc \
layBitmapsToImage.cc \
layColorTests.cc \
layLayerProperties.cc \
layParsedLayerSource.cc \
layPixelBufferTests.cc \