Package org.jwildfire.image

Examples of org.jwildfire.image.Pixel


    SimpleImage img = (SimpleImage) pImg;
    int width = pImg.getImageWidth();
    int height = pImg.getImageHeight();
    int gridSize = this.gridSize;
    Grid grid = (gridSize < 1) ? Grid.OFF : this.grid;
    Pixel pixel = new Pixel();

    int pw = this.width;
    int ph = this.height;
    if (pw < 1)
      pw = 1;
    else if (pw > width)
      pw = width;
    if (ph < 1)
      ph = 1;
    else if (ph > height)
      ph = height;
    if ((pw == 1) && (ph == 1))
      return;
    int pwo = pw;
    int pho = ph;
    int hc = width / pw;
    if ((width % pw) != 0)
      hc += 2;
    int vc = height / ph;
    if ((height % ph) != 0)
      vc += 2;
    int pwa[] = new int[hc];
    int pha[] = new int[vc];

    int gSize = 0;
    if (grid != Grid.OFF) {
      gSize = gridSize;
      if ((gSize > pwo) || (gSize > pho)) {
        if (pwo > pho)
          gSize = pho;
        else
          gSize = pwo;
      }
    }
    int grUp[] = null, ggUp[] = null, gbUp[] = null;
    int grDown[] = null, ggDown[] = null, gbDown[] = null;
    int grLeft[] = null, ggLeft[] = null, gbLeft[] = null;
    int grRight[] = null, ggRight[] = null, gbRight[] = null;

    if (((grid) != Grid.OFF) && (gSize >= 1)) {
      if ((gSize % 2) == 0)
        gSize++;
      int s = (gSize / 2 + 1);
      if (gSize > 1) {
        grUp = new int[s];
        ggUp = new int[s];
        gbUp = new int[s];
        grDown = new int[s];
        ggDown = new int[s];
        gbDown = new int[s];
        grLeft = new int[s];
        ggLeft = new int[s];
        gbLeft = new int[s];
        grRight = new int[s];
        ggRight = new int[s];
        gbRight = new int[s];
      }
    }
    //
    if ((width % pw) == 0) {
      for (int i = 0; i < hc; i++)
        pwa[i] = pw;
    }
    else {
      if (this.centre) {
        pwa[0] = (width % pw) / 2;
        if (pwa[0] == 0)
          pwa[0] = 1;
        for (int i = 1; i < (hc - 1); i++)
          pwa[i] = pw;
        pwa[hc - 1] = width - pwa[0] - (hc - 2) * pw;
        if (pwa[hc - 1] == 0)
          hc--;
      }
      else {
        hc--;
        for (int i = 0; i < (hc - 1); i++)
          pwa[i] = pw;
        pwa[hc - 1] = width - (hc - 1) * pw;
      }
    }

    if ((height % ph) == 0) {
      for (int i = 0; i < vc; i++)
        pha[i] = ph;
    }
    else {
      if (this.centre) {
        pha[0] = (height % ph) / 2;
        if (pha[0] == 0)
          pha[0] = 1;
        for (int i = 1; i < (vc - 1); i++)
          pha[i] = ph;
        pha[vc - 1] = height - pha[0] - (vc - 2) * ph;
        if (pha[vc - 1] == 0)
          vc--;
      }
      else {
        vc--;
        for (int i = 0; i < (vc - 1); i++)
          pha[i] = ph;
        pha[vc - 1] = height - (vc - 1) * ph;
      }
    }

    {
      int topOffset = 0;
      for (int i = 0; i < vc; i++) {
        ph = pha[i];
        int leftOffset = 0;
        for (int j = 0; j < hc; j++) {
          pw = pwa[j];
          int pc = pw * ph;
          /* compute the average-color */
          int ra = 0, ga = 0, ba = 0;
          for (int k = 0; k < ph; k++) {
            for (int l = 0; l < pw; l++) {
              int x = leftOffset + l;
              int y = topOffset + k;
              pixel.setARGBValue(srcImg.getARGBValue(x, y));
              ra += pixel.r;
              ga += pixel.g;
              ba += pixel.b;
            }
          }
View Full Code Here


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

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

  }

  private void shearX(SimpleImage pImg) {
    int width = pImg.getImageWidth();
    int height = pImg.getImageHeight();
    Pixel pPixel = new Pixel();
    double cx = (double) width / 2.0 - 0.5;
    double cy = (double) height / 2.0 - 0.5;
    double oy = this.centreY - cy;
    double zoom = this.zoom;
    if (zoom < 0.01)
View Full Code Here

  }

  private void shearX_Damp(SimpleImage pImg) {
    int width = pImg.getImageWidth();
    int height = pImg.getImageHeight();
    Pixel pPixel = new Pixel();
    double cx = (double) width / 2.0 - 0.5;
    double cy = (double) height / 2.0 - 0.5;
    double ox = this.centreX - cx;
    double oy = this.centreY - cy;
    double zoom = this.zoom;
View Full Code Here

  }

  private void shearY(SimpleImage pImg) {
    int width = pImg.getImageWidth();
    int height = pImg.getImageHeight();
    Pixel pPixel = new Pixel();
    double cx = (double) width / 2.0 - 0.5;
    double cy = (double) height / 2.0 - 0.5;
    double ox = this.centreX - cx;
    double zoom = this.zoom;
    if (zoom < 0.01)
View Full Code Here

  }

  private void shearY_Damp(SimpleImage pImg) {
    int width = pImg.getImageWidth();
    int height = pImg.getImageHeight();
    Pixel pPixel = new Pixel();
    double cx = (double) width / 2.0 - 0.5;
    double cy = (double) height / 2.0 - 0.5;
    double ox = this.centreX - cx;
    double oy = this.centreY - cy;
    double zoom = this.zoom;
View Full Code Here

    StringBuilder sb = new StringBuilder();
    String name = "JWildfire";
    sb.append(name + " {\n");
    sb.append("gradient:\n");
    sb.append(" title=\"" + name + "\" smooth=no\n");
    Pixel p = new Pixel();
    int lastColor = -1;
    for (int i = 0; i < width; i++) {
      // swap R and B
      p.r = pImg.getBValue(i, 0);
      p.g = pImg.getGValue(i, 0);
      p.b = pImg.getRValue(i, 0);
      p.a = 0;
      int color = p.getARGBValue();
      if (color != lastColor) {
        sb.append(" index=" + i + " color=" + color + "\n");
        lastColor = color;
      }
    }
View Full Code Here

    double famount = this.amount;
    double fdamping = this.damping;

    double w1 = (double) width - 1.0;
    double h1 = (double) height - 1.0;
    Pixel pPixel = new Pixel();
    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++) {
        pPixel.setARGBValue(img.getARGBValue(j, i));

        /* transform the point */
        double x0 = (double) j - cx;
        double rr = Math.sqrt(x0 * x0 + dyq);
        x0 *= zoom;
View Full Code Here

  protected void performPixelTransformation(WFImage pImg) {
    SimpleImage img = (SimpleImage) pImg;
    int width = pImg.getImageWidth();
    int height = pImg.getImageHeight();
    final double brMAX = 256.0;
    Pixel pixel = new Pixel();
    /* saturation */
    if (this.saturation != 0) {
      int rs = 2990;
      int gs = 5880;
      int bs = 1130;
      rs = (rs * Tools.VPREC) / 10000;
      gs = (gs * Tools.VPREC) / 10000;
      bs = (bs * Tools.VPREC) / 10000;
      int scl = (int) ((double) this.saturation / 255.0 * 1024.0 + 0.5);
      for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
          pixel.setARGBValue(img.getARGBValue(j, i));
          int avg = (rs * pixel.r + gs * pixel.g + bs * pixel.b) >> Tools.SPREC;
          pixel.r += ((pixel.r - avg) * scl) >> Tools.SPREC;
          if (pixel.r < 0)
            pixel.r = 0;
          else if (pixel.r > 255)
            pixel.r = 255;
          pixel.g += ((pixel.g - avg) * scl) >> Tools.SPREC;
          if (pixel.g < 0)
            pixel.g = 0;
          else if (pixel.g > 255)
            pixel.g = 255;
          pixel.b += ((pixel.b - avg) * scl) >> Tools.SPREC;
          if (pixel.b < 0)
            pixel.b = 0;
          else if (pixel.b > 255)
            pixel.b = 255;
          img.setRGB(j, i, pixel);
        }
      }
    }
    /* gamma */
    if (this.gamma != 0) {
      double max = 255.0;
      double g = (double) 512.0 / (512.0 + (double) this.gamma);
      int gamma[] = new int[256];
      double da, aa;
      da = aa = 1.0 / 255.0;
      gamma[0] = 0;
      for (int i = 1; i < 256; i++) {
        int val = (int) (max * Math.pow(aa, g) + 0.5);
        aa += da;
        gamma[i] = val;
      }
      for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
          pixel.setARGBValue(img.getARGBValue(j, i));
          pixel.r = gamma[pixel.r];
          pixel.g = gamma[pixel.g];
          pixel.b = gamma[pixel.b];
          img.setRGB(j, i, pixel);
        }
      }
    }
    /* red */
    if (this.red != 0) {
      int tt = (int) ((double) this.red / (double) brMAX * (double) 255.0 + 0.5);
      for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
          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);
        }
      }
    }
    /* green */
    if (this.green != 0) {
      int tt = (int) ((double) this.green / (double) brMAX * (double) 255.0 + 0.5);
      for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
          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);
        }
      }
    }
    /* blue */
    if (this.blue != 0) {
      int tt = (int) ((double) this.blue / (double) brMAX * (double) 255.0 + 0.5);
      for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
          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);
        }
      }
    }
    /* brightness */
    if (brightness != 0) {
      int tt = (int) ((double) this.brightness / (double) brMAX * (double) 255.0 + 0.5);
      for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
          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);
        }
      }

    }
    /* contrast */
    if (this.contrast != 0) {
      double scale = (double) this.contrast / brMAX;
      int sc = (int) (scale * (double) Tools.VPREC + 0.5);
      int dc;
      if (this.contrast > 0) {
        for (int i = 0; i < height; i++) {
          for (int j = 0; j < width; j++) {
            pixel.setARGBValue(img.getARGBValue(j, i));
            dc = (int) (((int) (pixel.r - (int) 127) * sc) >> Tools.SPREC);
            if (dc < (-255))
              dc = (-255);
            else if (dc > 255)
              dc = 255;
            pixel.r += dc;
            if (pixel.r < 0)
              pixel.r = 0;
            else if (pixel.r > 255)
              pixel.r = 255;
            dc = (int) (((int) (pixel.g - (int) 127) * sc) >> Tools.SPREC);
            if (dc < (-255))
              dc = (-255);
            else if (dc > 255)
              dc = 255;
            pixel.g += dc;
            if (pixel.g < 0)
              pixel.g = 0;
            else if (pixel.g > 255)
              pixel.g = 255;
            dc = (int) ((int) ((pixel.b - (int) 127) * sc) >> Tools.SPREC);
            if (dc < (-255))
              dc = (-255);
            else if (dc > 255)
              dc = 255;
            pixel.b += dc;
            if (pixel.b < 0)
              pixel.b = 0;
            else if (pixel.b > 255)
              pixel.b = 255;
            img.setRGB(j, i, pixel);
          }
        }
      }
      else {
        int val;
        for (int i = 0; i < height; i++) {
          for (int j = 0; j < width; j++) {
            pixel.setARGBValue(img.getARGBValue(j, i));
            dc = (int) (((int) ((int) pixel.r - (int) 127) * sc) >> Tools.SPREC);
            if (dc < (-255))
              dc = (-255);
            else if (dc > 255)
              dc = 255;
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.