Search in sources :

Example 1 with WFImage

use of org.jwildfire.image.WFImage 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 WFImage

use of org.jwildfire.image.WFImage 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 WFImage

use of org.jwildfire.image.WFImage in project JWildfire by thargor6.

the class FlameParamsList method setRessource.

public boolean setRessource(String pName, byte[] pValue) {
    for (int i = 1; i <= size(); i++) {
        String flameIndexStr = getFlameIndexStr(i);
        if ((RESSOURCE_FLAME + flameIndexStr).equalsIgnoreCase(pName)) {
            String flameXML = pValue != null ? new String(pValue) : "";
            if (flameXML.length() > 0) {
                parseFlame(flameXML);
                get(i - 1).setFlameXML(flameXML);
            } else {
                get(i - 1).setFlameXML(null);
            }
            return true;
        } else if ((RESSOURCE_FLAME_PARAM1 + flameIndexStr).equalsIgnoreCase(pName)) {
            get(i - 1).setFlameParam1(pValue != null ? new String(pValue) : "");
            return true;
        } else if ((RESSOURCE_FLAME_PARAM1_MAP + flameIndexStr).equalsIgnoreCase(pName)) {
            String filename = pValue != null ? new String(pValue) : "";
            SimpleImage map = null;
            if (filename.length() > 0) {
                try {
                    WFImage img = RessourceManager.getImage(filename);
                    if (img.getImageWidth() < 8 || img.getImageHeight() < 8 || !(img instanceof SimpleImage)) {
                        throw new Exception("Invalid param map");
                    }
                    map = (SimpleImage) img;
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
            get(i - 1).setFlameParamMap1Filename(map != null ? filename : null);
            return true;
        } else if ((RESSOURCE_FLAME_PARAM2 + flameIndexStr).equalsIgnoreCase(pName)) {
            get(i - 1).setFlameParam2(pValue != null ? new String(pValue) : "");
            return true;
        } else if ((RESSOURCE_FLAME_PARAM2_MAP + flameIndexStr).equalsIgnoreCase(pName)) {
            String filename = pValue != null ? new String(pValue) : "";
            SimpleImage map = null;
            if (filename.length() > 0) {
                try {
                    WFImage img = RessourceManager.getImage(filename);
                    if (img.getImageWidth() < 8 || img.getImageHeight() < 8 || !(img instanceof SimpleImage)) {
                        throw new Exception("Invalid param map");
                    }
                    map = (SimpleImage) img;
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
            get(i - 1).setFlameParamMap2Filename(map != null ? filename : null);
            return true;
        } else if ((RESSOURCE_FLAME_PARAM3 + flameIndexStr).equalsIgnoreCase(pName)) {
            get(i - 1).setFlameParam3(pValue != null ? new String(pValue) : "");
            return true;
        } else if ((RESSOURCE_FLAME_PARAM3_MAP + flameIndexStr).equalsIgnoreCase(pName)) {
            String filename = pValue != null ? new String(pValue) : "";
            SimpleImage map = null;
            if (filename.length() > 0) {
                try {
                    WFImage img = RessourceManager.getImage(filename);
                    if (img.getImageWidth() < 8 || img.getImageHeight() < 8 || !(img instanceof SimpleImage)) {
                        throw new Exception("Invalid param map");
                    }
                    map = (SimpleImage) img;
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
            get(i - 1).setFlameParamMap3Filename(map != null ? filename : null);
            return true;
        }
    }
    return false;
}
Also used : WFImage(org.jwildfire.image.WFImage) SimpleImage(org.jwildfire.image.SimpleImage)

Example 4 with WFImage

use of org.jwildfire.image.WFImage 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 5 with WFImage

use of org.jwildfire.image.WFImage 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)

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