Search in sources :

Example 11 with SimpleHDRImage

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

the class AbstractColorMapWFFunc 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 - 2);
    double y = (pInputY - (offsetY + 0.5) + 1.0) / scaleY * (double) (imgHeight - 2);
    int ix, iy;
    if (blend_colormap > 0) {
        ix = (int) MathLib.trunc(x);
        iy = (int) MathLib.trunc(y);
    } else {
        ix = Tools.FTOI(x);
        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) {
            if (blend_colormap > 0) {
                double iufrac = MathLib.frac(x);
                double ivfrac = MathLib.frac(y);
                toolPixel.setARGBValue(((SimpleImage) colorMap).getARGBValue(ix, iy));
                int lur = toolPixel.r;
                int lug = toolPixel.g;
                int lub = toolPixel.b;
                toolPixel.setARGBValue(((SimpleImage) colorMap).getARGBValue(ix + 1, iy));
                int rur = toolPixel.r;
                int rug = toolPixel.g;
                int rub = toolPixel.b;
                toolPixel.setARGBValue(((SimpleImage) colorMap).getARGBValue(ix, iy + 1));
                int lbr = toolPixel.r;
                int lbg = toolPixel.g;
                int lbb = toolPixel.b;
                toolPixel.setARGBValue(((SimpleImage) colorMap).getARGBValue(ix + 1, iy + 1));
                int rbr = toolPixel.r;
                int rbg = toolPixel.g;
                int rbb = toolPixel.b;
                r = GfxMathLib.blerp(lur, rur, lbr, rbr, iufrac, ivfrac);
                g = GfxMathLib.blerp(lug, rug, lbg, rbg, iufrac, ivfrac);
                b = GfxMathLib.blerp(lub, rub, lbb, rbb, iufrac, ivfrac);
            } else {
                toolPixel.setARGBValue(((SimpleImage) colorMap).getARGBValue(ix, iy));
                r = toolPixel.r;
                g = toolPixel.g;
                b = toolPixel.b;
            }
            if (dc_color > 0) {
                pVarTP.rgbColor = true;
                pVarTP.redColor = r;
                pVarTP.greenColor = g;
                pVarTP.blueColor = b;
            }
        } else {
            if (blend_colormap > 0) {
                double iufrac = MathLib.frac(x);
                double ivfrac = MathLib.frac(y);
                ((SimpleHDRImage) colorMap).getRGBValues(rgbArray, ix, iy);
                double lur = rgbArray[0];
                double lug = rgbArray[1];
                double lub = rgbArray[2];
                ((SimpleHDRImage) colorMap).getRGBValues(rgbArray, ix + 1, iy);
                double rur = rgbArray[0];
                double rug = rgbArray[1];
                double rub = rgbArray[2];
                ((SimpleHDRImage) colorMap).getRGBValues(rgbArray, ix, iy + 1);
                double lbr = rgbArray[0];
                double lbg = rgbArray[1];
                double lbb = rgbArray[2];
                ((SimpleHDRImage) colorMap).getRGBValues(rgbArray, ix + 1, iy + 1);
                double rbr = rgbArray[0];
                double rbg = rgbArray[1];
                double rbb = rgbArray[2];
                r = GfxMathLib.blerp(lur, rur, lbr, rbr, iufrac, ivfrac);
                g = GfxMathLib.blerp(lug, rug, lbg, rbg, iufrac, ivfrac);
                b = GfxMathLib.blerp(lub, rub, lbb, rbb, iufrac, ivfrac);
            } else {
                ((SimpleHDRImage) colorMap).getRGBValues(rgbArray, ix, iy);
                r = rgbArray[0];
                g = rgbArray[1];
                b = rgbArray[2];
            }
            if (dc_color > 0) {
                pVarTP.rgbColor = true;
                pVarTP.redColor = r;
                pVarTP.greenColor = g;
                pVarTP.blueColor = b;
            }
        }
    } else {
        r = g = b = 0.0;
        if (dc_color > 0) {
            pVarTP.rgbColor = true;
            pVarTP.redColor = r;
            pVarTP.greenColor = g;
            pVarTP.blueColor = b;
        }
    }
    double dz = this.offsetZ;
    if (fabs(scaleZ) > EPSILON) {
        double intensity = (0.299 * r + 0.588 * g + 0.113 * b) / 255.0;
        dz += scaleZ * intensity;
    }
    if (resetZ != 0) {
        pVarTP.z = dz;
    } else {
        pVarTP.z += dz;
    }
    if (dc_color > 0) {
        pVarTP.color = getColorIdx(Tools.FTOI(r), Tools.FTOI(g), Tools.FTOI(b));
    }
}
Also used : SimpleHDRImage(org.jwildfire.image.SimpleHDRImage) SimpleImage(org.jwildfire.image.SimpleImage) XYZPoint(org.jwildfire.create.tina.base.XYZPoint)

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