1 32 package com.imagero.uio.buffer.arrays; 33 34 35 import com.imagero.uio.buffer.MemoryAccessManager; 36 37 44 public class ShortArrayBufferManager extends AbstractArrayBufferManager { 45 46 short[] data; 47 48 53 public ShortArrayBufferManager(short[] data) { 54 this(data, Math.min(TILE_SIZE, data.length)); 55 } 56 57 61 public ShortArrayBufferManager(short[] data, int size) { 62 this(data, 0, data.length, size); 63 } 64 65 70 public ShortArrayBufferManager(short[] data, int offset, int length) { 71 this(data, offset, length, TILE_SIZE); 72 } 73 74 80 public ShortArrayBufferManager(short[] data, int offset, int length, int size) { 81 this.data = data; 82 this.tileSize = size; 83 this.unitSize = 2; 84 this.length = length; 85 this.offset = offset; 86 accessManager = MemoryAccessManager.createMemoryAccessManager(); 87 } 88 89 98 protected int writeUnitLE(byte[] source, int sourceOffset, int destOffset) { 99 int v = ((source[sourceOffset++] & 0xFF)) 100 | (((source[sourceOffset++] & 0xFF)) << 8); 101 data[destOffset] = (short) v; 102 return sourceOffset; 103 } 104 105 114 protected int writeUnitBE(byte[] source, int sourceOffset, int destOffset) { 115 int v = ((source[sourceOffset++] & 0xFF) << 8) 116 | (source[sourceOffset++] & 0xFF); 117 data[destOffset] = (short) v; 118 return sourceOffset; 119 } 120 121 130 protected int readUnitBE(int offset, byte[] dest, int destOffset) { 131 int v = data[offset]; 132 dest[destOffset++] = (byte) ((v >>> 8) & 0xFF); 133 dest[destOffset++] = (byte) (v & 0xFF); 134 return destOffset; 135 } 136 137 146 protected int readUnitLE(int offset, byte[] dest, int destOffset) { 147 int v = data[offset]; 148 dest[destOffset++] = (byte) (v & 0xFF); 149 dest[destOffset++] = (byte) ((v >>> 8) & 0xFF); 150 return destOffset; 151 } 152 153 } 198 | Popular Tags |