bits.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * bits.h
00003  *****************************************************************************
00004  * Copyright (C) 2001, 2002 the VideoLAN team
00005  * $Id$
00006  *
00007  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
00008  *          Eric Petit <titer@videolan.org>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00023  *****************************************************************************/
00024 
00025 typedef struct bits_buffer_s
00026 {
00027     int     i_size;
00028 
00029     int     i_data;
00030     uint8_t i_mask;
00031     uint8_t *p_data;
00032 
00033 } bits_buffer_t;
00034 
00035 static inline int bits_initwrite( bits_buffer_t *p_buffer,
00036                                   int i_size, void *p_data )
00037 {
00038     p_buffer->i_size = i_size;
00039     p_buffer->i_data = 0;
00040     p_buffer->i_mask = 0x80;
00041     p_buffer->p_data = p_data;
00042     if( !p_buffer->p_data )
00043     {
00044         if( !( p_buffer->p_data = malloc( i_size ) ) )
00045             return -1;
00046     }
00047     p_buffer->p_data[0] = 0;
00048     return 0;
00049 }
00050 
00051 static inline void bits_align( bits_buffer_t *p_buffer )
00052 {
00053     if( p_buffer->i_mask != 0x80 && p_buffer->i_data < p_buffer->i_size )
00054     {
00055         p_buffer->i_mask = 0x80;
00056         p_buffer->i_data++;
00057         p_buffer->p_data[p_buffer->i_data] = 0x00;
00058     }
00059 }
00060 
00061 static inline void bits_write( bits_buffer_t *p_buffer,
00062                                int i_count, uint64_t i_bits )
00063 {
00064     while( i_count > 0 )
00065     {
00066         i_count--;
00067 
00068         if( ( i_bits >> i_count )&0x01 )
00069         {
00070             p_buffer->p_data[p_buffer->i_data] |= p_buffer->i_mask;
00071         }
00072         else
00073         {
00074             p_buffer->p_data[p_buffer->i_data] &= ~p_buffer->i_mask;
00075         }
00076         p_buffer->i_mask >>= 1;
00077         if( p_buffer->i_mask == 0 )
00078         {
00079             p_buffer->i_data++;
00080             p_buffer->i_mask = 0x80;
00081         }
00082     }
00083 }
00084 
00085 

Generated on Tue May 25 08:04:59 2010 for VLC by  doxygen 1.5.6