Reduce margin to 1px, remove calls to gc(), update comments by

jmakovicka 

Signed-off-by: yvecai <yvecai@gmail.com>
This commit is contained in:
yvecai 2012-02-09 19:23:00 +01:00 committed by Jindřich Makovička
parent 8a753b2ef7
commit f96d7ab203

View file

@ -39,7 +39,7 @@ public class SQLiteTileSource implements ITileSource {
private int maxZoom = 17;
private int baseZoom = 17; //Default base zoom
final int margin = 6;
final int margin = 1;
final int tileSize = 256;
public SQLiteTileSource(File f, List<TileSourceTemplate> toFindUrl){
@ -202,12 +202,9 @@ public class SQLiteTileSource implements ITileSource {
}
private Bitmap getMetaTile(int x, int y, int zoom, int flags) {
// return a 268x268 tile ((6+256+6)x(6+256+6) px) around a given tile
// return a (tileSize+2*margin)^2 tile around a given tile
// based on its neighbor. This is needed to have a nice bilinear resampling
// on tile edges. A 258x258 would do well, but maybe somebody wants to
// implement bicubic resampling for nicer effect.
// The code looks bad because we load only one 256x256 bitmap at a time
// instead of cropping from a 768x768 bitmap, which causes memory issues.
// on tile edges. Margin of 1 is enough for bilinear resampling.
SQLiteDatabase db = getDatabase();
if(db == null){
@ -246,8 +243,7 @@ public class SQLiteTileSource implements ITileSource {
}
}
}
System.gc();
return stitchedImage; // return a 256x256 tile + 6px margin
return stitchedImage; // return a tileSize+2*margin size image
}
public Bitmap getImage(int x, int y, int zoom) {
@ -255,7 +251,6 @@ public class SQLiteTileSource implements ITileSource {
if(db == null){
return null;
}
if (zoom > maxZoom) return null;
if ( zoom <= baseZoom) {
// return the normal tile if exists
Cursor cursor = db.rawQuery("SELECT image FROM tiles WHERE x = ? AND y = ? AND z = ?", new String[] {x+"", y+"",(17 - zoom)+""}); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
@ -278,6 +273,9 @@ public class SQLiteTileSource implements ITileSource {
int offset_x= x - (base_xtile << n);
int offset_y= y - (base_ytile << n);
int flags = 0x020;
if (scaledSize < 8)
return null;
if (offset_x == 0)
flags |= 0x444;
@ -287,7 +285,7 @@ public class SQLiteTileSource implements ITileSource {
flags |= 0x700;
else if (offset_y == (1 << n) - 1)
flags |= 0x007;
Bitmap metaTile = getMetaTile(base_xtile, base_ytile, baseZoom, flags);
if(metaTile != null){
@ -295,19 +293,19 @@ public class SQLiteTileSource implements ITileSource {
int delta_px = scaledSize * offset_x;
int delta_py = scaledSize * offset_y;
Bitmap xn = Bitmap.createBitmap(metaTile,
delta_px, //(+6)
delta_py, //(+6)
scaledSize + 2 * margin,
scaledSize + 2 * margin);
metaTile.recycle();
int scaleto = 256 + ((2 * margin) << n);
Bitmap scaled = Bitmap.createScaledBitmap(xn,scaleto,scaleto,true);
xn.recycle();
return Bitmap.createBitmap(scaled, (margin << n), (margin << n), 256, 256);
Bitmap xn = Bitmap.createBitmap(metaTile,
delta_px,
delta_py,
scaledSize + 2 * margin,
scaledSize + 2 * margin);
metaTile.recycle();
int scaleto = tileSize + ((2 * margin) << n);
Bitmap scaled = Bitmap.createScaledBitmap(xn,scaleto,scaleto,true);
xn.recycle();
return Bitmap.createBitmap(scaled, (margin << n), (margin << n), tileSize, tileSize);
}
return null;
}
}
}
public ITileSource getBase() {
return base;