1 32 package com.imagero.uio.buffer.arrays; 33 34 35 import com.imagero.uio.buffer.MemoryAccessManager; 36 37 44 public class LongArrayBufferManager extends AbstractArrayBufferManager { 45 46 long[] data; 47 48 53 public LongArrayBufferManager(long[] data) { 54 this(data, Math.min(TILE_SIZE, data.length)); 55 } 56 57 61 public LongArrayBufferManager(long[] data, int size) { 62 this(data, 0, data.length, size); 63 } 64 65 70 public LongArrayBufferManager(long[] data, int offset, int length) { 71 this(data, offset, length, TILE_SIZE); 72 } 73 74 80 public LongArrayBufferManager(long[] data, int offset, int length, int size) { 81 this.data = data; 82 this.tileSize = size; 83 this.unitSize = 8; 84 this.length = length; 85 this.offset = offset; 86 accessManager = MemoryAccessManager.createMemoryAccessManager(); 87 } 88 89 98 protected int writeUnitBE(byte[] source, int sourceOffset, int destOffset) { 99 long v = ((long) (source[sourceOffset++] & 0xFF) << 56) 100 | ((long) (source[sourceOffset++] & 0xFF) << 48) 101 | ((long) (source[sourceOffset++] & 0xFF) << 40) 102 | ((long) (source[sourceOffset++] & 0xFF) << 32) 103 | ((long) (source[sourceOffset++] & 0xFF) << 24) 104 | ((long) (source[sourceOffset++] & 0xFF) << 16) 105 | ((long) (source[sourceOffset++] & 0xFF) << 8) 106 | (source[sourceOffset++] & 0xFF); 107 108 data[destOffset] = v; 109 return sourceOffset; 110 } 111 112 121 protected int writeUnitLE(byte[] source, int sourceOffset, int destOffset) { 122 long v = (source[sourceOffset++] & 0xFF) 123 | ((long) (source[sourceOffset++] & 0xFF) << 8) 124 | ((long) (source[sourceOffset++] & 0xFF) << 16) 125 | ((long) (source[sourceOffset++] & 0xFF) << 24) 126 | ((long) (source[sourceOffset++] & 0xFF) << 32) 127 | ((long) (source[sourceOffset++] & 0xFF) << 40) 128 | ((long) (source[sourceOffset++] & 0xFF) << 48) 129 | ((long) (source[sourceOffset++] & 0xFF) << 56); 130 data[destOffset] = v; 131 return sourceOffset; 132 } 133 134 143 protected int readUnitLE(int offset, byte[] dest, int destOffset) { 144 long v = data[offset]; 145 dest[destOffset++] = (byte) (v & 0xFF); 146 dest[destOffset++] = (byte) ((v >>> 8) & 0xFF); 147 dest[destOffset++] = (byte) ((v >>> 16) & 0xFF); 148 dest[destOffset++] = (byte) ((v >>> 24) & 0xFF); 149 dest[destOffset++] = (byte) ((v >>> 32) & 0xFF); 150 dest[destOffset++] = (byte) ((v >>> 40) & 0xFF); 151 dest[destOffset++] = (byte) ((v >>> 48) & 0xFF); 152 dest[destOffset++] = (byte) ((v >>> 56) & 0xFF); 153 154 return destOffset; 155 } 156 157 166 protected int readUnitBE(int offset, byte[] dest, int destOffset) { 167 long v = data[offset]; 168 dest[destOffset++] = (byte) ((v >>> 56) & 0xFF); 169 dest[destOffset++] = (byte) ((v >>> 48) & 0xFF); 170 dest[destOffset++] = (byte) ((v >>> 40) & 0xFF); 171 dest[destOffset++] = (byte) ((v >>> 32) & 0xFF); 172 dest[destOffset++] = (byte) ((v >>> 24) & 0xFF); 173 dest[destOffset++] = (byte) ((v >>> 16) & 0xFF); 174 dest[destOffset++] = (byte) ((v >>> 8) & 0xFF); 175 dest[destOffset++] = (byte) (v & 0xFF); 176 177 return destOffset; 178 } 179 180 } 227 | Popular Tags |