summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2014-12-27 04:18:44 +0100
committerMichael Niedermayer <michaelni@gmx.at>2014-12-27 19:09:05 +0100
commitcc91488588acc81766c3f2d644d649ece5a4166e (patch)
tree09d6609459b7e8a3fcaa6286cb2934076f43a10c
parented96830afc05fb917443da09bec881f61e57003d (diff)
avfilter/vf_cropdetect: Factorize duplicated code using a macro
This simplifies subsequent changes Reviewed-by: Benoit Fouet <benoit.fouet@free.fr> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r--libavfilter/vf_cropdetect.c34
1 files changed, 10 insertions, 24 deletions
diff --git a/libavfilter/vf_cropdetect.c b/libavfilter/vf_cropdetect.c
index b01407866a..0ba2a38b0e 100644
--- a/libavfilter/vf_cropdetect.c
+++ b/libavfilter/vf_cropdetect.c
@@ -137,33 +137,19 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
s->frame_nb = 1;
}
- for (y = 0; y < s->y1; y++) {
- if (checkline(ctx, frame->data[0] + frame->linesize[0] * y, bpp, frame->width, bpp) > s->limit) {
- s->y1 = y;
- break;
- }
+#define FIND(DST, FROM, NOEND, INC, STEP0, STEP1, LEN) \
+ for (y = FROM; NOEND; INC) {\
+ if (checkline(ctx, frame->data[0] + STEP0 * y, STEP1, LEN, bpp) > s->limit) {\
+ DST = y;\
+ break;\
+ }\
}
- for (y = frame->height - 1; y > FFMAX(s->y2, s->y1); y--) {
- if (checkline(ctx, frame->data[0] + frame->linesize[0] * y, bpp, frame->width, bpp) > s->limit) {
- s->y2 = y;
- break;
- }
- }
-
- for (y = 0; y < s->x1; y++) {
- if (checkline(ctx, frame->data[0] + bpp*y, frame->linesize[0], frame->height, bpp) > s->limit) {
- s->x1 = y;
- break;
- }
- }
+ FIND(s->y1, 0, y < s->y1, y++, frame->linesize[0], bpp, frame->width);
+ FIND(s->y2, frame->height - 1, y > FFMAX(s->y2, s->y1), y--, frame->linesize[0], bpp, frame->width);
+ FIND(s->x1, 0, y < s->x1, y++, bpp, frame->linesize[0], frame->height);
+ FIND(s->x2, frame->width - 1, y > FFMAX(s->x2, s->x1), y--, bpp, frame->linesize[0], frame->height);
- for (y = frame->width - 1; y > FFMAX(s->x2, s->x1); y--) {
- if (checkline(ctx, frame->data[0] + bpp*y, frame->linesize[0], frame->height, bpp) > s->limit) {
- s->x2 = y;
- break;
- }
- }
// round x and y (up), important for yuv colorspaces
// make sure they stay rounded!