mikroSDK Reference Manual
gl_jpeg_types.h
1/****************************************************************************
2**
3** Copyright (C) 2024 MikroElektronika d.o.o.
4** Contact: https://www.mikroe.com/contact
5**
6** This file is part of the mikroSDK package
7**
8** Commercial License Usage
9**
10** Licensees holding valid commercial NECTO compilers AI licenses may use this
11** file in accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The MikroElektronika Company.
14** For licensing terms and conditions see
15** https://www.mikroe.com/legal/software-license-agreement.
16** For further information use the contact form at
17** https://www.mikroe.com/contact.
18**
19**
20** GNU Lesser General Public License Usage
21**
22** Alternatively, this file may be used for
23** non-commercial projects under the terms of the GNU Lesser
24** General Public License version 3 as published by the Free Software
25** Foundation: https://www.gnu.org/licenses/lgpl-3.0.html.
26**
27** The above copyright notice and this permission notice shall be
28** included in all copies or substantial portions of the Software.
29**
30** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31** OF MERCHANTABILITY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
32** TO THE WARRANTIES FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
33** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
34** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
35** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
36** OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37**
38****************************************************************************/
39
41
42#ifndef JPEG_TYPES_H
43#define JPEG_TYPES_H
44
45#include "gl_jpeg_constants.h"
46#include "gl_types.h"
47
48typedef struct
49{
50 uint8_t jfif; /* JFIF marker found flag */
51 uint8_t major_rev; /* Should be 1 */
52 uint8_t minor_rev; /* Should be 0-2 but is not a show stopper */
53} jpeg_decoder_app0_t;
54
55typedef struct
56{
57 uint8_t data_bits; /* Data precision, can be 8(, 12 or 16) */
58 uint16_t width; /* Width in pixels */
59 uint16_t height; /* Height in pixels */
60 uint8_t channels; /* Number of channels e.g. YCbCr = 3 */
61 uint8_t channel_type[_JPEG_MAX_CHANNELS];
62 uint8_t channel_h_samp_factor[_JPEG_MAX_CHANNELS];
63 uint8_t channel_v_samp_factor[_JPEG_MAX_CHANNELS];
64 uint8_t channel_quant_table_map[_JPEG_MAX_CHANNELS];
65} jpeg_decoder_sof0_t;
66
67typedef struct
68{
69 uint8_t quant_uses_16_bits; /* If flag is set, it is an error as 16 bit is not supported */
70 uint16_t quant_table[_JPEG_MAX_CHANNELS][64]; /* Supports only 8 & 16 bit resolutions */
71} jpeg_decoder_dqt_t;
72
73typedef struct
74{
75 uint16_t restart_interval; /* The restart interval in blocks */
76} jpeg_decoder_dri_t;
77
78typedef struct
79{
80 uint8_t huff_tables;
81 uint8_t huff_ac_symbol_len[_JPEG_MAX_HUFF_TABLES][16]; /* Supports only 8 bit resolution */
82 uint8_t huff_ac_symbol[_JPEG_MAX_HUFF_TABLES][256]; /* Maximum possible symbols are 256 */
83 uint8_t huff_dc_symbol_len[_JPEG_MAX_HUFF_TABLES][16]; /* Supports only 8 bit resolution */
84 uint8_t huff_dc_symbol[_JPEG_MAX_HUFF_TABLES][16]; /* Maximum possible symbols are 16 for DC :-) */
85} jpeg_decoder_dht_t;
86
87typedef struct
88{
89 uint8_t channel_huff_ac_table_map[_JPEG_MAX_CHANNELS];
90 uint8_t channel_huff_dc_table_map[_JPEG_MAX_CHANNELS];
91} jpeg_decoder_sos_t;
92
93typedef struct
94{
95 uint16_t huff_ac_sym_start[_JPEG_MAX_HUFF_TABLES][16]; /* Starting symbol for each length */
96 uint16_t huff_dc_sym_start[_JPEG_MAX_HUFF_TABLES][16]; /* Starting symbol for each length */
97} jpeg_decoder_huff_t;
98
99typedef struct
100{
101 uint16_t work_bits;
102 uint8_t bits_available;
103 uint8_t blocks_in_one_pass;
104 int16_t one_block[_JPEG_MAX_BLOCKS][64]; /* Temporary storage for a 8x8 block */
105 uint16_t block_number;
106 uint8_t channel_map[_JPEG_MAX_BLOCKS];
107 uint8_t sub_sample_type;
108 int16_t prev_dc_value[_JPEG_MAX_CHANNELS];
109 uint8_t *current_huff_symbol_len_table;
110 uint8_t *current_huff_symbol_table;
111 uint16_t *current_huff_symbol_start_table;
112 uint16_t *current_quant_table;
113 uint8_t data_buffer[_JPEG_MAX_DATA_BUF_LEN];
114 uint16_t buffer_len;
115 uint16_t buffer_index;
116 uint8_t first_bit;
117} jpeg_work_memory_t;
118
119typedef struct gl_jpeg_types
120{
121 gl_rectangle_t *dest;
122 gl_rectangle_t *src;
123 uint16_t drawn_x;
124 uint16_t drawn_y;
125 uint16_t image_offset_x;
126 uint16_t image_offset_y;
127} jpeg_drawing_t;
128
129
130typedef struct
131{
132 uint8_t r;
133 uint8_t g;
134 uint8_t b;
135} jpeg_color_t;
136
137typedef struct
138{
139 int16_t *y_ptr;
140 int16_t *cb_ptr;
141 int16_t *cr_ptr;
142} jpeg_color_space_pointers_t;
143
144// ToDo : rename jpeg errors
145typedef enum
146{
147 GL_DRAW_IMAGE_SUCCESS = 0,
148 GL_DRAW_IMAGE_UNSUPPORTED_FORMAT,
149 GL_DRAW_IMAGE_ERROR,
150 GL_DRAW_IMAGE_DEST_ERROR,
151 GL_DRAW_IMAGE_JPEG_ERROR_1,
152 GL_DRAW_IMAGE_JPEG_ERROR_2,
153 GL_DRAW_IMAGE_JPEG_ERROR_3,
154 GL_DRAW_IMAGE_JPEG_ERROR_4,
155 GL_DRAW_IMAGE_JPEG_ERROR_5,
156 GL_DRAW_IMAGE_JPEG_ERROR_6,
157 GL_DRAW_IMAGE_JPEG_ERROR_7,
158 GL_DRAW_IMAGE_JPEG_ERROR_8,
159 GL_DRAW_IMAGE_JPEG_ERROR_9,
160 GL_DRAW_IMAGE_JPEG_ERROR_10,
161 GL_DRAW_IMAGE_JPEG_ERROR_11,
162 GL_DRAW_IMAGE_JPEG_ERROR_12,
163 GL_DRAW_IMAGE_JPEG_ERROR_13,
164 GL_DRAW_IMAGE_JPEG_ERROR_14,
165 GL_DRAW_IMAGE_JPEG_ERROR_15,
166 GL_DRAW_IMAGE_JPEG_ERROR_16
167} gl_draw_image_result_t;
168
169typedef struct
170{
171 const code uint8_t * image_file_as_array;
172 jpeg_decoder_app0_t app0;
173 jpeg_decoder_sof0_t sof0;
174 jpeg_decoder_dqt_t dqt;
175 jpeg_decoder_dri_t dri;
176 jpeg_decoder_dht_t dht;
177 jpeg_decoder_sos_t sos;
178 jpeg_decoder_huff_t huff;
179 jpeg_work_memory_t work_memory;
180 jpeg_drawing_t drawing;
181 gl_draw_image_result_t error;
182} jpeg_decoder_t;
183
184#endif // JPEG_TYPES_H
185
Declaration of types for Graphic Library.
The context structure for storing rectangle by its top left point and width and height (in pixels).
Definition gl_types.h:131