mjpegdec.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * MJPEG decoder
  3. * Copyright (c) 2000, 2001 Fabrice Bellard
  4. * Copyright (c) 2003 Alex Beregszaszi
  5. * Copyright (c) 2003-2004 Michael Niedermayer
  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. * MJPEG decoder.
  26. */
  27. #ifndef AVCODEC_MJPEGDEC_H
  28. #define AVCODEC_MJPEGDEC_H
  29. #include "libavutil/log.h"
  30. #include "libavutil/pixdesc.h"
  31. #include "libavutil/stereo3d.h"
  32. #include "avcodec.h"
  33. #include "blockdsp.h"
  34. #include "get_bits.h"
  35. #include "hpeldsp.h"
  36. #include "idctdsp.h"
  37. #undef near /* This file uses struct member 'near' which in windows.h is defined as empty. */
  38. #define MAX_COMPONENTS 4
  39. typedef struct MJpegDecodeContext {
  40. AVClass *class;
  41. AVCodecContext *avctx;
  42. GetBitContext gb;
  43. int buf_size;
  44. int start_code; /* current start code */
  45. int buffer_size;
  46. uint8_t *buffer;
  47. uint16_t quant_matrixes[4][64];
  48. VLC vlcs[3][4];
  49. int qscale[4]; ///< quantizer scale calculated from quant_matrixes
  50. int org_height; /* size given at codec init */
  51. int first_picture; /* true if decoding first picture */
  52. int interlaced; /* true if interlaced */
  53. int bottom_field; /* true if bottom field */
  54. int lossless;
  55. int ls;
  56. int progressive;
  57. int bayer; /* true if it's a bayer-encoded JPEG embedded in a DNG */
  58. int rgb;
  59. uint8_t upscale_h[4];
  60. uint8_t upscale_v[4];
  61. int rct; /* standard rct */
  62. int pegasus_rct; /* pegasus reversible colorspace transform */
  63. int bits; /* bits per component */
  64. int colr;
  65. int xfrm;
  66. int adobe_transform;
  67. int maxval;
  68. int near; ///< near lossless bound (si 0 for lossless)
  69. int t1,t2,t3;
  70. int reset; ///< context halfing interval ?rename
  71. int width, height;
  72. int mb_width, mb_height;
  73. int nb_components;
  74. int block_stride[MAX_COMPONENTS];
  75. int component_id[MAX_COMPONENTS];
  76. int h_count[MAX_COMPONENTS]; /* horizontal and vertical count for each component */
  77. int v_count[MAX_COMPONENTS];
  78. int comp_index[MAX_COMPONENTS];
  79. int dc_index[MAX_COMPONENTS];
  80. int ac_index[MAX_COMPONENTS];
  81. int nb_blocks[MAX_COMPONENTS];
  82. int h_scount[MAX_COMPONENTS];
  83. int v_scount[MAX_COMPONENTS];
  84. int quant_sindex[MAX_COMPONENTS];
  85. int h_max, v_max; /* maximum h and v counts */
  86. int quant_index[4]; /* quant table index for each component */
  87. int last_dc[MAX_COMPONENTS]; /* last DEQUANTIZED dc (XXX: am I right to do that ?) */
  88. AVFrame *picture; /* picture structure */
  89. AVFrame *picture_ptr; /* pointer to picture structure */
  90. int got_picture; ///< we found a SOF and picture is valid, too.
  91. int linesize[MAX_COMPONENTS]; ///< linesize << interlaced
  92. int8_t *qscale_table;
  93. DECLARE_ALIGNED(32, int16_t, block)[64];
  94. int16_t (*blocks[MAX_COMPONENTS])[64]; ///< intermediate sums (progressive mode)
  95. uint8_t *last_nnz[MAX_COMPONENTS];
  96. uint64_t coefs_finished[MAX_COMPONENTS]; ///< bitmask of which coefs have been completely decoded (progressive mode)
  97. int palette_index;
  98. ScanTable scantable;
  99. BlockDSPContext bdsp;
  100. HpelDSPContext hdsp;
  101. IDCTDSPContext idsp;
  102. int restart_interval;
  103. int restart_count;
  104. int buggy_avid;
  105. int cs_itu601;
  106. int interlace_polarity;
  107. int multiscope;
  108. int mjpb_skiptosod;
  109. int cur_scan; /* current scan, used by JPEG-LS */
  110. int flipped; /* true if picture is flipped */
  111. uint16_t (*ljpeg_buffer)[4];
  112. unsigned int ljpeg_buffer_size;
  113. int extern_huff;
  114. AVDictionary *exif_metadata;
  115. AVStereo3D *stereo3d; ///!< stereoscopic information (cached, since it is read before frame allocation)
  116. const AVPixFmtDescriptor *pix_desc;
  117. uint8_t **iccdata;
  118. int *iccdatalens;
  119. int iccnum;
  120. int iccread;
  121. // Raw stream data for hwaccel use.
  122. const uint8_t *raw_image_buffer;
  123. size_t raw_image_buffer_size;
  124. const uint8_t *raw_scan_buffer;
  125. size_t raw_scan_buffer_size;
  126. uint8_t raw_huffman_lengths[2][4][16];
  127. uint8_t raw_huffman_values[2][4][256];
  128. enum AVPixelFormat hwaccel_sw_pix_fmt;
  129. enum AVPixelFormat hwaccel_pix_fmt;
  130. void *hwaccel_picture_private;
  131. } MJpegDecodeContext;
  132. int ff_mjpeg_decode_init(AVCodecContext *avctx);
  133. int ff_mjpeg_decode_end(AVCodecContext *avctx);
  134. int ff_mjpeg_decode_frame(AVCodecContext *avctx,
  135. void *data, int *got_frame,
  136. AVPacket *avpkt);
  137. int ff_mjpeg_decode_dqt(MJpegDecodeContext *s);
  138. int ff_mjpeg_decode_dht(MJpegDecodeContext *s);
  139. int ff_mjpeg_decode_sof(MJpegDecodeContext *s);
  140. int ff_mjpeg_decode_sos(MJpegDecodeContext *s,
  141. const uint8_t *mb_bitmask,int mb_bitmask_size,
  142. const AVFrame *reference);
  143. int ff_mjpeg_find_marker(MJpegDecodeContext *s,
  144. const uint8_t **buf_ptr, const uint8_t *buf_end,
  145. const uint8_t **unescaped_buf_ptr, int *unescaped_buf_size);
  146. #endif /* AVCODEC_MJPEGDEC_H */