Opened 10 years ago
Closed 10 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.
- Zooming of the map has become much smoother and some jitter, which was previously present, has disappeared.
- 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.
- 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)
Change History (10)
comment:1 by , 10 years ago
Milestone: | → 15.03 |
---|---|
Summary: | Rounding errors in displaying of tiles → [PATCH] Rounding errors in displaying of tiles |
comment:2 by , 10 years ago
by , 10 years ago
Attachment: | bug_zoom1.png added |
---|
by , 10 years ago
Attachment: | bug_zoom2.png added |
---|
by , 10 years ago
Attachment: | fixed_zoom1.png added |
---|
by , 10 years ago
Attachment: | fixed_zoom2.png added |
---|
comment:3 by , 10 years ago
Yes, certainly. I have made some screenshots to show the difference.
Steps to reproduce:
- Open JOSM
- Select Imagery->ScanEx IRS
- Create a new layer
- Create a node in this layer
- Take the first screenshot (..._zoom1.png)
- Zoom in so that the node doesn't move (do not move cursor after the node is created)
- 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 , 10 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.
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.