예제 #1
0
        public void uncompress(int[] @in, IntWrapper inpos, int inlength, int[] @out, IntWrapper outpos)
        {
            int s         = 0;
            int val       = 0;
            int p         = inpos.get();
            int finalp    = inpos.get() + inlength;
            int tmpoutpos = outpos.get();

            for (int v = 0, shift = 0; p < finalp;)
            {
                val = @in[p];
                int c = (sbyte)(int)((uint)val >> s);
                s += 8;
                p += s >> 5;
                s  = s & 31;
                v += ((c & 127) << shift);
                if ((c & 128) == 128)
                {
                    @out[tmpoutpos++] = v;
                    v     = 0;
                    shift = 0;
                }
                else
                {
                    shift += 7;
                }
            }
            outpos.set(tmpoutpos);
            inpos.add(inlength);
        }
예제 #2
0
        public void headlessCompress(int[] @in, IntWrapper inpos, int inlength, int[] @out, IntWrapper outpos)
        {
            if (inlength == 0)
            {
                return;
            }
            ByteBuffer buf = ByteBuffer.allocateDirect(inlength * 8);

            buf.order(ByteOrder.LITTLE_ENDIAN);
            for (int k = inpos.get(); k < inpos.get() + inlength; ++k)
            {
                long val = @in[k] & 0xFFFFFFFFL; // To be consistent with
                // unsigned integers in C/C++
                if (val < (1 << 7))
                {
                    buf.put((sbyte)(val | (1 << 7)));
                }
                else if (val < (1 << 14))
                {
                    buf.put((sbyte)extract7bits(0, val));
                    buf.put((sbyte)(extract7bitsmaskless(1, (val)) | (1 << 7)));
                }
                else if (val < (1 << 21))
                {
                    buf.put((sbyte)extract7bits(0, val));
                    buf.put((sbyte)extract7bits(1, val));
                    buf.put((sbyte)(extract7bitsmaskless(2, (val)) | (1 << 7)));
                }
                else if (val < (1 << 28))
                {
                    buf.put((sbyte)extract7bits(0, val));
                    buf.put((sbyte)extract7bits(1, val));
                    buf.put((sbyte)extract7bits(2, val));
                    buf.put((sbyte)(extract7bitsmaskless(3, (val)) | (1 << 7)));
                }
                else
                {
                    buf.put((sbyte)extract7bits(0, val));
                    buf.put((sbyte)extract7bits(1, val));
                    buf.put((sbyte)extract7bits(2, val));
                    buf.put((sbyte)extract7bits(3, val));
                    buf.put((sbyte)(extract7bitsmaskless(4, (val)) | (1 << 7)));
                }
            }
            while (buf.position() % 4 != 0)
            {
                buf.put((sbyte)0);
            }
            int length = buf.position();

            buf.flip();
            IntBuffer ibuf = buf.asIntBuffer();

            ibuf.get(@out, outpos.get(), length / 4);
            outpos.add(length / 4);
            inpos.add(inlength);
        }
예제 #3
0
        public void compress(int[] @in, IntWrapper inpos, int inlength, sbyte[] @out, IntWrapper outpos)
        {
            if (inlength == 0)
            {
                return;
            }
            int outpostmp = outpos.get();

            for (int k = inpos.get(); k < inpos.get() + inlength; ++k)
            {
                long val = @in[k] & 0xFFFFFFFFL; // To be consistent with
                // unsigned integers in C/C++
                if (val < (1 << 7))
                {
                    @out[outpostmp++] = (sbyte)(val | (1 << 7));
                }
                else if (val < (1 << 14))
                {
                    @out[outpostmp++] = (sbyte)extract7bits(0, val);
                    @out[outpostmp++] = (sbyte)(extract7bitsmaskless(1, (val)) | (1 << 7));
                }
                else if (val < (1 << 21))
                {
                    @out[outpostmp++] = (sbyte)extract7bits(0, val);
                    @out[outpostmp++] = (sbyte)extract7bits(1, val);
                    @out[outpostmp++] = (sbyte)(extract7bitsmaskless(2, (val)) | (1 << 7));
                }
                else if (val < (1 << 28))
                {
                    @out[outpostmp++] = (sbyte)extract7bits(0, val);
                    @out[outpostmp++] = (sbyte)extract7bits(1, val);
                    @out[outpostmp++] = (sbyte)extract7bits(2, val);
                    @out[outpostmp++] = (sbyte)(extract7bitsmaskless(3, (val)) | (1 << 7));
                }
                else
                {
                    @out[outpostmp++] = (sbyte)extract7bits(0, val);
                    @out[outpostmp++] = (sbyte)extract7bits(1, val);
                    @out[outpostmp++] = (sbyte)extract7bits(2, val);
                    @out[outpostmp++] = (sbyte)extract7bits(3, val);
                    @out[outpostmp++] = (sbyte)(extract7bitsmaskless(4, (val)) | (1 << 7));
                }
            }
            outpos.set(outpostmp);
            inpos.add(inlength);
        }
예제 #4
0
        public void uncompress(sbyte[] @in, IntWrapper inpos, int inlength, int[] @out, IntWrapper outpos)
        {
            int p         = inpos.get();
            int finalp    = inpos.get() + inlength;
            int tmpoutpos = outpos.get();

            for (int v = 0; p < finalp; @out[tmpoutpos++] = v)
            {
                v = @in[p] & 0x7F;
                if (@in[p] < 0)
                {
                    p += 1;
                    continue;
                }
                v = ((@in[p + 1] & 0x7F) << 7) | v;
                if (@in[p + 1] < 0)
                {
                    p += 2;
                    continue;
                }
                v = ((@in[p + 2] & 0x7F) << 14) | v;
                if (@in[p + 2] < 0)
                {
                    p += 3;
                    continue;
                }
                v = ((@in[p + 3] & 0x7F) << 21) | v;
                if (@in[p + 3] < 0)
                {
                    p += 4;
                    continue;
                }
                v  = ((@in[p + 4] & 0x7F) << 28) | v;
                p += 5;
            }
            outpos.set(tmpoutpos);
            inpos.add(p);
        }
예제 #5
0
        public void compress(int[] inBuf, IntWrapper inPos, int inLen, int[] outBuf, IntWrapper outPos)
        {
            if (inLen == 0)
            {
                return;
            }

            ByteBuffer byteBuf = ByteBuffer.allocateDirect(inLen * 5 + 3);

            DeltaZigzagEncoding.Encoder ctx = new DeltaZigzagEncoding.Encoder(0);

            // Delta+Zigzag+VariableByte encoding.
            int ip = inPos.get();

            int inPosLast = ip + inLen;

            for (; ip < inPosLast; ++ip)
            {
                // Filter with delta+zigzag encoding.
                int n = ctx.encodeInt(inBuf[ip]);
                // Variable byte encoding.

                //PORT NOTE: The following IF statements are ported from a switch. Fall through switches are not allowed in C#
                int zeros = Integer.numberOfLeadingZeros(n);

                if (zeros < 4)
                {
                    byteBuf.put((sbyte)(((int)((uint)n >> 28) & 0x7F) | 0x80));
                }

                if (zeros < 11)
                {
                    byteBuf.put((sbyte)(((int)((uint)n >> 21) & 0x7F) | 0x80));
                }

                if (zeros < 18)
                {
                    byteBuf.put((sbyte)(((int)((uint)n >> 14) & 0x7F) | 0x80));
                }

                if (zeros < 25)
                {
                    byteBuf.put((sbyte)(((int)((uint)n >> 7) & 0x7F) | 0x80));
                }

                byteBuf.put((sbyte)((uint)n & 0x7F));
            }

            // Padding buffer to considerable as IntBuffer.
            for (int i = (4 - (byteBuf.position() % 4)) % 4; i > 0; --i)
            {
                unchecked
                {
                    byteBuf.put((sbyte)(0x80));
                }
            }

            int outLen = byteBuf.position() / 4;

            byteBuf.flip();
            IntBuffer intBuf = byteBuf.asIntBuffer();

            /*
             * Console.WriteLine(String.format(
             * "inLen=%d pos=%d limit=%d outLen=%d outBuf.len=%d", inLen,
             * intBuf.position(), intBuf.limit(), outLen, outBuf.Length));
             */
            intBuf.get(outBuf, outPos.get(), outLen);
            inPos.add(inLen);
            outPos.add(outLen);
        }
예제 #6
0
 public void headlessUncompress(int[] @in, IntWrapper inpos, int inlength, int[] @out, IntWrapper outpos, int num)
 {
     Array.Copy(@in, inpos.get(), @out, outpos.get(), num);
     inpos.add(num);
     outpos.add(num);
 }