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: 17. May 2024
25 * $Revision: V.1.2.8
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#include <inttypes.h>
40
41#include "arm_2d_features.h"
42#include "arm_2d_utils.h"
43#include "__arm_2d_math.h"
44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
49#if defined(__clang__)
50# pragma clang diagnostic push
51# pragma clang diagnostic ignored "-Wunknown-warning-option"
52# pragma clang diagnostic ignored "-Wreserved-identifier"
53# pragma clang diagnostic ignored "-Wmissing-declarations"
54# pragma clang diagnostic ignored "-Wpadded"
55# pragma clang diagnostic ignored "-Wc11-extensions"
56# pragma clang diagnostic ignored "-Wembedded-directive"
57#elif __IS_COMPILER_ARM_COMPILER_5__
58# pragma diag_suppress 64
59#elif __IS_COMPILER_GCC__
60# pragma GCC diagnostic push
61# pragma GCC diagnostic ignored "-Wmissing-declarations"
62# pragma GCC diagnostic ignored "-Wpadded"
63#endif
64
65/*!
66 * \addtogroup gKernel 1 Kernel
67 * @{
68 */
69
70/*============================ MACROS ========================================*/
71
72/* A patch for GCC support */
73#if defined(__IS_COMPILER_GCC__) && __IS_COMPILER_GCC__ && __ARM_2D_HAS_HELIUM__
74
75# if (__GNUC__ > 13) || \
76 (__GNUC__ == 13 && __GNUC_MINOR__ > 2) || \
77 (__GNUC__ == 13 && __GNUC_MINOR__ == 2 && __GNUC_PATCHLEVEL__ >= 1)
78
79 /* require minimal gcc version: 13.2 rel1 */
80# ifndef __ARM_2D_SUPPRESS_GCC_HELIUM_PERFORMANCE_WARNING__
81# pragma GCC warning "GCC only has basic support for Helium and its\
82 performance might highly like disappoint you,You can define a macro\
83 __ARM_2D_SUPPRESS_GCC_HELIUM_PERFORMANCE_WARNING__ to suppress this warning."
84# endif
85
86# ifndef USE_MVE_INTRINSICS
87# define USE_MVE_INTRINSICS
88# endif
89
90# else
91 /* the gcc version is too low to support helium well */
92# ifndef __ARM_2D_SUPPRESS_GCC_HELIUM_PATCH_WARNING__
93# pragma GCC warning "As GCC has compilation issues for supporting Helium,\
94 the scalar version is used. You can define a macro\
95 __ARM_2D_SUPPRESS_GCC_HELIUM_PATCH_WARNING__ to suppress this warning."
96# endif
97
98# undef __ARM_2D_HAS_HELIUM__
99# undef __ARM_2D_HAS_HELIUM_INTEGER__
100# undef __ARM_2D_HAS_HELIUM_FLOAT__
101
102# define __ARM_2D_HAS_HELIUM__ 0 //!< target MCU has no Helium extension
103# define __ARM_2D_HAS_HELIUM_INTEGER__ 0 //!< target MCU has no Helium integer extension
104# define __ARM_2D_HAS_HELIUM_FLOAT__ 0 //!< target MCU has no Helium floating point extension
105
106# endif
107
108#endif
109
110#if defined(__IS_COMPILER_IAR__) && __IS_COMPILER_IAR__
111# ifndef USE_MVE_INTRINSICS
112# define USE_MVE_INTRINSICS
113# endif
114#endif
115
116
117
118/*============================ MACROFIED FUNCTIONS ===========================*/
119/*============================ TYPES =========================================*/
120
121
122/*----------------------------------------------------------------------------*
123 * Infrastructure *
124 *----------------------------------------------------------------------------*/
125
126/*!
127 * \brief finite-state-machine status return (Compatible with arm_status, minimal integer: int8_t)
128 *
129 */
130typedef enum {
131 arm_fsm_rt_err = -1, //!< fsm error
132 arm_fsm_rt_cpl = 0, //!< fsm complete
133 arm_fsm_rt_on_going = 1, //!< fsm on-going
134 arm_fsm_rt_wait_for_obj = 2, //!< fsm wait for IPC object
135 arm_fsm_rt_async = 3, //!< fsm work asynchronously, please check it later.
136 arm_fsm_rt_wait_for_res = 4, //!< wait for resource
138
139/*!
140 * \brief the error code for arm-2d (minimal integer: int8_t)
141 *
142 */
143typedef enum {
144 ARM_2D_ERR_INVALID_STATUS = -13, //!< the target service is in an invalid status for an API
145 ARM_2D_ERR_NOT_AVAILABLE = -12, //!< service is not available or not initialissed
146 ARM_2D_ERR_UNSUPPORTED_COLOUR = -11, //!< the specified colour is not supported
147 ARM_2D_ERR_BUSY = -10, //!< service is busy
148 ARM_2D_ERR_INSUFFICIENT_RESOURCE = -9, //!< insufficient resource
149 ARM_2D_ERR_IO_BUSY = -8, //!< HW accelerator is busy
150 ARM_2D_ERR_IO_ERROR = -7, //!< Generic HW error
151 ARM_2D_ERR_MISSING_PARAM = -6, //!< missing mandatory parameter
152 ARM_2D_ERR_INVALID_OP = -5, //!< unsupported / invalid operation
153 ARM_2D_ERR_NOT_SUPPORT = -4, //!< feature/service/operation is not supported
154 ARM_2D_ERR_OUT_OF_REGION = -3, //!< the operation is out of target area
155 ARM_2D_ERR_INVALID_PARAM = -2, //!< invalid parameter
156 ARM_2D_ERR_UNKNOWN = -1, //!< generic or unknown errors
157 ARM_2D_ERR_NONE = 0, //!< no error
159
160/*!
161 * \brief comparison result
162 *
163 */
164typedef enum {
165 ARM_2D_CMP_SMALLER = -1, //!< the target is smaller than the reference
166 ARM_2D_CMP_EQUALS = 0, //!< the target is equal to the reference
167 ARM_2D_CMP_LARGER = 1, //!< the target is larger than the reference
169
170/*----------------------------------------------------------------------------*
171 * Colour definitions *
172 *----------------------------------------------------------------------------*/
173
174/*!
175 * \brief the colour type for gray8 (8bit gray scale)
176 *
177 */
178typedef struct arm_2d_color_gray8_t {
179 uint8_t tValue;
181
182/*!
183 * \brief the colour type for rgb565
184 *
185 */
187 uint16_t tValue;
188 struct {
189 uint16_t u5B : 5;
190 uint16_t u6G : 6;
191 uint16_t u5R : 5;
192 };
194
195/*!
196 * \brief the colour type for brga8888
197 *
198 * \details In most cases four equal-sized pieces of adjacent memory are used,
199 * one for each channel, and a 0 in a channel indicates black color or
200 * transparent alpha, while all-1 bits indicates white or fully opaque
201 * alpha. By far the most common format is to store 8 bits (one byte)
202 * for each channel, which is 32 bits for each pixel.
203 *
204 * (source: https://en.wikipedia.org/wiki/RGBA_color_model#ARGB32)
205 */
207 uint32_t tValue;
208 uint8_t chChannel[4];
209 struct {
210 uint32_t u8B : 8;
211 uint32_t u8G : 8;
212 uint32_t u8R : 8;
213 uint32_t u8A : 8;
214 };
216
217/*!
218 * \brief the colour type for rgb888 (compliant with ccca888 and bgra8888)
219 *
220 * \details In most cases four equal-sized pieces of adjacent memory are used,
221 * one for each channel, and a 0 in a channel indicates black color or
222 * transparent alpha, while all-1 bits indicates white or fully opaque
223 * alpha. By far the most common format is to store 8 bits (one byte)
224 * for each channel, which is 32 bits for each pixel.
225 *
226 * (source: https://en.wikipedia.org/wiki/RGBA_color_model#ARGB32)
227 */
229 uint32_t tValue;
230 struct {
231 uint32_t u8B : 8;
232 uint32_t u8G : 8;
233 uint32_t u8R : 8;
234 uint32_t : 8;
235 };
237
238/*!
239 * \brief the colour type for any 32bit colour formats which has an alpha channel on its 3rd byte.
240 *
241 * \details In most cases four equal-sized pieces of adjacent memory are used,
242 * one for each channel, and a 0 in a channel indicates black color or
243 * transparent alpha, while all-1 bits indicates white or fully opaque
244 * alpha. By far the most common format is to store 8 bits (one byte)
245 * for each channel, which is 32 bits for each pixel.
246 *
247 * (source: https://en.wikipedia.org/wiki/RGBA_color_model#ARGB32)
248 */
250 uint32_t tValue;
251 struct {
252 uint8_t u8C[3];
253 uint8_t u8A;
254 };
256
257/*!
258 * \brief the colour type for any 32bit colour formats which has an alpha channel on its first byte.
259 *
260 * \details In most cases four equal-sized pieces of adjacent memory are used,
261 * one for each channel, and a 0 in a channel indicates black color or
262 * transparent alpha, while all-1 bits indicates white or fully opaque
263 * alpha. By far the most common format is to store 8 bits (one byte)
264 * for each channel, which is 32 bits for each pixel.
265 *
266 * (source: https://en.wikipedia.org/wiki/RGBA_color_model#ARGB32)
267 */
269 uint32_t tValue;
270 struct {
271 uint8_t u8A;
272 uint8_t u8C[3];
273 };
275
276/*!
277 * \brief the colour type for any 32bit colour formats which has an unused-alpha channel on its 3rd byte.
278 *
279 * \details In most cases four equal-sized pieces of adjacent memory are used,
280 * one for each channel, and a 0 in a channel indicates black color or
281 * transparent alpha, while all-1 bits indicates white or fully opaque
282 * alpha. By far the most common format is to store 8 bits (one byte)
283 * for each channel, which is 32 bits for each pixel.
284 *
285 * (source: https://en.wikipedia.org/wiki/RGBA_color_model#ARGB32)
286 */
288 uint32_t tValue;
289 struct {
290 uint8_t u8C[3];
291 uint8_t : 8;
292 };
294
295/*!
296 * \brief the colour type for any 32bit colour formats which has an unused-alpha channel on its first byte.
297 *
298 * \details In most cases four equal-sized pieces of adjacent memory are used,
299 * one for each channel, and a 0 in a channel indicates black color or
300 * transparent alpha, while all-1 bits indicates white or fully opaque
301 * alpha. By far the most common format is to store 8 bits (one byte)
302 * for each channel, which is 32 bits for each pixel.
303 *
304 * (source: https://en.wikipedia.org/wiki/RGBA_color_model#ARGB32)
305 */
307 uint32_t tValue;
308 struct {
309 uint8_t : 8;
310 uint8_t u8C[3];
311 };
313
314
315/*!
316 * \brief the generic type to hold a colour
317 *
318 */
319typedef union arm_2d_colour_t {
320
321 uint32_t wColour;
322 uint16_t hwColour;
323 uint8_t chColour;
324
333
335
336/*!
337 * \brief enumerations for colour attributes
338 */
339enum {
340 ARM_2D_COLOUR_SZ_1BIT = 0, //!< 1 bit:black and white
341 ARM_2D_COLOUR_SZ_2BIT = 1, //!< 4 colours or 4 gray-levels
342 ARM_2D_COLOUR_SZ_4BIT = 2, //!< 16 colours or 16 gray-levels
343 ARM_2D_COLOUR_SZ_8BIT = 3, //!< 256 colours
344 ARM_2D_COLOUR_SZ_16BIT = 4, //!< 16bits
345 ARM_2D_COLOUR_SZ_32BIT = 5, //!< true colour (32bit)
346 ARM_2D_COLOUR_SZ_24BIT = 6, //!< true colour (24bit)
347
348 ARM_2D_COLOUR_SZ_1BIT_msk = ARM_2D_COLOUR_SZ_1BIT << 1,
349 ARM_2D_COLOUR_SZ_2BIT_msk = ARM_2D_COLOUR_SZ_2BIT << 1,
350 ARM_2D_COLOUR_SZ_4BIT_msk = ARM_2D_COLOUR_SZ_4BIT << 1,
351 ARM_2D_COLOUR_SZ_8BIT_msk = ARM_2D_COLOUR_SZ_8BIT << 1,
352 ARM_2D_COLOUR_SZ_16BIT_msk = ARM_2D_COLOUR_SZ_16BIT<< 1,
353 ARM_2D_COLOUR_SZ_32BIT_msk = ARM_2D_COLOUR_SZ_32BIT<< 1,
354 ARM_2D_COLOUR_SZ_24BIT_msk = ARM_2D_COLOUR_SZ_24BIT<< 1,
355 ARM_2D_COLOUR_SZ_msk = (0x07 << 1),
356
357 ARM_2D_COLOUR_LITTLE_ENDIAN = 0,
358 ARM_2D_COLOUR_BIG_ENDIAN = 1,
359
360 ARM_2D_COLOUR_LITTLE_ENDIAN_msk = ARM_2D_COLOUR_LITTLE_ENDIAN << 4,
361 ARM_2D_COLOUR_BIG_ENDIAN_msk = ARM_2D_COLOUR_BIG_ENDIAN << 4,
362
363 ARM_2D_COLOUR_NO_ALPHA = 0,
364 ARM_2D_COLOUR_HAS_ALPHA = 1,
365
366 ARM_2D_COLOUR_NO_ALPHA_msk = ARM_2D_COLOUR_NO_ALPHA << 0,
367 ARM_2D_COLOUR_HAS_ALPHA_msk = ARM_2D_COLOUR_HAS_ALPHA << 0,
368
369 ARM_2D_COLOUR_VARIANT_pos = 5,
370 ARM_2D_COLOUR_VARIANT_msk = 0x07 << ARM_2D_COLOUR_VARIANT_pos,
371};
372
373/* macros for colour attributes */
374#define ARM_2D_M_COLOUR_SZ_1BIT 0 //!< 1 bit:black and white
375#define ARM_2D_M_COLOUR_SZ_2BIT 1 //!< 4 colours or 4 gray-levels
376#define ARM_2D_M_COLOUR_SZ_4BIT 2 //!< 16 colours or 16 gray-levels
377#define ARM_2D_M_COLOUR_SZ_8BIT 3 //!< 256 colours
378#define ARM_2D_M_COLOUR_SZ_16BIT 4 //!< 16bits
379#define ARM_2D_M_COLOUR_SZ_32BIT 5 //!< true colour
380#define ARM_2D_M_COLOUR_SZ_24BIT 6 //!< true colour
381
382#define ARM_2D_M_COLOUR_SZ_1BIT_msk (ARM_2D_M_COLOUR_SZ_1BIT << 1) //!< bitmask for 1bit colour formats
383#define ARM_2D_M_COLOUR_SZ_2BIT_msk (ARM_2D_M_COLOUR_SZ_2BIT << 1) //!< bitmask for 2bit colour formats
384#define ARM_2D_M_COLOUR_SZ_4BIT_msk (ARM_2D_M_COLOUR_SZ_4BIT << 1) //!< bitmask for 4bit colour formats
385#define ARM_2D_M_COLOUR_SZ_8BIT_msk (ARM_2D_M_COLOUR_SZ_8BIT << 1) //!< bitmask for 8bit colour formats
386#define ARM_2D_M_COLOUR_SZ_16BIT_msk (ARM_2D_M_COLOUR_SZ_16BIT<< 1) //!< bitmask for 16bit colour formats
387#define ARM_2D_M_COLOUR_SZ_32BIT_msk (ARM_2D_M_COLOUR_SZ_32BIT<< 1) //!< bitmask for 32bit colour formats
388#define ARM_2D_M_COLOUR_SZ_24BIT_msk (ARM_2D_M_COLOUR_SZ_24BIT<< 1) //!< bitmask for 24bit colour formats
389#define ARM_2D_M_COLOUR_SZ_msk (0x07 << 1), //!< bitmask for the SZ bitfield
390
391#define ARM_2D_M_COLOUR_LITTLE_ENDIAN 0 //!< pixels are stored in little endian
392#define ARM_2D_M_COLOUR_BIG_ENDIAN 1 //!< pixels are stored big endian
393
394#define ARM_2D_M_COLOUR_LITTLE_ENDIAN_msk (ARM_2D_M_COLOUR_LITTLE_ENDIAN << 4)//!< bitmask for little-endian
395#define ARM_2D_M_COLOUR_BIG_ENDIAN_msk (ARM_2D_M_COLOUR_BIG_ENDIAN << 4)//!< bitmask for big-endian
396
397#define ARM_2D_M_COLOUR_NO_ALPHA 0 //!< there is no alpha channel in each pixel
398#define ARM_2D_M_COLOUR_HAS_ALPHA 1 //!< there is an alpha channel in each pixel
399
400#define ARM_2D_M_COLOUR_NO_ALPHA_msk (ARM_2D_M_COLOUR_NO_ALPHA << 0) //!< bitmask for no-alpha-channel-in-pixel
401#define ARM_2D_M_COLOUR_HAS_ALPHA_msk (ARM_2D_M_COLOUR_HAS_ALPHA << 0) //!< bitmask for has-alpha-channel-in-pixel
402
403#define ARM_2D_M_COLOUR_VARIANT_pos 5 //!< offset for the VARIANT bitfield
404#define ARM_2D_M_COLOUR_VARIANT_msk (0x07<<ARM_2D_M_COLOUR_VARIANT_pos) //!< bitmask for the VARIANT bitfield
405
406/*!
407 * \brief enumerations for colour types
408 *
409 */
410enum {
411 ARM_2D_COLOUR_MONOCHROME = ARM_2D_COLOUR_SZ_1BIT_msk,
412 ARM_2D_COLOUR_BIN = ARM_2D_COLOUR_SZ_1BIT_msk,
413 ARM_2D_COLOUR_1BIT = ARM_2D_COLOUR_SZ_1BIT_msk,
414
415 ARM_2D_COLOUR_MASK_A2 = ARM_2D_M_COLOUR_SZ_2BIT_msk,
416 ARM_2D_COLOUR_MASK_A4 = ARM_2D_M_COLOUR_SZ_4BIT_msk,
417
418 ARM_2D_COLOUR_2BIT = ARM_2D_M_COLOUR_SZ_2BIT_msk,
419 ARM_2D_COLOUR_4BIT = ARM_2D_M_COLOUR_SZ_4BIT_msk,
420
421 ARM_2D_COLOUR_8BIT = ARM_2D_COLOUR_SZ_8BIT_msk,
422 ARM_2D_COLOUR_GRAY8 = ARM_2D_COLOUR_SZ_8BIT_msk,
423 ARM_2D_COLOUR_MASK_A8 = ARM_2D_COLOUR_SZ_8BIT_msk,
424
425 ARM_2D_COLOUR_16BIT = ARM_2D_COLOUR_SZ_16BIT_msk,
426 ARM_2D_COLOUR_RGB16 = ARM_2D_COLOUR_SZ_16BIT_msk,
427 ARM_2D_COLOUR_RGB565 = ARM_2D_COLOUR_RGB16,
428
429/* won't support
430 ARM_2D_COLOUR_RGB565_BE = ARM_2D_COLOUR_SZ_16BIT_msk |
431 ARM_2D_COLOUR_BIG_ENDIAN_msk ,
432 */
433
434 ARM_2D_COLOUR_24BIT = ARM_2D_COLOUR_SZ_24BIT_msk , /* not supported yet */
435 ARM_2D_COLOUR_RGB24 = ARM_2D_COLOUR_SZ_24BIT_msk , /* not supported yet */
436
437 ARM_2D_COLOUR_32BIT = ARM_2D_COLOUR_SZ_32BIT_msk ,
438 ARM_2D_COLOUR_RGB32 = ARM_2D_COLOUR_SZ_32BIT_msk ,
439
440 ARM_2D_COLOUR_CCCN888 = ARM_2D_COLOUR_RGB32 ,
441 ARM_2D_COLOUR_CCCA8888 = ARM_2D_COLOUR_SZ_32BIT_msk |
442 ARM_2D_COLOUR_HAS_ALPHA_msk ,
443
444 ARM_2D_COLOUR_RGB888 = ARM_2D_COLOUR_CCCN888 ,
445 ARM_2D_COLOUR_BGRA8888 = ARM_2D_COLOUR_CCCA8888 ,
446
447/* not supported yet
448 ARM_2D_COLOUR_NCCC888 = ARM_2D_COLOUR_RGB32 |
449 ARM_2D_COLOUR_BIG_ENDIAN_msk ,
450 ARM_2D_COLOUR_ACCC8888 = ARM_2D_COLOUR_SZ_32BIT_msk |
451 ARM_2D_COLOUR_HAS_ALPHA_msk |
452 ARM_2D_COLOUR_BIG_ENDIAN_msk ,
453*/
454
455 ARM_2D_CHANNEL_8in32 = ARM_2D_COLOUR_SZ_32BIT_msk |
456 ARM_2D_COLOUR_HAS_ALPHA_msk |
457 ARM_2D_COLOUR_VARIANT_msk ,
458};
459
460/* macros for colour formats */
461#define ARM_2D_M_COLOUR_MONOCHROME ARM_2D_M_COLOUR_SZ_1BIT_msk //!< macro for the monochrome
462#define ARM_2D_M_COLOUR_BIN ARM_2D_M_COLOUR_SZ_1BIT_msk //!< macro for the 1bit colour format (alias)
463#define ARM_2D_M_COLOUR_1BIT ARM_2D_M_COLOUR_SZ_1BIT_msk //!< macro for the 1bin colour format (alias)
464
465#define ARM_2D_M_COLOUR_MASK_A2 ARM_2D_M_COLOUR_SZ_2BIT_msk //!< macro for the 2bit alpha mask
466#define ARM_2D_M_COLOUR_MASK_A4 ARM_2D_M_COLOUR_SZ_4BIT_msk //!< macro for the 4bit alpha mask
467
468#define ARM_2D_M_COLOUR_8BIT ARM_2D_M_COLOUR_SZ_8BIT_msk //!< macro for the generic 8bit colour formats
469#define ARM_2D_M_COLOUR_GRAY8 ARM_2D_M_COLOUR_SZ_8BIT_msk //!< macro for the gray8 colour format
470#define ARM_2D_M_COLOUR_MASK_A8 ARM_2D_M_COLOUR_SZ_8BIT_msk //!< macro for the 8bit alpha mask
471
472#define ARM_2D_M_COLOUR_16BIT ARM_2D_M_COLOUR_SZ_16BIT_msk //!< macro for the generic 16bit colour formats
473#define ARM_2D_M_COLOUR_RGB16 ARM_2D_M_COLOUR_SZ_16BIT_msk //!< macro for the generic 16bit colour formats
474#define ARM_2D_M_COLOUR_RGB565 ARM_2D_M_COLOUR_RGB16 //!< macro for the rgb565
475
476/* won't support
477#define ARM_2D_M_COLOUR_RGB565_BE ( ARM_2D_M_COLOUR_SZ_16BIT_msk \
478 | ARM_2D_M_COLOUR_BIG_ENDIAN_msk )
479 */
480
481#define ARM_2D_M_COLOUR_24BIT ARM_2D_M_COLOUR_SZ_24BIT_msk //!< macro for the generic 24bit colour formats
482#define ARM_2D_M_COLOUR_RGB24 ARM_2D_M_COLOUR_SZ_24BIT_msk //!< macro for the generic 24bit colour formats
483
484#define ARM_2D_M_COLOUR_32BIT ARM_2D_M_COLOUR_SZ_32BIT_msk //!< macro for the generic 32bit colour formats
485#define ARM_2D_M_COLOUR_RGB32 ARM_2D_M_COLOUR_SZ_32BIT_msk //!< macro for the generic 32bit colour formats
486
487#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
488
489/*! macro for the generic 32bit colour formats with an alpha channel at the highest byte */
490#define ARM_2D_M_COLOUR_CCCA8888 ( ARM_2D_M_COLOUR_SZ_32BIT_msk \
491 | ARM_2D_M_COLOUR_HAS_ALPHA_msk)
492
493#define ARM_2D_M_COLOUR_RGBX888 ARM_2D_M_COLOUR_CCCN888 //!< macro for the RGB888 (BGRN8888)
494#define ARM_2D_M_COLOUR_BGRA8888 ARM_2D_M_COLOUR_CCCA8888 //!< macro for the BGRA8888
495
496/* not supported yet
497#define ARM_2D_M_COLOUR_NCCC888 ( ARM_2D_M_COLOUR_RGB32 \
498 | ARM_2D_M_COLOUR_BIG_ENDIAN_msk )
499#define ARM_2D_M_COLOUR_ACCC8888 ( ARM_2D_M_COLOUR_SZ_32BIT_msk \
500 | ARM_2D_M_COLOUR_HAS_ALPHA_msk \
501 | ARM_2D_M_COLOUR_BIG_ENDIAN_msk )
502*/
503/*! macro for a special colour format which access only one channel in RGB32 */
504#define ARM_2D_M_CHANNEL_8in32 ( ARM_2D_M_COLOUR_SZ_32BIT_msk \
505 | ARM_2D_M_COLOUR_HAS_ALPHA_msk) \
506 | ARM_2D_M_COLOUR_VARIANT_msk )
507
508/*!
509 * \brief a type used as colour descriptor
510 *
511 */
512typedef union {
513 struct {
514 uint8_t bHasAlpha : 1; //!< whether the target colour has alpha channel
515 uint8_t u3ColourSZ : 3; //!< the size of the colour
516 uint8_t bBigEndian : 1; //!< whether the colour is stored in big endian
517 uint8_t u2Variant : 2;
518 uint8_t : 1;
519 };
520 struct {
521 uint8_t u7ColourFormat : 7;
522 uint8_t : 1;
523 };
524 uint8_t chScheme;
526
527/*----------------------------------------------------------------------------*
528 * Tile and Regions *
529 *----------------------------------------------------------------------------*/
530
531/*!
532 * \brief a type for coordinates (integer)
533 *
534 */
535typedef struct arm_2d_location_t {
536 int16_t iX; //!< x in Cartesian coordinate system
537 int16_t iY; //!< y in Cartesian coordinate system
539
540/*!
541 * \brief a type for coordinates in floating point
542 *
543 */
544typedef struct arm_2d_point_float_t {
545 float fX; //!< x in Cartesian coordinate system
546 float fY; //!< y in Cartesian coordinate system
548
549/*!
550 * \brief a type for coordinates in fixed point
551 *
552 */
553typedef struct arm_2d_point_fx_t {
554 int32_t X; //!< x in Cartesian coordinate system
555 int32_t Y; //!< y in Cartesian coordinate system
557
558/*!
559 * \brief a type for the size of an rectangular area
560 *
561 */
562typedef struct arm_2d_size_t {
563 int16_t iWidth; //!< width of an rectangular area
564 int16_t iHeight; //!< height of an rectangular area
566
567/*!
568 * \brief a type for an rectangular area
569 *
570 */
571typedef struct arm_2d_region_t {
572 implement_ex(arm_2d_location_t, tLocation); //!< the location (top-left corner)
573 implement_ex(arm_2d_size_t, tSize); //!< the size
575
576/*!
577 * \brief the tile extension ID
578 *
579 */
580enum {
581 ARM_2D_TILE_EXTENSION_NONE = 0, //!< no extension in the tile.tInfo.Extension field
582 ARM_2D_TILE_EXTENSION_PFB, //!< contains PFB extension information
583};
584
585/*!
586 * \brief a type for tile
587 *
588 */
589typedef struct arm_2d_tile_t arm_2d_tile_t;
591 implement_ex(struct {
592 uint8_t bIsRoot : 1; //!< is this tile a root tile
593 uint8_t bHasEnforcedColour : 1; //!< does this tile contains enforced colour info
594 uint8_t bDerivedResource : 1; //!< indicate whether this is a derived resources (when bIsRoot == 0)
595 uint8_t bVirtualResource : 1; //!< indicate whether the resource should be loaded on-demand
596 uint8_t bVirtualScreen : 1; //!< DO NOT USE! indicate whether the tile is considered as the virtual screen, it is used in dirty region calculation
597 uint8_t u3ExtensionID : 3; //!< Tile Extension ID
598 arm_2d_color_info_t tColourInfo; //!< enforced colour
599
600 union {
601 uint16_t : 16;
602 struct {
603 uint8_t bIsNewFrame : 1;
604 uint8_t bIsDryRun : 1;
605 }PFB;
606 } Extension;
607
608 }, tInfo);
609
610 implement_ex(arm_2d_region_t, tRegion); //!< the region of the tile
611
612 union {
613 /* when bIsRoot is true, phwBuffer is available,
614 * otherwise ptParent is available
615 */
616 arm_2d_tile_t *ptParent; //!< a pointer points to the parent tile
617 uint8_t *pchBuffer; //!< a pointer points to a buffer in a 8bit colour type
618 uint16_t *phwBuffer; //!< a pointer points to a buffer in a 16bit colour type
619 uint32_t *pwBuffer; //!< a pointer points to a buffer in a 32bit colour type
620
621 intptr_t nAddress; //!< a pointer in integer
622 };
623};
624
625/*----------------------------------------------------------------------------*
626 * Misc *
627 *----------------------------------------------------------------------------*/
628
629/*!
630 * \brief alignment
631 */
632typedef enum {
633 ARM_2D_ALIGN_LEFT = _BV(0), /*!< align to left */
634 ARM_2D_ALIGN_RIGHT = _BV(1), /*!< align to right */
635 ARM_2D_ALIGN_TOP = _BV(2), /*!< align to top */
636 ARM_2D_ALIGN_BOTTOM = _BV(3), /*!< align to bottom */
637
638 ARM_2D_ALIGN_CENTRE = 0, /*!< align to centre */
639 ARM_2D_ALIGN_CENTRE_ALIAS = ARM_2D_ALIGN_LEFT /*!< align to centre */
643
644 ARM_2D_ALIGN_TOP_LEFT = ARM_2D_ALIGN_TOP /*!< align to top left corner */
646 ARM_2D_ALIGN_TOP_RIGHT = ARM_2D_ALIGN_TOP /*!< align to top right corner */
648 ARM_2D_ALIGN_BOTTOM_LEFT = ARM_2D_ALIGN_BOTTOM /*!< align to bottom left corner */
650 ARM_2D_ALIGN_BOTTOM_RIGHT = ARM_2D_ALIGN_BOTTOM /*!< align to bottom right corner */
653
654/*!
655 * \brief the margin inside a region / container
656 */
657typedef struct arm_2d_margin_t {
658 uint8_t chLeft; /*!< left margin */
659 uint8_t chRight; /*!< right margin */
660 uint8_t chTop; /*!< top margin */
661 uint8_t chBottom; /*!< bottom margin */
663
664/*!
665 * \brief the padding between rectanglar areas
666 */
667typedef struct arm_2d_padding_t {
668 int8_t chLeft; /*!< left padding */
669 int8_t chRight; /*!< right padding */
670 int8_t chTop; /*!< top padding */
671 int8_t chBottom; /*!< bottom padding */
673
674/*!
675 * \brief the enumeration type for describing memory types
676 *
677 */
678typedef enum {
679 ARM_2D_MEM_TYPE_UNSPECIFIED, //!< normal memory, we don't know its characterisics
680 ARM_2D_MEM_TYPE_SLOW, //!< for slow memories, such as SDRAM, DDRAM, external memory etc
681 ARM_2D_MEM_TYPE_FAST, //!< for fast memories, such as TCM, SRAM etc.
683
684typedef union __arm_2d_mem_info_t {
685 struct {
686 uint32_t u24SizeInByte : 24; //!< the memory size in Byte
687 uint32_t u2ItemSize : 3; //!< the size of the data item
688 uint32_t u2Align : 3; //!< the alignment
689 uint32_t u2Type : 2; //!< The memory type define in enum arm_2d_mem_type_t
690 };
691 uint32_t Value; //!< Memory Information
693
694/*!
695 * \brief scratch memory descriptor
696 * \note "manually" derived from __arm_2d_mem_info_t
697 */
698typedef struct arm_2d_scratch_mem_t {
699 implement_ex(union {
700 struct {
701 uint32_t u24SizeInByte : 24; //!< the memory size in Byte
702 uint32_t u2ItemSize : 3; //!< the size of the data item
703 uint32_t u2Align : 3; //!< the alignment
704 uint32_t u2Type : 2; //!< The memory type define in enum arm_2d_mem_type_t
705 };
706 uint32_t Value; //!< Memory Information
707 }, tInfo);
708
709 uintptr_t pBuffer;
711
712/*!
713 * \brief a type for scratch memory blocks
714 *
715 */
716typedef struct __arm_2d_mem_t __arm_2d_mem_t;
718 union {
719 __arm_2d_mem_t *ptNext; //!< a list pointer
720 uint32_t wSignature; //!< a signature for validation
721 };
722 __arm_2d_mem_info_t tInfo; //!< memory info
723 uint8_t pBuffer[]; //!< a constant pointer points to the buffer following this header
724};
725
726
727/*!
728 * \brief a type for virtual resource
729 *
730 * \note the flag tTile.tInfo.bVirtualResource must be true (1)
731 */
732typedef struct arm_2d_vres_t arm_2d_vres_t;
734
735 /*! base class: tTile */
737
738 /*! a reference of an user object */
739 uintptr_t pTarget;
740
741 /*!
742 * \brief a method to load a specific part of an image
743 * \param[in] pTarget a reference of an user object
744 * \param[in] ptVRES a reference of this virtual resource
745 * \param[in] ptRegion the target region of the image
746 * \return intptr_t the address of a resource buffer which holds the content
747 */
748 intptr_t (*Load) ( uintptr_t pTarget,
749 arm_2d_vres_t *ptVRES,
750 arm_2d_region_t *ptRegion);
751
752 /*!
753 * \brief a method to despose the buffer
754 * \param[in] pTarget a reference of an user object
755 * \param[in] ptVRES a reference of this virtual resource
756 * \param[in] pBuffer the target buffer
757 */
758 void (*Depose) ( uintptr_t pTarget,
759 arm_2d_vres_t *ptVRES,
760 intptr_t pBuffer );
761};
762
763/*----------------------------------------------------------------------------*
764 * Task *
765 *----------------------------------------------------------------------------*/
766
767/*!
768 * \brief arm-2d application level task control block
769 *
770 */
771typedef struct arm_2d_task_t {
772ARM_PRIVATE(
773 arm_fsm_rt_t tResult; //!< the temporary result of the task
774 uint8_t chState; //!< the state of the FSM
775
776 void *ptTask; //!< a pointer for an internal object
779
780/*----------------------------------------------------------------------------*
781 * Operation and Events Handling *
782 *----------------------------------------------------------------------------*/
783
784
786
787/*!
788 * \brief a prototype of event handlers for 2D operations
789 *
790 * \param[in] ptThisOP the target 2D operation descriptor
791 * \param[in] tResult the operation result
792 * \param[in] pTarget A user attached object
793 * \return bool a boolean value to indicate whether the event has been handled
794 */
796 arm_fsm_rt_t tResult,
797 void *pTarget);
798
799/*!
800 * \brief a type for 2D operation event handling
801 *
802 */
803typedef struct arm_2d_op_evt_t {
805 void *pTarget; //!< user attached target
807
808/*!
809 * \brief a prototype for generic event handlers
810 *
811 * \param pTarget A user attached object
812 * \return bool a boolean value to indicate whether the event has been handled
813 */
814typedef bool arm_2d_evt_handler_t(void *pTarget);
815
816/*!
817 * \brief a type for generic event handling
818 *
819 */
820typedef struct arm_2d_evt_t {
821 arm_2d_evt_handler_t *fnHandler; //!< event handler
822 void *pTarget; //!< user attached target
824
825
826#define ARM_2D_OP_INFO_PARAM_HAS_SOURCE _BV(0) //!< opcode has source tile info
827#define ARM_2D_OP_INFO_PARAM_HAS_TARGET _BV(1) //!< opcode has target tile info
828#define ARM_2D_OP_INFO_PARAM_HAS_SOURCE_MASK _BV(2) //!< opcode has source mask info
829#define ARM_2D_OP_INFO_PARAM_HAS_TARGET_MASK _BV(3) //!< opcode has target mask info
830#define ARM_2D_OP_INFO_PARAM_HAS_ORIGIN _BV(4) //!< opcode has original tile info
831
832/*! a bitmask for INFO_PARAM_HAS_xxxx bitfields */
833#define ARM_2D_OP_INFO_PARAM_TILES_MASK ( \
834 ARM_2D_OP_INFO_PARAM_HAS_SOURCE | \
835 ARM_2D_OP_INFO_PARAM_HAS_TARGET | \
836 ARM_2D_OP_INFO_PARAM_HAS_SOURCE_MASK | \
837 ARM_2D_OP_INFO_PARAM_HAS_TARGET_MASK | \
838 ARM_2D_OP_INFO_PARAM_HAS_ORIGIN )
839
840
841//! \brief an incomplete defintion which is only used for defining pointers
843
844/*!
845 * \brief A descriptive header for 2D operations
846 */
847typedef union __arm_2d_op_info_t {
848 struct {
849 arm_2d_color_info_t Colour; //!< the colour used in thie operation
850 union {
851 struct {
852 uint8_t bHasSource : 1; //!< whether this operation contains source tile
853 uint8_t bHasTarget : 1; //!< whether this operation contains target tile
854 uint8_t bHasSrcMask : 1; //!< whether this operation has Mask layer for source tile
855 uint8_t bHasDesMask : 1; //!< whether this operation has Mask layer for target tile
856 uint8_t bHasOrigin : 1; //!< whether the Source has an origin tile
857 uint8_t : 2;
858 uint8_t bAllowEnforcedColour : 1; //!< whether this operation allow enforced colours in tiles
859 };
860 uint8_t chValue; //!< feature value
861 }Param; //!< operation feature set
862
863 uint8_t chInClassOffset; //!< some operation uses this as the offset of the key member in the class
864 uint8_t chOpIndex; //!< __ARM_2D_OP_IDX_XXXXXX
865
866 union {
867 struct {
868 uint8_t CopyLike; //!< A copy-like interface contains the target tile, the source tile and the copy size
869 uint8_t FillLike; //!< A copy-like interface contains the target tile and the source tile
870 };
871 struct {
872 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
873 uint8_t FillOrigLike; //!< A copy-like interface contains the target tile, the dummy tile and the reference to the original source tile
874 };
875 struct {
876 uint8_t TileProcessLike; //!< A simple interface contains only the target tile
877 };
878 }LowLevelInterfaceIndex; //!< Low level interface index
879
880 union {
881 const __arm_2d_low_level_io_t *IO[2]; //!< array of IOs
882
883 struct {
884 const __arm_2d_low_level_io_t *ptCopyLike; //!< the function pointer for a copy-like implementation
885 const __arm_2d_low_level_io_t *ptFillLike; //!< the function pointer for a fill-like implementation
886 };
887 struct {
888 const __arm_2d_low_level_io_t *ptCopyOrigLike; //!< the function pointer for a copy-orig-like implementation
889 const __arm_2d_low_level_io_t *ptFillOrigLike; //!< the function pointer for a fill-orig-like implementation
890 };
891 struct {
892 const __arm_2d_low_level_io_t *ptTileProcessLike; //!< the function pointer for the tile-process-like implementation
893 };
894 }LowLevelIO; //!< low level IO definition
895
896 }Info; //!< operation description
897 uint32_t wID; //!< Operation ID
899
900/*!
901 * \brief how would you want to accelerate the 2d-operation
902 */
903enum {
904 //! Use hardware acceleration if possible, even if there is a long queue to wait
906
907 //! Only use Hardware Acceleration, if it is not supported, IO error will be issued
909
910 //! Only use software algorithm
912
913 //!< don't care, let the arm-2d library decide
914 ARM_2D_PREF_ACC_DONT_CARE = 3,
915};
916
917#define __ARM_2D_OP_STATUS_BUSY_msk (1 << 4) //!< bitmask for the busy flag
918#define __ARM_2D_OP_STATUS_IO_ERROR_msk (1 << 5) //!< bitmask for the IO error flag
919#define __ARM_2D_OP_STATUS_CPL_msk (1 << 6) //!< bitmask for the complete flag
920
921/*!
922 * \brief a type for 2D operation status
923 *
924 */
925typedef union arm_2d_op_status_t {
926 struct {
927 uint16_t u4SubTaskCount : 4; //!< sub task count
928 uint16_t bIsBusy : 1; //!< busy flag
929 uint16_t bIOError : 1; //!< HW IO Error
930 uint16_t bOpCpl : 1; //!< the whole operation complete
931 uint16_t : 9; //!< reserved
932 };
933 uint16_t tValue; //!< the host integer
935
936/*!
937 * \brief the abstract class of 2D operations
938 *
939 */
941ARM_PRIVATE(
942 arm_2d_op_core_t *ptNext; //!< a pointer for a single list
943
944 const __arm_2d_op_info_t *ptOp; //!< the pointer for the corresponding 2D operation description
945
946 struct {
947 uint8_t u2ACCMethods : 2; //!< acceleration Methods
948 uint8_t : 6; //!< reserved
949 }Preference;
950
951 int8_t tResult; //!< operation result
952 volatile arm_2d_op_status_t Status; //!< operation status
953
954 arm_2d_op_evt_t evt2DOpCpl; //!< operation-complete event
955
956#if __ARM_2D_HAS_ASYNC__
957 uintptr_t pSemaphore; //!< point to semaphore
958#endif
960
961 uintptr_t pUserParam; //!< user attached object
962};
963
964/*!
965 * \brief the base class for operations with only a target tile
966 * \note arm_2d_op_msk_t inherits from arm_2d_op_core_t
967 */
968typedef struct arm_2d_op_t {
970 struct {
971 const arm_2d_tile_t *ptTile; //!< target tile
972 const arm_2d_region_t *ptRegion; //!< target region
973 } Target;
975
976/*!
977 * \brief the base class for operations with a target tile and a target mask
978 * \note arm_2d_op_msk_t inherits from arm_2d_op_t
979 */
980typedef struct arm_2d_op_msk_t {
982 struct {
983 const arm_2d_tile_t *ptTile; //!< target tile
984 const arm_2d_region_t *ptRegion; //!< target region
985 } Target;
986
987 /* derived part */
988 struct {
989 const arm_2d_tile_t *ptTargetSide; //!< target mask tile
990 } Mask;
992
993/*!
994 * \brief the base class for operations with a target tile and a source tile
995 * \note arm_2d_op_src_t inherits from arm_2d_op_t
996 */
997typedef struct arm_2d_op_src_t {
999 struct {
1000 const arm_2d_tile_t *ptTile; //!< target tile
1001 const arm_2d_region_t *ptRegion; //!< target region
1002 } Target;
1003
1004 /* derived part */
1005 struct {
1006 const arm_2d_tile_t *ptTile; //!< source tile
1007 }Source;
1008 uint32_t wMode;
1010
1011/*!
1012 * \brief the base class for operations with a target tile, a source tile and masks
1013 * \note arm_2d_op_src_msk_t inherits from arm_2d_op_src_t
1014 */
1015typedef struct arm_2d_op_src_msk_t {
1017 struct {
1018 const arm_2d_tile_t *ptTile; //!< target tile
1019 const arm_2d_region_t *ptRegion; //!< target region
1020 } Target;
1021 struct {
1022 const arm_2d_tile_t *ptTile; //!< source tile
1023 }Source;
1024 uint32_t wMode;
1025
1026 /* derived part */
1027 struct {
1028 const arm_2d_tile_t *ptSourceSide; //!< source side mask
1029 const arm_2d_tile_t *ptTargetSide; //!< target side mask
1030 } Mask;
1032
1033/*!
1034 * \brief the base class for operations with a target tile, a source tile and masks
1035 * \note arm_2d_op_src_msk_opc_t inherits from arm_2d_op_src_msk_t
1036 */
1039 struct {
1040 const arm_2d_tile_t *ptTile; //!< target tile
1041 const arm_2d_region_t *ptRegion; //!< target region
1042 } Target;
1043 struct {
1044 const arm_2d_tile_t *ptTile; //!< source tile
1045 }Source;
1046 uint32_t wMode;
1047
1048 /* derived part */
1049 struct {
1050 const arm_2d_tile_t *ptSourceSide; //!< source side mask
1051 const arm_2d_tile_t *ptTargetSide; //!< target side mask
1052 } Mask;
1053
1054 uint8_t chOpacity; //!< opacity
1056
1057/*!
1058 * \brief the base class for operations with a target tile, a dummy tile and a reference to the original source tile
1059 * \note arm_2d_op_src_orig_t inherits from arm_2d_op_src_t
1060 */
1061typedef struct arm_2d_op_src_orig_t {
1063 struct {
1064 const arm_2d_tile_t *ptTile; //!< target tile
1065 const arm_2d_region_t *ptRegion; //!< target region
1066 } Target;
1067 struct {
1068 const arm_2d_tile_t *ptTile; //!< the dummy source tile
1069 }Source;
1070 uint32_t wMode;
1071
1072 /* derived part */
1073 struct {
1074 const arm_2d_tile_t *ptTile; //!< the origin tile
1075 arm_2d_tile_t tDummySource; //!< the buffer for the source
1076 }Origin;
1077
1079
1080/*!
1081 * \brief the base class for operations with a target tile, a dummy tile, a reference to the original source tile and masks
1082 * \note arm_2d_op_src_orig_msk_t inherits from arm_2d_op_src_orig_t
1083 */
1086 struct {
1087 const arm_2d_tile_t *ptTile; //!< target tile
1088 const arm_2d_region_t *ptRegion; //!< target region
1089 } Target;
1090 struct {
1091 const arm_2d_tile_t *ptTile; //!< the dummy source tile
1092 }Source;
1093 uint32_t wMode;
1094 struct {
1095 const arm_2d_tile_t *ptTile; //!< the origin tile
1096 arm_2d_tile_t tDummySource; //!< the buffer for the source
1097 }Origin;
1098
1099 /* derived part */
1100 struct {
1101 const arm_2d_tile_t *ptOriginSide; //!< origin side mask
1102 const arm_2d_tile_t *ptTargetSide; //!< target side mask
1103 } Mask;
1105
1106
1107/*----------------------------------------------------------------------------*
1108 * Fast Rotation linear regression structure
1109 *----------------------------------------------------------------------------*/
1110
1111#if (__ARM_2D_HAS_HELIUM_FLOAT__ || __ARM_2D_HAS_FPU__) \
1112 && !__ARM_2D_CFG_FORCED_FIXED_POINT_TRANSFORM__
1113/*!
1114 * \brief a type for parameters of linear interpolation (in floating point)
1115 *
1116 */
1117typedef struct arm_2d_rot_linear_regr_t {
1118 float slopeY;
1119 float interceptY;
1120 float slopeX;
1121 float interceptX;
1123
1124#else
1125/*!
1126 * \brief a type for parameters of linear interpolation (in fixed point)
1127 *
1128 */
1130 int32_t slopeY;
1131 int32_t interceptY;
1132 int32_t slopeX;
1133 int32_t interceptX;
1135
1136#endif
1137
1138/*============================ GLOBAL VARIABLES ==============================*/
1139/*============================ PROTOTYPES ====================================*/
1140
1141/*! @} */
1142
1143#if defined(__clang__)
1144#pragma clang diagnostic pop
1145#elif __IS_COMPILER_ARM_COMPILER_5__
1146#pragma diag_warning 64
1147#elif __IS_COMPILER_GCC__
1148#pragma GCC diagnostic pop
1149#endif
1150
1151#ifdef __cplusplus
1152}
1153#endif
1154
1155#endif // __ARM_2D_TYPES_H__
1156
1157