Search in sources :

Example 1 with MedianCutQuantizer

use of org.jwildfire.create.tina.palette.MedianCutQuantizer in project JWildfire by thargor6.

the class WikimediaCommonsRandomFlameGenerator method obtainImage.

protected ImageData obtainImage() {
    try {
        String url = "http://commons.wikimedia.org/wiki/Special:Random/File";
        int minSize = 16;
        int maxSize = 16000;
        byte[] htmlData = downloadRessource(url);
        String html = new String(htmlData);
        String imgUrl = getImgUrl(html);
        String pageUrl = getPageUrl(html);
        if (imgUrl != null && pageUrl != null && isValidImgUrl(imgUrl)) {
            byte[] imgData = downloadRessource(imgUrl);
            String fileExt = RessourceManager.guessImageExtension(imgData);
            File f = File.createTempFile("tmp", "." + fileExt);
            f.deleteOnExit();
            Tools.writeFile(f.getAbsolutePath(), imgData);
            WFImage img = new ImageReader(new JLabel()).loadImage(f.getAbsolutePath());
            if (img.getImageWidth() >= minSize && img.getImageWidth() <= maxSize && img.getImageHeight() >= minSize && img.getImageHeight() <= maxSize) {
                int hashcode = RessourceManager.calcHashCode(imgData);
                SimpleImage wfImg = (SimpleImage) RessourceManager.getImage(hashcode, imgData);
                RGBPalette gradient = new MedianCutQuantizer().createPalette(wfImg);
                return new ImageData(pageUrl, imgUrl, imgData, gradient);
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return null;
}
Also used : WFImage(org.jwildfire.image.WFImage) RGBPalette(org.jwildfire.create.tina.palette.RGBPalette) SimpleImage(org.jwildfire.image.SimpleImage) JLabel(javax.swing.JLabel) ImageReader(org.jwildfire.io.ImageReader) File(java.io.File) MedianCutQuantizer(org.jwildfire.create.tina.palette.MedianCutQuantizer)

Example 2 with MedianCutQuantizer

use of org.jwildfire.create.tina.palette.MedianCutQuantizer in project JWildfire by thargor6.

the class ColorMapRandomFlameGenerator method obtainImage.

@Override
protected ImageData obtainImage() {
    try {
        int minSize = 16;
        int maxSize = 16000;
        File file = getRandomFile();
        if (file != null) {
            byte[] imgData = Tools.readFile(file.getAbsolutePath());
            WFImage img = new ImageReader(new JLabel()).loadImage(file.getAbsolutePath());
            if (img.getImageWidth() >= minSize && img.getImageWidth() <= maxSize && img.getImageHeight() >= minSize && img.getImageHeight() <= maxSize) {
                int hashcode = RessourceManager.calcHashCode(imgData);
                SimpleImage wfImg = (SimpleImage) RessourceManager.getImage(hashcode, imgData);
                RGBPalette gradient = new MedianCutQuantizer().createPalette(wfImg);
                return new ImageData(null, file.getName(), imgData, gradient);
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return null;
}
Also used : WFImage(org.jwildfire.image.WFImage) RGBPalette(org.jwildfire.create.tina.palette.RGBPalette) SimpleImage(org.jwildfire.image.SimpleImage) JLabel(javax.swing.JLabel) ImageReader(org.jwildfire.io.ImageReader) File(java.io.File) MedianCutQuantizer(org.jwildfire.create.tina.palette.MedianCutQuantizer)

Example 3 with MedianCutQuantizer

use of org.jwildfire.create.tina.palette.MedianCutQuantizer 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)

Aggregations

File (java.io.File)3 MedianCutQuantizer (org.jwildfire.create.tina.palette.MedianCutQuantizer)3 RGBPalette (org.jwildfire.create.tina.palette.RGBPalette)3 SimpleImage (org.jwildfire.image.SimpleImage)3 ImageReader (org.jwildfire.io.ImageReader)3 JLabel (javax.swing.JLabel)2 WFImage (org.jwildfire.image.WFImage)2 JFileChooser (javax.swing.JFileChooser)1 ImageFileChooser (org.jwildfire.swing.ImageFileChooser)1