+/**************************************************************************
+ *
+ * Copyright 2009 Younes Manton.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
#include "vl_bitstream_parser.h"
#include <assert.h>
#include <limits.h>
assert(bitstream);
- if (cur_bit + how_many_bits > sizeof(unsigned) * CHAR_BIT)
- {
- return grab_bits(cur_bit, sizeof(unsigned) * CHAR_BIT - cur_bit,
- bitstream[cur_int]) |
- grab_bits(0, cur_bit + how_many_bits - sizeof(unsigned) * CHAR_BIT,
- bitstream[cur_int + 1]) << (sizeof(unsigned) * CHAR_BIT - cur_bit);
+ if (cur_bit + how_many_bits > sizeof(unsigned) * CHAR_BIT) {
+ unsigned lower = grab_bits(cur_bit, sizeof(unsigned) * CHAR_BIT - cur_bit,
+ bitstream[cur_int]);
+ unsigned upper = grab_bits(0, cur_bit + how_many_bits - sizeof(unsigned) * CHAR_BIT,
+ bitstream[cur_int + 1]);
+ return lower | upper << (sizeof(unsigned) * CHAR_BIT - cur_bit);
}
else
return grab_bits(cur_bit, how_many_bits, bitstream[cur_int]);
cursor = parser->cursor;
cur_bitstream = parser->cur_bitstream;
- while (1)
- {
+ while (1) {
unsigned bits_left = parser->sizes[cur_bitstream] * CHAR_BIT - cursor;
unsigned bits_to_show = how_many_bits > bits_left ? bits_left : how_many_bits;
bits |= show_bits(cursor, bits_to_show,
parser->bitstreams[cur_bitstream]) << shift;
- if (how_many_bits > bits_to_show)
- {
+ if (how_many_bits > bits_to_show) {
how_many_bits -= bits_to_show;
cursor = 0;
++cur_bitstream;
parser->cursor += how_many_bits;
- while (parser->cursor > parser->sizes[parser->cur_bitstream] * CHAR_BIT)
- {
+ while (parser->cursor > parser->sizes[parser->cur_bitstream] * CHAR_BIT) {
parser->cursor -= parser->sizes[parser->cur_bitstream++] * CHAR_BIT;
assert(parser->cur_bitstream < parser->num_bitstreams);
}
c = parser->cursor - how_many_bits;
- while (c < 0)
- {
+ while (c < 0) {
c += parser->sizes[parser->cur_bitstream--] * CHAR_BIT;
assert(parser->cur_bitstream < parser->num_bitstreams);
}