Arm-2D  
2D Image Processing Library for Cortex-M Processors
arm_2d_conversion.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: #include "arm_2d.h"
22 * Description: Public header file to contain the APIs for colour space
23 * conversions
24 *
25 * $Date: 17. June 2022
26 * $Revision: V.1.0.2
27 *
28 * Target Processor: Cortex-M cores
29 * -------------------------------------------------------------------- */
30
31#ifndef __ARM_2D_CONVERSION_H__
32#define __ARM_2D_CONVERSION_H__
33
34/*============================ INCLUDES ======================================*/
35
36#include "arm_2d_types.h"
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41
42#if defined(__clang__)
43# pragma clang diagnostic push
44# pragma clang diagnostic ignored "-Wunknown-warning-option"
45# pragma clang diagnostic ignored "-Wreserved-identifier"
46# pragma clang diagnostic ignored "-Wdeclaration-after-statement"
47# pragma clang diagnostic ignored "-Wunknown-warning-option"
48# pragma clang diagnostic ignored "-Wreserved-identifier"
49# pragma clang diagnostic ignored "-Wsign-conversion"
50#elif defined(__IS_COMPILER_IAR__)
51# pragma diag_suppress=Go029
52#endif
53
54/*!
55 * \addtogroup gConversion 6 Conversion Operations
56 * @{
57 */
58
59/*============================ MACROS ========================================*/
60/*============================ MACROFIED FUNCTIONS ===========================*/
61
62#define arm_2d_convert_colour_to_rgb888(__SRC_ADDR, /* source tile address */ \
63 __DES_ADDR /* target tile address */) \
64 arm_2dp_convert_colour_to_rgb888( NULL, \
65 (__SRC_ADDR), \
66 (__DES_ADDR))
67
68#define arm_2d_convert_colour_to_rgb565(__SRC_ADDR, /* source tile address */ \
69 __DES_ADDR /* target tile address */) \
70 arm_2dp_convert_colour_to_rgb565( NULL, \
71 (__SRC_ADDR), \
72 (__DES_ADDR))
73
74/*============================ TYPES =========================================*/
75
77
78/*! \brief 3x16-bit packed RGB color
79 * autovectorizer friendly format
80 */
81typedef union {
82 uint16_t RGBA[4];
83 struct {
84 uint16_t R;
85 uint16_t G;
86 uint16_t B;
87 uint16_t A;
88 };
90
91/*============================ GLOBAL VARIABLES ==============================*/
92/*============================ PROTOTYPES ====================================*/
93
94/*----------------------------------------------------------------------------*
95 * RGB565 channels extraction/packing *
96 *----------------------------------------------------------------------------*/
97
98/*!
99 * \brief unpack a rgb565 colour into a given __arm_2d_color_fast_rgb_t object
100 * \param[in] hwColour the target rgb565 colour
101 * \param[out] ptRGB a __arm_2d_color_fast_rgb_t object
102 */
103ARM_NONNULL(2)
104__STATIC_INLINE void __arm_2d_rgb565_unpack(uint16_t hwColor,
106{
107 assert(NULL != ptRGB);
108
109 /* uses explicit extraction, leading to a more efficient autovectorized code */
110 uint16_t maskRunpk = 0x001f, maskGunpk = 0x003f;
111
112 ptRGB->R = (uint16_t) ((hwColor & maskRunpk) << 3);
113 ptRGB->B = (uint16_t) ((hwColor >> 11) << 3);
114 ptRGB->G = (uint16_t) (((hwColor >> 5) & maskGunpk) << 2);
115 ptRGB->A = 0xFF;
116}
117
118/*!
119 * \brief generate a rgb565 colour from a __arm_2d_color_fast_rgb_t object
120 * \param[in] ptRGB the target __arm_2d_color_fast_rgb_t object
121 * \return uint16_t a rgb565 colour
122 */
123ARM_NONNULL(1)
124__STATIC_INLINE uint16_t __arm_2d_rgb565_pack(__arm_2d_color_fast_rgb_t * ptRGB)
125{
126 assert(NULL != ptRGB);
127
128 arm_2d_color_rgb565_t tOutput = {
129 .u5R = (uint16_t) ptRGB->R >> 3,
130 .u6G = (uint16_t) ptRGB->G >> 2,
131 .u5B = (uint16_t) ptRGB->B >> 3,
132 };
133 return tOutput.tValue;
134}
135
136/*!
137 * \brief generate a cccn888 colour from a __arm_2d_color_fast_rgb_t object
138 * \param[in] ptRGB the target __arm_2d_color_fast_rgb_t object
139 * \return uint32_t a cccn888 colour
140 * \note the alpha channel will be kept in the output value
141 */
142ARM_NONNULL(1)
143__STATIC_INLINE uint32_t __arm_2d_cccn888_pack(__arm_2d_color_fast_rgb_t * ptRGB)
144{
145 assert(NULL != ptRGB);
146
147 arm_2d_color_bgra8888_t tOutput = {
148 .u8R = (uint16_t) ptRGB->R,
149 .u8G = (uint16_t) ptRGB->G,
150 .u8B = (uint16_t) ptRGB->B,
151 .u8A = (uint16_t) ptRGB->A,
152 };
153 return tOutput.tValue;
154}
155
156
157/*----------------------------------------------------------------------------*
158 * Colour Conversion *
159 *----------------------------------------------------------------------------*/
160
161/*!
162 * \brief convert the colour format of a given tile to rgb888
163 * \param[in] ptOP the control block, NULL means using the default control block
164 * \param[in] ptSource the source tile
165 * \param[out] ptTarget the output tile (holding a buffer)
166 * \return arm_fsm_rt_t the operation result
167 */
168extern
169ARM_NONNULL(2,3)
171 const arm_2d_tile_t *ptSource,
172 const arm_2d_tile_t *ptTarget);
173/*!
174 * \brief convert the colour format of a given tile to rgb565
175 * \param[in] ptOP the control block, NULL means using the default control block
176 * \param[in] ptSource the source tile
177 * \param[out] ptTarget the output tile (holding a buffer)
178 * \return arm_fsm_rt_t the operation result
179 */
180extern
181ARM_NONNULL(2,3)
183 const arm_2d_tile_t *ptSource,
184 const arm_2d_tile_t *ptTarget);
185
186/*! @} */
187
188#if defined(__clang__)
189# pragma clang diagnostic pop
190#elif defined(__IS_COMPILER_IAR__)
191# pragma diag_warning=Go029
192#endif
193
194#ifdef __cplusplus
195}
196#endif
197
198#endif