Class SwtCompatibleRaster

java.lang.Object
java.awt.image.Raster
java.awt.image.WritableRaster
de.intarsys.cwt.swt.image.SwtCompatibleRaster

public class SwtCompatibleRaster extends WritableRaster
  • Field Details

    • bandOffset

      protected int bandOffset
      private band offset for use by native code
    • data

      protected byte[] data
      The image data array.
    • dataOffsets

      protected int[] dataOffsets
      Data offsets for each band of image data.
    • pixelStride

      protected int pixelStride
      Pixel stride of the image data contained in this Raster.
    • scanlineStride

      protected int scanlineStride
      Scanline stride of the image data contained in this Raster.
  • Constructor Details

  • Method Details

    • createChild

      public Raster createChild(int x, int y, int width, int height, int x0, int y0, int[] bandList)
      Creates a subraster given a region of the raster. The x and y coordinates specify the horizontal and vertical offsets from the upper-left corner of this raster to the upper-left corner of the subraster. A subset of the bands of the parent Raster may be specified. If this is null, then all the bands are present in the subRaster. A translation to the subRaster may also be specified. Note that the subraster will reference the same DataBuffer as the parent raster, but using different offsets.
      Overrides:
      createChild in class Raster
      Parameters:
      x - X offset.
      y - Y offset.
      width - Width (in pixels) of the subraster.
      height - Height (in pixels) of the subraster.
      x0 - Translated X origin of the subraster.
      y0 - Translated Y origin of the subraster.
      bandList - Array of band indices.
      Throws:
      RasterFormatException - if the specified bounding box is outside of the parent raster.
    • createCompatibleWritableRaster

      public WritableRaster createCompatibleWritableRaster()
      Creates a Raster with the same layout and the same width and height, and with new zeroed data arrays. If the Raster is a subRaster, this will call createCompatibleRaster(width, height).
      Overrides:
      createCompatibleWritableRaster in class Raster
    • createCompatibleWritableRaster

      public WritableRaster createCompatibleWritableRaster(int w, int h)
      Creates a Raster with the same layout but using a different width and height, and with new zeroed data arrays.
      Overrides:
      createCompatibleWritableRaster in class Raster
    • createWritableChild

      public WritableRaster createWritableChild(int x, int y, int width, int height, int x0, int y0, int[] bandList)
      Creates a Writable subRaster given a region of the Raster. The x and y coordinates specify the horizontal and vertical offsets from the upper-left corner of this Raster to the upper-left corner of the subRaster. A subset of the bands of the parent Raster may be specified. If this is null, then all the bands are present in the subRaster. A translation to the subRaster may also be specified. Note that the subRaster will reference the same DataBuffer as the parent Raster, but using different offsets.
      Overrides:
      createWritableChild in class WritableRaster
      Parameters:
      x - X offset.
      y - Y offset.
      width - Width (in pixels) of the subraster.
      height - Height (in pixels) of the subraster.
      x0 - Translated X origin of the subraster.
      y0 - Translated Y origin of the subraster.
      bandList - Array of band indices.
      Throws:
      RasterFormatException - if the specified bounding box is outside of the parent Raster.
    • getByteData

      public byte[] getByteData(int x, int y, int w, int h, byte[] outData)
      Returns a byte array of data elements from the specified rectangular region. An ArrayIndexOutOfBounds exception will be thrown at runtime if the pixel coordinates are out of bounds.
       byte[] bandData = raster.getByteData(x, y, w, h, null);
       int numDataElements = raster.getnumDataElements();
       byte[] pixel = new byte[numDataElements];
       // To find a data element at location (x2, y2)
       System.arraycopy(bandData, ((y2 - y) * w + (x2 - x)) * numDataElements, pixel,
                      0, numDataElements);
       
      Parameters:
      x - The X coordinate of the upper left pixel location.
      y - The Y coordinate of the upper left pixel location.
      outData - If non-null, data elements for all bands at the specified location are returned in this array.
      width - Width of the pixel rectangle.
      height - Height of the pixel rectangle.
      Returns:
      Data array with data elements for all bands.
    • getByteData

      public byte[] getByteData(int x, int y, int w, int h, int band, byte[] outData)
      Returns a byte array of data elements from the specified rectangular region for the specified band. An ArrayIndexOutOfBounds exception will be thrown at runtime if the pixel coordinates are out of bounds.
       byte[] bandData = raster.getByteData(x, y, w, h, null);
       
       // To find the data element at location (x2, y2)
       byte bandElement = bandData[((y2 - y) * w + (x2 - x))];
       
      Parameters:
      x - The X coordinate of the upper left pixel location.
      y - The Y coordinate of the upper left pixel location.
      band - The band to return.
      outData - If non-null, data elements for all bands at the specified location are returned in this array.
      width - Width of the pixel rectangle.
      height - Height of the pixel rectangle.
      Returns:
      Data array with data elements for all bands.
    • getDataElements

      public Object getDataElements(int x, int y, int w, int h, Object obj)
      Returns an array of data elements from the specified rectangular region. An ArrayIndexOutOfBounds exception will be thrown at runtime if the pixel coordinates are out of bounds. A ClassCastException will be thrown if the input object is non null and references anything other than an array of transferType.
       byte[] bandData = (byte[]) raster.getDataElements(x, y, w, h, null);
       int numDataElements = raster.getNumDataElements();
       byte[] pixel = new byte[numDataElements];
       // To find a data element at location (x2, y2)
       System.arraycopy(bandData, ((y2 - y) * w + (x2 - x)) * numDataElements, pixel,
                      0, numDataElements);
       
      Overrides:
      getDataElements in class Raster
      Parameters:
      x - The X coordinate of the upper left pixel location.
      y - The Y coordinate of the upper left pixel location.
      width - Width of the pixel rectangle.
      height - Height of the pixel rectangle.
      outData - An object reference to an array of type defined by getTransferType() and length w*h*getNumDataElements(). If null an array of appropriate type and size will be allocated.
      Returns:
      An object reference to an array of type defined by getTransferType() with the request pixel data.
    • getDataElements

      public Object getDataElements(int actualX, int actualY, Object obj)
      Returns the data elements for all bands at the specified location. An ArrayIndexOutOfBounds exception will be thrown at runtime if the pixel coordinate is out of bounds. A ClassCastException will be thrown if the input object is non null and references anything other than an array of transferType.
      Overrides:
      getDataElements in class Raster
      Parameters:
      actualX - The X coordinate of the pixel location.
      actualY - The Y coordinate of the pixel location.
      outData - An object reference to an array of type defined by getTransferType() and length getNumDataElements(). If null an array of appropriate type and size will be allocated.
      Returns:
      An object reference to an array of type defined by getTransferType() with the request pixel data.
    • getDataOffset

      public int getDataOffset(int band)
      Returns the data offset for the specified band. The data offset is the index into the data array in which the first sample of the first scanline is stored.
      Parameters:
      band - The band whose offset is returned.
    • getDataOffsets

      public int[] getDataOffsets()
      Returns a copy of the data offsets array. For each band the data offset is the index into the band's data array, of the first sample of the band.
    • getDataStorage

      public byte[] getDataStorage()
      Returns a reference to the data array.
    • getPixels

      public int[] getPixels(int x, int y, int w, int h, int[] iArray)
      Overrides:
      getPixels in class Raster
    • getPixelStride

      public int getPixelStride()
      Returns pixel stride -- the number of data array elements between two samples for the same band on the same scanline.
    • getSample

      public int getSample(int x, int y, int b)
      Overrides:
      getSample in class Raster
    • getSamples

      public int[] getSamples(int x, int y, int w, int h, int b, int[] iArray)
      Overrides:
      getSamples in class Raster
    • getScanlineStride

      public int getScanlineStride()
      Returns the scanline stride -- the number of data array elements between a given sample and the sample in the same column of the next row in the same band.
    • putByteData

      public void putByteData(int x, int y, int w, int h, byte[] inData)
      Stores a byte array of data elements into the specified rectangular region. An ArrayIndexOutOfBounds exception will be thrown at runtime if the pixel coordinates are out of bounds. The data elements in the data array are assumed to be packed. That is, a data element for the nth band at location (x2, y2) would be found at:
       inData[((y2 - y) * w + (x2 - x)) * numDataElements + n]
       
      Parameters:
      x - The X coordinate of the upper left pixel location.
      y - The Y coordinate of the upper left pixel location.
      w - Width of the pixel rectangle.
      h - Height of the pixel rectangle.
      inData - The data elements to be stored.
    • putByteData

      public void putByteData(int x, int y, int w, int h, int band, byte[] inData)
      Stores a byte array of data elements into the specified rectangular region for the specified band. An ArrayIndexOutOfBounds exception will be thrown at runtime if the pixel coordinates are out of bounds. The data elements in the data array are assumed to be packed. That is, a data element at location (x2, y2) would be found at:
       inData[((y2 - y) * w + (x2 - x)) + n]
       
      Parameters:
      x - The X coordinate of the upper left pixel location.
      y - The Y coordinate of the upper left pixel location.
      w - Width of the pixel rectangle.
      h - Height of the pixel rectangle.
      band - The band to set.
      inData - The data elements to be stored.
    • setDataElements

      public void setDataElements(int x, int y, int w, int h, Object obj)
      Stores an array of data elements into the specified rectangular region. An ArrayIndexOutOfBounds exception will be thrown at runtime if the pixel coordinates are out of bounds. A ClassCastException will be thrown if the input object is non null and references anything other than an array of transferType. The data elements in the data array are assumed to be packed. That is, a data element for the nth band at location (x2, y2) would be found at:
       inData[((y2 - y) * w + (x2 - x)) * numDataElements + n]
       
      Overrides:
      setDataElements in class WritableRaster
      Parameters:
      x - The X coordinate of the upper left pixel location.
      y - The Y coordinate of the upper left pixel location.
      w - Width of the pixel rectangle.
      h - Height of the pixel rectangle.
      inData - An object reference to an array of type defined by getTransferType() and length w*h*getNumDataElements() containing the pixel data to place between x,y and x+h, y+h.
    • setDataElements

      public void setDataElements(int x, int y, Object obj)
      Stores the data elements for all bands at the specified location. An ArrayIndexOutOfBounds exception will be thrown at runtime if the pixel coordinate is out of bounds. A ClassCastException will be thrown if the input object is non null and references anything other than an array of transferType.
      Overrides:
      setDataElements in class WritableRaster
      Parameters:
      x - The X coordinate of the pixel location.
      y - The Y coordinate of the pixel location.
      inData - An object reference to an array of type defined by getTransferType() and length getNumDataElements() containing the pixel data to place at x,y.
    • setDataElements

      public void setDataElements(int x, int y, Raster inRaster)
      Stores the Raster data at the specified location. An ArrayIndexOutOfBounds exception will be thrown at runtime if the pixel coordinates are out of bounds.
      Overrides:
      setDataElements in class WritableRaster
      Parameters:
      x - The X coordinate of the pixel location.
      y - The Y coordinate of the pixel location.
      inRaster - Raster of data to place at x,y location.
    • setPixels

      public void setPixels(int x, int y, int w, int h, int[] iArray)
      Overrides:
      setPixels in class WritableRaster
    • setRect

      public void setRect(int dx, int dy, Raster srcRaster)
      Overrides:
      setRect in class WritableRaster
    • setSample

      public void setSample(int x, int y, int b, int s)
      Overrides:
      setSample in class WritableRaster
    • setSamples

      public void setSamples(int x, int y, int w, int h, int b, int[] iArray)
      Overrides:
      setSamples in class WritableRaster
    • toString

      public String toString()
      Overrides:
      toString in class Object