Esempio n. 1
0
 protected void setImpl(int dx, int dy, int sx, int sy, int sw, int sh, PImage src) {
   WritableRaster raster = ((BufferedImage) (primarySurface ? offscreen : image)).getRaster();
   if ((sx == 0) && (sy == 0) && (sw == src.width) && (sh == src.height)) {
     raster.setDataElements(dx, dy, src.width, src.height, src.pixels);
   } else {
     // TODO Optimize, incredibly inefficient to reallocate this much memory
     PImage temp = src.get(sx, sy, sw, sh);
     raster.setDataElements(dx, dy, temp.width, temp.height, temp.pixels);
   }
 }
Esempio n. 2
0
 public void set(int x, int y, int argb) {
   if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) return;
   //    ((BufferedImage) image).setRGB(x, y, argb);
   getset[0] = argb;
   WritableRaster raster = ((BufferedImage) (primarySurface ? offscreen : image)).getRaster();
   raster.setDataElements(x, y, getset);
 }
Esempio n. 3
0
 public void backgroundImpl() {
   if (backgroundAlpha) {
     // Create a small array that can be used to set the pixels several times.
     // Using a single-pixel line of length 'width' is a tradeoff between
     // speed (setting each pixel individually is too slow) and memory
     // (an array for width*height would waste lots of memory if it stayed
     // resident, and would terrify the gc if it were re-created on each trip
     // to background().
     WritableRaster raster = ((BufferedImage) image).getRaster();
     if ((clearPixels == null) || (clearPixels.length < width)) {
       clearPixels = new int[width];
     }
     java.util.Arrays.fill(clearPixels, backgroundColor);
     for (int i = 0; i < height; i++) {
       raster.setDataElements(0, i, width, 1, clearPixels);
     }
   } else {
     // new Exception().printStackTrace(System.out);
     // in case people do transformations before background(),
     // need to handle this with a push/reset/pop
     pushMatrix();
     resetMatrix();
     g2.setColor(new Color(backgroundColor)); // , backgroundAlpha));
     g2.fillRect(0, 0, width, height);
     popMatrix();
   }
 }
 public DisplayImage16(int w, int h) {
   this();
   iWidth = w;
   iHeight = h;
   iSize = iWidth * iHeight;
   imageBufferArray = new short[iSize];
   for (int i = 0; i < iSize; i++) {
     imageBufferArray[i] = 0;
   }
   bImage = new BufferedImage(iWidth, iHeight, BufferedImage.TYPE_USHORT_GRAY);
   bRaster = bImage.getRaster();
   bRaster.setDataElements(0, 0, iWidth, iHeight, imageBufferArray);
   //    buffGraphics = (Graphics2D) bImage.createGraphics();
   //    buffGraphics.setFont(font);
   this.setPreferredSize(new Dimension(iWidth, iHeight));
   setVisible(true);
   // this.setBorder(BorderFactory.createLoweredBevelBorder());
 }
 public void updateImage(short[] imageData) {
   bRaster.setDataElements(0, 0, iWidth, iHeight, imageData);
   repaint();
 }
Esempio n. 6
0
    /**
     * Update the pixels of the cache image. Already determined that the tint has changed, or the
     * pixels have changed, so should just go through with the update without further checks.
     */
    public void update(boolean tint, int tintColor) {
      int bufferType = BufferedImage.TYPE_INT_ARGB;
      boolean opaque = (tintColor & 0xFF000000) == 0xFF000000;
      if (source.format == RGB) {
        if (!tint || (tint && opaque)) {
          bufferType = BufferedImage.TYPE_INT_RGB;
        }
      }
      boolean wrongType = (image != null) && (image.getType() != bufferType);
      if ((image == null) || wrongType) {
        image = new BufferedImage(source.width, source.height, bufferType);
      }

      WritableRaster wr = image.getRaster();
      if (tint) {
        if (tintedPixels == null || tintedPixels.length != source.width) {
          tintedPixels = new int[source.width];
        }
        int a2 = (tintColor >> 24) & 0xff;
        int r2 = (tintColor >> 16) & 0xff;
        int g2 = (tintColor >> 8) & 0xff;
        int b2 = (tintColor) & 0xff;

        if (bufferType == BufferedImage.TYPE_INT_RGB) {
          // int alpha = tintColor & 0xFF000000;
          int index = 0;
          for (int y = 0; y < source.height; y++) {
            for (int x = 0; x < source.width; x++) {
              int argb1 = source.pixels[index++];
              int r1 = (argb1 >> 16) & 0xff;
              int g1 = (argb1 >> 8) & 0xff;
              int b1 = (argb1) & 0xff;

              tintedPixels[x] = // 0xFF000000 |
                  (((r2 * r1) & 0xff00) << 8) | ((g2 * g1) & 0xff00) | (((b2 * b1) & 0xff00) >> 8);
            }
            wr.setDataElements(0, y, source.width, 1, tintedPixels);
          }
          // could this be any slower?
          //          float[] scales = { tintR, tintG, tintB };
          //          float[] offsets = new float[3];
          //          RescaleOp op = new RescaleOp(scales, offsets, null);
          //          op.filter(image, image);

        } else if (bufferType == BufferedImage.TYPE_INT_ARGB) {
          int index = 0;
          for (int y = 0; y < source.height; y++) {
            if (source.format == RGB) {
              int alpha = tintColor & 0xFF000000;
              for (int x = 0; x < source.width; x++) {
                int argb1 = source.pixels[index++];
                int r1 = (argb1 >> 16) & 0xff;
                int g1 = (argb1 >> 8) & 0xff;
                int b1 = (argb1) & 0xff;
                tintedPixels[x] =
                    alpha
                        | (((r2 * r1) & 0xff00) << 8)
                        | ((g2 * g1) & 0xff00)
                        | (((b2 * b1) & 0xff00) >> 8);
              }
            } else if (source.format == ARGB) {
              for (int x = 0; x < source.width; x++) {
                int argb1 = source.pixels[index++];
                int a1 = (argb1 >> 24) & 0xff;
                int r1 = (argb1 >> 16) & 0xff;
                int g1 = (argb1 >> 8) & 0xff;
                int b1 = (argb1) & 0xff;
                tintedPixels[x] =
                    (((a2 * a1) & 0xff00) << 16)
                        | (((r2 * r1) & 0xff00) << 8)
                        | ((g2 * g1) & 0xff00)
                        | (((b2 * b1) & 0xff00) >> 8);
              }
            } else if (source.format == ALPHA) {
              int lower = tintColor & 0xFFFFFF;
              for (int x = 0; x < source.width; x++) {
                int a1 = source.pixels[index++];
                tintedPixels[x] = (((a2 * a1) & 0xff00) << 16) | lower;
              }
            }
            wr.setDataElements(0, y, source.width, 1, tintedPixels);
          }
          // Not sure why ARGB images take the scales in this order...
          //          float[] scales = { tintR, tintG, tintB, tintA };
          //          float[] offsets = new float[4];
          //          RescaleOp op = new RescaleOp(scales, offsets, null);
          //          op.filter(image, image);
        }
      } else {
        wr.setDataElements(0, 0, source.width, source.height, source.pixels);
      }
      this.tinted = tint;
      this.tintedColor = tintColor;
    }
Esempio n. 7
0
 /**
  * Update the pixels[] buffer to the PGraphics image.
  *
  * <p>Unlike in PImage, where updatePixels() only requests that the update happens, in
  * PGraphicsJava2D, this will happen immediately.
  */
 public void updatePixels() {
   // updatePixels(0, 0, width, height);
   WritableRaster raster = ((BufferedImage) (primarySurface ? offscreen : image)).getRaster();
   raster.setDataElements(0, 0, width, height, pixels);
 }