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: 06. April 2023
25 * $Revision: V.1.1.1
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_8BIT = ARM_2D_COLOUR_SZ_8BIT_msk,
362 ARM_2D_COLOUR_GRAY8 = ARM_2D_COLOUR_SZ_8BIT_msk,
363 ARM_2D_COLOUR_MASK_A8 = ARM_2D_COLOUR_SZ_8BIT_msk,
364
365 ARM_2D_COLOUR_16BIT = ARM_2D_COLOUR_SZ_16BIT_msk,
366 ARM_2D_COLOUR_RGB16 = ARM_2D_COLOUR_SZ_16BIT_msk,
367 ARM_2D_COLOUR_RGB565 = ARM_2D_COLOUR_RGB16,
368
369/* won't support
370 ARM_2D_COLOUR_RGB565_BE = ARM_2D_COLOUR_SZ_16BIT_msk |
371 ARM_2D_COLOUR_BIG_ENDIAN_msk ,
372 */
373
374 ARM_2D_COLOUR_32BIT = ARM_2D_COLOUR_SZ_32BIT_msk ,
375 ARM_2D_COLOUR_RGB32 = ARM_2D_COLOUR_SZ_32BIT_msk ,
376
377 ARM_2D_COLOUR_CCCN888 = ARM_2D_COLOUR_RGB32 ,
378 ARM_2D_COLOUR_CCCA8888 = ARM_2D_COLOUR_SZ_32BIT_msk |
379 ARM_2D_COLOUR_HAS_ALPHA_msk ,
380
381 ARM_2D_COLOUR_RGB888 = ARM_2D_COLOUR_CCCN888 ,
382 ARM_2D_COLOUR_BGRA8888 = ARM_2D_COLOUR_CCCA8888 ,
383
384/* not supported yet
385 ARM_2D_COLOUR_NCCC888 = ARM_2D_COLOUR_RGB32 |
386 ARM_2D_COLOUR_BIG_ENDIAN_msk ,
387 ARM_2D_COLOUR_ACCC8888 = ARM_2D_COLOUR_SZ_32BIT_msk |
388 ARM_2D_COLOUR_HAS_ALPHA_msk |
389 ARM_2D_COLOUR_BIG_ENDIAN_msk ,
390*/
391 ARM_2D_CHANNEL_8in32 = ARM_2D_COLOUR_SZ_32BIT_msk |
392 ARM_2D_COLOUR_HAS_ALPHA_msk |
393 ARM_2D_COLOUR_VARIANT_msk ,
394};
395
396/* macros for colour formats */
397#define ARM_2D_M_COLOUR_MONOCHROME ARM_2D_M_COLOUR_SZ_1BIT_msk //!< macro for the monochrome
398#define ARM_2D_M_COLOUR_BIN ARM_2D_M_COLOUR_SZ_1BIT_msk //!< macro for the 1bit colour format (alias)
399#define ARM_2D_M_COLOUR_1BIT ARM_2D_M_COLOUR_SZ_1BIT_msk //!< macro for the 1bin colour format (alias)
400
401#define ARM_2D_M_COLOUR_MASK_A2 ARM_2D_M_COLOUR_SZ_2BIT_msk //!< macro for the 2bit alpha mask
402#define ARM_2D_M_COLOUR_MASK_A4 ARM_2D_M_COLOUR_SZ_4BIT_msk //!< macro for the 4bit alpha mask
403
404#define ARM_2D_M_COLOUR_8BIT ARM_2D_M_COLOUR_SZ_8BIT_msk //!< macro for the generic 8bit colour formats
405#define ARM_2D_M_COLOUR_GRAY8 ARM_2D_M_COLOUR_SZ_8BIT_msk //!< macro for the gray8 colour format
406#define ARM_2D_M_COLOUR_MASK_A8 ARM_2D_M_COLOUR_SZ_8BIT_msk //!< macro for the 8bit alpha mask
407
408#define ARM_2D_M_COLOUR_16BIT ARM_2D_M_COLOUR_SZ_16BIT_msk //!< macro for the generic 16bit colour formats
409#define ARM_2D_M_COLOUR_RGB16 ARM_2D_M_COLOUR_SZ_16BIT_msk //!< macro for the generic 16bit colour formats
410#define ARM_2D_M_COLOUR_RGB565 ARM_2D_M_COLOUR_RGB16 //!< macro for the rgb565
411
412/* won't support
413#define ARM_2D_M_COLOUR_RGB565_BE ( ARM_2D_M_COLOUR_SZ_16BIT_msk \
414 | ARM_2D_M_COLOUR_BIG_ENDIAN_msk )
415 */
416
417#define ARM_2D_M_COLOUR_32BIT ARM_2D_M_COLOUR_SZ_32BIT_msk //!< macro for the generic 32bit colour formats
418#define ARM_2D_M_COLOUR_RGB32 ARM_2D_M_COLOUR_SZ_32BIT_msk //!< macro for the generic 32bit colour formats
419
420#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
421
422/*! macro for the generic 32bit colour formats with an alpha channel at the highest byte */
423#define ARM_2D_M_COLOUR_CCCA8888 ( ARM_2D_M_COLOUR_SZ_32BIT_msk \
424 | ARM_2D_M_COLOUR_HAS_ALPHA_msk)
425
426#define ARM_2D_M_COLOUR_RGB888 ARM_2D_M_COLOUR_CCCN888 //!< macro for the RGB888 (BGRN8888)
427#define ARM_2D_M_COLOUR_BGRAA8888 ARM_2D_M_COLOUR_CCCA8888 //!< macro for the BGRA8888
428
429/* not supported yet
430#define ARM_2D_M_COLOUR_NCCC888 ( ARM_2D_M_COLOUR_RGB32 \
431 | ARM_2D_M_COLOUR_BIG_ENDIAN_msk )
432#define ARM_2D_M_COLOUR_ACCC8888 ( ARM_2D_M_COLOUR_SZ_32BIT_msk \
433 | ARM_2D_M_COLOUR_HAS_ALPHA_msk \
434 | ARM_2D_M_COLOUR_BIG_ENDIAN_msk )
435*/
436/*! macro for a special colour format which access only one channel in RGB32 */
437#define ARM_2D_M_CHANNEL_8in32 ( ARM_2D_M_COLOUR_SZ_32BIT_msk \
438 | ARM_2D_M_COLOUR_HAS_ALPHA_msk) \
439 | ARM_2D_M_COLOUR_VARIANT_msk )
440
441/*!
442 * \brief a type used as colour descriptor
443 *
444 */
445typedef union {
446 struct {
447 uint8_t bHasAlpha : 1; //!< whether the target colour has alpha channel
448 uint8_t u3ColourSZ : 3; //!< the size of the colour
449 uint8_t bBigEndian : 1; //!< whether the colour is stored in big endian
450 uint8_t u3Variant : 3;
451 };
452 uint8_t chScheme;
454
455/*----------------------------------------------------------------------------*
456 * Tile and Regions *
457 *----------------------------------------------------------------------------*/
458
459/*!
460 * \brief a type for coordinates (integer)
461 *
462 */
463typedef struct arm_2d_location_t {
464 int16_t iX; //!< x in Cartesian coordinate system
465 int16_t iY; //!< y in Cartesian coordinate system
467
468/*!
469 * \brief a type for coordinates in floating point
470 *
471 */
472typedef struct arm_2d_point_float_t {
473 float fX; //!< x in Cartesian coordinate system
474 float fY; //!< y in Cartesian coordinate system
476
477/*!
478 * \brief a type for coordinates in fixed point
479 *
480 */
481typedef struct arm_2d_point_fx_t {
482 int32_t X; //!< x in Cartesian coordinate system
483 int32_t Y; //!< y in Cartesian coordinate system
485
486/*!
487 * \brief a type for the size of an rectangular area
488 *
489 */
490typedef struct arm_2d_size_t {
491 int16_t iWidth; //!< width of an rectangular area
492 int16_t iHeight; //!< height of an rectangular area
494
495/*!
496 * \brief a type for an rectangular area
497 *
498 */
499typedef struct arm_2d_region_t {
500 implement_ex(arm_2d_location_t, tLocation); //!< the location (top-left corner)
501 implement_ex(arm_2d_size_t, tSize); //!< the size
503
504/*!
505 * \brief a type for tile
506 *
507 */
508typedef struct arm_2d_tile_t arm_2d_tile_t;
510 implement_ex(struct {
511 uint8_t bIsRoot : 1; //!< is this tile a root tile
512 uint8_t bHasEnforcedColour : 1; //!< does this tile contains enforced colour info
513 uint8_t bDerivedResource : 1; //!< indicate whether this is a derived resources (when bIsRoot == 0)
514 uint8_t bVirtualResource : 1; //!< indicate whether the resource should be loaded on-demand
515 uint8_t : 4;
516 uint8_t : 8;
517 uint8_t : 8;
518 arm_2d_color_info_t tColourInfo; //!< enforced colour
519 }, tInfo);
520
521 implement_ex(arm_2d_region_t, tRegion); //!< the region of the tile
522
523 union {
524 /* when bIsRoot is true, phwBuffer is available,
525 * otherwise ptParent is available
526 */
527 arm_2d_tile_t *ptParent; //!< a pointer points to the parent tile
528 uint8_t *pchBuffer; //!< a pointer points to a buffer in a 8bit colour type
529 uint16_t *phwBuffer; //!< a pointer points to a buffer in a 16bit colour type
530 uint32_t *pwBuffer; //!< a pointer points to a buffer in a 32bit colour type
531
532 intptr_t nAddress; //!< a pointer in integer
533 };
534};
535
536/*!
537 * \brief the enumeration type for describing memory types
538 *
539 */
540typedef enum {
541 ARM_2D_MEM_TYPE_UNSPECIFIED, //!< normal memory, we don't know its characterisics
542 ARM_2D_MEM_TYPE_SLOW, //!< for slow memories, such as SDRAM, DDRAM, external memory etc
543 ARM_2D_MEM_TYPE_FAST, //!< for fast memories, such as TCM, SRAM etc.
545
546typedef union __arm_2d_mem_info_t {
547 struct {
548 uint32_t u24SizeInByte : 24; //!< the memory size in Byte
549 uint32_t u2ItemSize : 3; //!< the size of the data item
550 uint32_t u2Align : 3; //!< the alignment
551 uint32_t u2Type : 2; //!< The memory type define in enum arm_2d_mem_type_t
552 };
553 uint32_t Value; //!< Memory Information
555
556
557/*!
558 * \brief a type for scratch memory blocks
559 *
560 */
561typedef struct __arm_2d_mem_t __arm_2d_mem_t;
563 union {
564 __arm_2d_mem_t *ptNext; //!< a list pointer
565 uint32_t wSignature; //!< a signature for validation
566 };
567 __arm_2d_mem_info_t tInfo; //!< memory info
568 uint8_t pBuffer[]; //!< a constant pointer points to the buffer following this header
569};
570
571
572/*!
573 * \brief a type for virtual resource
574 *
575 * \note the flag tTile.tInfo.bVirtualResource must be true (1)
576 */
577typedef struct arm_2d_vres_t arm_2d_vres_t;
579
580 /*! base class: tTile */
582
583 /*! a reference of an user object */
584 uintptr_t pTarget;
585
586 /*!
587 * \brief a method to load a specific part of an image
588 * \param[in] pTarget a reference of an user object
589 * \param[in] ptVRES a reference of this virtual resource
590 * \param[in] ptRegion the target region of the image
591 * \return intptr_t the address of a resource buffer which holds the content
592 */
593 intptr_t (*Load) ( uintptr_t pTarget,
594 arm_2d_vres_t *ptVRES,
595 arm_2d_region_t *ptRegion);
596
597 /*!
598 * \brief a method to despose the buffer
599 * \param[in] pTarget a reference of an user object
600 * \param[in] ptVRES a reference of this virtual resource
601 * \param[in] pBuffer the target buffer
602 */
603 void (*Depose) ( uintptr_t pTarget,
604 arm_2d_vres_t *ptVRES,
605 intptr_t pBuffer );
606};
607
608/*----------------------------------------------------------------------------*
609 * Task *
610 *----------------------------------------------------------------------------*/
611
612/*!
613 * \brief arm-2d application level task control block
614 *
615 */
616typedef struct arm_2d_task_t {
617ARM_PRIVATE(
618 arm_fsm_rt_t tResult; //!< the temporary result of the task
619 uint8_t chState; //!< the state of the FSM
620
621 void *ptTask; //!< a pointer for an internal object
624
625/*----------------------------------------------------------------------------*
626 * Operation and Events Handling *
627 *----------------------------------------------------------------------------*/
628
629
631
632/*!
633 * \brief a prototype of event handlers for 2D operations
634 *
635 * \param[in] ptThisOP the target 2D operation descriptor
636 * \param[in] tResult the operation result
637 * \param[in] pTarget A user attached object
638 * \return bool a boolean value to indicate whether the event has been handled
639 */
641 arm_fsm_rt_t tResult,
642 void *pTarget);
643
644/*!
645 * \brief a type for 2D operation event handling
646 *
647 */
648typedef struct arm_2d_op_evt_t {
650 void *pTarget; //!< user attached target
652
653/*!
654 * \brief a prototype for generic event handlers
655 *
656 * \param pTarget A user attached object
657 * \return bool a boolean value to indicate whether the event has been handled
658 */
659typedef bool arm_2d_evt_handler_t(void *pTarget);
660
661/*!
662 * \brief a type for generic event handling
663 *
664 */
665typedef struct arm_2d_evt_t {
666 arm_2d_evt_handler_t *fnHandler; //!< event handler
667 void *pTarget; //!< user attached target
669
670
671#define ARM_2D_OP_INFO_PARAM_HAS_SOURCE _BV(0) //!< opcode has source tile info
672#define ARM_2D_OP_INFO_PARAM_HAS_TARGET _BV(1) //!< opcode has target tile info
673#define ARM_2D_OP_INFO_PARAM_HAS_SOURCE_MASK _BV(2) //!< opcode has source mask info
674#define ARM_2D_OP_INFO_PARAM_HAS_TARGET_MASK _BV(3) //!< opcode has target mask info
675#define ARM_2D_OP_INFO_PARAM_HAS_ORIGIN _BV(4) //!< opcode has original tile info
676
677/*! a bitmask for INFO_PARAM_HAS_xxxx bitfields */
678#define ARM_2D_OP_INFO_PARAM_TILES_MASK ( \
679 ARM_2D_OP_INFO_PARAM_HAS_SOURCE | \
680 ARM_2D_OP_INFO_PARAM_HAS_TARGET | \
681 ARM_2D_OP_INFO_PARAM_HAS_SOURCE_MASK | \
682 ARM_2D_OP_INFO_PARAM_HAS_TARGET_MASK | \
683 ARM_2D_OP_INFO_PARAM_HAS_ORIGIN )
684
685
686//! \brief an incomplete defintion which is only used for defining pointers
688
689/*!
690 * \brief A descriptive header for 2D operations
691 */
692typedef union __arm_2d_op_info_t {
693 struct {
694 arm_2d_color_info_t Colour; //!< the colour used in thie operation
695 union {
696 struct {
697 uint8_t bHasSource : 1; //!< whether this operation contains source tile
698 uint8_t bHasTarget : 1; //!< whether this operation contains target tile
699 uint8_t bHasSrcMask : 1; //!< whether this operation has Mask layer for source tile
700 uint8_t bHasDesMask : 1; //!< whether this operation has Mask layer for target tile
701 uint8_t bHasOrigin : 1; //!< whether the Source has an origin tile
702 uint8_t : 2;
703 uint8_t bAllowEnforcedColour : 1; //!< whether this operation allow enforced colours in tiles
704 };
705 uint8_t chValue; //!< feature value
706 }Param; //!< operation feature set
707
708 uint8_t chInClassOffset; //!< some operation uses this as the offset of the key member in the class
709 uint8_t chOpIndex; //!< __ARM_2D_OP_IDX_XXXXXX
710
711 union {
712 struct {
713 uint8_t CopyLike; //!< A copy-like interface contains the target tile, the source tile and the copy size
714 uint8_t FillLike; //!< A copy-like interface contains the target tile and the source tile
715 };
716 struct {
717 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
718 uint8_t FillOrigLike; //!< A copy-like interface contains the target tile, the dummy tile and the reference to the original source tile
719 };
720 struct {
721 uint8_t TileProcessLike; //!< A simple interface contains only the target tile
722 };
723 }LowLevelInterfaceIndex; //!< Low level interface index
724
725 union {
726 const __arm_2d_low_level_io_t *IO[2]; //!< array of IOs
727
728 struct {
729 const __arm_2d_low_level_io_t *ptCopyLike; //!< the function pointer for a copy-like implementation
730 const __arm_2d_low_level_io_t *ptFillLike; //!< the function pointer for a fill-like implementation
731 };
732 struct {
733 const __arm_2d_low_level_io_t *ptCopyOrigLike; //!< the function pointer for a copy-orig-like implementation
734 const __arm_2d_low_level_io_t *ptFillOrigLike; //!< the function pointer for a fill-orig-like implementation
735 };
736 struct {
737 const __arm_2d_low_level_io_t *ptTileProcessLike; //!< the function pointer for the tile-process-like implementation
738 };
739 }LowLevelIO; //!< low level IO definition
740
741 }Info; //!< operation description
742 uint32_t wID; //!< Operation ID
744
745/*!
746 * \brief how would you want to accelerate the 2d-operation
747 */
748enum {
749 //! Use hardware acceleration if possible, even if there is a long queue to wait
751
752 //! Only use Hardware Acceleration, if it is not supported, IO error will be issued
754
755 //! Only use software algorithm
757
758 //!< don't care, let the arm-2d library decide
759 ARM_2D_PREF_ACC_DONT_CARE = 3,
760};
761
762#define __ARM_2D_OP_STATUS_BUSY_msk (1 << 4) //!< bitmask for the busy flag
763#define __ARM_2D_OP_STATUS_IO_ERROR_msk (1 << 5) //!< bitmask for the IO error flag
764#define __ARM_2D_OP_STATUS_CPL_msk (1 << 6) //!< bitmask for the complete flag
765
766/*!
767 * \brief a type for 2D operation status
768 *
769 */
770typedef union arm_2d_op_status_t {
771 struct {
772 uint16_t u4SubTaskCount : 4; //!< sub task count
773 uint16_t bIsBusy : 1; //!< busy flag
774 uint16_t bIOError : 1; //!< HW IO Error
775 uint16_t bOpCpl : 1; //!< the whole operation complete
776 uint16_t : 9; //!< reserved
777 };
778 uint16_t tValue; //!< the host integer
780
781/*!
782 * \brief the abstract class of 2D operations
783 *
784 */
786ARM_PRIVATE(
787 arm_2d_op_core_t *ptNext; //!< a pointer for a single list
788
789 const __arm_2d_op_info_t *ptOp; //!< the pointer for the corresponding 2D operation description
790
791 struct {
792 uint8_t u2ACCMethods : 2; //!< acceleration Methods
793 uint8_t : 6; //!< reserved
794 }Preference;
795
796 int8_t tResult; //!< operation result
797 volatile arm_2d_op_status_t Status; //!< operation status
798
799 arm_2d_op_evt_t evt2DOpCpl; //!< operation-complete event
800
801#if __ARM_2D_HAS_ASYNC__
802 uintptr_t pSemaphore; //!< point to semaphore
803#endif
805
806 uintptr_t pUserParam; //!< user attached object
807};
808
809/*!
810 * \brief the base class for operations with only a target tile
811 * \note arm_2d_op_msk_t inherits from arm_2d_op_core_t
812 */
813typedef struct arm_2d_op_t {
815 struct {
816 const arm_2d_tile_t *ptTile; //!< target tile
817 const arm_2d_region_t *ptRegion; //!< target region
818 } Target;
820
821/*!
822 * \brief the base class for operations with a target tile and a target mask
823 * \note arm_2d_op_msk_t inherits from arm_2d_op_t
824 */
825typedef struct arm_2d_op_msk_t {
827 struct {
828 const arm_2d_tile_t *ptTile; //!< target tile
829 const arm_2d_region_t *ptRegion; //!< target region
830 } Target;
831
832 /* derived part */
833 struct {
834 const arm_2d_tile_t *ptTile; //!< target tile
835 } Mask;
837
838/*!
839 * \brief the base class for operations with a target tile and a source tile
840 * \note arm_2d_op_src_t inherits from arm_2d_op_t
841 */
842typedef struct arm_2d_op_src_t {
844 struct {
845 const arm_2d_tile_t *ptTile; //!< target tile
846 const arm_2d_region_t *ptRegion; //!< target region
847 } Target;
848
849 /* derived part */
850 struct {
851 const arm_2d_tile_t *ptTile; //!< source tile
852 }Source;
853 uint32_t wMode;
855
856/*!
857 * \brief the base class for operations with a target tile, a source tile and masks
858 * \note arm_2d_op_src_msk_t inherits from arm_2d_op_src_t
859 */
860typedef struct arm_2d_op_src_msk_t {
862 struct {
863 const arm_2d_tile_t *ptTile; //!< target tile
864 const arm_2d_region_t *ptRegion; //!< target region
865 } Target;
866 struct {
867 const arm_2d_tile_t *ptTile; //!< source tile
868 }Source;
869 uint32_t wMode;
870
871 /* derived part */
872 struct {
873 const arm_2d_tile_t *ptSourceSide; //!< source side mask
874 const arm_2d_tile_t *ptTargetSide; //!< target side mask
875 } Mask;
877
878/*!
879 * \brief the base class for operations with a target tile, a dummy tile and a reference to the original source tile
880 * \note arm_2d_op_src_orig_t inherits from arm_2d_op_src_t
881 */
882typedef struct arm_2d_op_src_orig_t {
884 struct {
885 const arm_2d_tile_t *ptTile; //!< target tile
886 const arm_2d_region_t *ptRegion; //!< target region
887 } Target;
888 struct {
889 const arm_2d_tile_t *ptTile; //!< the dummy source tile
890 }Source;
891 uint32_t wMode;
892
893 /* derived part */
894 struct {
895 const arm_2d_tile_t *ptTile; //!< the origin tile
896 arm_2d_tile_t tDummySource; //!< the buffer for the source
897 }Origin;
898
900
901/*!
902 * \brief the base class for operations with a target tile, a dummy tile, a reference to the original source tile and masks
903 * \note arm_2d_op_src_orig_msk_t inherits from arm_2d_op_src_orig_t
904 */
907 struct {
908 const arm_2d_tile_t *ptTile; //!< target tile
909 const arm_2d_region_t *ptRegion; //!< target region
910 } Target;
911 struct {
912 const arm_2d_tile_t *ptTile; //!< the dummy source tile
913 }Source;
914 uint32_t wMode;
915 struct {
916 const arm_2d_tile_t *ptTile; //!< the origin tile
917 arm_2d_tile_t tDummySource; //!< the buffer for the source
918 }Origin;
919
920 /* derived part */
921 struct {
922 const arm_2d_tile_t *ptOriginSide; //!< origin side mask
923 const arm_2d_tile_t *ptTargetSide; //!< target side mask
924 } Mask;
926
927
928/*----------------------------------------------------------------------------*
929 * Fast Rotation linear regression structure
930 *----------------------------------------------------------------------------*/
931
932#if (__ARM_2D_HAS_HELIUM_FLOAT__ || __ARM_2D_HAS_FPU__) \
933 && !__ARM_2D_CFG_FORCED_FIXED_POINT_TRANSFORM__
934/*!
935 * \brief a type for parameters of linear interpolation (in floating point)
936 *
937 */
938typedef struct arm_2d_rot_linear_regr_t {
939 float slopeY;
940 float interceptY;
941 float slopeX;
942 float interceptX;
944
945#else
946/*!
947 * \brief a type for parameters of linear interpolation (in fixed point)
948 *
949 */
951 int32_t slopeY;
952 int32_t interceptY;
953 int32_t slopeX;
954 int32_t interceptX;
956
957#endif
958
959/*============================ GLOBAL VARIABLES ==============================*/
960/*============================ PROTOTYPES ====================================*/
961
962/*! @} */
963
964#if defined(__clang__)
965#pragma clang diagnostic pop
966#elif __IS_COMPILER_ARM_COMPILER_5__
967#pragma diag_warning 64
968#elif __IS_COMPILER_GCC__
969#pragma GCC diagnostic pop
970#endif
971
972#ifdef __cplusplus
973}
974#endif
975
976#endif // __ARM_2D_TYPES_H__
977
978