2D Image Processing Library for Cortex-M Processors
All Data Structures Functions Variables Typedefs Enumerations Enumerator Modules Pages
arm_2d_types.h
1/*
2 * Copyright (C) 2022 Arm Limited or its affiliates. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Licensed under the Apache License, Version 2.0 (the License); you may
7 * not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19/* ----------------------------------------------------------------------
20 * Project: Arm-2D Library
21 * Title: arm_2d_types.h
22 * Description: Public header file to contain the Arm-2D structs
23 *
24 * $Date: 4. Nov 2023
25 * $Revision: V.1.1.3
26 *
27 * Target Processor: Cortex-M cores
28 * -------------------------------------------------------------------- */
29
30
31#ifndef __ARM_2D_TYPES_H__
32#define __ARM_2D_TYPES_H__
33
34/*============================ INCLUDES ======================================*/
35#include <string.h>
36#include <stdint.h>
37#include <stdbool.h>
38#include <assert.h>
39
40#include "arm_2d_features.h"
41#include "arm_2d_utils.h"
42#include "__arm_2d_math.h"
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
48#if defined(__clang__)
49# pragma clang diagnostic push
50# pragma clang diagnostic ignored "-Wunknown-warning-option"
51# pragma clang diagnostic ignored "-Wreserved-identifier"
52# pragma clang diagnostic ignored "-Wmissing-declarations"
53# pragma clang diagnostic ignored "-Wpadded"
54# pragma clang diagnostic ignored "-Wc11-extensions"
55# pragma clang diagnostic ignored "-Wembedded-directive"
56#elif __IS_COMPILER_ARM_COMPILER_5__
57# pragma diag_suppress 64
58#elif __IS_COMPILER_GCC__
59# pragma GCC diagnostic push
60# pragma GCC diagnostic ignored "-Wmissing-declarations"
61# pragma GCC diagnostic ignored "-Wpadded"
62#endif
63
64/*!
65 * \addtogroup gKernel 1 Kernel
66 * @{
67 */
68
69/*============================ MACROS ========================================*/
70
71/* A patch for GCC support */
72#if defined(__IS_COMPILER_GCC__) && __IS_COMPILER_GCC__ && __ARM_2D_HAS_HELIUM__
73
74# ifndef __ARM_2D_SUPPRESS_GCC_HELIUM_PATCH_WARNING__
75# pragma GCC warning "As GCC has compilation issues for supporting Helium,\
76 the scalar version is used. You can define a macro\
77 __ARM_2D_SUPPRESS_GCC_HELIUM_PATCH_WARNING__ to suppress this warning."
78# endif
79
80# undef __ARM_2D_HAS_HELIUM__
81# undef __ARM_2D_HAS_HELIUM_INTEGER__
82# undef __ARM_2D_HAS_HELIUM_FLOAT__
83
84# define __ARM_2D_HAS_HELIUM__ 0 //!< target MCU has no Helium extension
85# define __ARM_2D_HAS_HELIUM_INTEGER__ 0 //!< target MCU has no Helium integer extension
86# define __ARM_2D_HAS_HELIUM_FLOAT__ 0 //!< target MCU has no Helium floating point extension
87#endif
88
89/*============================ MACROFIED FUNCTIONS ===========================*/
90/*============================ TYPES =========================================*/
91
92
93/*----------------------------------------------------------------------------*
94 * Infrastructure *
95 *----------------------------------------------------------------------------*/
96
97/*!
98 * \brief finite-state-machine status return (Compatible with arm_status, minimal integer: int8_t)
99 *
100 */
101typedef enum {
102 arm_fsm_rt_err = -1, //!< fsm error
103 arm_fsm_rt_cpl = 0, //!< fsm complete
104 arm_fsm_rt_on_going = 1, //!< fsm on-going
105 arm_fsm_rt_wait_for_obj = 2, //!< fsm wait for IPC object
106 arm_fsm_rt_async = 3, //!< fsm work asynchronously, please check it later.
107 arm_fsm_rt_wait_for_res = 4, //!< wait for resource
109
110/*!
111 * \brief the error code for arm-2d (minimal integer: int8_t)
112 *
113 */
114typedef enum {
115 ARM_2D_ERR_NOT_AVAILABLE = -12, //!< service is not available or not initialissed
116 ARM_2D_ERR_UNSUPPORTED_COLOUR = -11, //!< the specified colour is not supported
117 ARM_2D_ERR_BUSY = -10, //!< service is busy
118 ARM_2D_ERR_INSUFFICIENT_RESOURCE = -9, //!< insufficient resource
119 ARM_2D_ERR_IO_BUSY = -8, //!< HW accelerator is busy
120 ARM_2D_ERR_IO_ERROR = -7, //!< Generic HW error
121 ARM_2D_ERR_MISSING_PARAM = -6, //!< missing mandatory parameter
122 ARM_2D_ERR_INVALID_OP = -5, //!< unsupported / invalid operation
123 ARM_2D_ERR_NOT_SUPPORT = -4, //!< feature/service/operation is not supported
124 ARM_2D_ERR_OUT_OF_REGION = -3, //!< the operation is out of target area
125 ARM_2D_ERR_INVALID_PARAM = -2, //!< invalid parameter
126 ARM_2D_ERR_UNKNOWN = -1, //!< generic or unknown errors
127 ARM_2D_ERR_NONE = 0, //!< no error
129
130/*!
131 * \brief comparison result
132 *
133 */
134typedef enum {
135 ARM_2D_CMP_SMALLER = -1, //!< the target is smaller than the reference
136 ARM_2D_CMP_EQUALS = 0, //!< the target is equal to the reference
137 ARM_2D_CMP_LARGER = 1, //!< the target is larger than the reference
139
140/*----------------------------------------------------------------------------*
141 * Colour definitions *
142 *----------------------------------------------------------------------------*/
143
144/*!
145 * \brief the colour type for gray8 (8bit gray scale)
146 *
147 */
148typedef union arm_2d_color_gray8_t {
149 uint8_t tValue;
151
152/*!
153 * \brief the colour type for rgb565
154 *
155 */
157 uint16_t tValue;
158 struct {
159 uint16_t u5B : 5;
160 uint16_t u6G : 6;
161 uint16_t u5R : 5;
162 };
164
165/*!
166 * \brief the colour type for brga8888
167 *
168 * \details In most cases four equal-sized pieces of adjacent memory are used,
169 * one for each channel, and a 0 in a channel indicates black color or
170 * transparent alpha, while all-1 bits indicates white or fully opaque
171 * alpha. By far the most common format is to store 8 bits (one byte)
172 * for each channel, which is 32 bits for each pixel.
173 *
174 * (source: https://en.wikipedia.org/wiki/RGBA_color_model#ARGB32)
175 */
177 uint32_t tValue;
178 struct {
179 uint32_t u8B : 8;
180 uint32_t u8G : 8;
181 uint32_t u8R : 8;
182 uint32_t u8A : 8;
183 };
185
186/*!
187 * \brief the colour type for rgb888 (compliant with ccca888 and bgra8888)
188 *
189 * \details In most cases four equal-sized pieces of adjacent memory are used,
190 * one for each channel, and a 0 in a channel indicates black color or
191 * transparent alpha, while all-1 bits indicates white or fully opaque
192 * alpha. By far the most common format is to store 8 bits (one byte)
193 * for each channel, which is 32 bits for each pixel.
194 *
195 * (source: https://en.wikipedia.org/wiki/RGBA_color_model#ARGB32)
196 */
198 uint32_t tValue;
199 struct {
200 uint32_t u8B : 8;
201 uint32_t u8G : 8;
202 uint32_t u8R : 8;
203 uint32_t : 8;
204 };
206
207/*!
208 * \brief the colour type for any 32bit colour formats which has an alpha channel on its 3rd byte.
209 *
210 * \details In most cases four equal-sized pieces of adjacent memory are used,
211 * one for each channel, and a 0 in a channel indicates black color or
212 * transparent alpha, while all-1 bits indicates white or fully opaque
213 * alpha. By far the most common format is to store 8 bits (one byte)
214 * for each channel, which is 32 bits for each pixel.
215 *
216 * (source: https://en.wikipedia.org/wiki/RGBA_color_model#ARGB32)
217 */
219 uint32_t tValue;
220 struct {
221 uint8_t u8C[3];
222 uint8_t u8A;
223 };
225
226/*!
227 * \brief the colour type for any 32bit colour formats which has an alpha channel on its first byte.
228 *
229 * \details In most cases four equal-sized pieces of adjacent memory are used,
230 * one for each channel, and a 0 in a channel indicates black color or
231 * transparent alpha, while all-1 bits indicates white or fully opaque
232 * alpha. By far the most common format is to store 8 bits (one byte)
233 * for each channel, which is 32 bits for each pixel.
234 *
235 * (source: https://en.wikipedia.org/wiki/RGBA_color_model#ARGB32)
236 */
238 uint32_t tValue;
239 struct {
240 uint8_t u8A;
241 uint8_t u8C[3];
242 };
244
245/*!
246 * \brief the colour type for any 32bit colour formats which has an unused-alpha channel on its 3rd byte.
247 *
248 * \details In most cases four equal-sized pieces of adjacent memory are used,
249 * one for each channel, and a 0 in a channel indicates black color or
250 * transparent alpha, while all-1 bits indicates white or fully opaque
251 * alpha. By far the most common format is to store 8 bits (one byte)
252 * for each channel, which is 32 bits for each pixel.
253 *
254 * (source: https://en.wikipedia.org/wiki/RGBA_color_model#ARGB32)
255 */
257 uint32_t tValue;
258 struct {
259 uint8_t u8C[3];
260 uint8_t : 8;
261 };
263
264/*!
265 * \brief the colour type for any 32bit colour formats which has an unused-alpha channel on its first byte.
266 *
267 * \details In most cases four equal-sized pieces of adjacent memory are used,
268 * one for each channel, and a 0 in a channel indicates black color or
269 * transparent alpha, while all-1 bits indicates white or fully opaque
270 * alpha. By far the most common format is to store 8 bits (one byte)
271 * for each channel, which is 32 bits for each pixel.
272 *
273 * (source: https://en.wikipedia.org/wiki/RGBA_color_model#ARGB32)
274 */
276 uint32_t tValue;
277 struct {
278 uint8_t : 8;
279 uint8_t u8C[3];
280 };
282
283/*!
284 * \brief enumerations for colour attributes
285 */
286enum {
287 ARM_2D_COLOUR_SZ_1BIT = 0, //!< 1 bit:black and white
288 ARM_2D_COLOUR_SZ_2BIT = 1, //!< 4 colours or 4 gray-levels
289 ARM_2D_COLOUR_SZ_4BIT = 2, //!< 16 colours or 16 gray-levels
290 ARM_2D_COLOUR_SZ_8BIT = 3, //!< 256 colours
291 ARM_2D_COLOUR_SZ_16BIT = 4, //!< 16bits
292 ARM_2D_COLOUR_SZ_32BIT = 5, //!< true colour
293
294 ARM_2D_COLOUR_SZ_1BIT_msk = ARM_2D_COLOUR_SZ_1BIT << 1,
295 ARM_2D_COLOUR_SZ_2BIT_msk = ARM_2D_COLOUR_SZ_2BIT << 1,
296 ARM_2D_COLOUR_SZ_4BIT_msk = ARM_2D_COLOUR_SZ_4BIT << 1,
297 ARM_2D_COLOUR_SZ_8BIT_msk = ARM_2D_COLOUR_SZ_8BIT << 1,
298 ARM_2D_COLOUR_SZ_16BIT_msk = ARM_2D_COLOUR_SZ_16BIT<< 1,
299 ARM_2D_COLOUR_SZ_32BIT_msk = ARM_2D_COLOUR_SZ_32BIT<< 1,
300 ARM_2D_COLOUR_SZ_msk = (0x07 << 1),
301
302 ARM_2D_COLOUR_LITTLE_ENDIAN = 0,
303 ARM_2D_COLOUR_BIG_ENDIAN = 1,
304
305 ARM_2D_COLOUR_LITTLE_ENDIAN_msk = ARM_2D_COLOUR_LITTLE_ENDIAN << 4,
306 ARM_2D_COLOUR_BIG_ENDIAN_msk = ARM_2D_COLOUR_BIG_ENDIAN << 4,
307
308 ARM_2D_COLOUR_NO_ALPHA = 0,
309 ARM_2D_COLOUR_HAS_ALPHA = 1,
310
311 ARM_2D_COLOUR_NO_ALPHA_msk = ARM_2D_COLOUR_NO_ALPHA << 0,
312 ARM_2D_COLOUR_HAS_ALPHA_msk = ARM_2D_COLOUR_HAS_ALPHA << 0,
313
314 ARM_2D_COLOUR_VARIANT_pos = 5,
315 ARM_2D_COLOUR_VARIANT_msk = 0x07 << ARM_2D_COLOUR_VARIANT_pos,
316};
317
318/* macros for colour attributes */
319#define ARM_2D_M_COLOUR_SZ_1BIT 0 //!< 1 bit:black and white
320#define ARM_2D_M_COLOUR_SZ_2BIT 1 //!< 4 colours or 4 gray-levels
321#define ARM_2D_M_COLOUR_SZ_4BIT 2 //!< 16 colours or 16 gray-levels
322#define ARM_2D_M_COLOUR_SZ_8BIT 3 //!< 256 colours
323#define ARM_2D_M_COLOUR_SZ_16BIT 4 //!< 16bits
324#define ARM_2D_M_COLOUR_SZ_32BIT 5 //!< true colour
325
326#define ARM_2D_M_COLOUR_SZ_1BIT_msk (ARM_2D_M_COLOUR_SZ_1BIT << 1) //!< bitmask for 1bit colour formats
327#define ARM_2D_M_COLOUR_SZ_2BIT_msk (ARM_2D_M_COLOUR_SZ_2BIT << 1) //!< bitmask for 2bit colour formats
328#define ARM_2D_M_COLOUR_SZ_4BIT_msk (ARM_2D_M_COLOUR_SZ_4BIT << 1) //!< bitmask for 4bit colour formats
329#define ARM_2D_M_COLOUR_SZ_8BIT_msk (ARM_2D_M_COLOUR_SZ_8BIT << 1) //!< bitmask for 8bit colour formats
330#define ARM_2D_M_COLOUR_SZ_16BIT_msk (ARM_2D_M_COLOUR_SZ_16BIT<< 1) //!< bitmask for 16bit colour formats
331#define ARM_2D_M_COLOUR_SZ_32BIT_msk (ARM_2D_M_COLOUR_SZ_32BIT<< 1) //!< bitmask for 32bit colour formats
332#define ARM_2D_M_COLOUR_SZ_msk (0x07 << 1), //!< bitmask for the SZ bitfield
333
334#define ARM_2D_M_COLOUR_LITTLE_ENDIAN 0 //!< pixels are stored in little endian
335#define ARM_2D_M_COLOUR_BIG_ENDIAN 1 //!< pixels are stored big endian
336
337#define ARM_2D_M_COLOUR_LITTLE_ENDIAN_msk (ARM_2D_M_COLOUR_LITTLE_ENDIAN << 4)//!< bitmask for little-endian
338#define ARM_2D_M_COLOUR_BIG_ENDIAN_msk (ARM_2D_M_COLOUR_BIG_ENDIAN << 4)//!< bitmask for big-endian
339
340#define ARM_2D_M_COLOUR_NO_ALPHA 0 //!< there is no alpha channel in each pixel
341#define ARM_2D_M_COLOUR_HAS_ALPHA 1 //!< there is an alpha channel in each pixel
342
343#define ARM_2D_M_COLOUR_NO_ALPHA_msk (ARM_2D_M_COLOUR_NO_ALPHA << 0) //!< bitmask for no-alpha-channel-in-pixel
344#define ARM_2D_M_COLOUR_HAS_ALPHA_msk (ARM_2D_M_COLOUR_HAS_ALPHA << 0) //!< bitmask for has-alpha-channel-in-pixel
345
346#define ARM_2D_M_COLOUR_VARIANT_pos 5 //!< offset for the VARIANT bitfield
347#define ARM_2D_M_COLOUR_VARIANT_msk (0x07<<ARM_2D_M_COLOUR_VARIANT_pos) //!< bitmask for the VARIANT bitfield
348
349/*!
350 * \brief enumerations for colour types
351 *
352 */
353enum {
354 ARM_2D_COLOUR_MONOCHROME = ARM_2D_COLOUR_SZ_1BIT_msk,
355 ARM_2D_COLOUR_BIN = ARM_2D_COLOUR_SZ_1BIT_msk,
356 ARM_2D_COLOUR_1BIT = ARM_2D_COLOUR_SZ_1BIT_msk,
357
358 ARM_2D_COLOUR_MASK_A2 = ARM_2D_M_COLOUR_SZ_2BIT_msk,
359 ARM_2D_COLOUR_MASK_A4 = ARM_2D_M_COLOUR_SZ_4BIT_msk,
360
361 ARM_2D_COLOUR_2BIT = ARM_2D_M_COLOUR_SZ_2BIT_msk,
362 ARM_2D_COLOUR_4BIT = ARM_2D_M_COLOUR_SZ_4BIT_msk,
363
364 ARM_2D_COLOUR_8BIT = ARM_2D_COLOUR_SZ_8BIT_msk,
365 ARM_2D_COLOUR_GRAY8 = ARM_2D_COLOUR_SZ_8BIT_msk,
366 ARM_2D_COLOUR_MASK_A8 = ARM_2D_COLOUR_SZ_8BIT_msk,
367
368 ARM_2D_COLOUR_16BIT = ARM_2D_COLOUR_SZ_16BIT_msk,
369 ARM_2D_COLOUR_RGB16 = ARM_2D_COLOUR_SZ_16BIT_msk,
370 ARM_2D_COLOUR_RGB565 = ARM_2D_COLOUR_RGB16,
371
372/* won't support
373 ARM_2D_COLOUR_RGB565_BE = ARM_2D_COLOUR_SZ_16BIT_msk |
374 ARM_2D_COLOUR_BIG_ENDIAN_msk ,
375 */
376
377 ARM_2D_COLOUR_32BIT = ARM_2D_COLOUR_SZ_32BIT_msk ,
378 ARM_2D_COLOUR_RGB32 = ARM_2D_COLOUR_SZ_32BIT_msk ,
379
380 ARM_2D_COLOUR_CCCN888 = ARM_2D_COLOUR_RGB32 ,
381 ARM_2D_COLOUR_CCCA8888 = ARM_2D_COLOUR_SZ_32BIT_msk |
382 ARM_2D_COLOUR_HAS_ALPHA_msk ,
383
384 ARM_2D_COLOUR_RGB888 = ARM_2D_COLOUR_CCCN888 ,
385 ARM_2D_COLOUR_BGRA8888 = ARM_2D_COLOUR_CCCA8888 ,
386
387/* not supported yet
388 ARM_2D_COLOUR_NCCC888 = ARM_2D_COLOUR_RGB32 |
389 ARM_2D_COLOUR_BIG_ENDIAN_msk ,
390 ARM_2D_COLOUR_ACCC8888 = ARM_2D_COLOUR_SZ_32BIT_msk |
391 ARM_2D_COLOUR_HAS_ALPHA_msk |
392 ARM_2D_COLOUR_BIG_ENDIAN_msk ,
393*/
394 ARM_2D_CHANNEL_8in32 = ARM_2D_COLOUR_SZ_32BIT_msk |
395 ARM_2D_COLOUR_HAS_ALPHA_msk |
396 ARM_2D_COLOUR_VARIANT_msk ,
397};
398
399/* macros for colour formats */
400#define ARM_2D_M_COLOUR_MONOCHROME ARM_2D_M_COLOUR_SZ_1BIT_msk //!< macro for the monochrome
401#define ARM_2D_M_COLOUR_BIN ARM_2D_M_COLOUR_SZ_1BIT_msk //!< macro for the 1bit colour format (alias)
402#define ARM_2D_M_COLOUR_1BIT ARM_2D_M_COLOUR_SZ_1BIT_msk //!< macro for the 1bin colour format (alias)
403
404#define ARM_2D_M_COLOUR_MASK_A2 ARM_2D_M_COLOUR_SZ_2BIT_msk //!< macro for the 2bit alpha mask
405#define ARM_2D_M_COLOUR_MASK_A4 ARM_2D_M_COLOUR_SZ_4BIT_msk //!< macro for the 4bit alpha mask
406
407#define ARM_2D_M_COLOUR_8BIT ARM_2D_M_COLOUR_SZ_8BIT_msk //!< macro for the generic 8bit colour formats
408#define ARM_2D_M_COLOUR_GRAY8 ARM_2D_M_COLOUR_SZ_8BIT_msk //!< macro for the gray8 colour format
409#define ARM_2D_M_COLOUR_MASK_A8 ARM_2D_M_COLOUR_SZ_8BIT_msk //!< macro for the 8bit alpha mask
410
411#define ARM_2D_M_COLOUR_16BIT ARM_2D_M_COLOUR_SZ_16BIT_msk //!< macro for the generic 16bit colour formats
412#define ARM_2D_M_COLOUR_RGB16 ARM_2D_M_COLOUR_SZ_16BIT_msk //!< macro for the generic 16bit colour formats
413#define ARM_2D_M_COLOUR_RGB565 ARM_2D_M_COLOUR_RGB16 //!< macro for the rgb565
414
415/* won't support
416#define ARM_2D_M_COLOUR_RGB565_BE ( ARM_2D_M_COLOUR_SZ_16BIT_msk \
417 | ARM_2D_M_COLOUR_BIG_ENDIAN_msk )
418 */
419
420#define ARM_2D_M_COLOUR_32BIT ARM_2D_M_COLOUR_SZ_32BIT_msk //!< macro for the generic 32bit colour formats
421#define ARM_2D_M_COLOUR_RGB32 ARM_2D_M_COLOUR_SZ_32BIT_msk //!< macro for the generic 32bit colour formats
422
423#define ARM_2D_M_COLOUR_CCCN888 ARM_2D_M_COLOUR_RGB32 //!< macro for the generic 32bit colour formats with an reserved channel at the highest byte
424
425/*! macro for the generic 32bit colour formats with an alpha channel at the highest byte */
426#define ARM_2D_M_COLOUR_CCCA8888 ( ARM_2D_M_COLOUR_SZ_32BIT_msk \
427 | ARM_2D_M_COLOUR_HAS_ALPHA_msk)
428
429#define ARM_2D_M_COLOUR_RGB888 ARM_2D_M_COLOUR_CCCN888 //!< macro for the RGB888 (BGRN8888)
430#define ARM_2D_M_COLOUR_BGRAA8888 ARM_2D_M_COLOUR_CCCA8888 //!< macro for the BGRA8888
431
432/* not supported yet
433#define ARM_2D_M_COLOUR_NCCC888 ( ARM_2D_M_COLOUR_RGB32 \
434 | ARM_2D_M_COLOUR_BIG_ENDIAN_msk )
435#define ARM_2D_M_COLOUR_ACCC8888 ( ARM_2D_M_COLOUR_SZ_32BIT_msk \
436 | ARM_2D_M_COLOUR_HAS_ALPHA_msk \
437 | ARM_2D_M_COLOUR_BIG_ENDIAN_msk )
438*/
439/*! macro for a special colour format which access only one channel in RGB32 */
440#define ARM_2D_M_CHANNEL_8in32 ( ARM_2D_M_COLOUR_SZ_32BIT_msk \
441 | ARM_2D_M_COLOUR_HAS_ALPHA_msk) \
442 | ARM_2D_M_COLOUR_VARIANT_msk )
443
444/*!
445 * \brief a type used as colour descriptor
446 *
447 */
448typedef union {
449 struct {
450 uint8_t bHasAlpha : 1; //!< whether the target colour has alpha channel
451 uint8_t u3ColourSZ : 3; //!< the size of the colour
452 uint8_t bBigEndian : 1; //!< whether the colour is stored in big endian
453 uint8_t u3Variant : 3;
454 };
455 uint8_t chScheme;
457
458/*----------------------------------------------------------------------------*
459 * Tile and Regions *
460 *----------------------------------------------------------------------------*/
461
462/*!
463 * \brief a type for coordinates (integer)
464 *
465 */
466typedef struct arm_2d_location_t {
467 int16_t iX; //!< x in Cartesian coordinate system
468 int16_t iY; //!< y in Cartesian coordinate system
470
471/*!
472 * \brief a type for coordinates in floating point
473 *
474 */
475typedef struct arm_2d_point_float_t {
476 float fX; //!< x in Cartesian coordinate system
477 float fY; //!< y in Cartesian coordinate system
479
480/*!
481 * \brief a type for coordinates in fixed point
482 *
483 */
484typedef struct arm_2d_point_fx_t {
485 int32_t X; //!< x in Cartesian coordinate system
486 int32_t Y; //!< y in Cartesian coordinate system
488
489/*!
490 * \brief a type for the size of an rectangular area
491 *
492 */
493typedef struct arm_2d_size_t {
494 int16_t iWidth; //!< width of an rectangular area
495 int16_t iHeight; //!< height of an rectangular area
497
498/*!
499 * \brief a type for an rectangular area
500 *
501 */
502typedef struct arm_2d_region_t {
503 implement_ex(arm_2d_location_t, tLocation); //!< the location (top-left corner)
504 implement_ex(arm_2d_size_t, tSize); //!< the size
506
507/*!
508 * \brief a type for tile
509 *
510 */
511typedef struct arm_2d_tile_t arm_2d_tile_t;
513 implement_ex(struct {
514 uint8_t bIsRoot : 1; //!< is this tile a root tile
515 uint8_t bHasEnforcedColour : 1; //!< does this tile contains enforced colour info
516 uint8_t bDerivedResource : 1; //!< indicate whether this is a derived resources (when bIsRoot == 0)
517 uint8_t bVirtualResource : 1; //!< indicate whether the resource should be loaded on-demand
518 uint8_t bVirtualScreen : 1; //!< DO NOT USE! indicate whether the tile is considered as the virtual screen, it is used in dirty region calculation
519 uint8_t : 3;
520 uint8_t : 8;
521 uint8_t : 8;
522 arm_2d_color_info_t tColourInfo; //!< enforced colour
523 }, tInfo);
524
525 implement_ex(arm_2d_region_t, tRegion); //!< the region of the tile
526
527 union {
528 /* when bIsRoot is true, phwBuffer is available,
529 * otherwise ptParent is available
530 */
531 arm_2d_tile_t *ptParent; //!< a pointer points to the parent tile
532 uint8_t *pchBuffer; //!< a pointer points to a buffer in a 8bit colour type
533 uint16_t *phwBuffer; //!< a pointer points to a buffer in a 16bit colour type
534 uint32_t *pwBuffer; //!< a pointer points to a buffer in a 32bit colour type
535
536 intptr_t nAddress; //!< a pointer in integer
537 };
538};
539
540/*!
541 * \brief the enumeration type for describing memory types
542 *
543 */
544typedef enum {
545 ARM_2D_MEM_TYPE_UNSPECIFIED, //!< normal memory, we don't know its characterisics
546 ARM_2D_MEM_TYPE_SLOW, //!< for slow memories, such as SDRAM, DDRAM, external memory etc
547 ARM_2D_MEM_TYPE_FAST, //!< for fast memories, such as TCM, SRAM etc.
549
550typedef union __arm_2d_mem_info_t {
551 struct {
552 uint32_t u24SizeInByte : 24; //!< the memory size in Byte
553 uint32_t u2ItemSize : 3; //!< the size of the data item
554 uint32_t u2Align : 3; //!< the alignment
555 uint32_t u2Type : 2; //!< The memory type define in enum arm_2d_mem_type_t
556 };
557 uint32_t Value; //!< Memory Information
559
560
561/*!
562 * \brief a type for scratch memory blocks
563 *
564 */
565typedef struct __arm_2d_mem_t __arm_2d_mem_t;
567 union {
568 __arm_2d_mem_t *ptNext; //!< a list pointer
569 uint32_t wSignature; //!< a signature for validation
570 };
571 __arm_2d_mem_info_t tInfo; //!< memory info
572 uint8_t pBuffer[]; //!< a constant pointer points to the buffer following this header
573};
574
575
576/*!
577 * \brief a type for virtual resource
578 *
579 * \note the flag tTile.tInfo.bVirtualResource must be true (1)
580 */
581typedef struct arm_2d_vres_t arm_2d_vres_t;
583
584 /*! base class: tTile */
586
587 /*! a reference of an user object */
588 uintptr_t pTarget;
589
590 /*!
591 * \brief a method to load a specific part of an image
592 * \param[in] pTarget a reference of an user object
593 * \param[in] ptVRES a reference of this virtual resource
594 * \param[in] ptRegion the target region of the image
595 * \return intptr_t the address of a resource buffer which holds the content
596 */
597 intptr_t (*Load) ( uintptr_t pTarget,
598 arm_2d_vres_t *ptVRES,
599 arm_2d_region_t *ptRegion);
600
601 /*!
602 * \brief a method to despose the buffer
603 * \param[in] pTarget a reference of an user object
604 * \param[in] ptVRES a reference of this virtual resource
605 * \param[in] pBuffer the target buffer
606 */
607 void (*Depose) ( uintptr_t pTarget,
608 arm_2d_vres_t *ptVRES,
609 intptr_t pBuffer );
610};
611
612/*----------------------------------------------------------------------------*
613 * Task *
614 *----------------------------------------------------------------------------*/
615
616/*!
617 * \brief arm-2d application level task control block
618 *
619 */
620typedef struct arm_2d_task_t {
621ARM_PRIVATE(
622 arm_fsm_rt_t tResult; //!< the temporary result of the task
623 uint8_t chState; //!< the state of the FSM
624
625 void *ptTask; //!< a pointer for an internal object
628
629/*----------------------------------------------------------------------------*
630 * Operation and Events Handling *
631 *----------------------------------------------------------------------------*/
632
633
635
636/*!
637 * \brief a prototype of event handlers for 2D operations
638 *
639 * \param[in] ptThisOP the target 2D operation descriptor
640 * \param[in] tResult the operation result
641 * \param[in] pTarget A user attached object
642 * \return bool a boolean value to indicate whether the event has been handled
643 */
645 arm_fsm_rt_t tResult,
646 void *pTarget);
647
648/*!
649 * \brief a type for 2D operation event handling
650 *
651 */
652typedef struct arm_2d_op_evt_t {
654 void *pTarget; //!< user attached target
656
657/*!
658 * \brief a prototype for generic event handlers
659 *
660 * \param pTarget A user attached object
661 * \return bool a boolean value to indicate whether the event has been handled
662 */
663typedef bool arm_2d_evt_handler_t(void *pTarget);
664
665/*!
666 * \brief a type for generic event handling
667 *
668 */
669typedef struct arm_2d_evt_t {
670 arm_2d_evt_handler_t *fnHandler; //!< event handler
671 void *pTarget; //!< user attached target
673
674
675#define ARM_2D_OP_INFO_PARAM_HAS_SOURCE _BV(0) //!< opcode has source tile info
676#define ARM_2D_OP_INFO_PARAM_HAS_TARGET _BV(1) //!< opcode has target tile info
677#define ARM_2D_OP_INFO_PARAM_HAS_SOURCE_MASK _BV(2) //!< opcode has source mask info
678#define ARM_2D_OP_INFO_PARAM_HAS_TARGET_MASK _BV(3) //!< opcode has target mask info
679#define ARM_2D_OP_INFO_PARAM_HAS_ORIGIN _BV(4) //!< opcode has original tile info
680
681/*! a bitmask for INFO_PARAM_HAS_xxxx bitfields */
682#define ARM_2D_OP_INFO_PARAM_TILES_MASK ( \
683 ARM_2D_OP_INFO_PARAM_HAS_SOURCE | \
684 ARM_2D_OP_INFO_PARAM_HAS_TARGET | \
685 ARM_2D_OP_INFO_PARAM_HAS_SOURCE_MASK | \
686 ARM_2D_OP_INFO_PARAM_HAS_TARGET_MASK | \
687 ARM_2D_OP_INFO_PARAM_HAS_ORIGIN )
688
689
690//! \brief an incomplete defintion which is only used for defining pointers
692
693/*!
694 * \brief A descriptive header for 2D operations
695 */
696typedef union __arm_2d_op_info_t {
697 struct {
698 arm_2d_color_info_t Colour; //!< the colour used in thie operation
699 union {
700 struct {
701 uint8_t bHasSource : 1; //!< whether this operation contains source tile
702 uint8_t bHasTarget : 1; //!< whether this operation contains target tile
703 uint8_t bHasSrcMask : 1; //!< whether this operation has Mask layer for source tile
704 uint8_t bHasDesMask : 1; //!< whether this operation has Mask layer for target tile
705 uint8_t bHasOrigin : 1; //!< whether the Source has an origin tile
706 uint8_t : 2;
707 uint8_t bAllowEnforcedColour : 1; //!< whether this operation allow enforced colours in tiles
708 };
709 uint8_t chValue; //!< feature value
710 }Param; //!< operation feature set
711
712 uint8_t chInClassOffset; //!< some operation uses this as the offset of the key member in the class
713 uint8_t chOpIndex; //!< __ARM_2D_OP_IDX_XXXXXX
714
715 union {
716 struct {
717 uint8_t CopyLike; //!< A copy-like interface contains the target tile, the source tile and the copy size
718 uint8_t FillLike; //!< A copy-like interface contains the target tile and the source tile
719 };
720 struct {
721 uint8_t CopyOrigLike; //!< A copy-like interface contains the target tile, the dummy tile, the reference to the original source tile and the copy size
722 uint8_t FillOrigLike; //!< A copy-like interface contains the target tile, the dummy tile and the reference to the original source tile
723 };
724 struct {
725 uint8_t TileProcessLike; //!< A simple interface contains only the target tile
726 };
727 }LowLevelInterfaceIndex; //!< Low level interface index
728
729 union {
730 const __arm_2d_low_level_io_t *IO[2]; //!< array of IOs
731
732 struct {
733 const __arm_2d_low_level_io_t *ptCopyLike; //!< the function pointer for a copy-like implementation
734 const __arm_2d_low_level_io_t *ptFillLike; //!< the function pointer for a fill-like implementation
735 };
736 struct {
737 const __arm_2d_low_level_io_t *ptCopyOrigLike; //!< the function pointer for a copy-orig-like implementation
738 const __arm_2d_low_level_io_t *ptFillOrigLike; //!< the function pointer for a fill-orig-like implementation
739 };
740 struct {
741 const __arm_2d_low_level_io_t *ptTileProcessLike; //!< the function pointer for the tile-process-like implementation
742 };
743 }LowLevelIO; //!< low level IO definition
744
745 }Info; //!< operation description
746 uint32_t wID; //!< Operation ID
748
749/*!
750 * \brief how would you want to accelerate the 2d-operation
751 */
752enum {
753 //! Use hardware acceleration if possible, even if there is a long queue to wait
755
756 //! Only use Hardware Acceleration, if it is not supported, IO error will be issued
758
759 //! Only use software algorithm
761
762 //!< don't care, let the arm-2d library decide
763 ARM_2D_PREF_ACC_DONT_CARE = 3,
764};
765
766#define __ARM_2D_OP_STATUS_BUSY_msk (1 << 4) //!< bitmask for the busy flag
767#define __ARM_2D_OP_STATUS_IO_ERROR_msk (1 << 5) //!< bitmask for the IO error flag
768#define __ARM_2D_OP_STATUS_CPL_msk (1 << 6) //!< bitmask for the complete flag
769
770/*!
771 * \brief a type for 2D operation status
772 *
773 */
774typedef union arm_2d_op_status_t {
775 struct {
776 uint16_t u4SubTaskCount : 4; //!< sub task count
777 uint16_t bIsBusy : 1; //!< busy flag
778 uint16_t bIOError : 1; //!< HW IO Error
779 uint16_t bOpCpl : 1; //!< the whole operation complete
780 uint16_t : 9; //!< reserved
781 };
782 uint16_t tValue; //!< the host integer
784
785/*!
786 * \brief the abstract class of 2D operations
787 *
788 */
790ARM_PRIVATE(
791 arm_2d_op_core_t *ptNext; //!< a pointer for a single list
792
793 const __arm_2d_op_info_t *ptOp; //!< the pointer for the corresponding 2D operation description
794
795 struct {
796 uint8_t u2ACCMethods : 2; //!< acceleration Methods
797 uint8_t : 6; //!< reserved
798 }Preference;
799
800 int8_t tResult; //!< operation result
801 volatile arm_2d_op_status_t Status; //!< operation status
802
803 arm_2d_op_evt_t evt2DOpCpl; //!< operation-complete event
804
805#if __ARM_2D_HAS_ASYNC__
806 uintptr_t pSemaphore; //!< point to semaphore
807#endif
809
810 uintptr_t pUserParam; //!< user attached object
811};
812
813/*!
814 * \brief the base class for operations with only a target tile
815 * \note arm_2d_op_msk_t inherits from arm_2d_op_core_t
816 */
817typedef struct arm_2d_op_t {
819 struct {
820 const arm_2d_tile_t *ptTile; //!< target tile
821 const arm_2d_region_t *ptRegion; //!< target region
822 } Target;
824
825/*!
826 * \brief the base class for operations with a target tile and a target mask
827 * \note arm_2d_op_msk_t inherits from arm_2d_op_t
828 */
829typedef struct arm_2d_op_msk_t {
831 struct {
832 const arm_2d_tile_t *ptTile; //!< target tile
833 const arm_2d_region_t *ptRegion; //!< target region
834 } Target;
835
836 /* derived part */
837 struct {
838 const arm_2d_tile_t *ptTile; //!< target tile
839 } Mask;
841
842/*!
843 * \brief the base class for operations with a target tile and a source tile
844 * \note arm_2d_op_src_t inherits from arm_2d_op_t
845 */
846typedef struct arm_2d_op_src_t {
848 struct {
849 const arm_2d_tile_t *ptTile; //!< target tile
850 const arm_2d_region_t *ptRegion; //!< target region
851 } Target;
852
853 /* derived part */
854 struct {
855 const arm_2d_tile_t *ptTile; //!< source tile
856 }Source;
857 uint32_t wMode;
859
860/*!
861 * \brief the base class for operations with a target tile, a source tile and masks
862 * \note arm_2d_op_src_msk_t inherits from arm_2d_op_src_t
863 */
864typedef struct arm_2d_op_src_msk_t {
866 struct {
867 const arm_2d_tile_t *ptTile; //!< target tile
868 const arm_2d_region_t *ptRegion; //!< target region
869 } Target;
870 struct {
871 const arm_2d_tile_t *ptTile; //!< source tile
872 }Source;
873 uint32_t wMode;
874
875 /* derived part */
876 struct {
877 const arm_2d_tile_t *ptSourceSide; //!< source side mask
878 const arm_2d_tile_t *ptTargetSide; //!< target side mask
879 } Mask;
881
882/*!
883 * \brief the base class for operations with a target tile, a dummy tile and a reference to the original source tile
884 * \note arm_2d_op_src_orig_t inherits from arm_2d_op_src_t
885 */
886typedef struct arm_2d_op_src_orig_t {
888 struct {
889 const arm_2d_tile_t *ptTile; //!< target tile
890 const arm_2d_region_t *ptRegion; //!< target region
891 } Target;
892 struct {
893 const arm_2d_tile_t *ptTile; //!< the dummy source tile
894 }Source;
895 uint32_t wMode;
896
897 /* derived part */
898 struct {
899 const arm_2d_tile_t *ptTile; //!< the origin tile
900 arm_2d_tile_t tDummySource; //!< the buffer for the source
901 }Origin;
902
904
905/*!
906 * \brief the base class for operations with a target tile, a dummy tile, a reference to the original source tile and masks
907 * \note arm_2d_op_src_orig_msk_t inherits from arm_2d_op_src_orig_t
908 */
911 struct {
912 const arm_2d_tile_t *ptTile; //!< target tile
913 const arm_2d_region_t *ptRegion; //!< target region
914 } Target;
915 struct {
916 const arm_2d_tile_t *ptTile; //!< the dummy source tile
917 }Source;
918 uint32_t wMode;
919 struct {
920 const arm_2d_tile_t *ptTile; //!< the origin tile
921 arm_2d_tile_t tDummySource; //!< the buffer for the source
922 }Origin;
923
924 /* derived part */
925 struct {
926 const arm_2d_tile_t *ptOriginSide; //!< origin side mask
927 const arm_2d_tile_t *ptTargetSide; //!< target side mask
928 } Mask;
930
931
932/*----------------------------------------------------------------------------*
933 * Fast Rotation linear regression structure
934 *----------------------------------------------------------------------------*/
935
936#if (__ARM_2D_HAS_HELIUM_FLOAT__ || __ARM_2D_HAS_FPU__) \
937 && !__ARM_2D_CFG_FORCED_FIXED_POINT_TRANSFORM__
938/*!
939 * \brief a type for parameters of linear interpolation (in floating point)
940 *
941 */
942typedef struct arm_2d_rot_linear_regr_t {
943 float slopeY;
944 float interceptY;
945 float slopeX;
946 float interceptX;
948
949#else
950/*!
951 * \brief a type for parameters of linear interpolation (in fixed point)
952 *
953 */
955 int32_t slopeY;
956 int32_t interceptY;
957 int32_t slopeX;
958 int32_t interceptX;
960
961#endif
962
963/*============================ GLOBAL VARIABLES ==============================*/
964/*============================ PROTOTYPES ====================================*/
965
966/*! @} */
967
968#if defined(__clang__)
969#pragma clang diagnostic pop
970#elif __IS_COMPILER_ARM_COMPILER_5__
971#pragma diag_warning 64
972#elif __IS_COMPILER_GCC__
973#pragma GCC diagnostic pop
974#endif
975
976#ifdef __cplusplus
977}
978#endif
979
980#endif // __ARM_2D_TYPES_H__
981
982