yading@10: /* yading@10: * MJPEG decoder yading@10: * Copyright (c) 2000, 2001 Fabrice Bellard yading@10: * Copyright (c) 2003 Alex Beregszaszi yading@10: * Copyright (c) 2003-2004 Michael Niedermayer yading@10: * yading@10: * This file is part of FFmpeg. yading@10: * yading@10: * FFmpeg is free software; you can redistribute it and/or yading@10: * modify it under the terms of the GNU Lesser General Public yading@10: * License as published by the Free Software Foundation; either yading@10: * version 2.1 of the License, or (at your option) any later version. yading@10: * yading@10: * FFmpeg is distributed in the hope that it will be useful, yading@10: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@10: * Lesser General Public License for more details. yading@10: * yading@10: * You should have received a copy of the GNU Lesser General Public yading@10: * License along with FFmpeg; if not, write to the Free Software yading@10: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@10: */ yading@10: yading@10: /** yading@10: * @file yading@10: * MJPEG decoder. yading@10: */ yading@10: yading@10: #ifndef AVCODEC_MJPEGDEC_H yading@10: #define AVCODEC_MJPEGDEC_H yading@10: yading@10: #include "libavutil/log.h" yading@10: yading@10: #include "avcodec.h" yading@10: #include "get_bits.h" yading@10: #include "dsputil.h" yading@10: #include "hpeldsp.h" yading@10: yading@10: #define MAX_COMPONENTS 4 yading@10: yading@10: typedef struct MJpegDecodeContext { yading@10: AVClass *class; yading@10: AVCodecContext *avctx; yading@10: GetBitContext gb; yading@10: yading@10: int start_code; /* current start code */ yading@10: int buffer_size; yading@10: uint8_t *buffer; yading@10: yading@10: int16_t quant_matrixes[4][64]; yading@10: VLC vlcs[3][4]; yading@10: int qscale[4]; ///< quantizer scale calculated from quant_matrixes yading@10: yading@10: int org_height; /* size given at codec init */ yading@10: int first_picture; /* true if decoding first picture */ yading@10: int interlaced; /* true if interlaced */ yading@10: int bottom_field; /* true if bottom field */ yading@10: int lossless; yading@10: int ls; yading@10: int progressive; yading@10: int rgb; yading@10: int upscale_h; yading@10: int chroma_height; yading@10: int upscale_v; yading@10: int rct; /* standard rct */ yading@10: int pegasus_rct; /* pegasus reversible colorspace transform */ yading@10: int bits; /* bits per component */ yading@10: yading@10: int maxval; yading@10: int near; ///< near lossless bound (si 0 for lossless) yading@10: int t1,t2,t3; yading@10: int reset; ///< context halfing interval ?rename yading@10: yading@10: int width, height; yading@10: int mb_width, mb_height; yading@10: int nb_components; yading@10: int block_stride[MAX_COMPONENTS]; yading@10: int component_id[MAX_COMPONENTS]; yading@10: int h_count[MAX_COMPONENTS]; /* horizontal and vertical count for each component */ yading@10: int v_count[MAX_COMPONENTS]; yading@10: int comp_index[MAX_COMPONENTS]; yading@10: int dc_index[MAX_COMPONENTS]; yading@10: int ac_index[MAX_COMPONENTS]; yading@10: int nb_blocks[MAX_COMPONENTS]; yading@10: int h_scount[MAX_COMPONENTS]; yading@10: int v_scount[MAX_COMPONENTS]; yading@10: int h_max, v_max; /* maximum h and v counts */ yading@10: int quant_index[4]; /* quant table index for each component */ yading@10: int last_dc[MAX_COMPONENTS]; /* last DEQUANTIZED dc (XXX: am I right to do that ?) */ yading@10: AVFrame picture; /* picture structure */ yading@10: AVFrame *picture_ptr; /* pointer to picture structure */ yading@10: int got_picture; ///< we found a SOF and picture is valid, too. yading@10: int linesize[MAX_COMPONENTS]; ///< linesize << interlaced yading@10: int8_t *qscale_table; yading@10: DECLARE_ALIGNED(16, int16_t, block)[64]; yading@10: int16_t (*blocks[MAX_COMPONENTS])[64]; ///< intermediate sums (progressive mode) yading@10: uint8_t *last_nnz[MAX_COMPONENTS]; yading@10: uint64_t coefs_finished[MAX_COMPONENTS]; ///< bitmask of which coefs have been completely decoded (progressive mode) yading@10: ScanTable scantable; yading@10: DSPContext dsp; yading@10: HpelDSPContext hdsp; yading@10: yading@10: int restart_interval; yading@10: int restart_count; yading@10: yading@10: int buggy_avid; yading@10: int cs_itu601; yading@10: int interlace_polarity; yading@10: yading@10: int mjpb_skiptosod; yading@10: yading@10: int cur_scan; /* current scan, used by JPEG-LS */ yading@10: int flipped; /* true if picture is flipped */ yading@10: yading@10: uint16_t (*ljpeg_buffer)[4]; yading@10: unsigned int ljpeg_buffer_size; yading@10: yading@10: int extern_huff; yading@10: } MJpegDecodeContext; yading@10: yading@10: int ff_mjpeg_decode_init(AVCodecContext *avctx); yading@10: int ff_mjpeg_decode_end(AVCodecContext *avctx); yading@10: int ff_mjpeg_decode_frame(AVCodecContext *avctx, yading@10: void *data, int *got_frame, yading@10: AVPacket *avpkt); yading@10: int ff_mjpeg_decode_dqt(MJpegDecodeContext *s); yading@10: int ff_mjpeg_decode_dht(MJpegDecodeContext *s); yading@10: int ff_mjpeg_decode_sof(MJpegDecodeContext *s); yading@10: int ff_mjpeg_decode_sos(MJpegDecodeContext *s, yading@10: const uint8_t *mb_bitmask, const AVFrame *reference); yading@10: int ff_mjpeg_find_marker(MJpegDecodeContext *s, yading@10: const uint8_t **buf_ptr, const uint8_t *buf_end, yading@10: const uint8_t **unescaped_buf_ptr, int *unescaped_buf_size); yading@10: yading@10: #endif /* AVCODEC_MJPEGDEC_H */