Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

bits.h

00001 /*****************************************************************************
00002  * bits.h
00003  *****************************************************************************
00004  * Copyright (C) 2001, 2002 the VideoLAN team
00005  * $Id: bits.h 12798 2005-10-09 17:01:08Z fenrir $
00006  *
00007  * Authors: Laurent Aimar <[email protected]>
00008  *          Eric Petit <[email protected]>
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., 59 Temple Place - Suite 330, Boston, MA  02111, 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     p_buffer->p_data[0] = 0;
00043     if( !p_buffer->p_data )
00044     {
00045         if( !( p_buffer->p_data = malloc( i_size ) ) )
00046             return -1;
00047     }
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 Dec 20 10:14:49 2005 for vlc-0.8.4a by  doxygen 1.4.2