Browse Source

AP_HAL_Linux: improve crop_8bpp() performance

Based on gbenchmark metrics.

Before:
Benchmark             Time(ns)    CPU(ns) Iterations
----------------------------------------------------
BM_Crop8bpp/64/64         3206       3197     198113
BM_Crop8bpp/240/240      38166      38181      18421
BM_Crop8bpp/640/480     193589     193317       3621

After:
Benchmark             Time(ns)    CPU(ns) Iterations
----------------------------------------------------
BM_Crop8bpp/64/64         2652       2657     232103
BM_Crop8bpp/240/240      33532      33506      20792
BM_Crop8bpp/640/480     187848     188201       3684
master
Ricardo de Almeida Gonzaga 9 years ago committed by Lucas De Marchi
parent
commit
3748760ead
  1. 14
      libraries/AP_HAL_Linux/VideoIn.cpp

14
libraries/AP_HAL_Linux/VideoIn.cpp

@ -293,11 +293,17 @@ void VideoIn::crop_8bpp(uint8_t *buffer, uint8_t *new_buffer, @@ -293,11 +293,17 @@ void VideoIn::crop_8bpp(uint8_t *buffer, uint8_t *new_buffer,
uint32_t width, uint32_t left, uint32_t crop_width,
uint32_t top, uint32_t crop_height)
{
for (uint32_t j = top; j < top + crop_height; j++) {
for (uint32_t i = left; i < left + crop_width; i++) {
new_buffer[(i - left) + (j - top) * crop_width] =
buffer[i + j * width];
uint32_t crop_x = left + crop_width;
uint32_t crop_y = top + crop_height;
uint32_t buffer_index = top * width;
uint32_t new_buffer_index = 0;
for (uint32_t j = top; j < crop_y; j++) {
for (uint32_t i = left; i < crop_x; i++) {
new_buffer[i - left + new_buffer_index] = buffer[i + buffer_index];
}
buffer_index += width;
new_buffer_index += crop_width;
}
}

Loading…
Cancel
Save