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.

157 lines
4.8KB

  1. /*
  2. * MJPEG encoder and decoder
  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 Libav.
  12. *
  13. * Libav 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. * Libav 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 Libav; 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 and decoder.
  30. */
  31. #ifndef AVCODEC_MJPEG_H
  32. #define AVCODEC_MJPEG_H
  33. #include "libavutil/internal.h"
  34. #include "avcodec.h"
  35. #include "put_bits.h"
  36. /* JPEG marker codes */
  37. typedef enum {
  38. /* start of frame */
  39. SOF0 = 0xc0, /* baseline */
  40. SOF1 = 0xc1, /* extended sequential, huffman */
  41. SOF2 = 0xc2, /* progressive, huffman */
  42. SOF3 = 0xc3, /* lossless, huffman */
  43. SOF5 = 0xc5, /* differential sequential, huffman */
  44. SOF6 = 0xc6, /* differential progressive, huffman */
  45. SOF7 = 0xc7, /* differential lossless, huffman */
  46. JPG = 0xc8, /* reserved for JPEG extension */
  47. SOF9 = 0xc9, /* extended sequential, arithmetic */
  48. SOF10 = 0xca, /* progressive, arithmetic */
  49. SOF11 = 0xcb, /* lossless, arithmetic */
  50. SOF13 = 0xcd, /* differential sequential, arithmetic */
  51. SOF14 = 0xce, /* differential progressive, arithmetic */
  52. SOF15 = 0xcf, /* differential lossless, arithmetic */
  53. DHT = 0xc4, /* define huffman tables */
  54. DAC = 0xcc, /* define arithmetic-coding conditioning */
  55. /* restart with modulo 8 count "m" */
  56. RST0 = 0xd0,
  57. RST1 = 0xd1,
  58. RST2 = 0xd2,
  59. RST3 = 0xd3,
  60. RST4 = 0xd4,
  61. RST5 = 0xd5,
  62. RST6 = 0xd6,
  63. RST7 = 0xd7,
  64. SOI = 0xd8, /* start of image */
  65. EOI = 0xd9, /* end of image */
  66. SOS = 0xda, /* start of scan */
  67. DQT = 0xdb, /* define quantization tables */
  68. DNL = 0xdc, /* define number of lines */
  69. DRI = 0xdd, /* define restart interval */
  70. DHP = 0xde, /* define hierarchical progression */
  71. EXP = 0xdf, /* expand reference components */
  72. APP0 = 0xe0,
  73. APP1 = 0xe1,
  74. APP2 = 0xe2,
  75. APP3 = 0xe3,
  76. APP4 = 0xe4,
  77. APP5 = 0xe5,
  78. APP6 = 0xe6,
  79. APP7 = 0xe7,
  80. APP8 = 0xe8,
  81. APP9 = 0xe9,
  82. APP10 = 0xea,
  83. APP11 = 0xeb,
  84. APP12 = 0xec,
  85. APP13 = 0xed,
  86. APP14 = 0xee,
  87. APP15 = 0xef,
  88. JPG0 = 0xf0,
  89. JPG1 = 0xf1,
  90. JPG2 = 0xf2,
  91. JPG3 = 0xf3,
  92. JPG4 = 0xf4,
  93. JPG5 = 0xf5,
  94. JPG6 = 0xf6,
  95. SOF48 = 0xf7, ///< JPEG-LS
  96. LSE = 0xf8, ///< JPEG-LS extension parameters
  97. JPG9 = 0xf9,
  98. JPG10 = 0xfa,
  99. JPG11 = 0xfb,
  100. JPG12 = 0xfc,
  101. JPG13 = 0xfd,
  102. COM = 0xfe, /* comment */
  103. TEM = 0x01, /* temporary private use for arithmetic coding */
  104. /* 0x02 -> 0xbf reserved */
  105. } JPEG_MARKER;
  106. static inline void put_marker(PutBitContext *p, int code)
  107. {
  108. put_bits(p, 8, 0xff);
  109. put_bits(p, 8, code);
  110. }
  111. #define PREDICT(ret, topleft, top, left, predictor)\
  112. switch(predictor){\
  113. case 1: ret= left; break;\
  114. case 2: ret= top; break;\
  115. case 3: ret= topleft; break;\
  116. case 4: ret= left + top - topleft; break;\
  117. case 5: ret= left + ((top - topleft)>>1); break;\
  118. case 6: ret= top + ((left - topleft)>>1); break;\
  119. default:\
  120. case 7: ret= (left + top)>>1; break;\
  121. }
  122. extern av_export const uint8_t avpriv_mjpeg_bits_dc_luminance[];
  123. extern av_export const uint8_t avpriv_mjpeg_val_dc[];
  124. extern av_export const uint8_t avpriv_mjpeg_bits_dc_chrominance[];
  125. extern av_export const uint8_t avpriv_mjpeg_bits_ac_luminance[];
  126. extern av_export const uint8_t avpriv_mjpeg_val_ac_luminance[];
  127. extern av_export const uint8_t avpriv_mjpeg_bits_ac_chrominance[];
  128. extern av_export const uint8_t avpriv_mjpeg_val_ac_chrominance[];
  129. void ff_mjpeg_build_huffman_codes(uint8_t *huff_size, uint16_t *huff_code,
  130. const uint8_t *bits_table,
  131. const uint8_t *val_table);
  132. #endif /* AVCODEC_MJPEG_H */