Search in sources :

Example 1 with ImageReader

use of org.jwildfire.io.ImageReader 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 ImageReader

use of org.jwildfire.io.ImageReader 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 ImageReader

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

the class RessourceManager method getImage.

public static WFImage getImage(int pHashCode, byte[] pImageData) throws Exception {
    Integer key = Integer.valueOf(pHashCode);
    WFImage res = imageMapByHash.get(key);
    if (res == null) {
        String fileExt = guessImageExtension(pImageData);
        File f = File.createTempFile("tmp", "." + fileExt);
        f.deleteOnExit();
        Tools.writeFile(f.getAbsolutePath(), pImageData);
        if ("hdr".equalsIgnoreCase(fileExt)) {
            res = new ImageReader(new JLabel()).loadHDRImage(f.getAbsolutePath());
        } else {
            res = new ImageReader(new JLabel()).loadImage(f.getAbsolutePath());
        }
        imageMapByHash.put(key, res);
    }
    return res;
}
Also used : WFImage(org.jwildfire.image.WFImage) JLabel(javax.swing.JLabel) ImageReader(org.jwildfire.io.ImageReader) File(java.io.File)

Example 4 with ImageReader

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

the class RessourceManager method getImage.

public static WFImage getImage(String pFilename) throws Exception {
    if (pFilename == null || pFilename.length() == 0) {
        throw new IllegalStateException();
    }
    WFImage res = imageMapByName.get(pFilename);
    if (res == null) {
        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)) {
            res = new ImageReader(new JLabel()).loadHDRImage(pFilename);
        } else {
            res = new ImageReader(new JLabel()).loadImage(pFilename);
        }
        imageMapByName.put(pFilename, res);
    }
    return res;
}
Also used : WFImage(org.jwildfire.image.WFImage) FileNotFoundException(java.io.FileNotFoundException) JLabel(javax.swing.JLabel) ImageReader(org.jwildfire.io.ImageReader) File(java.io.File)

Example 5 with ImageReader

use of org.jwildfire.io.ImageReader 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();
    }
}
Also used : ImageIcon(javax.swing.ImageIcon) SimpleHDRImage(org.jwildfire.image.SimpleHDRImage) SimpleImage(org.jwildfire.image.SimpleImage) FastHDRTonemapper(org.jwildfire.image.FastHDRTonemapper) ScaleTransformer(org.jwildfire.transform.ScaleTransformer) ImageReader(org.jwildfire.io.ImageReader)

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