Package org.jwildfire.image

Examples of org.jwildfire.image.SimpleImage


  @Property(category = PropertyCategory.SECONDARY, description = "intensity of the light")
  private double intensity;

  @Override
  protected void performPixelTransformation(WFImage pImg) {
    SimpleImage img = (SimpleImage) pImg;
    int intensity = (int) (this.intensity * (double) VPREC + 0.5);
    int amount = (int) (this.amount * (double) VPREC + 0.5);

    int left = this.left;
    int top = this.top;
    int width = pImg.getImageWidth();
    int height = pImg.getImageHeight();
    Buffer heightMapBuffer = this.heightMap;
    SimpleImage heightMap = heightMapBuffer.getImage();

    int bwidth = heightMap.getImageWidth();
    int bheight = heightMap.getImageHeight();

    /* compute the light-vector */
    int plCosA, lvx, lvy, lvz;
    {
      double lx = 0.0 - (double) lightX;
      double ly = 0.0 - (double) lightY;
      double lz = (double) 0.0 - (double) lightZ;

      double r = Math.sqrt(lx * lx + ly * ly + lz * lz);
      if (r != (float) 0.0) {
        lx /= r;
        ly /= r;
        lz /= r;
      }
      else {
        lx = (double) 0.0;
        ly = (double) 0.0;
        lz = (double) 1.0;
      }

      lvx = (int) (lx * (double) VPREC + 0.5);
      lvy = (int) (ly * (double) VPREC + 0.5);
      lvz = (int) (lz * (double) VPREC + 0.5);

      int nz = 0 - VPREC;
      int nx = 0;
      int ny = 0;
      plCosA = ((lvx * nx + VPREC2) >> SPREC) + ((lvy * ny + VPREC2) >> SPREC)
          + ((lvz * nz + VPREC2) >> SPREC);
      plCosA = (plCosA * intensity + VPREC2) >> SPREC;
      if (plCosA < 0)
        plCosA = 0 - plCosA;
      else
        plCosA = 0;
    }

    int x1 = -VPREC;
    int y1 = -VPREC;
    int x2 = VPREC;
    int y2 = -VPREC;
    int x3 = -VPREC;
    int y3 = VPREC;
    int x4 = VPREC;
    int y4 = VPREC;
    int x5 = 0;
    int y5 = 0;

    int a1x = x5 - x1;
    int a1y = y5 - y1;
    int b1x = x5 - x2;
    int b1y = y5 - y2;

    int a2x = x5 - x2;
    int a2y = y5 - y2;
    int b2x = x5 - x4;
    int b2y = y5 - y4;

    int a3x = x5 - x4;
    int a3y = y5 - y4;
    int b3x = x5 - x3;
    int b3y = y5 - y3;

    int a4x = x5 - x3;
    int a4y = y5 - y3;
    int b4x = x5 - x1;
    int b4y = y5 - y1;

    Pixel sPixel = new Pixel();
    Pixel hPixel = new Pixel();
    Pixel hLUPixel = new Pixel();
    Pixel hRUPixel = new Pixel();
    Pixel hLBPixel = new Pixel();
    Pixel hRBPixel = new Pixel();

    for (int i = 0; i < height; i++) {
      int biy = i - top;
      for (int j = 0; j < width; j++) {
        int bix = j - left;
        int z1, z2, z3, z4, z5;
        if ((bix >= 0) && (bix < bwidth) && (biy >= 0) && (biy < bheight)) {
          hPixel.setARGBValue(heightMap.getARGBValue(bix, biy));

          hLUPixel.setARGBValue(heightMap.getARGBValueIgnoreBounds(bix - 1, biy - 1));
          hRUPixel.setARGBValue(heightMap.getARGBValueIgnoreBounds(bix + 1, biy - 1));

          hLBPixel.setARGBValue(heightMap.getARGBValueIgnoreBounds(bix - 1, biy + 1));
          hRBPixel.setARGBValue(heightMap.getARGBValueIgnoreBounds(bix + 1, biy + 1));

          z5 = 0 - ((int) (hPixel.r) << SPREC) / 255;
          if (biy > 0) {
            if (bix > 0)
              z1 = 0 - ((int) (hLUPixel.r) << SPREC) / 255;
View Full Code Here


    return false;
  }

  @Override
  protected void performImageTransformation(WFImage pImg) {
    SimpleImage img = (SimpleImage) pImg;
    if ((leftSize > 0) || (topSize > 0) || (rightSize > 0) || (bottomSize > 0)) {
      PlainImageCreator creator = new PlainImageCreator();
      creator.setBgColor(color);
      SimpleImage bgImg = creator.createImage(pImg.getImageWidth() + leftSize + rightSize,
          pImg.getImageHeight() + topSize + bottomSize);
      ComposeTransformer cT = new ComposeTransformer();
      cT.setForegroundImage(img);
      cT.setLeft(leftSize);
      cT.setTop(topSize);
      cT.setGenlock(ComposeTransformer.Genlock.NONE);
      cT.setHAlign(ComposeTransformer.HAlignment.OFF);
      cT.setVAlign(ComposeTransformer.VAlignment.OFF);
      cT.transformImage(bgImg);
      img.setBufferedImage(bgImg.getBufferedImg(), bgImg.getImageWidth(), bgImg.getImageHeight());
    }
  }
View Full Code Here

  @Property(description = "Smoothing amount", category = PropertyCategory.SECONDARY)
  private int smoothing = 1;

  @Override
  protected void performPixelTransformation(WFImage pImg) {
    SimpleImage img = (SimpleImage) pImg;
    int width = pImg.getImageWidth();
    int height = pImg.getImageHeight();
    Pixel pPixel = new Pixel();
    double alpha = (0.0 - this.amount) * Math.PI / 180.0;
    double cosa = Math.cos(alpha);
    double sina = Math.sin(alpha);
    double cx = this.centreX - 0.5;
    double cy = this.centreY - 0.5;
    double zoom = this.zoom;
    if (zoom < 0.01)
      zoom = 0.01;
    zoom = 1.0 / zoom;
    double radius = this.radius * this.radius;

    double w1 = (double) width - 1.0;
    double h1 = (double) height - 1.0;
    for (int i = 0; i < height; i++) {
      double dyq = (double) i - cy;
      double y0 = dyq * zoom;
      dyq *= dyq;
      for (int j = 0; j < width; j++) {
        /* transform the point */
        double x0 = (double) j - cx;
        double rr = x0 * x0 + dyq;
        if (rr <= radius) {
          x0 *= zoom;
          double x = cosa * x0 + sina * y0 + cx;
          double y = -sina * x0 + cosa * y0 + cy;

          /* render it */
          /* 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(j, i, pPixel.r, pPixel.g, pPixel.b);
        }
      }
    }
    applySmoothing(img, smoothing);
  }
View Full Code Here

  @Property(category = PropertyCategory.SECONDARY, description = "Top offset of the height map")
  private int top = 0;

  @Override
  protected void performPixelTransformation(WFImage pImg) {
    SimpleImage img = (SimpleImage) pImg;
    /* generate the op-table (op[value][alpha]*/
    int optable[][] = new int[256][256];
    for (int i = 0; i < 256; i++) {
      for (int j = 0; j < 256; j++) {
        int val = i * (j + 1) + (int) 128;
        val /= (int) 256;
        optable[i][j] = Tools.limitColor(val);
      }
    }

    SimpleImage alpha = this.alphaChannel.getImage();
    int awidth = alpha.getImageWidth();
    int aheight = alpha.getImageHeight();

    int bgwidth = pImg.getImageWidth();
    int bgheight = pImg.getImageHeight();
    int hsize = 0, vsize = 0;
    int bgleft = 0, bgtop = 0;
    int aleft = 0, atop = 0;
    /* case 1 */
    if ((left >= 0) && (top >= 0)) {
      if ((left >= bgwidth) || (top >= bgheight))
        return;

      hsize = bgwidth - left;
      if (hsize > awidth)
        hsize = awidth;
      vsize = bgheight - top;
      if (vsize > aheight)
        vsize = aheight;

      bgtop = top;
      bgleft = left;
      aleft = 0;
      atop = 0;
    }
    /* case 2 */
    else if ((left < 0) && (top >= 0)) {
      if ((left <= (0 - awidth)) || (top >= bgheight))
        return;

      hsize = awidth + left;
      if (hsize > bgwidth)
        hsize = bgwidth;
      vsize = bgheight - top;
      if (vsize > aheight)
        vsize = aheight;

      bgtop = top;
      bgleft = 0;
      atop = 0;
      aleft = 0 - left;
    }
    /* case 3 */
    else if ((left >= 0) && (top < 0)) {
      if ((left >= bgwidth) || (top <= (0 - aheight)))
        return;
      hsize = bgwidth - left;
      if (hsize > awidth)
        hsize = awidth;
      vsize = aheight + top;
      if (vsize > bgheight)
        vsize = bgheight;

      bgtop = 0;
      bgleft = left;
      atop = 0 - top;
      aleft = 0;
    }
    /* case 4 */
    else if ((left < 0) && (top < 0)) {
      if ((left <= (0 - awidth)) || (top <= (0 - aheight)))
        return;

      hsize = awidth + left;
      if (hsize > bgwidth)
        hsize = bgwidth;
      vsize = aheight + top;
      if (vsize > bgheight)
        vsize = bgheight;

      bgtop = 0;
      bgleft = 0;

      atop = 0 - top;
      aleft = 0 - left;
    }

    img.fillBackground(0, 0, 0);
    Pixel pixel = new Pixel();
    for (int i = 0; i < vsize; i++) {
      for (int j = 0; j < hsize; j++) {
        int x = j + bgleft;
        int y = i + bgtop;
        pixel.setARGBValue(srcImg.getARGBValue(x, y));
        int a = alpha.getRValue(j + aleft, i + atop);
        pixel.r = optable[pixel.r][a];
        pixel.g = optable[pixel.g][a];
        pixel.b = optable[pixel.b][a];
        img.setRGB(x, y, pixel);
      }
View Full Code Here

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

  private short[][] generateDisk(int pSize) {
    short s = (short) pSize;
    if ((s < 3) || (s % 2 == 0))
      throw new IllegalArgumentException(String.valueOf(pSize));
    short s2 = (short) (s / 2);
    SimpleImage img = new SimpleImage(s + 120, s + 120);
    Graphics g = img.getGraphics();
    g.setColor(new Color(255, 0, 0));
    // fillOval gave strange effects at low scales, but drawOval seems to work
    g.drawOval(0, 0, s - 1, s - 1);

    // fill it manually
    for (short i = 0; i < s; i++) {
      nextLine: for (short j = 0; j <= s2; j++) {
        if (img.getRValue(j, i) == 255) {
          g.drawLine(j, i, s - j - 1, i);
          continue nextLine;
        }
      }
    }
    int cnt = 0;
    for (short i = 0; i < s; i++) {
      for (short j = 0; j < s; j++) {
        if (img.getRValue(j, i) == 255)
          cnt++;
      }
    }
    int idx = 0;
    short[][] res = new short[cnt][2];
    for (short i = 0; i < s; i++) {
      for (short j = 0; j < s; j++) {
        if (img.getRValue(j, i) == 255) {
          res[idx][0] = (short) (j - s2);
          res[idx++][1] = (short) (i - s2);
        }
      }
    }
View Full Code Here

  private void loadImages() {
    frame.setTitle("Welcome to " + Tools.APP_TITLE + " " + Tools.APP_VERSION);
    // Load logo
    try {
      SimpleImage img = getImage(Tools.SPECIAL_VERSION ? "logo_special.png" : "logo.png");
      northPanel.setLayout(null);
      ImagePanel imgPanel = new ImagePanel(img, 0, 0, img.getImageWidth());
      imgPanel.setPreferredSize(new Dimension(img.getImageWidth(), img.getImageHeight()));
      imgPanel.setLocation(Tools.SPECIAL_VERSION ? 7 : 107, 4);
      getNorthPanel().add(imgPanel);
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }

    String imageFilename = "";
    try {
      if (Tools.SPECIAL_VERSION) {
        final int IMG_COUNT = 3;
        int imageIdx = (int) (Math.random() * IMG_COUNT) + 1;
        String id = String.valueOf(imageIdx);
        while (id.length() < 3) {
          id = "0" + id;
        }
        imageFilename = "special" + id + ".jpg";
      }
      else {
        final int IMG_COUNT = 101;
        int imageIdx = (int) (Math.random() * IMG_COUNT) + 1;
        String id = String.valueOf(imageIdx);
        while (id.length() < 3) {
          id = "0" + id;
        }
        imageFilename = "image" + id + ".jpg";
      }
      SimpleImage img = getImage(imageFilename);
      imgDisplayPanel.setLayout(null);
      ImagePanel imgPanel = new ImagePanel(img, 0, 0, img.getImageWidth());
      getImgDisplayPanel().add(imgPanel);

      //      System.out.println(imgDisplayPanel.getSize().height + " " + imgDisplayPanel.getSize().width);
      imgPanel.setLayout(null);
    }
View Full Code Here

    int height = fileImg.getHeight(null);
    BufferedImage bImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics g = bImg.getGraphics();
    g.drawImage(fileImg, 0, 0, null);
    fileImg = null;
    return new SimpleImage(bImg, width, height);
  }
View Full Code Here

  @Property(category = PropertyCategory.SECONDARY, description = "Exposure bias (mode=EXPOSURE)")
  private double exposureBias;

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

  @Property(description = "Formula of the blue channel")
  private String formula3Blue;

  @Override
  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);
            parser.setVarValue("fgG", (double) fgPixel.g / 255.0);
View Full Code Here

TOP

Related Classes of org.jwildfire.image.SimpleImage

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.