You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.8KB

  1. /*
  2. * Lagarith range decoder
  3. * Copyright (c) 2009 Nathan Caldwell <saintdev (at) gmail.com>
  4. * Copyright (c) 2009 David Conrad
  5. *
  6. * This file is part of Libav.
  7. *
  8. * Libav is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * Libav is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with Libav; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. /**
  23. * @file
  24. * Lagarith range decoder
  25. * @author Nathan Caldwell
  26. * @author David Conrad
  27. */
  28. #include "bitstream.h"
  29. #include "lagarithrac.h"
  30. void ff_lag_rac_init(lag_rac *l, BitstreamContext *bc, int length)
  31. {
  32. int i, j, left;
  33. /* According to reference decoder "1st byte is garbage",
  34. * however, it gets skipped by the call to bitstream_align()
  35. */
  36. bitstream_align(bc);
  37. left = bitstream_bits_left(bc) >> 3;
  38. l->bytestream_start =
  39. l->bytestream = bc->buffer + bitstream_tell(bc) / 8;
  40. l->bytestream_end = l->bytestream_start + FFMIN(length, left);
  41. l->range = 0x80;
  42. l->low = *l->bytestream >> 1;
  43. l->hash_shift = FFMAX(l->scale, 8) - 8;
  44. for (i = j = 0; i < 256; i++) {
  45. unsigned r = i << l->hash_shift;
  46. while (l->prob[j + 1] <= r)
  47. j++;
  48. l->range_hash[i] = j;
  49. }
  50. /* Add conversion factor to hash_shift so we don't have to in lag_get_rac. */
  51. l->hash_shift += 23;
  52. }