Modify

Opened 9 years ago

Closed 9 years ago

#11263 closed defect (fixed)

[PATCH] Rounding errors in displaying of tiles

Reported by: asdqweasd Owned by: team
Priority: normal Milestone: 15.03
Component: Core imagery Version: latest
Keywords: Cc:

Description

In function drawImageInside in file TMSLayer.java there are several casts from double to int, so rounding is performed towards zero.

int img_x_offset = (int)(screen_x_offset * imageXScaling);
int img_y_offset = (int)(screen_y_offset * imageYScaling);

int img_x_end = img_x_offset + (int)(target.getWidth() * imageXScaling);
int img_y_end = img_y_offset + (int)(target.getHeight() * imageYScaling);

However, the values before rounding are often close to integer values. In some cases they are less then the nearest integer and are like 255.999..., but in some cases they are greater, for example 256.000... This causes corresponding integer value to be decreased by one randomly.

I have changed these lines to make rounding to the nearest value:

int img_x_offset = (int)(screen_x_offset * imageXScaling + 0.5);
int img_y_offset = (int)(screen_y_offset * imageYScaling + 0.5);

int img_x_end = img_x_offset + (int)(target.getWidth() * imageXScaling + 0.5);
int img_y_end = img_y_offset + (int)(target.getHeight() * imageYScaling + 0.5);

I have noticed several enhancements in appearance of the imagery by comparing the old version and the new one by running them simultaneously.

  1. Zooming of the map has become much smoother and some jitter, which was previously present, has disappeared.
  2. While dragging the map, new tiles previously sometimes appeared misplaced by about a pixel, and after dragging further, they jumped to the correct position. After the fix the imagery looks more solid.
  3. When zoomed to the maximum level and trying to zoom more, the imagery previously jumped to a random offset each time.

I'm not sure that this is the correct way to fix the bug, because I don't understand the whole process of calculating offsets and rendering the tiles, and I need help of somebody experienced in this.

Also, similar pieces of code should be checked (for example, WMSLayer) to see, if this bug affects them too.

Attachments (4)

bug_zoom1.png (145.3 KB ) - added by asdqweasd 9 years ago.
bug_zoom2.png (129.6 KB ) - added by asdqweasd 9 years ago.
fixed_zoom1.png (131.4 KB ) - added by asdqweasd 9 years ago.
fixed_zoom2.png (119.8 KB ) - added by asdqweasd 9 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 by stoecker, 9 years ago

Milestone: 15.03
Summary: Rounding errors in displaying of tiles[PATCH] Rounding errors in displaying of tiles

comment:2 by stoecker, 9 years ago

Can you please give an example (i.e. position and comparing screenshots). Patch looks good to me, but I'd like to see the effect.

by asdqweasd, 9 years ago

Attachment: bug_zoom1.png added

by asdqweasd, 9 years ago

Attachment: bug_zoom2.png added

by asdqweasd, 9 years ago

Attachment: fixed_zoom1.png added

by asdqweasd, 9 years ago

Attachment: fixed_zoom2.png added

comment:3 by asdqweasd, 9 years ago

Yes, certainly. I have made some screenshots to show the difference.

Steps to reproduce:

  1. Open JOSM
  2. Select Imagery->ScanEx IRS
  3. Create a new layer
  4. Create a node in this layer
  5. Take the first screenshot (..._zoom1.png)
  6. Zoom in so that the node doesn't move (do not move cursor after the node is created)
  7. Take the second screenshow (..._zoom2.png)

I have done this twice: for buggy version and for fixed version. In the buggy version you can see that imagery becomes displaced relative to the node after zooming, while in the fixed version imagery stays in place.

comment:4 by asdqweasd, 9 years ago

However, screenshots are not enough to see what happens, while tiles are loaded, because it happens quickly and I can't capture them at the right time. So video capture is required, but I'm not sure, how to do it on my system.

comment:5 by stoecker, 9 years ago

Buggy:

Fixed:

comment:6 by stoecker, 9 years ago

Resolution: fixed
Status: newclosed

In 8153/josm:

fix #11263 - displacement in TMS layers - fix by asdqweasd

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain team.
as The resolution will be set.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.