|
328 | 328 | } |
329 | 329 |
|
330 | 330 |
|
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, |
333 | 333 | uint32_t bytes_per_pixel, copy_func_cb_t func, uint8_t rotate) |
334 | 334 | { |
335 | 335 | 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); |
340 | 340 | } 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); |
345 | 345 | } |
346 | 346 |
|
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; |
350 | 352 | size_t offset = y_start * copy_bytes_per_line + x_start * bytes_per_pixel; |
351 | 353 |
|
352 | 354 | // 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", |
353 | 355 | // 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)); |
354 | 356 |
|
355 | 357 | switch (rotate) { |
356 | 358 | 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); |
358 | 360 |
|
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); |
361 | 363 | } else { |
362 | 364 | 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; |
366 | 368 | } |
367 | 369 | } |
368 | 370 |
|
369 | 371 | break; |
370 | 372 |
|
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 |
383 | 374 | case RGB_BUS_ROTATION_90: |
384 | 375 | uint32_t j; |
385 | 376 | uint32_t i; |
386 | 377 |
|
387 | 378 | for (int y = y_start; y < y_end; y++) { |
388 | 379 | 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; |
392 | 396 | } |
393 | 397 | } |
394 | 398 | break; |
395 | 399 |
|
| 400 | + // SWAP_XY MIRROR_X |
396 | 401 | case RGB_BUS_ROTATION_270: |
397 | 402 | uint32_t jj; |
398 | 403 | uint32_t ii; |
399 | 404 |
|
400 | 405 | for (int y = y_start; y < y_end; y++) { |
401 | 406 | 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); |
405 | 410 | } |
406 | 411 | } |
407 | 412 | break; |
|
0 commit comments