Search in sources :

Example 26 with SimpleImage

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

the class RasterTools method saveFloatBuffer.

public static void saveFloatBuffer(float[][] buf, String filename) {
    double min, max;
    min = max = buf[0][0];
    for (int i = 0; i < buf.length; i++) {
        for (int j = 0; j < buf[0].length; j++) {
            if (inRange(buf[i][j])) {
                min = max = buf[i][j];
                break;
            }
        }
    }
    for (int i = 0; i < buf.length; i++) {
        for (int j = 0; j < buf[0].length; j++) {
            if (inRange(buf[i][j])) {
                if (buf[i][j] < min)
                    min = buf[i][j];
                else if (buf[i][j] > max && !Double.isInfinite(buf[i][j]))
                    max = buf[i][j];
            }
        }
    }
    double d = max - min;
    System.out.println("Saving float buffer \"" + new File(filename).getName() + "\", min = " + min + ", max = " + max);
    SimpleImage img = new SimpleImage(buf.length, buf[0].length);
    for (int i = 0; i < buf.length; i++) {
        for (int j = 0; j < buf[0].length; j++) {
            int a = Tools.roundColor((buf[i][j] - min) / d * 255.0);
            img.setARGB(i, j, 255, a, a, a);
        }
    }
    try {
        new ImageWriter().saveAsPNG(img, filename);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) ImageWriter(org.jwildfire.io.ImageWriter) File(java.io.File)

Example 27 with SimpleImage

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

the class TextWFFunc method getPoints.

@SuppressWarnings("unchecked")
private List<Point> getPoints() {
    if (_points == null) {
        String key = makeRessourceKey();
        _points = (List<Point>) RessourceManager.getRessource(key);
        if (_points == null) {
            TextTransformer txt = new TextTransformer();
            txt.setText1(text);
            txt.setAntialiasing(false);
            txt.setColor(Color.WHITE);
            txt.setMode(Mode.NORMAL);
            txt.setFontStyle(FontStyle.PLAIN);
            txt.setFontName(font_name);
            txt.setFontSize(font_size);
            txt.setHAlign(HAlignment.CENTRE);
            txt.setVAlign(VAlignment.CENTRE);
            txt.setBaseLineOffset(baseline);
            Dimension dim = txt.calculateTextSize();
            int imgWidth = (int) (dim.getWidth() + 2 * font_size);
            int imgHeight = (int) (dim.getHeight() + 2 * font_size);
            SimpleImage imgMap = new SimpleImage(imgWidth, imgHeight);
            txt.transformImage(imgMap);
            _points = new ArrayList<Point>();
            double w2 = (double) imgMap.getImageWidth() / 2.0;
            double h2 = (double) imgMap.getImageHeight() / 2.0;
            for (int i = 0; i < imgMap.getImageHeight(); i++) {
                for (int j = 0; j < imgMap.getImageWidth(); j++) {
                    int argb = imgMap.getARGBValue(j, i);
                    if (argb != 0) {
                        double x = ((double) j - w2) / (double) imgMap.getImageWidth();
                        double y = ((double) i - h2) / (double) imgMap.getImageHeight();
                        _points.add(new Point(x, y));
                    }
                }
            }
            // System.out.println("IMG: " + imgWidth + "x" + imgHeight + ", POINTS: " + _points.size());
            RessourceManager.putRessource(key, _points);
        }
    }
    return _points;
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) TextTransformer(org.jwildfire.transform.TextTransformer) XYZPoint(org.jwildfire.create.tina.base.XYZPoint) Dimension(java.awt.Dimension) XYZPoint(org.jwildfire.create.tina.base.XYZPoint)

Example 28 with SimpleImage

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

the class ScriptProcessor method executeTransformer.

public TransformResult executeTransformer(String pInputName, boolean pStoreMesh3D, String pOutputName, String pOutput3DName, boolean pRecordAction) {
    Buffer inBuffer = bufferList.bufferByName(pInputName);
    if (inBuffer == null) {
        dumpBuffers();
        throw new RuntimeException("Input buffer <" + pInputName + "> not found");
    }
    SimpleImage newImg = null;
    SimpleHDRImage newHDRImg = null;
    if (inBuffer.getBufferType() == BufferType.IMAGE) {
        transformer.setStoreMesh3D(pStoreMesh3D);
        newImg = inBuffer.getImage().clone();
        transformer.transformImage(newImg);
    } else if (inBuffer.getBufferType() == BufferType.HDR_IMAGE) {
        transformer.setStoreMesh3D(pStoreMesh3D);
        newHDRImg = inBuffer.getHDRImage().clone();
        transformer.transformImage(newHDRImg);
    } else if (inBuffer.getBufferType() == BufferType.MESH3D) {
        transformer.setStoreMesh3D(pStoreMesh3D);
        Mesh3D mesh3D = inBuffer.getMesh3D();
        newImg = new SimpleImage(mesh3D.getImageWidth(), mesh3D.getImageHeight());
        transformer.setInputMesh3D(mesh3D);
        transformer.transformImage(newImg);
    }
    Buffer outBuffer = null;
    if (newImg != null) {
        outBuffer = bufferList.addImageBuffer(addBuffersToDesktop ? desktop : null, transformer.getName(), newImg);
        if ((pOutputName != null) && (pOutputName.length() > 0))
            outBuffer.setName(pOutputName);
    }
    Buffer outHDRBuffer = null;
    if (newHDRImg != null) {
        outHDRBuffer = bufferList.addHDRImageBuffer(addBuffersToDesktop ? desktop : null, transformer.getName(), newHDRImg);
        if ((pOutputName != null) && (pOutputName.length() > 0))
            outHDRBuffer.setName(pOutputName);
    }
    Buffer outBuffer3D = null;
    if (pStoreMesh3D) {
        ScaleTransformer scaleT = new ScaleTransformer();
        scaleT.setAspect(ScaleAspect.KEEP_WIDTH);
        scaleT.setUnit(ScaleTransformer.Unit.PIXELS);
        scaleT.setScaleWidth(120);
        SimpleImage scaledImg = newImg.clone();
        scaleT.transformImage(scaledImg);
        outBuffer3D = bufferList.addMesh3DBuffer(addBuffersToDesktop ? desktop : null, pInputName, transformer.getOutputMesh3D(true), scaledImg);
        if ((pOutput3DName != null) && (pOutput3DName.length() > 0))
            outBuffer3D.setName(pOutput3DName);
    }
    return new TransformResult(inBuffer, outBuffer, outHDRBuffer, outBuffer3D);
}
Also used : SimpleHDRImage(org.jwildfire.image.SimpleHDRImage) Mesh3D(org.jwildfire.transform.Mesh3D) SimpleImage(org.jwildfire.image.SimpleImage) ScaleTransformer(org.jwildfire.transform.ScaleTransformer)

Example 29 with SimpleImage

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

the class WelcomeInternalFrame method getImage.

private SimpleImage getImage(String pName) throws Exception {
    byte[] imgData = getImagedata(pName);
    Image fileImg = Toolkit.getDefaultToolkit().createImage(imgData);
    MediaTracker tracker = new MediaTracker(this);
    tracker.addImage(fileImg, 0);
    tracker.waitForID(0);
    int width = fileImg.getWidth(null);
    int height = fileImg.getHeight(null);
    BufferedImage bImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics g = bImg.getGraphics();
    g.drawImage(fileImg, 0, 0, null);
    fileImg = null;
    return new SimpleImage(bImg, width, height);
}
Also used : Graphics(java.awt.Graphics) MediaTracker(java.awt.MediaTracker) SimpleImage(org.jwildfire.image.SimpleImage) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) SimpleImage(org.jwildfire.image.SimpleImage) BufferedImage(java.awt.image.BufferedImage)

Example 30 with SimpleImage

use of org.jwildfire.image.SimpleImage 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();
    }
}
Also used : ImageIcon(javax.swing.ImageIcon) SimpleHDRImage(org.jwildfire.image.SimpleHDRImage) SimpleImage(org.jwildfire.image.SimpleImage) FastHDRTonemapper(org.jwildfire.image.FastHDRTonemapper) ScaleTransformer(org.jwildfire.transform.ScaleTransformer) ImageReader(org.jwildfire.io.ImageReader)

Aggregations

SimpleImage (org.jwildfire.image.SimpleImage)174 Pixel (org.jwildfire.image.Pixel)37 ImagePanel (org.jwildfire.swing.ImagePanel)24 FlamePanel (org.jwildfire.create.tina.swing.flamepanel.FlamePanel)20 Dimension (java.awt.Dimension)18 Flame (org.jwildfire.create.tina.base.Flame)17 File (java.io.File)16 RenderedFlame (org.jwildfire.create.tina.render.RenderedFlame)16 ArrayList (java.util.ArrayList)14 Rectangle (java.awt.Rectangle)12 FlameRenderer (org.jwildfire.create.tina.render.FlameRenderer)12 RenderInfo (org.jwildfire.create.tina.render.RenderInfo)12 Graphics (java.awt.Graphics)10 SimpleHDRImage (org.jwildfire.image.SimpleHDRImage)10 WFImage (org.jwildfire.image.WFImage)9 ImageReader (org.jwildfire.io.ImageReader)9 JPanel (javax.swing.JPanel)8 JScrollPane (javax.swing.JScrollPane)8 ResolutionProfile (org.jwildfire.base.ResolutionProfile)8 Color (java.awt.Color)7