AP_HAL_Linux: add shrink_8bpp() to VideoIn

This function shrinks a selected area on a 8bpp image.

The focus in this function was the performance, so this may not be the
clearer or the most understandable way to write it. The performance
was measured using GoogleBenchmark[1].

[1] - https://github.com/google/benchmark.git
This commit is contained in:
Ricardo de Almeida Gonzaga 2015-05-11 00:56:25 +00:00 committed by Lucas De Marchi
parent 9e243f50ca
commit 553d36c860
2 changed files with 44 additions and 0 deletions

View File

@ -250,6 +250,45 @@ void VideoIn::prepare_capture()
}
}
void VideoIn::shrink_8bpp(uint8_t *buffer, uint8_t *new_buffer,
uint32_t width, uint32_t height, uint32_t left,
uint32_t selection_width, uint32_t top,
uint32_t selection_height, uint32_t fx, uint32_t fy)
{
uint32_t i, j, k, kk, px, block_x, block_y, block_position;
uint32_t out_width = selection_width / fx;
uint32_t out_height = selection_height / fy;
uint32_t width_per_fy = width * fy;
uint32_t fx_fy = fx * fy;
uint32_t width_sum, out_width_sum = 0;
/* selection offset */
block_y = top * width;
block_position = left + block_y;
for (i = 0; i < out_height; i++) {
block_x = left;
for (j = 0; j < out_width; j++) {
px = 0;
width_sum = 0;
for(k = 0; k < fy; k++) {
for(kk = 0; kk < fx; kk++) {
px += buffer[block_position + kk + width_sum];
}
width_sum += width;
}
new_buffer[j + out_width_sum] = px / (fx_fy);
block_x += fx;
block_position = block_x + block_y;
}
block_y += width_per_fy;
out_width_sum += out_width;
}
}
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)

View File

@ -51,6 +51,11 @@ public:
uint32_t width, uint32_t height);
void prepare_capture();
static void shrink_8bpp(uint8_t *buffer, uint8_t *new_buffer,
uint32_t width, uint32_t height, uint32_t left,
uint32_t selection_width, uint32_t top,
uint32_t selection_height, uint32_t fx, uint32_t fy);
static void crop_8bpp(uint8_t *buffer, uint8_t *new_buffer,
uint32_t width, uint32_t left,
uint32_t crop_width, uint32_t top,