mjpegenc_huffman.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * MJPEG encoder
  3. * Copyright (c) 2016 William Ma, Ted Ying, Jerry Jiang
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file
  23. * Huffman table generation for MJPEG encoder.
  24. */
  25. #ifndef AVCODEC_MJPEGENC_HUFFMAN_H
  26. #define AVCODEC_MJPEGENC_HUFFMAN_H
  27. #include <stdint.h>
  28. typedef struct MJpegEncHuffmanContext {
  29. int val_count[256];
  30. } MJpegEncHuffmanContext;
  31. // Uses the package merge algorithm to compute the Huffman table.
  32. void ff_mjpeg_encode_huffman_init(MJpegEncHuffmanContext *s);
  33. static inline void ff_mjpeg_encode_huffman_increment(MJpegEncHuffmanContext *s,
  34. uint8_t val)
  35. {
  36. s->val_count[val]++;
  37. }
  38. void ff_mjpeg_encode_huffman_close(MJpegEncHuffmanContext *s,
  39. uint8_t bits[17], uint8_t val[],
  40. int max_nval);
  41. /**
  42. * Used to assign a occurrence count or "probability" to an input value
  43. */
  44. typedef struct PTable {
  45. int value; ///< input value
  46. int prob; ///< number of occurences of this value in input
  47. } PTable;
  48. /**
  49. * Used to store intermediate lists in the package merge algorithm
  50. */
  51. typedef struct PackageMergerList {
  52. int nitems; ///< number of items in the list and probability ex. 4
  53. int item_idx[515]; ///< index range for each item in items 0, 2, 5, 9, 13
  54. int probability[514]; ///< probability of each item 3, 8, 18, 46
  55. int items[257 * 16]; ///< chain of all individual values that make up items A, B, A, B, C, A, B, C, D, C, D, D, E
  56. } PackageMergerList;
  57. /**
  58. * Used to store optimal huffman encoding results
  59. */
  60. typedef struct HuffTable {
  61. int code; ///< code is the input value
  62. int length; ///< length of the encoding
  63. } HuffTable;
  64. void ff_mjpegenc_huffman_compute_bits(PTable *prob_table, HuffTable *distincts,
  65. int size, int max_length);
  66. #endif /* AVCODEC_MJPEGENC_HUFFMAN_H */