Search in sources :

Example 6 with SimpleHDRImage

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

the class FlameRenderer method renderImageNormal.

private RenderedFlame renderImageNormal(RenderInfo pRenderInfo, int pTotalImagePartCount, int pTotalImagePartIdx) {
    progressDisplayPhaseCount = pTotalImagePartCount;
    progressDisplayPhase = pTotalImagePartIdx;
    RenderedFlame res = new RenderedFlame();
    res.init(pRenderInfo, flame);
    if (forceAbort)
        return res;
    boolean renderNormal = true;
    boolean renderHDR = pRenderInfo.isRenderHDR();
    if (!flame.isRenderable()) {
        if (renderNormal) {
            if (renderScale > 0) {
                res.getImage().resetImage(res.getImage().getImageWidth() * renderScale, res.getImage().getImageHeight() * renderScale);
            }
            if (flame.getBGImageFilename().length() > 0) {
                try {
                    res.getImage().fillBackground((SimpleImage) RessourceManager.getImage(flame.getBGImageFilename()));
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            } else {
                new FlameBGColorHandler(flame).fillBackground(res.getImage());
            }
        }
        if (renderHDR) {
            res.getHDRImage().fillBackground(flame.getBgColorRed(), flame.getBgColorGreen(), flame.getBgColorBlue());
            try {
                res.getHDRImage().fillBackground((SimpleImage) RessourceManager.getImage(flame.getBGImageFilename()));
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        return res;
    }
    double origZoom = flame.getCamZoom();
    try {
        SimpleImage img = renderNormal ? res.getImage() : null;
        SimpleHDRImage hdrImg = renderHDR ? res.getHDRImage() : null;
        if (renderNormal) {
            initRaster(pRenderInfo, img.getImageWidth(), img.getImageHeight(), flame.getSampleDensity());
        } else if (renderHDR) {
            initRaster(pRenderInfo, hdrImg.getImageWidth(), hdrImg.getImageHeight(), flame.getSampleDensity());
        } else {
            throw new IllegalStateException();
        }
        if (pRenderInfo.getRestoredRaster() == null) {
            List<List<RenderPacket>> renderFlames = new ArrayList<List<RenderPacket>>();
            for (int t = 0; t < prefs.getTinaRenderThreads(); t++) {
                renderFlames.add(createRenderPackets(flame, flame.getFrame()));
            }
            forceAbort = false;
            iterate(0, 1, renderFlames, null);
            raster.finalizeRaster();
            if (pRenderInfo.isStoreRaster()) {
                res.setRaster(raster);
            }
        } else {
            if (flame.getSolidRenderSettings().isSolidRenderingEnabled()) {
                FlameRendererView view = createView(flame);
                raster.notifyInit(view.getLightViewCalculator());
            }
        }
        if (!forceAbort) {
            if ((flame.getSampleDensity() <= 10.0 && flame.getSpatialFilterRadius() <= MathLib.EPSILON) || renderScale > 1) {
                renderImageSimple(img);
            } else {
                renderImage(img, hdrImg, res.getZBuffer());
            }
        }
    } finally {
        flame.setCamZoom(origZoom);
    }
    return res;
}
Also used : SimpleHDRImage(org.jwildfire.image.SimpleHDRImage) ArrayList(java.util.ArrayList) PCPoint(org.jwildfire.create.tina.base.raster.RasterPointCloud.PCPoint) SimpleImage(org.jwildfire.image.SimpleImage) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with SimpleHDRImage

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

the class ColorMapHolder method applyImageColor.

public void applyImageColor(XYZPoint pVarTP, int ix, int iy, double iu, double iv) {
    if (ix >= 0 && ix < colorMapWidth && iy >= 0 && iy < colorMapHeight) {
        if (colorMap instanceof SimpleImage) {
            if (blend_colormap > 0) {
                int ix1 = ix + 1;
                if (ix1 >= colorMapWidth)
                    ix1 = 0;
                int iy1 = iy + 1;
                if (iy1 >= colorMapHeight)
                    iy1 = 0;
                double iufrac = MathLib.frac(iu);
                double ivfrac = MathLib.frac(iv);
                toolPixel.setARGBValue(((SimpleImage) colorMap).getARGBValue(ix, iy));
                int lur = toolPixel.r;
                int lug = toolPixel.g;
                int lub = toolPixel.b;
                toolPixel.setARGBValue(((SimpleImage) colorMap).getARGBValue(ix1, iy));
                int rur = toolPixel.r;
                int rug = toolPixel.g;
                int rub = toolPixel.b;
                toolPixel.setARGBValue(((SimpleImage) colorMap).getARGBValue(ix, iy1));
                int lbr = toolPixel.r;
                int lbg = toolPixel.g;
                int lbb = toolPixel.b;
                toolPixel.setARGBValue(((SimpleImage) colorMap).getARGBValue(ix1, iy1));
                int rbr = toolPixel.r;
                int rbg = toolPixel.g;
                int rbb = toolPixel.b;
                pVarTP.rgbColor = true;
                pVarTP.redColor = GfxMathLib.blerp(lur, rur, lbr, rbr, iufrac, ivfrac);
                pVarTP.greenColor = GfxMathLib.blerp(lug, rug, lbg, rbg, iufrac, ivfrac);
                pVarTP.blueColor = GfxMathLib.blerp(lub, rub, lbb, rbb, iufrac, ivfrac);
            } else {
                toolPixel.setARGBValue(((SimpleImage) colorMap).getARGBValue(ix, iy));
                pVarTP.rgbColor = true;
                pVarTP.redColor = toolPixel.r;
                pVarTP.greenColor = toolPixel.g;
                pVarTP.blueColor = toolPixel.b;
            }
        } else {
            if (blend_colormap > 0) {
                int ix1 = ix + 1;
                if (ix1 >= colorMapWidth)
                    ix1 = 0;
                int iy1 = iy + 1;
                if (iy1 >= colorMapHeight)
                    iy1 = 0;
                double iufrac = MathLib.frac(iu);
                double ivfrac = MathLib.frac(iv);
                ((SimpleHDRImage) colorMap).getRGBValues(rgbArray, ix, iy);
                float lur = rgbArray[0];
                float lug = rgbArray[1];
                float lub = rgbArray[2];
                ((SimpleHDRImage) colorMap).getRGBValues(rgbArray, ix1, iy);
                float rur = rgbArray[0];
                float rug = rgbArray[1];
                float rub = rgbArray[2];
                ((SimpleHDRImage) colorMap).getRGBValues(rgbArray, ix, iy1);
                float lbr = rgbArray[0];
                float lbg = rgbArray[1];
                float lbb = rgbArray[2];
                ((SimpleHDRImage) colorMap).getRGBValues(rgbArray, ix1, iy1);
                float rbr = rgbArray[0];
                float rbg = rgbArray[1];
                float rbb = rgbArray[2];
                pVarTP.rgbColor = true;
                pVarTP.redColor = GfxMathLib.blerp(lur, rur, lbr, rbr, iufrac, ivfrac);
                pVarTP.greenColor = GfxMathLib.blerp(lug, rug, lbg, rbg, iufrac, ivfrac);
                pVarTP.blueColor = GfxMathLib.blerp(lub, rub, lbb, rbb, iufrac, ivfrac);
            } else {
                ((SimpleHDRImage) colorMap).getRGBValues(rgbArray, ix, iy);
                pVarTP.rgbColor = true;
                pVarTP.redColor = rgbArray[0];
                pVarTP.greenColor = rgbArray[1];
                pVarTP.blueColor = rgbArray[2];
            }
        }
    } else {
        pVarTP.rgbColor = true;
        pVarTP.redColor = 0;
        pVarTP.greenColor = 0;
        pVarTP.blueColor = 0;
    }
}
Also used : SimpleHDRImage(org.jwildfire.image.SimpleHDRImage) SimpleImage(org.jwildfire.image.SimpleImage) XYZPoint(org.jwildfire.create.tina.base.XYZPoint)

Example 8 with SimpleHDRImage

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

the class ImageReader method loadHDRImage.

public SimpleHDRImage loadHDRImage(String pFilename) throws Exception {
    File file = new File(pFilename);
    if (!file.exists())
        throw new FileNotFoundException(pFilename);
    InputStream f = new BufferedInputStream(new FileInputStream(pFilename));
    // header
    String header = readNextLine(f);
    if (!"#?RGBE".equals(header)) {
        throw new IllegalArgumentException("Invalid header <" + header + ">");
    }
    // format
    String format = readNextLine(f);
    if (!"FORMAT=32-bit_rle_rgbe".equals(format)) {
        throw new IllegalArgumentException("Invalid format <" + format + ">");
    }
    // skip empty line
    readNextLine(f);
    // image size
    String dimension = readNextLine(f);
    Pattern pattern = Pattern.compile("\\-Y ([0-9]+) \\+X ([0-9]+)");
    Matcher matcher = pattern.matcher(dimension);
    if (!matcher.find()) {
        throw new IllegalArgumentException("Invalid dimension identifier<" + dimension + ">");
    }
    int width = Integer.parseInt(matcher.group(2));
    int height = Integer.parseInt(matcher.group(1));
    SimpleHDRImage res = new SimpleHDRImage(width, height);
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            int r = f.read();
            int g = f.read();
            int b = f.read();
            int e = f.read();
            res.setRGBEValue(j, i, r, g, b, e);
        }
    }
    return res;
}
Also used : Pattern(java.util.regex.Pattern) SimpleHDRImage(org.jwildfire.image.SimpleHDRImage) BufferedInputStream(java.io.BufferedInputStream) Matcher(java.util.regex.Matcher) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 9 with SimpleHDRImage

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

the class ScriptProcessor method loadImage.

public Buffer loadImage(String pFilename) throws Exception {
    if (!new File(pFilename).exists())
        throw new FileNotFoundException(pFilename);
    String fileExt = null;
    {
        int p = pFilename.lastIndexOf(".");
        if (p >= 0 && p < pFilename.length() - 2) {
            fileExt = pFilename.substring(p + 1, pFilename.length());
        }
    }
    if ("hdr".equalsIgnoreCase(fileExt)) {
        SimpleHDRImage img = new ImageReader(desktop).loadHDRImage(pFilename);
        File file = new File(pFilename);
        Buffer buffer = bufferList.addHDRImageBuffer(addBuffersToDesktop ? desktop : null, file.getName(), img);
        return buffer;
    } else {
        SimpleImage img = new ImageReader(desktop).loadImage(pFilename);
        File file = new File(pFilename);
        Buffer buffer = bufferList.addImageBuffer(addBuffersToDesktop ? desktop : null, file.getName(), img);
        return buffer;
    }
}
Also used : SimpleHDRImage(org.jwildfire.image.SimpleHDRImage) SimpleImage(org.jwildfire.image.SimpleImage) FileNotFoundException(java.io.FileNotFoundException) ImageReader(org.jwildfire.io.ImageReader) File(java.io.File)

Example 10 with SimpleHDRImage

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

the class HDRComposeTransformer method performImageTransformation.

@Override
protected void performImageTransformation(WFImage pImg) {
    SimpleHDRImage fgImg = foreground.getHDRImage();
    SimpleHDRImage bgImg = (SimpleHDRImage) pImg;
    if ((fgImg.getImageWidth() != bgImg.getImageWidth()) || (fgImg.getImageHeight() != bgImg.getImageHeight())) {
        throw new IllegalArgumentException();
    }
    SimpleHDRImage res = new SimpleHDRImage(fgImg.getImageWidth(), fgImg.getImageHeight());
    float[] fgRGB = new float[3];
    float[] bgRGB = new float[3];
    float r, g, b;
    float trans = (float) transparency * 0.01f;
    if (trans < 0.0f) {
        trans = 0.0f;
    } else if (trans > 1.0f) {
        trans = 1.0f;
    }
    float invTrans = 1.0f - trans;
    float fgScale = (float) intensity;
    float bgScale = (float) intensity;
    float fgRed, fgGreen, fgBlue;
    float bgRed, bgGreen, bgBlue;
    float mergedRed, mergedGreen, mergedBlue;
    HSLTransformer fgHSL = new HSLTransformer();
    HSLTransformer bgHSL = new HSLTransformer();
    HSLTransformer mergedHSL = new HSLTransformer();
    float[] lum = new float[2];
    fgImg.getMinMaxLum(lum);
    float fgLumMin = lum[0];
    float fgLumMax = lum[1];
    if ((fgLumMax - fgLumMin) < MathLib.EPSILON) {
        fgLumMax = fgLumMin + (float) MathLib.EPSILON;
    }
    bgImg.getMinMaxLum(lum);
    float bgLumMin = lum[0];
    float bgLumMax = lum[1];
    if ((bgLumMax - bgLumMin) < MathLib.EPSILON) {
        bgLumMax = bgLumMin + (float) MathLib.EPSILON;
    }
    bgScale *= (fgLumMax - fgLumMin) / (bgLumMax - bgLumMin);
    for (int i = 0; i < fgImg.getImageHeight(); i++) {
        for (int j = 0; j < fgImg.getImageWidth(); j++) {
            fgImg.getRGBValues(fgRGB, j, i);
            fgRed = fgRGB[0] * fgScale;
            fgGreen = fgRGB[1] * fgScale;
            fgBlue = fgRGB[2] * fgScale;
            bgRed = bgRGB[0] * bgScale;
            bgGreen = bgRGB[1] * bgScale;
            bgBlue = bgRGB[2] * bgScale;
            bgImg.getRGBValues(bgRGB, j, i);
            switch(mergeMode) {
                case MULTIPLY:
                    mergedRed = fgRed * bgRed;
                    mergedGreen = fgGreen * bgGreen;
                    mergedBlue = fgBlue * bgBlue;
                    break;
                case ADD:
                    mergedRed = (fgRed + bgRed) * 0.5f;
                    mergedGreen = (fgGreen + bgGreen) * 0.5f;
                    mergedBlue = (fgBlue + bgBlue) * 0.5f;
                    break;
                case SUBTRACT:
                    mergedRed = bgRed - fgRed;
                    if (mergedRed < 0.0f) {
                        mergedRed = 0.0f;
                    }
                    mergedGreen = bgGreen - fgGreen;
                    if (mergedGreen < 0.0f) {
                        mergedGreen = 0.0f;
                    }
                    mergedBlue = bgBlue - fgBlue;
                    if (mergedBlue < 0.0f) {
                        mergedBlue = 0.0f;
                    }
                    break;
                case RED:
                    mergedRed = fgRed;
                    mergedGreen = bgGreen;
                    mergedBlue = bgBlue;
                    break;
                case GREEN:
                    mergedRed = bgRed;
                    mergedGreen = fgGreen;
                    mergedBlue = bgBlue;
                    break;
                case BLUE:
                    mergedRed = bgRed;
                    mergedGreen = bgGreen;
                    mergedBlue = fgBlue;
                    break;
                case LIGHTEN:
                    {
                        float fgLum = SimpleHDRImage.calcLum(fgRed, fgGreen, fgBlue);
                        float bgLum = SimpleHDRImage.calcLum(bgRed, bgGreen, bgBlue);
                        if (fgLum > bgLum) {
                            mergedRed = fgRed;
                            mergedGreen = fgGreen;
                            mergedBlue = fgBlue;
                        } else {
                            mergedRed = bgRed;
                            mergedGreen = bgGreen;
                            mergedBlue = bgBlue;
                        }
                    }
                    break;
                case DARKEN:
                    {
                        float fgLum = SimpleHDRImage.calcLum(fgRed, fgGreen, fgBlue);
                        float bgLum = SimpleHDRImage.calcLum(bgRed, bgGreen, bgBlue);
                        if (fgLum < bgLum) {
                            mergedRed = fgRed;
                            mergedGreen = fgGreen;
                            mergedBlue = fgBlue;
                        } else {
                            mergedRed = bgRed;
                            mergedGreen = bgGreen;
                            mergedBlue = bgBlue;
                        }
                    }
                    break;
                case HSL_ADD:
                    fgHSL.setRGB(fgRed, fgGreen, fgBlue);
                    bgHSL.setRGB(bgRed, bgGreen, bgBlue);
                    mergedHSL.setHSL(fgHSL.getHue() + bgHSL.getHue(), fgHSL.getSaturation() + bgHSL.getSaturation(), fgHSL.getLuminosity() + bgHSL.getLuminosity(), fgHSL.getAmp());
                    mergedRed = mergedHSL.getRed();
                    mergedGreen = mergedHSL.getGreen();
                    mergedBlue = mergedHSL.getBlue();
                    break;
                default:
                    mergedRed = fgRed;
                    mergedGreen = fgGreen;
                    mergedBlue = fgBlue;
                    break;
            }
            r = mergedRed * invTrans + bgRed * trans;
            g = mergedGreen * invTrans + bgGreen * trans;
            b = mergedBlue * invTrans + bgBlue * trans;
            res.setRGB(j, i, r, g, b);
        }
    }
    ((SimpleHDRImage) pImg).assignImage(res);
}
Also used : SimpleHDRImage(org.jwildfire.image.SimpleHDRImage)

Aggregations

SimpleHDRImage (org.jwildfire.image.SimpleHDRImage)11 SimpleImage (org.jwildfire.image.SimpleImage)9 XYZPoint (org.jwildfire.create.tina.base.XYZPoint)4 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 ImageReader (org.jwildfire.io.ImageReader)2 ScaleTransformer (org.jwildfire.transform.ScaleTransformer)2 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 ImageIcon (javax.swing.ImageIcon)1 PCPoint (org.jwildfire.create.tina.base.raster.RasterPointCloud.PCPoint)1 FastHDRTonemapper (org.jwildfire.image.FastHDRTonemapper)1 WFImage (org.jwildfire.image.WFImage)1 Mesh3D (org.jwildfire.transform.Mesh3D)1