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.

186 lines
5.9KB

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