int threadCount = prefs.getTinaRenderThreads() - 1;
if (threadCount < 1)
threadCount = 1;
logDensityFilter.setRaster(raster, rasterWidth, rasterHeight, pImage.getImageWidth(), pImage.getImageHeight());
if (renderScale == 2) {
SimpleImage newImg = new SimpleImage(pImage.getImageWidth() * renderScale, pImage.getImageHeight() * renderScale);
if (threadCount == 1) {
LogDensityPoint logDensityPnt = new LogDensityPoint();
GammaCorrectedRGBPoint rbgPoint = new GammaCorrectedRGBPoint();
for (int i = 0; i < pImage.getImageHeight(); i++) {
for (int j = 0; j < pImage.getImageWidth(); j++) {
logDensityFilter.transformPointSimple(logDensityPnt, j, i);
gammaCorrectionFilter.transformPoint(logDensityPnt, rbgPoint);
int x = j * renderScale;
int y = i * renderScale;
newImg.setARGB(x, y, rbgPoint.alpha, rbgPoint.red, rbgPoint.green, rbgPoint.blue);
newImg.setARGB(x + 1, y, rbgPoint.alpha, rbgPoint.red, rbgPoint.green, rbgPoint.blue);
newImg.setARGB(x, y + 1, rbgPoint.alpha, rbgPoint.red, rbgPoint.green, rbgPoint.blue);
newImg.setARGB(x + 1, y + 1, rbgPoint.alpha, rbgPoint.red, rbgPoint.green, rbgPoint.blue);
}
}
}
else {
int rowsPerThread = pImage.getImageHeight() / threadCount;
List<RenderImageSimpleScaledThread> threads = new ArrayList<RenderImageSimpleScaledThread>();
for (int i = 0; i < threadCount; i++) {
int startRow = i * rowsPerThread;
int endRow = i < rowsPerThread - 1 ? startRow + rowsPerThread : pImage.getImageHeight();
RenderImageSimpleScaledThread thread = new RenderImageSimpleScaledThread(startRow, endRow, pImage, newImg);
threads.add(thread);
thread.run();
}
while (true) {
boolean ready = true;
for (RenderImageSimpleScaledThread t : threads) {
if (!t.isDone()) {
ready = false;
break;
}
}
if (!ready) {
try {
Thread.sleep(1);
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
else
break;
}
}
pImage.setBufferedImage(newImg.getBufferedImg(), newImg.getImageWidth(), newImg.getImageHeight());
}
else if (renderScale == 1) {
if (threadCount == 1) {
LogDensityPoint logDensityPnt = new LogDensityPoint();
GammaCorrectedRGBPoint rbgPoint = new GammaCorrectedRGBPoint();