]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/common.c
8bpp support (no dithering yet, use -vop noise for now)
[ffmpeg] / libavcodec / common.c
index 5224299fdad82bd45956a64a5de337f7c2629c29..97788ec9dc2596f33d784ec6a0bf61d3dda8656a 100644 (file)
@@ -1,25 +1,24 @@
 /*
  * Common bit i/o utils
- * Copyright (c) 2000, 2001 Gerard Lantau.
+ * Copyright (c) 2000, 2001 Fabrice Bellard.
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
  *
- * This program is distributed in the hope that it will be useful,
+ * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  * alternative bitstream reader & writer by Michael Niedermayer <michaelni@gmx.at>
  */
 #include "common.h"
-#include <math.h>
 
 void init_put_bits(PutBitContext *s, 
                    UINT8 *buffer, int buffer_size,
@@ -108,6 +107,15 @@ void jflush_put_bits(PutBitContext *s)
 }
 #endif
 
+void put_string(PutBitContext * pbc, char *s)
+{
+    while(*s){
+        put_bits(pbc, 8, *s);
+        s++;
+    }
+    put_bits(pbc, 8, 0);
+}
+
 /* bit input functions */
 
 void init_get_bits(GetBitContext *s, 
@@ -166,6 +174,9 @@ unsigned int get_bits_long(GetBitContext *s, int n)
                 (buf_ptr[-2] << 8) |
                 (buf_ptr[-1]);     
 #endif
+            val |= bit_buf >> (32 + bit_cnt);
+            bit_buf <<= - bit_cnt;
+            bit_cnt += 32;
         } else {
             buf_ptr -= 4;
             bit_buf = 0;
@@ -177,11 +188,13 @@ unsigned int get_bits_long(GetBitContext *s, int n)
                 bit_buf |= *buf_ptr++ << 8;
             if (buf_ptr < s->buf_end)
                 bit_buf |= *buf_ptr++;
+
+            val |= bit_buf >> (32 + bit_cnt);
+            bit_buf <<= - bit_cnt;
+            bit_cnt += 8*(buf_ptr - s->buf_ptr);
+            if(bit_cnt<0) bit_cnt=0;
         }
         s->buf_ptr = buf_ptr;
-        val |= bit_buf >> (32 + bit_cnt);
-        bit_buf <<= - bit_cnt;
-        bit_cnt += 32;
     }
     s->bit_buf = bit_buf;
     s->bit_cnt = bit_cnt;
@@ -435,10 +448,8 @@ int init_vlc(VLC *vlc, int nb_bits, int nb_codes,
                     bits, bits_wrap, bits_size,
                     codes, codes_wrap, codes_size,
                     0, 0) < 0) {
-        if (vlc->table_bits)
-            free(vlc->table_bits);
-        if (vlc->table_codes)
-            free(vlc->table_codes);
+        av_free(vlc->table_bits);
+        av_free(vlc->table_codes);
         return -1;
     }
     return 0;
@@ -447,8 +458,8 @@ int init_vlc(VLC *vlc, int nb_bits, int nb_codes,
 
 void free_vlc(VLC *vlc)
 {
-    free(vlc->table_bits);
-    free(vlc->table_codes);
+    av_free(vlc->table_bits);
+    av_free(vlc->table_codes);
 }
 
 int ff_gcd(int a, int b){