use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class BaseFlameListCreator method createParamMapList.
private List<SimpleImage> createParamMapList(SimpleImage structureMap, int pIndex) {
List<SimpleImage> res = new ArrayList<SimpleImage>();
for (FlameParams flameParam : flameParams) {
SimpleImage paramMap = null;
try {
String flameParamname;
String flameParamMapFilename;
switch(pIndex) {
case 0:
flameParamname = flameParam.getFlameParam1();
flameParamMapFilename = flameParam.getFlameParamMap1Filename();
break;
case 1:
flameParamname = flameParam.getFlameParam2();
flameParamMapFilename = flameParam.getFlameParamMap2Filename();
break;
case 2:
flameParamname = flameParam.getFlameParam3();
flameParamMapFilename = flameParam.getFlameParamMap3Filename();
break;
default:
throw new IllegalArgumentException();
}
if (flameParamname != null && flameParamname.length() > 0 && flameParamMapFilename != null && flameParamMapFilename.length() > 0) {
SimpleImage map = (SimpleImage) RessourceManager.getImage(flameParamMapFilename);
if ((map.getImageWidth() != structureMap.getImageWidth()) || (map.getImageHeight() != structureMap.getImageHeight())) {
map = map.clone();
ScaleTransformer scaleT = new ScaleTransformer();
scaleT.setScaleWidth(structureMap.getImageWidth());
scaleT.setScaleHeight(structureMap.getImageHeight());
scaleT.setAspect(ScaleAspect.IGNORE);
scaleT.transformImage(map);
paramMap = map;
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
res.add(paramMap);
}
return res;
}
use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class BaseFlameListCreator method preprocessImage.
private void preprocessImage(SimpleImage tImage) {
if (imageParams.getErode() == 1) {
long t0 = System.currentTimeMillis();
ErodeTransformer eT = new ErodeTransformer();
eT.initDefaultParams(tImage);
eT.setMode(ErodeTransformer.Mode.DILATE);
eT.setSize(imageParams.getErodeSize());
eT.setShape(ErodeTransformer.Shape.DISK);
eT.transformImage(tImage);
long t1 = System.currentTimeMillis();
statistics.getAction(ActionType.ERODE).setDuration(t1 - t0);
currProgress += updatePreprocessStep;
progressUpdater.updateProgress(currProgress);
}
List<SimpleImage> convImages = new ArrayList<SimpleImage>();
if (imageParams.getConv_north() == 1) {
long t0 = System.currentTimeMillis();
SimpleImage north = tImage.clone();
ConvolveTransformer transformer = new ConvolveTransformer();
transformer.initDefaultParams(north);
transformer.setKernelType(KernelType.SOBEL_3X3);
transformer.setKernelDirection(KernelDirection.NORTH);
transformer.setColorMode(ColorMode.GREY);
transformer.transformImage(north);
convImages.add(north);
long t1 = System.currentTimeMillis();
statistics.getAction(ActionType.CONV_NORTH).setDuration(t1 - t0);
currProgress += updatePreprocessStep;
progressUpdater.updateProgress(currProgress);
}
if (imageParams.getConv_east() == 1) {
long t0 = System.currentTimeMillis();
SimpleImage east = tImage.clone();
ConvolveTransformer transformer = new ConvolveTransformer();
transformer.initDefaultParams(east);
transformer.setKernelType(KernelType.SOBEL_3X3);
transformer.setKernelDirection(KernelDirection.EAST);
transformer.setColorMode(ColorMode.GREY);
transformer.transformImage(east);
convImages.add(east);
long t1 = System.currentTimeMillis();
statistics.getAction(ActionType.CONV_EAST).setDuration(t1 - t0);
currProgress += updatePreprocessStep;
progressUpdater.updateProgress(currProgress);
}
if (imageParams.getConv_south() == 1) {
long t0 = System.currentTimeMillis();
SimpleImage south = tImage.clone();
ConvolveTransformer transformer = new ConvolveTransformer();
transformer.initDefaultParams(south);
transformer.setKernelType(KernelType.SOBEL_3X3);
transformer.setKernelDirection(KernelDirection.SOUTH);
transformer.setColorMode(ColorMode.GREY);
transformer.transformImage(south);
convImages.add(south);
long t1 = System.currentTimeMillis();
statistics.getAction(ActionType.CONV_SOUTH).setDuration(t1 - t0);
currProgress += updatePreprocessStep;
progressUpdater.updateProgress(currProgress);
}
if (imageParams.getConv_west() == 1) {
long t0 = System.currentTimeMillis();
SimpleImage west = tImage.clone();
ConvolveTransformer transformer = new ConvolveTransformer();
transformer.initDefaultParams(west);
transformer.setKernelType(KernelType.SOBEL_3X3);
transformer.setKernelDirection(KernelDirection.WEST);
transformer.setColorMode(ColorMode.GREY);
transformer.transformImage(west);
convImages.add(west);
long t1 = System.currentTimeMillis();
statistics.getAction(ActionType.CONV_WEST).setDuration(t1 - t0);
currProgress += updatePreprocessStep;
progressUpdater.updateProgress(currProgress);
}
if (convImages.size() == 1) {
SimpleImage convImage = convImages.get(0);
tImage.setBufferedImage(convImage.getBufferedImg(), convImage.getImageWidth(), convImage.getImageHeight());
} else if (convImages.size() > 1) {
long t0 = System.currentTimeMillis();
for (int i = 0; i < tImage.getImageHeight(); i++) {
for (int j = 0; j < tImage.getImageWidth(); j++) {
int r = 0, g = 0, b = 0;
for (SimpleImage convImage : convImages) {
r += convImage.getRValue(j, i);
g += convImage.getGValue(j, i);
b += convImage.getBValue(j, i);
}
r = Tools.roundColor((double) r / (double) convImages.size());
g = Tools.roundColor((double) g / (double) convImages.size());
b = Tools.roundColor((double) b / (double) convImages.size());
tImage.setRGB(j, i, r, g, b);
}
}
long t1 = System.currentTimeMillis();
statistics.getAction(ActionType.CONV_MERGE).setDuration(t1 - t0);
currProgress += updatePreprocessStep;
progressUpdater.updateProgress(currProgress);
}
}
use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class FlameParamsList method setRessource.
public boolean setRessource(String pName, byte[] pValue) {
for (int i = 1; i <= size(); i++) {
String flameIndexStr = getFlameIndexStr(i);
if ((RESSOURCE_FLAME + flameIndexStr).equalsIgnoreCase(pName)) {
String flameXML = pValue != null ? new String(pValue) : "";
if (flameXML.length() > 0) {
parseFlame(flameXML);
get(i - 1).setFlameXML(flameXML);
} else {
get(i - 1).setFlameXML(null);
}
return true;
} else if ((RESSOURCE_FLAME_PARAM1 + flameIndexStr).equalsIgnoreCase(pName)) {
get(i - 1).setFlameParam1(pValue != null ? new String(pValue) : "");
return true;
} else if ((RESSOURCE_FLAME_PARAM1_MAP + flameIndexStr).equalsIgnoreCase(pName)) {
String filename = pValue != null ? new String(pValue) : "";
SimpleImage map = null;
if (filename.length() > 0) {
try {
WFImage img = RessourceManager.getImage(filename);
if (img.getImageWidth() < 8 || img.getImageHeight() < 8 || !(img instanceof SimpleImage)) {
throw new Exception("Invalid param map");
}
map = (SimpleImage) img;
} catch (Exception ex) {
ex.printStackTrace();
}
}
get(i - 1).setFlameParamMap1Filename(map != null ? filename : null);
return true;
} else if ((RESSOURCE_FLAME_PARAM2 + flameIndexStr).equalsIgnoreCase(pName)) {
get(i - 1).setFlameParam2(pValue != null ? new String(pValue) : "");
return true;
} else if ((RESSOURCE_FLAME_PARAM2_MAP + flameIndexStr).equalsIgnoreCase(pName)) {
String filename = pValue != null ? new String(pValue) : "";
SimpleImage map = null;
if (filename.length() > 0) {
try {
WFImage img = RessourceManager.getImage(filename);
if (img.getImageWidth() < 8 || img.getImageHeight() < 8 || !(img instanceof SimpleImage)) {
throw new Exception("Invalid param map");
}
map = (SimpleImage) img;
} catch (Exception ex) {
ex.printStackTrace();
}
}
get(i - 1).setFlameParamMap2Filename(map != null ? filename : null);
return true;
} else if ((RESSOURCE_FLAME_PARAM3 + flameIndexStr).equalsIgnoreCase(pName)) {
get(i - 1).setFlameParam3(pValue != null ? new String(pValue) : "");
return true;
} else if ((RESSOURCE_FLAME_PARAM3_MAP + flameIndexStr).equalsIgnoreCase(pName)) {
String filename = pValue != null ? new String(pValue) : "";
SimpleImage map = null;
if (filename.length() > 0) {
try {
WFImage img = RessourceManager.getImage(filename);
if (img.getImageWidth() < 8 || img.getImageHeight() < 8 || !(img instanceof SimpleImage)) {
throw new Exception("Invalid param map");
}
map = (SimpleImage) img;
} catch (Exception ex) {
ex.printStackTrace();
}
}
get(i - 1).setFlameParamMap3Filename(map != null ? filename : null);
return true;
}
}
return false;
}
use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class FlameRenderer method postFilterImage.
private void postFilterImage(SimpleImage pImage) {
if (pImage != null) {
int threadCount = prefs.getTinaRenderThreads();
if (threadCount < 1 || pImage.getImageHeight() < 8 * threadCount) {
threadCount = 1;
}
int rowsPerThread = pImage.getImageHeight() / threadCount;
SimpleImage input = pImage.clone();
List<PostFilterImageThread> threads = new ArrayList<PostFilterImageThread>();
for (int i = 0; i < threadCount; i++) {
int startRow = i * rowsPerThread;
int endRow = i < threadCount - 1 ? startRow + rowsPerThread : pImage.getImageHeight();
PostFilterImageThread thread = new PostFilterImageThread(startRow, endRow, input, pImage, flame.getPostNoiseFilterThreshold());
threads.add(thread);
if (threadCount > 1) {
new Thread(thread).start();
} else {
thread.run();
}
}
ThreadTools.waitForThreads(threadCount, threads);
}
}
use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class FlameRenderer method renderStereo3dAnaglyph.
private RenderedFlame renderStereo3dAnaglyph(RenderInfo pRenderInfo) {
RenderInfo localRenderInfo = pRenderInfo.makeCopy();
localRenderInfo.setRenderHDR(false);
localRenderInfo.setRenderZBuffer(false);
eye = Stereo3dEye.LEFT;
RenderedFlame leftRender = renderImageNormal(localRenderInfo, 2, 0);
eye = Stereo3dEye.RIGHT;
RenderedFlame rightRender = renderImageNormal(localRenderInfo, 2, 1);
if (flame.isStereo3dSwapSides()) {
RenderedFlame tmp = leftRender;
leftRender = rightRender;
rightRender = tmp;
}
Pixel lPixel = new Pixel();
Pixel rPixel = new Pixel();
Stereo3dColor leftColor = flame.getAnaglyph3dLeftEyeColor();
Stereo3dColor rightColor = flame.getAnaglyph3dRightEyeColor();
SimpleImage leftImg = leftRender.getImage();
SimpleImage rightImg = rightRender.getImage();
RenderedFlame mergedRender = new RenderedFlame();
localRenderInfo.setImageWidth(leftRender.getImage().getImageWidth());
localRenderInfo.setImageHeight(leftRender.getImage().getImageHeight());
mergedRender.init(localRenderInfo, flame);
SimpleImage mergedImg = mergedRender.getImage();
for (int i = 0; i < mergedImg.getImageHeight(); i++) {
for (int j = 0; j < mergedImg.getImageWidth(); j++) {
lPixel.setARGBValue(leftImg.getARGBValue(j, i));
rPixel.setARGBValue(rightImg.getARGBValue(j, i));
int mr = leftColor.calculateRed(lPixel.r, lPixel.g, lPixel.b) + rightColor.calculateRed(rPixel.r, rPixel.g, rPixel.b);
if (mr < 0)
mr = 0;
else if (mr > 255)
mr = 255;
int mg = leftColor.calculateGreen(lPixel.r, lPixel.g, lPixel.b) + rightColor.calculateGreen(rPixel.r, rPixel.g, rPixel.b);
if (mg < 0)
mg = 0;
else if (mg > 255)
mg = 255;
int mb = leftColor.calculateBlue(lPixel.r, lPixel.g, lPixel.b) + rightColor.calculateBlue(rPixel.r, rPixel.g, rPixel.b);
if (mb < 0)
mb = 0;
else if (mb > 255)
mb = 255;
mergedImg.setRGB(j, i, mr, mg, mb);
}
}
return mergedRender;
}
Aggregations