Exemple #1
0
 void createImage() {
   if (imageSource == null) {
     rgbCM = new DirectColorModel(32, 0xff0000, 0xff00, 0xff);
     imageSource = new MemoryImageSource(width, height, rgbCM, rgbPixels, 0, width);
     imageSource.setAnimated(true);
     imageSource.setFullBufferUpdates(true);
     awtImage = Toolkit.getDefaultToolkit().createImage(imageSource);
     newPixels = false;
   } else if (newPixels) {
     imageSource.newPixels(rgbPixels, rgbCM, 0, width);
     newPixels = false;
   } else imageSource.newPixels();
 }
 /**
  * Changes to a new int array to hold the pixels for this image. If the animation flag has been
  * turned on through the setAnimated() method, then the new pixels will be immediately delivered
  * to any ImageConsumers that are currently interested in the data for this image.
  *
  * @param newpix the new pixel array
  * @param newmodel the specified <code>ColorModel</code>
  * @param offset the offset into the array
  * @param scansize the distance from one row of pixels to the next in the array
  * @see #newPixels(int, int, int, int, boolean)
  * @see #setAnimated
  */
 public synchronized void newPixels(int[] newpix, ColorModel newmodel, int offset, int scansize) {
   this.pixels = newpix;
   this.model = newmodel;
   this.pixeloffset = offset;
   this.pixelscan = scansize;
   newPixels();
 }
Exemple #3
0
  public void putRegion(
      int viewWidth,
      int viewHeight,
      int regWidth,
      int regHeight,
      int regOffX,
      int regOffY,
      int[] regBuffer) {
    if (image == null) {
      setPreferredSize(new Dimension(viewWidth, viewHeight));
      imageBuffer = new int[viewWidth * viewHeight];
      imageSource = new MemoryImageSource(viewWidth, viewHeight, imageBuffer, 0, viewWidth);
      imageSource.setAnimated(true);
      image = createImage(imageSource);
    }

    int destIndex = regOffX + regOffY * viewWidth;
    int srcIndex = 0;
    int extraRowGap = viewWidth - regWidth;
    for (int j = 0; j < regHeight; j++, destIndex += extraRowGap)
      for (int i = 0; i < regWidth; i++, srcIndex++, destIndex++)
        imageBuffer[destIndex] = regBuffer[srcIndex];
    imageSource.newPixels(regOffX, regOffY, regWidth, regHeight);
    repaint(regOffX, regOffY, regWidth, regHeight);
  }
  public void notifyMoreDataReady(float[] bins) { // an array of floats

    if (recursion) System.err.println(" RECURSION ");
    nBins = bins.length;
    if (nBins == 0) return;

    recursion = true;

    if (size == null || nBins != size.height || nChunks != size.width) // || this is the or operator
    createGraphics(); //  Returns a Graphics2D object for rendering into the specified
                      // BufferedImage.

    int width = size.width;

    for (int i = 0;
        i < nBins;
        i++) { // this is recursing over all the rows (nbins is the number of rows)
      int bin = nBins - i - 1; // I think this makes it start from the top
      float val = mapper.eval(bins[bin]); //

      if (val < 0) val = 0.0f;
      if (val > 1.0) // I think this next section colours the pixels in the spectrum
      val = 1.0f; // display
      int c_r = (int) (255 * val);
      int c_g = c_r;
      int c_b = 255 - c_r;

      int color =
          (c_b)
              + (c_g << 8)
              + (c_r << 16)
              + (0xFF
                  << 24); // << operator means signed left shift-- it shifts the bits in the binary
                          // code to the left creating a bigger number the operand on the right
                          // specifies the amount of shift
      screenBuffer[i * width + ptr] =
          (255 << 24)
              + color; // I think loads the screenBuffer array. the index[i*width+ptr] is filled
                       // with the right operand
      // rgbarray[i] = color;
    }

    if (ptr % 1 == 0) { // ptr remainder(%) 1
      screenConverter.newPixels(
          ptr, 0, 1,
          nBins); // newPixels is method inside the MemoryImageSource i think it does this----Sends
                  // a rectangular region of the buffer of pixels to any ImageConsumers that are
                  // currently interested in the data for this image and notify them that an
                  // animation frame is complete.
      screenRepaint = true;
      repaint();
    }

    ptr =
        (ptr + 1)
            % size.width; // i think this may help in changing the co-ordinates ptr may be the x
                          // coordinate
    recursion = false;
  }
  public void shuffle(int p) {
    for (int i = 0; i < picWidth * picHeight; ++i) {
      m_Pix[i] = compPix(m_Img1Pix[i], m_Img2Pix[i], p);
    }

    m_ImgSrc.newPixels();
    revalidate();
  }
  /** Processes the data and renders it to a component */
  public synchronized int process(Buffer buffer) {
    if (component == null) return BUFFER_PROCESSED_FAILED;

    Format inf = buffer.getFormat();
    if (inf == null) return BUFFER_PROCESSED_FAILED;

    if (inf != inputFormat || !buffer.getFormat().equals(inputFormat)) {
      if (setInputFormat(inf) != null) return BUFFER_PROCESSED_FAILED;
    }

    Object data = buffer.getData();
    if (!(data instanceof int[])) return BUFFER_PROCESSED_FAILED;

    if (lastBuffer != buffer) {
      lastBuffer = buffer;
      newImage(buffer);
    }

    sourceImage.newPixels(0, 0, inWidth, inHeight);

    Graphics g = component.getGraphics();
    if (g != null) {
      if (reqBounds == null) {
        bounds = component.getBounds();
        bounds.x = 0;
        bounds.y = 0;
      } else bounds = reqBounds;
      g.drawImage(
          destImage,
          bounds.x,
          bounds.y,
          bounds.width,
          bounds.height,
          0,
          0,
          inWidth,
          inHeight,
          component);
    }

    return BUFFER_PROCESSED_OK;
  }
 public Image getSection(int x, int y, int width, int height) {
   if (width > imgWidth || height > imgHeight) {
     // create new image source and pixel array
     size = width * height;
     pixels = new int[size];
     imageSource = new MemoryImageSource(width, height, pixels, 0, width);
     imageSource.setAnimated(true);
     // imageSource.setFullBufferUpdates(true);
     image = Toolkit.getDefaultToolkit().createImage(imageSource);
   }
   if (width > imgWidth || height > imgHeight || x != oldX || y != oldY) {
     // recreate pixel array
     int skipWidth = 0;
     if (width < imgWidth && height <= imgHeight) {
       skipWidth = imgWidth - width;
     }
     int index = 0;
     for (int aY = 0; aY < height; aY++) {
       for (int aX = 0; aX < width; aX++) {
         if (index >= size) {
           System.out.println("oops...");
         }
         // pixels[index] = encodeColor(stats.getValueAt(x + aX, y +
         // aY));
         pixels[index] = mapColor(stats.getValueAt(x + aX, y + aY));
         index++;
       }
       index += skipWidth; // skip pixels to the right of clip area
     }
     oldX = x;
     oldY = y;
     imageSource.newPixels(0, 0, width, height);
     // imageSource.newPixels();
   }
   if (width > imgWidth || height > imgHeight) {
     imgWidth = width;
     imgHeight = height;
   }
   return image;
 }
 /**
  * Sends a rectangular region of the buffer of pixels to any ImageConsumers that are currently
  * interested in the data for this image and notify them that an animation frame is complete. This
  * method only has effect if the animation flag has been turned on through the setAnimated()
  * method. If the full buffer update flag was turned on with the setFullBufferUpdates() method
  * then the rectangle parameters will be ignored and the entire buffer will always be sent.
  *
  * @param x the x coordinate of the upper left corner of the rectangle of pixels to be sent
  * @param y the y coordinate of the upper left corner of the rectangle of pixels to be sent
  * @param w the width of the rectangle of pixels to be sent
  * @param h the height of the rectangle of pixels to be sent
  * @see #newPixels(int, int, int, int, boolean)
  * @see ImageConsumer
  * @see #setAnimated
  * @see #setFullBufferUpdates
  */
 public synchronized void newPixels(int x, int y, int w, int h) {
   newPixels(x, y, w, h, true);
 }
 /**
  * Sends a whole new buffer of pixels to any ImageConsumers that are currently interested in the
  * data for this image and notify them that an animation frame is complete. This method only has
  * effect if the animation flag has been turned on through the setAnimated() method.
  *
  * @see #newPixels(int, int, int, int, boolean)
  * @see ImageConsumer
  * @see #setAnimated
  */
 public void newPixels() {
   newPixels(0, 0, width, height, true);
 }