From e20c95fcc518a98d9a6764f79f7388fca88212c7 Mon Sep 17 00:00:00 2001 From: Gabriel Wang Date: Fri, 29 Nov 2024 15:00:16 +0000 Subject: [PATCH] Add colour format: gray8 and cccn888 to colour-reversing --- .../Include/__arm_2d_filter_reverse_colour.h | 57 +++++- .../Source/__arm_2d_filter_reverse_colour.c | 190 +++++++++++++++++- .../__arm_2d_filter_reverse_colour.c.jinja | 50 +++-- .../__arm_2d_filter_reverse_colour.h.jinja | 29 ++- 4 files changed, 292 insertions(+), 34 deletions(-) diff --git a/Library/Include/__arm_2d_filter_reverse_colour.h b/Library/Include/__arm_2d_filter_reverse_colour.h index 7be8732c..f6ff0c01 100644 --- a/Library/Include/__arm_2d_filter_reverse_colour.h +++ b/Library/Include/__arm_2d_filter_reverse_colour.h @@ -22,7 +22,7 @@ * Description: APIs for colour-reversing * * $Date: 29. Nov 2024 - * $Revision: V.0.3.0 + * $Revision: V.1.0.0 * * Target Processor: Cortex-M cores * @@ -56,16 +56,33 @@ extern "C" { /*============================ MACROS ========================================*/ /*============================ MACROFIED FUNCTIONS ===========================*/ + +#define arm_2d_gray8_filter_reverse_colour(__TARGET_ADDR, /* target tile */ \ + __REGION_ADDR) /* target region */ \ + arm_2dp_gray8_filter_reverse_colour(NULL, \ + (__TARGET_ADDR), \ + (__REGION_ADDR)) + +#define arm_2d_rgb565_filter_reverse_colour(__TARGET_ADDR, /* target tile */ \ + __REGION_ADDR) /* target region */ \ + arm_2dp_rgb565_filter_reverse_colour(NULL, \ + (__TARGET_ADDR), \ + (__REGION_ADDR)) + +#define arm_2d_cccn888_filter_reverse_colour(__TARGET_ADDR, /* target tile */ \ + __REGION_ADDR) /* target region */ \ + arm_2dp_cccn888_filter_reverse_colour(NULL, \ + (__TARGET_ADDR), \ + (__REGION_ADDR)) /*============================ TYPES =========================================*/ /*============================ GLOBAL VARIABLES ==============================*/ /*============================ PROTOTYPES ====================================*/ /*============================ LOCAL VARIABLES ===============================*/ /*============================ IMPLEMENTATION ================================*/ - extern ARM_NONNULL(2) /*! - * \brief reverse the colour of the target region + * \brief reverse the colour of the target region for gray8 * \param[in] ptOP the control block, NULL means using the default control block * \param[in] ptTarget the target tile * \param[in] ptRegion the target region @@ -73,10 +90,40 @@ ARM_NONNULL(2) * \param[in] tColour the target colour * \return arm_fsm_rt_t the operations result */ -arm_fsm_rt_t arm_2dp_rgb565_reverse_colour( arm_2d_op_fill_cl_msk_t *ptOP, +arm_fsm_rt_t arm_2dp_gray8_filter_reverse_colour( + arm_2d_op_fill_cl_msk_t *ptOP, + const arm_2d_tile_t *ptTarget, + const arm_2d_region_t *ptRegion); +extern +ARM_NONNULL(2) +/*! + * \brief reverse the colour of the target region for rgb565 + * \param[in] ptOP the control block, NULL means using the default control block + * \param[in] ptTarget the target tile + * \param[in] ptRegion the target region + * \param[in] ptLineMsk the target line mask + * \param[in] tColour the target colour + * \return arm_fsm_rt_t the operations result + */ +arm_fsm_rt_t arm_2dp_rgb565_filter_reverse_colour( + arm_2d_op_fill_cl_msk_t *ptOP, + const arm_2d_tile_t *ptTarget, + const arm_2d_region_t *ptRegion); +extern +ARM_NONNULL(2) +/*! + * \brief reverse the colour of the target region for cccn888 + * \param[in] ptOP the control block, NULL means using the default control block + * \param[in] ptTarget the target tile + * \param[in] ptRegion the target region + * \param[in] ptLineMsk the target line mask + * \param[in] tColour the target colour + * \return arm_fsm_rt_t the operations result + */ +arm_fsm_rt_t arm_2dp_cccn888_filter_reverse_colour( + arm_2d_op_fill_cl_msk_t *ptOP, const arm_2d_tile_t *ptTarget, const arm_2d_region_t *ptRegion); - /*! @} */ #if defined(__clang__) diff --git a/Library/Source/__arm_2d_filter_reverse_colour.c b/Library/Source/__arm_2d_filter_reverse_colour.c index 2bbe848d..28df1ea5 100644 --- a/Library/Source/__arm_2d_filter_reverse_colour.c +++ b/Library/Source/__arm_2d_filter_reverse_colour.c @@ -22,7 +22,7 @@ * Description: the source code of the colour-reversing * * $Date: 29. Nov 2024 - * $Revision: V.0.3.0 + * $Revision: V.1.0.0 * * Target Processor: Cortex-M cores * @@ -77,21 +77,108 @@ extern "C" { /*============================ MACROFIED FUNCTIONS ===========================*/ /*============================ TYPES =========================================*/ /*============================ GLOBAL VARIABLES ==============================*/ -extern -const __arm_2d_op_info_t ARM_2D_OP_FILTER_REVERSE_COLOUR_RGB565; /*============================ PROTOTYPES ====================================*/ /*============================ LOCAL VARIABLES ===============================*/ /*============================ IMPLEMENTATION ================================*/ +/* + * the Frontend API + */ + +ARM_NONNULL(2) +arm_fsm_rt_t arm_2dp_gray8_filter_reverse_colour( + arm_2d_op_fill_cl_msk_t *ptOP, + const arm_2d_tile_t *ptTarget, + const arm_2d_region_t *ptRegion) +{ + assert(NULL != ptTarget); + + ARM_2D_IMPL(arm_2d_op_t, ptOP); + + if (!__arm_2d_op_acquire((arm_2d_op_core_t *)ptThis)) { + return arm_fsm_rt_on_going; + } + + OP_CORE.ptOp = &ARM_2D_OP_FILTER_REVERSE_COLOUR_GRAY8; + + this.Target.ptTile = ptTarget; + this.Target.ptRegion = ptRegion; + + return __arm_2d_op_invoke((arm_2d_op_core_t *)ptThis); +} + + +/* default low level implementation */ + +__WEAK +void __arm_2d_impl_gray8_reverse_colour( uint8_t *__RESTRICT pchTarget, + int16_t iTargetStride, + arm_2d_size_t *__RESTRICT ptCopySize) +{ + for (int_fast16_t y = 0; y < ptCopySize->iHeight; y++) { + + uint8_t *__RESTRICT pchTargetLine = pchTarget; + for (int_fast16_t x = 0; x < ptCopySize->iWidth; x++){ + *pchTargetLine++ ^= __UINT8_MAX__; + } + pchTarget += iTargetStride; + } +} + +/* + * The backend entry + */ +arm_fsm_rt_t __arm_2d_gray8_sw_filter_reverse_colour( __arm_2d_sub_task_t *ptTask) +{ + ARM_2D_IMPL(arm_2d_op_t, ptTask->ptOP); + assert(ARM_2D_COLOUR_SZ_8BIT == OP_CORE.ptOp->Info.Colour.u3ColourSZ); + + __arm_2d_impl_gray8_reverse_colour( + ptTask->Param.tTileProcess.pBuffer, + ptTask->Param.tTileProcess.iStride, + &(ptTask->Param.tTileProcess.tValidRegion.tSize)); + + return arm_fsm_rt_cpl; +} + +/* + * OPCODE Low Level Implementation Entries + */ +__WEAK +def_low_lv_io( __ARM_2D_IO_FILTER_REVERSE_COLOUR_GRAY8, + __arm_2d_gray8_sw_filter_reverse_colour); /* Default SW Implementation */ + + +/* + * OPCODE + */ + +const __arm_2d_op_info_t ARM_2D_OP_FILTER_REVERSE_COLOUR_GRAY8 = { + .Info = { + .Colour = { + .chScheme = ARM_2D_COLOUR_GRAY8, + }, + .Param = { + .bHasSource = false, + .bHasTarget = true, + }, + .chOpIndex = __ARM_2D_OP_IDX_FILTER_REVERSE_COLOUR, + + .LowLevelIO = { + .ptTileProcessLike = ref_low_lv_io(__ARM_2D_IO_FILTER_REVERSE_COLOUR_GRAY8), + }, + }, +}; /* * the Frontend API */ ARM_NONNULL(2) -arm_fsm_rt_t arm_2dp_rgb565_reverse_colour( arm_2d_op_fill_cl_msk_t *ptOP, - const arm_2d_tile_t *ptTarget, - const arm_2d_region_t *ptRegion) +arm_fsm_rt_t arm_2dp_rgb565_filter_reverse_colour( + arm_2d_op_fill_cl_msk_t *ptOP, + const arm_2d_tile_t *ptTarget, + const arm_2d_region_t *ptRegion) { assert(NULL != ptTarget); @@ -118,8 +205,10 @@ void __arm_2d_impl_rgb565_reverse_colour( uint16_t *__RESTRICT phwTarget, arm_2d_size_t *__RESTRICT ptCopySize) { for (int_fast16_t y = 0; y < ptCopySize->iHeight; y++) { + + uint16_t *__RESTRICT phwTargetLine = phwTarget; for (int_fast16_t x = 0; x < ptCopySize->iWidth; x++){ - phwTarget[x] ^= __UINT16_MAX__; + *phwTargetLine++ ^= __UINT16_MAX__; } phwTarget += iTargetStride; } @@ -170,7 +259,94 @@ const __arm_2d_op_info_t ARM_2D_OP_FILTER_REVERSE_COLOUR_RGB565 = { }, }; +/* + * the Frontend API + */ + +ARM_NONNULL(2) +arm_fsm_rt_t arm_2dp_cccn888_filter_reverse_colour( + arm_2d_op_fill_cl_msk_t *ptOP, + const arm_2d_tile_t *ptTarget, + const arm_2d_region_t *ptRegion) +{ + assert(NULL != ptTarget); + + ARM_2D_IMPL(arm_2d_op_t, ptOP); + + if (!__arm_2d_op_acquire((arm_2d_op_core_t *)ptThis)) { + return arm_fsm_rt_on_going; + } + + OP_CORE.ptOp = &ARM_2D_OP_FILTER_REVERSE_COLOUR_CCCN888; + + this.Target.ptTile = ptTarget; + this.Target.ptRegion = ptRegion; + + return __arm_2d_op_invoke((arm_2d_op_core_t *)ptThis); +} + + +/* default low level implementation */ + +__WEAK +void __arm_2d_impl_cccn888_reverse_colour( uint32_t *__RESTRICT pwTarget, + int16_t iTargetStride, + arm_2d_size_t *__RESTRICT ptCopySize) +{ + for (int_fast16_t y = 0; y < ptCopySize->iHeight; y++) { + + uint32_t *__RESTRICT pwTargetLine = pwTarget; + for (int_fast16_t x = 0; x < ptCopySize->iWidth; x++){ + *pwTargetLine++ ^= 0x00FFFFFF; + } + pwTarget += iTargetStride; + } +} +/* + * The backend entry + */ +arm_fsm_rt_t __arm_2d_cccn888_sw_filter_reverse_colour( __arm_2d_sub_task_t *ptTask) +{ + ARM_2D_IMPL(arm_2d_op_t, ptTask->ptOP); + assert(ARM_2D_COLOUR_SZ_32BIT == OP_CORE.ptOp->Info.Colour.u3ColourSZ); + + __arm_2d_impl_cccn888_reverse_colour( + ptTask->Param.tTileProcess.pBuffer, + ptTask->Param.tTileProcess.iStride, + &(ptTask->Param.tTileProcess.tValidRegion.tSize)); + + return arm_fsm_rt_cpl; +} + +/* + * OPCODE Low Level Implementation Entries + */ +__WEAK +def_low_lv_io( __ARM_2D_IO_FILTER_REVERSE_COLOUR_CCCN888, + __arm_2d_cccn888_sw_filter_reverse_colour); /* Default SW Implementation */ + + +/* + * OPCODE + */ + +const __arm_2d_op_info_t ARM_2D_OP_FILTER_REVERSE_COLOUR_CCCN888 = { + .Info = { + .Colour = { + .chScheme = ARM_2D_COLOUR_CCCN888, + }, + .Param = { + .bHasSource = false, + .bHasTarget = true, + }, + .chOpIndex = __ARM_2D_OP_IDX_FILTER_REVERSE_COLOUR, + + .LowLevelIO = { + .ptTileProcessLike = ref_low_lv_io(__ARM_2D_IO_FILTER_REVERSE_COLOUR_CCCN888), + }, + }, +}; #ifdef __cplusplus } diff --git a/Library/jinja/__arm_2d_filter_reverse_colour.c.jinja b/Library/jinja/__arm_2d_filter_reverse_colour.c.jinja index 41a0d2c0..6e44a5dc 100644 --- a/Library/jinja/__arm_2d_filter_reverse_colour.c.jinja +++ b/Library/jinja/__arm_2d_filter_reverse_colour.c.jinja @@ -22,7 +22,7 @@ * Description: the source code of the colour-reversing * * $Date: 29. Nov 2024 - * $Revision: V.0.3.0 + * $Revision: V.1.0.0 * * Target Processor: Cortex-M cores * @@ -77,21 +77,27 @@ extern "C" { /*============================ MACROFIED FUNCTIONS ===========================*/ /*============================ TYPES =========================================*/ /*============================ GLOBAL VARIABLES ==============================*/ -extern -const __arm_2d_op_info_t ARM_2D_OP_FILTER_REVERSE_COLOUR_RGB565; /*============================ PROTOTYPES ====================================*/ /*============================ LOCAL VARIABLES ===============================*/ /*============================ IMPLEMENTATION ================================*/ +{%- for colour_name, colour_int, colour_int_prefix, colour_int_no_bits in [ + ('gray8', 'uint8_t', 'ch', '8' ), + ('rgb565', 'uint16_t', 'hw', '16' ), + ('cccn888', 'uint32_t', 'w', '32' ), + ] +%} + /* * the Frontend API */ ARM_NONNULL(2) -arm_fsm_rt_t arm_2dp_rgb565_reverse_colour( arm_2d_op_fill_cl_msk_t *ptOP, - const arm_2d_tile_t *ptTarget, - const arm_2d_region_t *ptRegion) +arm_fsm_rt_t arm_2dp_{{colour_name}}_filter_reverse_colour( + arm_2d_op_fill_cl_msk_t *ptOP, + const arm_2d_tile_t *ptTarget, + const arm_2d_region_t *ptRegion) { assert(NULL != ptTarget); @@ -101,7 +107,7 @@ arm_fsm_rt_t arm_2dp_rgb565_reverse_colour( arm_2d_op_fill_cl_msk_t *ptOP, return arm_fsm_rt_on_going; } - OP_CORE.ptOp = &ARM_2D_OP_FILTER_REVERSE_COLOUR_RGB565; + OP_CORE.ptOp = &ARM_2D_OP_FILTER_REVERSE_COLOUR_{{colour_name|upper}}; this.Target.ptTile = ptTarget; this.Target.ptRegion = ptRegion; @@ -113,27 +119,33 @@ arm_fsm_rt_t arm_2dp_rgb565_reverse_colour( arm_2d_op_fill_cl_msk_t *ptOP, /* default low level implementation */ __WEAK -void __arm_2d_impl_rgb565_reverse_colour( uint16_t *__RESTRICT phwTarget, +void __arm_2d_impl_{{colour_name}}_reverse_colour( {{colour_int}} *__RESTRICT p{{colour_int_prefix}}Target, int16_t iTargetStride, arm_2d_size_t *__RESTRICT ptCopySize) { for (int_fast16_t y = 0; y < ptCopySize->iHeight; y++) { + + {{colour_int}} *__RESTRICT p{{colour_int_prefix}}TargetLine = p{{colour_int_prefix}}Target; for (int_fast16_t x = 0; x < ptCopySize->iWidth; x++){ - phwTarget[x] ^= __UINT16_MAX__; + {%- if colour_name == "cccn888" %} + *pwTargetLine++ ^= 0x00FFFFFF; + {%- else %} + *p{{colour_int_prefix}}TargetLine++ ^= __UINT{{colour_int_no_bits}}_MAX__; + {%- endif %} } - phwTarget += iTargetStride; + p{{colour_int_prefix}}Target += iTargetStride; } } /* * The backend entry */ -arm_fsm_rt_t __arm_2d_rgb565_sw_filter_reverse_colour( __arm_2d_sub_task_t *ptTask) +arm_fsm_rt_t __arm_2d_{{colour_name}}_sw_filter_reverse_colour( __arm_2d_sub_task_t *ptTask) { ARM_2D_IMPL(arm_2d_op_t, ptTask->ptOP); - assert(ARM_2D_COLOUR_SZ_16BIT == OP_CORE.ptOp->Info.Colour.u3ColourSZ); + assert(ARM_2D_COLOUR_SZ_{{colour_int_no_bits}}BIT == OP_CORE.ptOp->Info.Colour.u3ColourSZ); - __arm_2d_impl_rgb565_reverse_colour( + __arm_2d_impl_{{colour_name}}_reverse_colour( ptTask->Param.tTileProcess.pBuffer, ptTask->Param.tTileProcess.iStride, &(ptTask->Param.tTileProcess.tValidRegion.tSize)); @@ -145,18 +157,18 @@ arm_fsm_rt_t __arm_2d_rgb565_sw_filter_reverse_colour( __arm_2d_sub_task_t *ptTa * OPCODE Low Level Implementation Entries */ __WEAK -def_low_lv_io( __ARM_2D_IO_FILTER_REVERSE_COLOUR_RGB565, - __arm_2d_rgb565_sw_filter_reverse_colour); /* Default SW Implementation */ +def_low_lv_io( __ARM_2D_IO_FILTER_REVERSE_COLOUR_{{colour_name|upper}}, + __arm_2d_{{colour_name}}_sw_filter_reverse_colour); /* Default SW Implementation */ /* * OPCODE */ -const __arm_2d_op_info_t ARM_2D_OP_FILTER_REVERSE_COLOUR_RGB565 = { +const __arm_2d_op_info_t ARM_2D_OP_FILTER_REVERSE_COLOUR_{{colour_name|upper}} = { .Info = { .Colour = { - .chScheme = ARM_2D_COLOUR_RGB565, + .chScheme = ARM_2D_COLOUR_{{colour_name|upper}}, }, .Param = { .bHasSource = false, @@ -165,12 +177,12 @@ const __arm_2d_op_info_t ARM_2D_OP_FILTER_REVERSE_COLOUR_RGB565 = { .chOpIndex = __ARM_2D_OP_IDX_FILTER_REVERSE_COLOUR, .LowLevelIO = { - .ptTileProcessLike = ref_low_lv_io(__ARM_2D_IO_FILTER_REVERSE_COLOUR_RGB565), + .ptTileProcessLike = ref_low_lv_io(__ARM_2D_IO_FILTER_REVERSE_COLOUR_{{colour_name|upper}}), }, }, }; - +{%- endfor %} #ifdef __cplusplus } diff --git a/Library/jinja/__arm_2d_filter_reverse_colour.h.jinja b/Library/jinja/__arm_2d_filter_reverse_colour.h.jinja index 2e139261..45056dd5 100644 --- a/Library/jinja/__arm_2d_filter_reverse_colour.h.jinja +++ b/Library/jinja/__arm_2d_filter_reverse_colour.h.jinja @@ -22,7 +22,7 @@ * Description: APIs for colour-reversing * * $Date: 29. Nov 2024 - * $Revision: V.0.3.0 + * $Revision: V.1.0.0 * * Target Processor: Cortex-M cores * @@ -56,16 +56,37 @@ extern "C" { /*============================ MACROS ========================================*/ /*============================ MACROFIED FUNCTIONS ===========================*/ + +{%- for colour_name, colour_int, colour_int_prefix, colour_int_no_bits in [ + ('gray8', 'uint8_t', 'ch', '8BIT' ), + ('rgb565', 'uint16_t', 'hw', '16BIT' ), + ('cccn888', 'uint32_t', 'w', '32BIT' ), + ] +%} + +#define arm_2d_{{colour_name}}_filter_reverse_colour(__TARGET_ADDR, /* target tile */ \ + __REGION_ADDR) /* target region */ \ + arm_2dp_{{colour_name}}_filter_reverse_colour(NULL, \ + (__TARGET_ADDR), \ + (__REGION_ADDR)) + +{%- endfor %} /*============================ TYPES =========================================*/ /*============================ GLOBAL VARIABLES ==============================*/ /*============================ PROTOTYPES ====================================*/ /*============================ LOCAL VARIABLES ===============================*/ /*============================ IMPLEMENTATION ================================*/ +{%- for colour_name, colour_int, colour_int_prefix, colour_int_no_bits in [ + ('gray8', 'uint8_t', 'ch', '8BIT' ), + ('rgb565', 'uint16_t', 'hw', '16BIT' ), + ('cccn888', 'uint32_t', 'w', '32BIT' ), + ] +%} extern ARM_NONNULL(2) /*! - * \brief reverse the colour of the target region + * \brief reverse the colour of the target region for {{colour_name}} * \param[in] ptOP the control block, NULL means using the default control block * \param[in] ptTarget the target tile * \param[in] ptRegion the target region @@ -73,10 +94,12 @@ ARM_NONNULL(2) * \param[in] tColour the target colour * \return arm_fsm_rt_t the operations result */ -arm_fsm_rt_t arm_2dp_rgb565_reverse_colour( arm_2d_op_fill_cl_msk_t *ptOP, +arm_fsm_rt_t arm_2dp_{{colour_name}}_filter_reverse_colour( + arm_2d_op_fill_cl_msk_t *ptOP, const arm_2d_tile_t *ptTarget, const arm_2d_region_t *ptRegion); +{%- endfor %} /*! @} */ #if defined(__clang__)