Search in sources :

Example 51 with SimpleImage

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

the class AbstractDisplacementMapWFFunc method transform.

public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP, double pAmount, double pInputX, double pInputY) {
    double x = (pInputX - (offsetX + 0.5) + 1.0) / scaleX * (double) (imgWidth - 1);
    double y = (pInputY - (offsetY + 0.5) + 1.0) / scaleY * (double) (imgHeight - 1);
    int ix = Tools.FTOI(x);
    int iy = Tools.FTOI(y);
    if (this.tileX == 1) {
        if (ix < 0) {
            int nx = ix / imgWidth - 1;
            ix -= nx * imgWidth;
        } else if (ix >= imgWidth) {
            int nx = ix / imgWidth;
            ix -= nx * imgWidth;
        }
    }
    if (this.tileY == 1) {
        if (iy < 0) {
            int ny = iy / imgHeight - 1;
            iy -= ny * imgHeight;
        } else if (iy >= imgHeight) {
            int ny = iy / imgHeight;
            iy -= ny * imgHeight;
        }
    }
    double r, g, b;
    if (ix >= 0 && ix < imgWidth && iy >= 0 && iy < imgHeight) {
        if (colorMap instanceof SimpleImage) {
            toolPixel.setARGBValue(((SimpleImage) colorMap).getARGBValue(ix, iy));
            r = (double) toolPixel.r / 255.0;
            g = (double) toolPixel.g / 255.0;
            b = (double) toolPixel.b / 255.0;
        } else {
            ((SimpleHDRImage) colorMap).getRGBValues(rgbArray, ix, iy);
            r = rgbArray[0];
            g = rgbArray[0];
            b = rgbArray[0];
        }
    } else {
        return;
    }
    switch(mode) {
        case MODE_TRANSLATE:
            {
                double amountX = (r - 0.5) * pAmount;
                double amountY = (g - 0.5) * pAmount;
                pVarTP.x += amountX;
                pVarTP.y += amountY;
            }
            break;
        case MODE_SCALE:
            {
                double intensity = calcIntensity(r, g, b) - bias;
                if (intensity > 0.0) {
                    double scl = 1.0 + (intensity - 0.5) * pAmount;
                    pVarTP.x *= scl;
                    pVarTP.y *= scl;
                }
            }
            break;
        case MODE_SCISSOR:
            {
                double amountX = (r - 0.5) * pAmount;
                double amountY = (g - 0.5) * pAmount;
                double newx = pVarTP.x * amountX * amountY + pVarTP.y * amountY;
                double newy = pVarTP.x * amountY - pVarTP.y * amountX * amountY;
                pVarTP.x = newx;
                pVarTP.y = newy;
            }
            break;
        case MODE_ROTATE:
        default:
            {
                double intensity = calcIntensity(r, g, b) - bias;
                if (intensity > 0.0) {
                    double angle = intensity * M_2PI * pAmount;
                    double sina = sin(angle);
                    double cosa = cos(angle);
                    double xnew = pVarTP.x * cosa - pVarTP.y * sina;
                    double ynew = pVarTP.x * sina + pVarTP.y * cosa;
                    pVarTP.x = xnew;
                    pVarTP.y = ynew;
                }
            }
    }
    switch(colorMode) {
        case COLOR_MODE_INHERIT:
            {
                pVarTP.rgbColor = true;
                pVarTP.redColor = r;
                pVarTP.greenColor = g;
                pVarTP.blueColor = b;
                pVarTP.color = getColorIdx(r, g, b);
            }
            break;
        default:
            // nothing to do
            break;
    }
}
Also used : SimpleHDRImage(org.jwildfire.image.SimpleHDRImage) SimpleImage(org.jwildfire.image.SimpleImage) XYZPoint(org.jwildfire.create.tina.base.XYZPoint)

Example 52 with SimpleImage

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

the class MeshGenController method refreshFlameImage.

public void refreshFlameImage(boolean pQuickRender, JPanel pRootPanel, FlameHolder pFlameHolder) {
    if (!refreshing) {
        FlamePanel imgPanel = getFlamePanel(pRootPanel, pFlameHolder);
        Rectangle bounds = imgPanel.getImageBounds();
        int width = bounds.width;
        int height = bounds.height;
        if (width >= 16 && height >= 16) {
            RenderInfo info = new RenderInfo(width, height, RenderMode.PREVIEW);
            Flame flame = pFlameHolder.getFlame();
            if (flame != null) {
                double oldSpatialFilterRadius = flame.getSpatialFilterRadius();
                double oldSampleDensity = flame.getSampleDensity();
                try {
                    double wScl = (double) info.getImageWidth() / (double) flame.getWidth();
                    double hScl = (double) info.getImageHeight() / (double) flame.getHeight();
                    flame.setPixelsPerUnit((wScl + hScl) * 0.5 * flame.getPixelsPerUnit());
                    flame.setWidth(info.getImageWidth());
                    flame.setHeight(info.getImageHeight());
                    FlameRenderer renderer = new FlameRenderer(flame, prefs, false, false);
                    if (pQuickRender) {
                        renderer.setProgressUpdater(null);
                        flame.setSampleDensity(3.0);
                        flame.setSpatialFilterRadius(0.0);
                    } else {
                        renderer.setProgressUpdater(renderSequenceProgressUpdater);
                        flame.setSampleDensity(prefs.getTinaRenderPreviewQuality());
                    }
                    RenderedFlame res = renderer.renderFlame(info);
                    imgPanel.setImage(res.getImage());
                } finally {
                    flame.setSpatialFilterRadius(oldSpatialFilterRadius);
                    flame.setSampleDensity(oldSampleDensity);
                }
            }
        } else {
            imgPanel.setImage(new SimpleImage(width, height));
        }
        pRootPanel.repaint();
    }
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) Rectangle(java.awt.Rectangle) FlamePanel(org.jwildfire.create.tina.swing.flamepanel.FlamePanel) FlameRenderer(org.jwildfire.create.tina.render.FlameRenderer) RenderInfo(org.jwildfire.create.tina.render.RenderInfo) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame) Flame(org.jwildfire.create.tina.base.Flame) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame)

Example 53 with SimpleImage

use of org.jwildfire.image.SimpleImage 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);
    }
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) ImageReader(org.jwildfire.io.ImageReader) File(java.io.File)

Example 54 with SimpleImage

use of org.jwildfire.image.SimpleImage 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;
}
Also used : HashMap(java.util.HashMap) RGBPalette(org.jwildfire.create.tina.palette.RGBPalette) SimpleImage(org.jwildfire.image.SimpleImage) ArrayList(java.util.ArrayList) RGBColor(org.jwildfire.create.tina.palette.RGBColor) ImageReader(org.jwildfire.io.ImageReader) File(java.io.File) Pixel(org.jwildfire.image.Pixel)

Example 55 with SimpleImage

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

the class PostBumpMapWFFunc method init.

@Override
public void init(FlameTransformationContext pContext, Layer pLayer, XForm pXForm, double pAmount) {
    bumpMap = null;
    if (inlinedImage != null) {
        try {
            bumpMap = RessourceManager.getImage(inlinedImageHash, inlinedImage);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else if (imageFilename != null && imageFilename.length() > 0) {
        try {
            bumpMap = RessourceManager.getImage(imageFilename);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    if (bumpMap == null) {
        bumpMap = new SimpleImage(320, 256);
    }
    imgWidth = bumpMap.getImageWidth();
    imgHeight = bumpMap.getImageHeight();
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage)

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