Package org.jwildfire.image

Examples of org.jwildfire.image.Pixel


  protected void performPixelTransformation(WFImage pImg) {
    SimpleImage bgImg = (SimpleImage) pImg;
    SimpleImage fgImg = (foregroundImage != null) ? foregroundImage : foreground.getImage();
    if (fgImg == bgImg)
      fgImg = fgImg.clone();
    Pixel fgPixel = new Pixel();
    Pixel bgPixel = new Pixel();
    // calculate left and top edge
    int fgLeft, fgTop;
    int bgWidth = bgImg.getImageWidth();
    int bgHeight = bgImg.getImageHeight();
    int fgWidth = fgImg.getImageWidth();
    int fgHeight = fgImg.getImageHeight();
    if (hAlign == HAlignment.CENTRE) {
      fgLeft = (bgWidth - fgWidth) / 2;
    }
    else if (hAlign == HAlignment.LEFT) {
      fgLeft = 0;
    }
    else if (hAlign == HAlignment.RIGHT) {
      fgLeft = bgWidth - fgWidth;
    }
    else {
      fgLeft = this.left;
    }

    if (vAlign == VAlignment.CENTRE) {
      fgTop = (bgHeight - fgHeight) / 2;
    }
    else if (vAlign == VAlignment.TOP) {
      fgTop = 0;
    }
    else if (vAlign == VAlignment.BOTTOM) {
      fgTop = bgHeight - fgHeight;
    }
    else {
      fgTop = this.top;
    }

    // Initialize the parser
    JEPWrapper parser = new JEPWrapper();
    parser.addVariable("fgR", 0.0);
    parser.addVariable("fgG", 0.0);
    parser.addVariable("fgB", 0.0);
    parser.addVariable("fgWidth", (double) fgWidth);
    parser.addVariable("fgHeight", (double) fgHeight);
    parser.addVariable("bgR", 0.0);
    parser.addVariable("bgG", 0.0);
    parser.addVariable("bgB", 0.0);
    parser.addVariable("bgWidth", (double) bgWidth);
    parser.addVariable("bgHeight", (double) bgHeight);
    parser.addVariable("fgLeft", (double) fgLeft);
    parser.addVariable("fgTop", (double) fgTop);
    parser.addVariable("fgX", 0.0);
    parser.addVariable("fgY", 0.0);
    Node redNode = parser.parse(formula1Red);
    Node greenNode = parser.parse(formula2Green);
    Node blueNode = parser.parse(formula3Blue);
    // compose the images
    for (int i = 0; i < fgHeight; i++) {
      int top = fgTop + i;
      if (top >= 0 && top < bgHeight) {
        parser.setVarValue("fgY", (double) i / 255.0);
        for (int j = 0; j < fgWidth; j++) {
          int left = fgLeft + j;
          if (left >= 0 && left < bgWidth) {
            parser.setVarValue("fgX", (double) j / 255.0);
            bgPixel.setARGBValue(bgImg.getARGBValue(left, top));
            fgPixel.setARGBValue(fgImg.getARGBValue(j, i));
            parser.setVarValue("bgR", (double) bgPixel.r / 255.0);
            parser.setVarValue("bgG", (double) bgPixel.g / 255.0);
            parser.setVarValue("bgB", (double) bgPixel.b / 255.0);
            parser.setVarValue("fgR", (double) fgPixel.r / 255.0);
View Full Code Here


    if (mode == Mode.CLOUDS) {
      final double rWeight = 0.2990;
      final double gWeight = 0.5880;
      final double bWeight = 0.1130;
      SimpleImage bgImg = (this.backgroundImg != null) ? backgroundImg.getImage() : null;
      Pixel pixel = new Pixel();
      Pixel bgPixel = new Pixel();
      for (int i = 0; i < mainImage.getWidth(); i++) {
        for (int j = 0; j < mainImage.getHeight(); j++) {
          pixel.setARGBValue(res.getARGBValue(i, j));
          double lum = pixel.r * rWeight + pixel.g * gWeight + pixel.b * bWeight;
          double c = lum - (cover * 255);
          if (c < 0)
            c = 0;
          int iVal = Tools.roundColor(255.0 - (Math.pow(this.sharpness, c) * 255.0));
          int bgRed = 0, bgGreen = 0, bgBlue = 0;
          switch (bgMode) {
            case IMAGE:
              if (bgImg != null) {
                bgPixel.setARGBValue(bgImg.getARGBValueIgnoreBounds(i, j));
                bgRed = bgPixel.r;
                bgGreen = bgPixel.g;
                bgBlue = bgPixel.b;
              }
              break;
View Full Code Here

        sumM += pMatrix[i][j];
      }
    }
    if (sumM == 0)
      sumM = 1;
    Pixel pixel = new Pixel();
    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 < sizeM; k++) {
          int y = i - sizeMHalve + k;
          for (int l = 0; l < sizeM; l++) {
            int x = j - sizeMHalve + l;
            pixel.setARGBValue(pSrcImg.getARGBValueIgnoreBounds(x, y));
            intSumR += pixel.r * pMatrix[k][l];
            intSumG += pixel.g * pMatrix[k][l];
            intSumB += pixel.b * pMatrix[k][l];
          }
        }
View Full Code Here

    double yscl = this.scaleY;

    double w1 = (double) width - 1.0;
    double h1 = (double) height - 1.0;

    Pixel pPixel = new Pixel();
    for (int pY = 0; pY < height; pY++) {
      for (int pX = 0; pX < width; pX++) {
        pPixel.setARGBValue(img.getARGBValue(pX, pY));
        int argb = srcImg.getARGBValue(pX, pY);
        toolPixel.setARGBValue(argb);
        double gint = (double) (toolPixel.r - avg);
        double x = (double) pX - xscl * gint;
        double y = (double) pY - yscl * gint;
 
View Full Code Here

    double cy = (double) height / 2 - 0.5;
    double daScale = (double) (width - 1) / (Math.PI + Math.PI);

    double a0 = this.phi0;
    double r0 = this.r0;
    Pixel pPixel = new Pixel();
    double w1 = (double) width - 1.0;
    double h1 = (double) height - 1.0;
    for (int i = 0; i < height; i++) {
      double dr = zoom * ((double) i + r0);
      if (dr < 0)
View Full Code Here

  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;
    }

    /* case 2 */
    else 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;
    }
    /* case 3 */
    else 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;
    }
    /* case 4 */
    else 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);
            }
View Full Code Here

    double zoom = 1.0 / this.zoom;
    double radius = this.radius;
    radius *= radius;
    double power = this.power;
    double da = alpha / Math.pow(radius, power);
    Pixel pPixel = new Pixel();
    for (int pY = 0; pY < pImg.getImageHeight(); pY++) {
      for (int pX = 0; pX < pImg.getImageWidth(); pX++) {
        pPixel.setARGBValue(img.getARGBValue(pX, pY));

        double dyq = (double) pY - cy;
        double y0 = dyq * zoom;
        dyq *= dyq;
        double x0 = (double) pX - cx;
View Full Code Here

        / Math.sqrt((double) width * (double) width + (double) height * (double) height);
    double PI2 = Math.PI / 2.0;
    double TWOPI = Math.PI + Math.PI;
    double a0 = (this.phi0) * Math.PI / 180.0;
    double r0 = this.r0;
    Pixel pPixel = new Pixel();
    double w1 = (double) width - 1.0;
    double h1 = (double) height - 1.0;
    for (int i = 0; i < height; i++) {
      double y0 = zoom * ((double) i - cy);
      for (int j = 0; j < width; j++) {
View Full Code Here

      vlen = this.radius - this.baseRadius;
    if (vlen < 0.0001)
      vlen = 0.0001;
    double vlenq = vlen * vlen;

    Pixel rgbPixel = new Pixel();
    HSLTransformer.HSLPixel hslPixel = new HSLTransformer.HSLPixel();
    switch (this.mode) {
      case HUE:
        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;
              double phue = (v1 + dv * prj) / 255.0;
              if (phue < (-1.0))
                phue = -1;
              else if (phue > 1.0)
                phue = 1.0;
              rgbPixel.setARGBValue(img.getARGBValue(j, i));
              HSLTransformer.rgb2hsl(rgbPixel, hslPixel);
              if (hslPixel.hue != (-1.0)) {
                hslPixel.hue += phue;
                if (hslPixel.hue < 0.0)
                  hslPixel.hue += 1.0;
                else if (hslPixel.hue > 1.0)
                  hslPixel.hue -= 1.0;
              }
              HSLTransformer.hsl2rgb(hslPixel, rgbPixel);
              img.setRGB(j, i, rgbPixel);
            }
          }
        }
        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;
              double phue = (v1 + dv * prj) / 255.0;
              if (phue < (-1.0))
                phue = -1;
              else if (phue > 1.0)
                phue = 1.0;
              rgbPixel.setARGBValue(img.getARGBValue(j, i));
              HSLTransformer.rgb2hsl(rgbPixel, hslPixel);
              if (hslPixel.hue != (-1.0)) {
                hslPixel.hue += phue;
                if (hslPixel.hue < 0.0)
                  hslPixel.hue += 1.0;
                else if (hslPixel.hue > 1.0)
                  hslPixel.hue -= 1.0;
              }
              HSLTransformer.hsl2rgb(hslPixel, rgbPixel);
              img.setRGB(j, i, rgbPixel);
            }
          }
        }
        break;
      case SATURATION:
        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;
              double psaturation = (v1 + dv * prj) / 255.0;
              if (psaturation < (-1.0))
                psaturation = -1.0;
              else if (psaturation > 1.0)
                psaturation = 1.0;
              rgbPixel.setARGBValue(img.getARGBValue(j, i));
              HSLTransformer.rgb2hsl(rgbPixel, hslPixel);
              hslPixel.saturation += psaturation;
              if (hslPixel.saturation < 0.0)
                hslPixel.saturation = 0.0;
              else if (hslPixel.saturation > 1.0)
                hslPixel.saturation = 1.0;
              HSLTransformer.hsl2rgb(hslPixel, rgbPixel);
              img.setRGB(j, i, rgbPixel);
            }
          }
        }
        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;
              double psaturation = (v1 + dv * prj) / 255.0;
              if (psaturation < (-1.0))
                psaturation = -1.0;
              else if (psaturation > 1.0)
                psaturation = 1.0;
              rgbPixel.setARGBValue(img.getARGBValue(j, i));
              HSLTransformer.rgb2hsl(rgbPixel, hslPixel);
              hslPixel.saturation += psaturation;
              if (hslPixel.saturation < 0.0)
                hslPixel.saturation = 0.0;
              else if (hslPixel.saturation > 1.0)
                hslPixel.saturation = 1.0;
              HSLTransformer.hsl2rgb(hslPixel, rgbPixel);
              img.setRGB(j, i, rgbPixel);
            }
          }
        }
        break;
      case LUMINOSITY:
        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;
              double pluminosity = (v1 + dv * prj) / 255.0;
              if (pluminosity < (-1.0))
                pluminosity = -1;
              else if (pluminosity > 1.0)
                pluminosity = 1.0;
              rgbPixel.setARGBValue(img.getARGBValue(j, i));
              HSLTransformer.rgb2hsl(rgbPixel, hslPixel);
              hslPixel.luminosity += pluminosity;
              if (hslPixel.luminosity < 0.0)
                hslPixel.luminosity = 0.0;
              else if (hslPixel.luminosity > 1.0)
                hslPixel.luminosity = 1.0;
              HSLTransformer.hsl2rgb(hslPixel, rgbPixel);
              img.setRGB(j, i, rgbPixel);
            }
          }
        }
        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;
              double pluminosity = (v1 + dv * prj) / 255.0;
              if (pluminosity < (-1.0))
                pluminosity = -1;
              else if (pluminosity > 1.0)
                pluminosity = 1.0;
              rgbPixel.setARGBValue(img.getARGBValue(j, i));
              HSLTransformer.rgb2hsl(rgbPixel, hslPixel);
              hslPixel.luminosity += pluminosity;
              if (hslPixel.luminosity < 0.0)
                hslPixel.luminosity = 0.0;
              else if (hslPixel.luminosity > 1.0)
View Full Code Here

    mesh3d.setPP1(pp1);
    mesh3d.setPP2(pp2);
    mesh3d.setPP3(pp3);

    int color[] = new int[fCount];
    Pixel toolPixel = new Pixel();
    toolPixel.setRGB(225, 185, 160);
    int argb = toolPixel.getARGBValue();
    for (int c = 0; c < fCount; c++) {
      color[c] = argb;
    }
    mesh3d.setColor(color);
View Full Code Here

TOP

Related Classes of org.jwildfire.image.Pixel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.