use of java.nio.ShortBuffer in project android_frameworks_base by crdroidandroid.
the class GLLogWrapper method doArrayElement.
private void doArrayElement(StringBuilder builder, boolean enabled, String name, PointerInfo pointer, int index) {
if (!enabled) {
return;
}
builder.append(" ");
builder.append(name + ":{");
if (pointer == null || pointer.mTempByteBuffer == null) {
builder.append("undefined }");
return;
}
if (pointer.mStride < 0) {
builder.append("invalid stride");
return;
}
int stride = pointer.getStride();
ByteBuffer byteBuffer = pointer.mTempByteBuffer;
int size = pointer.mSize;
int type = pointer.mType;
int sizeofType = pointer.sizeof(type);
int byteOffset = stride * index;
for (int i = 0; i < size; i++) {
if (i > 0) {
builder.append(", ");
}
switch(type) {
case GL_BYTE:
{
byte d = byteBuffer.get(byteOffset);
builder.append(Integer.toString(d));
}
break;
case GL_UNSIGNED_BYTE:
{
byte d = byteBuffer.get(byteOffset);
builder.append(Integer.toString(0xff & d));
}
break;
case GL_SHORT:
{
ShortBuffer shortBuffer = byteBuffer.asShortBuffer();
short d = shortBuffer.get(byteOffset / 2);
builder.append(Integer.toString(d));
}
break;
case GL_FIXED:
{
IntBuffer intBuffer = byteBuffer.asIntBuffer();
int d = intBuffer.get(byteOffset / 4);
builder.append(Integer.toString(d));
}
break;
case GL_FLOAT:
{
FloatBuffer intBuffer = byteBuffer.asFloatBuffer();
float d = intBuffer.get(byteOffset / 4);
builder.append(Float.toString(d));
}
break;
default:
builder.append("?");
break;
}
byteOffset += sizeofType;
}
builder.append("}");
}
use of java.nio.ShortBuffer in project JMRI by JMRI.
the class JavaSoundAudioBuffer method convertAudioEndianness.
/**
* Converts the endianness of an AudioBuffer to the format required by the
* JRE.
*
* @param audioData byte array containing the read PCM data
* @param twoByteSamples true if 16-bits per sample
* @return byte array containing converted PCM data
*/
private static byte[] convertAudioEndianness(byte[] audioData, boolean twoByteSamples) {
// Create ByteBuffer for output and set endianness
ByteBuffer out = ByteBuffer.allocate(audioData.length);
out.order(ByteOrder.nativeOrder());
// Wrap the audioData into a ByteBuffer for input and set endianness
// (always Little Endian for a WAV file)
ByteBuffer in = ByteBuffer.wrap(audioData);
in.order(ByteOrder.LITTLE_ENDIAN);
// Check if we have double-byte samples (i.e. 16-bit)
if (twoByteSamples) {
// If so, create ShortBuffer views of the in and out ByteBuffers
// for further processing
ShortBuffer outShort = out.asShortBuffer();
ShortBuffer inShort = in.asShortBuffer();
// Loop through appending data to the output buffer
while (inShort.hasRemaining()) {
outShort.put(inShort.get());
}
} else {
// Otherwise, just loop through appending data to the output buffer
while (in.hasRemaining()) {
out.put(in.get());
}
}
// Rewind the ByteBuffer
out.rewind();
// Convert output to an array if necessary
if (!out.hasArray()) {
// Allocate space
byte[] array = new byte[out.capacity()];
// fill the array
out.get(array);
// clear the ByteBuffer
out.clear();
return array;
}
return out.array();
}
use of java.nio.ShortBuffer in project jdk8u_jdk by JetBrains.
the class TrueTypeFont method lookupName.
/* Return the requested name in the requested locale, for the
* MS platform ID. If the requested locale isn't found, return US
* English, if that isn't found, return null and let the caller
* figure out how to handle that.
*/
protected String lookupName(short findLocaleID, int findNameID) {
String foundName = null;
byte[] name = new byte[1024];
ByteBuffer buffer = getTableBuffer(nameTag);
if (buffer != null) {
ShortBuffer sbuffer = buffer.asShortBuffer();
// format - not needed.
sbuffer.get();
short numRecords = sbuffer.get();
/* The name table uses unsigned shorts. Many of these
* are known small values that fit in a short.
* The values that are sizes or offsets into the table could be
* greater than 32767, so read and store those as ints
*/
int stringPtr = ((int) sbuffer.get()) & 0xffff;
for (int i = 0; i < numRecords; i++) {
short platformID = sbuffer.get();
if (platformID != MS_PLATFORM_ID) {
sbuffer.position(sbuffer.position() + 5);
// skip over this record.
continue;
}
short encodingID = sbuffer.get();
short langID = sbuffer.get();
short nameID = sbuffer.get();
int nameLen = ((int) sbuffer.get()) & 0xffff;
int namePtr = (((int) sbuffer.get()) & 0xffff) + stringPtr;
if (nameID == findNameID && ((foundName == null && langID == ENGLISH_LOCALE_ID) || langID == findLocaleID)) {
buffer.position(namePtr);
buffer.get(name, 0, nameLen);
foundName = makeString(name, nameLen, encodingID);
if (langID == findLocaleID) {
return foundName;
}
}
}
}
return foundName;
}
use of java.nio.ShortBuffer in project jdk8u_jdk by JetBrains.
the class TrueTypeFont method getStyleMetrics.
@Override
public void getStyleMetrics(float pointSize, float[] metrics, int offset) {
if (ulSize == 0f && ulPos == 0f) {
ByteBuffer head_Table = getTableBuffer(headTag);
int upem = -1;
if (head_Table != null && head_Table.capacity() >= 18) {
ShortBuffer sb = head_Table.asShortBuffer();
upem = sb.get(9) & 0xffff;
if (upem < 16 || upem > 16384) {
upem = 2048;
}
}
ByteBuffer os2_Table = getTableBuffer(os_2Tag);
setStrikethroughMetrics(os2_Table, upem);
ByteBuffer post_Table = getTableBuffer(postTag);
setUnderlineMetrics(post_Table, upem);
}
metrics[offset] = stPos * pointSize;
metrics[offset + 1] = stSize * pointSize;
metrics[offset + 2] = ulPos * pointSize;
metrics[offset + 3] = ulSize * pointSize;
}
use of java.nio.ShortBuffer in project jdk8u_jdk by JetBrains.
the class TrueTypeFont method setUnderlineMetrics.
private void setUnderlineMetrics(ByteBuffer postTable, int upem) {
if (postTable == null || postTable.capacity() < 12 || upem < 0) {
ulSize = .05f;
ulPos = .1f;
return;
}
ShortBuffer sb = postTable.asShortBuffer();
ulSize = sb.get(5) / (float) upem;
ulPos = -sb.get(4) / (float) upem;
}
Aggregations