mirror of https://github.com/KLayout/klayout.git
* Fixed issue #473 (fast accessors to image pixel and mask data through arrays) * Updated Jenkinsfile to not publish a PR build * Updated Jenkinsfile to not publish a PR build
This commit is contained in:
parent
7c89192ad8
commit
946af71f2f
|
|
@ -445,6 +445,40 @@ static void img_set_trans (ImageRef *obj, const db::DCplxTrans &t)
|
|||
obj->set_matrix (n);
|
||||
}
|
||||
|
||||
static std::vector<double> get_data (ImageRef *obj, int component)
|
||||
{
|
||||
std::vector<double> data;
|
||||
data.reserve (obj->width () * obj->height ());
|
||||
for (size_t y = 0; y < obj->height (); ++y) {
|
||||
for (size_t x = 0; x < obj->width (); ++x) {
|
||||
data.push_back (obj->pixel (x, y, (unsigned int) component));
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
static void set_mask_data (ImageRef *obj, const std::vector<bool> &mask)
|
||||
{
|
||||
std::vector<bool>::const_iterator m = mask.begin ();
|
||||
for (size_t y = 0; y < obj->height (); ++y) {
|
||||
for (size_t x = 0; x < obj->width (); ++x) {
|
||||
obj->set_mask (x, y, m == mask.end () ? true : *m++);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static std::vector<bool> get_mask_data (ImageRef *obj)
|
||||
{
|
||||
std::vector<bool> data;
|
||||
data.reserve (obj->width () * obj->height ());
|
||||
for (size_t y = 0; y < obj->height (); ++y) {
|
||||
for (size_t x = 0; x < obj->width (); ++x) {
|
||||
data.push_back (obj->mask (x, y));
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
// NOTE: img::Object is available as "BasicImage" to allow binding for other methods.
|
||||
gsi::Class<img::Object> decl_BasicImage ("lay", "BasicImage", gsi::Methods (), "@hide");
|
||||
|
||||
|
|
@ -710,6 +744,27 @@ gsi::Class<ImageRef> decl_Image (decl_BasicImage, "lay", "Image",
|
|||
"\n"
|
||||
"See the constructor description for the data organisation in that field.\n"
|
||||
) +
|
||||
gsi::method_ext ("data", &get_data, gsi::arg ("channel", 0),
|
||||
"@brief Gets the data array for a specific color channel\n"
|
||||
"Returns an array of pixel values for the given channel. For a color image, channel 0 is green, channel 1 is red and channel 2 is blue. "
|
||||
"For a monochrome image, the channel is ignored.\n"
|
||||
"\n"
|
||||
"For the format of the data see the constructor description.\n"
|
||||
"\n"
|
||||
"This method has been introduced in version 0.27.\n"
|
||||
) +
|
||||
gsi::method_ext ("mask_data=", &set_mask_data, gsi::arg ("mask_data"),
|
||||
"@brief Sets the mask from a array of boolean values\n"
|
||||
"The order of the boolean values is line first, from bottom to top and left to right and is the same as the order in the data array.\n"
|
||||
"\n"
|
||||
"This method has been introduced in version 0.27.\n"
|
||||
) +
|
||||
gsi::method_ext ("mask_data", &get_mask_data,
|
||||
"@brief Gets the mask from a array of boolean values\n"
|
||||
"See \\set_mask_data for a description of the data field.\n"
|
||||
"\n"
|
||||
"This method has been introduced in version 0.27.\n"
|
||||
) +
|
||||
gsi::method_ext ("pixel_width=", &img_set_pixel_width,
|
||||
"@brief Sets the pixel width\n"
|
||||
"@args w\n"
|
||||
|
|
|
|||
|
|
@ -109,10 +109,15 @@ class IMG_TestClass < TestBase
|
|||
assert_equal(ii.mask(1, 2), true)
|
||||
assert_equal(ii.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.5;1.5;2.5;10;20;]")
|
||||
image.set_mask(1, 2, false)
|
||||
md = image.mask_data
|
||||
assert_equal(ii.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,1;0.5,1;1.5,1;2.5,1;10,1;20,0;]")
|
||||
assert_equal(ii.mask(1, 2), false)
|
||||
image.set_mask(1, 2, true)
|
||||
assert_equal(ii.mask(1, 2), true)
|
||||
image.mask_data = md
|
||||
assert_equal(ii.mask(1, 2), false)
|
||||
image.mask_data = []
|
||||
assert_equal(ii.mask(1, 2), true)
|
||||
|
||||
image.set_data(2, 3, data, data2, [])
|
||||
copy1 = image.dup
|
||||
|
|
@ -132,6 +137,12 @@ class IMG_TestClass < TestBase
|
|||
image.set_data(2, 3, data)
|
||||
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.5;1.5;2.5;10;20;]")
|
||||
|
||||
d = image.data
|
||||
image.set_data(2, 3, [])
|
||||
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;]")
|
||||
image.set_data(2, 3, d)
|
||||
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.5;1.5;2.5;10;20;]")
|
||||
|
||||
assert_equal(image.width, 2);
|
||||
assert_equal(image.height, 3);
|
||||
assert_equal(image.box.to_s, "(-6.5,5;1,10)")
|
||||
|
|
@ -185,6 +196,14 @@ class IMG_TestClass < TestBase
|
|||
assert_equal(image.is_visible?, false)
|
||||
assert_equal(image.to_s, "color:matrix=(0,-2.5,-2.75) (2.5,0,7.5) (0,0,1);min_value=0;max_value=1;is_visible=false;z_position=0;brightness=0.5;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,1,0;0.5,1.5,0;1.5,2.5,0;2.5,3.5,0;10,0,0;20,0,0;]")
|
||||
|
||||
d1 = image.data(0)
|
||||
d2 = image.data(1)
|
||||
d3 = image.data(2)
|
||||
image.set_data(2, 3, [], [], [])
|
||||
assert_equal(image.to_s, "color:matrix=(0,-2.5,-2.75) (2.5,0,7.5) (0,0,1);min_value=0;max_value=1;is_visible=false;z_position=0;brightness=0.5;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;0,0,0;0,0,0;0,0,0;0,0,0;]")
|
||||
image.set_data(2, 3, d1, d2, d3)
|
||||
assert_equal(image.to_s, "color:matrix=(0,-2.5,-2.75) (2.5,0,7.5) (0,0,1);min_value=0;max_value=1;is_visible=false;z_position=0;brightness=0.5;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,1,0;0.5,1.5,0;1.5,2.5,0;2.5,3.5,0;10,0,0;20,0,0;]")
|
||||
|
||||
end
|
||||
|
||||
def test_3
|
||||
|
|
|
|||
Loading…
Reference in New Issue