mjpeg.h 4.7 KB

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