63 lines
2.3 KiB
Plaintext
63 lines
2.3 KiB
Plaintext
avoid reading the next byte ahead
|
|
f6774c386f404b49a13d9027567d57e104c5a415
|
|
|
|
Index: src/bitreader.c
|
|
--- src/bitreader.c.orig
|
|
+++ src/bitreader.c
|
|
@@ -26,12 +26,11 @@
|
|
|
|
#include "dvdread/bitreader.h"
|
|
|
|
-int dvdread_getbits_init(getbits_state_t *state, uint8_t *start) {
|
|
+int dvdread_getbits_init(getbits_state_t *state, const uint8_t *start) {
|
|
if ((state == NULL) || (start == NULL)) return 0;
|
|
state->start = start;
|
|
state->bit_position = 0;
|
|
state->byte_position = 0;
|
|
- state->byte = start[0];
|
|
return 1;
|
|
}
|
|
|
|
@@ -47,37 +46,32 @@ uint32_t dvdread_getbits(getbits_state_t *state, uint3
|
|
|
|
if ((state->bit_position) > 0) { /* Last getbits left us in the middle of a byte. */
|
|
if (number_of_bits > (8-state->bit_position)) { /* this getbits will span 2 or more bytes. */
|
|
- byte = state->byte;
|
|
+ byte = state->start[state->byte_position] << state->bit_position;
|
|
byte = byte >> (state->bit_position);
|
|
result = byte;
|
|
number_of_bits -= (8-state->bit_position);
|
|
state->bit_position = 0;
|
|
state->byte_position++;
|
|
- state->byte = state->start[state->byte_position];
|
|
} else {
|
|
- byte=state->byte;
|
|
- state->byte = state->byte << number_of_bits;
|
|
+ byte = state->start[state->byte_position] << state->bit_position;
|
|
byte = byte >> (8 - number_of_bits);
|
|
result = byte;
|
|
state->bit_position += number_of_bits; /* Here it is impossible for bit_position > 8 */
|
|
if (state->bit_position == 8) {
|
|
state->bit_position = 0;
|
|
state->byte_position++;
|
|
- state->byte = state->start[state->byte_position];
|
|
}
|
|
number_of_bits = 0;
|
|
}
|
|
}
|
|
if ((state->bit_position) == 0) {
|
|
while (number_of_bits > 7) {
|
|
- result = (result << 8) + state->byte;
|
|
+ result = (result << 8) + state->start[state->byte_position];
|
|
state->byte_position++;
|
|
- state->byte = state->start[state->byte_position];
|
|
number_of_bits -= 8;
|
|
}
|
|
if (number_of_bits > 0) { /* number_of_bits < 8 */
|
|
- byte = state->byte;
|
|
- state->byte = state->byte << number_of_bits;
|
|
+ byte = state->start[state->byte_position] << state->bit_position;
|
|
state->bit_position += number_of_bits; /* Here it is impossible for bit_position > 7 */
|
|
byte = byte >> (8 - number_of_bits);
|
|
result = (result << number_of_bits) + byte;
|