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