diff --git a/ffplay.c b/ffplay.c index 07d7836679..90c18f4aca 100644 --- a/ffplay.c +++ b/ffplay.c @@ -234,6 +234,7 @@ typedef struct VideoState { #if !CONFIG_AVFILTER struct SwsContext *img_convert_ctx; #endif + SDL_Rect last_display_rect; char filename[1024]; int width, height, xleft, ytop; @@ -461,6 +462,42 @@ static inline void fill_rectangle(SDL_Surface *screen, SDL_UpdateRect(screen, x, y, w, h); } +/* draw only the border of a rectangle */ +static void fill_border(int xleft, int ytop, int width, int height, int x, int y, int w, int h, int color, int update) +{ + int w1, w2, h1, h2; + + /* fill the background */ + w1 = x; + if (w1 < 0) + w1 = 0; + w2 = width - (x + w); + if (w2 < 0) + w2 = 0; + h1 = y; + if (h1 < 0) + h1 = 0; + h2 = height - (y + h); + if (h2 < 0) + h2 = 0; + fill_rectangle(screen, + xleft, ytop, + w1, height, + color, update); + fill_rectangle(screen, + xleft + width - w2, ytop, + w2, height, + color, update); + fill_rectangle(screen, + xleft + w1, ytop, + width - w1 - w2, h1, + color, update); + fill_rectangle(screen, + xleft + w1, ytop + height - h2, + width - w1 - w2, h2, + color, update); +} + #define ALPHA_BLEND(a, oldp, newp, s)\ ((((oldp << s) * (255 - (a))) + (newp * (a))) / (255 << s)) @@ -761,6 +798,12 @@ static void video_image_display(VideoState *is) calculate_display_rect(&rect, is->xleft, is->ytop, is->width, is->height, vp); SDL_DisplayYUVOverlay(vp->bmp, &rect); + + if (rect.x != is->last_display_rect.x || rect.y != is->last_display_rect.y || rect.w != is->last_display_rect.w || rect.h != is->last_display_rect.h || is->force_refresh) { + int bgcolor = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00); + fill_border(is->xleft, is->ytop, is->width, is->height, rect.x, rect.y, rect.w, rect.h, bgcolor, 1); + is->last_display_rect = rect; + } } }