Class MatrixToBufferedImage

java.lang.Object
net.algart.external.awt.MatrixToBufferedImage
Direct Known Subclasses:
MatrixToBufferedImage.InterleavedRGBToInterleaved, MatrixToBufferedImage.InterleavedToBandedRGB

public abstract class MatrixToBufferedImage extends Object
  • Constructor Details

    • MatrixToBufferedImage

      public MatrixToBufferedImage()
  • Method Details

    • isUnsignedInt32

      public boolean isUnsignedInt32()
    • setUnsignedInt32

      public MatrixToBufferedImage setUnsignedInt32(boolean unsignedInt32)
      Specifies how to convert 32-bit int values to bytes: by simple unsigned shift ">>>24" (true value) or via usual AlgART scaling: 0 to 0, Integer.MAX_VALUE to 255 (false value). This flag is used in toDataBuffer(Matrix) method.
      Parameters:
      unsignedInt32 - whether int values are considered to be unsigned 32-bit; default is false.
      Returns:
      a reference to this object.
    • toBufferedImage

      public final BufferedImage toBufferedImage(Matrix<? extends PArray> interleavedMatrix)
      Equivalent to toBufferedImage(interleavedMatrix, null).
      Parameters:
      interleavedMatrix - the interleaved matrix.
      Returns:
      the BufferedImage with the same data.
    • toBufferedImage

      public final BufferedImage toBufferedImage(Matrix<? extends PArray> interleavedMatrix, DataBuffer dataBuffer)
      Converts the given interleaved matrix (2- or 3-dimensional) into BufferedImage. Note: dataBuffer!=null, then the elements of the given matrix ignored, but the data of the given buffer are used instead. (It is supposed, that this buffer was created by toDataBuffer(net.algart.arrays.Matrix) method, maybe with some post-processing.)
      Parameters:
      interleavedMatrix - the interleaved matrix.
      dataBuffer - the data for BufferedImage; may be null, then it is automatically created as toDataBuffer(interleavedMatrix).
      Returns:
      the BufferedImage with the same data.
    • getWidth

      public int getWidth(Matrix<? extends PArray> interleavedMatrix)
      Returns the x-dimension of the image, corresponding to the given interleaved matrix. Note that it is int, not long (AWT images have 31-bit dimensions).
      Parameters:
      interleavedMatrix - the interleaved matrix.
      Returns:
      the width of the corresponding image.
    • getHeight

      public int getHeight(Matrix<? extends PArray> interleavedMatrix)
      Returns the y-dimension of the image, corresponding to the given interleaved matrix. Note that it is int, not long (AWT images have 31-bit dimensions).
      Parameters:
      interleavedMatrix - the interleaved matrix.
      Returns:
      the height of the corresponding image.
    • getBandCount

      public int getBandCount(Matrix<? extends PArray> interleavedMatrix)
      Returns the number of color bands of the image, corresponding to the given interleaved matrix. For example, it is 3 for RGB image or 4 for RGB-Alpha.
      Parameters:
      interleavedMatrix - the interleaved matrix.
      Returns:
      the corresponding number of color bands.
    • toDataBuffer

      public final DataBuffer toDataBuffer(Matrix<? extends PArray> interleavedMatrix)
      Converts the given interleaved matrix (2- or 3-dimensional) into java.awt.image.DataBuffer. This method is useful in addition to toBufferedImage(Matrix, java.awt.image.DataBuffer), if you want to do something with the created DataBuffer, for example, to correct some its pixels.

      This method automatically converts the source data to byte (8-bit) array, if bytesRequired() returns true.

      Parameters:
      interleavedMatrix - the interleaved data.
      Returns:
      the newly allocated DataBuffer with the same data.
    • colorValue

      public long colorValue(Matrix<? extends PArray> interleavedMatrix, Color color, int bankIndex)
      Converts the color into a form, stored in the data buffer, returned by toDataBuffer(Matrix).

      The default implementation is suitable for monochrome, indexed and multi-bank data buffers.

      Note: if the interleaved matrix is monochrome or indexed, i.e. getBandCount(interleavedMatrix)==1, this method returns

       Math.round(0.3 * color.getRed() + 0.59 * color.getGreen() + 0.11 * color.getBlue())
       

      The good idea is to provide identical R, G, B color components in such cases (if this method is not overridden).

      Parameters:
      interleavedMatrix - the interleaved data.
      color - some color.
      bankIndex - index of the bank in terms of java.awt.image.DataBuffer.
      Returns:
      the corresponded component of this color or interleaved RGB-Alpha value, depending on the structure of the data buffer.
    • bytesRequired

      public boolean bytesRequired()
      Returns true if the AlgART array or matrix, passed to the methods of this class, must contain byte elements. In this case, this class converts all other element types into byte (but the client may do this itself).

      The default implementation returns true. Please override this method if your implementation forms specific versions of java.awt.image.DataBuffer for non-byte element types.

    • palette

      public byte[][] palette()
      Returns the palette (byte[4][256]) if the indexed image is supposed.

      The default implementation returns null, that means non-indexed image.

      Returns:
      the palette or null if the image should be not indexed.
    • toDataBuffer

      protected abstract DataBuffer toDataBuffer(PArray interleavedArray, int bandCount)
      Actual method, on which toDataBuffer(Matrix) is based.

      The passed AlgART array must be direct accessible.

      Parameters:
      interleavedArray - the interleaved data.
      bandCount - the number of bands: if called from toDataBuffer(Matrix), it is 1 for 2-dimensional matrix and dim(0) for 3-dimensional matrix.
      Returns:
      the newly allocated DataBuffer with the same data.
    • rgbAlphaMasks

      protected int[] rgbAlphaMasks(int bandCount)
      Returns the band masks, which will be passed to Raster.createPackedRaster method, if you want to convert data into a packed BufferedImage. The resulting array may be null, that means an unpacked form of the raster (Raster.createBandedRaster), or an array containing bandCount elements: red, green, blue and (if necessary) alpha masks.
      Parameters:
      bandCount - the number of masks (3 or 4, in other cases null is returned).
      Returns:
      the bit masks for storing bands in the packed int values.
    • getDataArray

      public static Object getDataArray(DataBuffer dataBuffer, int bankIndex)
      Equivalent to dataBuffer.getData(bankIndex) for the corresponding specific element type. It can be used, for example, together with SimpleMemoryModel.asUpdatableArray(Object) method.
      Parameters:
      dataBuffer - the data buffer.
      bankIndex - the band index.
      Returns:
      the data array for the specified bank.
    • toDataBufferBand0Filter

      protected void toDataBufferBand0Filter(byte[] src, int srcPos, byte[] dest)