Mercurial > libdvdread4.hg
annotate bitreader.c @ 81:7e9feef7a82d src
Do not extract libdvdcss version via dvdcss_interface_2.
The variable is deprecated and only informs about the
libdvdcss API version, which carries no meaning nowadays.
| author | diego |
|---|---|
| date | Thu, 21 Mar 2013 19:23:12 +0000 |
| parents | 9f1804080f76 |
| children |
| rev | line source |
|---|---|
| 3 | 1 /* |
| 22 | 2 * Copyright (C) 2000, 2001, 2002, 2003 HÃ¥kan Hjort <d95hjort@dtek.chalmers.se> |
| 3 | 3 * |
|
21
4aa618ae094f
Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents:
3
diff
changeset
|
4 * This file is part of libdvdread. |
|
4aa618ae094f
Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents:
3
diff
changeset
|
5 * |
|
4aa618ae094f
Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents:
3
diff
changeset
|
6 * libdvdread is free software; you can redistribute it and/or modify |
| 3 | 7 * it under the terms of the GNU General Public License as published by |
| 8 * the Free Software Foundation; either version 2 of the License, or | |
| 9 * (at your option) any later version. | |
| 10 * | |
|
21
4aa618ae094f
Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents:
3
diff
changeset
|
11 * libdvdread is distributed in the hope that it will be useful, |
| 3 | 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 * GNU General Public License for more details. | |
| 15 * | |
|
21
4aa618ae094f
Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents:
3
diff
changeset
|
16 * You should have received a copy of the GNU General Public License along |
|
4aa618ae094f
Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents:
3
diff
changeset
|
17 * with libdvdread; if not, write to the Free Software Foundation, Inc., |
|
4aa618ae094f
Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents:
3
diff
changeset
|
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 3 | 19 */ |
| 20 | |
| 21 #include <stdio.h> | |
| 22 #include <stdlib.h> | |
| 23 #include <string.h> | |
| 24 #include <inttypes.h> | |
| 25 | |
|
33
c743d79f187b
Move installed headers into dvdread directory to make them easier to
reimar
parents:
22
diff
changeset
|
26 #include "dvdread/bitreader.h" |
| 3 | 27 |
| 28 int dvdread_getbits_init(getbits_state_t *state, uint8_t *start) { | |
| 29 if ((state == NULL) || (start == NULL)) return 0; | |
| 30 state->start = start; | |
| 31 state->bit_position = 0; | |
| 32 state->byte_position = 0; | |
| 33 state->byte = start[0]; | |
| 34 return 1; | |
| 35 } | |
| 36 | |
| 37 /* Non-optimized getbits. */ | |
| 38 /* This can easily be optimized for particular platforms. */ | |
| 39 uint32_t dvdread_getbits(getbits_state_t *state, uint32_t number_of_bits) { | |
| 40 uint32_t result=0; | |
| 41 uint8_t byte=0; | |
| 42 if (number_of_bits > 32) { | |
| 43 printf("Number of bits > 32 in getbits\n"); | |
| 44 abort(); | |
| 45 } | |
| 46 | |
| 47 if ((state->bit_position) > 0) { /* Last getbits left us in the middle of a byte. */ | |
| 48 if (number_of_bits > (8-state->bit_position)) { /* this getbits will span 2 or more bytes. */ | |
| 49 byte = state->byte; | |
| 50 byte = byte >> (state->bit_position); | |
| 51 result = byte; | |
| 52 number_of_bits -= (8-state->bit_position); | |
| 53 state->bit_position = 0; | |
| 54 state->byte_position++; | |
| 55 state->byte = state->start[state->byte_position]; | |
| 56 } else { | |
| 57 byte=state->byte; | |
| 58 state->byte = state->byte << number_of_bits; | |
| 59 byte = byte >> (8 - number_of_bits); | |
| 60 result = byte; | |
| 61 state->bit_position += number_of_bits; /* Here it is impossible for bit_position > 8 */ | |
| 62 if (state->bit_position == 8) { | |
| 63 state->bit_position = 0; | |
| 64 state->byte_position++; | |
| 65 state->byte = state->start[state->byte_position]; | |
| 66 } | |
| 67 number_of_bits = 0; | |
| 68 } | |
| 69 } | |
| 70 if ((state->bit_position) == 0) { | |
| 71 while (number_of_bits > 7) { | |
| 72 result = (result << 8) + state->byte; | |
| 73 state->byte_position++; | |
| 74 state->byte = state->start[state->byte_position]; | |
| 75 number_of_bits -= 8; | |
| 76 } | |
| 77 if (number_of_bits > 0) { /* number_of_bits < 8 */ | |
| 78 byte = state->byte; | |
| 79 state->byte = state->byte << number_of_bits; | |
| 80 state->bit_position += number_of_bits; /* Here it is impossible for bit_position > 7 */ | |
| 81 byte = byte >> (8 - number_of_bits); | |
| 82 result = (result << number_of_bits) + byte; | |
| 83 number_of_bits = 0; | |
| 84 } | |
| 85 } | |
| 86 | |
| 87 return result; | |
| 88 } | |
| 89 | |
| 90 #if 0 /* TODO: optimized versions not yet used */ | |
| 91 | |
| 92 /* WARNING: This function can only be used on a byte boundary. | |
| 93 No checks are made that we are in fact on a byte boundary. | |
| 94 */ | |
| 95 uint16_t dvdread_get16bits(getbits_state_t *state) { | |
| 96 uint16_t result; | |
| 97 state->byte_position++; | |
| 98 result = (state->byte << 8) + state->start[state->byte_position++]; | |
| 99 state->byte = state->start[state->byte_position]; | |
| 100 return result; | |
| 101 } | |
| 102 | |
| 103 /* WARNING: This function can only be used on a byte boundary. | |
| 104 No checks are made that we are in fact on a byte boundary. | |
| 105 */ | |
| 106 uint32_t dvdread_get32bits(getbits_state_t *state) { | |
| 107 uint32_t result; | |
| 108 state->byte_position++; | |
| 109 result = (state->byte << 8) + state->start[state->byte_position++]; | |
| 110 result = (result << 8) + state->start[state->byte_position++]; | |
| 111 result = (result << 8) + state->start[state->byte_position++]; | |
| 112 state->byte = state->start[state->byte_position]; | |
| 113 return result; | |
| 114 } | |
| 115 | |
| 116 #endif |
