2
0

mjpegenc.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * MJPEG encoder
  3. * Copyright (c) 2000, 2001 Fabrice Bellard
  4. * Copyright (c) 2003 Alex Beregszaszi
  5. * Copyright (c) 2003-2004 Michael Niedermayer
  6. *
  7. * Support for external huffman table, various fixes (AVID workaround),
  8. * aspecting, new decode_frame mechanism and apple mjpeg-b support
  9. * by Alex Beregszaszi
  10. *
  11. * This file is part of FFmpeg.
  12. *
  13. * FFmpeg is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU Lesser General Public
  15. * License as published by the Free Software Foundation; either
  16. * version 2.1 of the License, or (at your option) any later version.
  17. *
  18. * FFmpeg is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  21. * Lesser General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Lesser General Public
  24. * License along with FFmpeg; if not, write to the Free Software
  25. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  26. */
  27. /**
  28. * @file
  29. * MJPEG encoder.
  30. */
  31. #ifndef AVCODEC_MJPEGENC_H
  32. #define AVCODEC_MJPEGENC_H
  33. #include <stdint.h>
  34. #include "mjpeg.h"
  35. #include "mpegvideo.h"
  36. #include "put_bits.h"
  37. /**
  38. * Buffer of JPEG frame data.
  39. *
  40. * Optimal Huffman table generation requires the frame data to be loaded into
  41. * a buffer so that the tables can be computed.
  42. * There are at most mb_width*mb_height*12*64 of these per frame.
  43. */
  44. typedef struct MJpegHuffmanCode {
  45. // 0=DC lum, 1=DC chrom, 2=AC lum, 3=AC chrom
  46. uint8_t table_id; ///< The Huffman table id associated with the data.
  47. uint8_t code; ///< The exponent.
  48. uint16_t mant; ///< The mantissa.
  49. } MJpegHuffmanCode;
  50. /**
  51. * Holds JPEG frame data and Huffman table data.
  52. */
  53. typedef struct MJpegContext {
  54. //FIXME use array [3] instead of lumi / chroma, for easier addressing
  55. uint8_t huff_size_dc_luminance[12]; ///< DC luminance Huffman table size.
  56. uint16_t huff_code_dc_luminance[12]; ///< DC luminance Huffman table codes.
  57. uint8_t huff_size_dc_chrominance[12]; ///< DC chrominance Huffman table size.
  58. uint16_t huff_code_dc_chrominance[12]; ///< DC chrominance Huffman table codes.
  59. uint8_t huff_size_ac_luminance[256]; ///< AC luminance Huffman table size.
  60. uint16_t huff_code_ac_luminance[256]; ///< AC luminance Huffman table codes.
  61. uint8_t huff_size_ac_chrominance[256]; ///< AC chrominance Huffman table size.
  62. uint16_t huff_code_ac_chrominance[256]; ///< AC chrominance Huffman table codes.
  63. /** Storage for AC luminance VLC (in MpegEncContext) */
  64. uint8_t uni_ac_vlc_len[64 * 64 * 2];
  65. /** Storage for AC chrominance VLC (in MpegEncContext) */
  66. uint8_t uni_chroma_ac_vlc_len[64 * 64 * 2];
  67. // Default DC tables have exactly 12 values
  68. uint8_t bits_dc_luminance[17]; ///< DC luminance Huffman bits.
  69. uint8_t val_dc_luminance[12]; ///< DC luminance Huffman values.
  70. uint8_t bits_dc_chrominance[17]; ///< DC chrominance Huffman bits.
  71. uint8_t val_dc_chrominance[12]; ///< DC chrominance Huffman values.
  72. // 8-bit JPEG has max 256 values
  73. uint8_t bits_ac_luminance[17]; ///< AC luminance Huffman bits.
  74. uint8_t val_ac_luminance[256]; ///< AC luminance Huffman values.
  75. uint8_t bits_ac_chrominance[17]; ///< AC chrominance Huffman bits.
  76. uint8_t val_ac_chrominance[256]; ///< AC chrominance Huffman values.
  77. size_t huff_ncode; ///< Number of current entries in the buffer.
  78. MJpegHuffmanCode *huff_buffer; ///< Buffer for Huffman code values.
  79. } MJpegContext;
  80. /**
  81. * Enum for the Huffman encoding strategy.
  82. */
  83. enum HuffmanTableOption {
  84. HUFFMAN_TABLE_DEFAULT = 0, ///< Use the default Huffman tables.
  85. HUFFMAN_TABLE_OPTIMAL = 1, ///< Compute and use optimal Huffman tables.
  86. NB_HUFFMAN_TABLE_OPTION = 2
  87. };
  88. static inline void put_marker(PutBitContext *p, enum JpegMarker code)
  89. {
  90. put_bits(p, 8, 0xff);
  91. put_bits(p, 8, code);
  92. }
  93. int ff_mjpeg_encode_init(MpegEncContext *s);
  94. void ff_mjpeg_encode_close(MpegEncContext *s);
  95. void ff_mjpeg_encode_mb(MpegEncContext *s, int16_t block[12][64]);
  96. #endif /* AVCODEC_MJPEGENC_H */