FFmpeg
Loading...
Searching...
No Matches
mjpegenc.h
Go to the documentation of this file.
1/*
2 * MJPEG encoder
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/**
29 * @file
30 * MJPEG encoder.
31 */
32
33#ifndef AVCODEC_MJPEGENC_H
34#define AVCODEC_MJPEGENC_H
35
36#include <stdint.h>
37
38#include "mjpeg.h"
39#include "put_bits.h"
40
41/**
42 * Holds JPEG frame data and Huffman table data.
43 */
44typedef struct MJpegContext {
46 /* Force duplication of mjpeg matrices, useful for rtp streaming */
48 /* Tristate controlling the Ultra HDR gain map XMP packet */
51 //FIXME use array [3] instead of lumi / chroma, for easier addressing
52 uint8_t huff_size_dc_luminance[12]; ///< DC luminance Huffman table size.
53 uint16_t huff_code_dc_luminance[12]; ///< DC luminance Huffman table codes.
54 uint8_t huff_size_dc_chrominance[12]; ///< DC chrominance Huffman table size.
55 uint16_t huff_code_dc_chrominance[12]; ///< DC chrominance Huffman table codes.
56
57 uint8_t huff_size_ac_luminance[256]; ///< AC luminance Huffman table size.
58 uint16_t huff_code_ac_luminance[256]; ///< AC luminance Huffman table codes.
59 uint8_t huff_size_ac_chrominance[256]; ///< AC chrominance Huffman table size.
60 uint16_t huff_code_ac_chrominance[256]; ///< AC chrominance Huffman table codes.
61
62 /** Storage for AC luminance VLC */
63 uint8_t uni_ac_vlc_len[64 * 64 * 2];
64 /** Storage for AC chrominance VLC */
65 uint8_t uni_chroma_ac_vlc_len[64 * 64 * 2];
66
67 // Default DC tables have exactly 12 values
68 uint8_t bits_dc_luminance[17]; ///< DC luminance Huffman bits.
69 uint8_t val_dc_luminance[12]; ///< DC luminance Huffman values.
70 uint8_t bits_dc_chrominance[17]; ///< DC chrominance Huffman bits.
71 uint8_t val_dc_chrominance[12]; ///< DC chrominance Huffman values.
72
73 // 8-bit JPEG has max 256 values
74 uint8_t bits_ac_luminance[17]; ///< AC luminance Huffman bits.
75 uint8_t val_ac_luminance[256]; ///< AC luminance Huffman values.
76 uint8_t bits_ac_chrominance[17]; ///< AC chrominance Huffman bits.
77 uint8_t val_ac_chrominance[256]; ///< AC chrominance Huffman values.
78
79 size_t huff_ncode; ///< Number of current entries in the buffer.
80 struct MJpegHuffmanCode *huff_buffer; ///< Buffer for Huffman code values.
82
83/**
84 * Enum for the Huffman encoding strategy.
85 */
87 HUFFMAN_TABLE_DEFAULT = 0, ///< Use the default Huffman tables.
88 HUFFMAN_TABLE_OPTIMAL = 1, ///< Compute and use optimal Huffman tables.
90};
91
92static inline void put_marker(PutBitContext *p, enum JpegMarker code)
93{
94 put_bits(p, 8, 0xff);
95 put_bits(p, 8, code);
96}
97
98typedef struct MPVEncContext MPVEncContext;
99
101
102#endif /* AVCODEC_MJPEGENC_H */
#define s(width, name)
Definition cbs_vp9.c:198
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition j2kenc.c:154
MJPEG encoder and decoder.
JpegMarker
Definition mjpeg.h:37
HuffmanTableOption
Enum for the Huffman encoding strategy.
Definition mjpegenc.h:86
@ HUFFMAN_TABLE_OPTIMAL
Compute and use optimal Huffman tables.
Definition mjpegenc.h:88
@ NB_HUFFMAN_TABLE_OPTION
Definition mjpegenc.h:89
@ HUFFMAN_TABLE_DEFAULT
Use the default Huffman tables.
Definition mjpegenc.h:87
int ff_mjpeg_encode_stuffing(MPVEncContext *s)
Writes the complete JPEG frame when optimal huffman tables are enabled, otherwise writes the stuffing...
Definition mjpegenc.c:238
static void put_marker(PutBitContext *p, enum JpegMarker code)
Definition mjpegenc.h:92
bitstream writer API
const uint8_t * code
Definition spdifenc.c:433
Holds JPEG frame data and Huffman table data.
Definition mjpegenc.h:44
int force_duplicated_matrix
Definition mjpegenc.h:47
uint8_t huff_size_dc_chrominance[12]
DC chrominance Huffman table size.
Definition mjpegenc.h:54
uint8_t huff_size_ac_chrominance[256]
AC chrominance Huffman table size.
Definition mjpegenc.h:59
uint8_t bits_dc_luminance[17]
DC luminance Huffman bits.
Definition mjpegenc.h:68
uint8_t huff_size_dc_luminance[12]
DC luminance Huffman table size.
Definition mjpegenc.h:52
uint8_t bits_ac_luminance[17]
AC luminance Huffman bits.
Definition mjpegenc.h:74
struct MJpegHuffmanCode * huff_buffer
Buffer for Huffman code values.
Definition mjpegenc.h:80
uint16_t huff_code_ac_luminance[256]
AC luminance Huffman table codes.
Definition mjpegenc.h:58
int xmp_warned
Definition mjpegenc.h:50
uint16_t huff_code_ac_chrominance[256]
AC chrominance Huffman table codes.
Definition mjpegenc.h:60
size_t huff_ncode
Number of current entries in the buffer.
Definition mjpegenc.h:79
uint8_t val_ac_luminance[256]
AC luminance Huffman values.
Definition mjpegenc.h:75
uint8_t val_ac_chrominance[256]
AC chrominance Huffman values.
Definition mjpegenc.h:77
uint16_t huff_code_dc_chrominance[12]
DC chrominance Huffman table codes.
Definition mjpegenc.h:55
uint8_t huff_size_ac_luminance[256]
AC luminance Huffman table size.
Definition mjpegenc.h:57
uint8_t bits_dc_chrominance[17]
DC chrominance Huffman bits.
Definition mjpegenc.h:70
int xmp_gain_map
Definition mjpegenc.h:49
uint8_t val_dc_luminance[12]
DC luminance Huffman values.
Definition mjpegenc.h:69
uint16_t huff_code_dc_luminance[12]
DC luminance Huffman table codes.
Definition mjpegenc.h:53
uint8_t uni_chroma_ac_vlc_len[64 *64 *2]
Storage for AC chrominance VLC.
Definition mjpegenc.h:65
uint8_t uni_ac_vlc_len[64 *64 *2]
Storage for AC luminance VLC.
Definition mjpegenc.h:63
uint8_t bits_ac_chrominance[17]
AC chrominance Huffman bits.
Definition mjpegenc.h:76
uint8_t val_dc_chrominance[12]
DC chrominance Huffman values.
Definition mjpegenc.h:71
Buffer of JPEG frame data.
Definition mjpegenc.c:55