Search in sources :

Example 16 with Pixel

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

the class ComposeTransformer 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();
    Pixel hPixel = new Pixel();
    Pixel bPixel = new Pixel();
    // calculate left and top edge
    int left, top;
    if (hAlign == HAlignment.CENTRE) {
        left = (bImg.getImageWidth() - fImg.getImageWidth()) / 2;
    } else if (hAlign == HAlignment.LEFT) {
        left = 0;
    } else if (hAlign == HAlignment.RIGHT) {
        left = bImg.getImageWidth() - fImg.getImageWidth();
    } else {
        left = this.left;
    }
    if (vAlign == VAlignment.CENTRE) {
        top = (bImg.getImageHeight() - fImg.getImageHeight()) / 2;
    } else if (vAlign == VAlignment.TOP) {
        top = 0;
    } else if (vAlign == VAlignment.BOTTOM) {
        top = bImg.getImageHeight() - fImg.getImageHeight();
    } else {
        top = this.top;
    }
    // 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;
        }
    }
    // 
    int mix = 100 - this.transparency;
    if (mix == 100) {
        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));
                    bImg.setRGB(bgleft + j, bgtop + i, hPixel.r, hPixel.g, hPixel.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)) {
                        bImg.setRGB(bgleft + j, bgtop + i, hPixel.r, hPixel.g, hPixel.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))) {
                        bImg.setRGB(bgleft + j, bgtop + i, hPixel.r, hPixel.g, hPixel.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))) {
                            bImg.setRGB(bgleft + j, bgtop + i, hPixel.r, hPixel.g, hPixel.b);
                        }
                    }
                }
            }
        }
    } else {
        int m1 = 100 - mix;
        int m2 = mix;
        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));
                    bPixel.setARGBValue(bImg.getARGBValue(bgleft + j, bgtop + i));
                    int r = ((int) ((int) bPixel.r * m1) + (int) ((int) hPixel.r) * m2) / (int) 100;
                    int g = ((int) ((int) bPixel.g * m1) + (int) ((int) hPixel.g) * m2) / (int) 100;
                    int b = ((int) ((int) bPixel.b * m1) + (int) ((int) hPixel.b) * m2) / (int) 100;
                    bImg.setRGB(bgleft + j, bgtop + i, 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)) {
                        bPixel.setARGBValue(bImg.getARGBValue(bgleft + j, bgtop + i));
                        int r = ((int) ((int) bPixel.r * m1) + (int) ((int) hPixel.r) * m2) / (int) 100;
                        int g = ((int) ((int) bPixel.g * m1) + (int) ((int) hPixel.g) * m2) / (int) 100;
                        int b = ((int) ((int) bPixel.b * m1) + (int) ((int) hPixel.b) * m2) / (int) 100;
                        bImg.setRGB(bgleft + j, bgtop + i, 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))) {
                        bPixel.setARGBValue(bImg.getARGBValue(bgleft + j, bgtop + i));
                        int r = ((int) ((int) bPixel.r * m1) + (int) ((int) hPixel.r) * m2) / (int) 100;
                        int g = ((int) ((int) bPixel.g * m1) + (int) ((int) hPixel.g) * m2) / (int) 100;
                        int b = ((int) ((int) bPixel.b * m1) + (int) ((int) hPixel.b) * m2) / (int) 100;
                        bImg.setRGB(bgleft + j, bgtop + i, 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))) {
                        bPixel.setARGBValue(bImg.getARGBValue(bgleft + j, bgtop + i));
                        int r = ((int) ((int) bPixel.r * m1) + (int) ((int) hPixel.r) * m2) / (int) 100;
                        int g = ((int) ((int) bPixel.g * m1) + (int) ((int) hPixel.g) * m2) / (int) 100;
                        int b = ((int) ((int) bPixel.b * m1) + (int) ((int) hPixel.b) * m2) / (int) 100;
                        bImg.setRGB(bgleft + j, bgtop + i, r, g, b);
                    }
                }
            }
        }
    }
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) Pixel(org.jwildfire.image.Pixel)

Example 17 with Pixel

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

the class ConvolveTransformer method performPixelTransformation.

@Override
protected void performPixelTransformation(WFImage pImg) {
    SimpleImage img = (SimpleImage) pImg;
    int[][] kernel = getKernel();
    int width = srcImg.getImageWidth();
    int height = srcImg.getImageHeight();
    int m1 = this.transparency;
    int m2 = (100 - this.transparency);
    int kernelSize = kernel.length;
    int halveKernelSize = kernelSize / 2;
    int kernelSum = 0;
    for (int i = 0; i < kernelSize; i++) {
        for (int j = 0; j < kernelSize; j++) {
            kernelSum += kernel[i][j];
        }
    }
    if (kernelSum == 0)
        kernelSum = 1;
    Pixel pixel = new Pixel();
    if (colorMode == ColorMode.GREY) {
        srcImg = srcImg.clone();
        new ColorToGrayTransformer().transformImage(srcImg);
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < width; j++) {
                int intSumR = 0;
                for (int k = 0; k < kernelSize; k++) {
                    int y = i - halveKernelSize + k;
                    addPixels: for (int l = 0; l < kernelSize; l++) {
                        int x = j - halveKernelSize + l;
                        if (x < 0) {
                            switch(this.edgeMode) {
                                case MIRROR:
                                    x = -x;
                                    break;
                                case WRAP:
                                    x += width;
                                    break;
                                case BLACK:
                                    continue addPixels;
                            }
                        } else if (x >= width) {
                            switch(this.edgeMode) {
                                case MIRROR:
                                    x = 2 * width - x - 1;
                                    break;
                                case WRAP:
                                    x -= width;
                                    break;
                                case BLACK:
                                    continue addPixels;
                            }
                        }
                        if (y < 0) {
                            switch(this.edgeMode) {
                                case MIRROR:
                                    y = -y;
                                    break;
                                case WRAP:
                                    y += height;
                                    break;
                                case BLACK:
                                    continue addPixels;
                            }
                        } else if (y >= height) {
                            switch(this.edgeMode) {
                                case MIRROR:
                                    y = 2 * height - y - 1;
                                    break;
                                case WRAP:
                                    y -= height;
                                    break;
                                case BLACK:
                                    continue addPixels;
                            }
                        }
                        intSumR += srcImg.getRValue(x, y) * kernel[k][l];
                    }
                }
                intSumR = Tools.limitColor((intSumR / kernelSum) + this.bias);
                if (this.transparency == 0) {
                    img.setRGB(j, i, intSumR, intSumR, intSumR);
                } else {
                    pixel.setARGBValue(srcImg.getARGBValue(j, i));
                    int rval = Tools.limitColor(((pixel.r * m1 + intSumR * m2) / 100));
                    img.setRGB(j, i, rval, rval, rval);
                }
            }
        }
    } else {
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < width; j++) {
                int intSumR = 0;
                int intSumG = 0;
                int intSumB = 0;
                for (int k = 0; k < kernelSize; k++) {
                    int y = i - halveKernelSize + k;
                    addPixels: for (int l = 0; l < kernelSize; l++) {
                        int x = j - halveKernelSize + l;
                        if (x < 0) {
                            switch(this.edgeMode) {
                                case MIRROR:
                                    x = -x;
                                    break;
                                case WRAP:
                                    x += width;
                                    break;
                                case BLACK:
                                    continue addPixels;
                            }
                        } else if (x >= width) {
                            switch(this.edgeMode) {
                                case MIRROR:
                                    x = 2 * width - x - 1;
                                    break;
                                case WRAP:
                                    x -= width;
                                    break;
                                case BLACK:
                                    continue addPixels;
                            }
                        }
                        if (y < 0) {
                            switch(this.edgeMode) {
                                case MIRROR:
                                    y = -y;
                                    break;
                                case WRAP:
                                    y += height;
                                    break;
                                case BLACK:
                                    continue addPixels;
                            }
                        } else if (y >= height) {
                            switch(this.edgeMode) {
                                case MIRROR:
                                    y = 2 * height - y - 1;
                                    break;
                                case WRAP:
                                    y -= height;
                                    break;
                                case BLACK:
                                    continue addPixels;
                            }
                        }
                        pixel.setARGBValue(srcImg.getARGBValue(x, y));
                        intSumR += pixel.r * kernel[k][l];
                        intSumG += pixel.g * kernel[k][l];
                        intSumB += pixel.b * kernel[k][l];
                    }
                }
                intSumR = Tools.limitColor((intSumR / kernelSum) + this.bias);
                intSumG = Tools.limitColor((intSumG / kernelSum) + this.bias);
                intSumB = Tools.limitColor((intSumB / kernelSum) + this.bias);
                if (this.transparency == 0) {
                    img.setRGB(j, i, intSumR, intSumG, intSumB);
                } else {
                    pixel.setARGBValue(srcImg.getARGBValue(j, i));
                    int rval = Tools.limitColor(((pixel.r * m1 + intSumR * m2) / 100));
                    int gval = Tools.limitColor(((pixel.g * m1 + intSumG * m2) / 100));
                    int bval = Tools.limitColor(((pixel.b * m1 + intSumB * m2) / 100));
                    img.setRGB(j, i, rval, gval, bval);
                }
            }
        }
    }
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) Pixel(org.jwildfire.image.Pixel)

Example 18 with Pixel

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

the class DisplaceMapTransformer method performPixelTransformation.

@Override
protected void performPixelTransformation(WFImage pImg) {
    if ((Math.abs(this.amount) < MathLib.EPSILON) || ((displaceXMap == null) && (displaceYMap == null)))
        return;
    SimpleImage img = (SimpleImage) pImg;
    double nAmount = this.amount / 127.5;
    double rZoom = 1.0 / this.zoom;
    int width = pImg.getImageWidth();
    int height = pImg.getImageHeight();
    SimpleImage xMap = (displaceXMap != null) ? displaceXMap.getImage() : null;
    SimpleImage yMap = (displaceYMap != null) ? displaceYMap.getImage() : null;
    Pixel pPixel = new Pixel();
    double w1 = (double) width - 1.0;
    double h1 = (double) height - 1.0;
    double cx = (double) width / 2.0;
    double cy = (double) height / 2.0;
    for (int pY = 0; pY < height; pY++) {
        for (int pX = 0; pX < width; pX++) {
            double x0 = pX - cx;
            double y0 = pY - cy;
            double dX, dY;
            if (xMap == null)
                dX = 0.0;
            else
                dX = (double) (xMap.getRValueIgnoreBounds(pX, pY) - 127.5) * nAmount;
            if (yMap == null)
                dY = 0.0;
            else
                dY = (double) (yMap.getGValueIgnoreBounds(pX, pY) - 127.5) * nAmount;
            double x = cx + (x0 + dX) * rZoom;
            double y = cy + (y0 + dY) * rZoom;
            /* render it */
            double xi = Tools.fmod33(x);
            double yi = Tools.fmod33(y);
            if ((x < 0.0) || (x > w1) || (y < 0.0) || (y > h1)) {
                pPixel.r = pPixel.g = pPixel.b = 0;
            } else {
                readSrcPixels(x, y);
                pPixel.r = roundColor(((1.0 - yi) * ((1.0 - xi) * (srcP.r) + xi * (srcQ.r)) + yi * ((1.0 - xi) * (srcR.r) + xi * (srcS.r))));
                pPixel.g = roundColor(((1.0 - yi) * ((1.0 - xi) * (srcP.g) + xi * (srcQ.g)) + yi * ((1.0 - xi) * (srcR.g) + xi * (srcS.g))));
                pPixel.b = roundColor(((1.0 - yi) * ((1.0 - xi) * (srcP.b) + xi * (srcQ.b)) + yi * ((1.0 - xi) * (srcR.b) + xi * (srcS.b))));
            }
            img.setRGB(pX, pY, pPixel.r, pPixel.g, pPixel.b);
        }
    }
    applySmoothing(img, 3);
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) Pixel(org.jwildfire.image.Pixel)

Example 19 with Pixel

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

the class DisplaceTransformer method performPixelTransformation.

@Override
protected void performPixelTransformation(WFImage pImg) {
    SimpleImage img = (SimpleImage) pImg;
    int width = pImg.getImageWidth();
    int height = pImg.getImageHeight();
    int probability = this.probability;
    int rrad = this.radius;
    srand123(seed);
    Pixel sPixel = new Pixel();
    if (probability == 100) {
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < width; j++) {
                sPixel.setARGBValue(img.getARGBValue(j, i));
                int sr = sPixel.r;
                int sg = sPixel.g;
                int sb = sPixel.b;
                int dx = (int) (rrad * drand() + 0.5);
                int dy = (int) (rrad * drand() + 0.5);
                int px = j + dx;
                int py = i + dy;
                if (px < 0)
                    px = 0;
                else if (px >= width)
                    px = width - 1;
                if (py < 0)
                    py = 0;
                else if (py >= height)
                    py = height - 1;
                sPixel.setARGBValue(img.getARGBValue(px, py));
                int rp = sPixel.r;
                int gp = sPixel.g;
                int bp = sPixel.b;
                img.setRGB(j, i, rp, gp, bp);
                img.setRGB(px, py, sr, sg, sb);
            }
        }
    } else {
        double rprob = (double) ((double) 1.0 - (double) probability / (double) 100.0);
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < width; j++) {
                sPixel.setARGBValue(img.getARGBValue(j, i));
                int sr = sPixel.r;
                int sg = sPixel.g;
                int sb = sPixel.b;
                if (drand() >= rprob) {
                    int dx = (int) (rrad * drand() + 0.5);
                    int dy = (int) (rrad * drand() + 0.5);
                    int px = j + dx;
                    int py = i + dy;
                    if (px < 0)
                        px = 0;
                    else if (px >= width)
                        px = width - 1;
                    if (py < 0)
                        py = 0;
                    else if (py >= height)
                        py = height - 1;
                    sPixel.setARGBValue(img.getARGBValue(px, py));
                    int rp = sPixel.r;
                    int gp = sPixel.g;
                    int bp = sPixel.b;
                    img.setRGB(j, i, rp, gp, bp);
                    img.setRGB(px, py, sr, sg, sb);
                }
            }
        }
    }
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) Pixel(org.jwildfire.image.Pixel)

Example 20 with Pixel

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

the class ErodeTransformer method performPixelTransformation.

@Override
protected void performPixelTransformation(WFImage pImg) {
    if (this.size <= 1)
        return;
    SimpleImage img = (SimpleImage) pImg;
    Tools.srand123(this.seed);
    int width = pImg.getImageWidth();
    int height = pImg.getImageHeight();
    short[][] shape;
    switch(this.shape) {
        case DIAMOND:
            shape = generateDiamond(this.size);
            break;
        case DISK:
            shape = generateDisk(this.size);
            break;
        case SQUARE:
            shape = generateSquare(this.size);
            break;
        case PLUS:
            shape = generatePlus(this.size);
            break;
        case X:
            shape = generateX(this.size);
            break;
        default:
            shape = generateRandom(this.size);
            break;
    }
    SimpleImage srcGreyImg = null;
    if ((this.mode == Mode.DILATE) || (this.mode == Mode.ERODE) || (this.mode == Mode.NEON)) {
        srcGreyImg = srcImg.clone();
        ColorToGrayTransformer cT = new ColorToGrayTransformer();
        cT.setWeights(ColorToGrayTransformer.Weights.LUMINANCE);
        cT.transformImage(srcGreyImg);
    }
    switch(mode) {
        case ERODE:
            for (int i = 0; i < height; i++) {
                for (int j = 0; j < width; j++) {
                    int lumMin = srcGreyImg.getRValue(j, i);
                    int xLumMin = j;
                    int yLumMin = i;
                    for (int s = 0; s < shape.length; s++) {
                        int x = j + shape[s][0];
                        int y = i + shape[s][1];
                        if ((x >= 0) && (x < width) && (y >= 0) && (y < height)) {
                            int lum = srcGreyImg.getRValue(x, y);
                            if (lum < lumMin) {
                                lumMin = lum;
                                xLumMin = x;
                                yLumMin = y;
                            }
                        }
                    }
                    img.setARGB(j, i, srcImg.getARGBValue(xLumMin, yLumMin));
                }
            }
            break;
        case DILATE:
            for (int i = 0; i < height; i++) {
                for (int j = 0; j < width; j++) {
                    int lumMax = srcGreyImg.getRValue(j, i);
                    int xLumMax = j;
                    int yLumMax = i;
                    for (int s = 0; s < shape.length; s++) {
                        int x = j + shape[s][0];
                        int y = i + shape[s][1];
                        if ((x >= 0) && (x < width) && (y >= 0) && (y < height)) {
                            int lum = srcGreyImg.getRValue(x, y);
                            if (lum > lumMax) {
                                lumMax = lum;
                                xLumMax = x;
                                yLumMax = y;
                            }
                        }
                    }
                    img.setARGB(j, i, srcImg.getARGBValue(xLumMax, yLumMax));
                }
            }
            break;
        case NEON:
            Pixel srcPixel = new Pixel();
            Pixel currPixel = new Pixel();
            for (int i = 0; i < height; i++) {
                for (int j = 0; j < width; j++) {
                    int lumMax = srcGreyImg.getRValue(j, i);
                    int lum0 = lumMax;
                    int xLumMax = j;
                    int yLumMax = i;
                    for (int s = 0; s < shape.length; s++) {
                        int x = j + shape[s][0];
                        int y = i + shape[s][1];
                        if ((x >= 0) && (x < width) && (y >= 0) && (y < height)) {
                            int lum = srcGreyImg.getRValue(x, y);
                            if (lum > lumMax) {
                                lumMax = lum;
                                xLumMax = x;
                                yLumMax = y;
                            }
                        }
                    }
                    int m1 = 30;
                    int m2 = 100 - m1;
                    srcPixel.setARGBValue(srcImg.getARGBValue(xLumMax, yLumMax));
                    currPixel.setARGBValue(srcImg.getARGBValue(j, i));
                    currPixel.r = (srcPixel.r * m1 + currPixel.r * m2) / 100;
                    currPixel.g = (srcPixel.g * m1 + currPixel.g * m2) / 100;
                    currPixel.b = (srcPixel.b * m1 + currPixel.b * m2) / 100;
                    if (Math.abs(lum0 - lumMax) > 50)
                        img.setRGB(j, i, 0, 128, 0);
                // pImg.setARGB(j, i, srcImg.getARGBValue(xLumMax, yLumMax));
                }
            }
            break;
        case OILTRANSFER:
            int[] colorValues = new int[shape.length];
            short[] colorUsed = new short[shape.length];
            for (int i = 0; i < height; i++) {
                for (int j = 0; j < width; j++) {
                    int cCount = 0;
                    for (int s = 0; s < colorUsed.length; s++) colorUsed[s] = 0;
                    for (int s = 0; s < shape.length; s++) {
                        int x = j + shape[s][0];
                        int y = i + shape[s][1];
                        if ((x >= 0) && (x < width) && (y >= 0) && (y < height)) {
                            int color = srcImg.getARGBValue(x, y);
                            boolean found = false;
                            for (short t = 0; t < cCount; t++) {
                                if (colorValues[t] == color) {
                                    colorUsed[t]++;
                                    found = true;
                                    break;
                                }
                            }
                            if (!found) {
                                colorValues[cCount] = color;
                                colorUsed[cCount++] = 1;
                            }
                        }
                    }
                    int color = srcImg.getARGBValue(j, i);
                    int usedMax = 1;
                    for (int t = 0; t < cCount; t++) {
                        if (colorUsed[t] > usedMax) {
                            usedMax = colorUsed[t];
                            color = colorValues[t];
                        }
                    }
                    img.setARGB(j, i, color);
                }
            }
            break;
    }
}
Also used : 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