public class ArrayConverter
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static int |
INT_SIZE |
private static int |
SHORT_SIZE |
Modifier | Constructor and Description |
---|---|
private |
ArrayConverter() |
Modifier and Type | Method and Description |
---|---|
private static void |
checkArray(byte[] array,
int offset,
int length)
Makes sure that the arguments define a valid (existing) array interval.
|
static void |
convertPacked2BitIntensityTo8Bit(byte[] src,
int srcOffset,
byte[] dest,
int destOffset,
int numPackedBytes)
Converts bytes with two four-bit-intensity samples to 8 byte intensity
values, each stored in one byte.
|
static void |
convertPacked4BitIntensityTo8Bit(byte[] src,
int srcOffset,
byte[] dest,
int destOffset,
int numPackedBytes)
Converts bytes with four two-bit-intensity samples to byte-sized intensity values.
|
static void |
copyPackedBytes(byte[] src,
int srcOffset,
int srcBitOffset,
byte[] dest,
int destOffset,
int destBitOffset,
int numSamples)
Copies a number of bit values from one byte array to another.
|
static void |
decodePacked1Bit(byte[] src,
int srcOffset,
byte[] dest,
int destOffset,
int numPackedBytes) |
static void |
decodePacked2Bit(byte[] src,
int srcOffset,
byte[] dest,
int destOffset,
int numPackedBytes)
Decodes bytes with four two-bit samples to single bytes.
|
static void |
decodePacked4Bit(byte[] src,
int srcOffset,
byte[] dest,
int destOffset,
int numPackedBytes)
Decodes bytes with two four-bit samples to single bytes.
|
static void |
decodePackedRGB565BigEndianToRGB24(byte[] src,
int srcOffset,
byte[] red,
int redOffset,
byte[] green,
int greenOffset,
byte[] blue,
int blueOffset,
int numPixels)
Convert 16 bit RGB samples stored in big endian (BE) byte order
with 5 bits for red and blue and 6 bits for green to 24
bit RGB byte samples.
|
static void |
encodePacked2Bit(byte[] src,
int srcOffset,
byte[] dest,
int destOffset,
int numSamples) |
static void |
encodePacked4Bit(byte[] src,
int srcOffset,
byte[] dest,
int destOffset,
int numSamples) |
static void |
encodeRGB24ToPackedRGB565BigEndian(byte[] red,
int redOffset,
byte[] green,
int greenOffset,
byte[] blue,
int blueOffset,
byte[] dest,
int destOffset,
int numPixels)
Convert 24 bit RGB pixels to 16 bit pixels stored in big endian (BE) byte order
with 5 bits for red and blue and 6 bits for green.
|
static int |
getIntBE(byte[] src,
int srcOffset)
Reads four consecutive bytes from the given array at the
given position in big endian order and returns them as
an
int . |
static int |
getIntLE(byte[] src,
int srcOffset)
Reads four consecutive bytes from the given array at the
given position in little endian order and returns them as
an
int . |
static short |
getShortBE(byte[] src,
int srcOffset)
Reads two consecutive bytes from the given array at the
given position in big endian order and returns them as
a
short . |
static int |
getShortBEAsInt(byte[] src,
int srcOffset) |
static short |
getShortLE(byte[] src,
int srcOffset)
Reads two consecutive bytes from the given array at the
given position in little endian order and returns them as
a
short . |
static void |
setIntBE(byte[] dest,
int destOffset,
int newValue)
Writes an int value into four consecutive bytes of a byte array,
in big endian (network) byte order.
|
static void |
setIntLE(byte[] dest,
int destOffset,
int newValue)
Writes an int value into four consecutive bytes of a byte array,
in little endian (Intel) byte order.
|
static void |
setShortBE(byte[] dest,
int destOffset,
short newValue) |
static void |
setShortLE(byte[] dest,
int destOffset,
short newValue) |
private static final int SHORT_SIZE
private static final int INT_SIZE
private static void checkArray(byte[] array, int offset, int length) throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
public static void convertPacked2BitIntensityTo8Bit(byte[] src, int srcOffset, byte[] dest, int destOffset, int numPackedBytes)
A little discussion on how to implement this method
was held in the German Java newsgroup
de.comp.lang.java.
The message I wrote to start the thread has the ID
1ef7du4vfqsd2pskb6jukut6pnhn87htt2@4ax.com
.
Read the
thread
at Google Groups.
src
- byte array, each byte stores four two-bit intensity valuessrcOffset
- index into srcdest
- byte array, each byte stores an eight-bit intensity valuesdestOffset
- index into destnumPackedBytes
- number of bytes in src to be decodedpublic static void convertPacked4BitIntensityTo8Bit(byte[] src, int srcOffset, byte[] dest, int destOffset, int numPackedBytes)
src
- byte array, each byte stores two four-bit intensity valuessrcOffset
- index into srcdest
- byte array, each byte stores an eight-bit intensity valuesdestOffset
- index into destnumPackedBytes
- number of bytes in src to be decodedpublic static void copyPackedBytes(byte[] src, int srcOffset, int srcBitOffset, byte[] dest, int destOffset, int destBitOffset, int numSamples)
src
- array from which is copiedsrcOffset
- index into the src array of the first byte from which is copiedsrcBitOffset
- first bit within src[srcOffset] from which is copied (0 is left-most, 1 is second left-most, 7 is right-most)dest
- array to which is copieddestOffset
- index into the dest array of the first byte to which is copieddestBitOffset
- first bit within dest[destOffset] to which is copied (0 is left-most, 1 is second left-most, 7 is right-most)numSamples
- number of bits to be copiedpublic static void decodePacked1Bit(byte[] src, int srcOffset, byte[] dest, int destOffset, int numPackedBytes)
public static void decodePacked2Bit(byte[] src, int srcOffset, byte[] dest, int destOffset, int numPackedBytes)
numPackedBytes
bytes at src[srcOffset]
(these will be read and interpreted) and
numPackedBytes * 4
at dest[destOffset]
(where the decoded
byte values will be stored.
src
- byte array, each byte stores four two-bit valuessrcOffset
- index into srcdest
- byte array, each byte stores a single decoded value (from 0 to 3)destOffset
- index into destnumPackedBytes
- number of bytes in src to be decodedpublic static void decodePacked4Bit(byte[] src, int srcOffset, byte[] dest, int destOffset, int numPackedBytes)
numPackedBytes
bytes at src[srcOffset]
(these will be read and interpreted) and
numPackedBytes * 2
at dest[destOffset]
(where the decoded
byte values will be stored.
src
- byte array, each byte stores two four-bit valuessrcOffset
- index into srcdest
- byte array, each byte stores a single decoded valuedestOffset
- index into destnumPackedBytes
- number of bytes in src to be decodedpublic static void decodePackedRGB565BigEndianToRGB24(byte[] src, int srcOffset, byte[] red, int redOffset, byte[] green, int greenOffset, byte[] blue, int blueOffset, int numPixels)
public static void encodePacked2Bit(byte[] src, int srcOffset, byte[] dest, int destOffset, int numSamples)
public static void encodePacked4Bit(byte[] src, int srcOffset, byte[] dest, int destOffset, int numSamples)
public static void encodeRGB24ToPackedRGB565BigEndian(byte[] red, int redOffset, byte[] green, int greenOffset, byte[] blue, int blueOffset, byte[] dest, int destOffset, int numPixels)
public static int getIntBE(byte[] src, int srcOffset)
int
.src
- the array from which bytes are readsrcOffset
- the index into the array from which the bytes are readpublic static int getIntLE(byte[] src, int srcOffset)
int
.src
- the array from which bytes are readsrcOffset
- the index into the array from which the bytes are readpublic static short getShortBE(byte[] src, int srcOffset)
short
.src
- the array from which two bytes are readsrcOffset
- the index into the array from which the two bytes are readpublic static int getShortBEAsInt(byte[] src, int srcOffset)
public static short getShortLE(byte[] src, int srcOffset)
short
.src
- the array from which two bytes are readsrcOffset
- the index into the array from which the two bytes are readpublic static void setIntBE(byte[] dest, int destOffset, int newValue)
dest
- the array to which bytes are writtendestOffset
- index of the array to which the first byte is writtennewValue
- the int value to be written to the arraypublic static void setIntLE(byte[] dest, int destOffset, int newValue)
dest
- the array to which bytes are writtendestOffset
- index of the array to which the first byte is writtennewValue
- the int value to be written to the arraypublic static void setShortBE(byte[] dest, int destOffset, short newValue)
public static void setShortLE(byte[] dest, int destOffset, short newValue)