Пример #1
0
 /**
  * Set the image value in the given writable field.
  * <P>
  * Image values are specified using a width, height and the number of
  * components. The number of items in the pixels array must be at least
  * <CODE>width * height<CODE>. If there are less items than this an
  * ArrayIndexOutOfBoundsException will be generated. The integer values
  * are represented according to the number of components. If the integer
  * contains values in bytes that are not used by the number of components
  * for that image, the values are ignored.
  * <P>
  * <B>1 Component Images</B><BR>
  * The integer has the intensity value stored in the lowest byte and can be
  * obtained:
  * <PRE>
  *    intensity = (pixel[i]     ) & 0xFF;
  * </PRE>
  * <P>
  * <B>2 Component Images</B><BR>
  * The integer has the transparency value stored in the lowest byte and the
  * intensity in the next byte:
  * <PRE>
  *    intensity = (pixel[i] >> 8) & 0xFF;
  *    alpha     = (pixel[i]     ) & 0xFF;
  * </PRE>
  * <P>
  * <B>3 Component Images</B><BR>
  * The three color components are stored in the integer array as follows:
  * <PRE>
  *    red   = (pixel[i] >> 16) & 0xFF;
  *    green = (pixel[i] >>  8) & 0xFF;
  *    blue  = (pixel[i]      ) & 0xFF;
  * </PRE>
  * <P>
  * <B>4 Component Images</B><BR>
  * The integer has the value stored in the array as follows:
  * <PRE>
  *    red   = (pixel[i] >> 24) & 0xFF;
  *    green = (pixel[i] >> 16) & 0xFF;
  *    blue  = (pixel[i] >>  8) & 0xFF;
  *    alpha = (pixel[i]      ) & 0xFF;
  * </PRE>
  * <P>
  * The width and height values must be greater than or equal to zero. The
  * number of components is between 1 and 4. Any value outside of these
  * bounds will generate an IllegalArgumentException.
  *
  * @param imgIndex The index of the image in the array
  * @param width The width of the image in pixels
  * @param height The height of the image in pixels
  * @param components The number of colour components [1-4]
  * @param pixels The array of pixel values as specified above.
  *
  * @exception IllegalArgumentException The number of components or width/
  *    height are illegal values.
  * @exception ArrayIndexOutOfBoundsException The number of pixels provided by the
  *    caller is not enough for the width * height.
  */
 public void set1Value(int imgIndex, int width, int height, int components, int[] pixels) {
   if (imgIndex < 0) throw new ArrayIndexOutOfBoundsException();
   if (width < 0 || height < 0 || components < 0 || components > 4)
     throw new IllegalArgumentException();
   checkWriteAccess();
   synchronized (theEventQueue.eventLock) {
     MFImageWrapper queuedElement = (MFImageWrapper) theEventQueue.getLast(this);
     if (queuedElement == null || !queuedElement.isSetOneValue) {
       // Input and output buffers do not mix
       if (!storedInput && !storedOutput) {
         // Avoid clogging this buffer if
         // index out of bounds
         if (imgIndex >= storedInputValue.length) throw new ArrayIndexOutOfBoundsException();
         queuedElement = this;
         loadInputValue();
         isSetOneValue = true;
       } else {
         // If this generates an ArrayIndexOutOfBounds its okay,
         // the element will be garbage.
         queuedElement =
             new MFImageWrapper(theNode, fieldIndex, theEventQueue, theEventAdapterFactory, true);
         queuedElement.isSetOneValue = true;
       }
       queuedElement.rewriteImageToSize(imgIndex, width, height);
       int startingIndex = queuedElement.findStartOfInputImage(imgIndex);
       queuedElement.storedInputValue[startingIndex + 2] = components;
       if (pixels.length != 0)
         System.arraycopy(
             pixels, 0, queuedElement.storedInputValue, startingIndex + 3, pixels.length);
       theEventQueue.processEvent(queuedElement);
     } else {
       checkDataSanity();
       queuedElement.rewriteImageToSize(imgIndex, width, height);
       int startingIndex = queuedElement.findStartOfInputImage(imgIndex);
       queuedElement.storedInputValue[startingIndex + 2] = components;
       if (pixels.length != 0)
         System.arraycopy(
             pixels, 0, queuedElement.storedInputValue, startingIndex + 3, pixels.length);
     }
   }
 }
Пример #2
0
 /**
  * Set the image value in the given writable field to the new image defined by a set of pixels.
  *
  * <p>
  *
  * @param imgIndex The index of the image in the array
  * @param img The new image to use as the source
  */
 public void setImage(int imgIndex, RenderedImage img)
     throws InvalidOperationTimingException, InvalidFieldValueException,
         InvalidWritableFieldException, InvalidFieldException {
   if (imgIndex < 0) throw new ArrayIndexOutOfBoundsException();
   checkWriteAccess();
   synchronized (theEventQueue.eventLock) {
     MFImageWrapper queuedElement = (MFImageWrapper) theEventQueue.getLast(this);
     if (queuedElement == null || !queuedElement.isSetOneValue) {
       // Input and output buffers do not mix
       if (!storedInput && !storedOutput) {
         // Avoid clogging this buffer if
         // index out of bounds
         if (imgIndex < 0) throw new ArrayIndexOutOfBoundsException();
         loadInputValue();
         if (imgIndex >= storedInputValue.length) throw new ArrayIndexOutOfBoundsException();
         queuedElement = this;
         loadInputValue();
         isSetOneValue = true;
       } else {
         // If this generates an ArrayIndexOutOfBounds its okay,
         // the element will be garbage.
         queuedElement =
             new MFImageWrapper(theNode, fieldIndex, theEventQueue, theEventAdapterFactory, true);
         queuedElement.isSetOneValue = true;
       }
       queuedElement.rewriteImageToSize(imgIndex, img.getWidth(), img.getHeight());
       SFImageUtils.convertRenderedImageToData(
           img, queuedElement.storedInputValue, queuedElement.findStartOfInputImage(imgIndex));
       theEventQueue.processEvent(queuedElement);
     } else {
       checkDataSanity();
       queuedElement.rewriteImageToSize(imgIndex, img.getWidth(), img.getHeight());
       SFImageUtils.convertRenderedImageToData(
           img, queuedElement.storedInputValue, queuedElement.findStartOfInputImage(imgIndex));
       queuedElement.getSize();
     }
   }
 }