use of org.jwildfire.image.WFImage in project JWildfire by thargor6.
the class FlameControlsDelegate method solidRenderingMaterialSelectReflMapBtn_clicked.
public void solidRenderingMaterialSelectReflMapBtn_clicked() {
MaterialSettings material = getSolidRenderingSelectedMaterial();
if (material != null) {
JFileChooser chooser = new ImageFileChooser(Tools.FILEEXT_PNG);
if (Prefs.getPrefs().getInputImagePath() != null) {
try {
if (getCurrFlame().getBGImageFilename().length() > 0) {
chooser.setSelectedFile(new File(getCurrFlame().getBGImageFilename()));
} else {
chooser.setCurrentDirectory(new File(Prefs.getPrefs().getInputImagePath()));
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
if (chooser.showOpenDialog(owner.getFlamePanel()) == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
try {
String filename = file.getAbsolutePath();
WFImage img = RessourceManager.getImage(filename);
if (img.getImageWidth() < 2 || img.getImageHeight() < 2 || !(img instanceof SimpleImage)) {
throw new Exception("Invalid image");
}
Prefs.getPrefs().setLastInputImageFile(file);
owner.saveUndoPoint();
material.setReflMapFilename(filename);
refreshReflMapColorIndicator();
owner.refreshFlameImage(true, false, 1, true, false);
} catch (Throwable ex) {
owner.errorHandler.handleError(ex);
}
}
}
}
use of org.jwildfire.image.WFImage in project JWildfire by thargor6.
the class TinaController method selectImageForBackgroundButton_actionPerformed.
public void selectImageForBackgroundButton_actionPerformed(ActionEvent e) {
JFileChooser chooser = new ImageFileChooser(Tools.FILEEXT_PNG);
if (prefs.getInputImagePath() != null) {
try {
if (getCurrFlame().getBGImageFilename().length() > 0) {
chooser.setSelectedFile(new File(getCurrFlame().getBGImageFilename()));
} else {
chooser.setCurrentDirectory(new File(prefs.getInputImagePath()));
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
if (chooser.showOpenDialog(centerPanel) == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
try {
String filename = file.getAbsolutePath();
WFImage img = RessourceManager.getImage(filename);
if (img.getImageWidth() < 2 || img.getImageHeight() < 2 || !(img instanceof SimpleImage)) {
throw new Exception("Invalid background image");
}
prefs.setLastInputImageFile(file);
saveUndoPoint();
getCurrFlame().setBGImageFilename(filename);
refreshFlameImage(true, false, 1, true, true);
} catch (Throwable ex) {
errorHandler.handleError(ex);
}
}
}
use of org.jwildfire.image.WFImage in project JWildfire by thargor6.
the class Bump3DTransformer method transformMesh.
@Override
protected void transformMesh(Mesh3D pMesh3D, int pImageWidth, int pImageHeight) {
int pCount = pMesh3D.getPCount();
int width = pImageWidth;
int height = pImageHeight;
double[] x = pMesh3D.getX();
double[] y = pMesh3D.getY();
double[] z = pMesh3D.getZ();
WFImage heightMap = this.heightMap.getHDRImage();
if (heightMap != null) {
int hwidth = heightMap.getImageWidth();
int hheight = heightMap.getImageHeight();
if ((hwidth != this.hWidth) || (hheight != this.hHeight)) {
throw new IllegalArgumentException("Heightmap has the wrong size (scaling of HDR images currently not supported)");
}
float[] lum = new float[2];
((SimpleHDRImage) heightMap).getMinMaxLum(lum);
lumMin = lum[0];
lumMax = lum[1];
lumRange = lumMax - lumMin;
} else {
heightMap = this.heightMap.getImage();
int hwidth = heightMap.getImageWidth();
int hheight = heightMap.getImageHeight();
if ((hwidth != this.hWidth) || (hheight != this.hHeight)) {
SimpleImage scaledHeightMap = ((SimpleImage) heightMap).clone();
ScaleTransformer scaleT = new ScaleTransformer();
scaleT.setAspect(this.aspect);
scaleT.setUnit(ScaleTransformer.Unit.PIXELS);
scaleT.setScaleWidth(this.hWidth);
scaleT.setScaleHeight(this.hHeight);
scaleT.performImageTransformation(scaledHeightMap);
heightMap = scaledHeightMap;
}
}
double amount = 0.0 - this.amount;
int dx = hLeft - width / 2;
int dy = hTop - height / 2;
if (hCentre) {
dx += (width - this.hWidth) / 2;
dy += (height - this.hHeight) / 2;
}
double[][] weights, intArray;
if (this.smoothingMatrix == SmoothingMatrix.MATRIX_3x3) {
int smoothSize = 3;
weights = weights_3x3;
intArray = new double[smoothSize][smoothSize];
} else {
int smoothSize = 5;
weights = weights_5x5;
intArray = new double[smoothSize][smoothSize];
}
double zmin = 0.0, zmax = 0.0;
for (int i = 0; i < pCount; i++) {
int xx = (int) (x[i] - (double) dx + 0.5);
int yy = (int) (y[i] - (double) dy + 0.5);
if ((xx >= 0) && (xx < this.hWidth) && (yy >= 0) && (yy < this.hHeight)) {
readPixels(heightMap, xx, yy, intArray);
double intensity = getWeightedIntensity(intArray, weights) * amount;
if (intensity < zmin)
zmin = intensity;
else if (intensity > zmax)
zmax = intensity;
z[i] += intensity;
}
}
// Subtract ground
double fam = (zmax - zmin) / 2.0 + zmin;
if ((fam != 0.0) && (noGround)) {
for (int i = 0; i < pCount; i++) {
z[i] -= fam;
}
}
}
use of org.jwildfire.image.WFImage in project JWildfire by thargor6.
the class FlameControlsDelegate method refreshReflMapColorIndicator.
private void refreshReflMapColorIndicator() {
MaterialSettings material = getSolidRenderingSelectedMaterial();
Color color = Color.BLACK;
if (material != null && material.getReflMapFilename() != null && !material.getReflMapFilename().isEmpty()) {
try {
WFImage img = RessourceManager.getImage(material.getReflMapFilename());
if (img instanceof SimpleImage) {
SimpleImage sImg = (SimpleImage) img;
int samples = 6;
int dx = sImg.getImageWidth() / samples;
int dy = sImg.getImageHeight() / samples;
double r = 0.0, g = 0.0, b = 0.0;
for (int x = 0; x < sImg.getImageWidth(); x += dx) {
for (int y = 0; y < sImg.getImageHeight(); y += dy) {
r += sImg.getRValue(x, y);
g += sImg.getGValue(x, y);
b += sImg.getBValue(x, y);
}
}
color = new Color(Tools.roundColor(r / (samples * samples)), Tools.roundColor(g / (samples * samples)), Tools.roundColor(b / (samples * samples)));
} else {
color = Color.RED;
}
} catch (Exception e) {
e.printStackTrace();
}
}
data.tinaSolidRenderingMaterialReflMapBtn.setBackground(color);
}
use of org.jwildfire.image.WFImage in project JWildfire by thargor6.
the class IFlamesController method loadImagesButton_clicked.
public void loadImagesButton_clicked() {
JFileChooser chooser = new ImageFileChooser(Tools.FILEEXT_PNG);
if (prefs.getInputImagePath() != null) {
try {
chooser.setCurrentDirectory(new File(prefs.getInputImagePath()));
} catch (Exception ex) {
ex.printStackTrace();
}
}
chooser.setMultiSelectionEnabled(true);
if (chooser.showOpenDialog(centerPanel) == JFileChooser.APPROVE_OPTION) {
Throwable lastError = null;
for (File file : chooser.getSelectedFiles()) {
try {
String filename = file.getAbsolutePath();
WFImage img = RessourceManager.getImage(filename);
if (img.getImageWidth() < 16 || img.getImageHeight() < 16 || !(img instanceof SimpleImage)) {
throw new Exception("Invalid image");
}
prefs.setLastInputImageFile(file);
addImageToImageLibrary(filename, new ThumbnailCacheKey(filename));
} catch (Throwable ex) {
lastError = ex;
}
}
refreshImageLibrary();
if (lastError != null) {
errorHandler.handleError(lastError);
}
}
}
Aggregations