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.

98 lines
2.4KB

  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 "bswapdsp.h"
  33. #include "huffyuv.h"
  34. int ff_huffyuv_generate_bits_table(uint32_t *dst, const uint8_t *len_table)
  35. {
  36. int len, index;
  37. uint32_t bits = 0;
  38. for (len = 32; len > 0; len--) {
  39. for (index = 0; index < 256; index++) {
  40. if (len_table[index] == len)
  41. dst[index] = bits++;
  42. }
  43. if (bits & 1) {
  44. av_log(NULL, AV_LOG_ERROR, "Error generating huffman table\n");
  45. return -1;
  46. }
  47. bits >>= 1;
  48. }
  49. return 0;
  50. }
  51. av_cold int ff_huffyuv_alloc_temp(HYuvContext *s)
  52. {
  53. int i;
  54. if (s->bitstream_bpp<24) {
  55. for (i=0; i<3; i++) {
  56. s->temp[i]= av_malloc(s->width + 16);
  57. if (!s->temp[i])
  58. return AVERROR(ENOMEM);
  59. }
  60. } else {
  61. s->temp[0]= av_mallocz(4*s->width + 16);
  62. if (!s->temp[0])
  63. return AVERROR(ENOMEM);
  64. }
  65. return 0;
  66. }
  67. av_cold void ff_huffyuv_common_init(AVCodecContext *avctx)
  68. {
  69. HYuvContext *s = avctx->priv_data;
  70. s->avctx = avctx;
  71. s->flags = avctx->flags;
  72. ff_bswapdsp_init(&s->bdsp);
  73. s->width = avctx->width;
  74. s->height = avctx->height;
  75. assert(s->width>0 && s->height>0);
  76. }
  77. void ff_huffyuv_common_end(HYuvContext *s)
  78. {
  79. int i;
  80. for(i = 0; i < 3; i++) {
  81. av_freep(&s->temp[i]);
  82. }
  83. }