Message ID | 20180702215340.22095-1-cus@passwd.hu |
---|---|
State | Accepted |
Commit | 85bfcc46d192891891057085d36cb2daba4b5c4f |
Headers | show |
On Mon, 2 Jul 2018, Marton Balint wrote: > SDL from version 2.0.8 has support for full range YUV and specifying > BT601/BT709 color space for YUV->RGB conversion. Applied. Regards, Marton
2018-07-02 23:53 GMT+02:00, Marton Balint <cus@passwd.hu>: > SDL from version 2.0.8 has support for full range YUV and specifying > BT601/BT709 color space for YUV->RGB conversion. > > Signed-off-by: Marton Balint <cus@passwd.hu> > --- > fftools/ffplay.c | 18 ++++++++++++++++++ > 1 file changed, 18 insertions(+) > > diff --git a/fftools/ffplay.c b/fftools/ffplay.c > index 55cea32cae..368e262123 100644 > --- a/fftools/ffplay.c > +++ b/fftools/ffplay.c > @@ -954,6 +954,22 @@ static int upload_texture(SDL_Texture **tex, AVFrame > *frame, struct SwsContext * > return ret; > } > > +static void set_sdl_yuv_conversion_mode(AVFrame *frame) > +{ > +#if SDL_VERSION_ATLEAST(2,0,8) > + SDL_YUV_CONVERSION_MODE mode = SDL_YUV_CONVERSION_AUTOMATIC; > + if (frame && (frame->format == AV_PIX_FMT_YUV420P || frame->format == > AV_PIX_FMT_YUYV422 || frame->format == AV_PIX_FMT_UYVY422)) { What happens if the format is YUVJ420P? Carl Eugen
On Fri, 13 Jul 2018, Carl Eugen Hoyos wrote: > 2018-07-02 23:53 GMT+02:00, Marton Balint <cus@passwd.hu>: >> SDL from version 2.0.8 has support for full range YUV and specifying >> BT601/BT709 color space for YUV->RGB conversion. >> >> Signed-off-by: Marton Balint <cus@passwd.hu> >> --- >> fftools/ffplay.c | 18 ++++++++++++++++++ >> 1 file changed, 18 insertions(+) >> >> diff --git a/fftools/ffplay.c b/fftools/ffplay.c >> index 55cea32cae..368e262123 100644 >> --- a/fftools/ffplay.c >> +++ b/fftools/ffplay.c >> @@ -954,6 +954,22 @@ static int upload_texture(SDL_Texture **tex, AVFrame >> *frame, struct SwsContext * >> return ret; >> } >> >> +static void set_sdl_yuv_conversion_mode(AVFrame *frame) >> +{ >> +#if SDL_VERSION_ATLEAST(2,0,8) >> + SDL_YUV_CONVERSION_MODE mode = SDL_YUV_CONVERSION_AUTOMATIC; >> + if (frame && (frame->format == AV_PIX_FMT_YUV420P || frame->format == >> AV_PIX_FMT_YUYV422 || frame->format == AV_PIX_FMT_UYVY422)) { > > What happens if the format is YUVJ420P? That cannot happen, because the filtering code would automagically convert it to one of the supported texture formats (typically YUV420P). In theory we could add support for direct rendering YUVJ420P (without software conversion), but since that format is deprecated, I'd rather not clutter the code with it. Regards, Marton
diff --git a/fftools/ffplay.c b/fftools/ffplay.c index 55cea32cae..368e262123 100644 --- a/fftools/ffplay.c +++ b/fftools/ffplay.c @@ -954,6 +954,22 @@ static int upload_texture(SDL_Texture **tex, AVFrame *frame, struct SwsContext * return ret; } +static void set_sdl_yuv_conversion_mode(AVFrame *frame) +{ +#if SDL_VERSION_ATLEAST(2,0,8) + SDL_YUV_CONVERSION_MODE mode = SDL_YUV_CONVERSION_AUTOMATIC; + if (frame && (frame->format == AV_PIX_FMT_YUV420P || frame->format == AV_PIX_FMT_YUYV422 || frame->format == AV_PIX_FMT_UYVY422)) { + if (frame->color_range == AVCOL_RANGE_JPEG) + mode = SDL_YUV_CONVERSION_JPEG; + else if (frame->colorspace == AVCOL_SPC_BT709) + mode = SDL_YUV_CONVERSION_BT709; + else if (frame->colorspace == AVCOL_SPC_BT470BG || frame->colorspace == AVCOL_SPC_SMPTE170M || frame->colorspace == AVCOL_SPC_SMPTE240M) + mode = SDL_YUV_CONVERSION_BT601; + } + SDL_SetYUVConversionMode(mode); +#endif +} + static void video_image_display(VideoState *is) { Frame *vp; @@ -1015,7 +1031,9 @@ static void video_image_display(VideoState *is) vp->flip_v = vp->frame->linesize[0] < 0; } + set_sdl_yuv_conversion_mode(vp->frame); SDL_RenderCopyEx(renderer, is->vid_texture, NULL, &rect, 0, NULL, vp->flip_v ? SDL_FLIP_VERTICAL : 0); + set_sdl_yuv_conversion_mode(NULL); if (sp) { #if USE_ONEPASS_SUBTITLE_RENDER SDL_RenderCopy(renderer, is->sub_texture, NULL, &rect);
SDL from version 2.0.8 has support for full range YUV and specifying BT601/BT709 color space for YUV->RGB conversion. Signed-off-by: Marton Balint <cus@passwd.hu> --- fftools/ffplay.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)