if (progress != null)
progress.startProgress();
long time = System.currentTimeMillis();
TileCacheEntry tce = null;
if (useCache && (img.getWidth() >= minCacheSize && img.getHeight() >= minCacheSize)) {
tce = CacheTileManager.getCache(c, px, py, img.getWidth(), img.getHeight(), globalXres, globalYres);
}
for (int y = 0; y < img.getHeight(); y++) {
if (progress != null)
progress.setProgress(y / (float) img.getHeight());
for (int x = 0; x < img.getWidth(); x++) {
float u = (float) (x + px * img.getWidth()) / (float) globalXres;
float v = (float) (y + py * img.getHeight()) / (float) globalYres;
final Vector4 col;
if (tce == null) col = c.valueRGBA(u, v);
else col = tce.sample(x, y);
final Vector3 color = new Vector3();
int val;
// !!UGH TODO: optimize this!!
if (mode == 0) {