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_SYNTAX__ 19 #define __JPEGD_SYNTAX__ 20 21 #include "mpp_frame.h" 22 23 #define JPEGDEC_YUV400 (0) 24 #define JPEGDEC_YUV420 (2) 25 #define JPEGDEC_YUV422 (3) 26 #define JPEGDEC_YUV444 (4) 27 #define JPEGDEC_YUV440 (5) 28 #define JPEGDEC_YUV411 (6) 29 30 #define DCT_SAMPLE_PRECISION_8 (8) 31 32 #define JPEGD_STREAM_BUFF_SIZE (512*1024) 33 #define MAX_COMPONENTS (3) /* for JFIF: YCbCr */ 34 #define DRI_MARKER_LENGTH (4) /* must be 4 bytes */ 35 #define QUANTIZE_TABLE_LENGTH (64) 36 #define MAX_AC_HUFFMAN_TABLE_LENGTH (162) /* for baseline */ 37 #define MAX_DC_HUFFMAN_TABLE_LENGTH (12) /* for baseline */ 38 #define MAX_HUFFMAN_CODE_BIT_LENGTH (16) /* The longest code word is 16 bits */ 39 #define ZERO_PADDING_LENGTH (4) /* 4 Bytes */ 40 #define JPEGD_BASELINE_TABLE_SIZE (QUANTIZE_TABLE_LENGTH * 3 \ 41 + MAX_AC_HUFFMAN_TABLE_LENGTH * 2 \ 42 + MAX_DC_HUFFMAN_TABLE_LENGTH * 2 \ 43 + ZERO_PADDING_LENGTH) /* 544 Bytes */ 44 45 #define JPEGD_DBG_FUNCTION (0x00000001) 46 #define JPEGD_DBG_STARTCODE (0x00000002) 47 #define JPEGD_DBG_TABLE (0x00000004) 48 #define JPEGD_DBG_RESULT (0x00000008) 49 #define JPEGD_DBG_IO (0x00000010) /* input and output write file */ 50 #define JPEGD_DBG_PARSER_INFO (0x00000020) /* parser information */ 51 #define JPEGD_DBG_SYNTAX_ERR (0x00000040) /* syntax error */ 52 #define JPEGD_DBG_HAL_INFO (0x00000080) /* hal information */ 53 #define JPEGD_DBG_HAL_TBL (0x00000100) /* hal information */ 54 55 extern RK_U32 jpegd_debug; 56 57 #define jpegd_dbg(flag, fmt, ...) _mpp_dbg(jpegd_debug, flag, fmt, ## __VA_ARGS__) 58 #define jpegd_dbg_f(flag, fmt, ...) _mpp_dbg_f(jpegd_debug, flag, fmt, ## __VA_ARGS__) 59 60 #define jpegd_dbg_func(fmt, ...) jpegd_dbg_f(JPEGD_DBG_FUNCTION, fmt, ## __VA_ARGS__) 61 #define jpegd_dbg_marker(fmt, ...) jpegd_dbg(JPEGD_DBG_STARTCODE, fmt, ## __VA_ARGS__) 62 #define jpegd_dbg_table(fmt, ...) jpegd_dbg(JPEGD_DBG_TABLE, fmt, ## __VA_ARGS__) 63 #define jpegd_dbg_result(fmt, ...) jpegd_dbg(JPEGD_DBG_RESULT, fmt, ## __VA_ARGS__) 64 #define jpegd_dbg_io(fmt, ...) jpegd_dbg(JPEGD_DBG_IO, fmt, ## __VA_ARGS__) 65 #define jpegd_dbg_parser(fmt, ...) jpegd_dbg(JPEGD_DBG_PARSER_INFO, fmt, ## __VA_ARGS__) 66 #define jpegd_dbg_syntax(fmt, ...) jpegd_dbg(JPEGD_DBG_SYNTAX_ERR, fmt, ## __VA_ARGS__) 67 #define jpegd_dbg_hal(fmt, ...) jpegd_dbg(JPEGD_DBG_HAL_INFO, fmt, ## __VA_ARGS__) 68 69 70 enum huffman_table_type { 71 HUFFMAN_TABLE_TYPE_DC = 0, 72 HUFFMAN_TABLE_TYPE_AC = 1, 73 HUFFMAN_TABLE_TYPE_BUTT = 2, 74 }; 75 76 enum huffman_table_id { 77 HUFFMAN_TABLE_ID_ZERO = 0, 78 HUFFMAN_TABLE_ID_ONE = 1, 79 HUFFMAN_TABLE_ID_TWO = 2, 80 HUFFMAN_TABLE_ID_THREE = 3, 81 HUFFMAN_TABLE_ID_BUTT = 4, 82 }; 83 84 enum quantize_table_id { 85 QUANTIZE_TABLE_ID_ZERO = 0, 86 QUANTIZE_TABLE_ID_ONE = 1, 87 QUANTIZE_TABLE_ID_TWO = 2, 88 QUANTIZE_TABLE_ID_THREE = 3, 89 QUANTIZE_TABLE_ID_BUTT = 4, 90 }; 91 92 /* Alternating Current Table */ 93 typedef struct { 94 RK_U32 bits[MAX_HUFFMAN_CODE_BIT_LENGTH]; 95 RK_U32 vals[MAX_AC_HUFFMAN_TABLE_LENGTH]; 96 RK_U32 actual_length; /* calculate based on actual stream */ 97 } AcTable; 98 99 /* Direct Current Table */ 100 typedef struct { 101 RK_U32 bits[MAX_HUFFMAN_CODE_BIT_LENGTH]; 102 RK_U32 vals[MAX_DC_HUFFMAN_TABLE_LENGTH]; 103 RK_U32 actual_length; /* calculate based on actual stream */ 104 } DcTable; 105 106 typedef struct JpegdSyntax { 107 /* just 16 bits because quantization parameters are much less than 2^16 */ 108 RK_U16 quant_matrixes[4][QUANTIZE_TABLE_LENGTH]; 109 110 /* only two ac table for baseline */ 111 AcTable ac_table[2]; 112 113 /* only two dc table for baseline */ 114 DcTable dc_table[2]; 115 116 /* quantizer scale calculated from quant_matrixes */ 117 RK_U32 qscale[4]; 118 119 /* output format */ 120 MppFrameFormat output_fmt; 121 122 /* especially for jpeg */ 123 RK_U32 yuv_mode; 124 RK_U8 fill_bottom; 125 RK_U8 fill_right; 126 127 /* syntax in SOS */ 128 RK_U8 scan_start; 129 RK_U8 scan_end; 130 RK_U8 prev_shift; /* Ah */ 131 RK_U8 point_transform; /* Al */ 132 133 /* 0 - not found; 1 - found */ 134 RK_U8 dht_found; 135 RK_U8 eoi_found; 136 RK_U8 sof0_found; 137 138 /* amount of quantize tables: 1 or 3 */ 139 RK_U8 qtable_cnt; 140 141 /* length of sos segment */ 142 RK_U32 sos_len; 143 144 /* decoded bytes by software */ 145 RK_U32 strm_offset; 146 147 /* hardware decode start address */ 148 RK_U8 *cur_pos; 149 150 /* length of a jpeg packet */ 151 RK_U32 pkt_len; 152 153 /* Horizontal pixel density */ 154 RK_U16 hor_density; 155 156 /* Vertical pixel density */ 157 RK_U16 ver_density; 158 159 RK_U32 width, height; 160 RK_U32 hor_stride, ver_stride; 161 162 /* Number of components in frame */ 163 RK_U32 nb_components; 164 165 /* Component id */ 166 RK_U32 component_id[MAX_COMPONENTS]; 167 168 /* Horizontal sampling factor */ 169 RK_U32 h_count[MAX_COMPONENTS]; 170 171 /* Vertical sampling factor */ 172 RK_U32 v_count[MAX_COMPONENTS]; 173 174 /* Huffman Table ID used by DC */ 175 RK_U32 dc_index[MAX_COMPONENTS]; 176 177 /* Huffman Table ID used by AC */ 178 RK_U32 ac_index[MAX_COMPONENTS]; 179 180 /* maximum h and v counts */ 181 RK_U32 h_max, v_max; 182 183 /* quant table index for each component */ 184 RK_U32 quant_index[MAX_COMPONENTS]; 185 186 RK_U32 restart_interval; 187 188 RK_U8 sample_precision; 189 RK_U8 qtbl_entry; 190 RK_U8 htbl_entry; 191 } JpegdSyntax; 192 193 #endif /*__JPEGD_SYNTAX__*/ 194