diff --git a/src/img/img/gsiDeclImg.cc b/src/img/img/gsiDeclImg.cc index 724befcb5..1fbcc7ac5 100644 --- a/src/img/img/gsiDeclImg.cc +++ b/src/img/img/gsiDeclImg.cc @@ -26,6 +26,7 @@ #include "gsiSignals.h" #include "imgObject.h" #include "imgService.h" +#include "imgStream.h" #include "dbTilingProcessor.h" #include "layLayoutView.h" @@ -413,6 +414,24 @@ static ImageRef *img_from_s (const std::string &s) return img.release (); } +static ImageRef *load_image (const std::string &path) +{ + tl::InputFile file (path); + tl::InputStream stream (file); + + std::auto_ptr read; + read.reset (img::ImageStreamer::read (stream)); + // need to create a copy for now ... + return new ImageRef (*read); +} + +static void save_image (const ImageRef *image, const std::string &path) +{ + tl::OutputFile file (path); + tl::OutputStream stream (file); + img::ImageStreamer::write (stream, *image); +} + static ImageRef *new_image () { return new ImageRef (); @@ -541,6 +560,16 @@ gsi::Class decl_Image (decl_BasicImage, "lay", "Image", "@brief Creates an image from the string returned by \\to_s.\n" "This method has been introduced in version 0.27." ) + + gsi::constructor ("read", &load_image, gsi::arg ("path"), + "@brief Loads the image from the given path.\n" + "\n" + "This method expects the image file as a KLayout image format file (.lyimg). " + "This is a XML-based format containing the image data plus placement and transformation " + "information for the image placement. In addition, image manipulation parameters for " + "false color display and color channel enhancement are embedded.\n" + "\n" + "This method has been introduced in version 0.27." + ) + gsi::constructor ("new", &gsi::new_image, "@brief Create a new image with the default attributes" "\n" @@ -681,6 +710,10 @@ gsi::Class decl_Image (decl_BasicImage, "lay", "Image", "@param t The magnifying transformation to apply\n" "@return The transformed object\n" ) + + gsi::method ("clear", &ImageRef::clear, + "@brief Clears the image data (sets to 0 or black).\n" + "This method has been introduced in version 0.27." + ) + gsi::method ("width", &ImageRef::width, "@brief Gets the width of the image in pixels\n" "@return The width in pixels\n" @@ -991,6 +1024,10 @@ gsi::Class decl_Image (decl_BasicImage, "lay", "Image", "@brief Converts the image to a string\n" "The string returned can be used to create an image object using \\from_s.\n" "@return The string\n" + ) + + gsi::method_ext ("write", &save_image, gsi::arg ("path"), + "@brief Saves the image to KLayout's image format (.lyimg)\n" + "This method has been introduced in version 0.27." ), "@brief An image to be stored as a layout annotation\n" "\n" diff --git a/testdata/ruby/imgObject.rb b/testdata/ruby/imgObject.rb index b9c0c8b43..7c1af0ae8 100644 --- a/testdata/ruby/imgObject.rb +++ b/testdata/ruby/imgObject.rb @@ -396,6 +396,25 @@ class IMG_TestClass < TestBase end + def test_4 + + tmp = File::join($ut_testtmp, "tmp.lyimg") + + t = RBA::DCplxTrans.new(2.5, 90, false, RBA::DPoint.new(1, 5)) + + image = RBA::Image.new(2, 3, t, [1,2,3,4,5,6]) + assert_equal(image.to_s, "mono:matrix=(0,-2.5,-2.75) (2.5,0,7.5) (0,0,1);min_value=0;max_value=1;is_visible=true;z_position=0;brightness=0;contrast=0;gamma=1;red_gain=1;green_gain=1;blue_gain=1;color_mapping=[0,'#000000';1,'#ffffff';];width=2;height=3;data=[1;2;3;4;5;6;]") + + image.write(tmp) + + image.clear + assert_equal(image.to_s, "mono:matrix=(0,-2.5,-2.75) (2.5,0,7.5) (0,0,1);min_value=0;max_value=1;is_visible=true;z_position=0;brightness=0;contrast=0;gamma=1;red_gain=1;green_gain=1;blue_gain=1;color_mapping=[0,'#000000';1,'#ffffff';];width=2;height=3;data=[0;0;0;0;0;0;]") + + image2 = RBA::Image::read(tmp) + assert_equal(image2.to_s, "mono:matrix=(0,-2.5,-2.75) (2.5,0,7.5) (0,0,1);min_value=0;max_value=1;is_visible=true;z_position=0;brightness=0;contrast=0;gamma=1;red_gain=1;green_gain=1;blue_gain=1;color_mapping=[0,'#000000';1,'#ffffff';];width=2;height=3;data=[1;2;3;4;5;6;]") + + end + end load("test_epilogue.rb")