From b95027a21b5a8b5754eb7ce9745f33410bc06dd2 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Tue, 31 May 2022 00:20:47 +0200 Subject: [PATCH] Refactoring: lay::PixelBuffer, BitmapBuffer -> tl, added image functions to RdbItem in GSI --- src/gsi/gsi/gsi.pro | 4 +- .../gsi/gsiDeclTlPixelBuffer.cc} | 108 ++++++++--------- src/img/img/imgObject.cc | 6 +- src/img/img/imgService.cc | 4 +- .../laybasic/gsiDeclLayLayoutViewBase.cc | 8 +- src/laybasic/laybasic/layBitmapsToImage.cc | 6 +- src/laybasic/laybasic/layBitmapsToImage.h | 14 ++- src/laybasic/laybasic/layLayoutCanvas.cc | 44 +++---- src/laybasic/laybasic/layLayoutCanvas.h | 16 +-- src/laybasic/laybasic/layLayoutViewBase.cc | 16 +-- src/laybasic/laybasic/layLayoutViewBase.h | 16 +-- .../laybasic/layPixelBufferPainter.cc | 4 +- src/laybasic/laybasic/layPixelBufferPainter.h | 13 +- .../laybasic/layRedrawThreadCanvas.cc | 4 +- src/laybasic/laybasic/layRedrawThreadCanvas.h | 6 +- src/laybasic/laybasic/layViewObject.cc | 4 +- src/laybasic/laybasic/layViewObject.h | 12 +- src/laybasic/laybasic/laybasic.pro | 4 +- src/laybasic/unit_tests/layBitmapsToImage.cc | 6 +- src/laybasic/unit_tests/unit_tests.pro | 1 - src/layui/layui/layLayerTreeModel.cc | 4 +- src/layview/unit_tests/layLayoutViewTests.cc | 48 ++++---- src/rdb/rdb/gsiDeclRdb.cc | 24 ++++ src/rdb/rdb/rdb.cc | 26 +++- src/rdb/rdb/rdb.h | 15 ++- src/rdb/unit_tests/{rdb.cc => rdbTests.cc} | 46 +++++++ src/rdb/unit_tests/unit_tests.pro | 4 +- src/tl/tl/tl.pro | 2 + .../tl/tlPixelBuffer.cc} | 4 +- .../tl/tlPixelBuffer.h} | 16 +-- .../unit_tests/tlPixelBufferTests.cc} | 114 +++++++++--------- src/tl/unit_tests/unit_tests.pro | 1 + testdata/ruby/rdbTest.rb | 19 +++ 33 files changed, 379 insertions(+), 240 deletions(-) rename src/{laybasic/laybasic/gsiDeclLayPixelBuffer.cc => gsi/gsi/gsiDeclTlPixelBuffer.cc} (79%) rename src/rdb/unit_tests/{rdb.cc => rdbTests.cc} (94%) rename src/{laybasic/laybasic/layPixelBuffer.cc => tl/tl/tlPixelBuffer.cc} (99%) rename src/{laybasic/laybasic/layPixelBuffer.h => tl/tl/tlPixelBuffer.h} (97%) rename src/{laybasic/unit_tests/layPixelBufferTests.cc => tl/unit_tests/tlPixelBufferTests.cc} (83%) diff --git a/src/gsi/gsi/gsi.pro b/src/gsi/gsi/gsi.pro index e02314d09..83cf1217b 100644 --- a/src/gsi/gsi/gsi.pro +++ b/src/gsi/gsi/gsi.pro @@ -47,7 +47,9 @@ HEADERS = \ # Note: unlike other modules, the tl declarations have to go here # since gsi is dependent on tl -SOURCES += gsiDeclTl.cc +SOURCES += \ + gsiDeclTl.cc \ + gsiDeclTlPixelBuffer.cc INCLUDEPATH += $$TL_INC DEPENDPATH += $$TL_INC diff --git a/src/laybasic/laybasic/gsiDeclLayPixelBuffer.cc b/src/gsi/gsi/gsiDeclTlPixelBuffer.cc similarity index 79% rename from src/laybasic/laybasic/gsiDeclLayPixelBuffer.cc rename to src/gsi/gsi/gsiDeclTlPixelBuffer.cc index 56653cf51..d4157b198 100644 --- a/src/laybasic/laybasic/gsiDeclLayPixelBuffer.cc +++ b/src/gsi/gsi/gsiDeclTlPixelBuffer.cc @@ -21,7 +21,7 @@ */ #include "gsiDecl.h" -#include "layPixelBuffer.h" +#include "tlPixelBuffer.h" #if defined(HAVE_QT) # include @@ -32,21 +32,21 @@ namespace gsi { // ------------------------------------------------------------------------------------- -// lay::BitmapBuffer +// tl::BitmapBuffer -static lay::PixelBuffer *create_pixel_buffer (unsigned int w, unsigned int h) +static tl::PixelBuffer *create_pixel_buffer (unsigned int w, unsigned int h) { - return new lay::PixelBuffer (w, h); + return new tl::PixelBuffer (w, h); } #if defined(HAVE_QT) && defined(HAVE_QTBINDINGS) -static void fill_with_qcolor (lay::PixelBuffer *pb, QColor c) +static void fill_with_qcolor (tl::PixelBuffer *pb, QColor c) { pb->fill (c.rgb ()); } #endif -tl::color_t get_pixel_from_pixel_buffer (const lay::PixelBuffer *pb, unsigned int x, unsigned int y) +tl::color_t get_pixel_from_pixel_buffer (const tl::PixelBuffer *pb, unsigned int x, unsigned int y) { if (x < pb->width () && y < pb->height ()) { return pb->scan_line (y)[x]; @@ -55,7 +55,7 @@ tl::color_t get_pixel_from_pixel_buffer (const lay::PixelBuffer *pb, unsigned in } } -void set_pixel_in_pixel_buffer (lay::PixelBuffer *pb, unsigned int x, unsigned int y, tl::color_t c) +void set_pixel_in_pixel_buffer (tl::PixelBuffer *pb, unsigned int x, unsigned int y, tl::color_t c) { if (! pb->transparent ()) { c |= 0xff000000; // ensures that alpha is set properly even if not required @@ -65,41 +65,41 @@ void set_pixel_in_pixel_buffer (lay::PixelBuffer *pb, unsigned int x, unsigned i } } -static lay::PixelBuffer read_pixel_buffer (const std::string &file) +static tl::PixelBuffer read_pixel_buffer (const std::string &file) { #if defined(HAVE_PNG) tl::InputStream stream (file); - return lay::PixelBuffer::read_png (stream); + return tl::PixelBuffer::read_png (stream); #elif defined(HAVE_QT) && defined(HAVE_QTBINDINGS) // QImage is fallback QImage img; img.load (tl::to_qstring (file), "PNG"); - return lay::PixelBuffer::from_image (img); + return tl::PixelBuffer::from_image (img); #else throw tl::Exception (tl::to_string (tr ("No PNG support compiled in for PixelBuffer"))); - return lay::PixelBuffer (); + return tl::PixelBuffer (); #endif } // TODO: there should be some more efficient version of byte strings which avoid copies -static lay::PixelBuffer pixel_buffer_from_png (const std::vector &data) +static tl::PixelBuffer pixel_buffer_from_png (const std::vector &data) { #if defined(HAVE_PNG) tl::InputMemoryStream data_stream (data.begin ().operator-> (), data.size ()); tl::InputStream stream (data_stream); - return lay::PixelBuffer::read_png (stream); + return tl::PixelBuffer::read_png (stream); #elif defined(HAVE_QT) && defined(HAVE_QTBINDINGS) // QImage is fallback tl_assert (data.size () < std::numeric_limits::max ()); QImage img = QImage::fromData ((const uchar *) data.begin ().operator-> (), int (data.size ())); - return lay::PixelBuffer::from_image (img); + return tl::PixelBuffer::from_image (img); #else throw tl::Exception (tl::to_string (tr ("No PNG support compiled in for PixelBuffer"))); - return lay::PixelBuffer (); + return tl::PixelBuffer (); #endif } -static void write_pixel_buffer (const lay::PixelBuffer *pb, const std::string &file) +static void write_pixel_buffer (const tl::PixelBuffer *pb, const std::string &file) { #if defined(HAVE_PNG) tl::OutputStream stream (file); @@ -114,7 +114,7 @@ static void write_pixel_buffer (const lay::PixelBuffer *pb, const std::string &f } // TODO: there should be some more efficient version of byte strings which avoid copies -static std::vector pixel_buffer_to_png (const lay::PixelBuffer *pb) +static std::vector pixel_buffer_to_png (const tl::PixelBuffer *pb) { #if defined(HAVE_PNG) tl::OutputMemoryStream data_stream; @@ -135,7 +135,7 @@ static std::vector pixel_buffer_to_png (const lay::PixelBuffer *pb) } -Class decl_PixelBuffer ("lay", "PixelBuffer", +Class decl_PixelBuffer ("lay", "PixelBuffer", gsi::constructor ("new", &create_pixel_buffer, gsi::arg ("width"), gsi::arg ("height"), "@brief Creates a pixel buffer object\n" "\n" @@ -144,21 +144,21 @@ Class decl_PixelBuffer ("lay", "PixelBuffer", "\n" "The pixels are basically uninitialized. You will need to use \\fill to initialize them to a certain value." ) + - gsi::method ("==", &lay::PixelBuffer::operator==, gsi::arg ("other"), + gsi::method ("==", &tl::PixelBuffer::operator==, gsi::arg ("other"), "@brief Returns a value indicating whether self is identical to the other image\n" ) + - gsi::method ("!=", &lay::PixelBuffer::operator!=, gsi::arg ("other"), + gsi::method ("!=", &tl::PixelBuffer::operator!=, gsi::arg ("other"), "@brief Returns a value indicating whether self is not identical to the other image\n" ) + - gsi::method ("transparent=", &lay::PixelBuffer::set_transparent, gsi::arg ("t"), + gsi::method ("transparent=", &tl::PixelBuffer::set_transparent, gsi::arg ("t"), "@brief Sets a flag indicating whether the pixel buffer supports an alpha channel\n" "\n" "By default, the pixel buffer does not support an alpha channel.\n" ) + - gsi::method ("transparent", &lay::PixelBuffer::transparent, + gsi::method ("transparent", &tl::PixelBuffer::transparent, "@brief Gets a flag indicating whether the pixel buffer supports an alpha channel\n" ) + - gsi::method ("fill", &lay::PixelBuffer::fill, gsi::arg ("color"), + gsi::method ("fill", &tl::PixelBuffer::fill, gsi::arg ("color"), "@brief Fills the pixel buffer with the given pixel value\n" ) + #if defined(HAVE_QT) && defined(HAVE_QTBINDINGS) @@ -166,13 +166,13 @@ Class decl_PixelBuffer ("lay", "PixelBuffer", "@brief Fills the pixel buffer with the given QColor\n" ) + #endif - gsi::method ("swap", &lay::PixelBuffer::swap, gsi::arg ("other"), + gsi::method ("swap", &tl::PixelBuffer::swap, gsi::arg ("other"), "@brief Swaps data with another PixelBuffer object\n" ) + - gsi::method ("width", &lay::PixelBuffer::width, + gsi::method ("width", &tl::PixelBuffer::width, "@brief Gets the width of the pixel buffer in pixels\n" ) + - gsi::method ("height", &lay::PixelBuffer::height, + gsi::method ("height", &tl::PixelBuffer::height, "@brief Gets the height of the pixel buffer in pixels\n" ) + gsi::method_ext ("set_pixel", &set_pixel_in_pixel_buffer, gsi::arg ("x"), gsi::arg ("y"), gsi::arg ("c"), @@ -182,10 +182,10 @@ Class decl_PixelBuffer ("lay", "PixelBuffer", "@brief Gets the value of the pixel at position x, y\n" ) + #if defined(HAVE_QT) && defined(HAVE_QTBINDINGS) - gsi::method ("to_qimage", &lay::PixelBuffer::to_image_copy, + gsi::method ("to_qimage", &tl::PixelBuffer::to_image_copy, "@brief Converts the pixel buffer to a \\QImage object" ) + - gsi::method ("from_qimage", &lay::PixelBuffer::from_image, gsi::arg ("qimage"), + gsi::method ("from_qimage", &tl::PixelBuffer::from_image, gsi::arg ("qimage"), "@brief Creates a pixel buffer object from a QImage object\n" ) + #endif @@ -209,14 +209,14 @@ Class decl_PixelBuffer ("lay", "PixelBuffer", "\n" "This method may not be available if PNG support is not compiled into KLayout." ) + - gsi::method ("patch", &lay::PixelBuffer::patch, gsi::arg ("other"), + gsi::method ("patch", &tl::PixelBuffer::patch, gsi::arg ("other"), "@brief Patches another pixel buffer into this one\n" "\n" "This method is the inverse of \\diff - it will patch the difference image created by diff into this " "pixel buffer. Note that this method will not do true alpha blending and requires the other pixel buffer " "to have the same format than self. Self will be modified by this operation." ) + - gsi::method ("diff", &lay::PixelBuffer::diff, gsi::arg ("other"), + gsi::method ("diff", &tl::PixelBuffer::diff, gsi::arg ("other"), "@brief Creates a difference image\n" "\n" "This method is provided to support transfer of image differences - i.e. small updates instead of full images. " @@ -238,14 +238,14 @@ Class decl_PixelBuffer ("lay", "PixelBuffer", // ------------------------------------------------------------------------------------- -// lay::BitmapBuffer +// tl::BitmapBuffer -static lay::BitmapBuffer *create_bitmap_buffer (unsigned int w, unsigned int h) +static tl::BitmapBuffer *create_bitmap_buffer (unsigned int w, unsigned int h) { - return new lay::BitmapBuffer (w, h); + return new tl::BitmapBuffer (w, h); } -bool get_pixel_from_bitmap_buffer (const lay::BitmapBuffer *pb, unsigned int x, unsigned int y) +bool get_pixel_from_bitmap_buffer (const tl::BitmapBuffer *pb, unsigned int x, unsigned int y) { if (x < pb->width () && y < pb->height ()) { return (pb->scan_line (y)[x / 8] & (0x01 << (x % 8))) != 0; @@ -254,7 +254,7 @@ bool get_pixel_from_bitmap_buffer (const lay::BitmapBuffer *pb, unsigned int x, } } -void set_pixel_in_bitmap_buffer (lay::BitmapBuffer *pb, unsigned int x, unsigned int y, bool c) +void set_pixel_in_bitmap_buffer (tl::BitmapBuffer *pb, unsigned int x, unsigned int y, bool c) { if (x < pb->width () && y < pb->height ()) { if (c) { @@ -265,41 +265,41 @@ void set_pixel_in_bitmap_buffer (lay::BitmapBuffer *pb, unsigned int x, unsigned } } -static lay::BitmapBuffer read_bitmap_buffer (const std::string &file) +static tl::BitmapBuffer read_bitmap_buffer (const std::string &file) { #if defined(HAVE_PNG) tl::InputStream stream (file); - return lay::BitmapBuffer::read_png (stream); + return tl::BitmapBuffer::read_png (stream); #elif defined(HAVE_QT) && defined(HAVE_QTBINDINGS) // QImage is fallback QImage img; img.load (tl::to_qstring (file), "PNG"); - return lay::BitmapBuffer::from_image (img); + return tl::BitmapBuffer::from_image (img); #else throw tl::Exception (tl::to_string (tr ("No PNG support compiled in for BitmapBuffer"))); - return lay::BitmapBuffer (); + return tl::BitmapBuffer (); #endif } // TODO: there should be some more efficient version of byte strings which avoid copies -static lay::BitmapBuffer bitmap_buffer_from_png (const std::vector &data) +static tl::BitmapBuffer bitmap_buffer_from_png (const std::vector &data) { #if defined(HAVE_PNG) tl::InputMemoryStream data_stream (data.begin ().operator-> (), data.size ()); tl::InputStream stream (data_stream); - return lay::BitmapBuffer::read_png (stream); + return tl::BitmapBuffer::read_png (stream); #elif defined(HAVE_QT) && defined(HAVE_QTBINDINGS) // QImage is fallback tl_assert (data.size () < std::numeric_limits::max ()); QImage img = QImage::fromData ((const uchar *) data.begin ().operator-> (), int (data.size ())); - return lay::BitmapBuffer::from_image (img); + return tl::BitmapBuffer::from_image (img); #else throw tl::Exception (tl::to_string (tr ("No PNG support compiled in for BitmapBuffer"))); - return lay::BitmapBuffer (); + return tl::BitmapBuffer (); #endif } -static void write_bitmap_buffer (const lay::BitmapBuffer *pb, const std::string &file) +static void write_bitmap_buffer (const tl::BitmapBuffer *pb, const std::string &file) { #if defined(HAVE_PNG) tl::OutputStream stream (file); @@ -314,7 +314,7 @@ static void write_bitmap_buffer (const lay::BitmapBuffer *pb, const std::string } // TODO: there should be some more efficient version of byte strings which avoid copies -static std::vector bitmap_buffer_to_png (const lay::BitmapBuffer *pb) +static std::vector bitmap_buffer_to_png (const tl::BitmapBuffer *pb) { #if defined(HAVE_PNG) tl::OutputMemoryStream data_stream; @@ -335,7 +335,7 @@ static std::vector bitmap_buffer_to_png (const lay::BitmapBuffer *pb) } -Class decl_BitmapBuffer ("lay", "BitmapBuffer", +Class decl_BitmapBuffer ("lay", "BitmapBuffer", gsi::constructor ("new", &create_bitmap_buffer, gsi::arg ("width"), gsi::arg ("height"), "@brief Creates a pixel buffer object\n" "\n" @@ -344,13 +344,13 @@ Class decl_BitmapBuffer ("lay", "BitmapBuffer", "\n" "The pixels are basically uninitialized. You will need to use \\fill to initialize them to a certain value." ) + - gsi::method ("==", &lay::BitmapBuffer::operator==, gsi::arg ("other"), + gsi::method ("==", &tl::BitmapBuffer::operator==, gsi::arg ("other"), "@brief Returns a value indicating whether self is identical to the other image\n" ) + - gsi::method ("!=", &lay::BitmapBuffer::operator!=, gsi::arg ("other"), + gsi::method ("!=", &tl::BitmapBuffer::operator!=, gsi::arg ("other"), "@brief Returns a value indicating whether self is not identical to the other image\n" ) + - gsi::method ("fill", &lay::BitmapBuffer::fill, gsi::arg ("color"), + gsi::method ("fill", &tl::BitmapBuffer::fill, gsi::arg ("color"), "@brief Fills the pixel buffer with the given pixel value\n" ) + #if defined(HAVE_QT) && defined(HAVE_QTBINDINGS) @@ -358,13 +358,13 @@ Class decl_BitmapBuffer ("lay", "BitmapBuffer", "@brief Fills the pixel buffer with the given QColor\n" ) + #endif - gsi::method ("swap", &lay::BitmapBuffer::swap, gsi::arg ("other"), + gsi::method ("swap", &tl::BitmapBuffer::swap, gsi::arg ("other"), "@brief Swaps data with another BitmapBuffer object\n" ) + - gsi::method ("width", &lay::BitmapBuffer::width, + gsi::method ("width", &tl::BitmapBuffer::width, "@brief Gets the width of the pixel buffer in pixels\n" ) + - gsi::method ("height", &lay::BitmapBuffer::height, + gsi::method ("height", &tl::BitmapBuffer::height, "@brief Gets the height of the pixel buffer in pixels\n" ) + gsi::method_ext ("set_pixel", &set_pixel_in_bitmap_buffer, gsi::arg ("x"), gsi::arg ("y"), gsi::arg ("c"), @@ -374,10 +374,10 @@ Class decl_BitmapBuffer ("lay", "BitmapBuffer", "@brief Gets the value of the pixel at position x, y\n" ) + #if defined(HAVE_QT) && defined(HAVE_QTBINDINGS) - gsi::method ("to_qimage", &lay::BitmapBuffer::to_image_copy, + gsi::method ("to_qimage", &tl::BitmapBuffer::to_image_copy, "@brief Converts the pixel buffer to a \\QImage object" ) + - gsi::method ("from_qimage", &lay::BitmapBuffer::from_image, gsi::arg ("qimage"), + gsi::method ("from_qimage", &tl::BitmapBuffer::from_image, gsi::arg ("qimage"), "@brief Creates a pixel buffer object from a QImage object\n" ) + #endif diff --git a/src/img/img/imgObject.cc b/src/img/img/imgObject.cc index 166ee9ebc..72389361b 100644 --- a/src/img/img/imgObject.cc +++ b/src/img/img/imgObject.cc @@ -27,7 +27,7 @@ #include "tlTimer.h" #include "layPlugin.h" #include "layConverters.h" -#include "layPixelBuffer.h" +#include "tlPixelBuffer.h" #include "dbPolygonTools.h" #include "tlFileUtils.h" #include "tlUri.h" @@ -1628,11 +1628,11 @@ Object::read_file () #elif defined(HAVE_PNG) - lay::PixelBuffer img; + tl::PixelBuffer img; { tl::InputStream stream (m_filename); - img = lay::PixelBuffer::read_png (stream); + img = tl::PixelBuffer::read_png (stream); } bool is_color = false; diff --git a/src/img/img/imgService.cc b/src/img/img/imgService.cc index daae974d7..6c9e2ec78 100644 --- a/src/img/img/imgService.cc +++ b/src/img/img/imgService.cc @@ -90,7 +90,7 @@ private: // ------------------------------------------------------------- static void -draw_scanline (unsigned int level, const img::Object &image_object, lay::PixelBuffer &pxbuffer, int y, const db::Matrix3d &t, const db::Matrix3d &it, const db::DPoint &q1, const db::DPoint &q2) +draw_scanline (unsigned int level, const img::Object &image_object, tl::PixelBuffer &pxbuffer, int y, const db::Matrix3d &t, const db::Matrix3d &it, const db::DPoint &q1, const db::DPoint &q2) { double source_width = image_object.width (); double source_height = image_object.height (); @@ -155,7 +155,7 @@ draw_image (const img::Object &image_object, const lay::Viewport &vp, lay::ViewO return; } - lay::PixelBuffer &image = *bmp_canvas->bg_image (); + tl::PixelBuffer &image = *bmp_canvas->bg_image (); db::DBox source_image_box (0.0, 0.0, image_object.width (), image_object.height ()); // safety measure to avoid division by zero. diff --git a/src/laybasic/laybasic/gsiDeclLayLayoutViewBase.cc b/src/laybasic/laybasic/gsiDeclLayLayoutViewBase.cc index 2771c4b24..d142c2a4c 100644 --- a/src/laybasic/laybasic/gsiDeclLayLayoutViewBase.cc +++ b/src/laybasic/laybasic/gsiDeclLayLayoutViewBase.cc @@ -327,12 +327,12 @@ static void save_as2 (lay::LayoutViewBase *view, unsigned int index, const std:: view->save_as (index, filename, tl::OutputStream::OM_Auto, options, true, 0); } -static lay::PixelBuffer get_pixels_with_options (lay::LayoutViewBase *view, unsigned int width, unsigned int height, int linewidth, int oversampling, double resolution, const db::DBox &target_box) +static tl::PixelBuffer get_pixels_with_options (lay::LayoutViewBase *view, unsigned int width, unsigned int height, int linewidth, int oversampling, double resolution, const db::DBox &target_box) { return view->get_pixels_with_options (width, height, linewidth, oversampling, resolution, tl::Color (), tl::Color (), tl::Color (), target_box); } -static lay::BitmapBuffer get_pixels_with_options_mono (lay::LayoutViewBase *view, unsigned int width, unsigned int height, int linewidth, const db::DBox &target_box) +static tl::BitmapBuffer get_pixels_with_options_mono (lay::LayoutViewBase *view, unsigned int width, unsigned int height, int linewidth, const db::DBox &target_box) { return view->get_pixels_with_options_mono (width, height, linewidth, tl::Color (), tl::Color (), tl::Color (), target_box); } @@ -1129,7 +1129,7 @@ LAYBASIC_PUBLIC Class decl_LayoutViewBase (QT_EXTERNAL_BASE "This method has been introduced in 0.23.10.\n" ) + #endif - gsi::method ("get_screenshot_pixels", static_cast (&lay::LayoutViewBase::get_screenshot_pb), + gsi::method ("get_screenshot_pixels", static_cast (&lay::LayoutViewBase::get_screenshot_pb), "@brief Gets a screenshot as a \\PixelBuffer\n" "\n" "Getting the image requires the drawing to be complete. Ideally, synchronous mode is switched on " @@ -1138,7 +1138,7 @@ LAYBASIC_PUBLIC Class decl_LayoutViewBase (QT_EXTERNAL_BASE "\n" "This method has been introduced in 0.28.\n" ) + - gsi::method ("get_pixels", static_cast (&lay::LayoutViewBase::get_pixels), gsi::arg ("width"), gsi::arg ("height"), + gsi::method ("get_pixels", static_cast (&lay::LayoutViewBase::get_pixels), gsi::arg ("width"), gsi::arg ("height"), "@brief Gets the layout image as a \\PixelBuffer\n" "\n" "@param width The width of the image to render in pixel.\n" diff --git a/src/laybasic/laybasic/layBitmapsToImage.cc b/src/laybasic/laybasic/layBitmapsToImage.cc index f155229cd..66d10b2d3 100644 --- a/src/laybasic/laybasic/layBitmapsToImage.cc +++ b/src/laybasic/laybasic/layBitmapsToImage.cc @@ -25,7 +25,7 @@ #include "layBitmap.h" #include "layDitherPattern.h" #include "layLineStyles.h" -#include "layPixelBuffer.h" +#include "tlPixelBuffer.h" #include "tlTimer.h" #include "tlAssert.h" #include "tlThreads.h" @@ -426,7 +426,7 @@ bitmaps_to_image (const std::vector &view_ops_in, const std::vector &pbitmaps_in, const lay::DitherPattern &dp, const lay::LineStyles &ls, - PixelBuffer *pimage, unsigned int width, unsigned int height, + tl::PixelBuffer *pimage, unsigned int width, unsigned int height, bool use_bitmap_index, tl::Mutex *mutex) { @@ -666,7 +666,7 @@ bitmaps_to_image (const std::vector &view_ops_in, const std::vector &pbitmaps_in, const lay::DitherPattern &dp, const lay::LineStyles &ls, - lay::BitmapBuffer *pimage, unsigned int width, unsigned int height, + tl::BitmapBuffer *pimage, unsigned int width, unsigned int height, bool use_bitmap_index, tl::Mutex *mutex) { diff --git a/src/laybasic/laybasic/layBitmapsToImage.h b/src/laybasic/laybasic/layBitmapsToImage.h index 3520fdaf5..000f964c1 100644 --- a/src/laybasic/laybasic/layBitmapsToImage.h +++ b/src/laybasic/laybasic/layBitmapsToImage.h @@ -29,14 +29,18 @@ #include +namespace tl +{ + class PixelBuffer; + class BitmapBuffer; +} + namespace lay { class DitherPattern; class LineStyles; class Bitmap; -class PixelBuffer; -class BitmapBuffer; /** * @brief This function converts the given set of bitmaps to a PixelBuffer @@ -58,7 +62,7 @@ bitmaps_to_image (const std::vector &view_ops, const std::vector &pbitmaps, const lay::DitherPattern &dp, const lay::LineStyles &ls, - lay::PixelBuffer *pimage, unsigned int width, unsigned int height, + tl::PixelBuffer *pimage, unsigned int width, unsigned int height, bool use_bitmap_index, tl::Mutex *mutex); @@ -72,12 +76,12 @@ bitmaps_to_image (const std::vector &view_ops, const std::vector &pbitmaps, const lay::DitherPattern &dp, const lay::LineStyles &ls, - lay::BitmapBuffer *pimage, unsigned int width, unsigned int height, + tl::BitmapBuffer *pimage, unsigned int width, unsigned int height, bool use_bitmap_index, tl::Mutex *mutex); /** - * @brief Convert a lay::Bitmap to a unsigned char * data field to be passed to lay::BitmapBuffer + * @brief Convert a lay::Bitmap to a unsigned char * data field to be passed to tl::BitmapBuffer * * This function converts the bitmap given the view_op into a raw byte data * field that can be passed to a QBitmap constructor. The data field is not diff --git a/src/laybasic/laybasic/layLayoutCanvas.cc b/src/laybasic/laybasic/layLayoutCanvas.cc index 3d5c89f8d..d4320a814 100644 --- a/src/laybasic/laybasic/layLayoutCanvas.cc +++ b/src/laybasic/laybasic/layLayoutCanvas.cc @@ -132,7 +132,7 @@ std::string ImageCacheEntry::to_string () const // ---------------------------------------------------------------------------- static void -blowup (const lay::PixelBuffer &src, lay::PixelBuffer &dest, unsigned int os) +blowup (const tl::PixelBuffer &src, tl::PixelBuffer &dest, unsigned int os) { unsigned int ymax = src.height (); unsigned int xmax = src.width (); @@ -152,7 +152,7 @@ blowup (const lay::PixelBuffer &src, lay::PixelBuffer &dest, unsigned int os) } static void -subsample (const lay::PixelBuffer &src, lay::PixelBuffer &dest, unsigned int os, double g) +subsample (const tl::PixelBuffer &src, tl::PixelBuffer &dest, unsigned int os, double g) { // TODO: this is probably not compatible with the endianess of SPARC .. @@ -448,7 +448,7 @@ LayoutCanvas::prepare_drawing () if (mp_image) { delete mp_image; } - mp_image = new lay::PixelBuffer (m_viewport_l.width (), m_viewport_l.height ()); + mp_image = new tl::PixelBuffer (m_viewport_l.width (), m_viewport_l.height ()); if (mp_image_fg) { delete mp_image_fg; mp_image_fg = 0; @@ -589,7 +589,7 @@ LayoutCanvas::paint_event () if (mp_image_bg) { delete mp_image_bg; } - mp_image_bg = new lay::PixelBuffer (*mp_image); + mp_image_bg = new tl::PixelBuffer (*mp_image); } else { // else reuse the saved image @@ -622,18 +622,18 @@ LayoutCanvas::paint_event () clear_fg_bitmaps (); do_render (m_viewport_l, *this, true); - mp_image_fg = new lay::PixelBuffer (); + mp_image_fg = new tl::PixelBuffer (); if (fg_bitmaps () > 0) { - lay::PixelBuffer full_image (*mp_image); + tl::PixelBuffer full_image (*mp_image); bitmaps_to_image (fg_view_op_vector (), fg_bitmap_vector (), dither_pattern (), line_styles (), &full_image, m_viewport_l.width (), m_viewport_l.height (), false, &m_mutex); // render the foreground parts .. if (m_oversampling == 1) { *mp_image_fg = full_image; } else { - lay::PixelBuffer subsampled_image (m_viewport.width (), m_viewport.height ()); + tl::PixelBuffer subsampled_image (m_viewport.width (), m_viewport.height ()); subsampled_image.set_transparent (mp_image->transparent ()); subsample (full_image, subsampled_image, m_oversampling, m_gamma); *mp_image_fg = subsampled_image; @@ -645,7 +645,7 @@ LayoutCanvas::paint_event () } else { - lay::PixelBuffer subsampled_image (m_viewport.width (), m_viewport.height ()); + tl::PixelBuffer subsampled_image (m_viewport.width (), m_viewport.height ()); subsampled_image.set_transparent (mp_image->transparent ()); subsample (*mp_image, subsampled_image, m_oversampling, m_gamma); *mp_image_fg = subsampled_image; @@ -670,7 +670,7 @@ LayoutCanvas::paint_event () if (fg_bitmaps () > 0) { - lay::PixelBuffer full_image (mp_image->width (), mp_image->height ()); + tl::PixelBuffer full_image (mp_image->width (), mp_image->height ()); full_image.set_transparent (true); full_image.fill (0); @@ -684,7 +684,7 @@ LayoutCanvas::paint_event () #endif painter.drawImage (QPoint (0, 0), img); } else { - lay::PixelBuffer subsampled_image (m_viewport.width (), m_viewport.height ()); + tl::PixelBuffer subsampled_image (m_viewport.width (), m_viewport.height ()); subsampled_image.set_transparent (true); subsample (full_image, subsampled_image, m_oversampling, m_gamma); QImage img = subsampled_image.to_image (); @@ -712,7 +712,7 @@ class DetachedViewObjectCanvas : public BitmapViewObjectCanvas { public: - DetachedViewObjectCanvas (tl::Color bg, tl::Color fg, tl::Color ac, unsigned int width_l, unsigned int height_l, double resolution, lay::PixelBuffer *img) + DetachedViewObjectCanvas (tl::Color bg, tl::Color fg, tl::Color ac, unsigned int width_l, unsigned int height_l, double resolution, tl::PixelBuffer *img) : BitmapViewObjectCanvas (width_l, height_l, resolution), m_bg (bg), m_fg (fg), m_ac (ac), mp_image (img) { @@ -720,7 +720,7 @@ public: m_gamma = 2.0; if (img->width () != width_l || img->height () != height_l) { - mp_image_l = new lay::PixelBuffer (width_l, height_l); + mp_image_l = new tl::PixelBuffer (width_l, height_l); mp_image_l->set_transparent (img->transparent ()); mp_image_l->fill (bg.rgb ()); } else { @@ -753,7 +753,7 @@ public: return m_ac; } - virtual lay::PixelBuffer *bg_image () + virtual tl::PixelBuffer *bg_image () { return mp_image_l ? mp_image_l : mp_image; } @@ -781,8 +781,8 @@ public: private: tl::Color m_bg, m_fg, m_ac; - lay::PixelBuffer *mp_image; - lay::PixelBuffer *mp_image_l; + tl::PixelBuffer *mp_image; + tl::PixelBuffer *mp_image_l; double m_gamma; }; @@ -828,13 +828,13 @@ private: bool m_bg, m_fg, m_ac; }; -lay::PixelBuffer +tl::PixelBuffer LayoutCanvas::image (unsigned int width, unsigned int height) { return image_with_options (width, height, -1, -1, -1.0, tl::Color (), tl::Color (), tl::Color (), db::DBox ()); } -lay::PixelBuffer +tl::PixelBuffer LayoutCanvas::image_with_options (unsigned int width, unsigned int height, int linewidth, int oversampling, double resolution, tl::Color background, tl::Color foreground, tl::Color active, const db::DBox &target_box) { if (oversampling <= 0) { @@ -857,7 +857,7 @@ LayoutCanvas::image_with_options (unsigned int width, unsigned int height, int l } // TODO: for other architectures MonoLSB may not be the right format - lay::PixelBuffer img (width, height); + tl::PixelBuffer img (width, height); // this may happen for BIG images: if (img.width () != width || img.height () != height) { @@ -910,7 +910,7 @@ LayoutCanvas::image_with_options (unsigned int width, unsigned int height, int l return img; } -lay::BitmapBuffer +tl::BitmapBuffer LayoutCanvas::image_with_options_mono (unsigned int width, unsigned int height, int linewidth, tl::Color background_c, tl::Color foreground_c, tl::Color active_c, const db::DBox &target_box) { if (linewidth <= 0) { @@ -946,7 +946,7 @@ LayoutCanvas::image_with_options_mono (unsigned int width, unsigned int height, redraw_thread.start (0 /*synchronous*/, m_layers, vp, 1.0, true); redraw_thread.stop (); // safety - lay::BitmapBuffer img (width, height); + tl::BitmapBuffer img (width, height); img.fill (background); rd_canvas.to_image_mono (view_ops, dither_pattern (), line_styles (), background, foreground, active, this, img, vp.width (), vp.height ()); @@ -954,13 +954,13 @@ LayoutCanvas::image_with_options_mono (unsigned int width, unsigned int height, return img; } -lay::PixelBuffer +tl::PixelBuffer LayoutCanvas::screenshot () { // if required, start the redraw thread .. prepare_drawing (); - lay::PixelBuffer img (m_viewport.width (), m_viewport.height ()); + tl::PixelBuffer img (m_viewport.width (), m_viewport.height ()); img.fill (m_background); DetachedViewObjectCanvas vo_canvas (background_color (), foreground_color (), active_color (), m_viewport_l.width (), m_viewport_l.height (), 1.0 / double (m_oversampling * m_dpr), &img); diff --git a/src/laybasic/laybasic/layLayoutCanvas.h b/src/laybasic/laybasic/layLayoutCanvas.h index d4495b147..1b5241873 100644 --- a/src/laybasic/laybasic/layLayoutCanvas.h +++ b/src/laybasic/laybasic/layLayoutCanvas.h @@ -164,10 +164,10 @@ public: return m_view_ops; } - lay::PixelBuffer screenshot (); - lay::PixelBuffer image (unsigned int width, unsigned int height); - lay::PixelBuffer image_with_options (unsigned int width, unsigned int height, int linewidth, int oversampling, double resolution, tl::Color background, tl::Color foreground, tl::Color active_color, const db::DBox &target_box); - lay::BitmapBuffer image_with_options_mono (unsigned int width, unsigned int height, int linewidth, tl::Color background, tl::Color foreground, tl::Color active, const db::DBox &target_box); + tl::PixelBuffer screenshot (); + tl::PixelBuffer image (unsigned int width, unsigned int height); + tl::PixelBuffer image_with_options (unsigned int width, unsigned int height, int linewidth, int oversampling, double resolution, tl::Color background, tl::Color foreground, tl::Color active_color, const db::DBox &target_box); + tl::BitmapBuffer image_with_options_mono (unsigned int width, unsigned int height, int linewidth, tl::Color background, tl::Color foreground, tl::Color active, const db::DBox &target_box); void update_image (); @@ -312,7 +312,7 @@ public: /** * @brief Reimplementation of ViewObjectCanvas: background image */ - lay::PixelBuffer *bg_image () + tl::PixelBuffer *bg_image () { return mp_image; } @@ -358,9 +358,9 @@ public: private: lay::LayoutViewBase *mp_view; - lay::PixelBuffer *mp_image; - lay::PixelBuffer *mp_image_bg; - lay::PixelBuffer *mp_image_fg; + tl::PixelBuffer *mp_image; + tl::PixelBuffer *mp_image_bg; + tl::PixelBuffer *mp_image_fg; db::DBox m_precious_box; lay::Viewport m_viewport, m_viewport_l; tl::color_t m_background; diff --git a/src/laybasic/laybasic/layLayoutViewBase.cc b/src/laybasic/laybasic/layLayoutViewBase.cc index a9753b596..9a31ad0ba 100644 --- a/src/laybasic/laybasic/layLayoutViewBase.cc +++ b/src/laybasic/laybasic/layLayoutViewBase.cc @@ -2534,7 +2534,7 @@ LayoutViewBase::get_screenshot () } #endif -lay::PixelBuffer +tl::PixelBuffer LayoutViewBase::get_screenshot_pb () { tl::SelfTimer timer (tl::verbosity () >= 11, tl::to_string (tr ("Save screenshot"))); @@ -2597,7 +2597,7 @@ LayoutViewBase::save_screenshot (const std::string &fn) tl::DeferredMethodScheduler::execute (); tl::OutputStream stream (fn); - lay::PixelBuffer img = mp_canvas->screenshot (); + tl::PixelBuffer img = mp_canvas->screenshot (); img.set_texts (png_texts (this, box ())); img.write_png (stream); @@ -2624,7 +2624,7 @@ LayoutViewBase::get_image (unsigned int width, unsigned int height) } #endif -lay::PixelBuffer +tl::PixelBuffer LayoutViewBase::get_pixels (unsigned int width, unsigned int height) { tl::SelfTimer timer (tl::verbosity () >= 11, tl::to_string (tr ("Get image"))); @@ -2653,7 +2653,7 @@ LayoutViewBase::get_image_with_options (unsigned int width, unsigned int height, } #endif -lay::PixelBuffer +tl::PixelBuffer LayoutViewBase::get_pixels_with_options (unsigned int width, unsigned int height, int linewidth, int oversampling, double resolution, tl::Color background, tl::Color foreground, tl::Color active, const db::DBox &target_box) { @@ -2665,7 +2665,7 @@ LayoutViewBase::get_pixels_with_options (unsigned int width, unsigned int height return mp_canvas->image_with_options (width, height, linewidth, oversampling, resolution, background, foreground, active, target_box); } -lay::BitmapBuffer +tl::BitmapBuffer LayoutViewBase::get_pixels_with_options_mono (unsigned int width, unsigned int height, int linewidth, tl::Color background, tl::Color foreground, tl::Color active, const db::DBox &target_box) { @@ -2712,7 +2712,7 @@ LayoutViewBase::save_image (const std::string &fn, unsigned int width, unsigned tl::DeferredMethodScheduler::execute (); tl::OutputStream stream (fn); - lay::PixelBuffer img = mp_canvas->image (width, height); + tl::PixelBuffer img = mp_canvas->image (width, height); std::vector > texts = png_texts (this, vp.box ()); img.set_texts (texts); img.write_png (stream); @@ -2775,13 +2775,13 @@ LayoutViewBase::save_image_with_options (const std::string &fn, tl::OutputStream stream (fn); if (monochrome) { - lay::BitmapBuffer img = mp_canvas->image_with_options_mono (width, height, linewidth, background, foreground, active, target_box); + tl::BitmapBuffer img = mp_canvas->image_with_options_mono (width, height, linewidth, background, foreground, active, target_box); img.set_texts (texts); img.write_png (stream); } else { - lay::PixelBuffer img = mp_canvas->image_with_options (width, height, linewidth, oversampling, resolution, background, foreground, active, target_box); + tl::PixelBuffer img = mp_canvas->image_with_options (width, height, linewidth, oversampling, resolution, background, foreground, active, target_box); img.set_texts (texts); img.write_png (stream); diff --git a/src/laybasic/laybasic/layLayoutViewBase.h b/src/laybasic/laybasic/layLayoutViewBase.h index e3e31e1cc..53d20dd93 100644 --- a/src/laybasic/laybasic/layLayoutViewBase.h +++ b/src/laybasic/laybasic/layLayoutViewBase.h @@ -837,9 +837,9 @@ public: #endif /** - * @brief Gets the screen content as a lay::PixelBuffer object + * @brief Gets the screen content as a tl::PixelBuffer object */ - lay::PixelBuffer get_screenshot_pb (); + tl::PixelBuffer get_screenshot_pb (); /** * @brief Save an image file with the given width and height @@ -871,9 +871,9 @@ public: #endif /** - * @brief Gets the screen content as a lay::PixelBuffer object + * @brief Gets the screen content as a tl::PixelBuffer object */ - lay::PixelBuffer get_pixels (unsigned int width, unsigned int height); + tl::PixelBuffer get_pixels (unsigned int width, unsigned int height); #if defined(HAVE_QT) /** @@ -894,7 +894,7 @@ public: #endif /** - * @brief Get the screen content as a lay::PixelBuffer object with the given width and height + * @brief Get the screen content as a tl::PixelBuffer object with the given width and height * * @param width The width of the image in pixels * @param height The height of the image @@ -906,10 +906,10 @@ public: * @param active The active color or tl::Color() for default * @param target_box The box to draw or db::DBox() for default */ - lay::PixelBuffer get_pixels_with_options (unsigned int width, unsigned int height, int linewidth, int oversampling, double resolution, tl::Color background, tl::Color foreground, tl::Color active_color, const db::DBox &target_box); + tl::PixelBuffer get_pixels_with_options (unsigned int width, unsigned int height, int linewidth, int oversampling, double resolution, tl::Color background, tl::Color foreground, tl::Color active_color, const db::DBox &target_box); /** - * @brief Get the screen content as a monochrome lay::BitmapBuffer object with the given options + * @brief Get the screen content as a monochrome tl::BitmapBuffer object with the given options * * @param width The width of the image in pixels * @param height The height of the image @@ -923,7 +923,7 @@ public: * * The colors will are converted to "on" pixels with a green channel value >= 50%. */ - lay::BitmapBuffer get_pixels_with_options_mono (unsigned int width, unsigned int height, int linewidth, tl::Color background, tl::Color foreground, tl::Color active_color, const db::DBox &target_box); + tl::BitmapBuffer get_pixels_with_options_mono (unsigned int width, unsigned int height, int linewidth, tl::Color background, tl::Color foreground, tl::Color active_color, const db::DBox &target_box); /** * @brief Hierarchy level selection setter diff --git a/src/laybasic/laybasic/layPixelBufferPainter.cc b/src/laybasic/laybasic/layPixelBufferPainter.cc index b846a417e..9afe397d2 100644 --- a/src/laybasic/laybasic/layPixelBufferPainter.cc +++ b/src/laybasic/laybasic/layPixelBufferPainter.cc @@ -23,12 +23,12 @@ #include "layPixelBufferPainter.h" #include "layFixedFont.h" -#include "layPixelBuffer.h" +#include "tlPixelBuffer.h" namespace lay { -PixelBufferPainter::PixelBufferPainter (lay::PixelBuffer &img, unsigned int width, unsigned int height, double resolution) +PixelBufferPainter::PixelBufferPainter (tl::PixelBuffer &img, unsigned int width, unsigned int height, double resolution) : mp_img (&img), m_resolution (resolution), m_width (width), m_height (height) { diff --git a/src/laybasic/laybasic/layPixelBufferPainter.h b/src/laybasic/laybasic/layPixelBufferPainter.h index 077aea1a7..480adbd2f 100644 --- a/src/laybasic/laybasic/layPixelBufferPainter.h +++ b/src/laybasic/laybasic/layPixelBufferPainter.h @@ -28,12 +28,15 @@ #include "tlColor.h" #include "dbPoint.h" +namespace tl +{ + class PixelBuffer; +} + namespace lay { -class PixelBuffer; - /** - * @brief A very simplistic painter for lay::PixelBuffer + * @brief A very simplistic painter for tl::PixelBuffer * * This painter supports very few primitives currently and is used to paint the * background grid for example. @@ -41,7 +44,7 @@ class PixelBuffer; class LAYBASIC_PUBLIC PixelBufferPainter { public: - PixelBufferPainter (lay::PixelBuffer &img, unsigned int width, unsigned int height, double resolution); + PixelBufferPainter (tl::PixelBuffer &img, unsigned int width, unsigned int height, double resolution); void set (const db::Point &p, tl::Color c); void draw_line (const db::Point &p1, const db::Point &p2, tl::Color c); @@ -50,7 +53,7 @@ public: void draw_text (const char *t, const db::Point &p, tl::Color c, int halign, int valign); private: - lay::PixelBuffer *mp_img; + tl::PixelBuffer *mp_img; double m_resolution; int m_width, m_height; }; diff --git a/src/laybasic/laybasic/layRedrawThreadCanvas.cc b/src/laybasic/laybasic/layRedrawThreadCanvas.cc index 9772379d2..ff5c6228a 100644 --- a/src/laybasic/laybasic/layRedrawThreadCanvas.cc +++ b/src/laybasic/laybasic/layRedrawThreadCanvas.cc @@ -392,7 +392,7 @@ BitmapRedrawThreadCanvas::initialize_plane (lay::CanvasPlane *plane, unsigned in } void -BitmapRedrawThreadCanvas::to_image (const std::vector &view_ops, const lay::DitherPattern &dp, const lay::LineStyles &ls, tl::Color background, tl::Color foreground, tl::Color active, const lay::Drawings *drawings, lay::PixelBuffer &img, unsigned int width, unsigned int height) +BitmapRedrawThreadCanvas::to_image (const std::vector &view_ops, const lay::DitherPattern &dp, const lay::LineStyles &ls, tl::Color background, tl::Color foreground, tl::Color active, const lay::Drawings *drawings, tl::PixelBuffer &img, unsigned int width, unsigned int height) { if (width > m_width) { width = m_width; @@ -412,7 +412,7 @@ BitmapRedrawThreadCanvas::to_image (const std::vector &view_ops, c } void -BitmapRedrawThreadCanvas::to_image_mono (const std::vector &view_ops, const lay::DitherPattern &dp, const lay::LineStyles &ls, bool background, bool foreground, bool active, const lay::Drawings *drawings, lay::BitmapBuffer &img, unsigned int width, unsigned int height) +BitmapRedrawThreadCanvas::to_image_mono (const std::vector &view_ops, const lay::DitherPattern &dp, const lay::LineStyles &ls, bool background, bool foreground, bool active, const lay::Drawings *drawings, tl::BitmapBuffer &img, unsigned int width, unsigned int height) { if (width > m_width) { width = m_width; diff --git a/src/laybasic/laybasic/layRedrawThreadCanvas.h b/src/laybasic/laybasic/layRedrawThreadCanvas.h index 0a36cc3b5..8fdab9f0e 100644 --- a/src/laybasic/laybasic/layRedrawThreadCanvas.h +++ b/src/laybasic/laybasic/layRedrawThreadCanvas.h @@ -29,7 +29,7 @@ #include "dbTrans.h" #include "layViewOp.h" #include "layBitmapRenderer.h" -#include "layPixelBuffer.h" +#include "tlPixelBuffer.h" #include "tlThreads.h" #include @@ -319,12 +319,12 @@ public: /** * @brief Transfer the content to a PixelBuffer */ - void to_image (const std::vector &view_ops, const lay::DitherPattern &dp, const lay::LineStyles &ls, tl::Color background, tl::Color foreground, tl::Color active, const lay::Drawings *drawings, PixelBuffer &img, unsigned int width, unsigned int height); + void to_image (const std::vector &view_ops, const lay::DitherPattern &dp, const lay::LineStyles &ls, tl::Color background, tl::Color foreground, tl::Color active, const lay::Drawings *drawings, tl::PixelBuffer &img, unsigned int width, unsigned int height); /** * @brief Transfer the content to a BitmapBuffer (monochrome) */ - void to_image_mono (const std::vector &view_ops, const lay::DitherPattern &dp, const lay::LineStyles &ls, bool background, bool foreground, bool active, const lay::Drawings *drawings, lay::BitmapBuffer &img, unsigned int width, unsigned int height); + void to_image_mono (const std::vector &view_ops, const lay::DitherPattern &dp, const lay::LineStyles &ls, bool background, bool foreground, bool active, const lay::Drawings *drawings, tl::BitmapBuffer &img, unsigned int width, unsigned int height); /** * @brief Gets the current bitmap data as a BitmapCanvasData object diff --git a/src/laybasic/laybasic/layViewObject.cc b/src/laybasic/laybasic/layViewObject.cc index 805e6c69f..c5167dd38 100644 --- a/src/laybasic/laybasic/layViewObject.cc +++ b/src/laybasic/laybasic/layViewObject.cc @@ -1357,13 +1357,13 @@ BitmapViewObjectCanvas::set_size (double resolution) m_resolution = resolution; } -lay::PixelBuffer * +tl::PixelBuffer * BitmapViewObjectCanvas::bg_image () { return 0; } -lay::BitmapBuffer * +tl::BitmapBuffer * BitmapViewObjectCanvas::bg_bitmap () { return 0; diff --git a/src/laybasic/laybasic/layViewObject.h b/src/laybasic/laybasic/layViewObject.h index 44f80e388..3ece60a4c 100644 --- a/src/laybasic/laybasic/layViewObject.h +++ b/src/laybasic/laybasic/layViewObject.h @@ -63,6 +63,12 @@ namespace db class Layout; } +namespace tl +{ + class PixelBuffer; + class BitmapBuffer; +} + namespace lay { class Viewport; @@ -70,8 +76,6 @@ class ViewObjectUI; class ViewObjectCanvas; class CanvasPlane; class Bitmap; -class PixelBuffer; -class BitmapBuffer; #if defined(HAVE_QT) class DragDropDataBase; @@ -1323,12 +1327,12 @@ public: /** * @brief Gets the pixel buffer that background objects render to */ - virtual lay::PixelBuffer *bg_image (); + virtual tl::PixelBuffer *bg_image (); /** * @brief Gets the monochrome pixel buffer that background objects render to */ - virtual lay::BitmapBuffer *bg_bitmap (); + virtual tl::BitmapBuffer *bg_bitmap (); private: std::map m_fg_bitmap_table; diff --git a/src/laybasic/laybasic/laybasic.pro b/src/laybasic/laybasic/laybasic.pro index d65643f2a..ba68de57c 100644 --- a/src/laybasic/laybasic/laybasic.pro +++ b/src/laybasic/laybasic/laybasic.pro @@ -36,7 +36,6 @@ SOURCES += \ gsiDeclLayLayoutViewBase.cc \ gsiDeclLayMarker.cc \ gsiDeclLayPlugin.cc \ - gsiDeclLayPixelBuffer.cc \ laybasicForceLink.cc \ layAnnotationShapes.cc \ layBitmap.cc \ @@ -64,7 +63,6 @@ SOURCES += \ layNetColorizer.cc \ layObjectInstPath.cc \ layParsedLayerSource.cc \ - layPixelBuffer.cc \ layPixelBufferPainter.cc \ layPlugin.cc \ layRedrawLayerInfo.cc \ @@ -116,7 +114,7 @@ HEADERS += \ layNetColorizer.h \ layObjectInstPath.h \ layParsedLayerSource.h \ - layPixelBuffer.h \ + tlPixelBuffer.h \ layPixelBufferPainter.h \ layPlugin.h \ layRedrawLayerInfo.h \ diff --git a/src/laybasic/unit_tests/layBitmapsToImage.cc b/src/laybasic/unit_tests/layBitmapsToImage.cc index 47d61206f..879924deb 100644 --- a/src/laybasic/unit_tests/layBitmapsToImage.cc +++ b/src/laybasic/unit_tests/layBitmapsToImage.cc @@ -24,11 +24,11 @@ #include "layBitmap.h" #include "layDitherPattern.h" #include "layLineStyles.h" -#include "layPixelBuffer.h" +#include "tlPixelBuffer.h" #include "tlUnitTest.h" std::string -to_string (const lay::PixelBuffer &img, unsigned int mask) +to_string (const tl::PixelBuffer &img, unsigned int mask) { std::string s; for (unsigned int i = 0; i < 32; ++i) { @@ -85,7 +85,7 @@ TEST(1) view_ops.push_back (lay::ViewOp (0x000080, lay::ViewOp::Copy, 0, 0, 0, lay::ViewOp::Rect, 1)); view_ops.push_back (lay::ViewOp (0x0000c0, lay::ViewOp::Or, 0, 0, 0, lay::ViewOp::Rect, 3)); - lay::PixelBuffer img (32, 32); + tl::PixelBuffer img (32, 32); img.fill (0); lay::DitherPattern dp; diff --git a/src/laybasic/unit_tests/unit_tests.pro b/src/laybasic/unit_tests/unit_tests.pro index d2e74f094..3e585c8ca 100644 --- a/src/laybasic/unit_tests/unit_tests.pro +++ b/src/laybasic/unit_tests/unit_tests.pro @@ -12,7 +12,6 @@ SOURCES = \ layBitmapsToImage.cc \ layLayerProperties.cc \ layParsedLayerSource.cc \ - layPixelBufferTests.cc \ layRenderer.cc \ layAbstractMenuTests.cc \ laySnapTests.cc diff --git a/src/layui/layui/layLayerTreeModel.cc b/src/layui/layui/layLayerTreeModel.cc index c95737acc..789e70b02 100644 --- a/src/layui/layui/layLayerTreeModel.cc +++ b/src/layui/layui/layLayerTreeModel.cc @@ -530,7 +530,7 @@ LayerTreeModel::parent (const QModelIndex &index) const */ static void single_bitmap_to_image (const lay::ViewOp &view_op, lay::Bitmap &bitmap, - lay::PixelBuffer *pimage, const lay::DitherPattern &dither_pattern, const lay::LineStyles &line_styles, + tl::PixelBuffer *pimage, const lay::DitherPattern &dither_pattern, const lay::LineStyles &line_styles, unsigned int width, unsigned int height) { std::vector view_ops; @@ -647,7 +647,7 @@ LayerTreeModel::icon_for_layer (const lay::LayerPropertiesConstIterator &iter, l tl::color_t fill_color = iter->has_fill_color (true) ? iter->eff_fill_color (true) : def_color; tl::color_t frame_color = iter->has_frame_color (true) ? iter->eff_frame_color (true) : def_color; - lay::PixelBuffer image (w, h); + tl::PixelBuffer image (w, h); image.set_transparent (true); image.fill (view->background_color ().rgb ()); diff --git a/src/layview/unit_tests/layLayoutViewTests.cc b/src/layview/unit_tests/layLayoutViewTests.cc index fac9e3fed..510c72317 100644 --- a/src/layview/unit_tests/layLayoutViewTests.cc +++ b/src/layview/unit_tests/layLayoutViewTests.cc @@ -72,12 +72,12 @@ static bool compare_images_mono (const QImage &qimg, const std::string &au) #endif -static bool compare_images (const lay::PixelBuffer &img, const lay::PixelBuffer &img2) +static bool compare_images (const tl::PixelBuffer &img, const tl::PixelBuffer &img2) { return img == img2; } -static bool compare_images (const lay::BitmapBuffer &img, const lay::BitmapBuffer &img2) +static bool compare_images (const tl::BitmapBuffer &img, const tl::BitmapBuffer &img2) { return img == img2; } @@ -162,7 +162,7 @@ TEST(4) lv.resize (42, 117); tl::msleep (250); - lay::PixelBuffer img = lv.get_screenshot_pb (); + tl::PixelBuffer img = lv.get_screenshot_pb (); EXPECT_EQ ((int) img.width (), 42); EXPECT_EQ ((int) img.height (), 117); @@ -181,7 +181,7 @@ TEST(11) lv.load_layout (tl::testsrc () + "/testdata/gds/t10.gds", true); - lay::PixelBuffer img; + tl::PixelBuffer img; img = lv.get_pixels_with_options (500, 500, 1, 1, 1.0, tl::Color (255, 255, 255), tl::Color (0, 0, 0), tl::Color (128, 128, 128), db::DBox ()); std::string tmp = tmp_file ("test.png"); @@ -192,10 +192,10 @@ TEST(11) tl::info << "PNG file written to " << tmp; std::string au = tl::testsrc () + "/testdata/lay/au_lv1.png"; - lay::PixelBuffer au_img; + tl::PixelBuffer au_img; { tl::InputStream stream (au); - au_img = lay::PixelBuffer::read_png (stream); + au_img = tl::PixelBuffer::read_png (stream); } tl::info << "PNG file read from " << au; @@ -209,7 +209,7 @@ TEST(12) lv.load_layout (tl::testsrc () + "/testdata/gds/t10.gds", true); - lay::PixelBuffer img; + tl::PixelBuffer img; img = lv.get_pixels_with_options (500, 500, 1, 1, 1.0, tl::Color (255, 255, 255), tl::Color (0, 0, 0), tl::Color (128, 128, 128), db::DBox ()); std::string tmp = tmp_file ("test.png"); @@ -220,10 +220,10 @@ TEST(12) tl::info << "PNG file written to " << tmp; std::string au = tl::testsrc () + "/testdata/lay/au_lv2.png"; - lay::PixelBuffer au_img; + tl::PixelBuffer au_img; { tl::InputStream stream (au); - au_img = lay::PixelBuffer::read_png (stream); + au_img = tl::PixelBuffer::read_png (stream); } tl::info << "PNG file read from " << au; @@ -238,7 +238,7 @@ TEST(13) lv.load_layout (tl::testsrc () + "/testdata/gds/t10.gds", true); - lay::BitmapBuffer img; + tl::BitmapBuffer img; img = lv.get_pixels_with_options_mono (500, 500, 1, tl::Color (255, 255, 255), tl::Color (0, 0, 0), tl::Color (128, 128, 128), db::DBox ()); std::string tmp = tmp_file ("test.png"); @@ -249,10 +249,10 @@ TEST(13) tl::info << "PNG file written to " << tmp; std::string au = tl::testsrc () + "/testdata/lay/au_lv3.png"; - lay::BitmapBuffer au_img; + tl::BitmapBuffer au_img; { tl::InputStream stream (au); - au_img = lay::BitmapBuffer::read_png (stream); + au_img = tl::BitmapBuffer::read_png (stream); } tl::info << "PNG file read from " << au; @@ -271,18 +271,18 @@ TEST(21) std::string tmp = tmp_file ("test.png"); lv.save_image_with_options (tmp, 500, 500, 1, 1, 1.0, tl::Color (255, 255, 255), tl::Color (0, 0, 0), tl::Color (128, 128, 128), db::DBox (), false); - lay::PixelBuffer img; + tl::PixelBuffer img; { tl::InputStream stream (tmp); - img = lay::PixelBuffer::read_png (stream); + img = tl::PixelBuffer::read_png (stream); } tl::info << "PNG file read from " << tmp; std::string au = tl::testsrc () + "/testdata/lay/au_lv1.png"; - lay::PixelBuffer au_img; + tl::PixelBuffer au_img; { tl::InputStream stream (au); - au_img = lay::PixelBuffer::read_png (stream); + au_img = tl::PixelBuffer::read_png (stream); } tl::info << "PNG file read from " << au; @@ -299,18 +299,18 @@ TEST(22) std::string tmp = tmp_file ("test.png"); lv.save_image_with_options (tmp, 500, 500, 1, 1, 1.0, tl::Color (255, 255, 255), tl::Color (0, 0, 0), tl::Color (128, 128, 128), db::DBox (), false); - lay::PixelBuffer img; + tl::PixelBuffer img; { tl::InputStream stream (tmp); - img = lay::PixelBuffer::read_png (stream); + img = tl::PixelBuffer::read_png (stream); } tl::info << "PNG file read from " << tmp; std::string au = tl::testsrc () + "/testdata/lay/au_lv2.png"; - lay::PixelBuffer au_img; + tl::PixelBuffer au_img; { tl::InputStream stream (au); - au_img = lay::PixelBuffer::read_png (stream); + au_img = tl::PixelBuffer::read_png (stream); } tl::info << "PNG file read from " << au; @@ -328,18 +328,18 @@ TEST(23) std::string tmp = tmp_file ("test.png"); lv.save_image_with_options (tmp, 500, 500, 1, 1, 1.0, tl::Color (255, 255, 255), tl::Color (0, 0, 0), tl::Color (128, 128, 128), db::DBox (), true); - lay::BitmapBuffer img; + tl::BitmapBuffer img; { tl::InputStream stream (tmp); - img = lay::BitmapBuffer::read_png (stream); + img = tl::BitmapBuffer::read_png (stream); } tl::info << "PNG file read from " << tmp; std::string au = tl::testsrc () + "/testdata/lay/au_lv3.png"; - lay::BitmapBuffer au_img; + tl::BitmapBuffer au_img; { tl::InputStream stream (au); - au_img = lay::BitmapBuffer::read_png (stream); + au_img = tl::BitmapBuffer::read_png (stream); } tl::info << "PNG file read from " << au; diff --git a/src/rdb/rdb/gsiDeclRdb.cc b/src/rdb/rdb/gsiDeclRdb.cc index 838e0bc19..22a99bca0 100644 --- a/src/rdb/rdb/gsiDeclRdb.cc +++ b/src/rdb/rdb/gsiDeclRdb.cc @@ -821,6 +821,30 @@ Class decl_RdbItem ("rdb", "RdbItem", "@brief Sets the image from a string\n" "@param image A base64-encoded image file (preferably in PNG format)\n" ) + +#if defined(HAVE_QTBINDINGS) + gsi::method ("image", &rdb::Item::image, + "@brief Gets the attached image as a QImage object\n" + "\n" + "This method has been added in version 0.28." + ) + + gsi::method ("image=", static_cast (&rdb::Item::set_image), + "@brief Sets the attached image from a QImage object\n" + "\n" + "This method has been added in version 0.28." + ) + +#endif +#if defined(HAVE_PNG) + gsi::method ("image_pixels", &rdb::Item::image_pixels, + "@brief Gets the attached image as a PixelBuffer object\n" + "\n" + "This method has been added in version 0.28." + ) + + gsi::method ("image=", static_cast (&rdb::Item::set_image), + "@brief Sets the attached image from a PixelBuffer object\n" + "\n" + "This method has been added in version 0.28." + ) + +#endif /* Not supported yet: gsi::method ("multiplicity", &rdb::Item::multiplicity, "@brief Gets the item's multiplicity\n" diff --git a/src/rdb/rdb/rdb.cc b/src/rdb/rdb/rdb.cc index 013cefe7f..ab5e2776b 100644 --- a/src/rdb/rdb/rdb.cc +++ b/src/rdb/rdb/rdb.cc @@ -27,6 +27,7 @@ #include "tlAssert.h" #include "tlStream.h" #include "tlLog.h" +#include "tlBase64.h" #include "dbPolygon.h" #include "dbBox.h" #include "dbEdge.h" @@ -961,7 +962,7 @@ Item::set_image (const QImage &image) } } -const QImage +QImage Item::image () const { if (m_image_str.empty ()) { @@ -980,6 +981,29 @@ Item::image () const } #endif +#if defined(HAVE_PNG) + +tl::PixelBuffer +Item::image_pixels () const +{ + std::vector data = tl::from_base64 (m_image_str.c_str ()); + tl::InputStream stream (new tl::InputMemoryStream ((const char *) data.begin ().operator-> (), data.size ())); + return tl::PixelBuffer::read_png (stream); +} + +void +Item::set_image (const tl::PixelBuffer &image) +{ + tl::OutputMemoryStream mem; + { + tl::OutputStream stream (mem); + image.write_png (stream); + } + m_image_str = tl::to_base64 ((const unsigned char *) mem.data (), mem.size ()); +} + +#endif + bool Item::has_image () const { diff --git a/src/rdb/rdb/rdb.h b/src/rdb/rdb/rdb.h index a8c513ab9..26eaafc70 100644 --- a/src/rdb/rdb/rdb.h +++ b/src/rdb/rdb/rdb.h @@ -30,6 +30,7 @@ #include "gsi.h" #include "tlObject.h" #include "tlObjectCollection.h" +#include "tlPixelBuffer.h" #include #include @@ -945,7 +946,7 @@ public: * * @return The image object or an empty image if no image is attached */ - const QImage image () const; + QImage image () const; /** * @brief Set the image for this item @@ -953,6 +954,18 @@ public: void set_image (const QImage &image); #endif +#if defined(HAVE_PNG) + /** + * @brief Gets the image as a tl::PixelBuffer object + */ + tl::PixelBuffer image_pixels () const; + + /** + * @brief Sets the image from a tl::PixelBuffer object + */ + void set_image (const tl::PixelBuffer &image); +#endif + /** * @brief Gets a value indicating whether the item has an image */ diff --git a/src/rdb/unit_tests/rdb.cc b/src/rdb/unit_tests/rdbTests.cc similarity index 94% rename from src/rdb/unit_tests/rdb.cc rename to src/rdb/unit_tests/rdbTests.cc index ed8adf652..1304abb3c 100644 --- a/src/rdb/unit_tests/rdb.cc +++ b/src/rdb/unit_tests/rdbTests.cc @@ -551,4 +551,50 @@ TEST(6) EXPECT_EQ (db.variants ("c2")[5], c2e->id ()); } +TEST(7) +{ + rdb::Database db; + rdb::Category *cath = db.create_category ("cath_name"); + rdb::Cell *c1 = db.create_cell ("c1"); + rdb::Item *i1 = db.create_item (c1->id (), cath->id ()); +#if defined(HAVE_QT) + + { + QImage img (16, 26, QImage::Format_RGB32); + for (int i = 0; i < img.height (); ++i) { + for (int j = 0; j < img.height (); ++j) { + img.scanLine (j) [i] = (i << 16) + j; + } + } + i1->set_image (img); + + QImage img2 = i1->image (); + + EXPECT_EQ (img.width (), img2.width ()); + EXPECT_EQ (img.height (), img2.height ()); + EXPECT_EQ (tl::PixelBuffer::from_image (img) == tl::PixelBuffer::from_image (img2), true); + } + +#endif + +#if defined(HAVE_PNG) + + { + tl::PixelBuffer img (16, 26); + for (unsigned int i = 0; i < img.width (); ++i) { + for (unsigned int j = 0; j < img.height (); ++j) { + img.scan_line (j) [i] = (i << 16) + j; + } + } + i1->set_image (img); + + tl::PixelBuffer img2 = i1->image_pixels (); + + EXPECT_EQ (img.width (), img2.width ()); + EXPECT_EQ (img.height (), img2.height ()); + EXPECT_EQ (img == img2, true); + } + +#endif +} diff --git a/src/rdb/unit_tests/unit_tests.pro b/src/rdb/unit_tests/unit_tests.pro index ed51891c5..c4f6be57b 100644 --- a/src/rdb/unit_tests/unit_tests.pro +++ b/src/rdb/unit_tests/unit_tests.pro @@ -7,8 +7,8 @@ TARGET = rdb_tests include($$PWD/../../lib_ut.pri) SOURCES = \ - rdb.cc \ - rdbRVEReaderTests.cc + rdbRVEReaderTests.cc \ + rdbTests.cc INCLUDEPATH += $$RDB_INC $$TL_INC $$DB_INC $$GSI_INC DEPENDPATH += $$RDB_INC $$TL_INC $$DB_INC $$GSI_INC diff --git a/src/tl/tl/tl.pro b/src/tl/tl/tl.pro index 022bc032c..0cc8c7ea4 100644 --- a/src/tl/tl/tl.pro +++ b/src/tl/tl/tl.pro @@ -28,6 +28,7 @@ SOURCES = \ tlLog.cc \ tlObject.cc \ tlProgress.cc \ + tlPixelBuffer.cc \ tlResources.cc \ tlScriptError.cc \ tlSleep.cc \ @@ -81,6 +82,7 @@ HEADERS = \ tlObject.h \ tlObjectCollection.h \ tlProgress.h \ + tlPixelBuffer.h \ tlResources.h \ tlReuseVector.h \ tlScriptError.h \ diff --git a/src/laybasic/laybasic/layPixelBuffer.cc b/src/tl/tl/tlPixelBuffer.cc similarity index 99% rename from src/laybasic/laybasic/layPixelBuffer.cc rename to src/tl/tl/tlPixelBuffer.cc index f671898b1..0c8566ad8 100644 --- a/src/laybasic/laybasic/layPixelBuffer.cc +++ b/src/tl/tl/tlPixelBuffer.cc @@ -20,7 +20,7 @@ */ -#include "layPixelBuffer.h" +#include "tlPixelBuffer.h" #include "tlAssert.h" #include "tlLog.h" @@ -30,7 +30,7 @@ #include -namespace lay +namespace tl { // ----------------------------------------------------------------------------------------------------- diff --git a/src/laybasic/laybasic/layPixelBuffer.h b/src/tl/tl/tlPixelBuffer.h similarity index 97% rename from src/laybasic/laybasic/layPixelBuffer.h rename to src/tl/tl/tlPixelBuffer.h index aad3912b6..62b6206f3 100644 --- a/src/laybasic/laybasic/layPixelBuffer.h +++ b/src/tl/tl/tlPixelBuffer.h @@ -20,10 +20,10 @@ */ -#ifndef HDR_layPixelBuffer -#define HDR_layPixelBuffer +#ifndef HDR_tlPixelBuffer +#define HDR_tlPixelBuffer -#include "laybasicCommon.h" +#include "tlCommon.h" #include "tlColor.h" #include "tlCopyOnWrite.h" #include "tlStream.h" @@ -36,13 +36,13 @@ # include #endif -namespace lay +namespace tl { /** * @brief An exception thrown when a PNG read error occurs */ -class LAYBASIC_PUBLIC PixelBufferReadError +class TL_PUBLIC PixelBufferReadError : public tl::Exception { public: @@ -53,7 +53,7 @@ public: /** * @brief An exception thrown when a PNG write error occurs */ -class LAYBASIC_PUBLIC PixelBufferWriteError +class TL_PUBLIC PixelBufferWriteError : public tl::Exception { public: @@ -67,7 +67,7 @@ public: * This class substitutes QImage in Qt-less applications. * It provides 32bit RGBA pixels with the format used by tl::Color. */ -class LAYBASIC_PUBLIC PixelBuffer +class TL_PUBLIC PixelBuffer { public: /** @@ -329,7 +329,7 @@ private: * This class substitutes QImage for monochrome images in Qt-less applications. */ -class LAYBASIC_PUBLIC BitmapBuffer +class TL_PUBLIC BitmapBuffer { public: /** diff --git a/src/laybasic/unit_tests/layPixelBufferTests.cc b/src/tl/unit_tests/tlPixelBufferTests.cc similarity index 83% rename from src/laybasic/unit_tests/layPixelBufferTests.cc rename to src/tl/unit_tests/tlPixelBufferTests.cc index 644b1d3ef..eb6b4a2fd 100644 --- a/src/laybasic/unit_tests/layPixelBufferTests.cc +++ b/src/tl/unit_tests/tlPixelBufferTests.cc @@ -20,7 +20,7 @@ */ -#include "layPixelBuffer.h" +#include "tlPixelBuffer.h" #include "tlUnitTest.h" #include "tlTimer.h" @@ -72,19 +72,19 @@ static bool compare_images_mono (const QImage &qimg, const std::string &au) #endif -static bool compare_images (const lay::PixelBuffer &img, const lay::PixelBuffer &img2) +static bool compare_images (const tl::PixelBuffer &img, const tl::PixelBuffer &img2) { return img == img2; } -static bool compare_images (const lay::BitmapBuffer &img, const lay::BitmapBuffer &img2) +static bool compare_images (const tl::BitmapBuffer &img, const tl::BitmapBuffer &img2) { return img == img2; } TEST(1) { - lay::PixelBuffer img (15, 25); + tl::PixelBuffer img (15, 25); EXPECT_EQ (img.width (), 15); EXPECT_EQ (img.height (), 25); EXPECT_EQ (img.stride (), 15 * sizeof (tl::color_t)); @@ -96,7 +96,7 @@ TEST(1) img.fill (0x112233); EXPECT_EQ (img.scan_line (5)[10], 0x112233); - lay::PixelBuffer img2; + tl::PixelBuffer img2; EXPECT_EQ (img2.transparent (), false); img2 = img; EXPECT_EQ (img2.transparent (), true); @@ -121,7 +121,7 @@ TEST(1) EXPECT_EQ (img.scan_line (5)[10], 0x332211); EXPECT_EQ (img2.scan_line (5)[10], 0x332211); - img2 = lay::PixelBuffer (10, 16); + img2 = tl::PixelBuffer (10, 16); EXPECT_EQ (img.width (), 15); EXPECT_EQ (img.height (), 25); EXPECT_EQ (img2.width (), 10); @@ -138,7 +138,7 @@ TEST(1) EXPECT_EQ (img.height (), 16); EXPECT_EQ (img.scan_line (5)[8], 0xff010203); - lay::PixelBuffer img3 (img); + tl::PixelBuffer img3 (img); EXPECT_EQ (compare_images (img, img3), true); EXPECT_EQ (img3.width (), 10); EXPECT_EQ (img3.height (), 16); @@ -153,25 +153,25 @@ TEST(1) EXPECT_EQ (img.height (), 16); EXPECT_EQ (img.scan_line (5)[8], 0xff102030); - lay::PixelBuffer img4 (std::move (img)); + tl::PixelBuffer img4 (std::move (img)); EXPECT_EQ (img4.width (), 10); EXPECT_EQ (img4.height (), 16); EXPECT_EQ (img4.scan_line (5)[8], 0xff102030); // other constructors - 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); + EXPECT_EQ (compare_images (tl::PixelBuffer (img4.width (), img4.height (), (const tl::color_t *) img4.data ()), img4), true); + EXPECT_EQ (compare_images (tl::PixelBuffer (img4.width (), img4.height (), (const tl::color_t *) img4.data (), img4.stride ()), img4), true); 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); + EXPECT_EQ (compare_images (tl::PixelBuffer (img4.width (), img4.height (), dnew), img4), true); } #if defined(HAVE_QT) TEST(2) { - lay::PixelBuffer img (227, 231); + tl::PixelBuffer img (227, 231); for (unsigned int i = 0; i < img.width (); ++i) { for (unsigned int j = 0; j < img.height (); ++j) { @@ -192,13 +192,13 @@ TEST(2) EXPECT_EQ (compare_images (qimg, au), true); - lay::PixelBuffer img_returned = lay::PixelBuffer::from_image (qimg); + tl::PixelBuffer img_returned = tl::PixelBuffer::from_image (qimg); EXPECT_EQ (compare_images (img, img_returned), true); - lay::PixelBuffer img_saved (img); + tl::PixelBuffer img_saved (img); img.scan_line (52) [42] = 0xff000000; - lay::PixelBuffer diff = img.diff (img_saved); + tl::PixelBuffer diff = img.diff (img_saved); EXPECT_EQ (diff.transparent (), true); EXPECT_EQ (diff.to_image ().format () == QImage::Format_ARGB32, true); EXPECT_EQ (compare_images (img.to_image (), au), false); @@ -237,14 +237,14 @@ TEST(2) // libpng support TEST(3) { - lay::PixelBuffer img; + tl::PixelBuffer img; std::string in = tl::testsrc () + "/testdata/lay/png1.png"; // ARGB32 tl::info << "PNG file read (libpng) from " << in; { tl::InputStream stream (in); - img = lay::PixelBuffer::read_png (stream); + img = tl::PixelBuffer::read_png (stream); } std::string tmp = tmp_file ("test.png"); @@ -254,11 +254,11 @@ TEST(3) } tl::info << "PNG file written to " << tmp; - lay::PixelBuffer img2; + tl::PixelBuffer img2; { tl::InputStream stream (tmp); - img2 = lay::PixelBuffer::read_png (stream); + img2 = tl::PixelBuffer::read_png (stream); } std::string tmp2 = tmp_file ("test2.png"); @@ -279,14 +279,14 @@ TEST(3) TEST(4) { - lay::PixelBuffer img; + tl::PixelBuffer img; std::string in = tl::testsrc () + "/testdata/lay/png2.png"; // RGB32 tl::info << "PNG file read (libpng) from " << in; { tl::InputStream stream (in); - img = lay::PixelBuffer::read_png (stream); + img = tl::PixelBuffer::read_png (stream); } std::string tmp = tmp_file ("test.png"); @@ -296,11 +296,11 @@ TEST(4) } tl::info << "PNG file written to " << tmp; - lay::PixelBuffer img2; + tl::PixelBuffer img2; { tl::InputStream stream (tmp); - img2 = lay::PixelBuffer::read_png (stream); + img2 = tl::PixelBuffer::read_png (stream); } std::string tmp2 = tmp_file ("test2.png"); @@ -321,14 +321,14 @@ TEST(4) TEST(5) { - lay::PixelBuffer img; + tl::PixelBuffer img; std::string in = tl::testsrc () + "/testdata/lay/png3.png"; // GA tl::info << "PNG file read (libpng) from " << in; { tl::InputStream stream (in); - img = lay::PixelBuffer::read_png (stream); + img = tl::PixelBuffer::read_png (stream); } std::string tmp = tmp_file ("test.png"); @@ -338,11 +338,11 @@ TEST(5) } tl::info << "PNG file written to " << tmp; - lay::PixelBuffer img2; + tl::PixelBuffer img2; { tl::InputStream stream (tmp); - img2 = lay::PixelBuffer::read_png (stream); + img2 = tl::PixelBuffer::read_png (stream); } std::string tmp2 = tmp_file ("test2.png"); @@ -363,14 +363,14 @@ TEST(5) TEST(6) { - lay::PixelBuffer img; + tl::PixelBuffer img; std::string in = tl::testsrc () + "/testdata/lay/png4.png"; // G tl::info << "PNG file read (libpng) from " << in; { tl::InputStream stream (in); - img = lay::PixelBuffer::read_png (stream); + img = tl::PixelBuffer::read_png (stream); } std::string tmp = tmp_file ("test.png"); @@ -380,11 +380,11 @@ TEST(6) } tl::info << "PNG file written to " << tmp; - lay::PixelBuffer img2; + tl::PixelBuffer img2; { tl::InputStream stream (tmp); - img2 = lay::PixelBuffer::read_png (stream); + img2 = tl::PixelBuffer::read_png (stream); } std::string tmp2 = tmp_file ("test2.png"); @@ -408,13 +408,13 @@ TEST(6) TEST(7) { { - tl::SelfTimer timer ("Run time - lay::Image copy, no write (should be very fast)"); + tl::SelfTimer timer ("Run time - tl::Image copy, no write (should be very fast)"); - lay::PixelBuffer img (1000, 1000); + tl::PixelBuffer img (1000, 1000); img.fill (0x112233); for (unsigned int i = 0; i < 5000; ++i) { - lay::PixelBuffer img2 (img); + tl::PixelBuffer img2 (img); } } @@ -422,7 +422,7 @@ TEST(7) { tl::SelfTimer timer ("Run time - QImage copy, no write (should be very fast)"); - lay::PixelBuffer img (1000, 1000); + tl::PixelBuffer img (1000, 1000); img.fill (0x112233); QImage qimg (img.to_image ()); @@ -433,22 +433,22 @@ TEST(7) #endif { - tl::SelfTimer timer ("Run time - lay::Image copy on write"); + tl::SelfTimer timer ("Run time - tl::Image copy on write"); - lay::PixelBuffer img (1000, 1000); + tl::PixelBuffer img (1000, 1000); img.fill (0x112233); for (unsigned int i = 0; i < 5000; ++i) { - lay::PixelBuffer img2 (img); + tl::PixelBuffer img2 (img); img2.scan_line (100) [7] = 0; } } #if defined(HAVE_QT) { - tl::SelfTimer timer ("Run time - QImage copy on write (should not be much less than lay::Image copy on write)"); + tl::SelfTimer timer ("Run time - QImage copy on write (should not be much less than tl::Image copy on write)"); - lay::PixelBuffer img (1000, 1000); + tl::PixelBuffer img (1000, 1000); img.fill (0x112233); QImage qimg (img.to_image ()); @@ -461,7 +461,7 @@ TEST(7) { tl::SelfTimer timer ("Run time - direct QImage paint"); - lay::PixelBuffer img (1000, 1000); + tl::PixelBuffer img (1000, 1000); img.fill (0x112233); QImage qimg (img.to_image ()); QImage qrec (img.to_image ()); @@ -474,9 +474,9 @@ TEST(7) } { - tl::SelfTimer timer ("Run time - lay::Image paint (should not be much more than direct QImage paint)"); + tl::SelfTimer timer ("Run time - tl::Image paint (should not be much more than direct QImage paint)"); - lay::PixelBuffer img (1000, 1000); + tl::PixelBuffer img (1000, 1000); img.fill (0x112233); QImage qrec (img.to_image ()); qrec.fill (0); @@ -494,7 +494,7 @@ TEST(7) TEST(11) { - lay::BitmapBuffer img (15, 25); + tl::BitmapBuffer img (15, 25); EXPECT_EQ (img.width (), 15); EXPECT_EQ (img.height (), 25); EXPECT_EQ (img.stride (), 4); @@ -502,7 +502,7 @@ TEST(11) img.fill (true); EXPECT_EQ (img.scan_line (5)[1], 0xff); - lay::BitmapBuffer img2; + tl::BitmapBuffer img2; img2 = img; EXPECT_EQ (img2.width (), 15); EXPECT_EQ (img2.height (), 25); @@ -523,7 +523,7 @@ TEST(11) EXPECT_EQ (img.scan_line (5)[1], 0); EXPECT_EQ (img2.scan_line (5)[1], 0); - img2 = lay::BitmapBuffer (10, 16); + img2 = tl::BitmapBuffer (10, 16); EXPECT_EQ (img.width (), 15); EXPECT_EQ (img.height (), 25); EXPECT_EQ (img2.width (), 10); @@ -540,7 +540,7 @@ TEST(11) EXPECT_EQ (img.height (), 16); EXPECT_EQ (img.scan_line (5)[0], 0xff); - lay::BitmapBuffer img3 (img); + tl::BitmapBuffer img3 (img); EXPECT_EQ (compare_images (img, img3), true); EXPECT_EQ (img3.width (), 10); EXPECT_EQ (img3.height (), 16); @@ -555,25 +555,25 @@ TEST(11) EXPECT_EQ (img.height (), 16); EXPECT_EQ (img.scan_line (5)[1], 0); - lay::BitmapBuffer img4 (std::move (img)); + tl::BitmapBuffer img4 (std::move (img)); EXPECT_EQ (img4.width (), 10); EXPECT_EQ (img4.height (), 16); EXPECT_EQ (img4.scan_line (5)[1], 0); // other constructors - EXPECT_EQ (compare_images (lay::BitmapBuffer (img4.width (), img4.height (), (const uint8_t *) img4.data ()), img4), true); - EXPECT_EQ (compare_images (lay::BitmapBuffer (img4.width (), img4.height (), (const uint8_t *) img4.data (), img4.stride ()), img4), true); + EXPECT_EQ (compare_images (tl::BitmapBuffer (img4.width (), img4.height (), (const uint8_t *) img4.data ()), img4), true); + EXPECT_EQ (compare_images (tl::BitmapBuffer (img4.width (), img4.height (), (const uint8_t *) img4.data (), img4.stride ()), img4), true); uint8_t *dnew = new uint8_t [ img4.width () * img4.height () * sizeof (uint8_t) ]; memcpy (dnew, (const uint8_t *) img4.data (), img4.stride () * img4.height ()); - EXPECT_EQ (compare_images (lay::BitmapBuffer (img4.width (), img4.height (), dnew), img4), true); + EXPECT_EQ (compare_images (tl::BitmapBuffer (img4.width (), img4.height (), dnew), img4), true); } #if defined(HAVE_QT) TEST(12) { - lay::BitmapBuffer img (227, 231); + tl::BitmapBuffer img (227, 231); for (unsigned int i = 0; i < img.stride (); ++i) { for (unsigned int j = 0; j < img.height (); ++j) { @@ -593,7 +593,7 @@ TEST(12) EXPECT_EQ (compare_images_mono (qimg, au), true); - lay::BitmapBuffer img_returned = lay::BitmapBuffer::from_image (qimg); + tl::BitmapBuffer img_returned = tl::BitmapBuffer::from_image (qimg); EXPECT_EQ (compare_images (img, img_returned), true); qimg = img.to_image_copy (); @@ -613,14 +613,14 @@ TEST(12) // libpng support TEST(13) { - lay::BitmapBuffer img; + tl::BitmapBuffer img; std::string in = tl::testsrc () + "/testdata/lay/au_mono.png"; tl::info << "PNG file read (libpng) from " << in; { tl::InputStream stream (in); - img = lay::BitmapBuffer::read_png (stream); + img = tl::BitmapBuffer::read_png (stream); } std::string tmp = tmp_file ("test.png"); @@ -630,11 +630,11 @@ TEST(13) } tl::info << "PNG file written to " << tmp; - lay::BitmapBuffer img2; + tl::BitmapBuffer img2; { tl::InputStream stream (tmp); - img2 = lay::BitmapBuffer::read_png (stream); + img2 = tl::BitmapBuffer::read_png (stream); } std::string tmp2 = tmp_file ("test2.png"); diff --git a/src/tl/unit_tests/unit_tests.pro b/src/tl/unit_tests/unit_tests.pro index d72aa7058..692ba586e 100644 --- a/src/tl/unit_tests/unit_tests.pro +++ b/src/tl/unit_tests/unit_tests.pro @@ -29,6 +29,7 @@ SOURCES = \ tlLongIntTests.cc \ tlMathTests.cc \ tlObjectTests.cc \ + tlPixelBufferTests.cc \ tlResourcesTests.cc \ tlReuseVectorTests.cc \ tlStableVectorTests.cc \ diff --git a/testdata/ruby/rdbTest.rb b/testdata/ruby/rdbTest.rb index 1bdaca1fd..07d06874b 100644 --- a/testdata/ruby/rdbTest.rb +++ b/testdata/ruby/rdbTest.rb @@ -430,6 +430,25 @@ class RDB_TestClass < TestBase item.image_str=is assert_equal(item.image_str, is) assert_equal(item.has_image?, true) + + if item.respond_to?(:image_pixels) + px=item.image_pixels + assert_equal(px.width, 42) + assert_equal(px.height, 52) + item.image = px + px2=item.image_pixels + assert_equal(px == px2, true) + end + + if item.respond_to?(:image) + px=item.image + assert_equal(px.width, 42) + assert_equal(px.height, 52) + item.image = px + px2=item.image + assert_equal(px2.width, 42) + assert_equal(px2.height, 52) + end vs = RBA::RdbItemValue.new("a string") vs2 = RBA::RdbItemValue.new("a string (ii)")