Skip to content

Commit 8ec4bf5

Browse files
committed
RGB driver work.
1 parent f029837 commit 8ec4bf5

File tree

1 file changed

+42
-37
lines changed

1 file changed

+42
-37
lines changed

ext_mod/lcd_bus/esp32_src/rgb_bus_rotation.c

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -328,80 +328,85 @@
328328
}
329329

330330

331-
void copy_pixels(uint8_t *to, uint8_t *from, uint32_t x_start, uint32_t y_start,
332-
uint32_t x_end, uint32_t y_end, uint32_t h_res, uint32_t v_res,
331+
void copy_pixels(uint8_t *dst, uint8_t *src, uint32_t x_start, uint32_t y_start,
332+
uint32_t x_end, uint32_t y_end, uint32_t d_width, uint32_t d_height,
333333
uint32_t bytes_per_pixel, copy_func_cb_t func, uint8_t rotate)
334334
{
335335
if (rotate == RGB_BUS_ROTATION_90 || rotate == RGB_BUS_ROTATION_270) {
336-
x_start = MIN(x_start, v_res);
337-
x_end = MIN(x_end, v_res);
338-
y_start = MIN(y_start, h_res);
339-
y_end = MIN(y_end, h_res);
336+
x_start = MIN(x_start, d_height);
337+
x_end = MIN(x_end, d_height);
338+
y_start = MIN(y_start, d_width);
339+
y_end = MIN(y_end, d_width);
340340
} else {
341-
x_start = MIN(x_start, h_res);
342-
x_end = MIN(x_end, h_res);
343-
y_start = MIN(y_start, v_res);
344-
y_end = MIN(y_end, v_res);
341+
x_start = MIN(x_start, d_width);
342+
x_end = MIN(x_end, d_width);
343+
y_start = MIN(y_start, d_height);
344+
y_end = MIN(y_end, d_height);
345345
}
346346

347-
uint16_t copy_bytes_per_line = (x_end - x_start) * (uint16_t)bytes_per_pixel;
348-
int pixels_per_line = h_res;
349-
uint32_t bytes_per_line = bytes_per_pixel * pixels_per_line;
347+
uint16_t src_bytes_per_line = (x_end - x_start + 1) * (uint16_t)bytes_per_pixel;
348+
uint32_t dst_bytes_per_line = bytes_per_pixel * d_width;
349+
size_t offset = y_start * src_bytes_per_line + x_start * bytes_per_pixel;
350+
351+
uint32_t copy_bytes_per_line = (x_end - x_start) * bytes_per_pixel;
350352
size_t offset = y_start * copy_bytes_per_line + x_start * bytes_per_pixel;
351353

352354
// mp_printf(&mp_plat_print, "x_start=%lu, y_start=%lu, x_end=%lu, y_end=%lu, copy_bytes_per_line=%u, bytes_per_line=%lu, %lu\n",
353355
// x_start, y_start, x_end, y_end, copy_bytes_per_line, bytes_per_line, (uint32_t)((y_start * h_res + x_start) * bytes_per_pixel));
354356

355357
switch (rotate) {
356358
case RGB_BUS_ROTATION_0:
357-
uint8_t *fb = to + ((y_start * h_res + x_start) * bytes_per_pixel);
359+
uint8_t *fb = dst + ((y_start * d_width + x_start) * bytes_per_pixel);
358360

359-
if (x_start == 0 && x_end == (h_res - 1)) {
360-
memcpy(fb, from, h_res * (y_end - y_start + 1) * bytes_per_pixel);
361+
if (x_start == 0 && x_end == (d_width - 1)) {
362+
memcpy(fb, src, d_width * (y_end - y_start + 1) * bytes_per_pixel);
361363
} else {
362364
for (int y = y_start; y < y_end; y++) {
363-
memcpy(fb, from, copy_bytes_per_line);
364-
fb += bytes_per_line;
365-
from += copy_bytes_per_line;
365+
memcpy(fb, src, src_bytes_per_line);
366+
fb += dst_bytes_per_line;
367+
from += src_bytes_per_line;
366368
}
367369
}
368370

369371
break;
370372

371-
case RGB_BUS_ROTATION_180:
372-
uint32_t index;
373-
for (int y = y_start; y < y_end; y++) {
374-
index = ((v_res - 1 - y) * h_res + (h_res - 1 - x_start)) * bytes_per_pixel;
375-
for (size_t x = x_start; x < x_end; x++) {
376-
func(to + index, from);
377-
index -= bytes_per_pixel;
378-
from += bytes_per_pixel;
379-
}
380-
}
381-
break;
382-
373+
// SWAP_XY MIRROR_Y
383374
case RGB_BUS_ROTATION_90:
384375
uint32_t j;
385376
uint32_t i;
386377

387378
for (int y = y_start; y < y_end; y++) {
388379
for (int x = x_start; x < x_end; x++) {
389-
j = y * copy_bytes_per_line + x * bytes_per_pixel - offset;
390-
i = ((v_res - 1 - x) * h_res + y) * bytes_per_pixel;
391-
func(to + i, from + j);
380+
j = y * src_bytes_per_line + x * bytes_per_pixel - offset;
381+
i = ((d_height - 1 - x) * d_width + y) * bytes_per_pixel;
382+
func(dst + i, src + j);
383+
}
384+
}
385+
break;
386+
387+
// MIRROR_X MIRROR_Y
388+
case RGB_BUS_ROTATION_180:
389+
uint32_t index;
390+
for (int y = y_start; y < y_end; y++) {
391+
index = ((d_height - 1 - y) * d_width + (d_width - 1 - x_start)) * bytes_per_pixel;
392+
for (size_t x = x_start; x < x_end; x++) {
393+
func(dst + index, src);
394+
index -= bytes_per_pixel;
395+
from += bytes_per_pixel;
392396
}
393397
}
394398
break;
395399

400+
// SWAP_XY MIRROR_X
396401
case RGB_BUS_ROTATION_270:
397402
uint32_t jj;
398403
uint32_t ii;
399404

400405
for (int y = y_start; y < y_end; y++) {
401406
for (int x = x_start; x < x_end; x++) {
402-
jj = y * copy_bytes_per_line + x * bytes_per_pixel - offset;
403-
ii = (x * h_res + h_res - 1 - y) * bytes_per_pixel;
404-
func(to + ii, from + jj);
407+
jj = y * src_bytes_per_line + x * bytes_per_pixel - offset;
408+
ii = (x * d_width + d_width - 1 - y) * bytes_per_pixel;
409+
func(dst + ii, src + jj);
405410
}
406411
}
407412
break;

0 commit comments

Comments
 (0)