From 347167ecf5ece40ccd9d76c515526c8e6551ac35 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Thu, 4 Aug 2011 01:34:49 +0200 Subject: [PATCH 1/2] lsws: use array for storing the supported in/out information Also remove the unnecessary isSupportedIn/Out macros. Make the code more compact/readable, and simplify the access to lsws-specific pixel format information. Signed-off-by: Luca Barbato --- libswscale/utils.c | 201 ++++++++++++++++++--------------------------- 1 file changed, 79 insertions(+), 122 deletions(-) diff --git a/libswscale/utils.c b/libswscale/utils.c index c6abb6b446..5d478b7a5a 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -63,133 +63,90 @@ const char *swscale_license(void) #define RET 0xC3 //near return opcode for x86 -#define isSupportedIn(x) ( \ - (x)==PIX_FMT_YUV420P \ - || (x)==PIX_FMT_YUVA420P \ - || (x)==PIX_FMT_YUYV422 \ - || (x)==PIX_FMT_UYVY422 \ - || (x)==PIX_FMT_RGB48BE \ - || (x)==PIX_FMT_RGB48LE \ - || (x)==PIX_FMT_RGB32 \ - || (x)==PIX_FMT_RGB32_1 \ - || (x)==PIX_FMT_BGR48BE \ - || (x)==PIX_FMT_BGR48LE \ - || (x)==PIX_FMT_BGR24 \ - || (x)==PIX_FMT_BGR565LE \ - || (x)==PIX_FMT_BGR565BE \ - || (x)==PIX_FMT_BGR555LE \ - || (x)==PIX_FMT_BGR555BE \ - || (x)==PIX_FMT_BGR32 \ - || (x)==PIX_FMT_BGR32_1 \ - || (x)==PIX_FMT_RGB24 \ - || (x)==PIX_FMT_RGB565LE \ - || (x)==PIX_FMT_RGB565BE \ - || (x)==PIX_FMT_RGB555LE \ - || (x)==PIX_FMT_RGB555BE \ - || (x)==PIX_FMT_GRAY8 \ - || (x)==PIX_FMT_Y400A \ - || (x)==PIX_FMT_YUV410P \ - || (x)==PIX_FMT_YUV440P \ - || (x)==PIX_FMT_NV12 \ - || (x)==PIX_FMT_NV21 \ - || (x)==PIX_FMT_GRAY16BE \ - || (x)==PIX_FMT_GRAY16LE \ - || (x)==PIX_FMT_YUV444P \ - || (x)==PIX_FMT_YUV422P \ - || (x)==PIX_FMT_YUV411P \ - || (x)==PIX_FMT_YUVJ420P \ - || (x)==PIX_FMT_YUVJ422P \ - || (x)==PIX_FMT_YUVJ440P \ - || (x)==PIX_FMT_YUVJ444P \ - || (x)==PIX_FMT_PAL8 \ - || (x)==PIX_FMT_BGR8 \ - || (x)==PIX_FMT_RGB8 \ - || (x)==PIX_FMT_BGR4_BYTE \ - || (x)==PIX_FMT_RGB4_BYTE \ - || (x)==PIX_FMT_YUV440P \ - || (x)==PIX_FMT_MONOWHITE \ - || (x)==PIX_FMT_MONOBLACK \ - || (x)==PIX_FMT_YUV420P9LE \ - || (x)==PIX_FMT_YUV444P9LE \ - || (x)==PIX_FMT_YUV420P10LE \ - || (x)==PIX_FMT_YUV422P10LE \ - || (x)==PIX_FMT_YUV444P10LE \ - || (x)==PIX_FMT_YUV420P16LE \ - || (x)==PIX_FMT_YUV422P16LE \ - || (x)==PIX_FMT_YUV444P16LE \ - || (x)==PIX_FMT_YUV420P9BE \ - || (x)==PIX_FMT_YUV444P9BE \ - || (x)==PIX_FMT_YUV420P10BE \ - || (x)==PIX_FMT_YUV444P10BE \ - || (x)==PIX_FMT_YUV422P10BE \ - || (x)==PIX_FMT_YUV420P16BE \ - || (x)==PIX_FMT_YUV422P16BE \ - || (x)==PIX_FMT_YUV444P16BE \ - ) +typedef struct FormatEntry { + int is_supported_in, is_supported_out; +} FormatEntry; + +const static FormatEntry format_entries[PIX_FMT_NB] = { + [PIX_FMT_YUV420P] = { 1 , 1 }, + [PIX_FMT_YUYV422] = { 1 , 1 }, + [PIX_FMT_RGB24] = { 1 , 1 }, + [PIX_FMT_BGR24] = { 1 , 1 }, + [PIX_FMT_YUV422P] = { 1 , 1 }, + [PIX_FMT_YUV444P] = { 1 , 1 }, + [PIX_FMT_YUV410P] = { 1 , 1 }, + [PIX_FMT_YUV411P] = { 1 , 1 }, + [PIX_FMT_GRAY8] = { 1 , 1 }, + [PIX_FMT_MONOWHITE] = { 1 , 1 }, + [PIX_FMT_MONOBLACK] = { 1 , 1 }, + [PIX_FMT_PAL8] = { 1 , 0 }, + [PIX_FMT_YUVJ420P] = { 1 , 1 }, + [PIX_FMT_YUVJ422P] = { 1 , 1 }, + [PIX_FMT_YUVJ444P] = { 1 , 1 }, + [PIX_FMT_UYVY422] = { 1 , 1 }, + [PIX_FMT_UYYVYY411] = { 0 , 0 }, + [PIX_FMT_BGR8] = { 1 , 1 }, + [PIX_FMT_BGR4] = { 0 , 1 }, + [PIX_FMT_BGR4_BYTE] = { 1 , 1 }, + [PIX_FMT_RGB8] = { 1 , 1 }, + [PIX_FMT_RGB4] = { 0 , 1 }, + [PIX_FMT_RGB4_BYTE] = { 1 , 1 }, + [PIX_FMT_NV12] = { 1 , 1 }, + [PIX_FMT_NV21] = { 1 , 1 }, + [PIX_FMT_ARGB] = { 1 , 1 }, + [PIX_FMT_RGBA] = { 1 , 1 }, + [PIX_FMT_ABGR] = { 1 , 1 }, + [PIX_FMT_BGRA] = { 1 , 1 }, + [PIX_FMT_GRAY16BE] = { 1 , 1 }, + [PIX_FMT_GRAY16LE] = { 1 , 1 }, + [PIX_FMT_YUV440P] = { 1 , 1 }, + [PIX_FMT_YUVJ440P] = { 1 , 1 }, + [PIX_FMT_YUVA420P] = { 1 , 1 }, + [PIX_FMT_RGB48BE] = { 1 , 1 }, + [PIX_FMT_RGB48LE] = { 1 , 1 }, + [PIX_FMT_RGB565BE] = { 1 , 1 }, + [PIX_FMT_RGB565LE] = { 1 , 1 }, + [PIX_FMT_RGB555BE] = { 1 , 1 }, + [PIX_FMT_RGB555LE] = { 1 , 1 }, + [PIX_FMT_BGR565BE] = { 1 , 1 }, + [PIX_FMT_BGR565LE] = { 1 , 1 }, + [PIX_FMT_BGR555BE] = { 1 , 1 }, + [PIX_FMT_BGR555LE] = { 1 , 1 }, + [PIX_FMT_YUV420P16LE] = { 1 , 1 }, + [PIX_FMT_YUV420P16BE] = { 1 , 1 }, + [PIX_FMT_YUV422P16LE] = { 1 , 1 }, + [PIX_FMT_YUV422P16BE] = { 1 , 1 }, + [PIX_FMT_YUV444P16LE] = { 1 , 1 }, + [PIX_FMT_YUV444P16BE] = { 1 , 1 }, + [PIX_FMT_RGB444LE] = { 0 , 1 }, + [PIX_FMT_RGB444BE] = { 0 , 1 }, + [PIX_FMT_BGR444LE] = { 0 , 1 }, + [PIX_FMT_BGR444BE] = { 0 , 1 }, + [PIX_FMT_Y400A] = { 1 , 0 }, + [PIX_FMT_BGR48BE] = { 1 , 1 }, + [PIX_FMT_BGR48LE] = { 1 , 1 }, + [PIX_FMT_YUV420P9BE] = { 1 , 1 }, + [PIX_FMT_YUV420P9LE] = { 1 , 1 }, + [PIX_FMT_YUV420P10BE] = { 1 , 1 }, + [PIX_FMT_YUV420P10LE] = { 1 , 1 }, + [PIX_FMT_YUV422P10BE] = { 1 , 1 }, + [PIX_FMT_YUV422P10LE] = { 1 , 1 }, + [PIX_FMT_YUV444P9BE] = { 1 , 0 }, + [PIX_FMT_YUV444P9LE] = { 1 , 0 }, + [PIX_FMT_YUV444P10BE] = { 1 , 0 }, + [PIX_FMT_YUV444P10LE] = { 1 , 0 }, +}; int sws_isSupportedInput(enum PixelFormat pix_fmt) { - return isSupportedIn(pix_fmt); + return (unsigned)pix_fmt < PIX_FMT_NB ? + format_entries[pix_fmt].is_supported_in : 0; } -#define isSupportedOut(x) ( \ - (x)==PIX_FMT_YUV420P \ - || (x)==PIX_FMT_YUVA420P \ - || (x)==PIX_FMT_YUYV422 \ - || (x)==PIX_FMT_UYVY422 \ - || (x)==PIX_FMT_YUV444P \ - || (x)==PIX_FMT_YUV422P \ - || (x)==PIX_FMT_YUV411P \ - || (x)==PIX_FMT_YUVJ420P \ - || (x)==PIX_FMT_YUVJ422P \ - || (x)==PIX_FMT_YUVJ440P \ - || (x)==PIX_FMT_YUVJ444P \ - || isRGBinBytes(x) \ - || isBGRinBytes(x) \ - || (x)==PIX_FMT_RGB565LE \ - || (x)==PIX_FMT_RGB565BE \ - || (x)==PIX_FMT_RGB555LE \ - || (x)==PIX_FMT_RGB555BE \ - || (x)==PIX_FMT_RGB444LE \ - || (x)==PIX_FMT_RGB444BE \ - || (x)==PIX_FMT_BGR565LE \ - || (x)==PIX_FMT_BGR565BE \ - || (x)==PIX_FMT_BGR555LE \ - || (x)==PIX_FMT_BGR555BE \ - || (x)==PIX_FMT_BGR444LE \ - || (x)==PIX_FMT_BGR444BE \ - || (x)==PIX_FMT_RGB8 \ - || (x)==PIX_FMT_BGR8 \ - || (x)==PIX_FMT_RGB4_BYTE \ - || (x)==PIX_FMT_BGR4_BYTE \ - || (x)==PIX_FMT_RGB4 \ - || (x)==PIX_FMT_BGR4 \ - || (x)==PIX_FMT_MONOBLACK \ - || (x)==PIX_FMT_MONOWHITE \ - || (x)==PIX_FMT_NV12 \ - || (x)==PIX_FMT_NV21 \ - || (x)==PIX_FMT_GRAY16BE \ - || (x)==PIX_FMT_GRAY16LE \ - || (x)==PIX_FMT_GRAY8 \ - || (x)==PIX_FMT_YUV410P \ - || (x)==PIX_FMT_YUV440P \ - || (x)==PIX_FMT_YUV420P9LE \ - || (x)==PIX_FMT_YUV420P10LE \ - || (x)==PIX_FMT_YUV420P16LE \ - || (x)==PIX_FMT_YUV422P10LE \ - || (x)==PIX_FMT_YUV422P16LE \ - || (x)==PIX_FMT_YUV444P16LE \ - || (x)==PIX_FMT_YUV420P9BE \ - || (x)==PIX_FMT_YUV420P10BE \ - || (x)==PIX_FMT_YUV422P10BE \ - || (x)==PIX_FMT_YUV420P16BE \ - || (x)==PIX_FMT_YUV422P16BE \ - || (x)==PIX_FMT_YUV444P16BE \ - ) - int sws_isSupportedOutput(enum PixelFormat pix_fmt) { - return isSupportedOut(pix_fmt); + return (unsigned)pix_fmt < PIX_FMT_NB ? + format_entries[pix_fmt].is_supported_out : 0; } extern const int32_t ff_yuv2rgb_coeffs[8][4]; @@ -798,11 +755,11 @@ int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter) unscaled = (srcW == dstW && srcH == dstH); - if (!isSupportedIn(srcFormat)) { + if (!sws_isSupportedInput(srcFormat)) { av_log(c, AV_LOG_ERROR, "%s is not supported as input pixel format\n", sws_format_name(srcFormat)); return AVERROR(EINVAL); } - if (!isSupportedOut(dstFormat)) { + if (!sws_isSupportedOutput(dstFormat)) { av_log(c, AV_LOG_ERROR, "%s is not supported as output pixel format\n", sws_format_name(dstFormat)); return AVERROR(EINVAL); } From 6a92551234c6966ab59d00052076b79133e6e7e5 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Thu, 4 Aug 2011 17:53:44 +0200 Subject: [PATCH 2/2] lsws: remove optimization debug logs in sws_init_context() The logged information is possibly false, and it tends to be outdated after each change since the logging code needs to be manually updated. Simplify and prevent confusing wrong debug messages. Signed-off-by: Luca Barbato --- libswscale/utils.c | 66 ---------------------------------------------- 1 file changed, 66 deletions(-) diff --git a/libswscale/utils.c b/libswscale/utils.c index 5d478b7a5a..525a370e7c 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -1062,72 +1062,6 @@ int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter) else if (HAVE_ALTIVEC && cpu_flags & AV_CPU_FLAG_ALTIVEC) av_log(c, AV_LOG_INFO, "using AltiVec\n"); else av_log(c, AV_LOG_INFO, "using C\n"); - if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) { - if (c->canMMX2BeUsed && (flags&SWS_FAST_BILINEAR)) - av_log(c, AV_LOG_VERBOSE, "using FAST_BILINEAR MMX2 scaler for horizontal scaling\n"); - else { - if (c->hLumFilterSize==4) - av_log(c, AV_LOG_VERBOSE, "using 4-tap MMX scaler for horizontal luminance scaling\n"); - else if (c->hLumFilterSize==8) - av_log(c, AV_LOG_VERBOSE, "using 8-tap MMX scaler for horizontal luminance scaling\n"); - else - av_log(c, AV_LOG_VERBOSE, "using n-tap MMX scaler for horizontal luminance scaling\n"); - - if (c->hChrFilterSize==4) - av_log(c, AV_LOG_VERBOSE, "using 4-tap MMX scaler for horizontal chrominance scaling\n"); - else if (c->hChrFilterSize==8) - av_log(c, AV_LOG_VERBOSE, "using 8-tap MMX scaler for horizontal chrominance scaling\n"); - else - av_log(c, AV_LOG_VERBOSE, "using n-tap MMX scaler for horizontal chrominance scaling\n"); - } - } else { -#if HAVE_MMX - av_log(c, AV_LOG_VERBOSE, "using x86 asm scaler for horizontal scaling\n"); -#else - if (flags & SWS_FAST_BILINEAR) - av_log(c, AV_LOG_VERBOSE, "using FAST_BILINEAR C scaler for horizontal scaling\n"); - else - av_log(c, AV_LOG_VERBOSE, "using C scaler for horizontal scaling\n"); -#endif - } - if (isPlanarYUV(dstFormat)) { - if (c->vLumFilterSize==1) - av_log(c, AV_LOG_VERBOSE, "using 1-tap %s \"scaler\" for vertical scaling (YV12 like)\n", - (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C"); - else - av_log(c, AV_LOG_VERBOSE, "using n-tap %s scaler for vertical scaling (YV12 like)\n", - (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C"); - } else { - if (c->vLumFilterSize==1 && c->vChrFilterSize==2) - av_log(c, AV_LOG_VERBOSE, "using 1-tap %s \"scaler\" for vertical luminance scaling (BGR)\n" - " 2-tap scaler for vertical chrominance scaling (BGR)\n", - (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C"); - else if (c->vLumFilterSize==2 && c->vChrFilterSize==2) - av_log(c, AV_LOG_VERBOSE, "using 2-tap linear %s scaler for vertical scaling (BGR)\n", - (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C"); - else - av_log(c, AV_LOG_VERBOSE, "using n-tap %s scaler for vertical scaling (BGR)\n", - (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C"); - } - - if (dstFormat==PIX_FMT_BGR24) - av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR24 converter\n", - (HAVE_MMX2 && cpu_flags & AV_CPU_FLAG_MMX2) ? "MMX2" : - ((HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C")); - else if (dstFormat==PIX_FMT_RGB32) - av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR32 converter\n", - (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C"); - else if (dstFormat==PIX_FMT_BGR565) - av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR16 converter\n", - (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C"); - else if (dstFormat==PIX_FMT_BGR555) - av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR15 converter\n", - (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C"); - else if (dstFormat == PIX_FMT_RGB444BE || dstFormat == PIX_FMT_RGB444LE || - dstFormat == PIX_FMT_BGR444BE || dstFormat == PIX_FMT_BGR444LE) - av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR12 converter\n", - (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C"); - av_log(c, AV_LOG_VERBOSE, "%dx%d -> %dx%d\n", srcW, srcH, dstW, dstH); av_log(c, AV_LOG_DEBUG, "lum srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n", c->srcW, c->srcH, c->dstW, c->dstH, c->lumXInc, c->lumYInc);