Search in sources :

Example 11 with ImageReader

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

the class ImageSequenceLoader method loadImage.

@Override
protected SimpleImage loadImage() {
    String fn = new File(this.filename).getName();
    String ext;
    int p = fn.lastIndexOf(".");
    if ((p > 0) && (p < fn.length() - 1)) {
        ext = fn.substring(p, fn.length());
        fn = fn.substring(0, p);
    } else {
        ext = "";
    }
    String baseFn = fn;
    String numberPart = "";
    for (int i = fn.length() - 1; i >= 0; i--) {
        char c = fn.charAt(i);
        if (!((c >= '0') && (c <= '9'))) {
            baseFn = fn.substring(0, i + 1);
            if (i < fn.length() - 1)
                numberPart = fn.substring(i + 1, fn.length());
            break;
        } else if (i == 0) {
            numberPart = fn;
            baseFn = "";
        }
    }
    System.out.println("BASE: " + baseFn);
    System.out.println("NUMBER: " + numberPart);
    System.out.println("EXT: " + ext);
    // generate current filename
    fn = String.valueOf(this.frame);
    while (fn.length() < numberPart.length()) fn = "0" + fn;
    fn = new File(this.filename).getParent() + File.separator + baseFn + fn + ext;
    System.out.println(this.frame + ": " + fn);
    try {
        return new ImageReader(getDesktop()).loadImage(fn);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
Also used : ImageReader(org.jwildfire.io.ImageReader) File(java.io.File)

Example 12 with ImageReader

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

the class ImageStackSampler method getIntensityInternal.

private int getIntensityInternal(int pX, int pY, int pZ) {
    if (pX < 0 || pX >= stackXSize || pY < 0 || pY >= stackYSize || pZ < 0 || pZ >= stackZSize)
        return 0;
    SimpleImage img = images.get(pZ);
    if (img == null) {
        String filename = String.format(inputfilename, imagesIndex.get(pZ));
        try {
            SimpleImage loadedImage = new ImageReader().loadImage(filename);
            for (PreFilter filter : preFilterList) {
                filter.apply(loadedImage);
            }
            if (downsample > 1) {
                double square = downsample * downsample;
                img = new SimpleImage(loadedImage.getImageWidth() / downsample, loadedImage.getImageHeight() / downsample);
                for (int i = 0; i < img.getImageHeight(); i++) {
                    for (int j = 0; j < img.getImageWidth(); j++) {
                        long sum = 0;
                        for (int ii = 0; ii < downsample; ii++) {
                            for (int jj = 0; jj < downsample; jj++) {
                                sum += loadedImage.getRValue(j * downsample + jj, i * downsample + ii);
                            }
                        }
                        int value = (int) (sum / square + 0.5);
                        img.setRGB(j, i, value, value, value);
                    }
                }
            } else {
                img = loadedImage;
            }
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
        images.set(pZ, img);
        int imgCount = 1;
        for (int i = pZ - 1; i >= 0; i--) {
            if (images.get(i) != null) {
                imgCount++;
                if (imgCount >= MAX_IMAGES_IN_CACHE) {
                    images.set(i, null);
                    imgCount--;
                }
            } else {
                break;
            }
        }
    }
    return img.getRValue(pX, pY);
}
Also used : PreFilter(org.jwildfire.create.tina.meshgen.filter.PreFilter) SimpleImage(org.jwildfire.image.SimpleImage) 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