xref: /rockchip-linux_mpp/mpp/codec/dec/jpeg/jpegd_parser.h (revision 437bfbeb9567cca9cd9080e3f6954aa9d6a94f18)
1 /*
2  *
3  * Copyright 2015 Rockchip Electronics Co. LTD
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef __JPEGD_PARSER_H__
19 #define __JPEGD_PARSER_H__
20 
21 #include <limits.h>
22 #include <string.h>
23 
24 #include "mpp_bitread.h"
25 
26 #include "jpegd_syntax.h"
27 
28 #define JPEG_IDENTIFIER(a, b, c, d) \
29        ((RK_U32)(d) | ((RK_U32)(c) << 8) | \
30          ((RK_U32)(b) << 16) | ((RK_U32)(a) << 24))
31 
32 
33 /* JPEG marker codes */
34 enum JpegMarker {
35     /* start of frame */
36     SOF0  = 0xc0,       /* baseline */
37     SOF1  = 0xc1,       /* extended sequential, huffman */
38     SOF2  = 0xc2,       /* progressive, huffman */
39     SOF3  = 0xc3,       /* lossless, huffman */
40 
41     SOF5  = 0xc5,       /* differential sequential, huffman */
42     SOF6  = 0xc6,       /* differential progressive, huffman */
43     SOF7  = 0xc7,       /* differential lossless, huffman */
44     JPG   = 0xc8,       /* reserved for JPEG extension */
45     SOF9  = 0xc9,       /* extended sequential, arithmetic */
46     SOF10 = 0xca,       /* progressive, arithmetic */
47     SOF11 = 0xcb,       /* lossless, arithmetic */
48 
49     SOF13 = 0xcd,       /* differential sequential, arithmetic */
50     SOF14 = 0xce,       /* differential progressive, arithmetic */
51     SOF15 = 0xcf,       /* differential lossless, arithmetic */
52 
53     DHT   = 0xc4,       /* define huffman tables */
54 
55     DAC   = 0xcc,       /* define arithmetic-coding conditioning */
56 
57     /* restart with modulo 8 count "m" */
58     RST0  = 0xd0,
59     RST1  = 0xd1,
60     RST2  = 0xd2,
61     RST3  = 0xd3,
62     RST4  = 0xd4,
63     RST5  = 0xd5,
64     RST6  = 0xd6,
65     RST7  = 0xd7,
66 
67     SOI   = 0xd8,       /* start of image */
68     EOI   = 0xd9,       /* end of image */
69     SOS   = 0xda,       /* start of scan */
70     DQT   = 0xdb,       /* define quantization tables */
71     DNL   = 0xdc,       /* define number of lines */
72     DRI   = 0xdd,       /* define restart interval */
73     DHP   = 0xde,       /* define hierarchical progression */
74     EXP   = 0xdf,       /* expand reference components */
75 
76     APP0  = 0xe0,
77     APP1  = 0xe1,
78     APP2  = 0xe2,
79     APP3  = 0xe3,
80     APP4  = 0xe4,
81     APP5  = 0xe5,
82     APP6  = 0xe6,
83     APP7  = 0xe7,
84     APP8  = 0xe8,
85     APP9  = 0xe9,
86     APP10 = 0xea,
87     APP11 = 0xeb,
88     APP12 = 0xec,
89     APP13 = 0xed,
90     APP14 = 0xee,
91     APP15 = 0xef,
92 
93     JPG0  = 0xf0,
94     JPG1  = 0xf1,
95     JPG2  = 0xf2,
96     JPG3  = 0xf3,
97     JPG4  = 0xf4,
98     JPG5  = 0xf5,
99     JPG6  = 0xf6,
100     SOF48 = 0xf7,       ///< JPEG-LS
101     LSE   = 0xf8,       ///< JPEG-LS extension parameters
102     JPG9  = 0xf9,
103     JPG10 = 0xfa,
104     JPG11 = 0xfb,
105     JPG12 = 0xfc,
106     JPG13 = 0xfd,
107 
108     COM   = 0xfe,       /* comment */
109 
110     TEM   = 0x01,       /* temporary private use for arithmetic coding */
111 
112     /* 0x02 -> 0xbf reserved */
113 };
114 
115 typedef struct JpegdCtx {
116     MppBufSlots              packet_slots;
117     MppBufSlots              frame_slots;
118 
119     /* slot index for output */
120     RK_S32                   frame_slot_index;
121     RK_U8                    *recv_buffer;
122 
123     /* input stream length or buffer size */
124     RK_U32                   streamLength;
125 
126     /* input stream buffer size */
127     RK_U32                   bufferSize;
128 
129     MppPacket                input_packet;
130     MppFrame                 output_frame;
131 
132     RK_S64                   pts;
133     RK_U32                   eos;
134     RK_U32                   input_jpeg_count;
135 
136     /* 0 - no need to copy stream; 1 - need to copy */
137     RK_S32                   copy_flag;
138     /* 0 - just scan parts of markers; 1 - scan all markers */
139     RK_S32                   scan_all_marker;
140 
141     RK_U8                    *buffer;
142 
143     /* current start code */
144     RK_S32                   start_code;
145 
146     /* bit read context */
147     BitReadCtx_t             *bit_ctx;
148     JpegdSyntax              *syntax;
149 } JpegdCtx;
150 
151 #endif /* __JPEGD_PARSER_H__ */
152