huffyuv.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (c) 2002-2014 Michael Niedermayer <michaelni@gmx.at>
  3. *
  4. * see http://www.pcisys.net/~melanson/codecs/huffyuv.txt for a description of
  5. * the algorithm used
  6. *
  7. * This file is part of FFmpeg.
  8. *
  9. * FFmpeg is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2.1 of the License, or (at your option) any later version.
  13. *
  14. * FFmpeg is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with FFmpeg; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. /**
  24. * @file
  25. * huffyuv codec for libavcodec.
  26. */
  27. #ifndef AVCODEC_HUFFYUV_H
  28. #define AVCODEC_HUFFYUV_H
  29. #include <stdint.h>
  30. #include "avcodec.h"
  31. #include "bswapdsp.h"
  32. #include "get_bits.h"
  33. #include "huffyuvdsp.h"
  34. #include "huffyuvencdsp.h"
  35. #include "put_bits.h"
  36. #include "lossless_videodsp.h"
  37. #include "lossless_videoencdsp.h"
  38. #define VLC_BITS 12
  39. #define MAX_BITS 16
  40. #define MAX_N (1<<MAX_BITS)
  41. #define MAX_VLC_N 16384
  42. typedef enum Predictor {
  43. LEFT = 0,
  44. PLANE,
  45. MEDIAN,
  46. } Predictor;
  47. typedef struct HYuvContext {
  48. AVClass *class;
  49. AVCodecContext *avctx;
  50. Predictor predictor;
  51. GetBitContext gb;
  52. PutBitContext pb;
  53. int interlaced;
  54. int decorrelate;
  55. int bitstream_bpp;
  56. int version;
  57. int yuy2; //use yuy2 instead of 422P
  58. int bgr32; //use bgr32 instead of bgr24
  59. int bps;
  60. int n; // 1<<bps
  61. int vlc_n; // number of vlc codes (FFMIN(1<<bps, MAX_VLC_N))
  62. int alpha;
  63. int chroma;
  64. int yuv;
  65. int chroma_h_shift;
  66. int chroma_v_shift;
  67. int width, height;
  68. int flags;
  69. int context;
  70. int picture_number;
  71. int last_slice_end;
  72. uint8_t *temp[3];
  73. uint16_t *temp16[3]; ///< identical to temp but 16bit type
  74. uint64_t stats[4][MAX_VLC_N];
  75. uint8_t len[4][MAX_VLC_N];
  76. uint32_t bits[4][MAX_VLC_N];
  77. uint32_t pix_bgr_map[1<<VLC_BITS];
  78. VLC vlc[8]; //Y,U,V,A,YY,YU,YV,AA
  79. uint8_t *bitstream_buffer;
  80. unsigned int bitstream_buffer_size;
  81. BswapDSPContext bdsp;
  82. HuffYUVDSPContext hdsp;
  83. HuffYUVEncDSPContext hencdsp;
  84. LLVidDSPContext llviddsp;
  85. LLVidEncDSPContext llvidencdsp;
  86. int non_determ; // non-deterministic, multi-threaded encoder allowed
  87. } HYuvContext;
  88. void ff_huffyuv_common_init(AVCodecContext *s);
  89. void ff_huffyuv_common_end(HYuvContext *s);
  90. int ff_huffyuv_alloc_temp(HYuvContext *s);
  91. int ff_huffyuv_generate_bits_table(uint32_t *dst, const uint8_t *len_table, int n);
  92. #endif /* AVCODEC_HUFFYUV_H */