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