Package org.jwildfire.image

Examples of org.jwildfire.image.Pixel


    int gs = 5880;
    int bs = 1130;
    rs = (rs * Tools.VPREC) / 10000;
    gs = (gs * Tools.VPREC) / 10000;
    bs = (bs * Tools.VPREC) / 10000;
    Pixel p0 = new Pixel();
    Pixel p1 = new Pixel();
    Tools.srand123(this.seed);

    /* flip the image */
    if (direction == Direction.LEFT) {
      srcImg = srcImg.clone();
      FlipTransformer ft = new FlipTransformer();
      ft.setAxis(FlipTransformer.Axis.X);
      ft.transformImage(srcImg);
      ft.setAxis(FlipTransformer.Axis.X);
      ft.transformImage(img);
    }

    /** 1st line **/
    for (int i = 0; i < width; i++)
      smask[0][i] = 1;
    /** lines 2...(height-2) **/
    for (int i = 1; i < (height - 1); i++) {
      /* 1st pixel */
      smask[i][0] = 1;
      /* process pixels 2..width-1 */
      for (int j = 1; j < (width - 1); j++) {
        int dd = 0, int1;
        p1.setARGBValue(srcImg.getARGBValue(j - 1, i - 1));
        int1 = (rs * p1.r + gs * p1.g + bs * p1.b) >> Tools.SPREC;
        dd += int1;

        p1.setARGBValue(srcImg.getARGBValue(j + 1, i - 1));
        int1 = (rs * p1.r + gs * p1.g + bs * p1.b) >> Tools.SPREC;
        dd -= int1;

        p1.setARGBValue(srcImg.getARGBValue(j - 1, i));
        int1 = (rs * p1.r + gs * p1.g + bs * p1.b) >> Tools.SPREC;
        dd += int1;

        p1.setARGBValue(srcImg.getARGBValue(j + 1, i));
        int1 = (rs * p1.r + gs * p1.g + bs * p1.b) >> Tools.SPREC;
        dd -= int1;

        p1.setARGBValue(srcImg.getARGBValue(j - 1, i + 1));
        int1 = (rs * p1.r + gs * p1.g + bs * p1.b) >> Tools.SPREC;
        dd += int1;

        p1.setARGBValue(srcImg.getARGBValue(j + 1, i + 1));
        int1 = (rs * p1.r + gs * p1.g + bs * p1.b) >> Tools.SPREC;
        dd -= int1;

        if (dd < contrast) {
          smask[i][j] = 1;
        }
      }
      /* last pixel */
      smask[i][width - 1] = 1;
    }
    /** last line **/
    for (int i = 0; i < width; i++)
      smask[height - 1][i] = 1;

    /** accept only "thick" lines **/
    for (int i = 1; i < (height - 1); i++) {
      for (int j = 1; j < (width - 1); j++) {
        if (smask[i][j] == 0) {
          if (smask[i][j + 1] != 0)
            smask[i][j] = 1;
        }
      }
    }

    /** create "thin" lines **/
    for (int i = 1; i < (height - 1); i++) {
      nextLine: for (int j = (width - 2); j >= 1; j--) {
        if (smask[i][j] == 0) {
          int k = j - 1;
          while (smask[i][k] == 0) {
            smask[i][k] = 1;
            k--;
            if (k < 1)
              continue nextLine;
          }
        }
      }
    }

    /** remove isolated pixels **/
    for (int i = 1; i < (height - 1); i++) {
      for (int j = 1; j < (width - 1); j++) {
        if (smask[i][j] == 0) {
          int dd = 0;
          dd += smask[i][j - 1];
          dd += smask[i][j + 1];
          dd += smask[i - 1][j];
          dd += smask[i + 1][j];
          dd += smask[i + 1][j - 1];
          dd += smask[i + 1][j + 1];
          dd += smask[i - 1][j - 1];
          dd += smask[i - 1][j + 1];
          if (dd == 8)
            smask[i][j] = 1;
        }
      }
    }

    /** apply the changes **/
    int intensity0 = this.intensity;
    int intensity1 = intensity0 / 2;

    {
      double rprob = (double) ((double) 1.0 - (double) this.probability / (double) 100.0);
      for (int i = 0; i < height; i++) {
        cont: for (int j = (width - 1); j >= 0; j--) {
          if ((smask[i][j] == 0) && (Tools.drand() >= rprob)) {
            if (j < 1) {
              continue cont;
            }
            int intensity = intensity0 + (int) (Tools.drand() * intensity1 + 0.5);
            double dm = 100.0 / (double) (intensity - 1);
            int kmax = intensity;
            if ((j + kmax) >= width)
              kmax = width - j;
            for (int k = 0; k < kmax; k++) {
              int mix = (int) (100.0 - (double) k * dm + 0.5);
              int m1 = 100 - mix;
              int m2 = mix;
              p0.setARGBValue(srcImg.getARGBValue(j, i));
              p1.setARGBValue(srcImg.getARGBValue(j + k, i));
              int rv = ((int) ((int) p1.r * m1) + (int) p0.r * m2) / (int) 100;
              int gv = ((int) ((int) p1.g * m1) + (int) p0.g * m2) / (int) 100;
              int bv = ((int) ((int) p1.b * m1) + (int) p0.b * m2) / (int) 100;
              img.setRGB(j + k, i, rv, gv, bv);
            }
View Full Code Here


    final int BLOCK_SIZE = 64;
    final int imageWidth = pImg.getImageWidth();
    final int imageHeight = pImg.getImageHeight();
    final BufferedImage bufferedImg = img.getBufferedImg();
    final int[] pixels = new int[imageWidth * BLOCK_SIZE];
    final Pixel p = new Pixel();
    for (int b = 0; b < imageHeight; b += BLOCK_SIZE) {
      int blockSize = BLOCK_SIZE;
      int currHeight = b + BLOCK_SIZE;
      if (currHeight > imageHeight) {
        blockSize -= (currHeight - imageHeight);
      }
      bufferedImg.getRGB(0, b, imageWidth, blockSize, pixels, 0, imageWidth);
      for (int y = 0; y < blockSize; y++) {
        for (int x = 0; x < imageWidth; x++) {
          p.setARGBValue(pixels[y * imageWidth + x]);
          transformPixel(p, x, y + b, imageWidth, imageHeight);
          pixels[y * imageWidth + x] = p.getARGBValue();
        }
      }
      bufferedImg.setRGB(0, b, imageWidth, blockSize, pixels, 0, imageWidth);
    }
  }
View Full Code Here

    int width = pImg.getImageWidth();
    int height = pImg.getImageHeight();

    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++) {
        /* transform the point */
        double x0 = pX - cx;
        double y0 = pY - cy;
View Full Code Here

      RenderedFlame tmp = leftRender;
      leftRender = rightRender;
      rightRender = tmp;
    }

    Pixel lPixel = new Pixel();
    Pixel rPixel = new Pixel();
    Stereo3dColor leftColor = flame.getAnaglyph3dLeftEyeColor();
    Stereo3dColor rightColor = flame.getAnaglyph3dRightEyeColor();
    SimpleImage leftImg = leftRender.getImage();
    SimpleImage rightImg = rightRender.getImage();

    RenderedFlame mergedRender = new RenderedFlame();
    localRenderInfo.setImageWidth(leftRender.getImage().getImageWidth());
    localRenderInfo.setImageHeight(leftRender.getImage().getImageHeight());
    mergedRender.init(localRenderInfo);
    SimpleImage mergedImg = mergedRender.getImage();

    for (int i = 0; i < mergedImg.getImageHeight(); i++) {
      for (int j = 0; j < mergedImg.getImageWidth(); j++) {
        lPixel.setARGBValue(leftImg.getARGBValue(j, i));
        rPixel.setARGBValue(rightImg.getARGBValue(j, i));
        int mr = leftColor.calculateRed(lPixel.r, lPixel.g, lPixel.b) + rightColor.calculateRed(rPixel.r, rPixel.g, rPixel.b);
        if (mr < 0)
          mr = 0;
        else if (mr > 255)
          mr = 255;
View Full Code Here

        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);
          }
View Full Code Here

      sclY = 1.0;
    double cxD = (double) (width - 1) * 0.5;
    double cyD = (double) (height - 1) * 0.5;
    double cxS = (double) (swidth - 1) * 0.5;
    double cyS = (double) (sheight - 1) * 0.5;
    Pixel pPixel = new Pixel();

    for (int i = 0; i < height; i++) {
      double y0 = (double) i - cyD;
      double y = y0 * sclY + cyS;
      for (int j = 0; j < width; j++) {
View Full Code Here

      sclY = 1.0;
    double cxD = (double) (width - 1) * 0.5;
    double cyD = (double) (height - 1) * 0.5;
    double cxS = (double) (swidth - 1) * 0.5;
    double cyS = (double) (sheight - 1) * 0.5;
    Pixel pPixel = new Pixel();

    for (int i = 0; i < height; i++) {
      double y0 = (double) i - cyD;
      double y = y0 * sclY + cyS;
      for (int j = 0; j < width; j++) {
View Full Code Here

      sclY = 1.0;
    double cxD = (double) (width - 1) * 0.5;
    double cyD = (double) (height - 1) * 0.5;
    double cxS = (double) (swidth - 1) * 0.5;
    double cyS = (double) (sheight - 1) * 0.5;
    Pixel pPixel = new Pixel();

    for (int i = 0; i < height; i++) {
      double y0 = (double) i - cyD;
      double yn = (y0 + 1.0) * sclY + cyS;
      if (yn >= (sheight - 0.5))
View Full Code Here

      sclY = 1.0;
    double cxD = (double) (width - 1) * 0.5;
    double cyD = (double) (height - 1) * 0.5;
    double cxS = (double) (swidth - 1) * 0.5;
    double cyS = (double) (sheight - 1) * 0.5;
    Pixel pPixel = new Pixel();

    for (int i = 0; i < height; i++) {
      double y0 = (double) i - cyD;
      for (int j = 0; j < width; j++) {
        // transform the point
View Full Code Here

    parser.addVariable("height", (double) height);
    Node redNode = parser.parse(formula1Red);
    Node greenNode = parser.parse(formula2Green);
    Node blueNode = parser.parse(formula3Blue);

    Pixel pixel = new Pixel();
    for (int i = 0; i < height; i++) {
      parser.setVarValue("y", i);
      for (int j = 0; j < width; j++) {
        parser.setVarValue("x", j);
        pixel.setARGBValue(srcImg.getARGBValue(j, i));
        if (useOriginalRGBValues) {
          parser.setVarValue("r", (double) pixel.r);
          parser.setVarValue("g", (double) pixel.g);
          parser.setVarValue("b", (double) pixel.b);
          pixel.r = Tools.roundColor((Double) parser.evaluate(redNode));
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.