X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavfilter%2Fbbox.c;h=3ed9045b02f96ebddf33cd97ce9800864fa55f1d;hb=3a3e8c35b63a40c4d59161097dc8652c15d13779;hp=be9b2e6b7352ebe668d93744b5b7948cd27e02b1;hpb=e427ba5c68a522b26a45bf7c61016d9349fab43d;p=ffmpeg diff --git a/libavfilter/bbox.c b/libavfilter/bbox.c index be9b2e6b735..3ed9045b02f 100644 --- a/libavfilter/bbox.c +++ b/libavfilter/bbox.c @@ -20,56 +20,71 @@ #include "bbox.h" -int ff_calculate_bounding_box(FFBoundingBox *bbox, - const uint8_t *data, int linesize, int w, int h, - int min_val) -{ - int x, y; - int start_x; - int start_y; - int end_x; - int end_y; - const uint8_t *line; - - /* left bound */ - for (start_x = 0; start_x < w; start_x++) - for (y = 0; y < h; y++) - if ((data[y * linesize + start_x] > min_val)) - goto outl; -outl: - if (start_x == w) /* no points found */ - return 0; - - /* right bound */ - for (end_x = w - 1; end_x >= start_x; end_x--) - for (y = 0; y < h; y++) - if ((data[y * linesize + end_x] > min_val)) - goto outr; -outr: - - /* top bound */ - line = data; - for (start_y = 0; start_y < h; start_y++) { - for (x = 0; x < w; x++) - if (line[x] > min_val) - goto outt; - line += linesize; - } -outt: +#define BBOX(type, name) \ +static int bbox_##name(FFBoundingBox *bbox, \ + const type *data, int linesize, int w, int h, \ + int min_val) \ +{ \ + int x, y; \ + int start_x; \ + int start_y; \ + int end_x; \ + int end_y; \ + const type *line; \ + \ + /* left bound */ \ + for (start_x = 0; start_x < w; start_x++) \ + for (y = 0; y < h; y++) \ + if ((data[y * linesize + start_x] > min_val)) \ + goto outl; \ +outl: \ + if (start_x == w) /* no points found */ \ + return 0; \ + \ + /* right bound */ \ + for (end_x = w - 1; end_x >= start_x; end_x--) \ + for (y = 0; y < h; y++) \ + if ((data[y * linesize + end_x] > min_val)) \ + goto outr; \ +outr: \ + \ + /* top bound */ \ + line = data; \ + for (start_y = 0; start_y < h; start_y++) { \ + for (x = 0; x < w; x++) \ + if (line[x] > min_val) \ + goto outt; \ + line += linesize; \ + } \ +outt: \ + \ + /* bottom bound */ \ + line = data + (h-1)*linesize; \ + for (end_y = h - 1; end_y >= start_y; end_y--) { \ + for (x = 0; x < w; x++) \ + if (line[x] > min_val) \ + goto outb; \ + line -= linesize; \ + } \ +outb: \ + \ + bbox->x1 = start_x; \ + bbox->y1 = start_y; \ + bbox->x2 = end_x; \ + bbox->y2 = end_y; \ + return 1; \ +} - /* bottom bound */ - line = data + (h-1)*linesize; - for (end_y = h - 1; end_y >= start_y; end_y--) { - for (x = 0; x < w; x++) - if (line[x] > min_val) - goto outb; - line -= linesize; - } -outb: +BBOX(uint8_t, 8) +BBOX(uint16_t, 16) - bbox->x1 = start_x; - bbox->y1 = start_y; - bbox->x2 = end_x; - bbox->y2 = end_y; - return 1; +int ff_calculate_bounding_box(FFBoundingBox *bbox, + const uint8_t *data, int linesize, + int w, int h, + int min_val, int depth) +{ + if (depth <= 8) + return bbox_8(bbox, data, linesize, w, h, min_val); + else + return bbox_16(bbox, (const uint16_t *)data, linesize / 2, w, h, min_val); }