本文整理汇总了Java中java.nio.ShortBuffer.get方法的典型用法代码示例。如果您正苦于以下问题:Java ShortBuffer.get方法的具体用法?Java ShortBuffer.get怎么用?Java ShortBuffer.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.ShortBuffer
的用法示例。
在下文中一共展示了ShortBuffer.get方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testShortGet
import java.nio.ShortBuffer; //导入方法依赖的package包/类
@Test(dataProvider = "shortViewProvider")
public void testShortGet(String desc, IntFunction<ByteBuffer> fbb,
Function<ByteBuffer, ShortBuffer> fbi) {
ByteBuffer bb = allocate(fbb);
ShortBuffer vb = fbi.apply(bb);
int o = bb.position();
for (int i = 0; i < vb.limit(); i++) {
short fromBytes = getShortFromBytes(bb, o + i * 2);
short fromMethodView = bb.getShort(o + i * 2);
assertValues(i, fromBytes, fromMethodView, bb);
short fromBufferView = vb.get(i);
assertValues(i, fromMethodView, fromBufferView, bb, vb);
}
for (int i = 0; i < vb.limit(); i++) {
short v = getShortFromBytes(bb, o + i * 2);
short a = bb.getShort();
assertValues(i, v, a, bb);
short b = vb.get();
assertValues(i, a, b, bb, vb);
}
}
示例2: remix
import java.nio.ShortBuffer; //导入方法依赖的package包/类
@Override
public void remix(final ShortBuffer inSBuff, final ShortBuffer outSBuff) {
// Up-mix mono to stereo
final int inRemaining = inSBuff.remaining();
final int outSpace = outSBuff.remaining() / 2;
final int samplesToBeProcessed = Math.min(inRemaining, outSpace);
for (int i = 0; i < samplesToBeProcessed; ++i) {
final short inSample = inSBuff.get();
outSBuff.put(inSample);
outSBuff.put(inSample);
}
}
示例3: setStrikethroughMetrics
import java.nio.ShortBuffer; //导入方法依赖的package包/类
private void setStrikethroughMetrics(ByteBuffer os_2Table, int upem) {
if (os_2Table == null || os_2Table.capacity() < 30 || upem < 0) {
stSize = .05f;
stPos = -.4f;
return;
}
ShortBuffer sb = os_2Table.asShortBuffer();
stSize = sb.get(13) / (float)upem;
stPos = -sb.get(14) / (float)upem;
}
示例4: initAllNames
import java.nio.ShortBuffer; //导入方法依赖的package包/类
protected void initAllNames(int requestedID, HashSet<String> names) {
byte[] name = new byte[256];
ByteBuffer buffer = getTableBuffer(nameTag);
if (buffer != null) {
ShortBuffer sbuffer = buffer.asShortBuffer();
sbuffer.get(); // format - not needed.
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);
continue; // skip over this record.
}
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 == requestedID) {
buffer.position(namePtr);
buffer.get(name, 0, nameLen);
names.add(makeString(name, nameLen, platformID, encodingID));
}
}
}
}
示例5: getStyleMetrics
import java.nio.ShortBuffer; //导入方法依赖的package包/类
@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;
}
示例6: initAllNames
import java.nio.ShortBuffer; //导入方法依赖的package包/类
protected void initAllNames(int requestedID, HashSet names) {
byte[] name = new byte[256];
ByteBuffer buffer = getTableBuffer(nameTag);
if (buffer != null) {
ShortBuffer sbuffer = buffer.asShortBuffer();
sbuffer.get(); // format - not needed.
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);
continue; // skip over this record.
}
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 == requestedID) {
buffer.position(namePtr);
buffer.get(name, 0, nameLen);
names.add(makeString(name, nameLen, encodingID));
}
}
}
}
示例7: remix
import java.nio.ShortBuffer; //导入方法依赖的package包/类
@Override
public void remix(final ShortBuffer inSBuff, final ShortBuffer outSBuff) {
// Down-mix stereo to mono
// Viktor Toth's algorithm -
// See: http://www.vttoth.com/CMS/index.php/technical-notes/68
// http://stackoverflow.com/a/25102339
final int inRemaining = inSBuff.remaining() / 2;
final int outSpace = outSBuff.remaining();
final int samplesToBeProcessed = Math.min(inRemaining, outSpace);
for (int i = 0; i < samplesToBeProcessed; ++i) {
// Convert to unsigned
final int a = inSBuff.get() + SIGNED_SHORT_LIMIT;
final int b = inSBuff.get() + SIGNED_SHORT_LIMIT;
int m;
// Pick the equation
if ((a < SIGNED_SHORT_LIMIT) || (b < SIGNED_SHORT_LIMIT)) {
// Viktor's first equation when both sources are "quiet"
// (i.e. less than middle of the dynamic range)
m = a * b / SIGNED_SHORT_LIMIT;
} else {
// Viktor's second equation when one or both sources are loud
m = 2 * (a + b) - (a * b) / SIGNED_SHORT_LIMIT - UNSIGNED_SHORT_MAX;
}
// Convert output back to signed short
if (m == UNSIGNED_SHORT_MAX + 1) m = UNSIGNED_SHORT_MAX;
outSBuff.put((short) (m - SIGNED_SHORT_LIMIT));
}
}
示例8: setUnderlineMetrics
import java.nio.ShortBuffer; //导入方法依赖的package包/类
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;
}
示例9: lookupName
import java.nio.ShortBuffer; //导入方法依赖的package包/类
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();
sbuffer.get(); // format - not needed.
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);
continue; // skip over this record.
}
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;
}
示例10: lookupElevation
import java.nio.ShortBuffer; //导入方法依赖的package包/类
private static double lookupElevation(ShortBuffer shortBuffer,
double lat, double lon,
double minX, double maxX, double minY, double maxY,
int width, int height,
int bgColor) {
final int tileHeight = height;
final int tileWidth = width;
final double sectorDeltaLat = maxY - minY;
final double sectorDeltaLon = maxX - minX;
final double dLat = maxY - lat;
final double dLon = lon - minX;
final double sLat = dLat / sectorDeltaLat;
final double sLon = dLon / sectorDeltaLon;
int j = (int) ((tileHeight - 1) * sLat);
int i = (int) ((tileWidth - 1) * sLon);
int k = j * tileWidth + i;
if (k >= tileHeight * tileWidth) return bgColor;
if (k < 0) return bgColor;
double eLeft = shortBuffer.get(k);
double eRight = i < (tileWidth - 1) ? shortBuffer.get(k + 1) : eLeft;
if (bgColor == eLeft)
eLeft = eRight;
if (bgColor == eRight)
eRight = eLeft;
double dw = sectorDeltaLon / (tileWidth - 1);
double dh = sectorDeltaLat / (tileHeight - 1);
double ssLon = (dLon - i * dw) / dw;
double ssLat = (dLat - j * dh) / dh;
double eTop = eLeft + ssLon * (eRight - eLeft);
if (j < tileHeight - 1 && i < tileWidth - 1)
{
eLeft = shortBuffer.get(k + tileWidth);
eRight = shortBuffer.get(k + tileWidth + 1);
if (bgColor == eLeft)
eLeft = eRight;
if (bgColor == eRight)
eRight = eLeft;
}
double eBot = eLeft + ssLon * (eRight - eLeft);
if (eTop == bgColor)
eTop = eBot;
if (eBot == bgColor)
eBot = eTop;
return eTop + ssLat * (eBot - eTop);
}
示例11: lookupName
import java.nio.ShortBuffer; //导入方法依赖的package包/类
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();
sbuffer.get(); // format - not needed.
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);
continue; // skip over this record.
}
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, platformID, encodingID);
if (langID == findLocaleID) {
return foundName;
}
}
}
}
return foundName;
}
示例12: getShort
import java.nio.ShortBuffer; //导入方法依赖的package包/类
short getShort(ShortBuffer vb, int i) { ck(vb.get(i / 2), getShortX(i)); return vb.get(i / 2); }