use of org.jwildfire.transform.ScaleTransformer in project JWildfire by thargor6.
the class ImageFilePreview method createThumbnail.
public void createThumbnail() {
if (currFile == null) {
currThumbnail = null;
return;
}
try {
if (currFile.exists()) {
String fileExt = null;
{
String filename = currFile.getName();
int p = filename.lastIndexOf(".");
if (p >= 0 && p < filename.length() - 2) {
fileExt = filename.substring(p + 1, filename.length());
}
}
if ("hdr".equalsIgnoreCase(fileExt)) {
SimpleHDRImage hdrImg = new ImageReader(this).loadHDRImage(currFile.getAbsolutePath());
SimpleImage img = new FastHDRTonemapper().renderImage(hdrImg);
ScaleTransformer scaleT = new ScaleTransformer();
scaleT.setScaleWidth(THUMBNAIL_WIDTH);
scaleT.setAspect(ScaleAspect.KEEP_WIDTH);
scaleT.setUnit(Unit.PIXELS);
scaleT.transformImage(img);
currThumbnail = new ImageIcon(img.getBufferedImg(), currFile.getName());
} else {
ImageIcon tmpIcon = new ImageIcon(currFile.getPath());
if (tmpIcon != null) {
if (tmpIcon.getIconWidth() > THUMBNAIL_WIDTH) {
currThumbnail = new ImageIcon(tmpIcon.getImage().getScaledInstance(THUMBNAIL_WIDTH, -1, Image.SCALE_DEFAULT));
} else {
currThumbnail = tmpIcon;
}
}
}
}
} catch (Throwable ex) {
ex.printStackTrace();
}
}
use of org.jwildfire.transform.ScaleTransformer in project JWildfire by thargor6.
the class ImageThumbnail method generatePreview.
private SimpleImage generatePreview() {
if (cacheKey != null) {
SimpleImage img = ThumbnailCacheProvider.getThumbnail(cacheKey, IMG_WIDTH);
if (img != null) {
return img;
}
}
SimpleImage image;
try {
image = ((SimpleImage) RessourceManager.getImage(filename));
RessourceManager.clearImage(filename);
ScaleTransformer scaleT = new ScaleTransformer();
scaleT.setScaleWidth(IMG_WIDTH);
scaleT.setAspect(ScaleAspect.KEEP_WIDTH);
scaleT.transformImage(image);
if (cacheKey != null) {
ThumbnailCacheProvider.storeThumbnail(cacheKey, IMG_WIDTH, image);
}
return image;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
use of org.jwildfire.transform.ScaleTransformer in project JWildfire by thargor6.
the class BaseFlameListCreator method calcBaseFlameList.
public List<BaseFlame> calcBaseFlameList(FlameTransformationContext pContext, WFImage pColorMap) {
instances.clear();
currProgress = 0;
iteratorCount = 0;
long totalT0 = System.currentTimeMillis();
if (!(pColorMap instanceof SimpleImage)) {
return Collections.emptyList();
}
SimpleImage colorMap = (SimpleImage) pColorMap;
initStatistics(colorMap);
SimpleImage structureMap = (SimpleImage) RessourceManager.getRessource(imageParams.getCachedPreprocessedImageKey());
if (structureMap == null) {
structureMap = colorMap.clone();
if (structureMap.getImageWidth() > imageParams.getMaxImgWidth()) {
long t0 = System.currentTimeMillis();
structureMap = structureMap.clone();
ScaleTransformer scaleT = new ScaleTransformer();
scaleT.setScaleWidth(imageParams.getMaxImgWidth());
scaleT.setAspect(ScaleAspect.KEEP_WIDTH);
scaleT.transformImage(structureMap);
long t1 = System.currentTimeMillis();
statistics.getAction(ActionType.SCALE).setDuration(t1 - t0);
currProgress += updatePreprocessStep;
progressUpdater.updateProgress(currProgress);
}
preprocessImage(structureMap);
RessourceManager.putRessource(imageParams.getCachedPreprocessedImageKey(), structureMap);
System.out.println("CALCED STRUCTURE MAP");
} else {
System.out.println("STRUCTUREMAP FROM CACHE");
}
List<SimpleImage> paramMaps1 = createParamMapList(structureMap, 0);
List<SimpleImage> paramMaps2 = createParamMapList(structureMap, 1);
List<SimpleImage> paramMaps3 = createParamMapList(structureMap, 2);
List<BaseFlame> res = new ArrayList<BaseFlame>();
int nextProgressUpdate = updateMainProgressStep;
long t0 = System.currentTimeMillis();
if (ShapeDistribution.GRID.equals(imageParams.getShape_distribution())) {
for (int i = 0; i < structureMap.getImageHeight(); i++) {
for (int j = 0; j < structureMap.getImageWidth(); j++) {
toolPixel.setARGBValue(structureMap.getARGBValue(j, i));
double r = (double) toolPixel.r / COLORSCL;
double g = (double) toolPixel.g / COLORSCL;
double b = (double) toolPixel.b / COLORSCL;
double intensity = calcIntensity(r, g, b);
for (int k = 0; k < IFlamesFunc.MAX_FLAME_COUNT; k++) {
FlameParams params = flameParams.get(k);
if (params != null && params.getFlameXML() != null && params.getFlameXML().length() > 0) {
int xoffset = params.getGridXOffset();
int xsize = params.getGridXSize();
if (xsize > 0 && (xoffset + j) % xsize == 0) {
int yoffset = params.getGridYOffset();
int ysize = params.getGridYSize();
if (ysize > 0 && (yoffset + i) % ysize == 0) {
addBaseFlame(pContext, paramMaps1, paramMaps2, paramMaps3, res, i, j, intensity, k, params);
}
}
}
}
nextProgressUpdate--;
if (nextProgressUpdate == 0) {
nextProgressUpdate = updateMainProgressStep;
currProgress += updateMainProgressStep;
progressUpdater.updateProgress(currProgress);
}
}
}
} else {
for (int i = 0; i < structureMap.getImageHeight(); i++) {
for (int j = 0; j < structureMap.getImageWidth(); j++) {
toolPixel.setARGBValue(structureMap.getARGBValue(j, i));
double r = (double) toolPixel.r / COLORSCL;
double g = (double) toolPixel.g / COLORSCL;
double b = (double) toolPixel.b / COLORSCL;
double intensity = calcIntensity(r, g, b);
if (intensity > imageParams.getStructure_threshold()) {
if (imageParams.getStructure_density() > randGen.random()) {
toolPixel.setARGBValue(colorMap.getARGBValueIgnoreBounds(Tools.FTOI(j * imageParams.getScaleColorMap()), Tools.FTOI(i * imageParams.getScaleColorMap())));
int shapeIndex = calcShapeIndex(toolPixel.r, toolPixel.g, toolPixel.b);
FlameParams params = shapeIndex >= 0 && shapeIndex < flameParams.size() ? flameParams.get(shapeIndex) : null;
if (params != null && params.getFlameXML() != null && params.getFlameXML().length() > 0) {
addBaseFlame(pContext, paramMaps1, paramMaps2, paramMaps3, res, i, j, intensity, shapeIndex, params);
}
}
}
nextProgressUpdate--;
if (nextProgressUpdate == 0) {
nextProgressUpdate = updateMainProgressStep;
currProgress += updateMainProgressStep;
progressUpdater.updateProgress(currProgress);
}
}
}
}
long t1 = System.currentTimeMillis();
statistics.addAction(ActionType.CREATE_STRUCTURE);
statistics.getAction(ActionType.CREATE_STRUCTURE).setDuration(t1 - t0);
statistics.setIteratorCount(iteratorCount);
statistics.setFlameCount(res.size());
long totalT1 = System.currentTimeMillis();
statistics.setTotalDuration(totalT1 - totalT0);
return res;
}
Aggregations