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;
}
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;
}
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;
}
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;
}
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();
}
}
Aggregations