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: 09. Aug 2022
26 * $Revision: V.1.0.3
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# pragma clang diagnostic ignored "-Wnarrowing"
51#elif defined(__IS_COMPILER_IAR__)
52# pragma diag_suppress=Go029
53#endif
54
55/*!
56 * \addtogroup gConversion 6 Conversion Operations
57 * @{
58 */
59
60/*============================ MACROS ========================================*/
61/*============================ MACROFIED FUNCTIONS ===========================*/
62
63#define arm_2d_convert_colour_to_rgb888(__SRC_ADDR, /* source tile address */ \
64 __DES_ADDR /* target tile address */) \
65 arm_2dp_convert_colour_to_rgb888( NULL, \
66 (__SRC_ADDR), \
67 (__DES_ADDR))
68
69#define arm_2d_convert_colour_to_rgb565(__SRC_ADDR, /* source tile address */ \
70 __DES_ADDR /* target tile address */) \
71 arm_2dp_convert_colour_to_rgb565( NULL, \
72 (__SRC_ADDR), \
73 (__DES_ADDR))
74
75/*============================ TYPES =========================================*/
76
78
79/*! \brief 3x16-bit packed RGB color
80 * autovectorizer friendly format
81 */
82typedef union {
83 uint16_t BGRA[4];
84 struct {
85 uint16_t B;
86 uint16_t G;
87 uint16_t R;
88 uint16_t A;
89 };
91
92/*============================ GLOBAL VARIABLES ==============================*/
93/*============================ PROTOTYPES ====================================*/
94
95/*----------------------------------------------------------------------------*
96 * RGB565 channels extraction/packing *
97 *----------------------------------------------------------------------------*/
98
99/*!
100 * \brief unpack a rgb565 colour into a given __arm_2d_color_fast_rgb_t object
101 * \param[in] hwColour the target rgb565 colour
102 * \param[out] ptRGB a __arm_2d_color_fast_rgb_t object
103 */
104ARM_NONNULL(2)
105__STATIC_INLINE void __arm_2d_rgb565_unpack(uint16_t hwColor,
107{
108 assert(NULL != ptRGB);
109
110 /* uses explicit extraction, leading to a more efficient autovectorized code */
111 uint16_t maskRunpk = 0x001f, maskGunpk = 0x003f;
112
113 ptRGB->B = (uint16_t) ((hwColor & maskRunpk) << 3);
114 ptRGB->R = (uint16_t) ((hwColor >> 11) << 3);
115 ptRGB->G = (uint16_t) (((hwColor >> 5) & maskGunpk) << 2);
116
117 ptRGB->A = 0xFF;
118}
119
120/*!
121 * \brief generate a rgb565 colour from a __arm_2d_color_fast_rgb_t object
122 * \param[in] ptRGB the target __arm_2d_color_fast_rgb_t object
123 * \return uint16_t a rgb565 colour
124 */
125ARM_NONNULL(1)
126__STATIC_INLINE uint16_t __arm_2d_rgb565_pack(__arm_2d_color_fast_rgb_t * ptRGB)
127{
128 assert(NULL != ptRGB);
129
130 arm_2d_color_rgb565_t tOutput = {
131 .u5R = (uint16_t) ptRGB->R >> 3,
132 .u6G = (uint16_t) ptRGB->G >> 2,
133 .u5B = (uint16_t) ptRGB->B >> 3,
134 };
135 return tOutput.tValue;
136}
137
138/*!
139 * \brief generate a cccn888 colour from a __arm_2d_color_fast_rgb_t object
140 * \param[in] ptRGB the target __arm_2d_color_fast_rgb_t object
141 * \return uint32_t a cccn888 colour
142 * \note the alpha channel will be kept in the output value
143 */
144ARM_NONNULL(1)
145__STATIC_INLINE uint32_t __arm_2d_cccn888_pack(__arm_2d_color_fast_rgb_t * ptRGB)
146{
147 assert(NULL != ptRGB);
148
149 arm_2d_color_bgra8888_t tOutput = {
150 .u8R = (uint16_t) ptRGB->R,
151 .u8G = (uint16_t) ptRGB->G,
152 .u8B = (uint16_t) ptRGB->B,
153 .u8A = (uint16_t) ptRGB->A,
154 };
155 return tOutput.tValue;
156}
157
158
159/*----------------------------------------------------------------------------*
160 * Colour Conversion *
161 *----------------------------------------------------------------------------*/
162
163/*!
164 * \brief convert the colour format of a given tile to gray8
165 * \param[in] ptOP the control block, NULL means using the default control block
166 * \param[in] ptSource the source tile
167 * \param[out] ptTarget the output tile (holding a buffer)
168 * \return arm_fsm_rt_t the operation result
169 */
170extern
171ARM_NONNULL(2,3)
173 const arm_2d_tile_t *ptSource,
174 const arm_2d_tile_t *ptTarget);
175
176/*!
177 * \brief convert the colour format of a given tile to rgb888
178 * \param[in] ptOP the control block, NULL means using the default control block
179 * \param[in] ptSource the source tile
180 * \param[out] ptTarget the output tile (holding a buffer)
181 * \return arm_fsm_rt_t the operation result
182 */
183extern
184ARM_NONNULL(2,3)
186 const arm_2d_tile_t *ptSource,
187 const arm_2d_tile_t *ptTarget);
188/*!
189 * \brief convert the colour format of a given tile to rgb565
190 * \param[in] ptOP the control block, NULL means using the default control block
191 * \param[in] ptSource the source tile
192 * \param[out] ptTarget the output tile (holding a buffer)
193 * \return arm_fsm_rt_t the operation result
194 */
195extern
196ARM_NONNULL(2,3)
198 const arm_2d_tile_t *ptSource,
199 const arm_2d_tile_t *ptTarget);
200
201/*! @} */
202
203#if defined(__clang__)
204# pragma clang diagnostic pop
205#elif defined(__IS_COMPILER_IAR__)
206# pragma diag_warning=Go029
207#endif
208
209#ifdef __cplusplus
210}
211#endif
212
213#endif