1 32 package com.imagero.uio.buffer.arrays; 33 34 import com.imagero.uio.buffer.MemoryAccessManager; 35 36 37 44 public class DoubleArrayBufferManager extends AbstractArrayBufferManager { 45 46 double[] data; 47 48 53 public DoubleArrayBufferManager(double[] data) { 54 this(data, Math.min(TILE_SIZE, data.length)); 55 } 56 57 63 public DoubleArrayBufferManager(double[] data, int size) { 64 this(data, 0, data.length, size); 65 } 66 67 74 public DoubleArrayBufferManager(double[] data, int offset, int length) { 75 this(data, offset, length, TILE_SIZE); 76 } 77 78 86 public DoubleArrayBufferManager(double[] data, int offset, int length, int size) { 87 this.data = data; 88 this.tileSize = size; 89 this.unitSize = 8; 90 this.length = length; 91 this.offset = offset; 92 accessManager = MemoryAccessManager.createMemoryAccessManager(); 93 } 94 95 104 protected int writeUnitBE(byte[] source, int sourceOffset, int destOffset) { 105 long v = ((long) (source[sourceOffset++] & 0xFF) << 56) 106 | ((long) (source[sourceOffset++] & 0xFF) << 48) 107 | ((long) (source[sourceOffset++] & 0xFF) << 40) 108 | ((long) (source[sourceOffset++] & 0xFF) << 32) 109 | ((long) (source[sourceOffset++] & 0xFF) << 24) 110 | ((long) (source[sourceOffset++] & 0xFF) << 16) 111 | ((long) (source[sourceOffset++] & 0xFF) << 8) 112 | (source[sourceOffset++] & 0xFF); 113 data[destOffset] = Double.longBitsToDouble(v); 114 return sourceOffset; 115 } 116 117 126 protected int writeUnitLE(byte[] source, int sourceOffset, int destOffset) { 127 long v = (source[sourceOffset++] & 0xFF) 128 | ((long) (source[sourceOffset++] & 0xFF) << 8) 129 | ((long) (source[sourceOffset++] & 0xFF) << 16) 130 | ((long) (source[sourceOffset++] & 0xFF) << 24) 131 | ((long) (source[sourceOffset++] & 0xFF) << 32) 132 | ((long) (source[sourceOffset++] & 0xFF) << 40) 133 | ((long) (source[sourceOffset++] & 0xFF) << 48) 134 | ((long) (source[sourceOffset++] & 0xFF) << 56); 135 data[destOffset] = Double.longBitsToDouble(v); 136 return sourceOffset; 137 } 138 139 148 protected int readUnitBE(int offset, byte[] dest, int destOffset) { 149 double d = data[offset]; 150 long v = Double.doubleToLongBits(d); 151 dest[destOffset++] = (byte) ((v >>> 56) & 0xFF); 152 dest[destOffset++] = (byte) ((v >>> 48) & 0xFF); 153 dest[destOffset++] = (byte) ((v >>> 40) & 0xFF); 154 dest[destOffset++] = (byte) ((v >>> 32) & 0xFF); 155 dest[destOffset++] = (byte) ((v >>> 24) & 0xFF); 156 dest[destOffset++] = (byte) ((v >>> 16) & 0xFF); 157 dest[destOffset++] = (byte) ((v >>> 8) & 0xFF); 158 dest[destOffset++] = (byte) (v & 0xFF); 159 return destOffset; 160 } 161 162 171 protected int readUnitLE(int offset, byte[] dest, int destOffset) { 172 double d = data[offset]; 173 long v = Double.doubleToLongBits(d); 174 dest[destOffset++] = (byte) (v & 0xFF); 175 dest[destOffset++] = (byte) ((v >>> 8) & 0xFF); 176 dest[destOffset++] = (byte) ((v >>> 16) & 0xFF); 177 dest[destOffset++] = (byte) ((v >>> 24) & 0xFF); 178 dest[destOffset++] = (byte) ((v >>> 32) & 0xFF); 179 dest[destOffset++] = (byte) ((v >>> 40) & 0xFF); 180 dest[destOffset++] = (byte) ((v >>> 48) & 0xFF); 181 dest[destOffset++] = (byte) ((v >>> 56) & 0xFF); 182 return destOffset; 183 } 184 } 185 | Popular Tags |