| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#include "lv_draw_pxp.h" |
| 17 |
|
| 18 |
#if LV_USE_PXP |
| 19 |
#if LV_USE_DRAW_PXP |
| 20 |
#include "lv_pxp_cfg.h" |
| 21 |
#include "lv_pxp_utils.h" |
| 22 |
#include "../../lv_draw_image_private.h" |
| 23 |
#include "../../lv_image_decoder_private.h" |
| 24 |
|
| 25 |
#include <math.h> |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
static void _pxp_draw_core_cb(lv_draw_task_t * t, const lv_draw_image_dsc_t * draw_dsc, |
| 39 |
const lv_image_decoder_dsc_t * decoder_dsc, lv_draw_image_sup_t * sup, |
| 40 |
const lv_area_t * img_coords, const lv_area_t * clipped_img_area); |
| 41 |
|
| 42 |
|
| 43 |
static void _pxp_blit_recolor(uint8_t * dest_buf, const lv_area_t * dest_area, int32_t dest_stride, |
| 44 |
lv_color_format_t dest_cf, const uint8_t * src_buf, const lv_area_t * src_area, |
| 45 |
int32_t src_stride, lv_color_format_t src_cf, const lv_draw_image_dsc_t * dsc); |
| 46 |
|
| 47 |
|
| 48 |
static void _pxp_blit_transform(uint8_t * dest_buf, const lv_area_t * dest_area, int32_t dest_stride, |
| 49 |
lv_color_format_t dest_cf, const uint8_t * src_buf, const lv_area_t * src_area, |
| 50 |
int32_t src_stride, lv_color_format_t src_cf, const lv_draw_image_dsc_t * dsc); |
| 51 |
|
| 52 |
|
| 53 |
static void _pxp_blit(uint8_t * dest_buf, const lv_area_t * dest_area, int32_t dest_stride, |
| 54 |
lv_color_format_t dest_cf, const uint8_t * src_buf, const lv_area_t * src_area, |
| 55 |
int32_t src_stride, lv_color_format_t src_cf, lv_opa_t opa); |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
void lv_draw_pxp_img(lv_draw_task_t * t) |
| 70 |
{ |
| 71 |
const lv_draw_image_dsc_t * dsc = t->draw_dsc; |
| 72 |
const lv_area_t * coords = &t->area; |
| 73 |
|
| 74 |
if(dsc->opa <= (lv_opa_t)LV_OPA_MIN) |
| 75 |
return; |
| 76 |
|
| 77 |
bool is_tiled = (dsc->tile != 0); |
| 78 |
if(is_tiled) |
| 79 |
lv_draw_image_tiled_helper(t, dsc, coords, _pxp_draw_core_cb, NULL); |
| 80 |
else |
| 81 |
lv_draw_image_normal_helper(t, dsc, coords, _pxp_draw_core_cb, NULL); |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
static void _pxp_draw_core_cb(lv_draw_task_t * t, const lv_draw_image_dsc_t * draw_dsc, |
| 88 |
const lv_image_decoder_dsc_t * decoder_dsc, lv_draw_image_sup_t * sup, |
| 89 |
const lv_area_t * img_coords, const lv_area_t * clipped_img_area) |
| 90 |
{ |
| 91 |
lv_layer_t * layer = t->target_layer; |
| 92 |
lv_draw_buf_t * draw_buf = layer->draw_buf; |
| 93 |
const lv_draw_buf_t * decoded = decoder_dsc->decoded; |
| 94 |
|
| 95 |
lv_area_t rel_clip_area; |
| 96 |
lv_area_copy(&rel_clip_area, clipped_img_area); |
| 97 |
lv_area_move(&rel_clip_area, -img_coords->x1, -img_coords->y1); |
| 98 |
|
| 99 |
lv_area_t rel_img_coords; |
| 100 |
lv_area_copy(&rel_img_coords, img_coords); |
| 101 |
lv_area_move(&rel_img_coords, -img_coords->x1, -img_coords->y1); |
| 102 |
|
| 103 |
const uint8_t * src_buf = decoded->data; |
| 104 |
|
| 105 |
lv_area_t src_area; |
| 106 |
if(!lv_area_intersect(&src_area, &rel_clip_area, &rel_img_coords)) |
| 107 |
return; |
| 108 |
|
| 109 |
int32_t src_stride = draw_dsc->header.stride; |
| 110 |
lv_color_format_t src_cf = draw_dsc->header.cf; |
| 111 |
|
| 112 |
uint8_t * dest_buf = draw_buf->data; |
| 113 |
int32_t dest_stride = draw_buf->header.stride; |
| 114 |
lv_color_format_t dest_cf = draw_buf->header.cf; |
| 115 |
bool has_recolor = (draw_dsc->recolor_opa > LV_OPA_MIN); |
| 116 |
bool has_transform = (draw_dsc->rotation != 0 || draw_dsc->scale_x != LV_SCALE_NONE || |
| 117 |
draw_dsc->scale_y != LV_SCALE_NONE); |
| 118 |
|
| 119 |
if(has_recolor && !has_transform) |
| 120 |
_pxp_blit_recolor(dest_buf, clipped_img_area, dest_stride, dest_cf, |
| 121 |
src_buf, &src_area, src_stride, src_cf, draw_dsc); |
| 122 |
else if(has_transform) |
| 123 |
_pxp_blit_transform(dest_buf, clipped_img_area, dest_stride, dest_cf, |
| 124 |
src_buf, &src_area, src_stride, src_cf, draw_dsc); |
| 125 |
else |
| 126 |
_pxp_blit(dest_buf, clipped_img_area, dest_stride, dest_cf, |
| 127 |
src_buf, &src_area, src_stride, src_cf, draw_dsc->opa); |
| 128 |
} |
| 129 |
|
| 130 |
static void _pxp_blit_recolor(uint8_t * dest_buf, const lv_area_t * dest_area, int32_t dest_stride, |
| 131 |
lv_color_format_t dest_cf, const uint8_t * src_buf, const lv_area_t * src_area, |
| 132 |
int32_t src_stride, lv_color_format_t src_cf, const lv_draw_image_dsc_t * dsc) |
| 133 |
{ |
| 134 |
|
| 135 |
int32_t dest_w = lv_area_get_width(dest_area); |
| 136 |
int32_t dest_h = lv_area_get_height(dest_area); |
| 137 |
int32_t src_w = lv_area_get_width(src_area); |
| 138 |
int32_t src_h = lv_area_get_height(src_area); |
| 139 |
|
| 140 |
bool src_has_alpha = (src_cf == LV_COLOR_FORMAT_ARGB8888); |
| 141 |
uint8_t src_px_size = lv_color_format_get_size(src_cf); |
| 142 |
uint8_t dest_px_size = lv_color_format_get_size(dest_cf); |
| 143 |
|
| 144 |
lv_pxp_reset(); |
| 145 |
|
| 146 |
|
| 147 |
pxp_as_buffer_config_t asBufferConfig = { |
| 148 |
.pixelFormat = pxp_get_as_px_format(src_cf), |
| 149 |
.bufferAddr = (uint32_t)(src_buf + src_stride * src_area->y1 + src_px_size * src_area->x1), |
| 150 |
.pitchBytes = src_stride |
| 151 |
}; |
| 152 |
PXP_SetAlphaSurfaceBufferConfig(PXP_ID, &asBufferConfig); |
| 153 |
PXP_SetAlphaSurfacePosition(PXP_ID, 0U, 0U, src_w - 1U, src_h - 1U); |
| 154 |
|
| 155 |
|
| 156 |
PXP_SetProcessSurfacePosition(PXP_ID, 0xFFFFU, 0xFFFFU, 0U, 0U); |
| 157 |
PXP_SetProcessSurfaceBackGroundColor(PXP_ID, lv_color_to_u32(dsc->recolor)); |
| 158 |
|
| 159 |
|
| 160 |
pxp_output_buffer_config_t outputBufferConfig = { |
| 161 |
.pixelFormat = pxp_get_out_px_format(dest_cf), |
| 162 |
.interlacedMode = kPXP_OutputProgressive, |
| 163 |
.buffer0Addr = (uint32_t)(dest_buf + dest_stride * dest_area->y1 + dest_px_size * dest_area->x1), |
| 164 |
.buffer1Addr = (uint32_t)0U, |
| 165 |
.pitchBytes = dest_stride, |
| 166 |
.width = dest_w, |
| 167 |
.height = dest_h |
| 168 |
}; |
| 169 |
PXP_SetOutputBufferConfig(PXP_ID, &outputBufferConfig); |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
pxp_porter_duff_config_t pdConfig = { |
| 179 |
.enable = 1, |
| 180 |
.dstColorMode = kPXP_PorterDuffColorWithAlpha, |
| 181 |
.srcColorMode = kPXP_PorterDuffColorWithAlpha, |
| 182 |
.dstGlobalAlphaMode = kPXP_PorterDuffGlobalAlpha, |
| 183 |
.srcGlobalAlphaMode = src_has_alpha ? kPXP_PorterDuffLocalAlpha : kPXP_PorterDuffGlobalAlpha, |
| 184 |
.dstFactorMode = kPXP_PorterDuffFactorStraight, |
| 185 |
.srcFactorMode = kPXP_PorterDuffFactorInversed, |
| 186 |
.dstGlobalAlpha = dsc->recolor_opa, |
| 187 |
.srcGlobalAlpha = 0xff, |
| 188 |
.dstAlphaMode = kPXP_PorterDuffAlphaStraight, |
| 189 |
.srcAlphaMode = kPXP_PorterDuffAlphaStraight |
| 190 |
}; |
| 191 |
PXP_SetPorterDuffConfig(PXP_ID, &pdConfig); |
| 192 |
|
| 193 |
lv_pxp_run(); |
| 194 |
} |
| 195 |
|
| 196 |
static void _pxp_blit_transform(uint8_t * dest_buf, const lv_area_t * dest_area, int32_t dest_stride, |
| 197 |
lv_color_format_t dest_cf, const uint8_t * src_buf, const lv_area_t * src_area, |
| 198 |
int32_t src_stride, lv_color_format_t src_cf, const lv_draw_image_dsc_t * dsc) |
| 199 |
{ |
| 200 |
int32_t src_w = lv_area_get_width(src_area); |
| 201 |
int32_t src_h = lv_area_get_height(src_area); |
| 202 |
int32_t dest_w = lv_area_get_width(dest_area); |
| 203 |
int32_t dest_h = lv_area_get_height(dest_area); |
| 204 |
|
| 205 |
bool has_rotation = (dsc->rotation != 0); |
| 206 |
bool has_scale = (dsc->scale_x != LV_SCALE_NONE || dsc->scale_y != LV_SCALE_NONE); |
| 207 |
uint8_t src_px_size = lv_color_format_get_size(src_cf); |
| 208 |
uint8_t dest_px_size = lv_color_format_get_size(dest_cf); |
| 209 |
|
| 210 |
lv_pxp_reset(); |
| 211 |
|
| 212 |
if(has_rotation) { |
| 213 |
|
| 214 |
pxp_rotate_degree_t pxp_angle; |
| 215 |
switch(dsc->rotation) { |
| 216 |
case 0: |
| 217 |
pxp_angle = kPXP_Rotate0; |
| 218 |
break; |
| 219 |
case 900: |
| 220 |
pxp_angle = kPXP_Rotate90; |
| 221 |
break; |
| 222 |
case 1800: |
| 223 |
pxp_angle = kPXP_Rotate180; |
| 224 |
break; |
| 225 |
case 2700: |
| 226 |
pxp_angle = kPXP_Rotate270; |
| 227 |
break; |
| 228 |
default: |
| 229 |
pxp_angle = kPXP_Rotate0; |
| 230 |
} |
| 231 |
|
| 232 |
PXP_SetRotateConfig(PXP_ID, kPXP_RotateOutputBuffer, pxp_angle, kPXP_FlipDisable); |
| 233 |
} |
| 234 |
|
| 235 |
|
| 236 |
pxp_ps_buffer_config_t psBufferConfig = { |
| 237 |
.pixelFormat = pxp_get_ps_px_format(src_cf), |
| 238 |
.swapByte = false, |
| 239 |
.bufferAddr = (uint32_t)(src_buf + src_stride * src_area->y1 + src_px_size * src_area->x1), |
| 240 |
.bufferAddrU = 0, |
| 241 |
.bufferAddrV = 0, |
| 242 |
.pitchBytes = src_stride |
| 243 |
}; |
| 244 |
PXP_SetProcessSurfaceBufferConfig(PXP_ID, &psBufferConfig); |
| 245 |
PXP_SetProcessSurfacePosition(PXP_ID, 0U, 0U, dest_w - 1U, dest_h - 1U); |
| 246 |
|
| 247 |
if(has_scale) |
| 248 |
PXP_SetProcessSurfaceScaler(PXP_ID, src_w, src_h, dest_w, dest_h); |
| 249 |
|
| 250 |
|
| 251 |
PXP_SetAlphaSurfacePosition(PXP_ID, 0xFFFFU, 0xFFFFU, 0U, 0U); |
| 252 |
|
| 253 |
|
| 254 |
pxp_output_buffer_config_t outputBufferConfig = { |
| 255 |
.pixelFormat = pxp_get_out_px_format(dest_cf), |
| 256 |
.interlacedMode = kPXP_OutputProgressive, |
| 257 |
.buffer0Addr = (uint32_t)(dest_buf + dest_stride * (dest_area->y1) + dest_px_size * (dest_area->x1)), |
| 258 |
.buffer1Addr = (uint32_t)0U, |
| 259 |
.pitchBytes = dest_stride, |
| 260 |
.width = dest_w, |
| 261 |
.height = dest_h |
| 262 |
}; |
| 263 |
PXP_SetOutputBufferConfig(PXP_ID, &outputBufferConfig); |
| 264 |
|
| 265 |
lv_pxp_run(); |
| 266 |
} |
| 267 |
|
| 268 |
static void _pxp_blit(uint8_t * dest_buf, const lv_area_t * dest_area, int32_t dest_stride, |
| 269 |
lv_color_format_t dest_cf, const uint8_t * src_buf, const lv_area_t * src_area, |
| 270 |
int32_t src_stride, lv_color_format_t src_cf, lv_opa_t opa) |
| 271 |
{ |
| 272 |
int32_t dest_w = lv_area_get_width(dest_area); |
| 273 |
int32_t dest_h = lv_area_get_height(dest_area); |
| 274 |
int32_t src_w = lv_area_get_width(src_area); |
| 275 |
int32_t src_h = lv_area_get_height(src_area); |
| 276 |
|
| 277 |
bool src_has_alpha = (src_cf == LV_COLOR_FORMAT_ARGB8888); |
| 278 |
uint8_t src_px_size = lv_color_format_get_size(src_cf); |
| 279 |
uint8_t dest_px_size = lv_color_format_get_size(dest_cf); |
| 280 |
|
| 281 |
lv_pxp_reset(); |
| 282 |
|
| 283 |
pxp_as_blend_config_t asBlendConfig = { |
| 284 |
.alpha = opa, |
| 285 |
.invertAlpha = false, |
| 286 |
.alphaMode = kPXP_AlphaRop, |
| 287 |
.ropMode = kPXP_RopMergeAs |
| 288 |
}; |
| 289 |
|
| 290 |
if(opa >= (lv_opa_t)LV_OPA_MAX && !src_has_alpha) { |
| 291 |
|
| 292 |
PXP_SetProcessSurfacePosition(PXP_ID, 0xFFFFU, 0xFFFFU, 0U, 0U); |
| 293 |
} |
| 294 |
else { |
| 295 |
|
| 296 |
|
| 297 |
pxp_ps_buffer_config_t psBufferConfig = { |
| 298 |
.pixelFormat = pxp_get_ps_px_format(dest_cf), |
| 299 |
.swapByte = false, |
| 300 |
.bufferAddr = (uint32_t)(dest_buf + dest_stride * dest_area->y1 + dest_px_size * dest_area->x1), |
| 301 |
.bufferAddrU = 0U, |
| 302 |
.bufferAddrV = 0U, |
| 303 |
.pitchBytes = dest_stride |
| 304 |
}; |
| 305 |
|
| 306 |
if(opa >= (lv_opa_t)LV_OPA_MAX) |
| 307 |
asBlendConfig.alphaMode = src_has_alpha ? kPXP_AlphaEmbedded : kPXP_AlphaOverride; |
| 308 |
else |
| 309 |
asBlendConfig.alphaMode = src_has_alpha ? kPXP_AlphaMultiply : kPXP_AlphaOverride; |
| 310 |
|
| 311 |
PXP_SetProcessSurfaceBufferConfig(PXP_ID, &psBufferConfig); |
| 312 |
PXP_SetProcessSurfacePosition(PXP_ID, 0U, 0U, dest_w - 1U, dest_h - 1U); |
| 313 |
} |
| 314 |
|
| 315 |
|
| 316 |
pxp_as_buffer_config_t asBufferConfig = { |
| 317 |
.pixelFormat = pxp_get_as_px_format(src_cf), |
| 318 |
.bufferAddr = (uint32_t)(src_buf + src_stride * src_area->y1 + src_px_size * src_area->x1), |
| 319 |
.pitchBytes = src_stride |
| 320 |
}; |
| 321 |
PXP_SetAlphaSurfaceBufferConfig(PXP_ID, &asBufferConfig); |
| 322 |
PXP_SetAlphaSurfacePosition(PXP_ID, 0U, 0U, src_w - 1U, src_h - 1U); |
| 323 |
PXP_SetAlphaSurfaceBlendConfig(PXP_ID, &asBlendConfig); |
| 324 |
PXP_EnableAlphaSurfaceOverlayColorKey(PXP_ID, false); |
| 325 |
|
| 326 |
|
| 327 |
pxp_output_buffer_config_t outputBufferConfig = { |
| 328 |
.pixelFormat = pxp_get_out_px_format(dest_cf), |
| 329 |
.interlacedMode = kPXP_OutputProgressive, |
| 330 |
.buffer0Addr = (uint32_t)(dest_buf + dest_stride * dest_area->y1 + dest_px_size * dest_area->x1), |
| 331 |
.buffer1Addr = (uint32_t)0U, |
| 332 |
.pitchBytes = dest_stride, |
| 333 |
.width = dest_w, |
| 334 |
.height = dest_h |
| 335 |
}; |
| 336 |
PXP_SetOutputBufferConfig(PXP_ID, &outputBufferConfig); |
| 337 |
|
| 338 |
lv_pxp_run(); |
| 339 |
} |
| 340 |
|
| 341 |
#endif |
| 342 |
#endif |