use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class FlameRenderer method renderSlices.
public void renderSlices(SliceRenderInfo pSliceRenderInfo, String pFilenamePattern) {
if (!flame.isRenderable())
throw new RuntimeException("Slices can not be created of empty flames");
int fileIdx = 1;
int passes = pSliceRenderInfo.getSlices() / pSliceRenderInfo.getSlicesPerRender();
if (pSliceRenderInfo.getSlices() % pSliceRenderInfo.getSlicesPerRender() != 0)
passes++;
progressDisplayPhaseCount = passes;
double zmin = pSliceRenderInfo.getZmin() < pSliceRenderInfo.getZmax() ? pSliceRenderInfo.getZmin() : pSliceRenderInfo.getZmax();
double zmax = pSliceRenderInfo.getZmin() < pSliceRenderInfo.getZmax() ? pSliceRenderInfo.getZmax() : pSliceRenderInfo.getZmin();
double thickness = (zmax - zmin) / (double) pSliceRenderInfo.getSlices();
double currZ = zmax;
int currSlice = 0;
for (int pass = 0; pass < passes; pass++) {
if (forceAbort) {
break;
}
System.gc();
progressDisplayPhase = pass;
Flame currFlame = flame.makeCopy();
prepareFlameForSliceRendering(currFlame);
initRasterSizes(pSliceRenderInfo.getImageWidth(), pSliceRenderInfo.getImageHeight());
List<RenderSlice> slices = new ArrayList<RenderSlice>();
for (int i = 0; i < pSliceRenderInfo.getSlicesPerRender() && currSlice < pSliceRenderInfo.getSlices(); i++) {
RenderSlice slice = new RenderSlice(allocRaster(flame.getSpatialOversampling(), flame.getSampleDensity()), currZ - thickness, currZ);
slices.add(slice);
currZ -= thickness;
currSlice++;
}
List<List<RenderPacket>> renderFlames = new ArrayList<List<RenderPacket>>();
for (int t = 0; t < prefs.getTinaRenderThreads(); t++) {
renderFlames.add(createRenderPackets(flame, flame.getFrame()));
}
iterate(0, 1, renderFlames, slices);
if (!forceAbort) {
LogDensityPoint logDensityPnt = new LogDensityPoint(flame.getActiveLightCount());
while (slices.size() > 0) {
if (forceAbort) {
break;
}
RenderSlice slice = slices.get(0);
RenderedFlame renderedFlame = new RenderedFlame();
renderedFlame.init(pSliceRenderInfo.createRenderInfo(), flame);
SimpleImage img = renderedFlame.getImage();
logDensityFilter.setRaster(slice.getRaster(), rasterWidth, rasterHeight, img.getImageWidth(), img.getImageHeight());
GammaCorrectedRGBPoint rbgPoint = new GammaCorrectedRGBPoint();
for (int i = 0; i < img.getImageHeight(); i++) {
for (int j = 0; j < img.getImageWidth(); j++) {
logDensityFilter.transformPoint(logDensityPnt, j, i);
gammaCorrectionFilter.transformPoint(logDensityPnt, rbgPoint, j, i);
img.setARGB(j, i, rbgPoint.alpha, rbgPoint.red, rbgPoint.green, rbgPoint.blue);
}
}
String filename = String.format(pFilenamePattern, fileIdx++);
try {
new ImageWriter().saveImage(renderedFlame.getImage(), filename);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
slice = null;
slices.remove(0);
}
}
}
}
use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class FlameRenderer method renderImageSimple.
private void renderImageSimple(SimpleImage pImage) {
int threadCount = prefs.getTinaRenderThreads();
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);
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 < threadCount - 1 ? startRow + rowsPerThread : pImage.getImageHeight();
RenderImageSimpleScaledThread thread = new RenderImageSimpleScaledThread(flame, logDensityFilter, gammaCorrectionFilter, renderScale, startRow, endRow, pImage, newImg);
threads.add(thread);
if (threadCount > 1) {
new Thread(thread).start();
} else {
thread.run();
}
}
ThreadTools.waitForThreads(threadCount, threads);
pImage.setBufferedImage(newImg.getBufferedImg(), newImg.getImageWidth(), newImg.getImageHeight());
} else if (renderScale == 1) {
int rowsPerThread = pImage.getImageHeight() / threadCount;
List<RenderImageSimpleThread> threads = new ArrayList<RenderImageSimpleThread>();
for (int i = 0; i < threadCount; i++) {
int startRow = i * rowsPerThread;
int endRow = i < rowsPerThread - 1 ? startRow + rowsPerThread : pImage.getImageHeight();
RenderImageSimpleThread thread = new RenderImageSimpleThread(flame, logDensityFilter, gammaCorrectionFilter, startRow, endRow, pImage);
threads.add(thread);
if (threadCount > 1) {
new Thread(thread).start();
} else {
thread.run();
}
}
ThreadTools.waitForThreads(threadCount, threads);
} else {
throw new IllegalArgumentException("renderScale " + renderScale);
}
}
use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class RandomFlameGeneratorSampler method calculateDiffCoverage.
public static double calculateDiffCoverage(SimpleImage pImg, SimpleImage pSimplifiedRefImg) {
SimpleImage img = createSimplifiedRefImage(pImg);
long maxCoverage = img.getImageWidth() * img.getImageHeight();
long coverage = 0;
Pixel pixel = new Pixel();
Pixel refPixel = new Pixel();
for (int k = 0; k < img.getImageHeight(); k++) {
for (int l = 0; l < img.getImageWidth(); l++) {
pixel.setARGBValue(img.getARGBValue(l, k));
refPixel.setARGBValue(pSimplifiedRefImg.getARGBValue(l, k));
if (fabs(pixel.r - refPixel.r) > 29.0 || fabs(pixel.g - refPixel.g) > 15.0 || fabs(pixel.b - refPixel.b) > 78.0) {
coverage++;
}
}
}
// System.out.println((double) coverage / (double) maxCoverage);
return (double) coverage / (double) maxCoverage;
}
use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class RandomFlameGeneratorSampler method createSimplifiedRefImage.
public static SimpleImage createSimplifiedRefImage(SimpleImage pImg) {
SimpleImage img = pImg.clone();
PixelizeTransformer pT = new PixelizeTransformer();
pT.setCentre(false);
pT.setGridSize(5);
pT.transformImage(img);
return img;
}
use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class RandomFlameGeneratorSampler method calculateCoverage.
public static double calculateCoverage(SimpleImage pImg, int bgRed, int bgGreen, int bgBlue, boolean useFilter) {
SimpleImage img;
if (useFilter) {
SimpleImage filteredImg = new SimpleImage(pImg.getBufferedImg(), pImg.getImageWidth(), pImg.getImageHeight());
ConvolveTransformer transformer = new ConvolveTransformer();
transformer.initDefaultParams(filteredImg);
transformer.setKernelType(KernelType.SOBEL_3X3);
transformer.transformImage(filteredImg);
img = filteredImg;
} else {
img = pImg;
}
long maxCoverage = img.getImageWidth() * img.getImageHeight();
long coverage = 0;
Pixel pixel = new Pixel();
if (bgRed == 0 && bgGreen == 0 && bgBlue == 0) {
for (int k = 0; k < img.getImageHeight(); k++) {
for (int l = 0; l < img.getImageWidth(); l++) {
pixel.setARGBValue(img.getARGBValue(l, k));
if (pixel.r > 29 || pixel.g > 15 || pixel.b > 78) {
coverage++;
}
}
}
} else {
for (int k = 0; k < img.getImageHeight(); k++) {
for (int l = 0; l < img.getImageWidth(); l++) {
pixel.setARGBValue(img.getARGBValue(l, k));
if (Math.abs(pixel.r - bgRed) > 29.0 && Math.abs(pixel.g - bgGreen) > 15.0 && Math.abs(pixel.b - bgBlue) > 78.0) {
coverage++;
}
}
}
}
return (double) coverage / (double) maxCoverage;
}
Aggregations