CompressionMethod cm = getCompressionMethod();
source.flush();
if (tiled) {
TileDescription td = getTiles();
int numTiles;
switch (td.getLevelMode()) {
case ONE_LEVEL:
numTiles = (1 + (dw.getYSize() - 1) / td.getYSize())
* (1 + (dw.getXSize() - 1) / td.getXSize());
break;
case MIPMAP_LEVELS:
{
int w = dw.getXSize();
int h = dw.getYSize();
int tw = td.getXSize();
int th = td.getYSize();
RoundingMode rm = td.getRoundingMode();
int n = 1 + round(Math.log(Math.max(w, h)) / Math.log(2.0), rm);
numTiles = 0;
for (int i = 0; i < n; i++) {
int lx = round(w / Math.pow(2.0, i), rm);
int ly = round(h / Math.pow(2.0, i), rm);
int tx = 1 + (lx - 1) / tw;
int ty = 1 + (ly - 1) / th;
numTiles += tx * ty;
}
break;
}
case RIPMAP_LEVELS:
{
int w = dw.getXSize();
int h = dw.getYSize();
int tw = td.getXSize();
int th = td.getYSize();
RoundingMode rm = td.getRoundingMode();
int nx = 1 + round(Math.log(w) / Math.log(2.0), rm);
int ny = 1 + round(Math.log(h) / Math.log(2.0), rm);
numTiles = 0;
for (int j = 0; j < ny; j++) {
int ly = round(h / Math.pow(2.0, j), rm);