Пример #1
0
static int
estimate_array (int16_t *data, int n)
{
  int i;
  int n_bits = 0;

  for(i=0;i<n;i++){
    n_bits += schro_pack_estimate_sint (data[i]);
  }
  return n_bits;
}
Пример #2
0
int test3 (void)
{
  SchroBuffer *buffer = schro_buffer_new_and_alloc (1000);
  SchroPack *pack;
  SchroUnpack unpack;
  SchroUnpack unpack2;
  int i;
  int ref[100];
  int x;
  int n_bytes;
  int n_bits = 0;
  int n_bits2 = 0;

  memset (buffer->data, 0, 1000);
  for(i=0;i<100;i++){
    ref[i] = (rand()&0xff) - 128;
  }

  pack = schro_pack_new ();
  schro_pack_encode_init (pack, buffer);
  n_bits = 0;
  for(i=0;i<50;i++){
    schro_pack_encode_sint (pack, ref[i]);
    n_bits += schro_pack_estimate_sint (ref[i]);
  }
  n_bits2 = 0;
  for(i=50;i<100;i++){
    schro_pack_encode_sint (pack, ref[i]);
    n_bits2 += schro_pack_estimate_sint (ref[i]);
  }
  schro_pack_flush(pack);
  n_bytes = schro_pack_get_offset (pack);
  schro_pack_free (pack);


  schro_unpack_init_with_data (&unpack, buffer->data, n_bytes, 1);
  schro_unpack_copy (&unpack2, &unpack);

  schro_unpack_limit_bits_remaining (&unpack, n_bits);
  for(i=0;i<50;i++){
    x = schro_unpack_decode_sint (&unpack);
    if (x != ref[i]) {
      SCHRO_ERROR("test3 failed at symbol %d (%d should be %d)", i, x, ref[i]);
      schro_unpack_dump(&unpack);
      return 0;
    }
  }
  for(i=0;i<10;i++){
    x = schro_unpack_decode_sint (&unpack);
    if (x != 0) {
      SCHRO_ERROR("test3 failed at symbol %d (%d should be 0)", i, x);
      schro_unpack_dump(&unpack);
      return 0;
    }
  }

  schro_unpack_skip_bits (&unpack2, n_bits);
  schro_unpack_limit_bits_remaining (&unpack2, n_bits2);
  for(i=50;i<100;i++){
    x = schro_unpack_decode_sint (&unpack2);
    if (x != ref[i]) {
      SCHRO_ERROR("test3 failed at symbol %d (%d should be %d)", i, x, ref[i]);
      schro_unpack_dump(&unpack2);
      return 0;
    }
  }
  for(i=0;i<10;i++){
    x = schro_unpack_decode_sint (&unpack2);
    if (x != 0) {
      SCHRO_ERROR("test3 failed at symbol %d (%d should be 0)", i, x);
      schro_unpack_dump(&unpack2);
      return 0;
    }
  }

  schro_buffer_unref (buffer);

  return 1;
}