Home | History | Annotate | Download | only in srce
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 2014 The Android Open Source Project
      4  *  Copyright 2003 - 2004 Open Interface North America, Inc. All rights reserved.
      5  *
      6  *  Licensed under the Apache License, Version 2.0 (the "License");
      7  *  you may not use this file except in compliance with the License.
      8  *  You may obtain a copy of the License at:
      9  *
     10  *  http://www.apache.org/licenses/LICENSE-2.0
     11  *
     12  *  Unless required by applicable law or agreed to in writing, software
     13  *  distributed under the License is distributed on an "AS IS" BASIS,
     14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15  *  See the License for the specific language governing permissions and
     16  *  limitations under the License.
     17  *
     18  ******************************************************************************/
     19 
     20 /**********************************************************************************
     21   $Revision: #1 $
     22 ***********************************************************************************/
     23 
     24 /**
     25 @file
     26 Functions for manipulating input bitstreams.
     27 
     28 @ingroup codec_internal
     29 */
     30 
     31 /**
     32 @addtogroup codec_internal
     33 @{
     34 */
     35 
     36 #include "oi_stddefs.h"
     37 #include "oi_bitstream.h"
     38 #include "oi_assert.h"
     39 
     40 PRIVATE void OI_BITSTREAM_ReadInit(OI_BITSTREAM *bs,
     41                                    const OI_BYTE *buffer)
     42 {
     43     bs->value = ((OI_INT32)buffer[0] << 16) | ((OI_INT32)buffer[1] << 8) | (buffer[2]);
     44     bs->ptr.r = buffer + 3;
     45     bs->bitPtr = 8;
     46 }
     47 
     48 PRIVATE OI_UINT32 OI_BITSTREAM_ReadUINT(OI_BITSTREAM *bs, OI_UINT bits)
     49 {
     50     OI_UINT32 result;
     51 
     52     OI_BITSTREAM_READUINT(result, bits, bs->ptr.r, bs->value, bs->bitPtr);
     53 
     54     return result;
     55 }
     56 
     57 PRIVATE OI_UINT8 OI_BITSTREAM_ReadUINT4Aligned(OI_BITSTREAM *bs)
     58 {
     59     OI_UINT32 result;
     60 
     61     OI_ASSERT(bs->bitPtr < 16);
     62     OI_ASSERT(bs->bitPtr % 4 == 0);
     63 
     64     if (bs->bitPtr == 8) {
     65         result = bs->value << 8;
     66         bs->bitPtr = 12;
     67     } else {
     68         result = bs->value << 12;
     69         bs->value = (bs->value << 8) | *bs->ptr.r++;
     70         bs->bitPtr = 8;
     71     }
     72     result >>= 28;
     73     OI_ASSERT(result < (1u << 4));
     74     return (OI_UINT8)result;
     75 }
     76 
     77 PRIVATE OI_UINT8 OI_BITSTREAM_ReadUINT8Aligned(OI_BITSTREAM *bs)
     78 {
     79     OI_UINT32 result;
     80     OI_ASSERT(bs->bitPtr == 8);
     81 
     82     result = bs->value >> 16;
     83     bs->value = (bs->value << 8) | *bs->ptr.r++;
     84 
     85     return (OI_UINT8)result;
     86 }
     87 
     88 /**
     89 @}
     90 */
     91 
     92 
     93