media/libvpx/vp9/encoder/vp9_write_bit_buffer.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/libvpx/vp9/encoder/vp9_write_bit_buffer.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,48 @@
     1.4 +/*
     1.5 + *  Copyright (c) 2013 The WebM project authors. All Rights Reserved.
     1.6 + *
     1.7 + *  Use of this source code is governed by a BSD-style license
     1.8 + *  that can be found in the LICENSE file in the root of the source
     1.9 + *  tree. An additional intellectual property rights grant can be found
    1.10 + *  in the file PATENTS.  All contributing project authors may
    1.11 + *  be found in the AUTHORS file in the root of the source tree.
    1.12 + */
    1.13 +
    1.14 +#ifndef VP9_BIT_WRITE_BUFFER_H_
    1.15 +#define VP9_BIT_WRITE_BUFFER_H_
    1.16 +
    1.17 +#include <limits.h>
    1.18 +
    1.19 +#include "vpx/vpx_integer.h"
    1.20 +
    1.21 +struct vp9_write_bit_buffer {
    1.22 +  uint8_t *bit_buffer;
    1.23 +  size_t bit_offset;
    1.24 +};
    1.25 +
    1.26 +static size_t vp9_rb_bytes_written(struct vp9_write_bit_buffer *wb) {
    1.27 +  return wb->bit_offset / CHAR_BIT + (wb->bit_offset % CHAR_BIT > 0);
    1.28 +}
    1.29 +
    1.30 +static void vp9_wb_write_bit(struct vp9_write_bit_buffer *wb, int bit) {
    1.31 +  const int off = wb->bit_offset;
    1.32 +  const int p = off / CHAR_BIT;
    1.33 +  const int q = CHAR_BIT - 1 - off % CHAR_BIT;
    1.34 +  if (q == CHAR_BIT -1) {
    1.35 +    wb->bit_buffer[p] = bit << q;
    1.36 +  } else {
    1.37 +    wb->bit_buffer[p] &= ~(1 << q);
    1.38 +    wb->bit_buffer[p] |= bit << q;
    1.39 +  }
    1.40 +  wb->bit_offset = off + 1;
    1.41 +}
    1.42 +
    1.43 +static void vp9_wb_write_literal(struct vp9_write_bit_buffer *wb,
    1.44 +                              int data, int bits) {
    1.45 +  int bit;
    1.46 +  for (bit = bits - 1; bit >= 0; bit--)
    1.47 +    vp9_wb_write_bit(wb, (data >> bit) & 1);
    1.48 +}
    1.49 +
    1.50 +
    1.51 +#endif  // VP9_BIT_WRITE_BUFFER_H_

mercurial