Пример #1
0
 public unsafe static void vp8_start_encode(ref BOOL_CODER bc, byte[] source, int length)
 {
     fixed(byte *pSrc = source)
     {
         vp8_start_encode(ref bc, pSrc, pSrc + length);
     }
 }
Пример #2
0
        public static void vp8_encode_value(ref BOOL_CODER bc, int data, int bits)
        {
            int bit;

            for (bit = bits - 1; bit >= 0; bit--)
            {
                vp8_encode_bool(ref bc, (1 & (data >> bit)), 0x80);
            }
        }
Пример #3
0
        public static void vp8_stop_encode(ref BOOL_CODER bc)
        {
            int i;

            for (i = 0; i < 32; ++i)
            {
                vp8_encode_bool(ref bc, 0, 128);
            }
        }
Пример #4
0
 public unsafe static void vp8_start_encode(ref BOOL_CODER bc, byte *source, byte *source_end)
 {
     bc.lowvalue   = 0;
     bc.range      = 255;
     bc.count      = -24;
     bc.buffer     = source;
     bc.buffer_end = source_end;
     bc.pos        = 0;
 }
Пример #5
0
        public unsafe void TestBitIO()
        {
            Random rnd = new Random();

            for (int method = 0; method <= 7; ++method)
            {  // we generate various proba
                const int kBitsToTest = 1000;
                byte[]    probas      = new byte[kBitsToTest];

                for (int i = 0; i < kBitsToTest; ++i)
                {
                    int parity = i & 1;
                    probas[i] = (byte)(
                        (method == 0) ? 0 : (method == 1) ? 255 :
                        (method == 2) ? 128 :
                        (method == 3) ? rnd.Next(0, 256) :
                        (method == 4) ? (parity > 0 ? 0 : 255) :
                        // alternate between low and high proba:
                        (method == 5) ? (parity > 0 ? rnd.Next(0, 128) : 255 - rnd.Next(0, 128)) :
                        (method == 6) ?
                        (parity > 0 ? rnd.Next(0, 64) : 255 - rnd.Next(0, 64)) :
                        (parity > 0 ? rnd.Next(0, 32) : 255 - rnd.Next(0, 32)));
                }
                for (int bit_method = 0; bit_method <= 3; ++bit_method)
                {
                    const int random_seed = 6432;
                    const int kBufferSize = 10000;
                    rnd = new Random(random_seed);
                    BOOL_CODER bw        = new BOOL_CODER();
                    byte[]     bw_buffer = new byte[kBufferSize];
                    boolhuff.vp8_start_encode(ref bw, bw_buffer, kBufferSize);

                    int bit = (bit_method == 0) ? 0 : (bit_method == 1) ? 1 : 0;
                    for (int i = 0; i < kBitsToTest; ++i)
                    {
                        if (bit_method == 2)
                        {
                            bit = (i & 1);
                        }
                        else if (bit_method == 3)
                        {
                            bit = rnd.Next(0, 1);
                        }
                        boolhuff.vp8_encode_bool(ref bw, bit, probas[i]);
                    }

                    boolhuff.vp8_stop_encode(ref bw);
                    // vp8dx_bool_decoder_fill() may read into uninitialized data that
                    // isn't used meaningfully, but may trigger an MSan warning.
                    //memset(bw_buffer + bw.pos, 0, sizeof(VP8_BD_VALUE) - 1);
                    for (int i = (int)bw.pos; i < dboolhuff.VP8_BD_VALUE_SIZE; i++)
                    {
                        bw_buffer[i] = 0;
                    }

                    BOOL_DECODER br = new BOOL_DECODER();
                    //encrypt_buffer(bw_buffer, kBufferSize);
                    //vp8dx_start_decode(&br, bw_buffer, kBufferSize, test_decrypt_cb,
                    //  reinterpret_cast<void*>(bw_buffer));
                    dboolhuff.vp8dx_start_decode(ref br, bw_buffer, kBufferSize);

                    //bit_rnd.Reset(random_seed);
                    rnd = new Random(random_seed);
                    for (int i = 0; i < kBitsToTest; ++i)
                    {
                        if (bit_method == 2)
                        {
                            bit = (i & 1);
                        }
                        else if (bit_method == 3)
                        {
                            bit = rnd.Next(0, 1);
                        }

                        /*GTEST_ASSERT_EQ(vp8dx_decode_bool(&br, probas[i]), bit)
                         * << "pos: " << i << " / " << kBitsToTest
                         * << " bit_method: " << bit_method << " method: " << method;*/

                        Assert.Equal(dboolhuff.vp8dx_decode_bool(ref br, probas[i]), bit);
                    }
                }
            }
        }