use of org.jwildfire.io.ImageReader 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);
}
}
}
use of org.jwildfire.io.ImageReader in project JWildfire by thargor6.
the class MeshGenController method importSequence.
private void importSequence(String pFilenamePattern) {
try {
final int firstIndex = 1;
int count = 0;
String lastFilename = null;
for (int i = firstIndex; i < Integer.MAX_VALUE; i++) {
String filename = String.format(pFilenamePattern, i);
if (filename.equals(lastFilename)) {
break;
}
if (new File(filename).exists()) {
count++;
} else {
break;
}
lastFilename = filename;
}
if (count > 0) {
File first = new File(String.format(pFilenamePattern, firstIndex));
SimpleImage img = new ImageReader(rootPanel).loadImage(first.getAbsolutePath());
if (img != null) {
sequenceWidthREd.setValue(img.getImageWidth());
sequenceHeightREd.setValue(img.getImageHeight());
sequenceSlicesREd.setValue(count);
setCurrSequencePattern(pFilenamePattern);
}
enableControls();
} else
throw new Exception("An image sequence has to contain at least one image");
} catch (Exception ex) {
errorHandler.handleError(ex);
}
}
use of org.jwildfire.io.ImageReader in project JWildfire by thargor6.
the class ImgPaletteReader method readPaletteFromMapData.
public List<RGBPalette> readPaletteFromMapData(String pMapData, String pFilename) throws Exception {
List<RGBPalette> res = new ArrayList<RGBPalette>();
RGBPalette gradient = new RGBPalette();
res.add(gradient);
gradient.setFlam3Name(new File(pFilename).getName());
SimpleImage img = new ImageReader().loadImage(pFilename);
if (img.getImageWidth() > 0 && img.getImageHeight() > 0) {
Map<Integer, RGBColor> colors = new HashMap<Integer, RGBColor>();
Pixel rgbPixel = new Pixel();
for (int i = 0; i < img.getImageWidth(); i++) {
rgbPixel.setARGBValue(img.getARGBValue(i, 0));
RGBColor color = new RGBColor(rgbPixel.r, rgbPixel.g, rgbPixel.b);
colors.put(i, color);
}
gradient.setColors(colors, false, false);
}
return res;
}
use of org.jwildfire.io.ImageReader in project JWildfire by thargor6.
the class JWildfire method createMainDesktopPane.
@SuppressWarnings("serial")
private JDesktopPane createMainDesktopPane() {
if (prefs.getDesktopBackgroundImagePath() != null && !prefs.getDesktopBackgroundImagePath().isEmpty()) {
try {
SimpleImage img = new ImageReader(this).loadImage(prefs.getDesktopBackgroundImagePath());
if (prefs.getDesktopBackgroundDarkenAmount() > 0.1) {
double scale = prefs.getDesktopBackgroundDarkenAmount();
{
BalancingTransformer bT = new BalancingTransformer();
bT.setContrast(Tools.limitValue(Tools.FTOI(-160.0 * scale), -200, 200));
bT.setGamma(Tools.limitValue(Tools.FTOI(-180.0 * scale), -200, 200));
bT.transformImage(img);
}
{
BalancingTransformer bT = new BalancingTransformer();
bT.setBrightness(Tools.limitValue(Tools.FTOI(-20.0 * scale), -200, 200));
bT.setContrast(Tools.limitValue(Tools.FTOI(-20.0 * scale), -200, 200));
bT.setGamma(Tools.limitValue(Tools.FTOI(-220.0 * scale), -200, 200));
bT.transformImage(img);
}
backgroundImage = img.getBufferedImg();
}
} catch (Exception ex) {
backgroundImage = null;
ex.printStackTrace();
}
}
if (backgroundImage == null) {
try {
backgroundImage = ImageIO.read(this.getClass().getResource("/org/jwildfire/swing/backgrounds/wallpaper_pearls2.png"));
} catch (Exception ex) {
backgroundImage = null;
ex.printStackTrace();
}
}
if (backgroundImage != null) {
return new JDesktopPane() {
@Override
protected void paintComponent(Graphics grphcs) {
super.paintComponent(grphcs);
grphcs.drawImage(backgroundImage, 0, 0, null);
}
@Override
public Dimension getPreferredSize() {
return new Dimension(backgroundImage.getWidth(), backgroundImage.getHeight());
}
};
} else {
return new JDesktopPane();
}
}
use of org.jwildfire.io.ImageReader in project JWildfire by thargor6.
the class ScriptProcessor method loadImage.
public Buffer loadImage(String pFilename) throws Exception {
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)) {
SimpleHDRImage img = new ImageReader(desktop).loadHDRImage(pFilename);
File file = new File(pFilename);
Buffer buffer = bufferList.addHDRImageBuffer(addBuffersToDesktop ? desktop : null, file.getName(), img);
return buffer;
} else {
SimpleImage img = new ImageReader(desktop).loadImage(pFilename);
File file = new File(pFilename);
Buffer buffer = bufferList.addImageBuffer(addBuffersToDesktop ? desktop : null, file.getName(), img);
return buffer;
}
}
Aggregations