Search in sources :

Example 76 with SimpleImage

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

the class ShiftLinesTransformer method performPixelTransformation.

@Override
protected void performPixelTransformation(WFImage pImg) {
    SimpleImage img = (SimpleImage) pImg;
    int dx = this.shiftAmount;
    Tools.srand123(this.seed);
    double rprob = (double) ((double) 1.0 - (double) (this.probability) / (double) 100.0);
    double fdx = (double) this.jitterAmount;
    if (axis == Axis.Y) {
        srcImg = srcImg.clone();
        TurnTransformer tT = new TurnTransformer();
        tT.setAngle(TurnTransformer.Angle._90);
        tT.setDirection(TurnTransformer.Direction.RIGHT);
        tT.transformImage(srcImg);
        tT.setAngle(TurnTransformer.Angle._90);
        tT.setDirection(TurnTransformer.Direction.RIGHT);
        tT.transformImage(img);
    }
    shiftLines: {
        int width = pImg.getImageWidth();
        int height = pImg.getImageHeight();
        int[] line = new int[width];
        if (this.jitter == Jitter.OFF) {
            if (dx == 0) {
                break shiftLines;
            }
            int adx2 = dx;
            if (adx2 < 0)
                adx2 = 0 - adx2;
            if (adx2 >= width) {
                img.fillBackground(0, 0, 0);
                break shiftLines;
            }
            int dx2 = dx;
            int sx = width - adx2;
            for (int i = 0; i < height; i++) {
                clearLine(line);
                if (dx2 > 0) {
                    copyLine(line, adx2, srcImg.getLine(i), 0, sx);
                } else {
                    copyLine(line, 0, srcImg.getLine(i), adx2, sx);
                }
                img.setLine(i, line);
                dx2 = 0 - dx2;
            }
        } else {
            for (int i = 0; i < height; i++) {
                int dx3;
                if ((probability >= 100) || (Tools.drand() >= rprob)) {
                    dx3 = (int) (Tools.drand() * fdx + 0.5);
                    if (this.jitter == Jitter.POSITIVE) {
                        if (dx3 < 0)
                            dx3 = 0 - dx3;
                    } else if (this.jitter == Jitter.NEGATIVE) {
                        if (dx3 > 0)
                            dx3 = 0 - dx3;
                    } else {
                        if (Tools.drand() > 0.5)
                            dx3 = 0 - dx3;
                    }
                } else
                    dx3 = 0;
                dx3 += this.shiftAmount;
                if (dx3 != 0) {
                    int adx2 = dx3;
                    if (adx2 < 0)
                        adx2 = 0 - adx2;
                    int dx2 = dx3;
                    int sx = width - adx2;
                    clearLine(line);
                    if (adx2 < width) {
                        if (dx2 > 0) {
                            copyLine(line, adx2, srcImg.getLine(i), 0, sx);
                        } else {
                            copyLine(line, 0, srcImg.getLine(i), adx2, sx);
                        }
                    }
                    img.setLine(i, line);
                }
            }
        }
    }
    if (axis == Axis.Y) {
        TurnTransformer tT = new TurnTransformer();
        tT.setAngle(TurnTransformer.Angle._90);
        tT.setDirection(TurnTransformer.Direction.LEFT);
        tT.transformImage(img);
    }
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage)

Example 77 with SimpleImage

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

the class TextTransformer method calculateTextSize.

public Dimension calculateTextSize() {
    SimpleImage img = new SimpleImage(320, 256);
    List<TextRow> rows = getRows();
    if ((rows == null) || (rows.size() < 1))
        return new Dimension(0, 0);
    TextRenderInfo renderInfo = createTextRenderInfo(img, rows);
    return new Dimension(renderInfo.maxWidth, renderInfo.areaHeight);
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) Dimension(java.awt.Dimension)

Example 78 with SimpleImage

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

the class Mesh3DTransformer method performImageTransformation.

@Override
protected void performImageTransformation(WFImage pImg) {
    Mesh3D lInputMesh3D;
    SimpleImage img = (SimpleImage) pImg;
    if (inputMesh3D == null) {
        lInputMesh3D = new Mesh3D();
        createMeshFromImage(lInputMesh3D, img, quant3D);
    } else {
        lInputMesh3D = inputMesh3D.clone();
    }
    int width = pImg.getImageWidth();
    int height = pImg.getImageHeight();
    transformMesh(lInputMesh3D, width, height);
    if (storeMesh3D) {
        this.outputMesh3D = lInputMesh3D.clone();
        this.outputMesh3D.setLastTransformation(this);
    }
    transform3D(lInputMesh3D, width, height);
    img.fillBackground(0, 0, 0);
    render3D(lInputMesh3D, img);
    applySmoothing(img, smoothing);
    lInputMesh3D = null;
    inputMesh3D = null;
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage)

Example 79 with SimpleImage

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

the class MotionBlurTransformer method performPixelTransformation.

@Override
protected void performPixelTransformation(WFImage pImg) {
    SimpleImage bgImg = (SimpleImage) pImg;
    SimpleImage fgImg = srcImg;
    int bgWidth = bgImg.getImageWidth();
    int bgHeight = bgImg.getImageHeight();
    int x1 = 0, y1 = 0;
    int x2 = this.deltaX;
    int y2 = this.deltaY;
    if ((x2 == 0) && (y2 == 0))
        return;
    int n;
    if (x2 > 0)
        n = x2;
    else
        n = 0 - x2;
    if (y2 > 0)
        n += y2;
    else
        n += 0 - y2;
    n++;
    n *= 2;
    int[] x = new int[n];
    int[] y = new int[n];
    n = Tools.bresenham(x1, y1, x2, y2, x, y);
    int mix = 25;
    int m1 = 100 - mix;
    int m2 = mix;
    for (int k = 1; k < n; k++) {
        int left = x[k];
        int top = y[k];
        /* case 1 */
        int bgLeft = 0, bgTop = 0, fgLeft = 0, fgTop = 0;
        int hSize = 0, vSize = 0;
        if ((left >= 0) && (top >= 0)) {
            if ((left >= bgWidth) || (top >= bgHeight))
                return;
            hSize = bgWidth - left;
            if (hSize > bgWidth)
                hSize = bgWidth;
            vSize = bgHeight - top;
            if (vSize > bgHeight)
                vSize = bgHeight;
            bgLeft = left;
            bgTop = top;
            fgLeft = 0;
            fgTop = 0;
        } else /* case 2 */
        if ((left < 0) && (top >= 0)) {
            if ((left <= (0 - bgWidth)) || (top >= bgHeight))
                return;
            hSize = bgWidth + left;
            if (hSize > bgWidth)
                hSize = bgWidth;
            vSize = bgHeight - top;
            if (vSize > bgHeight)
                vSize = bgHeight;
            bgLeft = 0;
            bgTop = top;
            fgLeft = 0 - left;
            fgTop = 0;
        } else /* case 3 */
        if ((left >= 0) && (top < 0)) {
            if ((left >= bgWidth) || (top <= (0 - bgHeight)))
                return;
            hSize = bgWidth - left;
            if (hSize > bgWidth)
                hSize = bgWidth;
            vSize = bgHeight + top;
            if (vSize > bgHeight)
                vSize = bgHeight;
            bgLeft = left;
            bgTop = 0;
            fgLeft = 0;
            fgTop = 0 - top;
        } else /* case 4 */
        if ((left < 0) && (top < 0)) {
            if ((left <= (0 - bgWidth)) || (top <= (0 - bgHeight)))
                return;
            hSize = bgWidth + left;
            if (hSize > bgWidth)
                hSize = bgWidth;
            vSize = bgHeight + top;
            if (vSize > bgHeight)
                vSize = bgHeight;
            bgLeft = 0;
            bgTop = 0;
            fgTop = 0 - top;
            fgLeft = 0 - left;
        }
        Pixel bgPixel = new Pixel();
        Pixel fgPixel = new Pixel();
        for (int i = 0; i < vSize; i++) {
            for (int j = 0; j < hSize; j++) {
                bgPixel.setARGBValue(bgImg.getARGBValue(j + bgLeft, i + bgTop));
                fgPixel.setARGBValue(fgImg.getARGBValue(j + fgLeft, i + fgTop));
                bgPixel.r = ((int) (bgPixel.r * m1) + (int) (fgPixel.r) * m2) / (int) 100;
                bgPixel.g = ((int) (bgPixel.g * m1) + (int) (fgPixel.g) * m2) / (int) 100;
                bgPixel.b = ((int) (bgPixel.b * m1) + (int) (fgPixel.b) * m2) / (int) 100;
                bgImg.setRGB(j + bgLeft, i + bgTop, bgPixel);
            }
        }
    }
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) Pixel(org.jwildfire.image.Pixel)

Example 80 with SimpleImage

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

the class BalancingGradientTransformer method performPixelTransformation.

@Override
protected void performPixelTransformation(WFImage pImg) {
    SimpleImage img = (SimpleImage) pImg;
    int width = pImg.getImageWidth();
    int height = pImg.getImageHeight();
    int x1 = this.x1;
    int y1 = this.y1;
    int v1 = this.value1;
    int x2 = this.x2;
    int y2 = this.y2;
    int v2 = this.value2;
    double rx = (double) (x2 - x1);
    double ry = (double) (y2 - y1);
    double dv = (double) (v2 - v1);
    double vlen;
    if (this.transition == Transition.PARALLEL)
        vlen = Math.sqrt(rx * rx + ry * ry);
    else
        vlen = this.radius - this.baseRadius;
    if (vlen < 0.0001)
        vlen = 0.0001;
    double vlenq = vlen * vlen;
    Pixel pixel = new Pixel();
    final double brMAX = 256.0;
    switch(this.mode) {
        case RED:
            if (this.transition == Transition.PARALLEL) {
                for (int i = 0; i < height; i++) {
                    double ay = (double) (i - y1);
                    for (int j = 0; j < width; j++) {
                        double ax = (double) (j - x1);
                        double prj = (ax * rx + ay * ry) / vlenq;
                        if (prj < 0.0)
                            prj = 0.0;
                        else if (prj > 1.0)
                            prj = 1.0;
                        int ival = v1 + (int) (dv * prj + 0.5);
                        int tt = (int) ((double) ival / (double) brMAX * (double) 255.0 + 0.5);
                        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);
                    }
                }
            } else {
                for (int i = 0; i < height; i++) {
                    double ay = (double) (i - y1);
                    for (int j = 0; j < width; j++) {
                        double ax = (double) (j - x1);
                        double prj = (Math.sqrt(ax * ax + ay * ay) - baseRadius) / vlen;
                        if (prj < 0.0)
                            prj = 0.0;
                        else if (prj > 1.0)
                            prj = 1.0;
                        int ival = v1 + (int) (dv * prj + 0.5);
                        int tt = (int) ((double) ival / (double) brMAX * (double) 255.0 + 0.5);
                        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);
                    }
                }
            }
            break;
        case GREEN:
            if (this.transition == Transition.PARALLEL) {
                for (int i = 0; i < height; i++) {
                    double ay = (double) (i - y1);
                    for (int j = 0; j < width; j++) {
                        double ax = (double) (j - x1);
                        double prj = (ax * rx + ay * ry) / vlenq;
                        if (prj < 0.0)
                            prj = 0.0;
                        else if (prj > 1.0)
                            prj = 1.0;
                        int ival = v1 + (int) (dv * prj + 0.5);
                        int tt = (int) ((double) ival / (double) brMAX * (double) 255.0 + 0.5);
                        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);
                    }
                }
            } else {
                for (int i = 0; i < height; i++) {
                    double ay = (double) (i - y1);
                    for (int j = 0; j < width; j++) {
                        double ax = (double) (j - x1);
                        double prj = (Math.sqrt(ax * ax + ay * ay) - baseRadius) / vlen;
                        if (prj < 0.0)
                            prj = 0.0;
                        else if (prj > 1.0)
                            prj = 1.0;
                        int ival = v1 + (int) (dv * prj + 0.5);
                        int tt = (int) ((double) ival / (double) brMAX * (double) 255.0 + 0.5);
                        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);
                    }
                }
            }
            break;
        case BLUE:
            if (this.transition == Transition.PARALLEL) {
                for (int i = 0; i < height; i++) {
                    double ay = (double) (i - y1);
                    for (int j = 0; j < width; j++) {
                        double ax = (double) (j - x1);
                        double prj = (ax * rx + ay * ry) / vlenq;
                        if (prj < 0.0)
                            prj = 0.0;
                        else if (prj > 1.0)
                            prj = 1.0;
                        int ival = v1 + (int) (dv * prj + 0.5);
                        int tt = (int) ((double) ival / (double) brMAX * (double) 255.0 + 0.5);
                        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);
                    }
                }
            } else {
                for (int i = 0; i < height; i++) {
                    double ay = (double) (i - y1);
                    for (int j = 0; j < width; j++) {
                        double ax = (double) (j - x1);
                        double prj = (Math.sqrt(ax * ax + ay * ay) - baseRadius) / vlen;
                        if (prj < 0.0)
                            prj = 0.0;
                        else if (prj > 1.0)
                            prj = 1.0;
                        int ival = v1 + (int) (dv * prj + 0.5);
                        int tt = (int) ((double) ival / (double) brMAX * (double) 255.0 + 0.5);
                        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);
                    }
                }
            }
            break;
        case BRIGHTNESS:
            if (this.transition == Transition.PARALLEL) {
                for (int i = 0; i < height; i++) {
                    double ay = (double) (i - y1);
                    for (int j = 0; j < width; j++) {
                        double ax = (double) (j - x1);
                        double prj = (ax * rx + ay * ry) / vlenq;
                        if (prj < 0.0)
                            prj = 0.0;
                        else if (prj > 1.0)
                            prj = 1.0;
                        int ival = v1 + (int) (dv * prj + 0.5);
                        int tt = (int) ((double) ival / (double) brMAX * (double) 255.0 + 0.5);
                        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);
                    }
                }
            } else {
                for (int i = 0; i < height; i++) {
                    double ay = (double) (i - y1);
                    for (int j = 0; j < width; j++) {
                        double ax = (double) (j - x1);
                        double prj = (Math.sqrt(ax * ax + ay * ay) - baseRadius) / vlen;
                        if (prj < 0.0)
                            prj = 0.0;
                        else if (prj > 1.0)
                            prj = 1.0;
                        int ival = v1 + (int) (dv * prj + 0.5);
                        int tt = (int) ((double) ival / (double) brMAX * (double) 255.0 + 0.5);
                        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);
                    }
                }
            }
            break;
        case CONTRAST:
            if (this.transition == Transition.PARALLEL) {
                for (int i = 0; i < height; i++) {
                    double ay = (double) (i - y1);
                    for (int j = 0; j < width; j++) {
                        double ax = (double) (j - x1);
                        double prj = (ax * rx + ay * ry) / vlenq;
                        if (prj < 0.0)
                            prj = 0.0;
                        else if (prj > 1.0)
                            prj = 1.0;
                        int ival = v1 + (int) (dv * prj + 0.5);
                        double scale = (double) (ival) / brMAX;
                        int sc = (int) (scale * (double) Tools.VPREC + 0.5);
                        int dc;
                        pixel.setARGBValue(img.getARGBValue(j, i));
                        if (ival > 0) {
                            dc = (int) (((int) (pixel.r - (int) 127) * sc) >> Tools.SPREC);
                            if (dc < (-255))
                                dc = (-255);
                            else if (dc > 255)
                                dc = 255;
                            dc = pixel.r + dc;
                            if (dc < 0)
                                dc = 0;
                            else if (dc > 255)
                                dc = 255;
                            pixel.r = dc;
                            dc = (int) (((int) (pixel.g - (int) 127) * sc) >> Tools.SPREC);
                            if (dc < (-255))
                                dc = (-255);
                            else if (dc > 255)
                                dc = 255;
                            dc = pixel.g + dc;
                            if (dc < 0)
                                dc = 0;
                            else if (dc > 255)
                                dc = 255;
                            pixel.g = dc;
                            dc = (int) ((int) ((pixel.b - (int) 127) * sc) >> Tools.SPREC);
                            if (dc < (-255))
                                dc = (-255);
                            else if (dc > 255)
                                dc = 255;
                            dc = pixel.b + dc;
                            if (dc < 0)
                                dc = 0;
                            else if (dc > 255)
                                dc = 255;
                            pixel.b = dc;
                        } else {
                            int val;
                            dc = (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);
                    }
                }
            } else {
                for (int i = 0; i < height; i++) {
                    double ay = (double) (i - y1);
                    for (int j = 0; j < width; j++) {
                        double ax = (double) (j - x1);
                        double prj = (Math.sqrt(ax * ax + ay * ay) - baseRadius) / vlen;
                        if (prj < 0.0)
                            prj = 0.0;
                        else if (prj > 1.0)
                            prj = 1.0;
                        int ival = v1 + (int) (dv * prj + 0.5);
                        double scale = (double) (ival) / brMAX;
                        int sc = (int) (scale * (double) Tools.VPREC + 0.5);
                        int dc;
                        pixel.setARGBValue(img.getARGBValue(j, i));
                        if (ival > 0) {
                            dc = (int) (((int) (pixel.r - (int) 127) * sc) >> Tools.SPREC);
                            if (dc < (-255))
                                dc = (-255);
                            else if (dc > 255)
                                dc = 255;
                            dc = pixel.r + dc;
                            if (dc < 0)
                                dc = 0;
                            else if (dc > 255)
                                dc = 255;
                            pixel.r = dc;
                            dc = (int) (((int) (pixel.g - (int) 127) * sc) >> Tools.SPREC);
                            if (dc < (-255))
                                dc = (-255);
                            else if (dc > 255)
                                dc = 255;
                            dc = pixel.g + dc;
                            if (dc < 0)
                                dc = 0;
                            else if (dc > 255)
                                dc = 255;
                            pixel.g = dc;
                            dc = (int) ((int) ((pixel.b - (int) 127) * sc) >> Tools.SPREC);
                            if (dc < (-255))
                                dc = (-255);
                            else if (dc > 255)
                                dc = 255;
                            dc = pixel.b + dc;
                            if (dc < 0)
                                dc = 0;
                            else if (dc > 255)
                                dc = 255;
                            pixel.b = dc;
                        } else {
                            int val;
                            dc = (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);
                    }
                }
            }
            break;
        case GAMMA:
            {
                final double max = 255.0;
                if (this.transition == Transition.PARALLEL) {
                    for (int i = 0; i < height; i++) {
                        double ay = (double) (i - y1);
                        for (int j = 0; j < width; j++) {
                            double ax = (double) (j - x1);
                            double prj = (ax * rx + ay * ry) / vlenq;
                            if (prj < 0.0)
                                prj = 0.0;
                            else if (prj > 1.0)
                                prj = 1.0;
                            int ival = v1 + (int) (dv * prj + 0.5);
                            double g = (double) 512.0 / (512.0 + (double) ival);
                            pixel.setARGBValue(img.getARGBValue(j, i));
                            int val;
                            val = pixel.r;
                            if (val == 0)
                                val = 0;
                            else
                                val = (int) (max * Math.pow((double) val / 255.0, g) + 0.5);
                            pixel.r = val;
                            val = pixel.g;
                            if (val == 0)
                                val = 0;
                            else
                                val = (int) (max * Math.pow((double) val / 255.0, g) + 0.5);
                            pixel.g = val;
                            val = pixel.b;
                            if (val == 0)
                                val = 0;
                            else
                                val = (int) (max * Math.pow((double) val / 255.0, g) + 0.5);
                            pixel.b = val;
                            img.setRGB(j, i, pixel);
                        }
                    }
                } else {
                    for (int i = 0; i < height; i++) {
                        double ay = (double) (i - y1);
                        for (int j = 0; j < width; j++) {
                            double ax = (double) (j - x1);
                            double prj = (Math.sqrt(ax * ax + ay * ay) - baseRadius) / vlen;
                            if (prj < 0.0)
                                prj = 0.0;
                            else if (prj > 1.0)
                                prj = 1.0;
                            int ival = v1 + (int) (dv * prj + 0.5);
                            double g = (double) 512.0 / (512.0 + (double) ival);
                            pixel.setARGBValue(img.getARGBValue(j, i));
                            int val;
                            val = pixel.r;
                            if (val == 0)
                                val = 0;
                            else
                                val = (int) (max * Math.pow((double) val / 255.0, g) + 0.5);
                            pixel.r = val;
                            val = pixel.g;
                            if (val == 0)
                                val = 0;
                            else
                                val = (int) (max * Math.pow((double) val / 255.0, g) + 0.5);
                            pixel.g = val;
                            val = pixel.b;
                            if (val == 0)
                                val = 0;
                            else
                                val = (int) (max * Math.pow((double) val / 255.0, g) + 0.5);
                            pixel.b = val;
                            img.setRGB(j, i, pixel);
                        }
                    }
                }
            }
            break;
        case SATURATION:
            {
                int rs = 2990;
                int gs = 5880;
                int bs = 1130;
                rs = (rs * Tools.VPREC) / 10000;
                gs = (gs * Tools.VPREC) / 10000;
                bs = (bs * Tools.VPREC) / 10000;
                if (this.transition == Transition.PARALLEL) {
                    for (int i = 0; i < height; i++) {
                        double ay = (double) (i - y1);
                        for (int j = 0; j < width; j++) {
                            double ax = (double) (j - x1);
                            double prj = (ax * rx + ay * ry) / vlenq;
                            if (prj < 0.0)
                                prj = 0.0;
                            else if (prj > 1.0)
                                prj = 1.0;
                            int ival = v1 + (int) (dv * prj + 0.5);
                            int scl = (int) ((double) ival / 255.0 * 1024.0 + 0.5);
                            pixel.setARGBValue(img.getARGBValue(j, i));
                            int rv = pixel.r;
                            int gv = pixel.g;
                            int bv = pixel.b;
                            int avg = (rs * rv + gs * gv + bs * bv) >> Tools.SPREC;
                            rv += ((rv - avg) * scl) >> Tools.SPREC;
                            if (rv < 0)
                                rv = 0;
                            else if (rv > 255)
                                rv = 255;
                            pixel.r = rv;
                            gv += ((gv - avg) * scl) >> Tools.SPREC;
                            if (gv < 0)
                                gv = 0;
                            else if (gv > 255)
                                gv = 255;
                            pixel.g = gv;
                            bv += ((bv - avg) * scl) >> Tools.SPREC;
                            if (bv < 0)
                                bv = 0;
                            else if (bv > 255)
                                bv = 255;
                            pixel.b = bv;
                            img.setRGB(j, i, pixel);
                        }
                    }
                } else {
                    for (int i = 0; i < height; i++) {
                        double ay = (double) (i - y1);
                        for (int j = 0; j < width; j++) {
                            double ax = (double) (j - x1);
                            double prj = (Math.sqrt(ax * ax + ay * ay) - baseRadius) / vlen;
                            if (prj < 0.0)
                                prj = 0.0;
                            else if (prj > 1.0)
                                prj = 1.0;
                            int ival = v1 + (int) (dv * prj + 0.5);
                            int scl = (int) ((double) ival / 255.0 * 1024.0 + 0.5);
                            pixel.setARGBValue(img.getARGBValue(j, i));
                            int rv = pixel.r;
                            int gv = pixel.g;
                            int bv = pixel.b;
                            int avg = (rs * rv + gs * gv + bs * bv) >> Tools.SPREC;
                            rv += ((rv - avg) * scl) >> Tools.SPREC;
                            if (rv < 0)
                                rv = 0;
                            else if (rv > 255)
                                rv = 255;
                            pixel.r = rv;
                            gv += ((gv - avg) * scl) >> Tools.SPREC;
                            if (gv < 0)
                                gv = 0;
                            else if (gv > 255)
                                gv = 255;
                            pixel.g = gv;
                            bv += ((bv - avg) * scl) >> Tools.SPREC;
                            if (bv < 0)
                                bv = 0;
                            else if (bv > 255)
                                bv = 255;
                            pixel.b = bv;
                            img.setRGB(j, i, pixel);
                        }
                    }
                }
            }
            break;
    }
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) Pixel(org.jwildfire.image.Pixel)

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