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 maxZoom = 17;
private int baseZoom = 17; //Default base zoom private int baseZoom = 17; //Default base zoom
final int margin = 6; final int margin = 1;
final int tileSize = 256; final int tileSize = 256;
public SQLiteTileSource(File f, List<TileSourceTemplate> toFindUrl){ 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) { 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 // 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 // on tile edges. Margin of 1 is enough for bilinear resampling.
// 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.
SQLiteDatabase db = getDatabase(); SQLiteDatabase db = getDatabase();
if(db == null){ if(db == null){
@ -246,8 +243,7 @@ public class SQLiteTileSource implements ITileSource {
} }
} }
} }
System.gc(); return stitchedImage; // return a tileSize+2*margin size image
return stitchedImage; // return a 256x256 tile + 6px margin
} }
public Bitmap getImage(int x, int y, int zoom) { public Bitmap getImage(int x, int y, int zoom) {
@ -255,7 +251,6 @@ public class SQLiteTileSource implements ITileSource {
if(db == null){ if(db == null){
return null; return null;
} }
if (zoom > maxZoom) return null;
if ( zoom <= baseZoom) { if ( zoom <= baseZoom) {
// return the normal tile if exists // 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$ 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_x= x - (base_xtile << n);
int offset_y= y - (base_ytile << n); int offset_y= y - (base_ytile << n);
int flags = 0x020; int flags = 0x020;
if (scaledSize < 8)
return null;
if (offset_x == 0) if (offset_x == 0)
flags |= 0x444; flags |= 0x444;
@ -287,7 +285,7 @@ public class SQLiteTileSource implements ITileSource {
flags |= 0x700; flags |= 0x700;
else if (offset_y == (1 << n) - 1) else if (offset_y == (1 << n) - 1)
flags |= 0x007; flags |= 0x007;
Bitmap metaTile = getMetaTile(base_xtile, base_ytile, baseZoom, flags); Bitmap metaTile = getMetaTile(base_xtile, base_ytile, baseZoom, flags);
if(metaTile != null){ if(metaTile != null){
@ -295,19 +293,19 @@ public class SQLiteTileSource implements ITileSource {
int delta_px = scaledSize * offset_x; int delta_px = scaledSize * offset_x;
int delta_py = scaledSize * offset_y; int delta_py = scaledSize * offset_y;
Bitmap xn = Bitmap.createBitmap(metaTile, Bitmap xn = Bitmap.createBitmap(metaTile,
delta_px, //(+6) delta_px,
delta_py, //(+6) delta_py,
scaledSize + 2 * margin, scaledSize + 2 * margin,
scaledSize + 2 * margin); scaledSize + 2 * margin);
metaTile.recycle(); metaTile.recycle();
int scaleto = 256 + ((2 * margin) << n); int scaleto = tileSize + ((2 * margin) << n);
Bitmap scaled = Bitmap.createScaledBitmap(xn,scaleto,scaleto,true); Bitmap scaled = Bitmap.createScaledBitmap(xn,scaleto,scaleto,true);
xn.recycle(); xn.recycle();
return Bitmap.createBitmap(scaled, (margin << n), (margin << n), 256, 256); return Bitmap.createBitmap(scaled, (margin << n), (margin << n), tileSize, tileSize);
} }
return null; return null;
} }
} }
public ITileSource getBase() { public ITileSource getBase() {
return base; return base;