00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "bbox.h"
00022
00023 int ff_calculate_bounding_box(FFBoundingBox *bbox,
00024 const uint8_t *data, int linesize, int w, int h,
00025 int min_val)
00026 {
00027 int x, y;
00028 int start_x;
00029 int start_y;
00030 int end_x;
00031 int end_y;
00032 const uint8_t *line;
00033
00034
00035 for (start_x = 0; start_x < w; start_x++)
00036 for (y = 0; y < h; y++)
00037 if ((data[y * linesize + start_x] > min_val))
00038 goto outl;
00039 outl:
00040 if (start_x == w)
00041 return 0;
00042
00043
00044 for (end_x = w - 1; end_x >= start_x; end_x--)
00045 for (y = 0; y < h; y++)
00046 if ((data[y * linesize + end_x] > min_val))
00047 goto outr;
00048 outr:
00049
00050
00051 line = data;
00052 for (start_y = 0; start_y < h; start_y++) {
00053 for (x = 0; x < w; x++)
00054 if (line[x] > min_val)
00055 goto outt;
00056 line += linesize;
00057 }
00058 outt:
00059
00060
00061 line = data + (h-1)*linesize;
00062 for (end_y = h - 1; end_y >= start_y; end_y--) {
00063 for (x = 0; x < w; x++)
00064 if (line[x] > min_val)
00065 goto outb;
00066 line -= linesize;
00067 }
00068 outb:
00069
00070 bbox->x1 = start_x;
00071 bbox->y1 = start_y;
00072 bbox->x2 = end_x;
00073 bbox->y2 = end_y;
00074 return 1;
00075 }