Commit 9bae1b6c authored by Davis King's avatar Davis King

The image_display didn't display overlay rectangles quite right. If you zoomed

in you could see that some of the pixels which are inside the rectangle were
outside the overlay.  Specifically, the right column and bottom row was outside
the overlay rectangle.  This has been fixed.  Now all pixels which are supposed
to be part of a rectangle are drawn as being inside the overlay rectangle.
parent 350d7bb5
......@@ -5797,9 +5797,18 @@ namespace dlib
{
rectangle orect = overlay_rects[i].rect;
orect.left() = orect.left()*zoom_in_scale/zoom_out_scale;
orect.right() = orect.right()*zoom_in_scale/zoom_out_scale;
orect.top() = orect.top()*zoom_in_scale/zoom_out_scale;
orect.bottom() = orect.bottom()*zoom_in_scale/zoom_out_scale;
if (zoom_in_scale != 1)
{
// make it so the box surrounds the pixels when we zoom in.
orect.right() = (orect.right()+1)*zoom_in_scale/zoom_out_scale;
orect.bottom() = (orect.bottom()+1)*zoom_in_scale/zoom_out_scale;
}
else
{
orect.right() = orect.right()*zoom_in_scale/zoom_out_scale;
orect.bottom() = orect.bottom()*zoom_in_scale/zoom_out_scale;
}
if (rect_is_selected && selected_rect == i)
draw_rectangle(c, translate_rect(orect, origin), invert_pixel(overlay_rects[i].color), area);
......@@ -5902,9 +5911,18 @@ namespace dlib
{
rectangle orect = overlay_rects[i].rect;
orect.left() = orect.left()*zoom_in_scale/zoom_out_scale;
orect.right() = orect.right()*zoom_in_scale/zoom_out_scale;
orect.top() = orect.top()*zoom_in_scale/zoom_out_scale;
orect.bottom() = orect.bottom()*zoom_in_scale/zoom_out_scale;
if (zoom_in_scale != 1)
{
// make it so the box surrounds the pixels when we zoom in.
orect.right() = (orect.right()+1)*zoom_in_scale/zoom_out_scale;
orect.bottom() = (orect.bottom()+1)*zoom_in_scale/zoom_out_scale;
}
else
{
orect.right() = orect.right()*zoom_in_scale/zoom_out_scale;
orect.bottom() = orect.bottom()*zoom_in_scale/zoom_out_scale;
}
orect = translate_rect(orect, origin);
......@@ -6018,7 +6036,16 @@ namespace dlib
c2 = c2*(double)zoom_out_scale;
}
const rectangle new_rect(c1,c2);
rectangle new_rect(c1,c2);
if (zoom_in_scale != 1)
{
// When we are zoomed in we adjust the rectangles a little so they
// are drown surrounding the pixels inside the rect. This adjustment
// is necessary to make this code consistent with this goal.
new_rect.right() -= 1;
new_rect.bottom() -= 1;
}
if (new_rect.width() > 0 && new_rect.height() > 0)
{
......
......@@ -796,6 +796,27 @@ int main()
try
{
image_window win;
array2d<unsigned char> img;
img.set_size(100,100);
assign_all_pixels(img,0);
fill_rect(img, rectangle(1,1,1,1), 255);
fill_rect(img, rectangle(1,3,2,5), 255);
fill_rect(img, rectangle(4,3,5,4), 255);
fill_rect(img, rectangle(9,9,13,10), 255);
win.set_image(img);
win.add_overlay(image_display::overlay_rect(rectangle(1,1,1,1), rgb_pixel(255,0,0)));
win.add_overlay(image_display::overlay_rect(rectangle(1,3,2,5), rgb_pixel(255,0,0)));
win.add_overlay(image_display::overlay_rect(rectangle(4,3,5,4), rgb_pixel(255,0,0)));
win.add_overlay(image_display::overlay_rect(rectangle(9,9,13,10), rgb_pixel(255,0,0)));
w.set_pos (100,200);
w.set_title("test window");
w.show();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment