00001 /* 00002 * Lagarith range decoder 00003 * Copyright (c) 2009 Nathan Caldwell <saintdev (at) gmail.com> 00004 * Copyright (c) 2009 David Conrad 00005 * 00006 * This file is part of FFmpeg. 00007 * 00008 * FFmpeg is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public 00010 * License as published by the Free Software Foundation; either 00011 * version 2.1 of the License, or (at your option) any later version. 00012 * 00013 * FFmpeg is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with FFmpeg; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00021 */ 00022 00030 #include "get_bits.h" 00031 #include "lagarithrac.h" 00032 00033 void lag_rac_init(lag_rac *l, GetBitContext *gb, int length) 00034 { 00035 int i, j; 00036 00037 /* According to reference decoder "1st byte is garbage", 00038 * however, it gets skipped by the call to align_get_bits() 00039 */ 00040 align_get_bits(gb); 00041 l->bytestream_start = 00042 l->bytestream = gb->buffer + get_bits_count(gb) / 8; 00043 l->bytestream_end = l->bytestream_start + length; 00044 00045 l->range = 0x80; 00046 l->low = *l->bytestream >> 1; 00047 l->hash_shift = FFMAX(l->scale - 8, 0); 00048 00049 for (i = j = 0; i < 256; i++) { 00050 unsigned r = i << l->hash_shift; 00051 while (l->prob[j + 1] <= r) 00052 j++; 00053 l->range_hash[i] = j; 00054 } 00055 00056 /* Add conversion factor to hash_shift so we don't have to in lag_get_rac. */ 00057 l->hash_shift += 23; 00058 }