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