Search in sources :

Example 6 with ImageReader

use of org.jwildfire.io.ImageReader in project JWildfire by thargor6.

the class TinaController method grabPaletteFromImageButton_actionPerformed.

public void grabPaletteFromImageButton_actionPerformed(ActionEvent e) {
    JFileChooser chooser = new ImageFileChooser(Tools.FILEEXT_PNG);
    if (prefs.getInputImagePath() != null) {
        try {
            chooser.setCurrentDirectory(new File(prefs.getInputImagePath()));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    if (chooser.showOpenDialog(centerPanel) == JFileChooser.APPROVE_OPTION) {
        File file = chooser.getSelectedFile();
        try {
            SimpleImage img = new ImageReader(centerPanel).loadImage(file.getAbsolutePath());
            prefs.setLastInputImageFile(file);
            RGBPalette palette = new MedianCutQuantizer().createPalette(img);
            data.paletteKeyFrames = null;
            saveUndoPoint();
            getCurrLayer().setPalette(palette);
            setLastGradient(palette);
            refreshPaletteColorsTable();
            refreshPaletteUI(palette);
            refreshFlameImage(true, false, 1, true, false);
        } catch (Throwable ex) {
            errorHandler.handleError(ex);
        }
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) RGBPalette(org.jwildfire.create.tina.palette.RGBPalette) ImageFileChooser(org.jwildfire.swing.ImageFileChooser) SimpleImage(org.jwildfire.image.SimpleImage) ImageReader(org.jwildfire.io.ImageReader) File(java.io.File) MedianCutQuantizer(org.jwildfire.create.tina.palette.MedianCutQuantizer)

Example 7 with ImageReader

use of org.jwildfire.io.ImageReader in project JWildfire by thargor6.

the class MeshGenController method importSequence.

private void importSequence(String pFilenamePattern) {
    try {
        final int firstIndex = 1;
        int count = 0;
        String lastFilename = null;
        for (int i = firstIndex; i < Integer.MAX_VALUE; i++) {
            String filename = String.format(pFilenamePattern, i);
            if (filename.equals(lastFilename)) {
                break;
            }
            if (new File(filename).exists()) {
                count++;
            } else {
                break;
            }
            lastFilename = filename;
        }
        if (count > 0) {
            File first = new File(String.format(pFilenamePattern, firstIndex));
            SimpleImage img = new ImageReader(rootPanel).loadImage(first.getAbsolutePath());
            if (img != null) {
                sequenceWidthREd.setValue(img.getImageWidth());
                sequenceHeightREd.setValue(img.getImageHeight());
                sequenceSlicesREd.setValue(count);
                setCurrSequencePattern(pFilenamePattern);
            }
            enableControls();
        } else
            throw new Exception("An image sequence has to contain at least one image");
    } catch (Exception ex) {
        errorHandler.handleError(ex);
    }
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) ImageReader(org.jwildfire.io.ImageReader) File(java.io.File)

Example 8 with ImageReader

use of org.jwildfire.io.ImageReader in project JWildfire by thargor6.

the class ImgPaletteReader method readPaletteFromMapData.

public List<RGBPalette> readPaletteFromMapData(String pMapData, String pFilename) throws Exception {
    List<RGBPalette> res = new ArrayList<RGBPalette>();
    RGBPalette gradient = new RGBPalette();
    res.add(gradient);
    gradient.setFlam3Name(new File(pFilename).getName());
    SimpleImage img = new ImageReader().loadImage(pFilename);
    if (img.getImageWidth() > 0 && img.getImageHeight() > 0) {
        Map<Integer, RGBColor> colors = new HashMap<Integer, RGBColor>();
        Pixel rgbPixel = new Pixel();
        for (int i = 0; i < img.getImageWidth(); i++) {
            rgbPixel.setARGBValue(img.getARGBValue(i, 0));
            RGBColor color = new RGBColor(rgbPixel.r, rgbPixel.g, rgbPixel.b);
            colors.put(i, color);
        }
        gradient.setColors(colors, false, false);
    }
    return res;
}
Also used : HashMap(java.util.HashMap) RGBPalette(org.jwildfire.create.tina.palette.RGBPalette) SimpleImage(org.jwildfire.image.SimpleImage) ArrayList(java.util.ArrayList) RGBColor(org.jwildfire.create.tina.palette.RGBColor) ImageReader(org.jwildfire.io.ImageReader) File(java.io.File) Pixel(org.jwildfire.image.Pixel)

Example 9 with ImageReader

use of org.jwildfire.io.ImageReader in project JWildfire by thargor6.

the class JWildfire method createMainDesktopPane.

@SuppressWarnings("serial")
private JDesktopPane createMainDesktopPane() {
    if (prefs.getDesktopBackgroundImagePath() != null && !prefs.getDesktopBackgroundImagePath().isEmpty()) {
        try {
            SimpleImage img = new ImageReader(this).loadImage(prefs.getDesktopBackgroundImagePath());
            if (prefs.getDesktopBackgroundDarkenAmount() > 0.1) {
                double scale = prefs.getDesktopBackgroundDarkenAmount();
                {
                    BalancingTransformer bT = new BalancingTransformer();
                    bT.setContrast(Tools.limitValue(Tools.FTOI(-160.0 * scale), -200, 200));
                    bT.setGamma(Tools.limitValue(Tools.FTOI(-180.0 * scale), -200, 200));
                    bT.transformImage(img);
                }
                {
                    BalancingTransformer bT = new BalancingTransformer();
                    bT.setBrightness(Tools.limitValue(Tools.FTOI(-20.0 * scale), -200, 200));
                    bT.setContrast(Tools.limitValue(Tools.FTOI(-20.0 * scale), -200, 200));
                    bT.setGamma(Tools.limitValue(Tools.FTOI(-220.0 * scale), -200, 200));
                    bT.transformImage(img);
                }
                backgroundImage = img.getBufferedImg();
            }
        } catch (Exception ex) {
            backgroundImage = null;
            ex.printStackTrace();
        }
    }
    if (backgroundImage == null) {
        try {
            backgroundImage = ImageIO.read(this.getClass().getResource("/org/jwildfire/swing/backgrounds/wallpaper_pearls2.png"));
        } catch (Exception ex) {
            backgroundImage = null;
            ex.printStackTrace();
        }
    }
    if (backgroundImage != null) {
        return new JDesktopPane() {

            @Override
            protected void paintComponent(Graphics grphcs) {
                super.paintComponent(grphcs);
                grphcs.drawImage(backgroundImage, 0, 0, null);
            }

            @Override
            public Dimension getPreferredSize() {
                return new Dimension(backgroundImage.getWidth(), backgroundImage.getHeight());
            }
        };
    } else {
        return new JDesktopPane();
    }
}
Also used : Graphics(java.awt.Graphics) BalancingTransformer(org.jwildfire.transform.BalancingTransformer) JDesktopPane(javax.swing.JDesktopPane) SimpleImage(org.jwildfire.image.SimpleImage) Dimension(java.awt.Dimension) ImageReader(org.jwildfire.io.ImageReader) PropertyVetoException(java.beans.PropertyVetoException)

Example 10 with ImageReader

use of org.jwildfire.io.ImageReader in project JWildfire by thargor6.

the class ScriptProcessor method loadImage.

public Buffer loadImage(String pFilename) throws Exception {
    if (!new File(pFilename).exists())
        throw new FileNotFoundException(pFilename);
    String fileExt = null;
    {
        int p = pFilename.lastIndexOf(".");
        if (p >= 0 && p < pFilename.length() - 2) {
            fileExt = pFilename.substring(p + 1, pFilename.length());
        }
    }
    if ("hdr".equalsIgnoreCase(fileExt)) {
        SimpleHDRImage img = new ImageReader(desktop).loadHDRImage(pFilename);
        File file = new File(pFilename);
        Buffer buffer = bufferList.addHDRImageBuffer(addBuffersToDesktop ? desktop : null, file.getName(), img);
        return buffer;
    } else {
        SimpleImage img = new ImageReader(desktop).loadImage(pFilename);
        File file = new File(pFilename);
        Buffer buffer = bufferList.addImageBuffer(addBuffersToDesktop ? desktop : null, file.getName(), img);
        return buffer;
    }
}
Also used : SimpleHDRImage(org.jwildfire.image.SimpleHDRImage) SimpleImage(org.jwildfire.image.SimpleImage) FileNotFoundException(java.io.FileNotFoundException) ImageReader(org.jwildfire.io.ImageReader) File(java.io.File)

Aggregations

ImageReader (org.jwildfire.io.ImageReader)12 File (java.io.File)9 SimpleImage (org.jwildfire.image.SimpleImage)9 JLabel (javax.swing.JLabel)4 RGBPalette (org.jwildfire.create.tina.palette.RGBPalette)4 WFImage (org.jwildfire.image.WFImage)4 MedianCutQuantizer (org.jwildfire.create.tina.palette.MedianCutQuantizer)3 FileNotFoundException (java.io.FileNotFoundException)2 SimpleHDRImage (org.jwildfire.image.SimpleHDRImage)2 Dimension (java.awt.Dimension)1 Graphics (java.awt.Graphics)1 PropertyVetoException (java.beans.PropertyVetoException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ImageIcon (javax.swing.ImageIcon)1 JDesktopPane (javax.swing.JDesktopPane)1 JFileChooser (javax.swing.JFileChooser)1 PreFilter (org.jwildfire.create.tina.meshgen.filter.PreFilter)1 RGBColor (org.jwildfire.create.tina.palette.RGBColor)1 FastHDRTonemapper (org.jwildfire.image.FastHDRTonemapper)1