|
2 | 2 |
|
3 | 3 | import htsjdk.samtools.cram.CRAMException;
|
4 | 4 | import htsjdk.samtools.cram.compression.BZIP2ExternalCompressor;
|
5 |
| -import htsjdk.samtools.cram.compression.rans.Utils; |
6 | 5 |
|
7 | 6 | import java.nio.ByteBuffer;
|
8 | 7 | import java.nio.ByteOrder;
|
@@ -39,16 +38,16 @@ private ByteBuffer uncompress(final ByteBuffer inBuffer, int outSize) {
|
39 | 38 | // if pack, get pack metadata, which will be used later to decode packed data
|
40 | 39 | int packDataLength = 0;
|
41 | 40 | int numSymbols = 0;
|
42 |
| - int[] packMappingTable = new int[0]; |
| 41 | + byte[] packMappingTable = null; |
43 | 42 | if (rangeParams.isPack()){
|
44 | 43 | packDataLength = outSize;
|
45 | 44 | numSymbols = inBuffer.get() & 0xFF;
|
46 | 45 |
|
47 | 46 | // if (numSymbols > 16 or numSymbols==0), raise exception
|
48 | 47 | if (numSymbols <= 16 && numSymbols!=0) {
|
49 |
| - packMappingTable = new int[numSymbols]; |
| 48 | + packMappingTable = new byte[numSymbols]; |
50 | 49 | for (int i = 0; i < numSymbols; i++) {
|
51 |
| - packMappingTable[i] = inBuffer.get() & 0xFF; |
| 50 | + packMappingTable[i] = inBuffer.get(); |
52 | 51 | }
|
53 | 52 | outSize = Utils.readUint7(inBuffer);
|
54 | 53 | } else {
|
@@ -92,8 +91,8 @@ private ByteBuffer uncompress(final ByteBuffer inBuffer, int outSize) {
|
92 | 91 | }
|
93 | 92 |
|
94 | 93 | // if pack, then decodePack
|
95 |
| - if (rangeParams.isPack() && packMappingTable.length > 0) { |
96 |
| - outBuffer = decodePack(outBuffer, packMappingTable, numSymbols, packDataLength); |
| 94 | + if (rangeParams.isPack()) { |
| 95 | + outBuffer = Utils.decodePack(outBuffer, packMappingTable, numSymbols, packDataLength); |
97 | 96 | }
|
98 | 97 | outBuffer.rewind();
|
99 | 98 | return outBuffer;
|
@@ -227,55 +226,6 @@ private ByteBuffer uncompressEXT(
|
227 | 226 | return outBuffer;
|
228 | 227 | }
|
229 | 228 |
|
230 |
| - private ByteBuffer decodePack(ByteBuffer inBuffer, final int[] packMappingTable, int numSymbols, int uncompressedPackOutputLength) { |
231 |
| - ByteBuffer outBufferPack = ByteBuffer.allocate(uncompressedPackOutputLength); |
232 |
| - int j = 0; |
233 |
| - |
234 |
| - if (numSymbols <= 1) { |
235 |
| - for (int i=0; i < uncompressedPackOutputLength; i++){ |
236 |
| - outBufferPack.put(i, (byte) packMappingTable[0]); |
237 |
| - } |
238 |
| - } |
239 |
| - |
240 |
| - // 1 bit per value |
241 |
| - else if (numSymbols <= 2) { |
242 |
| - int v = 0; |
243 |
| - for (int i=0; i < uncompressedPackOutputLength; i++){ |
244 |
| - if (i % 8 == 0){ |
245 |
| - v = inBuffer.get(j++); |
246 |
| - } |
247 |
| - outBufferPack.put(i, (byte) packMappingTable[v & 1]); |
248 |
| - v >>=1; |
249 |
| - } |
250 |
| - } |
251 |
| - |
252 |
| - // 2 bits per value |
253 |
| - else if (numSymbols <= 4){ |
254 |
| - int v = 0; |
255 |
| - for(int i=0; i < uncompressedPackOutputLength; i++){ |
256 |
| - if (i % 4 == 0){ |
257 |
| - v = inBuffer.get(j++); |
258 |
| - } |
259 |
| - outBufferPack.put(i, (byte) packMappingTable[v & 3]); |
260 |
| - v >>=2; |
261 |
| - } |
262 |
| - } |
263 |
| - |
264 |
| - // 4 bits per value |
265 |
| - else if (numSymbols <= 16){ |
266 |
| - int v = 0; |
267 |
| - for(int i=0; i < uncompressedPackOutputLength; i++){ |
268 |
| - if (i % 2 == 0){ |
269 |
| - v = inBuffer.get(j++); |
270 |
| - } |
271 |
| - outBufferPack.put(i, (byte) packMappingTable[v & 15]); |
272 |
| - v >>=4; |
273 |
| - } |
274 |
| - } |
275 |
| - inBuffer = outBufferPack; |
276 |
| - return inBuffer; |
277 |
| - } |
278 |
| - |
279 | 229 | private ByteBuffer decodeStripe(ByteBuffer inBuffer, final int outSize){
|
280 | 230 |
|
281 | 231 | final int numInterleaveStreams = inBuffer.get() & 0xFF;
|
|
0 commit comments