Search in sources :

Example 6 with SimpleImage

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

the class BaseFlameListCreator method createParamMapList.

private List<SimpleImage> createParamMapList(SimpleImage structureMap, int pIndex) {
    List<SimpleImage> res = new ArrayList<SimpleImage>();
    for (FlameParams flameParam : flameParams) {
        SimpleImage paramMap = null;
        try {
            String flameParamname;
            String flameParamMapFilename;
            switch(pIndex) {
                case 0:
                    flameParamname = flameParam.getFlameParam1();
                    flameParamMapFilename = flameParam.getFlameParamMap1Filename();
                    break;
                case 1:
                    flameParamname = flameParam.getFlameParam2();
                    flameParamMapFilename = flameParam.getFlameParamMap2Filename();
                    break;
                case 2:
                    flameParamname = flameParam.getFlameParam3();
                    flameParamMapFilename = flameParam.getFlameParamMap3Filename();
                    break;
                default:
                    throw new IllegalArgumentException();
            }
            if (flameParamname != null && flameParamname.length() > 0 && flameParamMapFilename != null && flameParamMapFilename.length() > 0) {
                SimpleImage map = (SimpleImage) RessourceManager.getImage(flameParamMapFilename);
                if ((map.getImageWidth() != structureMap.getImageWidth()) || (map.getImageHeight() != structureMap.getImageHeight())) {
                    map = map.clone();
                    ScaleTransformer scaleT = new ScaleTransformer();
                    scaleT.setScaleWidth(structureMap.getImageWidth());
                    scaleT.setScaleHeight(structureMap.getImageHeight());
                    scaleT.setAspect(ScaleAspect.IGNORE);
                    scaleT.transformImage(map);
                    paramMap = map;
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        res.add(paramMap);
    }
    return res;
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) ArrayList(java.util.ArrayList) ScaleTransformer(org.jwildfire.transform.ScaleTransformer)

Example 7 with SimpleImage

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

the class BaseFlameListCreator method preprocessImage.

private void preprocessImage(SimpleImage tImage) {
    if (imageParams.getErode() == 1) {
        long t0 = System.currentTimeMillis();
        ErodeTransformer eT = new ErodeTransformer();
        eT.initDefaultParams(tImage);
        eT.setMode(ErodeTransformer.Mode.DILATE);
        eT.setSize(imageParams.getErodeSize());
        eT.setShape(ErodeTransformer.Shape.DISK);
        eT.transformImage(tImage);
        long t1 = System.currentTimeMillis();
        statistics.getAction(ActionType.ERODE).setDuration(t1 - t0);
        currProgress += updatePreprocessStep;
        progressUpdater.updateProgress(currProgress);
    }
    List<SimpleImage> convImages = new ArrayList<SimpleImage>();
    if (imageParams.getConv_north() == 1) {
        long t0 = System.currentTimeMillis();
        SimpleImage north = tImage.clone();
        ConvolveTransformer transformer = new ConvolveTransformer();
        transformer.initDefaultParams(north);
        transformer.setKernelType(KernelType.SOBEL_3X3);
        transformer.setKernelDirection(KernelDirection.NORTH);
        transformer.setColorMode(ColorMode.GREY);
        transformer.transformImage(north);
        convImages.add(north);
        long t1 = System.currentTimeMillis();
        statistics.getAction(ActionType.CONV_NORTH).setDuration(t1 - t0);
        currProgress += updatePreprocessStep;
        progressUpdater.updateProgress(currProgress);
    }
    if (imageParams.getConv_east() == 1) {
        long t0 = System.currentTimeMillis();
        SimpleImage east = tImage.clone();
        ConvolveTransformer transformer = new ConvolveTransformer();
        transformer.initDefaultParams(east);
        transformer.setKernelType(KernelType.SOBEL_3X3);
        transformer.setKernelDirection(KernelDirection.EAST);
        transformer.setColorMode(ColorMode.GREY);
        transformer.transformImage(east);
        convImages.add(east);
        long t1 = System.currentTimeMillis();
        statistics.getAction(ActionType.CONV_EAST).setDuration(t1 - t0);
        currProgress += updatePreprocessStep;
        progressUpdater.updateProgress(currProgress);
    }
    if (imageParams.getConv_south() == 1) {
        long t0 = System.currentTimeMillis();
        SimpleImage south = tImage.clone();
        ConvolveTransformer transformer = new ConvolveTransformer();
        transformer.initDefaultParams(south);
        transformer.setKernelType(KernelType.SOBEL_3X3);
        transformer.setKernelDirection(KernelDirection.SOUTH);
        transformer.setColorMode(ColorMode.GREY);
        transformer.transformImage(south);
        convImages.add(south);
        long t1 = System.currentTimeMillis();
        statistics.getAction(ActionType.CONV_SOUTH).setDuration(t1 - t0);
        currProgress += updatePreprocessStep;
        progressUpdater.updateProgress(currProgress);
    }
    if (imageParams.getConv_west() == 1) {
        long t0 = System.currentTimeMillis();
        SimpleImage west = tImage.clone();
        ConvolveTransformer transformer = new ConvolveTransformer();
        transformer.initDefaultParams(west);
        transformer.setKernelType(KernelType.SOBEL_3X3);
        transformer.setKernelDirection(KernelDirection.WEST);
        transformer.setColorMode(ColorMode.GREY);
        transformer.transformImage(west);
        convImages.add(west);
        long t1 = System.currentTimeMillis();
        statistics.getAction(ActionType.CONV_WEST).setDuration(t1 - t0);
        currProgress += updatePreprocessStep;
        progressUpdater.updateProgress(currProgress);
    }
    if (convImages.size() == 1) {
        SimpleImage convImage = convImages.get(0);
        tImage.setBufferedImage(convImage.getBufferedImg(), convImage.getImageWidth(), convImage.getImageHeight());
    } else if (convImages.size() > 1) {
        long t0 = System.currentTimeMillis();
        for (int i = 0; i < tImage.getImageHeight(); i++) {
            for (int j = 0; j < tImage.getImageWidth(); j++) {
                int r = 0, g = 0, b = 0;
                for (SimpleImage convImage : convImages) {
                    r += convImage.getRValue(j, i);
                    g += convImage.getGValue(j, i);
                    b += convImage.getBValue(j, i);
                }
                r = Tools.roundColor((double) r / (double) convImages.size());
                g = Tools.roundColor((double) g / (double) convImages.size());
                b = Tools.roundColor((double) b / (double) convImages.size());
                tImage.setRGB(j, i, r, g, b);
            }
        }
        long t1 = System.currentTimeMillis();
        statistics.getAction(ActionType.CONV_MERGE).setDuration(t1 - t0);
        currProgress += updatePreprocessStep;
        progressUpdater.updateProgress(currProgress);
    }
}
Also used : ConvolveTransformer(org.jwildfire.transform.ConvolveTransformer) ErodeTransformer(org.jwildfire.transform.ErodeTransformer) SimpleImage(org.jwildfire.image.SimpleImage) ArrayList(java.util.ArrayList)

Example 8 with SimpleImage

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

the class FlameParamsList method setRessource.

public boolean setRessource(String pName, byte[] pValue) {
    for (int i = 1; i <= size(); i++) {
        String flameIndexStr = getFlameIndexStr(i);
        if ((RESSOURCE_FLAME + flameIndexStr).equalsIgnoreCase(pName)) {
            String flameXML = pValue != null ? new String(pValue) : "";
            if (flameXML.length() > 0) {
                parseFlame(flameXML);
                get(i - 1).setFlameXML(flameXML);
            } else {
                get(i - 1).setFlameXML(null);
            }
            return true;
        } else if ((RESSOURCE_FLAME_PARAM1 + flameIndexStr).equalsIgnoreCase(pName)) {
            get(i - 1).setFlameParam1(pValue != null ? new String(pValue) : "");
            return true;
        } else if ((RESSOURCE_FLAME_PARAM1_MAP + flameIndexStr).equalsIgnoreCase(pName)) {
            String filename = pValue != null ? new String(pValue) : "";
            SimpleImage map = null;
            if (filename.length() > 0) {
                try {
                    WFImage img = RessourceManager.getImage(filename);
                    if (img.getImageWidth() < 8 || img.getImageHeight() < 8 || !(img instanceof SimpleImage)) {
                        throw new Exception("Invalid param map");
                    }
                    map = (SimpleImage) img;
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
            get(i - 1).setFlameParamMap1Filename(map != null ? filename : null);
            return true;
        } else if ((RESSOURCE_FLAME_PARAM2 + flameIndexStr).equalsIgnoreCase(pName)) {
            get(i - 1).setFlameParam2(pValue != null ? new String(pValue) : "");
            return true;
        } else if ((RESSOURCE_FLAME_PARAM2_MAP + flameIndexStr).equalsIgnoreCase(pName)) {
            String filename = pValue != null ? new String(pValue) : "";
            SimpleImage map = null;
            if (filename.length() > 0) {
                try {
                    WFImage img = RessourceManager.getImage(filename);
                    if (img.getImageWidth() < 8 || img.getImageHeight() < 8 || !(img instanceof SimpleImage)) {
                        throw new Exception("Invalid param map");
                    }
                    map = (SimpleImage) img;
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
            get(i - 1).setFlameParamMap2Filename(map != null ? filename : null);
            return true;
        } else if ((RESSOURCE_FLAME_PARAM3 + flameIndexStr).equalsIgnoreCase(pName)) {
            get(i - 1).setFlameParam3(pValue != null ? new String(pValue) : "");
            return true;
        } else if ((RESSOURCE_FLAME_PARAM3_MAP + flameIndexStr).equalsIgnoreCase(pName)) {
            String filename = pValue != null ? new String(pValue) : "";
            SimpleImage map = null;
            if (filename.length() > 0) {
                try {
                    WFImage img = RessourceManager.getImage(filename);
                    if (img.getImageWidth() < 8 || img.getImageHeight() < 8 || !(img instanceof SimpleImage)) {
                        throw new Exception("Invalid param map");
                    }
                    map = (SimpleImage) img;
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
            get(i - 1).setFlameParamMap3Filename(map != null ? filename : null);
            return true;
        }
    }
    return false;
}
Also used : WFImage(org.jwildfire.image.WFImage) SimpleImage(org.jwildfire.image.SimpleImage)

Example 9 with SimpleImage

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

the class FlameRenderer method postFilterImage.

private void postFilterImage(SimpleImage pImage) {
    if (pImage != null) {
        int threadCount = prefs.getTinaRenderThreads();
        if (threadCount < 1 || pImage.getImageHeight() < 8 * threadCount) {
            threadCount = 1;
        }
        int rowsPerThread = pImage.getImageHeight() / threadCount;
        SimpleImage input = pImage.clone();
        List<PostFilterImageThread> threads = new ArrayList<PostFilterImageThread>();
        for (int i = 0; i < threadCount; i++) {
            int startRow = i * rowsPerThread;
            int endRow = i < threadCount - 1 ? startRow + rowsPerThread : pImage.getImageHeight();
            PostFilterImageThread thread = new PostFilterImageThread(startRow, endRow, input, pImage, flame.getPostNoiseFilterThreshold());
            threads.add(thread);
            if (threadCount > 1) {
                new Thread(thread).start();
            } else {
                thread.run();
            }
        }
        ThreadTools.waitForThreads(threadCount, threads);
    }
}
Also used : PostFilterImageThread(org.jwildfire.create.tina.render.image.PostFilterImageThread) SimpleImage(org.jwildfire.image.SimpleImage) ArrayList(java.util.ArrayList) PCPoint(org.jwildfire.create.tina.base.raster.RasterPointCloud.PCPoint) RenderImageThread(org.jwildfire.create.tina.render.image.RenderImageThread) RenderHDRImageThread(org.jwildfire.create.tina.render.image.RenderHDRImageThread) RenderImageSimpleScaledThread(org.jwildfire.create.tina.render.image.RenderImageSimpleScaledThread) RenderImageSimpleThread(org.jwildfire.create.tina.render.image.RenderImageSimpleThread) PostFilterImageThread(org.jwildfire.create.tina.render.image.PostFilterImageThread) RenderZBufferThread(org.jwildfire.create.tina.render.image.RenderZBufferThread)

Example 10 with SimpleImage

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

the class FlameRenderer method renderStereo3dAnaglyph.

private RenderedFlame renderStereo3dAnaglyph(RenderInfo pRenderInfo) {
    RenderInfo localRenderInfo = pRenderInfo.makeCopy();
    localRenderInfo.setRenderHDR(false);
    localRenderInfo.setRenderZBuffer(false);
    eye = Stereo3dEye.LEFT;
    RenderedFlame leftRender = renderImageNormal(localRenderInfo, 2, 0);
    eye = Stereo3dEye.RIGHT;
    RenderedFlame rightRender = renderImageNormal(localRenderInfo, 2, 1);
    if (flame.isStereo3dSwapSides()) {
        RenderedFlame tmp = leftRender;
        leftRender = rightRender;
        rightRender = tmp;
    }
    Pixel lPixel = new Pixel();
    Pixel rPixel = new Pixel();
    Stereo3dColor leftColor = flame.getAnaglyph3dLeftEyeColor();
    Stereo3dColor rightColor = flame.getAnaglyph3dRightEyeColor();
    SimpleImage leftImg = leftRender.getImage();
    SimpleImage rightImg = rightRender.getImage();
    RenderedFlame mergedRender = new RenderedFlame();
    localRenderInfo.setImageWidth(leftRender.getImage().getImageWidth());
    localRenderInfo.setImageHeight(leftRender.getImage().getImageHeight());
    mergedRender.init(localRenderInfo, flame);
    SimpleImage mergedImg = mergedRender.getImage();
    for (int i = 0; i < mergedImg.getImageHeight(); i++) {
        for (int j = 0; j < mergedImg.getImageWidth(); j++) {
            lPixel.setARGBValue(leftImg.getARGBValue(j, i));
            rPixel.setARGBValue(rightImg.getARGBValue(j, i));
            int mr = leftColor.calculateRed(lPixel.r, lPixel.g, lPixel.b) + rightColor.calculateRed(rPixel.r, rPixel.g, rPixel.b);
            if (mr < 0)
                mr = 0;
            else if (mr > 255)
                mr = 255;
            int mg = leftColor.calculateGreen(lPixel.r, lPixel.g, lPixel.b) + rightColor.calculateGreen(rPixel.r, rPixel.g, rPixel.b);
            if (mg < 0)
                mg = 0;
            else if (mg > 255)
                mg = 255;
            int mb = leftColor.calculateBlue(lPixel.r, lPixel.g, lPixel.b) + rightColor.calculateBlue(rPixel.r, rPixel.g, rPixel.b);
            if (mb < 0)
                mb = 0;
            else if (mb > 255)
                mb = 255;
            mergedImg.setRGB(j, i, mr, mg, mb);
        }
    }
    return mergedRender;
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) Stereo3dColor(org.jwildfire.create.tina.base.Stereo3dColor) Pixel(org.jwildfire.image.Pixel) PCPoint(org.jwildfire.create.tina.base.raster.RasterPointCloud.PCPoint)

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