Class PixelFormatUtil


  • public class PixelFormatUtil
    extends Object
    Pixel Rectangle Utilities.

    All conversion methods are endian independent.

    • Constructor Detail

      • PixelFormatUtil

        public PixelFormatUtil()
    • Method Detail

      • getShiftedI32

        public static int getShiftedI32​(int bytesPerPixel,
                                        byte[] data,
                                        int offset)
        Returns shifted bytes from the given data at given offset of maximal 4 bytesPerPixel.
        Parameters:
        bytesPerPixel - number of bytes per pixel to fetch, a maximum of 4 are allowed
        data - byte buffer covering complete pixel at position offset
        offset - byte offset of pixel data start
        Returns:
        the shifted 32bit integer value of the pixel
      • getShiftedI64

        public static long getShiftedI64​(int bytesPerPixel,
                                         byte[] data,
                                         int offset)
        Returns shifted bytes from the given data at given offset of maximal 8 bytesPerPixel.
        Parameters:
        bytesPerPixel - number of bytes per pixel to fetch, a maximum of 4 are allowed
        data - byte buffer covering complete pixel at position offset
        offset - byte offset of pixel data start
        Returns:
        the shifted 64bit integer value of the pixel
      • getShiftedI32

        public static int getShiftedI32​(int bytesPerPixel,
                                        ByteBuffer data,
                                        boolean retainDataPos)
        Returns shifted bytes from the given data at current position of maximal 4 bytesPerPixel.
        Parameters:
        bytesPerPixel - number of bytes per pixel to fetch, a maximum of 4 are allowed
        data - byte buffer covering complete pixel at position offset
        retainDataPos - if true, absolute ByteBuffer.get(int) is used and the data position stays unchanged. Otherwise relative ByteBuffer.get() is used and the data position changes.
        Returns:
        the shifted 32bit integer value of the pixel
      • getShiftedI64

        public static long getShiftedI64​(int bytesPerPixel,
                                         ByteBuffer data,
                                         boolean retainDataPos)
        Returns shifted bytes from the given data at current position of maximal 8 bytesPerPixel.
        Parameters:
        bytesPerPixel - number of bytes per pixel to fetch, a maximum of 4 are allowed
        data - byte buffer covering complete pixel at position offset
        retainDataPos - if true, absolute ByteBuffer.get(int) is used and the data position stays unchanged. Otherwise relative ByteBuffer.get() is used and the data position changes.
        Returns:
        the shifted 64bit integer value of the pixel
      • convertToInt32

        public static int convertToInt32​(PixelFormat dst_fmt,
                                         byte r,
                                         byte g,
                                         byte b,
                                         byte a)
      • convertToInt32

        public static int convertToInt32​(PixelFormat dest_fmt,
                                         PixelFormat src_fmt,
                                         int src_pixel)
      • convert

        public static void convert​(int width,
                                   int height,
                                   ByteBuffer src_bb,
                                   PixelFormat src_fmt,
                                   boolean src_glOriented,
                                   int src_lineStride,
                                   ByteBuffer dst_bb,
                                   PixelFormat dst_fmt,
                                   boolean dst_glOriented,
                                   int dst_lineStride)
                            throws IllegalStateException,
                                   IllegalArgumentException
        Parameters:
        width - width of the to be converted pixel rectangle
        height - height of the to be converted pixel rectangle
        src_bb - ByteBuffer source
        src_fmt - source PixelFormat
        src_glOriented - if true, the source memory is laid out in OpenGL's coordinate system, origin at bottom left, otherwise origin at top left.
        src_lineStride - line stride in byte-size for source, i.e. byte count from one line to the next. Must be >= src_fmt.comp.bytesPerPixel() * width or zero for default stride.
        dst_bb - ByteBuffer sink
        dst_fmt - destination PixelFormat
        dst_glOriented - if true, the source memory is laid out in OpenGL's coordinate system, origin at bottom left, otherwise origin at top left.
        dst_lineStride - line stride in byte-size for destination, i.e. byte count from one line to the next. Must be >= dst_fmt.comp.bytesPerPixel() * width or zero for default stride.
        Throws:
        IllegalStateException
        IllegalArgumentException - if src_lineStride or dst_lineStride is invalid