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.

97 lines
2.3KB

  1. /*
  2. * huffyuv codec for libavcodec
  3. *
  4. * Copyright (c) 2002-2003 Michael Niedermayer <michaelni@gmx.at>
  5. *
  6. * see http://www.pcisys.net/~melanson/codecs/huffyuv.txt for a description of
  7. * the algorithm used
  8. *
  9. * This file is part of Libav.
  10. *
  11. * Libav is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU Lesser General Public
  13. * License as published by the Free Software Foundation; either
  14. * version 2.1 of the License, or (at your option) any later version.
  15. *
  16. * Libav is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public
  22. * License along with Libav; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  24. */
  25. /**
  26. * @file
  27. * huffyuv codec for libavcodec.
  28. */
  29. #include <stdint.h>
  30. #include "libavutil/mem.h"
  31. #include "avcodec.h"
  32. #include "huffyuv.h"
  33. int ff_huffyuv_generate_bits_table(uint32_t *dst, const uint8_t *len_table)
  34. {
  35. int len, index;
  36. uint32_t bits = 0;
  37. for (len = 32; len > 0; len--) {
  38. for (index = 0; index < 256; index++) {
  39. if (len_table[index] == len)
  40. dst[index] = bits++;
  41. }
  42. if (bits & 1) {
  43. av_log(NULL, AV_LOG_ERROR, "Error generating huffman table\n");
  44. return -1;
  45. }
  46. bits >>= 1;
  47. }
  48. return 0;
  49. }
  50. av_cold int ff_huffyuv_alloc_temp(HYuvContext *s)
  51. {
  52. int i;
  53. if (s->bitstream_bpp<24) {
  54. for (i=0; i<3; i++) {
  55. s->temp[i]= av_malloc(s->width + 16);
  56. if (!s->temp[i])
  57. return AVERROR(ENOMEM);
  58. }
  59. } else {
  60. s->temp[0]= av_mallocz(4*s->width + 16);
  61. if (!s->temp[0])
  62. return AVERROR(ENOMEM);
  63. }
  64. return 0;
  65. }
  66. av_cold void ff_huffyuv_common_init(AVCodecContext *avctx)
  67. {
  68. HYuvContext *s = avctx->priv_data;
  69. s->avctx = avctx;
  70. s->flags = avctx->flags;
  71. ff_dsputil_init(&s->dsp, avctx);
  72. s->width = avctx->width;
  73. s->height = avctx->height;
  74. assert(s->width>0 && s->height>0);
  75. }
  76. void ff_huffyuv_common_end(HYuvContext *s)
  77. {
  78. int i;
  79. for(i = 0; i < 3; i++) {
  80. av_freep(&s->temp[i]);
  81. }
  82. }