1 |
|
|
/*************************************************************************** |
2 |
|
|
* Copyright (c) 2024 Microsoft Corporation |
3 |
|
|
* |
4 |
|
|
* This program and the accompanying materials are made available under the |
5 |
|
|
* terms of the MIT License which is available at |
6 |
|
|
* https://opensource.org/licenses/MIT. |
7 |
|
|
* |
8 |
|
|
* SPDX-License-Identifier: MIT |
9 |
|
|
**************************************************************************/ |
10 |
|
|
|
11 |
|
|
|
12 |
|
|
/**************************************************************************/ |
13 |
|
|
/**************************************************************************/ |
14 |
|
|
/** */ |
15 |
|
|
/** GUIX Component */ |
16 |
|
|
/** */ |
17 |
|
|
/** Image Reader Management (Image Reader) */ |
18 |
|
|
/** */ |
19 |
|
|
/**************************************************************************/ |
20 |
|
|
|
21 |
|
|
#define GX_SOURCE_CODE |
22 |
|
|
|
23 |
|
|
|
24 |
|
|
/* Include necessary system files. */ |
25 |
|
|
|
26 |
|
|
#include "gx_api.h" |
27 |
|
|
#include "gx_image_reader.h" |
28 |
|
|
#include "gx_utility.h" |
29 |
|
|
|
30 |
|
|
/**************************************************************************/ |
31 |
|
|
/* */ |
32 |
|
|
/* FUNCTION RELEASE */ |
33 |
|
|
/* */ |
34 |
|
|
/* _gx_image_reader_gx_image_type_get PORTABLE C */ |
35 |
|
|
/* 6.1 */ |
36 |
|
|
/* AUTHOR */ |
37 |
|
|
/* */ |
38 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
39 |
|
|
/* */ |
40 |
|
|
/* DESCRIPTION */ |
41 |
|
|
/* */ |
42 |
|
|
/* This function retrieves the image type and stores the image type */ |
43 |
|
|
/* in the GX_IMAGE_READER control block. */ |
44 |
|
|
/* */ |
45 |
|
|
/* INPUT */ |
46 |
|
|
/* */ |
47 |
|
|
/* image_reader Image reader control block. */ |
48 |
|
|
/* */ |
49 |
|
|
/* OUTPUT */ |
50 |
|
|
/* */ |
51 |
|
|
/* Completion Status */ |
52 |
|
|
/* */ |
53 |
|
|
/* CALLS */ |
54 |
|
|
/* */ |
55 |
|
|
/* None */ |
56 |
|
|
/* */ |
57 |
|
|
/* CALLED BY */ |
58 |
|
|
/* */ |
59 |
|
|
/* GUIX Internal Code */ |
60 |
|
|
/* */ |
61 |
|
|
/* RELEASE HISTORY */ |
62 |
|
|
/* */ |
63 |
|
|
/* DATE NAME DESCRIPTION */ |
64 |
|
|
/* */ |
65 |
|
|
/* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */ |
66 |
|
|
/* 09-30-2020 Kenneth Maxwell Modified comment(s), */ |
67 |
|
|
/* resulting in version 6.1 */ |
68 |
|
|
/* */ |
69 |
|
|
/**************************************************************************/ |
70 |
|
|
#if defined(GX_SOFTWARE_DECODER_SUPPORT) |
71 |
|
826 |
static UINT _gx_image_reader_image_type_get(GX_IMAGE_READER *image_reader) |
72 |
|
|
{ |
73 |
|
826 |
GX_UBYTE image_type = 0; |
74 |
|
|
GX_CONST GX_UBYTE *buffer; |
75 |
|
|
|
76 |
|
826 |
buffer = image_reader -> gx_image_reader_source_data; |
77 |
|
|
|
78 |
✓✓ |
826 |
if (buffer) |
79 |
|
|
{ |
80 |
✓✓ |
825 |
if (buffer[1] == 'P') |
81 |
|
|
{ |
82 |
|
604 |
image_type = GX_IMAGE_TYPE_PNG; |
83 |
|
|
} |
84 |
|
|
else |
85 |
|
|
{ |
86 |
✓✓ |
221 |
if (buffer[6] == 'J') |
87 |
|
|
{ |
88 |
|
210 |
image_type = GX_IMAGE_TYPE_JPG; |
89 |
|
|
} |
90 |
|
|
else |
91 |
|
|
{ |
92 |
✓✓✓✓ ✓✓ |
11 |
if (buffer[1] == 0xd8 && buffer[0] == 0xff && (buffer[2] == 0xff)) |
93 |
|
|
{ |
94 |
|
8 |
image_type = GX_IMAGE_TYPE_JPG; |
95 |
|
|
} |
96 |
|
|
} |
97 |
|
|
} |
98 |
|
|
} |
99 |
|
|
|
100 |
|
826 |
image_reader -> gx_image_reader_image_type = image_type; |
101 |
|
826 |
return GX_SUCCESS; |
102 |
|
|
} |
103 |
|
|
#endif |
104 |
|
|
|
105 |
|
|
/**************************************************************************/ |
106 |
|
|
/* */ |
107 |
|
|
/* FUNCTION RELEASE */ |
108 |
|
|
/* */ |
109 |
|
|
/* _gx_image_reader_image_decode PORTABLE C */ |
110 |
|
|
/* 6.3.0 */ |
111 |
|
|
/* AUTHOR */ |
112 |
|
|
/* */ |
113 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
114 |
|
|
/* */ |
115 |
|
|
/* DESCRIPTION */ |
116 |
|
|
/* */ |
117 |
|
|
/* This function decodes input image to raw pixelmap format. */ |
118 |
|
|
/* */ |
119 |
|
|
/* INPUT */ |
120 |
|
|
/* */ |
121 |
|
|
/* image_reader Image reader control block */ |
122 |
|
|
/* outmap Output pixelmap */ |
123 |
|
|
/* */ |
124 |
|
|
/* OUTPUT */ |
125 |
|
|
/* */ |
126 |
|
|
/* None */ |
127 |
|
|
/* */ |
128 |
|
|
/* CALLS */ |
129 |
|
|
/* */ |
130 |
|
|
/* _gx_image_reader_image_type_get */ |
131 |
|
|
/* _gx_utility_jpeg_decode */ |
132 |
|
|
/* _gx_utility_png_decode */ |
133 |
|
|
/* */ |
134 |
|
|
/* CALLED BY */ |
135 |
|
|
/* */ |
136 |
|
|
/* _gx_image_reader_colorspace_convert */ |
137 |
|
|
/* */ |
138 |
|
|
/* RELEASE HISTORY */ |
139 |
|
|
/* */ |
140 |
|
|
/* DATE NAME DESCRIPTION */ |
141 |
|
|
/* */ |
142 |
|
|
/* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */ |
143 |
|
|
/* 09-30-2020 Kenneth Maxwell Modified comment(s), */ |
144 |
|
|
/* resulting in version 6.1 */ |
145 |
|
|
/* 10-31-2023 Ting Zhu Modified comment(s), */ |
146 |
|
|
/* modified jpeg decode */ |
147 |
|
|
/* function parameter list, */ |
148 |
|
|
/* resulting in version 6.3.0 */ |
149 |
|
|
/* */ |
150 |
|
|
/**************************************************************************/ |
151 |
|
|
#if defined(GX_SOFTWARE_DECODER_SUPPORT) |
152 |
|
826 |
UINT _gx_image_reader_image_decode(GX_IMAGE_READER *image_reader, GX_PIXELMAP *outmap) |
153 |
|
|
{ |
154 |
|
|
UINT status; |
155 |
|
|
|
156 |
|
|
/* Get image type. */ |
157 |
|
826 |
_gx_image_reader_image_type_get(image_reader); |
158 |
|
|
|
159 |
✓✓✓ |
826 |
switch (image_reader -> gx_image_reader_image_type) |
160 |
|
|
{ |
161 |
|
218 |
case GX_IMAGE_TYPE_JPG: |
162 |
|
218 |
status = _gx_image_reader_jpeg_decode(image_reader, outmap); |
163 |
|
218 |
break; |
164 |
|
|
|
165 |
|
604 |
case GX_IMAGE_TYPE_PNG: |
166 |
|
604 |
status = _gx_image_reader_png_decode(image_reader -> gx_image_reader_source_data, image_reader -> gx_image_reader_source_data_size, outmap); |
167 |
✓✓ |
604 |
if (outmap -> gx_pixelmap_transparent_color) |
168 |
|
|
{ |
169 |
|
49 |
image_reader -> gx_image_reader_png_trans = (GX_COLOR *)outmap -> gx_pixelmap_transparent_color; |
170 |
|
|
} |
171 |
|
604 |
break; |
172 |
|
|
|
173 |
|
4 |
default: |
174 |
|
4 |
return GX_NOT_SUPPORTED; |
175 |
|
|
} |
176 |
|
|
|
177 |
✓✓ |
822 |
if (!(outmap -> gx_pixelmap_flags & GX_PIXELMAP_ALPHA)) |
178 |
|
|
{ |
179 |
|
449 |
image_reader -> gx_image_reader_mode = (GX_UBYTE)(image_reader -> gx_image_reader_mode & (ULONG)(~GX_IMAGE_READER_MODE_ALPHA)); |
180 |
|
|
} |
181 |
|
|
|
182 |
|
822 |
return status; |
183 |
|
|
} |
184 |
|
|
#endif |
185 |
|
|
|