pikapython/package/Arm2D/arm_2d_conversion.c

326 lines
12 KiB
C
Raw Normal View History

2021-11-09 22:19:51 +08:00
/*
* Copyright (C) 2010-2021 Arm Limited or its affiliates. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* ----------------------------------------------------------------------
* Project: Arm-2D Library
* Title: arm-2d_draw.c
* Description: APIs for colour format conversion
*
* $Date: 29. April 2021
* $Revision: V.0.8.0
*
* Target Processor: Cortex-M cores
*
* -------------------------------------------------------------------- */
/*============================ INCLUDES ======================================*/
#define __ARM_2D_IMPL__
#include "arm_2d.h"
#include "__arm_2d_impl.h"
#ifdef __cplusplus
extern "C" {
#endif
#if defined(__clang__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wunknown-warning-option"
# pragma clang diagnostic ignored "-Wreserved-identifier"
# pragma clang diagnostic ignored "-Wincompatible-pointer-types-discards-qualifiers"
# pragma clang diagnostic ignored "-Wmissing-variable-declarations"
# pragma clang diagnostic ignored "-Wcast-qual"
# pragma clang diagnostic ignored "-Wcast-align"
# pragma clang diagnostic ignored "-Wextra-semi-stmt"
# pragma clang diagnostic ignored "-Wsign-conversion"
# pragma clang diagnostic ignored "-Wunused-function"
# pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
# pragma clang diagnostic ignored "-Wdouble-promotion"
# pragma clang diagnostic ignored "-Wunused-parameter"
# pragma clang diagnostic ignored "-Wimplicit-float-conversion"
# pragma clang diagnostic ignored "-Wimplicit-int-conversion"
# pragma clang diagnostic ignored "-Wtautological-pointer-compare"
# pragma clang diagnostic ignored "-Wsign-compare"
# pragma clang diagnostic ignored "-Wmissing-prototypes"
# pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
# pragma clang diagnostic ignored "-Wswitch-enum"
# pragma clang diagnostic ignored "-Wswitch"
#elif defined(__IS_COMPILER_ARM_COMPILER_5__)
# pragma diag_suppress 174,177,188,68,513,144
#endif
/*============================ MACROS ========================================*/
/*============================ MACROFIED FUNCTIONS ===========================*/
/*============================ TYPES =========================================*/
/*============================ GLOBAL VARIABLES ==============================*/
/*============================ PROTOTYPES ====================================*/
void __arm_2d_impl_cccn888_to_rgb565(uint32_t *__RESTRICT pwSource,
int16_t iSourceStride,
uint16_t *__RESTRICT phwTarget,
int16_t iTargetStride,
arm_2d_size_t *__RESTRICT ptCopySize);
void __arm_2d_impl_rgb565_to_cccn888(uint16_t *__RESTRICT phwSourceBase,
int16_t iSourceStride,
uint32_t *__RESTRICT pwTargetBase,
int16_t iTargetStride,
arm_2d_size_t *__RESTRICT ptCopySize);
/*============================ LOCAL VARIABLES ===============================*/
/*============================ IMPLEMENTATION ================================*/
/*----------------------------------------------------------------------------*
* Convert Colour format *
*----------------------------------------------------------------------------*/
ARM_NONNULL(2,3)
arm_fsm_rt_t arm_2dp_convert_colour_to_rgb888( arm_2d_op_cl_convt_t *ptOP,
const arm_2d_tile_t *ptSource,
const arm_2d_tile_t *ptTarget)
{
assert(NULL != ptSource);
assert(NULL != ptTarget);
ARM_2D_IMPL(arm_2d_op_cl_convt_t, ptOP);
if (!__arm_2d_op_acquire((arm_2d_op_core_t *)ptThis)) {
return arm_fsm_rt_on_going;
}
//memset(ptThis, 0, sizeof(*ptThis));
OP_CORE.ptOp = &ARM_2D_OP_CONVERT_TO_RGB888;
this.Target.ptTile = ptTarget;
this.Target.ptRegion = NULL;
this.Source.ptTile = ptSource;
return __arm_2d_op_invoke((arm_2d_op_core_t *)ptThis);
}
ARM_NONNULL(2,3)
arm_fsm_rt_t arm_2dp_convert_colour_to_rgb565( arm_2d_op_cl_convt_t *ptOP,
const arm_2d_tile_t *ptSource,
const arm_2d_tile_t *ptTarget)
{
assert(NULL != ptSource);
assert(NULL != ptTarget);
ARM_2D_IMPL(arm_2d_op_cl_convt_t, ptOP);
if (!__arm_2d_op_acquire((arm_2d_op_core_t *)ptThis)) {
return arm_fsm_rt_on_going;
}
//memset(ptThis, 0, sizeof(*ptThis));
OP_CORE.ptOp = &ARM_2D_OP_CONVERT_TO_RGB565;
this.Target.ptTile = ptTarget;
this.Target.ptRegion = NULL;
this.Source.ptTile = ptSource;
return __arm_2d_op_invoke((arm_2d_op_core_t *)ptThis);
}
arm_fsm_rt_t __arm_2d_sw_convert_colour_to_rgb565(
__arm_2d_sub_task_t *ptTask)
{
ARM_2D_IMPL(arm_2d_op_cl_convt_t, ptTask->ptOP);
if (!this.Source.ptTile->bHasEnforcedColour) {
return (arm_fsm_rt_t)ARM_2D_ERR_MISSING_PARAM;
}
switch ( this.Source.ptTile->tInfo.tColourInfo.u3ColourSZ) {
case ARM_2D_COLOUR_SZ_16BIT:
/* no need to convert, return cpl directly */
break;
case ARM_2D_COLOUR_SZ_32BIT:
__arm_2d_impl_cccn888_to_rgb565( ptTask->Param.tCopy.tSource.pBuffer,
ptTask->Param.tCopy.tSource.iStride,
ptTask->Param.tCopy.tTarget.pBuffer,
ptTask->Param.tCopy.tTarget.iStride,
&(ptTask->Param.tCopy.tCopySize));
break;
default:
return (arm_fsm_rt_t)ARM_2D_ERR_UNSUPPORTED_COLOUR;
}
return arm_fsm_rt_cpl;
}
arm_fsm_rt_t __arm_2d_sw_convert_colour_to_rgb888(
__arm_2d_sub_task_t *ptTask)
{
ARM_2D_IMPL(arm_2d_op_cl_convt_t, ptTask->ptOP);
if (!this.Source.ptTile->bHasEnforcedColour) {
return (arm_fsm_rt_t)ARM_2D_ERR_MISSING_PARAM;
}
switch ( this.Source.ptTile->tInfo.tColourInfo.u3ColourSZ) {
case ARM_2D_COLOUR_SZ_16BIT:
__arm_2d_impl_rgb565_to_cccn888( ptTask->Param.tCopy.tSource.pBuffer,
ptTask->Param.tCopy.tSource.iStride,
ptTask->Param.tCopy.tTarget.pBuffer,
ptTask->Param.tCopy.tTarget.iStride,
&(ptTask->Param.tCopy.tCopySize));
break;
case ARM_2D_COLOUR_SZ_32BIT:
/* no need to convert, return cpl directly */
break;
default:
return (arm_fsm_rt_t)ARM_2D_ERR_UNSUPPORTED_COLOUR;
}
return arm_fsm_rt_cpl;
}
/*----------------------------------------------------------------------------*
* Accelerable Low Level APIs *
*----------------------------------------------------------------------------*/
__WEAK
void __arm_2d_impl_cccn888_to_rgb565(uint32_t *__RESTRICT pwSourceBase,
int16_t iSourceStride,
uint16_t *__RESTRICT phwTargetBase,
int16_t iTargetStride,
arm_2d_size_t *__RESTRICT ptCopySize)
{
for (int_fast16_t y = 0; y < ptCopySize->iHeight; y++) {
const uint32_t *__RESTRICT pwSource = pwSourceBase;
uint16_t *__RESTRICT phwTarget = phwTargetBase;
for (int_fast16_t x = 0; x < ptCopySize->iWidth; x++) {
arm_2d_color_rgba8888_t wSrcPixel;
__arm_2d_color_fast_rgb_t hwTargetPixel;
wSrcPixel.tValue = *pwSource++;
hwTargetPixel.R = wSrcPixel.u8R;
hwTargetPixel.G = wSrcPixel.u8G;
hwTargetPixel.B = wSrcPixel.u8B;
*phwTarget++ = __arm_2d_rgb565_pack(&hwTargetPixel);
}
pwSourceBase += iSourceStride;
phwTargetBase += iTargetStride;
}
}
__WEAK
void __arm_2d_impl_rgb565_to_cccn888(uint16_t *__RESTRICT phwSourceBase,
int16_t iSourceStride,
uint32_t *__RESTRICT pwTargetBase,
int16_t iTargetStride,
arm_2d_size_t *__RESTRICT ptCopySize)
{
for (int_fast16_t y = 0; y < ptCopySize->iHeight; y++) {
const uint16_t *__RESTRICT phwSource = phwSourceBase;
uint32_t *__RESTRICT pwTarget = pwTargetBase;
for (int_fast16_t x = 0; x < ptCopySize->iWidth; x++) {
__arm_2d_color_fast_rgb_t hwSrcPixel;
arm_2d_color_rgba8888_t wTargetPixel;
__arm_2d_rgb565_unpack(*phwSource++, &hwSrcPixel);
wTargetPixel.u8R = hwSrcPixel.R;
wTargetPixel.u8G = hwSrcPixel.G;
wTargetPixel.u8B = hwSrcPixel.B;
wTargetPixel.u8A = 0xFF;
*pwTarget++ = wTargetPixel.tValue;
}
phwSourceBase += iSourceStride;
pwTargetBase += iTargetStride;
}
}
/*----------------------------------------------------------------------------*
* Low Level IO Interfaces *
*----------------------------------------------------------------------------*/
__WEAK
def_low_lv_io(__ARM_2D_IO_COLOUR_CONVERT_TO_RGB565,
__arm_2d_sw_convert_colour_to_rgb565);
__WEAK
def_low_lv_io(__ARM_2D_IO_COLOUR_CONVERT_TO_RGB888,
__arm_2d_sw_convert_colour_to_rgb888);
const __arm_2d_op_info_t ARM_2D_OP_CONVERT_TO_RGB565 = {
.Info = {
.Colour = {
.chScheme = ARM_2D_COLOUR_RGB565,
},
.Param = {
.bHasSource = true,
.bHasTarget = true,
.bAllowEnforcedColour = true,
},
.chOpIndex = __ARM_2D_OP_IDX_COLOUR_FORMAT_CONVERSION,
.LowLevelIO = {
.ptCopyLike = ref_low_lv_io(__ARM_2D_IO_COLOUR_CONVERT_TO_RGB565),
.ptFillLike = NULL,
},
},
};
const __arm_2d_op_info_t ARM_2D_OP_CONVERT_TO_RGB888 = {
.Info = {
.Colour = {
.chScheme = ARM_2D_COLOUR_RGB888,
},
.Param = {
.bHasSource = true,
.bHasTarget = true,
.bAllowEnforcedColour = true,
},
.chOpIndex = __ARM_2D_OP_IDX_COLOUR_FORMAT_CONVERSION,
.LowLevelIO = {
.ptCopyLike = ref_low_lv_io(__ARM_2D_IO_COLOUR_CONVERT_TO_RGB888),
.ptFillLike = NULL,
},
},
};
#if defined(__clang__)
# pragma clang diagnostic pop
#elif defined(__IS_COMPILER_ARM_COMPILER_5__)
# pragma diag_warning 174,177,188,68,513,144
#endif
#ifdef __cplusplus
}
#endif