Search in sources :

Example 6 with WFImage

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);
            }
        }
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) WFImage(org.jwildfire.image.WFImage) MaterialSettings(org.jwildfire.create.tina.base.solidrender.MaterialSettings) ImageFileChooser(org.jwildfire.swing.ImageFileChooser) SimpleImage(org.jwildfire.image.SimpleImage) File(java.io.File)

Example 7 with WFImage

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);
        }
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) WFImage(org.jwildfire.image.WFImage) ImageFileChooser(org.jwildfire.swing.ImageFileChooser) SimpleImage(org.jwildfire.image.SimpleImage) File(java.io.File)

Example 8 with WFImage

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;
        }
    }
}
Also used : SimpleHDRImage(org.jwildfire.image.SimpleHDRImage) WFImage(org.jwildfire.image.WFImage) SimpleImage(org.jwildfire.image.SimpleImage)

Example 9 with WFImage

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);
}
Also used : WFImage(org.jwildfire.image.WFImage) MaterialSettings(org.jwildfire.create.tina.base.solidrender.MaterialSettings) Color(java.awt.Color) RGBColor(org.jwildfire.create.tina.palette.RGBColor) Stereo3dColor(org.jwildfire.create.tina.base.Stereo3dColor) SimpleImage(org.jwildfire.image.SimpleImage)

Example 10 with WFImage

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);
        }
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) WFImage(org.jwildfire.image.WFImage) ThumbnailCacheKey(org.jwildfire.create.tina.swing.ThumbnailCacheKey) ImageFileChooser(org.jwildfire.swing.ImageFileChooser) SimpleImage(org.jwildfire.image.SimpleImage) File(java.io.File)

Aggregations

WFImage (org.jwildfire.image.WFImage)11 SimpleImage (org.jwildfire.image.SimpleImage)9 File (java.io.File)8 JFileChooser (javax.swing.JFileChooser)4 JLabel (javax.swing.JLabel)4 ImageReader (org.jwildfire.io.ImageReader)4 ImageFileChooser (org.jwildfire.swing.ImageFileChooser)4 MaterialSettings (org.jwildfire.create.tina.base.solidrender.MaterialSettings)2 MedianCutQuantizer (org.jwildfire.create.tina.palette.MedianCutQuantizer)2 RGBPalette (org.jwildfire.create.tina.palette.RGBPalette)2 Color (java.awt.Color)1 FileNotFoundException (java.io.FileNotFoundException)1 Stereo3dColor (org.jwildfire.create.tina.base.Stereo3dColor)1 RGBColor (org.jwildfire.create.tina.palette.RGBColor)1 ThumbnailCacheKey (org.jwildfire.create.tina.swing.ThumbnailCacheKey)1 SimpleHDRImage (org.jwildfire.image.SimpleHDRImage)1