From 373f307ae6edbccd2183a934b409f7d2a3e20e9d Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Mon, 2 May 2022 00:26:13 +0200 Subject: [PATCH] WIP: image object, first steps --- src/laybasic/laybasic/layViewObject.h | 4 +- src/laybasic/unit_tests/layImageTests.cc | 92 ++++++++++++++++++++++++ src/tl/tl/tlCopyOnWrite.h | 4 +- src/tl/unit_tests/unit_tests.pro | 1 - 4 files changed, 95 insertions(+), 6 deletions(-) diff --git a/src/laybasic/laybasic/layViewObject.h b/src/laybasic/laybasic/layViewObject.h index fa0552136..38e84f5c1 100644 --- a/src/laybasic/laybasic/layViewObject.h +++ b/src/laybasic/laybasic/layViewObject.h @@ -1030,7 +1030,7 @@ public: } protected: -#if defined(HAVE_QT) +#if defined(HAVE_QT) // @@@ /** * @brief Qt focus event handler */ @@ -1101,7 +1101,7 @@ protected: void wheelEvent (QWheelEvent *e); #endif -#if !defined(HAVE_QT) +#if !defined(HAVE_QT) // @@@ void update (); #endif diff --git a/src/laybasic/unit_tests/layImageTests.cc b/src/laybasic/unit_tests/layImageTests.cc index e69de29bb..896116392 100644 --- a/src/laybasic/unit_tests/layImageTests.cc +++ b/src/laybasic/unit_tests/layImageTests.cc @@ -0,0 +1,92 @@ + +/* + + 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 "layImage.h" + +#include "tlUnitTest.h" + +#if defined(HAVE_QT) +#include +#endif + +TEST(1) +{ + lay::Image img (15, 25); + EXPECT_EQ (img.width (), 15); + EXPECT_EQ (img.height (), 25); + + img.fill (0x112233); + EXPECT_EQ (img.scan_line (5)[10], 0x112233); + + lay::Image img2; + img2 = img; + EXPECT_EQ (img2.width (), 15); + EXPECT_EQ (img2.height (), 25); + + EXPECT_EQ (img.scan_line (5)[10], 0x112233); + EXPECT_EQ (img2.scan_line (5)[10], 0x112233); + + img2.fill (0x332211); + EXPECT_EQ (img.scan_line (5)[10], 0x112233); + EXPECT_EQ (img2.scan_line (5)[10], 0x332211); + + img2.swap (img); + EXPECT_EQ (img2.scan_line (5)[10], 0x112233); + EXPECT_EQ (img.scan_line (5)[10], 0x332211); + + img2 = img; + EXPECT_EQ (img.scan_line (5)[10], 0x332211); + EXPECT_EQ (img2.scan_line (5)[10], 0x332211); + + img2 = lay::Image (10, 16); + EXPECT_EQ (img.width (), 15); + EXPECT_EQ (img.height (), 25); + EXPECT_EQ (img2.width (), 10); + EXPECT_EQ (img2.height (), 16); + img2.fill (0x010203); + + EXPECT_EQ (img.scan_line (5)[10], 0x332211); + EXPECT_EQ (img2.scan_line (5)[8], 0x010203); + + img = std::move (img2); + EXPECT_EQ (img.width (), 10); + EXPECT_EQ (img.height (), 16); + EXPECT_EQ (img.scan_line (5)[8], 0x010203); + + lay::Image img3 (img); + EXPECT_EQ (img3.width (), 10); + EXPECT_EQ (img3.height (), 16); + EXPECT_EQ (img3.scan_line (5)[8], 0x010203); + + img.fill (0x102030); + EXPECT_EQ (img3.width (), 10); + EXPECT_EQ (img3.height (), 16); + EXPECT_EQ (img3.scan_line (5)[8], 0x010203); + EXPECT_EQ (img.width (), 10); + EXPECT_EQ (img.height (), 16); + EXPECT_EQ (img.scan_line (5)[8], 0x102030); + + lay::Image img4 (std::move (img)); + EXPECT_EQ (img4.width (), 10); + EXPECT_EQ (img4.height (), 16); + EXPECT_EQ (img4.scan_line (5)[8], 0x102030); +} diff --git a/src/tl/tl/tlCopyOnWrite.h b/src/tl/tl/tlCopyOnWrite.h index 2dbbae8d1..54ef6dc47 100644 --- a/src/tl/tl/tlCopyOnWrite.h +++ b/src/tl/tl/tlCopyOnWrite.h @@ -152,9 +152,7 @@ public: return; } - tl::MutexLocker locker1 (&ms_lock); - tl::MutexLocker locker2 (&other.ms_lock); - + tl::MutexLocker locker (&ms_lock); std::swap (mp_x, other.mp_x); std::swap (mp_holder, other.mp_holder); } diff --git a/src/tl/unit_tests/unit_tests.pro b/src/tl/unit_tests/unit_tests.pro index a0acbddb2..768faad17 100644 --- a/src/tl/unit_tests/unit_tests.pro +++ b/src/tl/unit_tests/unit_tests.pro @@ -19,7 +19,6 @@ SOURCES = \ tlFileSystemWatcherTests.cc \ tlFileUtilsTests.cc \ tlHttpStreamTests.cc \ - tlImageTests.cc \ tlIncludeTests.cc \ tlInt128SupportTests.cc \ tlIntervalMapTests.cc \