public void compress(int[] @in, IntWrapper inpos, int inlength, int[] @out, IntWrapper outpos) { if (inlength == 0) { return; } @out[outpos.get()] = inlength; outpos.increment(); headlessCompress(@in, inpos, inlength, @out, outpos); }
public void compress(int[] @in, IntWrapper inpos, int inlength, int[] @out, IntWrapper outpos) { inlength = Util.greatestMultiple(inlength, BLOCK_SIZE); if (inlength == 0) { return; } @out[outpos.get()] = inlength; outpos.increment(); headlessCompress(@in, inpos, inlength, @out, outpos); }
public void uncompress(int[] @in, IntWrapper inpos, int inlength, int[] @out, IntWrapper outpos) { if (inlength == 0) { return; } int outlength = @in[inpos.get()]; inpos.increment(); headlessUncompress(@in, inpos, inlength, @out, outpos, outlength); }
private void decodePage(int[] @in, IntWrapper inpos, int[] @out, IntWrapper outpos, int thissize) { int initpos = inpos.get(); int wheremeta = @in[inpos.get()]; inpos.increment(); int inexcept = initpos + wheremeta; int bytesize = @in[inexcept++]; byteContainer.clear(); //byteContainer.asIntBuffer().put(@in, inexcept, (bytesize + 3) / 4); //Port note: I've collapsed the code here byteContainer.put(@in, inexcept, (bytesize + 3) / 4); byteContainer._ms.Position = 0; inexcept += (bytesize + 3) / 4; int bitmap = @in[inexcept++]; for (int k = 2; k <= 32; ++k) { if ((bitmap & (1 << (k - 1))) != 0) { int size = @in[inexcept++]; int roundedup = Util .greatestMultiple(size + 31, 32); if (dataTobePacked[k].Length < roundedup) { dataTobePacked[k] = new int[roundedup]; } if (inexcept + roundedup / 32 * k <= @in.Length) { int j = 0; for (; j < size; j += 32) { BitPacking.fastunpack(@in, inexcept, dataTobePacked[k], j, k); inexcept += k; } int overflow = j - size; inexcept -= overflow * k / 32; } else { int j = 0; int[] buf = new int[roundedup / 32 * k]; int initinexcept = inexcept; Array.Copy(@in, inexcept, buf, 0, @in.Length - inexcept); for (; j < size; j += 32) { BitPacking.fastunpack(buf, inexcept - initinexcept, dataTobePacked[k], j, k); inexcept += k; } int overflow = j - size; inexcept -= overflow * k / 32; } } } Arrays.fill(dataPointers, 0); int tmpoutpos = outpos.get(); int tmpinpos = inpos.get(); for (int run = 0, run_end = thissize / BLOCK_SIZE; run < run_end; ++run, tmpoutpos += BLOCK_SIZE) { int b = byteContainer.get(); int cexcept = byteContainer.get() & 0xFF; for (int k = 0; k < BLOCK_SIZE; k += 32) { BitPacking.fastunpack(@in, tmpinpos, @out, tmpoutpos + k, b); tmpinpos += b; } if (cexcept > 0) { int maxbits = byteContainer.get(); int index = maxbits - b; if (index == 1) { for (int k = 0; k < cexcept; ++k) { int pos = byteContainer.get() & 0xFF; @out[pos + tmpoutpos] |= 1 << b; } } else { for (int k = 0; k < cexcept; ++k) { int pos = byteContainer.get() & 0xFF; int exceptvalue = dataTobePacked[index][dataPointers[index]++]; @out[pos + tmpoutpos] |= exceptvalue << b; } } } } outpos.set(tmpoutpos); inpos.set(inexcept); }
private void encodePage(int[] @in, IntWrapper inpos, int thissize, int[] @out, IntWrapper outpos) { int headerpos = outpos.get(); outpos.increment(); int tmpoutpos = outpos.get(); // Clear working area. Arrays.fill(dataPointers, 0); byteContainer.clear(); int tmpinpos = inpos.get(); for (int finalinpos = tmpinpos + thissize - BLOCK_SIZE; tmpinpos <= finalinpos; tmpinpos += BLOCK_SIZE) { getBestBFromData(@in, tmpinpos); int tmpbestb = bestbbestcexceptmaxb[0]; byteContainer.put((sbyte)bestbbestcexceptmaxb[0]); byteContainer.put((sbyte)bestbbestcexceptmaxb[1]); if (bestbbestcexceptmaxb[1] > 0) { byteContainer.put((sbyte)bestbbestcexceptmaxb[2]); int index = bestbbestcexceptmaxb[2] - bestbbestcexceptmaxb[0]; if (dataPointers[index] + bestbbestcexceptmaxb[1] >= dataTobePacked[index].Length) { int newsize = 2 * (dataPointers[index] + bestbbestcexceptmaxb[1]); // make sure it is a multiple of 32 newsize = Util.greatestMultiple(newsize + 31, 32); dataTobePacked[index] = Arrays.copyOf(dataTobePacked[index], newsize); } for (int k = 0; k < BLOCK_SIZE; ++k) { if ((int)((uint)@in[k + tmpinpos] >> bestbbestcexceptmaxb[0]) != 0) { // we have an exception byteContainer.put((sbyte)k); dataTobePacked[index][dataPointers[index]++] = (int)((uint)@in[k + tmpinpos] >> tmpbestb); } } } for (int k = 0; k < BLOCK_SIZE; k += 32) { BitPacking.fastpack(@in, tmpinpos + k, @out, tmpoutpos, tmpbestb); tmpoutpos += tmpbestb; } } inpos.set(tmpinpos); @out[headerpos] = tmpoutpos - headerpos; int bytesize = byteContainer.position(); while ((byteContainer.position() & 3) != 0) { byteContainer.put((sbyte)0); } @out[tmpoutpos++] = bytesize; int howmanyints = byteContainer.position() / 4; byteContainer.flip(); byteContainer.asIntBuffer().get(@out, tmpoutpos, howmanyints); tmpoutpos += howmanyints; int bitmap = 0; for (int k = 2; k <= 32; ++k) { if (dataPointers[k] != 0) { bitmap |= (1 << (k - 1)); } } @out[tmpoutpos++] = bitmap; for (int k = 2; k <= 32; ++k) { if (dataPointers[k] != 0) { @out[tmpoutpos++] = dataPointers[k];// size int j = 0; for (; j < dataPointers[k]; j += 32) { BitPacking.fastpack(dataTobePacked[k], j, @out, tmpoutpos, k); tmpoutpos += k; } int overflow = j - dataPointers[k]; tmpoutpos -= overflow * k / 32; } } outpos.set(tmpoutpos); }