Search in sources :

Example 1 with SimpleImage

use of org.jwildfire.image.SimpleImage 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;
}
Also used : WFImage(org.jwildfire.image.WFImage) RGBPalette(org.jwildfire.create.tina.palette.RGBPalette) SimpleImage(org.jwildfire.image.SimpleImage) JLabel(javax.swing.JLabel) ImageReader(org.jwildfire.io.ImageReader) File(java.io.File) MedianCutQuantizer(org.jwildfire.create.tina.palette.MedianCutQuantizer)

Example 2 with SimpleImage

use of org.jwildfire.image.SimpleImage 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;
}
Also used : WFImage(org.jwildfire.image.WFImage) RGBPalette(org.jwildfire.create.tina.palette.RGBPalette) SimpleImage(org.jwildfire.image.SimpleImage) JLabel(javax.swing.JLabel) ImageReader(org.jwildfire.io.ImageReader) File(java.io.File) MedianCutQuantizer(org.jwildfire.create.tina.palette.MedianCutQuantizer)

Example 3 with SimpleImage

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

the class MutaGenController method drawSelectedSet.

public void drawSelectedSet() {
    Dimension imgSize = calcImageSize();
    MutationSet selectedSet = mutationList.get(selectedGenerationIdx);
    int rows = selectedSet.getRows();
    int cols = selectedSet.getCols();
    initProgress(rows, cols);
    int step = 0;
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            Flame mutation = selectedSet.getFlame(i, j).makeCopy();
            Flame morphed = createWeightedFlame(selectedSet.getBaseFlame(), mutation);
            SimpleImage renderedImg = renderFlame(morphed, imgSize, false);
            ImagePanel pnl = imagePanels[i][j];
            pnl.setImage(renderedImg);
            showProgress(++step);
            pnl.invalidate();
            try {
                Graphics g = pnl.getGraphics();
                if (g != null) {
                    pnl.paint(g);
                }
            } catch (Throwable ex) {
                ex.printStackTrace();
            }
        }
    }
    enableControls();
}
Also used : Graphics(java.awt.Graphics) SimpleImage(org.jwildfire.image.SimpleImage) Dimension(java.awt.Dimension) Flame(org.jwildfire.create.tina.base.Flame) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame) ImagePanel(org.jwildfire.swing.ImagePanel)

Example 4 with SimpleImage

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

the class RGBPaletteRenderer method renderHorizPalette.

public SimpleImage renderHorizPalette(RGBColor[] pColors, int pWidth, int pHeight) {
    if (pColors == null || pWidth < 1 || pHeight < 1)
        throw new IllegalArgumentException();
    SimpleImage img = new SimpleImage(RGBPalette.PALETTE_SIZE, pHeight);
    for (int i = 0; i < pColors.length; i++) {
        RGBColor color = pColors[i];
        if (color == null) {
            color = RGBPalette.BLACK;
        }
        int r = color.getRed();
        int g = color.getGreen();
        int b = color.getBlue();
        for (int j = 0; j < pHeight; j++) {
            img.setRGB(i, j, r, g, b);
        }
    }
    if (img.getImageWidth() != pWidth || img.getImageHeight() != pHeight) {
        ScaleTransformer scaleT = new ScaleTransformer();
        scaleT.setScaleWidth(pWidth);
        scaleT.setScaleHeight(pHeight);
        scaleT.setAspect(ScaleAspect.IGNORE);
        scaleT.setUnit(Unit.PIXELS);
        scaleT.transformImage(img);
    }
    return img;
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) ScaleTransformer(org.jwildfire.transform.ScaleTransformer)

Example 5 with SimpleImage

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

the class BaseFlameListCreator method addBaseFlame.

private void addBaseFlame(FlameTransformationContext pContext, List<SimpleImage> paramMaps1, List<SimpleImage> paramMaps2, List<SimpleImage> paramMaps3, List<BaseFlame> res, int i, int j, double intensity, int shapeIndex, FlameParams params) {
    if (preview) {
        double pInt = intensity / (1.0 - imageParams.getStructure_threshold());
        DynamicProperties motionProperties = calculateMotionProperties(imageParams.getScaleColorMap() * j, imageParams.getScaleColorMap() * i, pInt, params);
        BaseFlame p = new BaseFlame(pInt, 0, 0, 0, 1.0, imageParams, params, IFlamesIterator.BLANK, motionProperties);
        res.add(p);
    } else {
        FlameColor flameColor = createFlameColor(imageParams, toolPixel);
        // System.out.println("(" + toolPixel.r + " " + toolPixel.g + " " + toolPixel.b + ") -> (" + flameColor.r + " " + flameColor.g + " " + flameColor.b + ")");
        double flameBrightness;
        if (params.getBrightnessChange() > MathLib.EPSILON && (randGen.random() < params.getBrightnessChange() || (params.getBrightnessChange() - MathLib.EPSILON) >= 1.0) && params.getBrightnessMin() < params.getBrightnessMax()) {
            flameBrightness = params.getBrightnessMin() + randGen.random() * (params.getBrightnessMax() - params.getBrightnessMin());
        } else {
            flameBrightness = params.getBrightnessMin();
        }
        IFlamesIterator iterator = null;
        String param1 = params.getFlameParam1() != null && params.getFlameParam1().length() > 0 ? params.getFlameParam1() : null;
        String param2 = params.getFlameParam2() != null && params.getFlameParam2().length() > 0 ? params.getFlameParam2() : null;
        String param3 = params.getFlameParam3() != null && params.getFlameParam3().length() > 0 ? params.getFlameParam3() : null;
        if (params.isInstancing()) {
            iterator = instances.get(params);
            if (iterator == null) {
                iterator = new IFlamesIterator(pContext, params, null, null);
                iteratorCount++;
                instances.put(params, iterator);
            }
        } else {
            if (param1 != null || param2 != null || param3 != null) {
                List<String> paramNames = new ArrayList<String>();
                List<Double> paramValues = new ArrayList<Double>();
                if (param1 != null) {
                    SimpleImage paramMap1 = paramMaps1.get(shapeIndex);
                    double value;
                    if (paramMap1 != null) {
                        toolPixel.setARGBValue(paramMap1.getARGBValueIgnoreBounds(j, i));
                        double paramInt = calcIntensity(toolPixel.r, toolPixel.g, toolPixel.b);
                        value = params.getFlameParam1Min() + (paramInt / COLORSCL) * (params.getFlameParam1Max() - params.getFlameParam1Min());
                    } else {
                        value = params.getFlameParam1Min() + randGen.random() * (params.getFlameParam1Max() - params.getFlameParam1Min());
                    }
                    paramNames.add(params.getFlameParam1());
                    paramValues.add(value);
                }
                if (param2 != null) {
                    SimpleImage paramMap2 = paramMaps2.get(shapeIndex);
                    double value;
                    if (paramMap2 != null) {
                        toolPixel.setARGBValue(paramMap2.getARGBValueIgnoreBounds(j, i));
                        double paramInt = calcIntensity(toolPixel.r, toolPixel.g, toolPixel.b);
                        value = params.getFlameParam2Min() + (paramInt / COLORSCL) * (params.getFlameParam2Max() - params.getFlameParam2Min());
                    } else {
                        value = params.getFlameParam2Min() + randGen.random() * (params.getFlameParam2Max() - params.getFlameParam2Min());
                    }
                    paramNames.add(params.getFlameParam2());
                    paramValues.add(value);
                }
                if (param3 != null) {
                    SimpleImage paramMap3 = paramMaps3.get(shapeIndex);
                    double value;
                    if (paramMap3 != null) {
                        toolPixel.setARGBValue(paramMap3.getARGBValueIgnoreBounds(j, i));
                        double paramInt = calcIntensity(toolPixel.r, toolPixel.g, toolPixel.b);
                        value = params.getFlameParam3Min() + (paramInt / COLORSCL) * (params.getFlameParam3Max() - params.getFlameParam3Min());
                    } else {
                        value = params.getFlameParam3Min() + randGen.random() * (params.getFlameParam3Max() - params.getFlameParam3Min());
                    }
                    paramNames.add(params.getFlameParam3());
                    paramValues.add(value);
                }
                iterator = new IFlamesIterator(pContext, params, paramNames, paramValues);
                iteratorCount++;
            } else {
                iterator = new IFlamesIterator(pContext, params, null, null);
                iteratorCount++;
            }
        }
        double pInt = intensity / (1.0 - imageParams.getStructure_threshold());
        DynamicProperties motionProperties = calculateMotionProperties(imageParams.getScaleColorMap() * j, imageParams.getScaleColorMap() * i, pInt, params);
        BaseFlame p = new BaseFlame(pInt, flameColor.r, flameColor.g, flameColor.b, flameBrightness, imageParams, params, iterator, motionProperties);
        res.add(p);
    }
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) ArrayList(java.util.ArrayList)

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