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