Search in sources :

Example 41 with Pixel

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

the class AddTransformer method performPixelTransformation.

@Override
protected void performPixelTransformation(WFImage pImg) {
    SimpleImage img = (SimpleImage) pImg;
    SimpleImage fImg = (foregroundImage != null) ? foregroundImage : foreground.getImage();
    int width = pImg.getImageWidth();
    int height = pImg.getImageHeight();
    Pixel srcPixel = new Pixel();
    Pixel dstPixel = new Pixel();
    if (mode == Mode.ADD) {
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < width; j++) {
                srcPixel.setARGBValue(fImg.getARGBValueIgnoreBounds(j, i));
                dstPixel.setARGBValue(img.getARGBValue(j, i));
                dstPixel.r += srcPixel.r;
                if (dstPixel.r > 255)
                    dstPixel.r = 255;
                dstPixel.g += srcPixel.g;
                if (dstPixel.g > 255)
                    dstPixel.g = 255;
                dstPixel.b += srcPixel.b;
                if (dstPixel.b > 255)
                    dstPixel.b = 255;
                img.setRGB(j, i, dstPixel);
            }
        }
    } else if (mode == Mode.SUBTRACT) {
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < width; j++) {
                srcPixel.setARGBValue(fImg.getARGBValueIgnoreBounds(j, i));
                dstPixel.setARGBValue(img.getARGBValue(j, i));
                dstPixel.r -= srcPixel.r;
                if (dstPixel.r < 0)
                    dstPixel.r = 0;
                dstPixel.g -= srcPixel.g;
                if (dstPixel.g < 0)
                    dstPixel.g = 0;
                dstPixel.b -= srcPixel.b;
                if (dstPixel.b < 0)
                    dstPixel.b = 0;
                img.setRGB(j, i, dstPixel);
            }
        }
    } else if (mode == Mode.EXPOSURE) {
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < width; j++) {
                srcPixel.setARGBValue(fImg.getARGBValueIgnoreBounds(j, i));
                dstPixel.setARGBValue(img.getARGBValue(j, i));
                dstPixel.r = expose(dstPixel.r + 2 * srcPixel.r);
                dstPixel.g = expose(dstPixel.g + 2 * srcPixel.g);
                dstPixel.b = expose(dstPixel.b + 2 * srcPixel.b);
                img.setRGB(j, i, dstPixel);
            }
        }
    }
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) Pixel(org.jwildfire.image.Pixel)

Example 42 with Pixel

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

the class AlphaComposeTransformer method performPixelTransformation.

@Override
protected void performPixelTransformation(WFImage pImg) {
    SimpleImage bImg = (SimpleImage) pImg;
    SimpleImage fImg = (foregroundImage != null) ? foregroundImage : foreground.getImage();
    if (fImg == bImg)
        fImg = fImg.clone();
    SimpleImage aImg = (alphaChannelImage != null) ? alphaChannelImage : alphaChannel.getImage();
    if (aImg == bImg)
        aImg = aImg.clone();
    Pixel hPixel = new Pixel();
    Pixel bPixel = new Pixel();
    // calculate left and top edge
    int left, top;
    if (this.fgHAlign == HAlignment.CENTRE) {
        left = (bImg.getImageWidth() - fImg.getImageWidth()) / 2;
    } else if (this.fgHAlign == HAlignment.LEFT) {
        left = 0;
    } else if (this.fgHAlign == HAlignment.RIGHT) {
        left = bImg.getImageWidth() - fImg.getImageWidth();
    } else {
        left = this.fgLeft;
    }
    if (this.fgVAlign == VAlignment.CENTRE) {
        top = (bImg.getImageHeight() - fImg.getImageHeight()) / 2;
    } else if (this.fgVAlign == VAlignment.TOP) {
        top = 0;
    } else if (this.fgVAlign == VAlignment.BOTTOM) {
        top = bImg.getImageHeight() - fImg.getImageHeight();
    } else {
        top = this.fgTop;
    }
    // 
    // calculate alhpa left and top edge
    int aleft, atop;
    if (this.alphaHAlign == HAlignment.CENTRE) {
        aleft = (bImg.getImageWidth() - aImg.getImageWidth()) / 2;
    } else if (this.alphaHAlign == HAlignment.LEFT) {
        aleft = 0;
    } else if (this.alphaHAlign == HAlignment.RIGHT) {
        aleft = bImg.getImageWidth() - aImg.getImageWidth();
    } else {
        aleft = this.alphaLeft;
    }
    if (this.alphaVAlign == VAlignment.CENTRE) {
        atop = (bImg.getImageHeight() - aImg.getImageHeight()) / 2;
    } else if (this.alphaVAlign == VAlignment.TOP) {
        atop = 0;
    } else if (this.alphaVAlign == VAlignment.BOTTOM) {
        atop = bImg.getImageHeight() - aImg.getImageHeight();
    } else {
        atop = this.alphaTop;
    }
    // calculate affected region
    int hsize = 0, vsize = 0;
    int bgleft = 0, bgtop = 0;
    int sleft = 0, stop = 0;
    int swidth = fImg.getImageWidth();
    int sheight = fImg.getImageHeight();
    int bgwidth = bImg.getImageWidth();
    int bgheight = bImg.getImageHeight();
    /* case 1 */
    if ((left >= 0) && (top >= 0)) {
        if ((left >= bgwidth) || (top >= bgheight))
            return;
        hsize = bgwidth - left;
        if (hsize > swidth)
            hsize = swidth;
        vsize = bgheight - top;
        if (vsize > sheight)
            vsize = sheight;
        bgtop = top;
        bgleft = left;
        sleft = 0;
        stop = 0;
    } else /* case 2 */
    if ((left < 0) && (top >= 0)) {
        if ((left <= (0 - swidth)) || (top >= bgheight))
            return;
        hsize = swidth + left;
        if (hsize > bgwidth)
            hsize = bgwidth;
        vsize = bgheight - top;
        if (vsize > sheight)
            vsize = sheight;
        bgtop = top;
        bgleft = 0;
        sleft = 0 - left;
        stop = 0;
    } else /* case 3 */
    if ((left >= 0) && (top < 0)) {
        if ((left >= bgwidth) || (top <= (0 - sheight)))
            return;
        hsize = bgwidth - left;
        if (hsize > swidth)
            hsize = swidth;
        vsize = sheight + top;
        if (vsize > bgheight)
            vsize = bgheight;
        bgtop = 0;
        bgleft = left;
        stop = 0 - top;
        sleft = 0;
    } else /* case 4 */
    if ((left < 0) && (top < 0)) {
        if ((left <= (0 - swidth)) || (top <= (0 - sheight)))
            return;
        hsize = swidth + left;
        if (hsize > bgwidth)
            hsize = bgwidth;
        vsize = sheight + top;
        if (vsize > bgheight)
            vsize = bgheight;
        bgtop = 0;
        bgleft = 0;
        stop = 0 - top;
        sleft = 0 - left;
    }
    // Genlock colors
    int credA = this.colorA.getRed();
    int cgreenA = this.colorA.getGreen();
    int cblueA = this.colorA.getBlue();
    int credB = this.colorB.getRed();
    int cgreenB = this.colorB.getGreen();
    int cblueB = this.colorB.getBlue();
    {
        int tc;
        if (credA > credB) {
            tc = credA;
            credA = credB;
            credB = tc;
        }
        if (cgreenA > cgreenB) {
            tc = cgreenA;
            cgreenA = cgreenB;
            cgreenB = tc;
        }
        if (cblueA > cblueB) {
            tc = cblueA;
            cblueA = cblueB;
            cblueB = tc;
        }
    }
    // 
    if (this.genlock == Genlock.NONE) {
        for (int i = 0; i < vsize; i++) {
            for (int j = 0; j < hsize; j++) {
                hPixel.setARGBValue(fImg.getARGBValue(sleft + j, stop + i));
                int bgX = bgleft + j;
                int bgY = bgtop + i;
                int aX = bgX - aleft;
                int aY = bgY - atop;
                int mix = aImg.getRValueIgnoreBounds(aX, aY);
                int m1 = 255 - mix;
                int m2 = mix;
                bPixel.setARGBValue(bImg.getARGBValue(bgX, bgY));
                int r = ((int) ((int) bPixel.r * m1) + (int) ((int) hPixel.r) * m2) / (int) 255;
                int g = ((int) ((int) bPixel.g * m1) + (int) ((int) hPixel.g) * m2) / (int) 255;
                int b = ((int) ((int) bPixel.b * m1) + (int) ((int) hPixel.b) * m2) / (int) 255;
                bImg.setRGB(bgX, bgY, r, g, b);
            }
        }
    } else if (this.genlock == Genlock.COLOR) {
        for (int i = 0; i < vsize; i++) {
            for (int j = 0; j < hsize; j++) {
                hPixel.setARGBValue(fImg.getARGBValue(sleft + j, stop + i));
                if ((hPixel.r != credA) || (hPixel.g != cgreenA) || (hPixel.b != cblueA)) {
                    int bgX = bgleft + j;
                    int bgY = bgtop + i;
                    int aX = bgX - aleft;
                    int aY = bgY - atop;
                    int mix = aImg.getRValueIgnoreBounds(aX, aY);
                    int m1 = 255 - mix;
                    int m2 = mix;
                    bPixel.setARGBValue(bImg.getARGBValue(bgX, bgY));
                    int r = ((int) ((int) bPixel.r * m1) + (int) ((int) hPixel.r) * m2) / (int) 255;
                    int g = ((int) ((int) bPixel.g * m1) + (int) ((int) hPixel.g) * m2) / (int) 255;
                    int b = ((int) ((int) bPixel.b * m1) + (int) ((int) hPixel.b) * m2) / (int) 255;
                    bImg.setRGB(bgX, bgY, r, g, b);
                }
            }
        }
    } else if (this.genlock == Genlock.IN_RANGE) {
        for (int i = 0; i < vsize; i++) {
            for (int j = 0; j < hsize; j++) {
                hPixel.setARGBValue(fImg.getARGBValue(sleft + j, stop + i));
                if (((hPixel.r < credA) || (hPixel.r > credB)) && ((hPixel.g < cgreenA) || (hPixel.g > cgreenB)) && ((hPixel.b < cblueA) || (hPixel.b > cblueB))) {
                    int bgX = bgleft + j;
                    int bgY = bgtop + i;
                    int aX = bgX - aleft;
                    int aY = bgY - atop;
                    int mix = aImg.getRValueIgnoreBounds(aX, aY);
                    int m1 = 255 - mix;
                    int m2 = mix;
                    bPixel.setARGBValue(bImg.getARGBValue(bgX, bgY));
                    int r = ((int) ((int) bPixel.r * m1) + (int) ((int) hPixel.r) * m2) / (int) 255;
                    int g = ((int) ((int) bPixel.g * m1) + (int) ((int) hPixel.g) * m2) / (int) 255;
                    int b = ((int) ((int) bPixel.b * m1) + (int) ((int) hPixel.b) * m2) / (int) 255;
                    bImg.setRGB(bgX, bgY, r, g, b);
                }
            }
        }
    } else if (this.genlock == Genlock.OUT_RANGE) {
        for (int i = 0; i < vsize; i++) {
            for (int j = 0; j < hsize; j++) {
                hPixel.setARGBValue(fImg.getARGBValue(sleft + j, stop + i));
                if (((hPixel.r >= credA) && (hPixel.r <= credB)) && ((hPixel.g >= cgreenA) && (hPixel.g <= cgreenB)) && ((hPixel.b >= cblueA) && (hPixel.b <= cblueB))) {
                    int bgX = bgleft + j;
                    int bgY = bgtop + i;
                    int aX = bgX - aleft;
                    int aY = bgY - atop;
                    int mix = aImg.getRValueIgnoreBounds(aX, aY);
                    int m1 = 255 - mix;
                    int m2 = mix;
                    bPixel.setARGBValue(bImg.getARGBValue(bgX, bgY));
                    int r = ((int) ((int) bPixel.r * m1) + (int) ((int) hPixel.r) * m2) / (int) 255;
                    int g = ((int) ((int) bPixel.g * m1) + (int) ((int) hPixel.g) * m2) / (int) 255;
                    int b = ((int) ((int) bPixel.b * m1) + (int) ((int) hPixel.b) * m2) / (int) 255;
                    bImg.setRGB(bgX, bgY, r, g, b);
                }
            }
        }
    }
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) Pixel(org.jwildfire.image.Pixel)

Example 43 with Pixel

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

the class AlphaTransformer method performPixelTransformation.

@Override
protected void performPixelTransformation(WFImage pImg) {
    SimpleImage img = (SimpleImage) pImg;
    /* generate the op-table (op[value][alpha]*/
    int[][] optable = new int[256][256];
    for (int i = 0; i < 256; i++) {
        for (int j = 0; j < 256; j++) {
            int val = i * (j + 1) + (int) 128;
            val /= (int) 256;
            optable[i][j] = Tools.limitColor(val);
        }
    }
    SimpleImage alpha = this.alphaChannel.getImage();
    int awidth = alpha.getImageWidth();
    int aheight = alpha.getImageHeight();
    int bgwidth = pImg.getImageWidth();
    int bgheight = pImg.getImageHeight();
    int hsize = 0, vsize = 0;
    int bgleft = 0, bgtop = 0;
    int aleft = 0, atop = 0;
    /* case 1 */
    if ((left >= 0) && (top >= 0)) {
        if ((left >= bgwidth) || (top >= bgheight))
            return;
        hsize = bgwidth - left;
        if (hsize > awidth)
            hsize = awidth;
        vsize = bgheight - top;
        if (vsize > aheight)
            vsize = aheight;
        bgtop = top;
        bgleft = left;
        aleft = 0;
        atop = 0;
    } else /* case 2 */
    if ((left < 0) && (top >= 0)) {
        if ((left <= (0 - awidth)) || (top >= bgheight))
            return;
        hsize = awidth + left;
        if (hsize > bgwidth)
            hsize = bgwidth;
        vsize = bgheight - top;
        if (vsize > aheight)
            vsize = aheight;
        bgtop = top;
        bgleft = 0;
        atop = 0;
        aleft = 0 - left;
    } else /* case 3 */
    if ((left >= 0) && (top < 0)) {
        if ((left >= bgwidth) || (top <= (0 - aheight)))
            return;
        hsize = bgwidth - left;
        if (hsize > awidth)
            hsize = awidth;
        vsize = aheight + top;
        if (vsize > bgheight)
            vsize = bgheight;
        bgtop = 0;
        bgleft = left;
        atop = 0 - top;
        aleft = 0;
    } else /* case 4 */
    if ((left < 0) && (top < 0)) {
        if ((left <= (0 - awidth)) || (top <= (0 - aheight)))
            return;
        hsize = awidth + left;
        if (hsize > bgwidth)
            hsize = bgwidth;
        vsize = aheight + top;
        if (vsize > bgheight)
            vsize = bgheight;
        bgtop = 0;
        bgleft = 0;
        atop = 0 - top;
        aleft = 0 - left;
    }
    img.fillBackground(0, 0, 0);
    Pixel pixel = new Pixel();
    for (int i = 0; i < vsize; i++) {
        for (int j = 0; j < hsize; j++) {
            int x = j + bgleft;
            int y = i + bgtop;
            pixel.setARGBValue(srcImg.getARGBValue(x, y));
            int a = alpha.getRValue(j + aleft, i + atop);
            pixel.r = optable[pixel.r][a];
            pixel.g = optable[pixel.g][a];
            pixel.b = optable[pixel.b][a];
            img.setRGB(x, y, pixel);
        }
    }
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) Pixel(org.jwildfire.image.Pixel)

Example 44 with Pixel

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

the class BalancingTransformer method performPixelTransformation.

@Override
protected void performPixelTransformation(WFImage pImg) {
    SimpleImage img = (SimpleImage) pImg;
    int width = pImg.getImageWidth();
    int height = pImg.getImageHeight();
    final double brMAX = 256.0;
    Pixel pixel = new Pixel();
    /* saturation */
    if (this.saturation != 0) {
        int rs = 2990;
        int gs = 5880;
        int bs = 1130;
        rs = (rs * Tools.VPREC) / 10000;
        gs = (gs * Tools.VPREC) / 10000;
        bs = (bs * Tools.VPREC) / 10000;
        int scl = (int) ((double) this.saturation / 255.0 * 1024.0 + 0.5);
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < width; j++) {
                pixel.setARGBValue(img.getARGBValue(j, i));
                int avg = (rs * pixel.r + gs * pixel.g + bs * pixel.b) >> Tools.SPREC;
                pixel.r += ((pixel.r - avg) * scl) >> Tools.SPREC;
                if (pixel.r < 0)
                    pixel.r = 0;
                else if (pixel.r > 255)
                    pixel.r = 255;
                pixel.g += ((pixel.g - avg) * scl) >> Tools.SPREC;
                if (pixel.g < 0)
                    pixel.g = 0;
                else if (pixel.g > 255)
                    pixel.g = 255;
                pixel.b += ((pixel.b - avg) * scl) >> Tools.SPREC;
                if (pixel.b < 0)
                    pixel.b = 0;
                else if (pixel.b > 255)
                    pixel.b = 255;
                img.setRGB(j, i, pixel);
            }
        }
    }
    /* gamma */
    if (this.gamma != 0) {
        double max = 255.0;
        double g = (double) 512.0 / (512.0 + (double) this.gamma);
        int[] gamma = new int[256];
        double da, aa;
        da = aa = 1.0 / 255.0;
        gamma[0] = 0;
        for (int i = 1; i < 256; i++) {
            int val = (int) (max * Math.pow(aa, g) + 0.5);
            aa += da;
            gamma[i] = val;
        }
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < width; j++) {
                pixel.setARGBValue(img.getARGBValue(j, i));
                pixel.r = gamma[pixel.r];
                pixel.g = gamma[pixel.g];
                pixel.b = gamma[pixel.b];
                img.setRGB(j, i, pixel);
            }
        }
    }
    /* red */
    if (this.red != 0) {
        int tt = (int) ((double) this.red / (double) brMAX * (double) 255.0 + 0.5);
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < width; j++) {
                pixel.setARGBValue(img.getARGBValue(j, i));
                pixel.r += tt;
                if (pixel.r < 0)
                    pixel.r = 0;
                else if (pixel.r > 255)
                    pixel.r = 255;
                img.setRGB(j, i, pixel);
            }
        }
    }
    /* green */
    if (this.green != 0) {
        int tt = (int) ((double) this.green / (double) brMAX * (double) 255.0 + 0.5);
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < width; j++) {
                pixel.setARGBValue(img.getARGBValue(j, i));
                pixel.g += tt;
                if (pixel.g < 0)
                    pixel.g = 0;
                else if (pixel.g > 255)
                    pixel.g = 255;
                img.setRGB(j, i, pixel);
            }
        }
    }
    /* blue */
    if (this.blue != 0) {
        int tt = (int) ((double) this.blue / (double) brMAX * (double) 255.0 + 0.5);
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < width; j++) {
                pixel.setARGBValue(img.getARGBValue(j, i));
                pixel.b += tt;
                if (pixel.b < 0)
                    pixel.b = 0;
                else if (pixel.b > 255)
                    pixel.b = 255;
                img.setRGB(j, i, pixel);
            }
        }
    }
    /* brightness */
    if (brightness != 0) {
        int tt = (int) ((double) this.brightness / (double) brMAX * (double) 255.0 + 0.5);
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < width; j++) {
                pixel.setARGBValue(img.getARGBValue(j, i));
                pixel.r += tt;
                if (pixel.r < 0)
                    pixel.r = 0;
                else if (pixel.r > 255)
                    pixel.r = 255;
                pixel.g += tt;
                if (pixel.g < 0)
                    pixel.g = 0;
                else if (pixel.g > 255)
                    pixel.g = 255;
                pixel.b += tt;
                if (pixel.b < 0)
                    pixel.b = 0;
                else if (pixel.b > 255)
                    pixel.b = 255;
                img.setRGB(j, i, pixel);
            }
        }
    }
    /* contrast */
    if (this.contrast != 0) {
        double scale = (double) this.contrast / brMAX;
        int sc = (int) (scale * (double) Tools.VPREC + 0.5);
        int dc;
        if (this.contrast > 0) {
            for (int i = 0; i < height; i++) {
                for (int j = 0; j < width; j++) {
                    pixel.setARGBValue(img.getARGBValue(j, i));
                    dc = (int) (((int) (pixel.r - (int) 127) * sc) >> Tools.SPREC);
                    if (dc < (-255))
                        dc = (-255);
                    else if (dc > 255)
                        dc = 255;
                    pixel.r += dc;
                    if (pixel.r < 0)
                        pixel.r = 0;
                    else if (pixel.r > 255)
                        pixel.r = 255;
                    dc = (int) (((int) (pixel.g - (int) 127) * sc) >> Tools.SPREC);
                    if (dc < (-255))
                        dc = (-255);
                    else if (dc > 255)
                        dc = 255;
                    pixel.g += dc;
                    if (pixel.g < 0)
                        pixel.g = 0;
                    else if (pixel.g > 255)
                        pixel.g = 255;
                    dc = (int) ((int) ((pixel.b - (int) 127) * sc) >> Tools.SPREC);
                    if (dc < (-255))
                        dc = (-255);
                    else if (dc > 255)
                        dc = 255;
                    pixel.b += dc;
                    if (pixel.b < 0)
                        pixel.b = 0;
                    else if (pixel.b > 255)
                        pixel.b = 255;
                    img.setRGB(j, i, pixel);
                }
            }
        } else {
            int val;
            for (int i = 0; i < height; i++) {
                for (int j = 0; j < width; j++) {
                    pixel.setARGBValue(img.getARGBValue(j, i));
                    dc = (int) (((int) ((int) pixel.r - (int) 127) * sc) >> Tools.SPREC);
                    if (dc < (-255))
                        dc = (-255);
                    else if (dc > 255)
                        dc = 255;
                    val = pixel.r + dc;
                    if (pixel.r < 127) {
                        if (val > 127)
                            val = 127;
                    } else {
                        if (val < 127)
                            val = 127;
                    }
                    pixel.r = val;
                    dc = (int) ((int) ((pixel.g - (int) 127) * sc) >> Tools.SPREC);
                    if (dc < (-255))
                        dc = (-255);
                    else if (dc > 255)
                        dc = 255;
                    val = pixel.g + dc;
                    if (pixel.g < 127) {
                        if (val > 127)
                            val = 127;
                    } else {
                        if (val < 127)
                            val = 127;
                    }
                    pixel.g = val;
                    dc = (int) ((int) ((pixel.b - (int) 127) * sc) >> Tools.SPREC);
                    if (dc < (-255))
                        dc = (-255);
                    else if (dc > 255)
                        dc = 255;
                    val = pixel.b + dc;
                    if (pixel.b < 127) {
                        if (val > 127)
                            val = 127;
                    } else {
                        if (val < 127)
                            val = 127;
                    }
                    pixel.b = val;
                    img.setRGB(j, i, pixel);
                }
            }
        }
    }
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) Pixel(org.jwildfire.image.Pixel)

Example 45 with Pixel

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

the class BumpTransformer method performPixelTransformation.

@Override
protected void performPixelTransformation(WFImage pImg) {
    SimpleImage img = (SimpleImage) pImg;
    int intensity = (int) (this.intensity * (double) VPREC + 0.5);
    int amount = (int) (this.amount * (double) VPREC + 0.5);
    int left = this.left;
    int top = this.top;
    int width = pImg.getImageWidth();
    int height = pImg.getImageHeight();
    Buffer heightMapBuffer = this.heightMap;
    SimpleImage heightMap = heightMapBuffer.getImage();
    int bwidth = heightMap.getImageWidth();
    int bheight = heightMap.getImageHeight();
    /* compute the light-vector */
    int plCosA, lvx, lvy, lvz;
    {
        double lx = 0.0 - (double) lightX;
        double ly = 0.0 - (double) lightY;
        double lz = (double) 0.0 - (double) lightZ;
        double r = Math.sqrt(lx * lx + ly * ly + lz * lz);
        if (r != (float) 0.0) {
            lx /= r;
            ly /= r;
            lz /= r;
        } else {
            lx = (double) 0.0;
            ly = (double) 0.0;
            lz = (double) 1.0;
        }
        lvx = (int) (lx * (double) VPREC + 0.5);
        lvy = (int) (ly * (double) VPREC + 0.5);
        lvz = (int) (lz * (double) VPREC + 0.5);
        int nz = 0 - VPREC;
        int nx = 0;
        int ny = 0;
        plCosA = ((lvx * nx + VPREC2) >> SPREC) + ((lvy * ny + VPREC2) >> SPREC) + ((lvz * nz + VPREC2) >> SPREC);
        plCosA = (plCosA * intensity + VPREC2) >> SPREC;
        if (plCosA < 0)
            plCosA = 0 - plCosA;
        else
            plCosA = 0;
    }
    int x1 = -VPREC;
    int y1 = -VPREC;
    int x2 = VPREC;
    int y2 = -VPREC;
    int x3 = -VPREC;
    int y3 = VPREC;
    int x4 = VPREC;
    int y4 = VPREC;
    int x5 = 0;
    int y5 = 0;
    int a1x = x5 - x1;
    int a1y = y5 - y1;
    int b1x = x5 - x2;
    int b1y = y5 - y2;
    int a2x = x5 - x2;
    int a2y = y5 - y2;
    int b2x = x5 - x4;
    int b2y = y5 - y4;
    int a3x = x5 - x4;
    int a3y = y5 - y4;
    int b3x = x5 - x3;
    int b3y = y5 - y3;
    int a4x = x5 - x3;
    int a4y = y5 - y3;
    int b4x = x5 - x1;
    int b4y = y5 - y1;
    Pixel sPixel = new Pixel();
    Pixel hPixel = new Pixel();
    Pixel hLUPixel = new Pixel();
    Pixel hRUPixel = new Pixel();
    Pixel hLBPixel = new Pixel();
    Pixel hRBPixel = new Pixel();
    for (int i = 0; i < height; i++) {
        int biy = i - top;
        for (int j = 0; j < width; j++) {
            int bix = j - left;
            int z1, z2, z3, z4, z5;
            if ((bix >= 0) && (bix < bwidth) && (biy >= 0) && (biy < bheight)) {
                hPixel.setARGBValue(heightMap.getARGBValue(bix, biy));
                hLUPixel.setARGBValue(heightMap.getARGBValueIgnoreBounds(bix - 1, biy - 1));
                hRUPixel.setARGBValue(heightMap.getARGBValueIgnoreBounds(bix + 1, biy - 1));
                hLBPixel.setARGBValue(heightMap.getARGBValueIgnoreBounds(bix - 1, biy + 1));
                hRBPixel.setARGBValue(heightMap.getARGBValueIgnoreBounds(bix + 1, biy + 1));
                z5 = 0 - ((int) (hPixel.r) << SPREC) / 255;
                if (biy > 0) {
                    if (bix > 0)
                        z1 = 0 - ((int) (hLUPixel.r) << SPREC) / 255;
                    else
                        z1 = 0;
                    if (bix < (width - 2))
                        z2 = 0 - ((int) (hRUPixel.r) << SPREC) / 255;
                    else
                        z2 = 0;
                } else {
                    z1 = z2 = 0;
                }
                if (biy < (bheight - 1)) {
                    if (bix > 0)
                        z3 = 0 - ((int) (hLBPixel.r) << SPREC) / 255;
                    else
                        z3 = 0;
                    if (bix < (width - 1))
                        z4 = 0 - ((int) (hRBPixel.r) << SPREC) / 255;
                    else
                        z4 = 0;
                } else {
                    z3 = z4 = 0;
                }
            } else {
                z1 = z2 = z3 = z4 = z5 = 0;
            }
            z1 = (z1 * amount + VPREC2) >> SPREC;
            z2 = (z2 * amount + VPREC2) >> SPREC;
            z3 = (z3 * amount + VPREC2) >> SPREC;
            z4 = (z4 * amount + VPREC2) >> SPREC;
            z5 = (z5 * amount + VPREC2) >> SPREC;
            int a1z = z5 - z1;
            int b1z = z5 - z2;
            int a2z = z5 - z2;
            int b2z = z5 - z4;
            int a3z = z5 - z4;
            int b3z = z5 - z3;
            int a4z = z5 - z3;
            int b4z = z5 - z1;
            /* triangle 1 */
            int nx = (((a1y + VPREC2) >> SPREC) * b1z) - (((a1z + VPREC2) >> SPREC) * b1y);
            int ny = (((a1z + VPREC2) >> SPREC) * b1x) - (((a1x + VPREC2) >> SPREC) * b1z);
            int nz = (((a1x + VPREC2) >> SPREC) * b1y) - (((a1y + VPREC2) >> SPREC) * b1x);
            int dr = (((nx + VPREC2) >> SPREC) * nx) + (((ny + VPREC2) >> SPREC) * ny) + (((nz + VPREC2) >> SPREC) * nz);
            /*   #ifdef PPC
           ff=sqrt((float)dr);dr=(int)(ff*32.0+0.5);
           #else
           dr=wfm->iSqrt(dr);
           #endif*/
            dr = iSqrt(dr);
            if (dr != 0) {
                nx = ((nx << SPREC) + VPREC2) / dr;
                ny = ((ny << SPREC) + VPREC2) / dr;
                nz = ((nz << SPREC) + VPREC2) / dr;
            } else {
                nz = -VPREC;
                nx = ny = 0;
            }
            int lCosA = ((lvx * nx + VPREC2) >> SPREC) + ((lvy * ny + VPREC2) >> SPREC) + ((lvz * nz + VPREC2) >> SPREC);
            lCosA = (lCosA * intensity + VPREC2) >> SPREC;
            if (lCosA < 0)
                lCosA = 0;
            int lc1 = lCosA;
            /* triangle 2 */
            nx = (((a2y + VPREC2) >> SPREC) * b2z) - (((a2z + VPREC2) >> SPREC) * b2y);
            ny = (((a2z + VPREC2) >> SPREC) * b2x) - (((a2x + VPREC2) >> SPREC) * b2z);
            nz = (((a2x + VPREC2) >> SPREC) * b2y) - (((a2y + VPREC2) >> SPREC) * b2x);
            dr = (((nx + VPREC2) >> SPREC) * nx) + (((ny + VPREC2) >> SPREC) * ny) + (((nz + VPREC2) >> SPREC) * nz);
            /*   #ifdef PPC
           ff=sqrt((float)dr);dr=(int)(ff*32.0+0.5);
           #else
           dr=wfm->iSqrt(dr);
           #endif     */
            dr = iSqrt(dr);
            if (dr != 0) {
                nx = ((nx << SPREC) + VPREC2) / dr;
                ny = ((ny << SPREC) + VPREC2) / dr;
                nz = ((nz << SPREC) + VPREC2) / dr;
            } else {
                nz = -VPREC;
                nx = ny = 0;
            }
            lCosA = ((lvx * nx + VPREC2) >> SPREC) + ((lvy * ny + VPREC2) >> SPREC) + ((lvz * nz + VPREC2) >> SPREC);
            lCosA = (lCosA * intensity + VPREC2) >> SPREC;
            if (lCosA < 0)
                lCosA = 0;
            int lc2 = lCosA;
            /* triangle 3 */
            nx = (((a3y + VPREC2) >> SPREC) * b3z) - (((a3z + VPREC2) >> SPREC) * b3y);
            ny = (((a3z + VPREC2) >> SPREC) * b3x) - (((a3x + VPREC2) >> SPREC) * b3z);
            nz = (((a3x + VPREC2) >> SPREC) * b3y) - (((a3y + VPREC2) >> SPREC) * b3x);
            dr = (((nx + VPREC2) >> SPREC) * nx) + (((ny + VPREC2) >> SPREC) * ny) + (((nz + VPREC2) >> SPREC) * nz);
            /*   #ifdef PPC
           ff=sqrt((float)dr);dr=(int)(ff*32.0+0.5);
           #else
           dr=wfm->iSqrt(dr);
           #endif*/
            dr = iSqrt(dr);
            if (dr != 0) {
                nx = ((nx << SPREC) + VPREC2) / dr;
                ny = ((ny << SPREC) + VPREC2) / dr;
                nz = ((nz << SPREC) + VPREC2) / dr;
            } else {
                nz = -VPREC;
                nx = ny = 0;
            }
            lCosA = ((lvx * nx + VPREC2) >> SPREC) + ((lvy * ny + VPREC2) >> SPREC) + ((lvz * nz + VPREC2) >> SPREC);
            lCosA = (lCosA * intensity + VPREC2) >> SPREC;
            if (lCosA < 0)
                lCosA = 0;
            int lc3 = lCosA;
            /* triangle 4 */
            nx = (((a4y + VPREC2) >> SPREC) * b4z) - (((a4z + VPREC2) >> SPREC) * b4y);
            ny = (((a4z + VPREC2) >> SPREC) * b4x) - (((a4x + VPREC2) >> SPREC) * b4z);
            nz = (((a4x + VPREC2) >> SPREC) * b4y) - (((a4y + VPREC2) >> SPREC) * b4x);
            dr = (((nx + VPREC2) >> SPREC) * nx) + (((ny + VPREC2) >> SPREC) * ny) + (((nz + VPREC2) >> SPREC) * nz);
            /*   #ifdef PPC
           ff=sqrt((float)dr);dr=(int)(ff*32.0+0.5);
           #else
           dr=wfm->iSqrt(dr);
           #endif*/
            dr = iSqrt(dr);
            if (dr != 0) {
                nx = ((nx << SPREC) + VPREC2) / dr;
                ny = ((ny << SPREC) + VPREC2) / dr;
                nz = ((nz << SPREC) + VPREC2) / dr;
            } else {
                nz = -VPREC;
                nx = ny = 0;
            }
            lCosA = ((lvx * nx + VPREC2) >> SPREC) + ((lvy * ny + VPREC2) >> SPREC) + ((lvz * nz + VPREC2) >> SPREC);
            lCosA = (lCosA * intensity + VPREC2) >> SPREC;
            if (lCosA < 0)
                lCosA = 0;
            int lc4 = lCosA;
            sPixel.setARGBValue(img.getARGBValue(j, i));
            int rv4, rv3, rv2, rv1;
            rv4 = rv3 = rv2 = rv1 = sPixel.r;
            int gv4, gv3, gv2, gv1;
            gv4 = gv3 = gv2 = gv1 = sPixel.g;
            int bv4, bv3, bv2, bv1;
            bv4 = bv3 = bv2 = bv1 = sPixel.b;
            rv1 = ((int) rv1 * lc1 + VPREC2) >> SPREC;
            gv1 = ((int) gv1 * lc1 + VPREC2) >> SPREC;
            bv1 = ((int) bv1 * lc1 + VPREC2) >> SPREC;
            rv2 = ((int) rv2 * lc2 + VPREC2) >> SPREC;
            gv2 = ((int) gv2 * lc2 + VPREC2) >> SPREC;
            bv2 = ((int) bv2 * lc2 + VPREC2) >> SPREC;
            rv3 = ((int) rv3 * lc3 + VPREC2) >> SPREC;
            gv3 = ((int) gv3 * lc1 + VPREC2) >> SPREC;
            bv3 = ((int) bv3 * lc3 + VPREC2) >> SPREC;
            rv4 = ((int) rv4 * lc4 + VPREC2) >> SPREC;
            gv4 = ((int) gv4 * lc2 + VPREC2) >> SPREC;
            bv4 = ((int) bv4 * lc4 + VPREC2) >> SPREC;
            int rv = (rv1 + rv2 + rv3 + rv4) >> 2;
            int gv = (gv1 + gv2 + gv3 + gv4) >> 2;
            int bv = (bv1 + bv2 + bv3 + bv4) >> 2;
            if (rv > 255)
                rv = 255;
            if (gv > 255)
                gv = 255;
            if (bv > 255)
                bv = 255;
            img.setRGB(j, i, rv, gv, bv);
        }
    }
}
Also used : Buffer(org.jwildfire.swing.Buffer) SimpleImage(org.jwildfire.image.SimpleImage) Pixel(org.jwildfire.image.Pixel)

Aggregations

Pixel (org.jwildfire.image.Pixel)62 SimpleImage (org.jwildfire.image.SimpleImage)37 RGBColor (org.jwildfire.create.tina.palette.RGBColor)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)3 HSLPixel (org.jwildfire.transform.HSLTransformer.HSLPixel)3 Color (java.awt.Color)2 Graphics2D (java.awt.Graphics2D)2 BufferedImage (java.awt.image.BufferedImage)2 JEPWrapper (org.jwildfire.base.mathparser.JEPWrapper)2 HSLTransformer (org.jwildfire.transform.HSLTransformer)2 Node (org.nfunk.jep.Node)2 SVGDiagram (com.kitfox.svg.SVGDiagram)1 SVGUniverse (com.kitfox.svg.SVGUniverse)1 Graphics (java.awt.Graphics)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 StringReader (java.io.StringReader)1 Writer (java.io.Writer)1