From 72b95764d0c92b52b834b9cee46674f0e12dccd4 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Wed, 15 Feb 2012 11:46:47 +0100 Subject: [PATCH 01/19] swscale: variable declaration and placement cosmetics --- libswscale/rgb2rgb.c | 68 +++++++---------- libswscale/rgb2rgb_template.c | 139 +++++++++++++++------------------- 2 files changed, 90 insertions(+), 117 deletions(-) diff --git a/libswscale/rgb2rgb.c b/libswscale/rgb2rgb.c index 5ae0703a7f..2a9133d498 100644 --- a/libswscale/rgb2rgb.c +++ b/libswscale/rgb2rgb.c @@ -125,8 +125,8 @@ void sws_rgb2rgb_init(void) void rgb32to24(const uint8_t *src, uint8_t *dst, int src_size) { - int i; - int num_pixels = src_size >> 2; + int i, num_pixels = src_size >> 2; + for (i=0; i BGR24 (= B,G,R) */ @@ -162,13 +162,12 @@ void rgb24to32(const uint8_t *src, uint8_t *dst, int src_size) void rgb16tobgr32(const uint8_t *src, uint8_t *dst, int src_size) { - const uint16_t *end; uint8_t *d = dst; const uint16_t *s = (const uint16_t *)src; - end = s + src_size/2; + const uint16_t *end = s + src_size / 2; + while (s < end) { - register uint16_t bgr; - bgr = *s++; + register uint16_t bgr = *s++; #if HAVE_BIGENDIAN *d++ = 255; *d++ = (bgr&0x1F)<<3; @@ -185,11 +184,11 @@ void rgb16tobgr32(const uint8_t *src, uint8_t *dst, int src_size) void rgb12to15(const uint8_t *src, uint8_t *dst, int src_size) { - const uint16_t *end; uint16_t *d = (uint16_t *)dst; const uint16_t *s = (const uint16_t *)src; uint16_t rgb, r, g, b; - end = s + src_size / 2; + const uint16_t *end = s + src_size / 2; + while (s < end) { rgb = *s++; r = rgb & 0xF00; @@ -204,13 +203,12 @@ void rgb12to15(const uint8_t *src, uint8_t *dst, int src_size) void rgb16to24(const uint8_t *src, uint8_t *dst, int src_size) { - const uint16_t *end; uint8_t *d = dst; const uint16_t *s = (const uint16_t *)src; - end = s + src_size/2; + const uint16_t *end = s + src_size / 2; + while (s < end) { - register uint16_t bgr; - bgr = *s++; + register uint16_t bgr = *s++; *d++ = (bgr&0xF800)>>8; *d++ = (bgr&0x7E0)>>3; *d++ = (bgr&0x1F)<<3; @@ -219,8 +217,7 @@ void rgb16to24(const uint8_t *src, uint8_t *dst, int src_size) void rgb16tobgr16(const uint8_t *src, uint8_t *dst, int src_size) { - int i; - int num_pixels = src_size >> 1; + int i, num_pixels = src_size >> 1; for (i=0; i> 1; + int i, num_pixels = src_size >> 1; for (i=0; i>7; *d++ = (bgr&0x3E0)>>2; *d++ = (bgr&0x1F)<<3; @@ -279,8 +273,7 @@ void rgb15to24(const uint8_t *src, uint8_t *dst, int src_size) void rgb15tobgr16(const uint8_t *src, uint8_t *dst, int src_size) { - int i; - int num_pixels = src_size >> 1; + int i, num_pixels = src_size >> 1; for (i=0; i> 1; + int i, num_pixels = src_size >> 1; for (i=0; i>10) | (rgb&0x3E0) | (br<<10); } } @@ -305,8 +296,7 @@ void rgb12tobgr12(const uint8_t *src, uint8_t *dst, int src_size) { uint16_t *d = (uint16_t*)dst; uint16_t *s = (uint16_t*)src; - int i; - int num_pixels = src_size >> 1; + int i, num_pixels = src_size >> 1; for (i = 0; i < num_pixels; i++) { unsigned rgb = s[i]; @@ -316,15 +306,13 @@ void rgb12tobgr12(const uint8_t *src, uint8_t *dst, int src_size) void bgr8torgb8(const uint8_t *src, uint8_t *dst, int src_size) { - int i; - int num_pixels = src_size; + int i, num_pixels = src_size; + for (i=0; i>3; - b = (rgb&0xC0)>>6; + register uint8_t rgb = src[i]; + unsigned r = (rgb & 0x07); + unsigned g = (rgb & 0x38) >> 3; + unsigned b = (rgb & 0xC0) >> 6; dst[i] = ((b<<1)&0x07) | ((g&0x07)<<3) | ((r&0x03)<<6); } } diff --git a/libswscale/rgb2rgb_template.c b/libswscale/rgb2rgb_template.c index c02015e5b3..2eca93d395 100644 --- a/libswscale/rgb2rgb_template.c +++ b/libswscale/rgb2rgb_template.c @@ -30,8 +30,7 @@ static inline void rgb24tobgr32_c(const uint8_t *src, uint8_t *dst, int src_size { uint8_t *dest = dst; const uint8_t *s = src; - const uint8_t *end; - end = s + src_size; + const uint8_t *end = s + src_size; while (s < end) { #if HAVE_BIGENDIAN @@ -54,9 +53,7 @@ static inline void rgb32tobgr24_c(const uint8_t *src, uint8_t *dst, int src_size { uint8_t *dest = dst; const uint8_t *s = src; - const uint8_t *end; - - end = s + src_size; + const uint8_t *end = s + src_size; while (s < end) { #if HAVE_BIGENDIAN @@ -85,10 +82,9 @@ static inline void rgb15to16_c(const uint8_t *src, uint8_t *dst, int src_size) { register const uint8_t* s=src; register uint8_t* d=dst; - register const uint8_t *end; - const uint8_t *mm_end; - end = s + src_size; - mm_end = end - 3; + register const uint8_t *end = s + src_size; + const uint8_t *mm_end = end - 3; + while (s < mm_end) { register unsigned x= *((const uint32_t *)s); *((uint32_t *)d) = (x&0x7FFF7FFF) + (x&0x7FE07FE0); @@ -105,11 +101,9 @@ static inline void rgb16to15_c(const uint8_t *src, uint8_t *dst, int src_size) { register const uint8_t* s=src; register uint8_t* d=dst; - register const uint8_t *end; - const uint8_t *mm_end; - end = s + src_size; + register const uint8_t *end = s + src_size; + const uint8_t *mm_end = end - 3; - mm_end = end - 3; while (s < mm_end) { register uint32_t x= *((const uint32_t*)s); *((uint32_t *)d) = ((x>>1)&0x7FE07FE0) | (x&0x001F001F); @@ -125,9 +119,8 @@ static inline void rgb16to15_c(const uint8_t *src, uint8_t *dst, int src_size) static inline void rgb32to16_c(const uint8_t *src, uint8_t *dst, int src_size) { const uint8_t *s = src; - const uint8_t *end; uint16_t *d = (uint16_t *)dst; - end = s + src_size; + const uint8_t *end = s + src_size; while (s < end) { register int rgb = *(const uint32_t*)s; s += 4; @@ -138,9 +131,9 @@ static inline void rgb32to16_c(const uint8_t *src, uint8_t *dst, int src_size) static inline void rgb32tobgr16_c(const uint8_t *src, uint8_t *dst, int src_size) { const uint8_t *s = src; - const uint8_t *end; uint16_t *d = (uint16_t *)dst; - end = s + src_size; + const uint8_t *end = s + src_size; + while (s < end) { register int rgb = *(const uint32_t*)s; s += 4; *d++ = ((rgb&0xF8)<<8) + ((rgb&0xFC00)>>5) + ((rgb&0xF80000)>>19); @@ -150,9 +143,9 @@ static inline void rgb32tobgr16_c(const uint8_t *src, uint8_t *dst, int src_size static inline void rgb32to15_c(const uint8_t *src, uint8_t *dst, int src_size) { const uint8_t *s = src; - const uint8_t *end; uint16_t *d = (uint16_t *)dst; - end = s + src_size; + const uint8_t *end = s + src_size; + while (s < end) { register int rgb = *(const uint32_t*)s; s += 4; *d++ = ((rgb&0xFF)>>3) + ((rgb&0xF800)>>6) + ((rgb&0xF80000)>>9); @@ -162,9 +155,9 @@ static inline void rgb32to15_c(const uint8_t *src, uint8_t *dst, int src_size) static inline void rgb32tobgr15_c(const uint8_t *src, uint8_t *dst, int src_size) { const uint8_t *s = src; - const uint8_t *end; uint16_t *d = (uint16_t *)dst; - end = s + src_size; + const uint8_t *end = s + src_size; + while (s < end) { register int rgb = *(const uint32_t*)s; s += 4; *d++ = ((rgb&0xF8)<<7) + ((rgb&0xF800)>>6) + ((rgb&0xF80000)>>19); @@ -174,9 +167,9 @@ static inline void rgb32tobgr15_c(const uint8_t *src, uint8_t *dst, int src_size static inline void rgb24tobgr16_c(const uint8_t *src, uint8_t *dst, int src_size) { const uint8_t *s = src; - const uint8_t *end; uint16_t *d = (uint16_t *)dst; - end = s + src_size; + const uint8_t *end = s + src_size; + while (s < end) { const int b = *s++; const int g = *s++; @@ -188,9 +181,9 @@ static inline void rgb24tobgr16_c(const uint8_t *src, uint8_t *dst, int src_size static inline void rgb24to16_c(const uint8_t *src, uint8_t *dst, int src_size) { const uint8_t *s = src; - const uint8_t *end; uint16_t *d = (uint16_t *)dst; - end = s + src_size; + const uint8_t *end = s + src_size; + while (s < end) { const int r = *s++; const int g = *s++; @@ -202,9 +195,9 @@ static inline void rgb24to16_c(const uint8_t *src, uint8_t *dst, int src_size) static inline void rgb24tobgr15_c(const uint8_t *src, uint8_t *dst, int src_size) { const uint8_t *s = src; - const uint8_t *end; uint16_t *d = (uint16_t *)dst; - end = s + src_size; + const uint8_t *end = s + src_size; + while (s < end) { const int b = *s++; const int g = *s++; @@ -216,9 +209,9 @@ static inline void rgb24tobgr15_c(const uint8_t *src, uint8_t *dst, int src_size static inline void rgb24to15_c(const uint8_t *src, uint8_t *dst, int src_size) { const uint8_t *s = src; - const uint8_t *end; uint16_t *d = (uint16_t *)dst; - end = s + src_size; + const uint8_t *end = s + src_size; + while (s < end) { const int r = *s++; const int g = *s++; @@ -250,13 +243,12 @@ static inline void rgb24to15_c(const uint8_t *src, uint8_t *dst, int src_size) */ static inline void rgb15tobgr24_c(const uint8_t *src, uint8_t *dst, int src_size) { - const uint16_t *end; uint8_t *d = dst; const uint16_t *s = (const uint16_t*)src; - end = s + src_size/2; + const uint16_t *end = s + src_size / 2; + while (s < end) { - register uint16_t bgr; - bgr = *s++; + register uint16_t bgr = *s++; *d++ = (bgr&0x1F)<<3; *d++ = (bgr&0x3E0)>>2; *d++ = (bgr&0x7C00)>>7; @@ -265,13 +257,12 @@ static inline void rgb15tobgr24_c(const uint8_t *src, uint8_t *dst, int src_size static inline void rgb16tobgr24_c(const uint8_t *src, uint8_t *dst, int src_size) { - const uint16_t *end; uint8_t *d = (uint8_t *)dst; const uint16_t *s = (const uint16_t *)src; - end = s + src_size/2; + const uint16_t *end = s + src_size / 2; + while (s < end) { - register uint16_t bgr; - bgr = *s++; + register uint16_t bgr = *s++; *d++ = (bgr&0x1F)<<3; *d++ = (bgr&0x7E0)>>3; *d++ = (bgr&0xF800)>>8; @@ -280,13 +271,12 @@ static inline void rgb16tobgr24_c(const uint8_t *src, uint8_t *dst, int src_size static inline void rgb15to32_c(const uint8_t *src, uint8_t *dst, int src_size) { - const uint16_t *end; uint8_t *d = dst; const uint16_t *s = (const uint16_t *)src; - end = s + src_size/2; + const uint16_t *end = s + src_size / 2; + while (s < end) { - register uint16_t bgr; - bgr = *s++; + register uint16_t bgr = *s++; #if HAVE_BIGENDIAN *d++ = 255; *d++ = (bgr&0x7C00)>>7; @@ -303,13 +293,12 @@ static inline void rgb15to32_c(const uint8_t *src, uint8_t *dst, int src_size) static inline void rgb16to32_c(const uint8_t *src, uint8_t *dst, int src_size) { - const uint16_t *end; uint8_t *d = dst; const uint16_t *s = (const uint16_t*)src; - end = s + src_size/2; + const uint16_t *end = s + src_size / 2; + while (s < end) { - register uint16_t bgr; - bgr = *s++; + register uint16_t bgr = *s++; #if HAVE_BIGENDIAN *d++ = 255; *d++ = (bgr&0xF800)>>8; @@ -340,8 +329,7 @@ static inline void rgb24tobgr24_c(const uint8_t *src, uint8_t *dst, int src_size { unsigned i; for (i=0; i> 1; for (y=0; y> 1; for (y=0; y> 1; - y=0; - for (; y>1); uint8_t* d=dst1+dstStride1*y; - x=0; - for (;x>1); uint8_t* d=dst2+dstStride2*y; - x=0; - for (;x>2); const uint8_t* vp=src3+srcStride3*(y>>2); uint8_t* d=dst+dstStride*y; - x=0; - for (; x Date: Tue, 21 Feb 2012 20:09:31 +0100 Subject: [PATCH 02/19] swscale: K&R formatting cosmetics (part I) --- libswscale/options.c | 58 +-- libswscale/rgb2rgb.c | 251 +++++----- libswscale/rgb2rgb_template.c | 683 +++++++++++++------------- libswscale/yuv2rgb.c | 871 ++++++++++++++++++---------------- 4 files changed, 973 insertions(+), 890 deletions(-) diff --git a/libswscale/options.c b/libswscale/options.c index 9ba6e5e714..8072d436d2 100644 --- a/libswscale/options.c +++ b/libswscale/options.c @@ -19,12 +19,12 @@ */ #include "libavutil/avutil.h" -#include "libavutil/pixfmt.h" #include "libavutil/opt.h" +#include "libavutil/pixfmt.h" #include "swscale.h" #include "swscale_internal.h" -static const char * sws_context_to_name(void * ptr) +static const char *sws_context_to_name(void *ptr) { return "swscaler"; } @@ -34,34 +34,34 @@ static const char * sws_context_to_name(void * ptr) #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM static const AVOption options[] = { - { "sws_flags", "scaler/cpu flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.dbl = DEFAULT }, 0, UINT_MAX, VE, "sws_flags" }, - { "fast_bilinear", "fast bilinear", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_FAST_BILINEAR }, INT_MIN, INT_MAX, VE, "sws_flags" }, - { "bilinear", "bilinear", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_BILINEAR }, INT_MIN, INT_MAX, VE, "sws_flags" }, - { "bicubic", "bicubic", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_BICUBIC }, INT_MIN, INT_MAX, VE, "sws_flags" }, - { "experimental", "experimental", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_X }, INT_MIN, INT_MAX, VE, "sws_flags" }, - { "neighbor", "nearest neighbor", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_POINT }, INT_MIN, INT_MAX, VE, "sws_flags" }, - { "area", "averaging area", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_AREA }, INT_MIN, INT_MAX, VE, "sws_flags" }, - { "bicublin", "luma bicubic, chroma bilinear", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_BICUBLIN }, INT_MIN, INT_MAX, VE, "sws_flags" }, - { "gauss", "gaussian", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_GAUSS }, INT_MIN, INT_MAX, VE, "sws_flags" }, - { "sinc", "sinc", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_SINC }, INT_MIN, INT_MAX, VE, "sws_flags" }, - { "lanczos", "lanczos", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_LANCZOS }, INT_MIN, INT_MAX, VE, "sws_flags" }, - { "spline", "natural bicubic spline", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_SPLINE }, INT_MIN, INT_MAX, VE, "sws_flags" }, - { "print_info", "print info", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_PRINT_INFO }, INT_MIN, INT_MAX, VE, "sws_flags" }, - { "accurate_rnd", "accurate rounding", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_ACCURATE_RND }, INT_MIN, INT_MAX, VE, "sws_flags" }, - { "full_chroma_int", "full chroma interpolation", 0 , AV_OPT_TYPE_CONST, {.dbl = SWS_FULL_CHR_H_INT }, INT_MIN, INT_MAX, VE, "sws_flags" }, - { "full_chroma_inp", "full chroma input", 0 , AV_OPT_TYPE_CONST, {.dbl = SWS_FULL_CHR_H_INP }, INT_MIN, INT_MAX, VE, "sws_flags" }, - { "bitexact", "", 0 , AV_OPT_TYPE_CONST, {.dbl = SWS_BITEXACT }, INT_MIN, INT_MAX, VE, "sws_flags" }, + { "sws_flags", "scaler/cpu flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, { .dbl = DEFAULT }, 0, UINT_MAX, VE, "sws_flags" }, + { "fast_bilinear", "fast bilinear", 0, AV_OPT_TYPE_CONST, { .dbl = SWS_FAST_BILINEAR }, INT_MIN, INT_MAX, VE, "sws_flags" }, + { "bilinear", "bilinear", 0, AV_OPT_TYPE_CONST, { .dbl = SWS_BILINEAR }, INT_MIN, INT_MAX, VE, "sws_flags" }, + { "bicubic", "bicubic", 0, AV_OPT_TYPE_CONST, { .dbl = SWS_BICUBIC }, INT_MIN, INT_MAX, VE, "sws_flags" }, + { "experimental", "experimental", 0, AV_OPT_TYPE_CONST, { .dbl = SWS_X }, INT_MIN, INT_MAX, VE, "sws_flags" }, + { "neighbor", "nearest neighbor", 0, AV_OPT_TYPE_CONST, { .dbl = SWS_POINT }, INT_MIN, INT_MAX, VE, "sws_flags" }, + { "area", "averaging area", 0, AV_OPT_TYPE_CONST, { .dbl = SWS_AREA }, INT_MIN, INT_MAX, VE, "sws_flags" }, + { "bicublin", "luma bicubic, chroma bilinear", 0, AV_OPT_TYPE_CONST, { .dbl = SWS_BICUBLIN }, INT_MIN, INT_MAX, VE, "sws_flags" }, + { "gauss", "gaussian", 0, AV_OPT_TYPE_CONST, { .dbl = SWS_GAUSS }, INT_MIN, INT_MAX, VE, "sws_flags" }, + { "sinc", "sinc", 0, AV_OPT_TYPE_CONST, { .dbl = SWS_SINC }, INT_MIN, INT_MAX, VE, "sws_flags" }, + { "lanczos", "lanczos", 0, AV_OPT_TYPE_CONST, { .dbl = SWS_LANCZOS }, INT_MIN, INT_MAX, VE, "sws_flags" }, + { "spline", "natural bicubic spline", 0, AV_OPT_TYPE_CONST, { .dbl = SWS_SPLINE }, INT_MIN, INT_MAX, VE, "sws_flags" }, + { "print_info", "print info", 0, AV_OPT_TYPE_CONST, { .dbl = SWS_PRINT_INFO }, INT_MIN, INT_MAX, VE, "sws_flags" }, + { "accurate_rnd", "accurate rounding", 0, AV_OPT_TYPE_CONST, { .dbl = SWS_ACCURATE_RND }, INT_MIN, INT_MAX, VE, "sws_flags" }, + { "full_chroma_int", "full chroma interpolation", 0, AV_OPT_TYPE_CONST, { .dbl = SWS_FULL_CHR_H_INT }, INT_MIN, INT_MAX, VE, "sws_flags" }, + { "full_chroma_inp", "full chroma input", 0, AV_OPT_TYPE_CONST, { .dbl = SWS_FULL_CHR_H_INP }, INT_MIN, INT_MAX, VE, "sws_flags" }, + { "bitexact", "", 0, AV_OPT_TYPE_CONST, { .dbl = SWS_BITEXACT }, INT_MIN, INT_MAX, VE, "sws_flags" }, - { "srcw", "source width" , OFFSET(srcW), AV_OPT_TYPE_INT, {.dbl = 16 }, 1, INT_MAX, VE }, - { "srch", "source height" , OFFSET(srcH), AV_OPT_TYPE_INT, {.dbl = 16 }, 1, INT_MAX, VE }, - { "dstw", "destination width" , OFFSET(dstW), AV_OPT_TYPE_INT, {.dbl = 16 }, 1, INT_MAX, VE }, - { "dsth", "destination height", OFFSET(dstH), AV_OPT_TYPE_INT, {.dbl = 16 }, 1, INT_MAX, VE }, - { "src_format", "source format" , OFFSET(srcFormat), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, PIX_FMT_NB-1, VE }, - { "dst_format", "destination format", OFFSET(dstFormat), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, PIX_FMT_NB-1, VE }, - { "src_range" , "source range" , OFFSET(srcRange) , AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, 1, VE }, - { "dst_range" , "destination range" , OFFSET(dstRange) , AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, 1, VE }, - { "param0" , "scaler param 0" , OFFSET(param[0]) , AV_OPT_TYPE_DOUBLE, {.dbl = SWS_PARAM_DEFAULT}, INT_MIN, INT_MAX, VE }, - { "param1" , "scaler param 1" , OFFSET(param[1]) , AV_OPT_TYPE_DOUBLE, {.dbl = SWS_PARAM_DEFAULT}, INT_MIN, INT_MAX, VE }, + { "srcw", "source width", OFFSET(srcW), AV_OPT_TYPE_INT, { .dbl = 16 }, 1, INT_MAX, VE }, + { "srch", "source height", OFFSET(srcH), AV_OPT_TYPE_INT, { .dbl = 16 }, 1, INT_MAX, VE }, + { "dstw", "destination width", OFFSET(dstW), AV_OPT_TYPE_INT, { .dbl = 16 }, 1, INT_MAX, VE }, + { "dsth", "destination height", OFFSET(dstH), AV_OPT_TYPE_INT, { .dbl = 16 }, 1, INT_MAX, VE }, + { "src_format", "source format", OFFSET(srcFormat), AV_OPT_TYPE_INT, { .dbl = DEFAULT }, 0, PIX_FMT_NB - 1, VE }, + { "dst_format", "destination format", OFFSET(dstFormat), AV_OPT_TYPE_INT, { .dbl = DEFAULT }, 0, PIX_FMT_NB - 1, VE }, + { "src_range", "source range", OFFSET(srcRange), AV_OPT_TYPE_INT, { .dbl = DEFAULT }, 0, 1, VE }, + { "dst_range", "destination range", OFFSET(dstRange), AV_OPT_TYPE_INT, { .dbl = DEFAULT }, 0, 1, VE }, + { "param0", "scaler param 0", OFFSET(param[0]), AV_OPT_TYPE_DOUBLE, { .dbl = SWS_PARAM_DEFAULT }, INT_MIN, INT_MAX, VE }, + { "param1", "scaler param 1", OFFSET(param[1]), AV_OPT_TYPE_DOUBLE, { .dbl = SWS_PARAM_DEFAULT }, INT_MIN, INT_MAX, VE }, { NULL } }; diff --git a/libswscale/rgb2rgb.c b/libswscale/rgb2rgb.c index 2a9133d498..14b595f107 100644 --- a/libswscale/rgb2rgb.c +++ b/libswscale/rgb2rgb.c @@ -22,48 +22,58 @@ * License along with Libav; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + #include -#include "config.h" + #include "libavutil/bswap.h" +#include "config.h" #include "rgb2rgb.h" #include "swscale.h" #include "swscale_internal.h" -void (*rgb24tobgr32)(const uint8_t *src, uint8_t *dst, int src_size); -void (*rgb24tobgr16)(const uint8_t *src, uint8_t *dst, int src_size); -void (*rgb24tobgr15)(const uint8_t *src, uint8_t *dst, int src_size); void (*rgb32tobgr24)(const uint8_t *src, uint8_t *dst, int src_size); -void (*rgb32to16)(const uint8_t *src, uint8_t *dst, int src_size); -void (*rgb32to15)(const uint8_t *src, uint8_t *dst, int src_size); -void (*rgb15to16)(const uint8_t *src, uint8_t *dst, int src_size); -void (*rgb15tobgr24)(const uint8_t *src, uint8_t *dst, int src_size); -void (*rgb15to32)(const uint8_t *src, uint8_t *dst, int src_size); -void (*rgb16to15)(const uint8_t *src, uint8_t *dst, int src_size); -void (*rgb16tobgr24)(const uint8_t *src, uint8_t *dst, int src_size); -void (*rgb16to32)(const uint8_t *src, uint8_t *dst, int src_size); -void (*rgb24tobgr24)(const uint8_t *src, uint8_t *dst, int src_size); -void (*rgb24to16)(const uint8_t *src, uint8_t *dst, int src_size); -void (*rgb24to15)(const uint8_t *src, uint8_t *dst, int src_size); -void (*shuffle_bytes_2103)(const uint8_t *src, uint8_t *dst, int src_size); void (*rgb32tobgr16)(const uint8_t *src, uint8_t *dst, int src_size); void (*rgb32tobgr15)(const uint8_t *src, uint8_t *dst, int src_size); +void (*rgb24tobgr32)(const uint8_t *src, uint8_t *dst, int src_size); +void (*rgb24tobgr24)(const uint8_t *src, uint8_t *dst, int src_size); +void (*rgb24tobgr16)(const uint8_t *src, uint8_t *dst, int src_size); +void (*rgb24tobgr15)(const uint8_t *src, uint8_t *dst, int src_size); +void (*rgb16tobgr24)(const uint8_t *src, uint8_t *dst, int src_size); +void (*rgb15tobgr24)(const uint8_t *src, uint8_t *dst, int src_size); -void (*yv12toyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, +void (*rgb32to16)(const uint8_t *src, uint8_t *dst, int src_size); +void (*rgb32to15)(const uint8_t *src, uint8_t *dst, int src_size); +void (*rgb24to16)(const uint8_t *src, uint8_t *dst, int src_size); +void (*rgb24to15)(const uint8_t *src, uint8_t *dst, int src_size); +void (*rgb16to32)(const uint8_t *src, uint8_t *dst, int src_size); +void (*rgb16to15)(const uint8_t *src, uint8_t *dst, int src_size); +void (*rgb15to16)(const uint8_t *src, uint8_t *dst, int src_size); +void (*rgb15to32)(const uint8_t *src, uint8_t *dst, int src_size); + +void (*shuffle_bytes_2103)(const uint8_t *src, uint8_t *dst, int src_size); + +void (*yv12toyuy2)(const uint8_t *ysrc, const uint8_t *usrc, + const uint8_t *vsrc, uint8_t *dst, int width, int height, int lumStride, int chromStride, int dstStride); -void (*yv12touyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, +void (*yv12touyvy)(const uint8_t *ysrc, const uint8_t *usrc, + const uint8_t *vsrc, uint8_t *dst, int width, int height, int lumStride, int chromStride, int dstStride); -void (*yuv422ptoyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, +void (*yuv422ptoyuy2)(const uint8_t *ysrc, const uint8_t *usrc, + const uint8_t *vsrc, uint8_t *dst, int width, int height, int lumStride, int chromStride, int dstStride); -void (*yuv422ptouyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, +void (*yuv422ptouyvy)(const uint8_t *ysrc, const uint8_t *usrc, + const uint8_t *vsrc, uint8_t *dst, int width, int height, int lumStride, int chromStride, int dstStride); -void (*yuy2toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, +void (*yuy2toyv12)(const uint8_t *src, uint8_t *ydst, + uint8_t *udst, uint8_t *vdst, int width, int height, int lumStride, int chromStride, int srcStride); -void (*rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, +void (*rgb24toyv12)(const uint8_t *src, uint8_t *ydst, + uint8_t *udst, uint8_t *vdst, int width, int height, int lumStride, int chromStride, int srcStride); void (*planar2x)(const uint8_t *src, uint8_t *dst, int width, int height, @@ -76,45 +86,44 @@ void (*vu9_to_vu12)(const uint8_t *src1, const uint8_t *src2, int width, int height, int srcStride1, int srcStride2, int dstStride1, int dstStride2); -void (*yvu9_to_yuy2)(const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, - uint8_t *dst, +void (*yvu9_to_yuy2)(const uint8_t *src1, const uint8_t *src2, + const uint8_t *src3, uint8_t *dst, int width, int height, int srcStride1, int srcStride2, int srcStride3, int dstStride); -void (*uyvytoyuv420)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src, - int width, int height, +void (*uyvytoyuv420)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, + const uint8_t *src, int width, int height, int lumStride, int chromStride, int srcStride); -void (*uyvytoyuv422)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src, - int width, int height, +void (*uyvytoyuv422)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, + const uint8_t *src, int width, int height, int lumStride, int chromStride, int srcStride); -void (*yuyvtoyuv420)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src, - int width, int height, +void (*yuyvtoyuv420)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, + const uint8_t *src, int width, int height, int lumStride, int chromStride, int srcStride); -void (*yuyvtoyuv422)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src, - int width, int height, +void (*yuyvtoyuv422)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, + const uint8_t *src, int width, int height, int lumStride, int chromStride, int srcStride); #define RGB2YUV_SHIFT 8 -#define BY ((int)( 0.098*(1<RGB16 original by Strepto/Astral - ported to gcc & bugfixed : A'rpi - MMX2, 3DNOW optimization by Nick Kurshev - 32-bit C version, and and&add trick by Michael Niedermayer -*/ + * RGB15->RGB16 original by Strepto/Astral + * ported to gcc & bugfixed : A'rpi + * MMX2, 3DNOW optimization by Nick Kurshev + * 32-bit C version, and and&add trick by Michael Niedermayer + */ void sws_rgb2rgb_init(void) { @@ -127,16 +136,16 @@ void rgb32to24(const uint8_t *src, uint8_t *dst, int src_size) { int i, num_pixels = src_size >> 2; - for (i=0; i BGR24 (= B,G,R) */ - dst[3*i + 0] = src[4*i + 1]; - dst[3*i + 1] = src[4*i + 2]; - dst[3*i + 2] = src[4*i + 3]; + dst[3 * i + 0] = src[4 * i + 1]; + dst[3 * i + 1] = src[4 * i + 2]; + dst[3 * i + 2] = src[4 * i + 3]; #else - dst[3*i + 0] = src[4*i + 2]; - dst[3*i + 1] = src[4*i + 1]; - dst[3*i + 2] = src[4*i + 0]; + dst[3 * i + 0] = src[4 * i + 2]; + dst[3 * i + 1] = src[4 * i + 1]; + dst[3 * i + 2] = src[4 * i + 0]; #endif } } @@ -144,39 +153,40 @@ void rgb32to24(const uint8_t *src, uint8_t *dst, int src_size) void rgb24to32(const uint8_t *src, uint8_t *dst, int src_size) { int i; - for (i=0; 3*i BGR32 (= A,R,G,B) */ - dst[4*i + 0] = 255; - dst[4*i + 1] = src[3*i + 0]; - dst[4*i + 2] = src[3*i + 1]; - dst[4*i + 3] = src[3*i + 2]; + /* RGB24 (= R, G, B) -> BGR32 (= A, R, G, B) */ + dst[4 * i + 0] = 255; + dst[4 * i + 1] = src[3 * i + 0]; + dst[4 * i + 2] = src[3 * i + 1]; + dst[4 * i + 3] = src[3 * i + 2]; #else - dst[4*i + 0] = src[3*i + 2]; - dst[4*i + 1] = src[3*i + 1]; - dst[4*i + 2] = src[3*i + 0]; - dst[4*i + 3] = 255; + dst[4 * i + 0] = src[3 * i + 2]; + dst[4 * i + 1] = src[3 * i + 1]; + dst[4 * i + 2] = src[3 * i + 0]; + dst[4 * i + 3] = 255; #endif } } void rgb16tobgr32(const uint8_t *src, uint8_t *dst, int src_size) { - uint8_t *d = dst; - const uint16_t *s = (const uint16_t *)src; + uint8_t *d = dst; + const uint16_t *s = (const uint16_t *)src; const uint16_t *end = s + src_size / 2; while (s < end) { register uint16_t bgr = *s++; #if HAVE_BIGENDIAN *d++ = 255; - *d++ = (bgr&0x1F)<<3; - *d++ = (bgr&0x7E0)>>3; - *d++ = (bgr&0xF800)>>8; + *d++ = (bgr & 0x1F) << 3; + *d++ = (bgr & 0x7E0) >> 3; + *d++ = (bgr & 0xF800) >> 8; #else - *d++ = (bgr&0xF800)>>8; - *d++ = (bgr&0x7E0)>>3; - *d++ = (bgr&0x1F)<<3; + *d++ = (bgr & 0xF800) >> 8; + *d++ = (bgr & 0x7E0) >> 3; + *d++ = (bgr & 0x1F) << 3; *d++ = 255; #endif } @@ -184,34 +194,34 @@ void rgb16tobgr32(const uint8_t *src, uint8_t *dst, int src_size) void rgb12to15(const uint8_t *src, uint8_t *dst, int src_size) { - uint16_t *d = (uint16_t *)dst; - const uint16_t *s = (const uint16_t *)src; uint16_t rgb, r, g, b; + uint16_t *d = (uint16_t *)dst; + const uint16_t *s = (const uint16_t *)src; const uint16_t *end = s + src_size / 2; while (s < end) { - rgb = *s++; - r = rgb & 0xF00; - g = rgb & 0x0F0; - b = rgb & 0x00F; - r = (r << 3) | ((r & 0x800) >> 1); - g = (g << 2) | ((g & 0x080) >> 2); - b = (b << 1) | ( b >> 3); + rgb = *s++; + r = rgb & 0xF00; + g = rgb & 0x0F0; + b = rgb & 0x00F; + r = (r << 3) | ((r & 0x800) >> 1); + g = (g << 2) | ((g & 0x080) >> 2); + b = (b << 1) | ( b >> 3); *d++ = r | g | b; } } void rgb16to24(const uint8_t *src, uint8_t *dst, int src_size) { - uint8_t *d = dst; - const uint16_t *s = (const uint16_t *)src; + uint8_t *d = dst; + const uint16_t *s = (const uint16_t *)src; const uint16_t *end = s + src_size / 2; while (s < end) { register uint16_t bgr = *s++; - *d++ = (bgr&0xF800)>>8; - *d++ = (bgr&0x7E0)>>3; - *d++ = (bgr&0x1F)<<3; + *d++ = (bgr & 0xF800) >> 8; + *d++ = (bgr & 0x7E0) >> 3; + *d++ = (bgr & 0x1F) << 3; } } @@ -219,9 +229,9 @@ void rgb16tobgr16(const uint8_t *src, uint8_t *dst, int src_size) { int i, num_pixels = src_size >> 1; - for (i=0; i>11) | (rgb&0x7E0) | (rgb<<11); + for (i = 0; i < num_pixels; i++) { + unsigned rgb = ((const uint16_t *)src)[i]; + ((uint16_t *)dst)[i] = (rgb >> 11) | (rgb & 0x7E0) | (rgb << 11); } } @@ -229,29 +239,29 @@ void rgb16tobgr15(const uint8_t *src, uint8_t *dst, int src_size) { int i, num_pixels = src_size >> 1; - for (i=0; i>11) | ((rgb&0x7C0)>>1) | ((rgb&0x1F)<<10); + for (i = 0; i < num_pixels; i++) { + unsigned rgb = ((const uint16_t *)src)[i]; + ((uint16_t *)dst)[i] = (rgb >> 11) | ((rgb & 0x7C0) >> 1) | ((rgb & 0x1F) << 10); } } void rgb15tobgr32(const uint8_t *src, uint8_t *dst, int src_size) { - uint8_t *d = dst; - const uint16_t *s = (const uint16_t *)src; + uint8_t *d = dst; + const uint16_t *s = (const uint16_t *)src; const uint16_t *end = s + src_size / 2; while (s < end) { register uint16_t bgr = *s++; #if HAVE_BIGENDIAN *d++ = 255; - *d++ = (bgr&0x1F)<<3; - *d++ = (bgr&0x3E0)>>2; - *d++ = (bgr&0x7C00)>>7; + *d++ = (bgr & 0x1F) << 3; + *d++ = (bgr & 0x3E0) >> 2; + *d++ = (bgr & 0x7C00) >> 7; #else - *d++ = (bgr&0x7C00)>>7; - *d++ = (bgr&0x3E0)>>2; - *d++ = (bgr&0x1F)<<3; + *d++ = (bgr & 0x7C00) >> 7; + *d++ = (bgr & 0x3E0) >> 2; + *d++ = (bgr & 0x1F) << 3; *d++ = 255; #endif } @@ -259,15 +269,15 @@ void rgb15tobgr32(const uint8_t *src, uint8_t *dst, int src_size) void rgb15to24(const uint8_t *src, uint8_t *dst, int src_size) { - uint8_t *d = dst; - const uint16_t *s = (const uint16_t *)src; + uint8_t *d = dst; + const uint16_t *s = (const uint16_t *)src; const uint16_t *end = s + src_size / 2; while (s < end) { register uint16_t bgr = *s++; - *d++ = (bgr&0x7C00)>>7; - *d++ = (bgr&0x3E0)>>2; - *d++ = (bgr&0x1F)<<3; + *d++ = (bgr & 0x7C00) >> 7; + *d++ = (bgr & 0x3E0) >> 2; + *d++ = (bgr & 0x1F) << 3; } } @@ -275,9 +285,9 @@ void rgb15tobgr16(const uint8_t *src, uint8_t *dst, int src_size) { int i, num_pixels = src_size >> 1; - for (i=0; i>10) | ((rgb&0x3E0)<<1) | (rgb<<11); + for (i = 0; i < num_pixels; i++) { + unsigned rgb = ((const uint16_t *)src)[i]; + ((uint16_t *)dst)[i] = ((rgb & 0x7C00) >> 10) | ((rgb & 0x3E0) << 1) | (rgb << 11); } } @@ -285,22 +295,22 @@ void rgb15tobgr15(const uint8_t *src, uint8_t *dst, int src_size) { int i, num_pixels = src_size >> 1; - for (i=0; i>10) | (rgb&0x3E0) | (br<<10); + for (i = 0; i < num_pixels; i++) { + unsigned rgb = ((const uint16_t *)src)[i]; + unsigned br = rgb & 0x7C1F; + ((uint16_t *)dst)[i] = (br >> 10) | (rgb & 0x3E0) | (br << 10); } } void rgb12tobgr12(const uint8_t *src, uint8_t *dst, int src_size) { - uint16_t *d = (uint16_t*)dst; - uint16_t *s = (uint16_t*)src; + uint16_t *d = (uint16_t *)dst; + uint16_t *s = (uint16_t *)src; int i, num_pixels = src_size >> 1; for (i = 0; i < num_pixels; i++) { unsigned rgb = s[i]; - d[i] = (rgb << 8 | rgb & 0xF0 | rgb >> 8) & 0xFFF; + d[i] = (rgb << 8 | rgb & 0xF0 | rgb >> 8) & 0xFFF; } } @@ -308,21 +318,22 @@ void bgr8torgb8(const uint8_t *src, uint8_t *dst, int src_size) { int i, num_pixels = src_size; - for (i=0; i> 3; unsigned b = (rgb & 0xC0) >> 6; - dst[i] = ((b<<1)&0x07) | ((g&0x07)<<3) | ((r&0x03)<<6); + dst[i] = ((b << 1) & 0x07) | ((g & 0x07) << 3) | ((r & 0x03) << 6); } } #define DEFINE_SHUFFLE_BYTES(a, b, c, d) \ -void shuffle_bytes_##a##b##c##d(const uint8_t *src, uint8_t *dst, int src_size) \ +void shuffle_bytes_ ## a ## b ## c ## d(const uint8_t *src, \ + uint8_t *dst, int src_size) \ { \ - int i; \ + int i; \ \ - for (i = 0; i < src_size; i+=4) { \ + for (i = 0; i < src_size; i += 4) { \ dst[i + 0] = src[i + a]; \ dst[i + 1] = src[i + b]; \ dst[i + 2] = src[i + c]; \ diff --git a/libswscale/rgb2rgb_template.c b/libswscale/rgb2rgb_template.c index 2eca93d395..d1a43e01cb 100644 --- a/libswscale/rgb2rgb_template.c +++ b/libswscale/rgb2rgb_template.c @@ -26,266 +26,286 @@ #include -static inline void rgb24tobgr32_c(const uint8_t *src, uint8_t *dst, int src_size) +static inline void rgb24tobgr32_c(const uint8_t *src, uint8_t *dst, + int src_size) { - uint8_t *dest = dst; - const uint8_t *s = src; + uint8_t *dest = dst; + const uint8_t *s = src; const uint8_t *end = s + src_size; while (s < end) { #if HAVE_BIGENDIAN - /* RGB24 (= R,G,B) -> RGB32 (= A,B,G,R) */ - *dest++ = 255; - *dest++ = s[2]; - *dest++ = s[1]; - *dest++ = s[0]; - s+=3; + /* RGB24 (= R, G, B) -> RGB32 (= A, B, G, R) */ + *dest++ = 255; + *dest++ = s[2]; + *dest++ = s[1]; + *dest++ = s[0]; + s += 3; #else - *dest++ = *s++; - *dest++ = *s++; - *dest++ = *s++; - *dest++ = 255; + *dest++ = *s++; + *dest++ = *s++; + *dest++ = *s++; + *dest++ = 255; #endif } } -static inline void rgb32tobgr24_c(const uint8_t *src, uint8_t *dst, int src_size) +static inline void rgb32tobgr24_c(const uint8_t *src, uint8_t *dst, + int src_size) { - uint8_t *dest = dst; - const uint8_t *s = src; + uint8_t *dest = dst; + const uint8_t *s = src; const uint8_t *end = s + src_size; while (s < end) { #if HAVE_BIGENDIAN - /* RGB32 (= A,B,G,R) -> RGB24 (= R,G,B) */ + /* RGB32 (= A, B, G, R) -> RGB24 (= R, G, B) */ s++; - dest[2] = *s++; - dest[1] = *s++; - dest[0] = *s++; - dest += 3; + dest[2] = *s++; + dest[1] = *s++; + dest[0] = *s++; + dest += 3; #else - *dest++ = *s++; - *dest++ = *s++; - *dest++ = *s++; + *dest++ = *s++; + *dest++ = *s++; + *dest++ = *s++; s++; #endif } } /* - original by Strepto/Astral - ported to gcc & bugfixed: A'rpi - MMX2, 3DNOW optimization by Nick Kurshev - 32-bit C version, and and&add trick by Michael Niedermayer -*/ + * original by Strepto/Astral + * ported to gcc & bugfixed: A'rpi + * MMX2, 3DNOW optimization by Nick Kurshev + * 32-bit C version, and and&add trick by Michael Niedermayer + */ static inline void rgb15to16_c(const uint8_t *src, uint8_t *dst, int src_size) { - register const uint8_t* s=src; - register uint8_t* d=dst; + register uint8_t *d = dst; + register const uint8_t *s = src; register const uint8_t *end = s + src_size; const uint8_t *mm_end = end - 3; while (s < mm_end) { - register unsigned x= *((const uint32_t *)s); - *((uint32_t *)d) = (x&0x7FFF7FFF) + (x&0x7FE07FE0); - d+=4; - s+=4; + register unsigned x = *((const uint32_t *)s); + *((uint32_t *)d) = (x & 0x7FFF7FFF) + (x & 0x7FE07FE0); + d += 4; + s += 4; } if (s < end) { - register unsigned short x= *((const uint16_t *)s); - *((uint16_t *)d) = (x&0x7FFF) + (x&0x7FE0); + register unsigned short x = *((const uint16_t *)s); + *((uint16_t *)d) = (x & 0x7FFF) + (x & 0x7FE0); } } static inline void rgb16to15_c(const uint8_t *src, uint8_t *dst, int src_size) { - register const uint8_t* s=src; - register uint8_t* d=dst; + register uint8_t *d = dst; + register const uint8_t *s = src; register const uint8_t *end = s + src_size; const uint8_t *mm_end = end - 3; while (s < mm_end) { - register uint32_t x= *((const uint32_t*)s); - *((uint32_t *)d) = ((x>>1)&0x7FE07FE0) | (x&0x001F001F); - s+=4; - d+=4; + register uint32_t x = *((const uint32_t *)s); + *((uint32_t *)d) = ((x >> 1) & 0x7FE07FE0) | (x & 0x001F001F); + s += 4; + d += 4; } if (s < end) { - register uint16_t x= *((const uint16_t*)s); - *((uint16_t *)d) = ((x>>1)&0x7FE0) | (x&0x001F); + register uint16_t x = *((const uint16_t *)s); + *((uint16_t *)d) = ((x >> 1) & 0x7FE0) | (x & 0x001F); } } static inline void rgb32to16_c(const uint8_t *src, uint8_t *dst, int src_size) { - const uint8_t *s = src; - uint16_t *d = (uint16_t *)dst; + uint16_t *d = (uint16_t *)dst; + const uint8_t *s = src; const uint8_t *end = s + src_size; while (s < end) { - register int rgb = *(const uint32_t*)s; s += 4; - *d++ = ((rgb&0xFF)>>3) + ((rgb&0xFC00)>>5) + ((rgb&0xF80000)>>8); + register int rgb = *(const uint32_t *)s; + s += 4; + *d++ = ((rgb & 0xFF) >> 3) + + ((rgb & 0xFC00) >> 5) + + ((rgb & 0xF80000) >> 8); } } -static inline void rgb32tobgr16_c(const uint8_t *src, uint8_t *dst, int src_size) +static inline void rgb32tobgr16_c(const uint8_t *src, uint8_t *dst, + int src_size) { - const uint8_t *s = src; - uint16_t *d = (uint16_t *)dst; + uint16_t *d = (uint16_t *)dst; + const uint8_t *s = src; const uint8_t *end = s + src_size; while (s < end) { - register int rgb = *(const uint32_t*)s; s += 4; - *d++ = ((rgb&0xF8)<<8) + ((rgb&0xFC00)>>5) + ((rgb&0xF80000)>>19); + register int rgb = *(const uint32_t *)s; + s += 4; + *d++ = ((rgb & 0xF8) << 8) + + ((rgb & 0xFC00) >> 5) + + ((rgb & 0xF80000) >> 19); } } static inline void rgb32to15_c(const uint8_t *src, uint8_t *dst, int src_size) { - const uint8_t *s = src; - uint16_t *d = (uint16_t *)dst; + uint16_t *d = (uint16_t *)dst; + const uint8_t *s = src; const uint8_t *end = s + src_size; while (s < end) { - register int rgb = *(const uint32_t*)s; s += 4; - *d++ = ((rgb&0xFF)>>3) + ((rgb&0xF800)>>6) + ((rgb&0xF80000)>>9); + register int rgb = *(const uint32_t *)s; + s += 4; + *d++ = ((rgb & 0xFF) >> 3) + + ((rgb & 0xF800) >> 6) + + ((rgb & 0xF80000) >> 9); } } -static inline void rgb32tobgr15_c(const uint8_t *src, uint8_t *dst, int src_size) +static inline void rgb32tobgr15_c(const uint8_t *src, uint8_t *dst, + int src_size) { - const uint8_t *s = src; - uint16_t *d = (uint16_t *)dst; + uint16_t *d = (uint16_t *)dst; + const uint8_t *s = src; const uint8_t *end = s + src_size; while (s < end) { - register int rgb = *(const uint32_t*)s; s += 4; - *d++ = ((rgb&0xF8)<<7) + ((rgb&0xF800)>>6) + ((rgb&0xF80000)>>19); + register int rgb = *(const uint32_t *)s; + s += 4; + *d++ = ((rgb & 0xF8) << 7) + + ((rgb & 0xF800) >> 6) + + ((rgb & 0xF80000) >> 19); } } -static inline void rgb24tobgr16_c(const uint8_t *src, uint8_t *dst, int src_size) +static inline void rgb24tobgr16_c(const uint8_t *src, uint8_t *dst, + int src_size) { - const uint8_t *s = src; - uint16_t *d = (uint16_t *)dst; + uint16_t *d = (uint16_t *)dst; + const uint8_t *s = src; const uint8_t *end = s + src_size; while (s < end) { const int b = *s++; const int g = *s++; const int r = *s++; - *d++ = (b>>3) | ((g&0xFC)<<3) | ((r&0xF8)<<8); + *d++ = (b >> 3) | ((g & 0xFC) << 3) | ((r & 0xF8) << 8); } } static inline void rgb24to16_c(const uint8_t *src, uint8_t *dst, int src_size) { - const uint8_t *s = src; - uint16_t *d = (uint16_t *)dst; + uint16_t *d = (uint16_t *)dst; + const uint8_t *s = src; const uint8_t *end = s + src_size; while (s < end) { const int r = *s++; const int g = *s++; const int b = *s++; - *d++ = (b>>3) | ((g&0xFC)<<3) | ((r&0xF8)<<8); + *d++ = (b >> 3) | ((g & 0xFC) << 3) | ((r & 0xF8) << 8); } } -static inline void rgb24tobgr15_c(const uint8_t *src, uint8_t *dst, int src_size) +static inline void rgb24tobgr15_c(const uint8_t *src, uint8_t *dst, + int src_size) { - const uint8_t *s = src; - uint16_t *d = (uint16_t *)dst; + uint16_t *d = (uint16_t *)dst; + const uint8_t *s = src; const uint8_t *end = s + src_size; while (s < end) { const int b = *s++; const int g = *s++; const int r = *s++; - *d++ = (b>>3) | ((g&0xF8)<<2) | ((r&0xF8)<<7); + *d++ = (b >> 3) | ((g & 0xF8) << 2) | ((r & 0xF8) << 7); } } static inline void rgb24to15_c(const uint8_t *src, uint8_t *dst, int src_size) { - const uint8_t *s = src; - uint16_t *d = (uint16_t *)dst; + uint16_t *d = (uint16_t *)dst; + const uint8_t *s = src; const uint8_t *end = s + src_size; while (s < end) { const int r = *s++; const int g = *s++; const int b = *s++; - *d++ = (b>>3) | ((g&0xF8)<<2) | ((r&0xF8)<<7); + *d++ = (b >> 3) | ((g & 0xF8) << 2) | ((r & 0xF8) << 7); } } /* - I use less accurate approximation here by simply left-shifting the input - value and filling the low order bits with zeroes. This method improves PNG - compression but this scheme cannot reproduce white exactly, since it does - not generate an all-ones maximum value; the net effect is to darken the - image slightly. - - The better method should be "left bit replication": - - 4 3 2 1 0 - --------- - 1 1 0 1 1 - - 7 6 5 4 3 2 1 0 - ---------------- - 1 1 0 1 1 1 1 0 - |=======| |===| - | leftmost bits repeated to fill open bits - | - original bits -*/ -static inline void rgb15tobgr24_c(const uint8_t *src, uint8_t *dst, int src_size) + * I use less accurate approximation here by simply left-shifting the input + * value and filling the low order bits with zeroes. This method improves PNG + * compression but this scheme cannot reproduce white exactly, since it does + * not generate an all-ones maximum value; the net effect is to darken the + * image slightly. + * + * The better method should be "left bit replication": + * + * 4 3 2 1 0 + * --------- + * 1 1 0 1 1 + * + * 7 6 5 4 3 2 1 0 + * ---------------- + * 1 1 0 1 1 1 1 0 + * |=======| |===| + * | leftmost bits repeated to fill open bits + * | + * original bits + */ +static inline void rgb15tobgr24_c(const uint8_t *src, uint8_t *dst, + int src_size) { - uint8_t *d = dst; - const uint16_t *s = (const uint16_t*)src; + uint8_t *d = dst; + const uint16_t *s = (const uint16_t *)src; const uint16_t *end = s + src_size / 2; while (s < end) { register uint16_t bgr = *s++; - *d++ = (bgr&0x1F)<<3; - *d++ = (bgr&0x3E0)>>2; - *d++ = (bgr&0x7C00)>>7; + *d++ = (bgr & 0x1F) << 3; + *d++ = (bgr & 0x3E0) >> 2; + *d++ = (bgr & 0x7C00) >> 7; } } -static inline void rgb16tobgr24_c(const uint8_t *src, uint8_t *dst, int src_size) +static inline void rgb16tobgr24_c(const uint8_t *src, uint8_t *dst, + int src_size) { - uint8_t *d = (uint8_t *)dst; - const uint16_t *s = (const uint16_t *)src; + uint8_t *d = (uint8_t *)dst; + const uint16_t *s = (const uint16_t *)src; const uint16_t *end = s + src_size / 2; while (s < end) { register uint16_t bgr = *s++; - *d++ = (bgr&0x1F)<<3; - *d++ = (bgr&0x7E0)>>3; - *d++ = (bgr&0xF800)>>8; + *d++ = (bgr & 0x1F) << 3; + *d++ = (bgr & 0x7E0) >> 3; + *d++ = (bgr & 0xF800) >> 8; } } static inline void rgb15to32_c(const uint8_t *src, uint8_t *dst, int src_size) { - uint8_t *d = dst; - const uint16_t *s = (const uint16_t *)src; + uint8_t *d = dst; + const uint16_t *s = (const uint16_t *)src; const uint16_t *end = s + src_size / 2; while (s < end) { register uint16_t bgr = *s++; #if HAVE_BIGENDIAN *d++ = 255; - *d++ = (bgr&0x7C00)>>7; - *d++ = (bgr&0x3E0)>>2; - *d++ = (bgr&0x1F)<<3; + *d++ = (bgr & 0x7C00) >> 7; + *d++ = (bgr & 0x3E0) >> 2; + *d++ = (bgr & 0x1F) << 3; #else - *d++ = (bgr&0x1F)<<3; - *d++ = (bgr&0x3E0)>>2; - *d++ = (bgr&0x7C00)>>7; + *d++ = (bgr & 0x1F) << 3; + *d++ = (bgr & 0x3E0) >> 2; + *d++ = (bgr & 0x7C00) >> 7; *d++ = 255; #endif } @@ -293,46 +313,49 @@ static inline void rgb15to32_c(const uint8_t *src, uint8_t *dst, int src_size) static inline void rgb16to32_c(const uint8_t *src, uint8_t *dst, int src_size) { - uint8_t *d = dst; - const uint16_t *s = (const uint16_t*)src; + uint8_t *d = dst; + const uint16_t *s = (const uint16_t *)src; const uint16_t *end = s + src_size / 2; while (s < end) { register uint16_t bgr = *s++; #if HAVE_BIGENDIAN *d++ = 255; - *d++ = (bgr&0xF800)>>8; - *d++ = (bgr&0x7E0)>>3; - *d++ = (bgr&0x1F)<<3; + *d++ = (bgr & 0xF800) >> 8; + *d++ = (bgr & 0x7E0) >> 3; + *d++ = (bgr & 0x1F) << 3; #else - *d++ = (bgr&0x1F)<<3; - *d++ = (bgr&0x7E0)>>3; - *d++ = (bgr&0xF800)>>8; + *d++ = (bgr & 0x1F) << 3; + *d++ = (bgr & 0x7E0) >> 3; + *d++ = (bgr & 0xF800) >> 8; *d++ = 255; #endif } } -static inline void shuffle_bytes_2103_c(const uint8_t *src, uint8_t *dst, int src_size) +static inline void shuffle_bytes_2103_c(const uint8_t *src, uint8_t *dst, + int src_size) { - int idx = 15 - src_size; - const uint8_t *s = src-idx; - uint8_t *d = dst-idx; - for (; idx<15; idx+=4) { - register int v = *(const uint32_t *)&s[idx], g = v & 0xff00ff00; - v &= 0xff00ff; - *(uint32_t *)&d[idx] = (v>>16) + g + (v<<16); + int idx = 15 - src_size; + const uint8_t *s = src - idx; + uint8_t *d = dst - idx; + + for (; idx < 15; idx += 4) { + register int v = *(const uint32_t *)&s[idx], g = v & 0xff00ff00; + v &= 0xff00ff; + *(uint32_t *)&d[idx] = (v >> 16) + g + (v << 16); } } static inline void rgb24tobgr24_c(const uint8_t *src, uint8_t *dst, int src_size) { unsigned i; - for (i=0; i> 1; - for (y=0; y> 1; - for (y=0; y> 1; - for (y=0; y>2; - dst[2*x+2]= ( src[x] + 3*src[x+1])>>2; + for (x = 0; x < srcWidth - 1; x++) { + dst[2 * x + 1] = (3 * src[x] + src[x + 1]) >> 2; + dst[2 * x + 2] = (src[x] + 3 * src[x + 1]) >> 2; } - dst[2*srcWidth-1]= src[srcWidth-1]; + dst[2 * srcWidth - 1] = src[srcWidth - 1]; - dst+= dstStride; + dst += dstStride; - for (y=1; y>2; - dst[dstStride]= ( src[0] + 3*src[srcStride])>>2; + dst[0] = (src[0] * 3 + src[srcStride]) >> 2; + dst[dstStride] = (src[0] + 3 * src[srcStride]) >> 2; - for (x=mmxSize-1; x>2; - dst[2*x+dstStride+2]= ( src[x+0] + 3*src[x+srcStride+1])>>2; - dst[2*x+dstStride+1]= ( src[x+1] + 3*src[x+srcStride ])>>2; - dst[2*x +2]= (3*src[x+1] + src[x+srcStride ])>>2; + for (x = mmxSize - 1; x < srcWidth - 1; x++) { + dst[2 * x + 1] = (src[x + 0] * 3 + src[x + srcStride + 1]) >> 2; + dst[2 * x + dstStride + 2] = (src[x + 0] + 3 * src[x + srcStride + 1]) >> 2; + dst[2 * x + dstStride + 1] = (src[x + 1] + 3 * src[x + srcStride]) >> 2; + dst[2 * x + 2] = (src[x + 1] * 3 + src[x + srcStride]) >> 2; } - dst[srcWidth*2 -1 ]= (3*src[srcWidth-1] + src[srcWidth-1 + srcStride])>>2; - dst[srcWidth*2 -1 + dstStride]= ( src[srcWidth-1] + 3*src[srcWidth-1 + srcStride])>>2; + dst[srcWidth * 2 - 1] = (src[srcWidth - 1] * 3 + src[srcWidth - 1 + srcStride]) >> 2; + dst[srcWidth * 2 - 1 + dstStride] = (src[srcWidth - 1] + 3 * src[srcWidth - 1 + srcStride]) >> 2; - dst+=dstStride*2; - src+=srcStride; + dst += dstStride * 2; + src += srcStride; } // last line - dst[0]= src[0]; + dst[0] = src[0]; - for (x=0; x>2; - dst[2*x+2]= ( src[x] + 3*src[x+1])>>2; + for (x = 0; x < srcWidth - 1; x++) { + dst[2 * x + 1] = (src[x] * 3 + src[x + 1]) >> 2; + dst[2 * x + 2] = (src[x] + 3 * src[x + 1]) >> 2; } - dst[2*srcWidth-1]= src[srcWidth-1]; + dst[2 * srcWidth - 1] = src[srcWidth - 1]; } /** @@ -575,26 +598,26 @@ static inline void planar2x_c(const uint8_t *src, uint8_t *dst, int srcWidth, */ static inline void uyvytoyv12_c(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, - int width, int height, - int lumStride, int chromStride, - int srcStride) + int width, int height, int lumStride, + int chromStride, int srcStride) { int y; const int chromWidth = width >> 1; - for (y=0; y>RGB2YUV_SHIFT) + 16; - unsigned int V = ((RV*r + GV*g + BV*b)>>RGB2YUV_SHIFT) + 128; - unsigned int U = ((RU*r + GU*g + BU*b)>>RGB2YUV_SHIFT) + 128; + unsigned int Y = ((RY * r + GY * g + BY * b) >> RGB2YUV_SHIFT) + 16; + unsigned int V = ((RV * r + GV * g + BV * b) >> RGB2YUV_SHIFT) + 128; + unsigned int U = ((RU * r + GU * g + BU * b) >> RGB2YUV_SHIFT) + 128; udst[i] = U; vdst[i] = V; - ydst[2*i] = Y; + ydst[2 * i] = Y; - b = src[6*i+3]; - g = src[6*i+4]; - r = src[6*i+5]; + b = src[6 * i + 3]; + g = src[6 * i + 4]; + r = src[6 * i + 5]; - Y = ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16; - ydst[2*i+1] = Y; + Y = ((RY * r + GY * g + BY * b) >> RGB2YUV_SHIFT) + 16; + ydst[2 * i + 1] = Y; } ydst += lumStride; src += srcStride; - for (i=0; i>RGB2YUV_SHIFT) + 16; + unsigned int Y = ((RY * r + GY * g + BY * b) >> RGB2YUV_SHIFT) + 16; - ydst[2*i] = Y; + ydst[2 * i] = Y; - b = src[6*i+3]; - g = src[6*i+4]; - r = src[6*i+5]; + b = src[6 * i + 3]; + g = src[6 * i + 4]; + r = src[6 * i + 5]; - Y = ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16; - ydst[2*i+1] = Y; + Y = ((RY * r + GY * g + BY * b) >> RGB2YUV_SHIFT) + 16; + ydst[2 * i + 1] = Y; } udst += chromStride; vdst += chromStride; @@ -666,17 +689,16 @@ void rgb24toyv12_c(const uint8_t *src, uint8_t *ydst, uint8_t *udst, } static void interleaveBytes_c(const uint8_t *src1, const uint8_t *src2, - uint8_t *dest, int width, - int height, int src1Stride, - int src2Stride, int dstStride) + uint8_t *dest, int width, int height, + int src1Stride, int src2Stride, int dstStride) { int h; - for (h=0; h < height; h++) { + for (h = 0; h < height; h++) { int w; - for (w=0; w < width; w++) { - dest[2*w+0] = src1[w]; - dest[2*w+1] = src2[w]; + for (w = 0; w < width; w++) { + dest[2 * w + 0] = src1[w]; + dest[2 * w + 1] = src2[w]; } dest += dstStride; src1 += src1Stride; @@ -694,15 +716,15 @@ static inline void vu9_to_vu12_c(const uint8_t *src1, const uint8_t *src2, int w = width / 2; int h = height / 2; - for (y=0;y>1); - uint8_t* d=dst1+dstStride1*y; + for (y = 0; y < h; y++) { + const uint8_t *s1 = src1 + srcStride1 * (y >> 1); + uint8_t *d = dst1 + dstStride1 * y; for (x = 0; x < w; x++) d[2 * x] = d[2 * x + 1] = s1[x]; } - for (y=0;y>1); - uint8_t* d=dst2+dstStride2*y; + for (y = 0; y < h; y++) { + const uint8_t *s2 = src2 + srcStride2 * (y >> 1); + uint8_t *d = dst2 + dstStride2 * y; for (x = 0; x < w; x++) d[2 * x] = d[2 * x + 1] = s2[x]; } @@ -718,33 +740,32 @@ static inline void yvu9_to_yuy2_c(const uint8_t *src1, const uint8_t *src2, int w = width / 2; int h = height; - for (y=0;y>2); - const uint8_t* vp=src3+srcStride3*(y>>2); - uint8_t* d=dst+dstStride*y; + for (y = 0; y < h; y++) { + const uint8_t *yp = src1 + srcStride1 * y; + const uint8_t *up = src2 + srcStride2 * (y >> 2); + const uint8_t *vp = src3 + srcStride3 * (y >> 2); + uint8_t *d = dst + dstStride * y; for (x = 0; x < w; x++) { - const int x2 = x<<2; - d[8*x+0] = yp[x2]; - d[8*x+1] = up[x]; - d[8*x+2] = yp[x2+1]; - d[8*x+3] = vp[x]; - d[8*x+4] = yp[x2+2]; - d[8*x+5] = up[x]; - d[8*x+6] = yp[x2+3]; - d[8*x+7] = vp[x]; + const int x2 = x << 2; + d[8 * x + 0] = yp[x2]; + d[8 * x + 1] = up[x]; + d[8 * x + 2] = yp[x2 + 1]; + d[8 * x + 3] = vp[x]; + d[8 * x + 4] = yp[x2 + 2]; + d[8 * x + 5] = up[x]; + d[8 * x + 6] = yp[x2 + 3]; + d[8 * x + 7] = vp[x]; } } } static void extract_even_c(const uint8_t *src, uint8_t *dst, int count) { - dst += count; - src += 2*count; - count= - count; - - while(count<0) { - dst[count]= src[2*count]; + dst += count; + src += count * 2; + count = -count; + while (count < 0) { + dst[count] = src[2 * count]; count++; } } @@ -752,13 +773,13 @@ static void extract_even_c(const uint8_t *src, uint8_t *dst, int count) static void extract_even2_c(const uint8_t *src, uint8_t *dst0, uint8_t *dst1, int count) { - dst0+= count; - dst1+= count; - src += 4*count; - count= - count; - while(count<0) { - dst0[count]= src[4*count+0]; - dst1[count]= src[4*count+2]; + dst0 += count; + dst1 += count; + src += count * 4; + count = -count; + while (count < 0) { + dst0[count] = src[4 * count + 0]; + dst1[count] = src[4 * count + 2]; count++; } } @@ -766,14 +787,14 @@ static void extract_even2_c(const uint8_t *src, uint8_t *dst0, uint8_t *dst1, static void extract_even2avg_c(const uint8_t *src0, const uint8_t *src1, uint8_t *dst0, uint8_t *dst1, int count) { - dst0 += count; - dst1 += count; - src0 += 4*count; - src1 += 4*count; - count= - count; - while(count<0) { - dst0[count]= (src0[4*count+0]+src1[4*count+0])>>1; - dst1[count]= (src0[4*count+2]+src1[4*count+2])>>1; + dst0 += count; + dst1 += count; + src0 += count * 4; + src1 += count * 4; + count = -count; + while (count < 0) { + dst0[count] = (src0[4 * count + 0] + src1[4 * count + 0]) >> 1; + dst1[count] = (src0[4 * count + 2] + src1[4 * count + 2]) >> 1; count++; } } @@ -781,14 +802,14 @@ static void extract_even2avg_c(const uint8_t *src0, const uint8_t *src1, static void extract_odd2_c(const uint8_t *src, uint8_t *dst0, uint8_t *dst1, int count) { - dst0+= count; - dst1+= count; - src += 4*count; - count= - count; + dst0 += count; + dst1 += count; + src += count * 4; + count = -count; src++; - while(count<0) { - dst0[count]= src[4*count+0]; - dst1[count]= src[4*count+2]; + while (count < 0) { + dst0[count] = src[4 * count + 0]; + dst1[count] = src[4 * count + 2]; count++; } } @@ -796,16 +817,16 @@ static void extract_odd2_c(const uint8_t *src, uint8_t *dst0, uint8_t *dst1, static void extract_odd2avg_c(const uint8_t *src0, const uint8_t *src1, uint8_t *dst0, uint8_t *dst1, int count) { - dst0 += count; - dst1 += count; - src0 += 4*count; - src1 += 4*count; - count= - count; + dst0 += count; + dst1 += count; + src0 += count * 4; + src1 += count * 4; + count = -count; src0++; src1++; - while(count<0) { - dst0[count]= (src0[4*count+0]+src1[4*count+0])>>1; - dst1[count]= (src0[4*count+2]+src1[4*count+2])>>1; + while (count < 0) { + dst0[count] = (src0[4 * count + 0] + src1[4 * count + 0]) >> 1; + dst1[count] = (src0[4 * count + 2] + src1[4 * count + 2]) >> 1; count++; } } @@ -815,18 +836,18 @@ static void yuyvtoyuv420_c(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, int lumStride, int chromStride, int srcStride) { int y; - const int chromWidth= -((-width)>>1); + const int chromWidth = -((-width) >> 1); - for (y=0; y>1); + const int chromWidth = -((-width) >> 1); - for (y=0; y>1); + const int chromWidth = -((-width) >> 1); - for (y=0; y>1); + const int chromWidth = -((-width) >> 1); - for (y=0; y #include +#include "libavutil/cpu.h" +#include "libavutil/bswap.h" #include "config.h" #include "rgb2rgb.h" #include "swscale.h" #include "swscale_internal.h" -#include "libavutil/cpu.h" -#include "libavutil/bswap.h" extern const uint8_t dither_4x4_16[4][8]; extern const uint8_t dither_8x8_32[8][8]; @@ -41,14 +41,14 @@ extern const uint8_t dither_8x8_73[8][8]; extern const uint8_t dither_8x8_220[8][8]; const int32_t ff_yuv2rgb_coeffs[8][4] = { - {117504, 138453, 13954, 34903}, /* no sequence_display_extension */ - {117504, 138453, 13954, 34903}, /* ITU-R Rec. 709 (1990) */ - {104597, 132201, 25675, 53279}, /* unspecified */ - {104597, 132201, 25675, 53279}, /* reserved */ - {104448, 132798, 24759, 53109}, /* FCC */ - {104597, 132201, 25675, 53279}, /* ITU-R Rec. 624-4 System B, G */ - {104597, 132201, 25675, 53279}, /* SMPTE 170M */ - {117579, 136230, 16907, 35559} /* SMPTE 240M (1987) */ + { 117504, 138453, 13954, 34903 }, /* no sequence_display_extension */ + { 117504, 138453, 13954, 34903 }, /* ITU-R Rec. 709 (1990) */ + { 104597, 132201, 25675, 53279 }, /* unspecified */ + { 104597, 132201, 25675, 53279 }, /* reserved */ + { 104448, 132798, 24759, 53109 }, /* FCC */ + { 104597, 132201, 25675, 53279 }, /* ITU-R Rec. 624-4 System B, G */ + { 104597, 132201, 25675, 53279 }, /* SMPTE 170M */ + { 117579, 136230, 16907, 35559 } /* SMPTE 240M (1987) */ }; const int *sws_getCoefficients(int colorspace) @@ -65,503 +65,548 @@ const int *sws_getCoefficients(int colorspace) g = (void *)(c->table_gU[U] + c->table_gV[V]); \ b = (void *)c->table_bU[U]; -#define PUTRGB(dst,src,i) \ - Y = src[2*i]; \ - dst[2*i ] = r[Y] + g[Y] + b[Y]; \ - Y = src[2*i+1]; \ - dst[2*i+1] = r[Y] + g[Y] + b[Y]; +#define PUTRGB(dst, src, i) \ + Y = src[2 * i]; \ + dst[2 * i] = r[Y] + g[Y] + b[Y]; \ + Y = src[2 * i + 1]; \ + dst[2 * i + 1] = r[Y] + g[Y] + b[Y]; -#define PUTRGB24(dst,src,i) \ - Y = src[2*i]; \ - dst[6*i+0] = r[Y]; dst[6*i+1] = g[Y]; dst[6*i+2] = b[Y]; \ - Y = src[2*i+1]; \ - dst[6*i+3] = r[Y]; dst[6*i+4] = g[Y]; dst[6*i+5] = b[Y]; +#define PUTRGB24(dst, src, i) \ + Y = src[2 * i]; \ + dst[6 * i + 0] = r[Y]; \ + dst[6 * i + 1] = g[Y]; \ + dst[6 * i + 2] = b[Y]; \ + Y = src[2 * i + 1]; \ + dst[6 * i + 3] = r[Y]; \ + dst[6 * i + 4] = g[Y]; \ + dst[6 * i + 5] = b[Y]; -#define PUTBGR24(dst,src,i) \ - Y = src[2*i]; \ - dst[6*i+0] = b[Y]; dst[6*i+1] = g[Y]; dst[6*i+2] = r[Y]; \ - Y = src[2*i+1]; \ - dst[6*i+3] = b[Y]; dst[6*i+4] = g[Y]; dst[6*i+5] = r[Y]; +#define PUTBGR24(dst, src, i) \ + Y = src[2 * i]; \ + dst[6 * i + 0] = b[Y]; \ + dst[6 * i + 1] = g[Y]; \ + dst[6 * i + 2] = r[Y]; \ + Y = src[2 * i + 1]; \ + dst[6 * i + 3] = b[Y]; \ + dst[6 * i + 4] = g[Y]; \ + dst[6 * i + 5] = r[Y]; -#define PUTRGBA(dst,ysrc,asrc,i,s) \ - Y = ysrc[2*i]; \ - dst[2*i ] = r[Y] + g[Y] + b[Y] + (asrc[2*i ]<srcFormat == PIX_FMT_YUV422P) {\ - srcStride[1] *= 2;\ - srcStride[2] *= 2;\ - }\ - for (y=0; y>1)*srcStride[1];\ - const uint8_t *pv = src[2] + (y>>1)*srcStride[2];\ - const uint8_t av_unused *pa_1, *pa_2;\ - unsigned int h_size = c->dstW>>3;\ - if (alpha) {\ - pa_1 = src[3] + y*srcStride[3];\ - pa_2 = pa_1 + srcStride[3];\ - }\ - while (h_size--) {\ - int av_unused U, V;\ - int Y;\ +#define YUV2RGBFUNC(func_name, dst_type, alpha) \ + static int func_name(SwsContext *c, const uint8_t *src[], \ + int srcStride[], int srcSliceY, int srcSliceH, \ + uint8_t *dst[], int dstStride[]) \ + { \ + int y; \ + \ + if (!alpha && c->srcFormat == PIX_FMT_YUV422P) { \ + srcStride[1] *= 2; \ + srcStride[2] *= 2; \ + } \ + for (y = 0; y < srcSliceH; y += 2) { \ + dst_type *dst_1 = \ + (dst_type *)(dst[0] + (y + srcSliceY) * dstStride[0]); \ + dst_type *dst_2 = \ + (dst_type *)(dst[0] + (y + srcSliceY + 1) * dstStride[0]); \ + dst_type av_unused *r, *g, *b; \ + const uint8_t *py_1 = src[0] + y * srcStride[0]; \ + const uint8_t *py_2 = py_1 + srcStride[0]; \ + const uint8_t *pu = src[1] + (y >> 1) * srcStride[1]; \ + const uint8_t *pv = src[2] + (y >> 1) * srcStride[2]; \ + const uint8_t av_unused *pa_1, *pa_2; \ + unsigned int h_size = c->dstW >> 3; \ + if (alpha) { \ + pa_1 = src[3] + y * srcStride[3]; \ + pa_2 = pa_1 + srcStride[3]; \ + } \ + while (h_size--) { \ + int av_unused U, V, Y; \ -#define ENDYUV2RGBLINE(dst_delta)\ - pu += 4;\ - pv += 4;\ - py_1 += 8;\ - py_2 += 8;\ - dst_1 += dst_delta;\ - dst_2 += dst_delta;\ - }\ - if (c->dstW & 4) {\ - int av_unused Y, U, V;\ +#define ENDYUV2RGBLINE(dst_delta) \ + pu += 4; \ + pv += 4; \ + py_1 += 8; \ + py_2 += 8; \ + dst_1 += dst_delta; \ + dst_2 += dst_delta; \ + } \ + if (c->dstW & 4) { \ + int av_unused Y, U, V; \ -#define ENDYUV2RGBFUNC()\ - }\ - }\ - return srcSliceH;\ -} +#define ENDYUV2RGBFUNC() \ + } \ + } \ + return srcSliceH; \ + } -#define CLOSEYUV2RGBFUNC(dst_delta)\ - ENDYUV2RGBLINE(dst_delta)\ +#define CLOSEYUV2RGBFUNC(dst_delta) \ + ENDYUV2RGBLINE(dst_delta) \ ENDYUV2RGBFUNC() YUV2RGBFUNC(yuv2rgb_c_48, uint8_t, 0) LOADCHROMA(0); - PUTRGB48(dst_1,py_1,0); - PUTRGB48(dst_2,py_2,0); + PUTRGB48(dst_1, py_1, 0); + PUTRGB48(dst_2, py_2, 0); LOADCHROMA(1); - PUTRGB48(dst_2,py_2,1); - PUTRGB48(dst_1,py_1,1); + PUTRGB48(dst_2, py_2, 1); + PUTRGB48(dst_1, py_1, 1); LOADCHROMA(2); - PUTRGB48(dst_1,py_1,2); - PUTRGB48(dst_2,py_2,2); + PUTRGB48(dst_1, py_1, 2); + PUTRGB48(dst_2, py_2, 2); LOADCHROMA(3); - PUTRGB48(dst_2,py_2,3); - PUTRGB48(dst_1,py_1,3); + PUTRGB48(dst_2, py_2, 3); + PUTRGB48(dst_1, py_1, 3); ENDYUV2RGBLINE(48) LOADCHROMA(0); - PUTRGB48(dst_1,py_1,0); - PUTRGB48(dst_2,py_2,0); + PUTRGB48(dst_1, py_1, 0); + PUTRGB48(dst_2, py_2, 0); LOADCHROMA(1); - PUTRGB48(dst_2,py_2,1); - PUTRGB48(dst_1,py_1,1); + PUTRGB48(dst_2, py_2, 1); + PUTRGB48(dst_1, py_1, 1); ENDYUV2RGBFUNC() YUV2RGBFUNC(yuv2rgb_c_bgr48, uint8_t, 0) LOADCHROMA(0); - PUTBGR48(dst_1,py_1,0); - PUTBGR48(dst_2,py_2,0); + PUTBGR48(dst_1, py_1, 0); + PUTBGR48(dst_2, py_2, 0); LOADCHROMA(1); - PUTBGR48(dst_2,py_2,1); - PUTBGR48(dst_1,py_1,1); + PUTBGR48(dst_2, py_2, 1); + PUTBGR48(dst_1, py_1, 1); LOADCHROMA(2); - PUTBGR48(dst_1,py_1,2); - PUTBGR48(dst_2,py_2,2); + PUTBGR48(dst_1, py_1, 2); + PUTBGR48(dst_2, py_2, 2); LOADCHROMA(3); - PUTBGR48(dst_2,py_2,3); - PUTBGR48(dst_1,py_1,3); + PUTBGR48(dst_2, py_2, 3); + PUTBGR48(dst_1, py_1, 3); ENDYUV2RGBLINE(48) LOADCHROMA(0); - PUTBGR48(dst_1,py_1,0); - PUTBGR48(dst_2,py_2,0); + PUTBGR48(dst_1, py_1, 0); + PUTBGR48(dst_2, py_2, 0); LOADCHROMA(1); - PUTBGR48(dst_2,py_2,1); - PUTBGR48(dst_1,py_1,1); + PUTBGR48(dst_2, py_2, 1); + PUTBGR48(dst_1, py_1, 1); ENDYUV2RGBFUNC() YUV2RGBFUNC(yuv2rgb_c_32, uint32_t, 0) LOADCHROMA(0); - PUTRGB(dst_1,py_1,0); - PUTRGB(dst_2,py_2,0); + PUTRGB(dst_1, py_1, 0); + PUTRGB(dst_2, py_2, 0); LOADCHROMA(1); - PUTRGB(dst_2,py_2,1); - PUTRGB(dst_1,py_1,1); + PUTRGB(dst_2, py_2, 1); + PUTRGB(dst_1, py_1, 1); LOADCHROMA(2); - PUTRGB(dst_1,py_1,2); - PUTRGB(dst_2,py_2,2); + PUTRGB(dst_1, py_1, 2); + PUTRGB(dst_2, py_2, 2); LOADCHROMA(3); - PUTRGB(dst_2,py_2,3); - PUTRGB(dst_1,py_1,3); + PUTRGB(dst_2, py_2, 3); + PUTRGB(dst_1, py_1, 3); ENDYUV2RGBLINE(8) LOADCHROMA(0); - PUTRGB(dst_1,py_1,0); - PUTRGB(dst_2,py_2,0); + PUTRGB(dst_1, py_1, 0); + PUTRGB(dst_2, py_2, 0); LOADCHROMA(1); - PUTRGB(dst_2,py_2,1); - PUTRGB(dst_1,py_1,1); + PUTRGB(dst_2, py_2, 1); + PUTRGB(dst_1, py_1, 1); ENDYUV2RGBFUNC() YUV2RGBFUNC(yuva2rgba_c, uint32_t, 1) LOADCHROMA(0); - PUTRGBA(dst_1,py_1,pa_1,0,24); - PUTRGBA(dst_2,py_2,pa_2,0,24); + PUTRGBA(dst_1, py_1, pa_1, 0, 24); + PUTRGBA(dst_2, py_2, pa_2, 0, 24); LOADCHROMA(1); - PUTRGBA(dst_2,py_2,pa_1,1,24); - PUTRGBA(dst_1,py_1,pa_2,1,24); + PUTRGBA(dst_2, py_2, pa_1, 1, 24); + PUTRGBA(dst_1, py_1, pa_2, 1, 24); LOADCHROMA(2); - PUTRGBA(dst_1,py_1,pa_1,2,24); - PUTRGBA(dst_2,py_2,pa_2,2,24); + PUTRGBA(dst_1, py_1, pa_1, 2, 24); + PUTRGBA(dst_2, py_2, pa_2, 2, 24); LOADCHROMA(3); - PUTRGBA(dst_2,py_2,pa_1,3,24); - PUTRGBA(dst_1,py_1,pa_2,3,24); - pa_1 += 8;\ - pa_2 += 8;\ + PUTRGBA(dst_2, py_2, pa_1, 3, 24); + PUTRGBA(dst_1, py_1, pa_2, 3, 24); + pa_1 += 8; \ + pa_2 += 8; \ ENDYUV2RGBLINE(8) LOADCHROMA(0); - PUTRGBA(dst_1,py_1,pa_1,0,24); - PUTRGBA(dst_2,py_2,pa_2,0,24); + PUTRGBA(dst_1, py_1, pa_1, 0, 24); + PUTRGBA(dst_2, py_2, pa_2, 0, 24); LOADCHROMA(1); - PUTRGBA(dst_2,py_2,pa_1,1,24); - PUTRGBA(dst_1,py_1,pa_2,1,24); + PUTRGBA(dst_2, py_2, pa_1, 1, 24); + PUTRGBA(dst_1, py_1, pa_2, 1, 24); ENDYUV2RGBFUNC() YUV2RGBFUNC(yuva2argb_c, uint32_t, 1) LOADCHROMA(0); - PUTRGBA(dst_1,py_1,pa_1,0,0); - PUTRGBA(dst_2,py_2,pa_2,0,0); + PUTRGBA(dst_1, py_1, pa_1, 0, 0); + PUTRGBA(dst_2, py_2, pa_2, 0, 0); LOADCHROMA(1); - PUTRGBA(dst_2,py_2,pa_2,1,0); - PUTRGBA(dst_1,py_1,pa_1,1,0); + PUTRGBA(dst_2, py_2, pa_2, 1, 0); + PUTRGBA(dst_1, py_1, pa_1, 1, 0); LOADCHROMA(2); - PUTRGBA(dst_1,py_1,pa_1,2,0); - PUTRGBA(dst_2,py_2,pa_2,2,0); + PUTRGBA(dst_1, py_1, pa_1, 2, 0); + PUTRGBA(dst_2, py_2, pa_2, 2, 0); LOADCHROMA(3); - PUTRGBA(dst_2,py_2,pa_2,3,0); - PUTRGBA(dst_1,py_1,pa_1,3,0); - pa_1 += 8;\ - pa_2 += 8;\ + PUTRGBA(dst_2, py_2, pa_2, 3, 0); + PUTRGBA(dst_1, py_1, pa_1, 3, 0); + pa_1 += 8; \ + pa_2 += 8; \ ENDYUV2RGBLINE(8) LOADCHROMA(0); - PUTRGBA(dst_1,py_1,pa_1,0,0); - PUTRGBA(dst_2,py_2,pa_2,0,0); + PUTRGBA(dst_1, py_1, pa_1, 0, 0); + PUTRGBA(dst_2, py_2, pa_2, 0, 0); LOADCHROMA(1); - PUTRGBA(dst_2,py_2,pa_2,1,0); - PUTRGBA(dst_1,py_1,pa_1,1,0); + PUTRGBA(dst_2, py_2, pa_2, 1, 0); + PUTRGBA(dst_1, py_1, pa_1, 1, 0); ENDYUV2RGBFUNC() YUV2RGBFUNC(yuv2rgb_c_24_rgb, uint8_t, 0) LOADCHROMA(0); - PUTRGB24(dst_1,py_1,0); - PUTRGB24(dst_2,py_2,0); + PUTRGB24(dst_1, py_1, 0); + PUTRGB24(dst_2, py_2, 0); LOADCHROMA(1); - PUTRGB24(dst_2,py_2,1); - PUTRGB24(dst_1,py_1,1); + PUTRGB24(dst_2, py_2, 1); + PUTRGB24(dst_1, py_1, 1); LOADCHROMA(2); - PUTRGB24(dst_1,py_1,2); - PUTRGB24(dst_2,py_2,2); + PUTRGB24(dst_1, py_1, 2); + PUTRGB24(dst_2, py_2, 2); LOADCHROMA(3); - PUTRGB24(dst_2,py_2,3); - PUTRGB24(dst_1,py_1,3); + PUTRGB24(dst_2, py_2, 3); + PUTRGB24(dst_1, py_1, 3); ENDYUV2RGBLINE(24) LOADCHROMA(0); - PUTRGB24(dst_1,py_1,0); - PUTRGB24(dst_2,py_2,0); + PUTRGB24(dst_1, py_1, 0); + PUTRGB24(dst_2, py_2, 0); LOADCHROMA(1); - PUTRGB24(dst_2,py_2,1); - PUTRGB24(dst_1,py_1,1); + PUTRGB24(dst_2, py_2, 1); + PUTRGB24(dst_1, py_1, 1); ENDYUV2RGBFUNC() // only trivial mods from yuv2rgb_c_24_rgb YUV2RGBFUNC(yuv2rgb_c_24_bgr, uint8_t, 0) LOADCHROMA(0); - PUTBGR24(dst_1,py_1,0); - PUTBGR24(dst_2,py_2,0); + PUTBGR24(dst_1, py_1, 0); + PUTBGR24(dst_2, py_2, 0); LOADCHROMA(1); - PUTBGR24(dst_2,py_2,1); - PUTBGR24(dst_1,py_1,1); + PUTBGR24(dst_2, py_2, 1); + PUTBGR24(dst_1, py_1, 1); LOADCHROMA(2); - PUTBGR24(dst_1,py_1,2); - PUTBGR24(dst_2,py_2,2); + PUTBGR24(dst_1, py_1, 2); + PUTBGR24(dst_2, py_2, 2); LOADCHROMA(3); - PUTBGR24(dst_2,py_2,3); - PUTBGR24(dst_1,py_1,3); + PUTBGR24(dst_2, py_2, 3); + PUTBGR24(dst_1, py_1, 3); ENDYUV2RGBLINE(24) LOADCHROMA(0); - PUTBGR24(dst_1,py_1,0); - PUTBGR24(dst_2,py_2,0); + PUTBGR24(dst_1, py_1, 0); + PUTBGR24(dst_2, py_2, 0); LOADCHROMA(1); - PUTBGR24(dst_2,py_2,1); - PUTBGR24(dst_1,py_1,1); + PUTBGR24(dst_2, py_2, 1); + PUTBGR24(dst_1, py_1, 1); ENDYUV2RGBFUNC() // This is exactly the same code as yuv2rgb_c_32 except for the types of // r, g, b, dst_1, dst_2 YUV2RGBFUNC(yuv2rgb_c_16, uint16_t, 0) LOADCHROMA(0); - PUTRGB(dst_1,py_1,0); - PUTRGB(dst_2,py_2,0); + PUTRGB(dst_1, py_1, 0); + PUTRGB(dst_2, py_2, 0); LOADCHROMA(1); - PUTRGB(dst_2,py_2,1); - PUTRGB(dst_1,py_1,1); + PUTRGB(dst_2, py_2, 1); + PUTRGB(dst_1, py_1, 1); LOADCHROMA(2); - PUTRGB(dst_1,py_1,2); - PUTRGB(dst_2,py_2,2); + PUTRGB(dst_1, py_1, 2); + PUTRGB(dst_2, py_2, 2); LOADCHROMA(3); - PUTRGB(dst_2,py_2,3); - PUTRGB(dst_1,py_1,3); + PUTRGB(dst_2, py_2, 3); + PUTRGB(dst_1, py_1, 3); CLOSEYUV2RGBFUNC(8) // r, g, b, dst_1, dst_2 YUV2RGBFUNC(yuv2rgb_c_12_ordered_dither, uint16_t, 0) - const uint8_t *d16 = dither_4x4_16[y&3]; -#define PUTRGB12(dst,src,i,o) \ - Y = src[2*i]; \ - dst[2*i] = r[Y+d16[0+o]] + g[Y+d16[0+o]] + b[Y+d16[0+o]]; \ - Y = src[2*i+1]; \ - dst[2*i+1] = r[Y+d16[1+o]] + g[Y+d16[1+o]] + b[Y+d16[1+o]]; + const uint8_t *d16 = dither_4x4_16[y & 3]; + +#define PUTRGB12(dst, src, i, o) \ + Y = src[2 * i]; \ + dst[2 * i] = r[Y + d16[0 + o]] + \ + g[Y + d16[0 + o]] + \ + b[Y + d16[0 + o]]; \ + Y = src[2 * i + 1]; \ + dst[2 * i + 1] = r[Y + d16[1 + o]] + \ + g[Y + d16[1 + o]] + \ + b[Y + d16[1 + o]]; LOADCHROMA(0); - PUTRGB12(dst_1,py_1,0,0); - PUTRGB12(dst_2,py_2,0,0+8); + PUTRGB12(dst_1, py_1, 0, 0); + PUTRGB12(dst_2, py_2, 0, 0 + 8); LOADCHROMA(1); - PUTRGB12(dst_2,py_2,1,2+8); - PUTRGB12(dst_1,py_1,1,2); + PUTRGB12(dst_2, py_2, 1, 2 + 8); + PUTRGB12(dst_1, py_1, 1, 2); LOADCHROMA(2); - PUTRGB12(dst_1,py_1,2,4); - PUTRGB12(dst_2,py_2,2,4+8); + PUTRGB12(dst_1, py_1, 2, 4); + PUTRGB12(dst_2, py_2, 2, 4 + 8); LOADCHROMA(3); - PUTRGB12(dst_2,py_2,3,6+8); - PUTRGB12(dst_1,py_1,3,6); + PUTRGB12(dst_2, py_2, 3, 6 + 8); + PUTRGB12(dst_1, py_1, 3, 6); CLOSEYUV2RGBFUNC(8) // r, g, b, dst_1, dst_2 YUV2RGBFUNC(yuv2rgb_c_8_ordered_dither, uint8_t, 0) - const uint8_t *d32 = dither_8x8_32[y&7]; - const uint8_t *d64 = dither_8x8_73[y&7]; -#define PUTRGB8(dst,src,i,o) \ - Y = src[2*i]; \ - dst[2*i] = r[Y+d32[0+o]] + g[Y+d32[0+o]] + b[Y+d64[0+o]]; \ - Y = src[2*i+1]; \ - dst[2*i+1] = r[Y+d32[1+o]] + g[Y+d32[1+o]] + b[Y+d64[1+o]]; + const uint8_t *d32 = dither_8x8_32[y & 7]; + const uint8_t *d64 = dither_8x8_73[y & 7]; + +#define PUTRGB8(dst, src, i, o) \ + Y = src[2 * i]; \ + dst[2 * i] = r[Y + d32[0 + o]] + \ + g[Y + d32[0 + o]] + \ + b[Y + d64[0 + o]]; \ + Y = src[2 * i + 1]; \ + dst[2 * i + 1] = r[Y + d32[1 + o]] + \ + g[Y + d32[1 + o]] + \ + b[Y + d64[1 + o]]; LOADCHROMA(0); - PUTRGB8(dst_1,py_1,0,0); - PUTRGB8(dst_2,py_2,0,0+8); + PUTRGB8(dst_1, py_1, 0, 0); + PUTRGB8(dst_2, py_2, 0, 0 + 8); LOADCHROMA(1); - PUTRGB8(dst_2,py_2,1,2+8); - PUTRGB8(dst_1,py_1,1,2); + PUTRGB8(dst_2, py_2, 1, 2 + 8); + PUTRGB8(dst_1, py_1, 1, 2); LOADCHROMA(2); - PUTRGB8(dst_1,py_1,2,4); - PUTRGB8(dst_2,py_2,2,4+8); + PUTRGB8(dst_1, py_1, 2, 4); + PUTRGB8(dst_2, py_2, 2, 4 + 8); LOADCHROMA(3); - PUTRGB8(dst_2,py_2,3,6+8); - PUTRGB8(dst_1,py_1,3,6); + PUTRGB8(dst_2, py_2, 3, 6 + 8); + PUTRGB8(dst_1, py_1, 3, 6); CLOSEYUV2RGBFUNC(8) YUV2RGBFUNC(yuv2rgb_c_4_ordered_dither, uint8_t, 0) - const uint8_t *d64 = dither_8x8_73[y&7]; - const uint8_t *d128 = dither_8x8_220[y&7]; + const uint8_t * d64 = dither_8x8_73[y & 7]; + const uint8_t *d128 = dither_8x8_220[y & 7]; int acc; -#define PUTRGB4D(dst,src,i,o) \ - Y = src[2*i]; \ - acc = r[Y+d128[0+o]] + g[Y+d64[0+o]] + b[Y+d128[0+o]]; \ - Y = src[2*i+1]; \ - acc |= (r[Y+d128[1+o]] + g[Y+d64[1+o]] + b[Y+d128[1+o]])<<4; \ - dst[i]= acc; +#define PUTRGB4D(dst, src, i, o) \ + Y = src[2 * i]; \ + acc = r[Y + d128[0 + o]] + \ + g[Y + d64[0 + o]] + \ + b[Y + d128[0 + o]]; \ + Y = src[2 * i + 1]; \ + acc |= (r[Y + d128[1 + o]] + \ + g[Y + d64[1 + o]] + \ + b[Y + d128[1 + o]]) << 4; \ + dst[i] = acc; LOADCHROMA(0); - PUTRGB4D(dst_1,py_1,0,0); - PUTRGB4D(dst_2,py_2,0,0+8); + PUTRGB4D(dst_1, py_1, 0, 0); + PUTRGB4D(dst_2, py_2, 0, 0 + 8); LOADCHROMA(1); - PUTRGB4D(dst_2,py_2,1,2+8); - PUTRGB4D(dst_1,py_1,1,2); + PUTRGB4D(dst_2, py_2, 1, 2 + 8); + PUTRGB4D(dst_1, py_1, 1, 2); LOADCHROMA(2); - PUTRGB4D(dst_1,py_1,2,4); - PUTRGB4D(dst_2,py_2,2,4+8); + PUTRGB4D(dst_1, py_1, 2, 4); + PUTRGB4D(dst_2, py_2, 2, 4 + 8); LOADCHROMA(3); - PUTRGB4D(dst_2,py_2,3,6+8); - PUTRGB4D(dst_1,py_1,3,6); + PUTRGB4D(dst_2, py_2, 3, 6 + 8); + PUTRGB4D(dst_1, py_1, 3, 6); CLOSEYUV2RGBFUNC(4) YUV2RGBFUNC(yuv2rgb_c_4b_ordered_dither, uint8_t, 0) - const uint8_t *d64 = dither_8x8_73[y&7]; - const uint8_t *d128 = dither_8x8_220[y&7]; + const uint8_t *d64 = dither_8x8_73[y & 7]; + const uint8_t *d128 = dither_8x8_220[y & 7]; -#define PUTRGB4DB(dst,src,i,o) \ - Y = src[2*i]; \ - dst[2*i] = r[Y+d128[0+o]] + g[Y+d64[0+o]] + b[Y+d128[0+o]]; \ - Y = src[2*i+1]; \ - dst[2*i+1] = r[Y+d128[1+o]] + g[Y+d64[1+o]] + b[Y+d128[1+o]]; +#define PUTRGB4DB(dst, src, i, o) \ + Y = src[2 * i]; \ + dst[2 * i] = r[Y + d128[0 + o]] + \ + g[Y + d64[0 + o]] + \ + b[Y + d128[0 + o]]; \ + Y = src[2 * i + 1]; \ + dst[2 * i + 1] = r[Y + d128[1 + o]] + \ + g[Y + d64[1 + o]] + \ + b[Y + d128[1 + o]]; LOADCHROMA(0); - PUTRGB4DB(dst_1,py_1,0,0); - PUTRGB4DB(dst_2,py_2,0,0+8); + PUTRGB4DB(dst_1, py_1, 0, 0); + PUTRGB4DB(dst_2, py_2, 0, 0 + 8); LOADCHROMA(1); - PUTRGB4DB(dst_2,py_2,1,2+8); - PUTRGB4DB(dst_1,py_1,1,2); + PUTRGB4DB(dst_2, py_2, 1, 2 + 8); + PUTRGB4DB(dst_1, py_1, 1, 2); LOADCHROMA(2); - PUTRGB4DB(dst_1,py_1,2,4); - PUTRGB4DB(dst_2,py_2,2,4+8); + PUTRGB4DB(dst_1, py_1, 2, 4); + PUTRGB4DB(dst_2, py_2, 2, 4 + 8); LOADCHROMA(3); - PUTRGB4DB(dst_2,py_2,3,6+8); - PUTRGB4DB(dst_1,py_1,3,6); + PUTRGB4DB(dst_2, py_2, 3, 6 + 8); + PUTRGB4DB(dst_1, py_1, 3, 6); CLOSEYUV2RGBFUNC(8) YUV2RGBFUNC(yuv2rgb_c_1_ordered_dither, uint8_t, 0) - const uint8_t *d128 = dither_8x8_220[y&7]; - char out_1 = 0, out_2 = 0; - g= c->table_gU[128] + c->table_gV[128]; + const uint8_t *d128 = dither_8x8_220[y & 7]; + char out_1 = 0, out_2 = 0; + g = c->table_gU[128] + c->table_gV[128]; -#define PUTRGB1(out,src,i,o) \ - Y = src[2*i]; \ - out+= out + g[Y+d128[0+o]]; \ - Y = src[2*i+1]; \ - out+= out + g[Y+d128[1+o]]; +#define PUTRGB1(out, src, i, o) \ + Y = src[2 * i]; \ + out += out + g[Y + d128[0 + o]]; \ + Y = src[2 * i + 1]; \ + out += out + g[Y + d128[1 + o]]; - PUTRGB1(out_1,py_1,0,0); - PUTRGB1(out_2,py_2,0,0+8); + PUTRGB1(out_1, py_1, 0, 0); + PUTRGB1(out_2, py_2, 0, 0 + 8); - PUTRGB1(out_2,py_2,1,2+8); - PUTRGB1(out_1,py_1,1,2); + PUTRGB1(out_2, py_2, 1, 2 + 8); + PUTRGB1(out_1, py_1, 1, 2); - PUTRGB1(out_1,py_1,2,4); - PUTRGB1(out_2,py_2,2,4+8); + PUTRGB1(out_1, py_1, 2, 4); + PUTRGB1(out_2, py_2, 2, 4 + 8); - PUTRGB1(out_2,py_2,3,6+8); - PUTRGB1(out_1,py_1,3,6); + PUTRGB1(out_2, py_2, 3, 6 + 8); + PUTRGB1(out_1, py_1, 3, 6); - dst_1[0]= out_1; - dst_2[0]= out_2; + dst_1[0] = out_1; + dst_2[0] = out_2; CLOSEYUV2RGBFUNC(1) SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c) { SwsFunc t = NULL; - if (HAVE_MMX) { + if (HAVE_MMX) t = ff_yuv2rgb_init_mmx(c); - } else if (HAVE_VIS) { + else if (HAVE_VIS) t = ff_yuv2rgb_init_vis(c); - } else if (HAVE_ALTIVEC) { + else if (HAVE_ALTIVEC) t = ff_yuv2rgb_init_altivec(c); - } else if (ARCH_BFIN) { + else if (ARCH_BFIN) t = ff_yuv2rgb_get_func_ptr_bfin(c); - } if (t) return t; - av_log(c, AV_LOG_WARNING, "No accelerated colorspace conversion found from %s to %s.\n", sws_format_name(c->srcFormat), sws_format_name(c->dstFormat)); + av_log(c, AV_LOG_WARNING, + "No accelerated colorspace conversion found from %s to %s.\n", + sws_format_name(c->srcFormat), sws_format_name(c->dstFormat)); switch (c->dstFormat) { case PIX_FMT_BGR48BE: - case PIX_FMT_BGR48LE: return yuv2rgb_c_bgr48; + case PIX_FMT_BGR48LE: + return yuv2rgb_c_bgr48; case PIX_FMT_RGB48BE: - case PIX_FMT_RGB48LE: return yuv2rgb_c_48; + case PIX_FMT_RGB48LE: + return yuv2rgb_c_48; case PIX_FMT_ARGB: - case PIX_FMT_ABGR: if (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX_FMT_YUVA420P) return yuva2argb_c; + case PIX_FMT_ABGR: + if (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX_FMT_YUVA420P) + return yuva2argb_c; case PIX_FMT_RGBA: - case PIX_FMT_BGRA: return (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX_FMT_YUVA420P) ? yuva2rgba_c : yuv2rgb_c_32; - case PIX_FMT_RGB24: return yuv2rgb_c_24_rgb; - case PIX_FMT_BGR24: return yuv2rgb_c_24_bgr; + case PIX_FMT_BGRA: + if (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX_FMT_YUVA420P) + return yuva2rgba_c; + else + return yuv2rgb_c_32; + case PIX_FMT_RGB24: + return yuv2rgb_c_24_rgb; + case PIX_FMT_BGR24: + return yuv2rgb_c_24_bgr; case PIX_FMT_RGB565: case PIX_FMT_BGR565: case PIX_FMT_RGB555: - case PIX_FMT_BGR555: return yuv2rgb_c_16; + case PIX_FMT_BGR555: + return yuv2rgb_c_16; case PIX_FMT_RGB444: - case PIX_FMT_BGR444: return yuv2rgb_c_12_ordered_dither; + case PIX_FMT_BGR444: + return yuv2rgb_c_12_ordered_dither; case PIX_FMT_RGB8: - case PIX_FMT_BGR8: return yuv2rgb_c_8_ordered_dither; + case PIX_FMT_BGR8: + return yuv2rgb_c_8_ordered_dither; case PIX_FMT_RGB4: - case PIX_FMT_BGR4: return yuv2rgb_c_4_ordered_dither; + case PIX_FMT_BGR4: + return yuv2rgb_c_4_ordered_dither; case PIX_FMT_RGB4_BYTE: - case PIX_FMT_BGR4_BYTE: return yuv2rgb_c_4b_ordered_dither; - case PIX_FMT_MONOBLACK: return yuv2rgb_c_1_ordered_dither; + case PIX_FMT_BGR4_BYTE: + return yuv2rgb_c_4b_ordered_dither; + case PIX_FMT_MONOBLACK: + return yuv2rgb_c_1_ordered_dither; default: assert(0); } return NULL; } -static void fill_table(uint8_t* table[256], const int elemsize, const int inc, void *y_tab) +static void fill_table(uint8_t *table[256], const int elemsize, + const int inc, void *y_tab) { int i; - int64_t cb = 0; + int64_t cb = 0; uint8_t *y_table = y_tab; y_table -= elemsize * (inc >> 9); for (i = 0; i < 256; i++) { table[i] = y_table + elemsize * (cb >> 16); - cb += inc; + cb += inc; } } @@ -569,44 +614,49 @@ static void fill_gv_table(int table[256], const int elemsize, const int inc) { int i; int64_t cb = 0; - int off = -(inc >> 9); + int off = -(inc >> 9); for (i = 0; i < 256; i++) { table[i] = elemsize * (off + (cb >> 16)); - cb += inc; + cb += inc; } } static uint16_t roundToInt16(int64_t f) { - int r= (f + (1<<15))>>16; - if (r<-0x7FFF) return 0x8000; - else if (r> 0x7FFF) return 0x7FFF; - else return r; + int r = (f + (1 << 15)) >> 16; + + if (r < -0x7FFF) + return 0x8000; + else if (r > 0x7FFF) + return 0x7FFF; + else + return r; } -av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4], int fullRange, - int brightness, int contrast, int saturation) +av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4], + int fullRange, int brightness, + int contrast, int saturation) { - const int isRgb = c->dstFormat==PIX_FMT_RGB32 - || c->dstFormat==PIX_FMT_RGB32_1 - || c->dstFormat==PIX_FMT_BGR24 - || c->dstFormat==PIX_FMT_RGB565BE - || c->dstFormat==PIX_FMT_RGB565LE - || c->dstFormat==PIX_FMT_RGB555BE - || c->dstFormat==PIX_FMT_RGB555LE - || c->dstFormat==PIX_FMT_RGB444BE - || c->dstFormat==PIX_FMT_RGB444LE - || c->dstFormat==PIX_FMT_RGB8 - || c->dstFormat==PIX_FMT_RGB4 - || c->dstFormat==PIX_FMT_RGB4_BYTE - || c->dstFormat==PIX_FMT_MONOBLACK; - const int isNotNe = c->dstFormat==PIX_FMT_NE(RGB565LE,RGB565BE) - || c->dstFormat==PIX_FMT_NE(RGB555LE,RGB555BE) - || c->dstFormat==PIX_FMT_NE(RGB444LE,RGB444BE) - || c->dstFormat==PIX_FMT_NE(BGR565LE,BGR565BE) - || c->dstFormat==PIX_FMT_NE(BGR555LE,BGR555BE) - || c->dstFormat==PIX_FMT_NE(BGR444LE,BGR444BE); + const int isRgb = c->dstFormat == PIX_FMT_RGB32 || + c->dstFormat == PIX_FMT_RGB32_1 || + c->dstFormat == PIX_FMT_BGR24 || + c->dstFormat == PIX_FMT_RGB565BE || + c->dstFormat == PIX_FMT_RGB565LE || + c->dstFormat == PIX_FMT_RGB555BE || + c->dstFormat == PIX_FMT_RGB555LE || + c->dstFormat == PIX_FMT_RGB444BE || + c->dstFormat == PIX_FMT_RGB444LE || + c->dstFormat == PIX_FMT_RGB8 || + c->dstFormat == PIX_FMT_RGB4 || + c->dstFormat == PIX_FMT_RGB4_BYTE || + c->dstFormat == PIX_FMT_MONOBLACK; + const int isNotNe = c->dstFormat == PIX_FMT_NE(RGB565LE, RGB565BE) || + c->dstFormat == PIX_FMT_NE(RGB555LE, RGB555BE) || + c->dstFormat == PIX_FMT_NE(RGB444LE, RGB444BE) || + c->dstFormat == PIX_FMT_NE(BGR565LE, BGR565BE) || + c->dstFormat == PIX_FMT_NE(BGR555LE, BGR555BE) || + c->dstFormat == PIX_FMT_NE(BGR444LE, BGR444BE); const int bpp = c->dstFormatBpp; uint8_t *y_table; uint16_t *y_table16; @@ -618,43 +668,42 @@ av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4], int int64_t cbu = inv_table[1]; int64_t cgu = -inv_table[2]; int64_t cgv = -inv_table[3]; - int64_t cy = 1<<16; + int64_t cy = 1 << 16; int64_t oy = 0; - - int64_t yb = 0; + int64_t yb = 0; if (!fullRange) { - cy = (cy*255) / 219; - oy = 16<<16; + cy = (cy * 255) / 219; + oy = 16 << 16; } else { - crv = (crv*224) / 255; - cbu = (cbu*224) / 255; - cgu = (cgu*224) / 255; - cgv = (cgv*224) / 255; + crv = (crv * 224) / 255; + cbu = (cbu * 224) / 255; + cgu = (cgu * 224) / 255; + cgv = (cgv * 224) / 255; } - cy = (cy *contrast ) >> 16; - crv = (crv*contrast * saturation) >> 32; - cbu = (cbu*contrast * saturation) >> 32; - cgu = (cgu*contrast * saturation) >> 32; - cgv = (cgv*contrast * saturation) >> 32; - oy -= 256*brightness; + cy = (cy * contrast) >> 16; + crv = (crv * contrast * saturation) >> 32; + cbu = (cbu * contrast * saturation) >> 32; + cgu = (cgu * contrast * saturation) >> 32; + cgv = (cgv * contrast * saturation) >> 32; + oy -= 256 * brightness; - c->uOffset= 0x0400040004000400LL; - c->vOffset= 0x0400040004000400LL; - c->yCoeff= roundToInt16(cy *8192) * 0x0001000100010001ULL; - c->vrCoeff= roundToInt16(crv*8192) * 0x0001000100010001ULL; - c->ubCoeff= roundToInt16(cbu*8192) * 0x0001000100010001ULL; - c->vgCoeff= roundToInt16(cgv*8192) * 0x0001000100010001ULL; - c->ugCoeff= roundToInt16(cgu*8192) * 0x0001000100010001ULL; - c->yOffset= roundToInt16(oy * 8) * 0x0001000100010001ULL; + c->uOffset = 0x0400040004000400LL; + c->vOffset = 0x0400040004000400LL; + c->yCoeff = roundToInt16(cy * 8192) * 0x0001000100010001ULL; + c->vrCoeff = roundToInt16(crv * 8192) * 0x0001000100010001ULL; + c->ubCoeff = roundToInt16(cbu * 8192) * 0x0001000100010001ULL; + c->vgCoeff = roundToInt16(cgv * 8192) * 0x0001000100010001ULL; + c->ugCoeff = roundToInt16(cgu * 8192) * 0x0001000100010001ULL; + c->yOffset = roundToInt16(oy * 8) * 0x0001000100010001ULL; - c->yuv2rgb_y_coeff = (int16_t)roundToInt16(cy <<13); - c->yuv2rgb_y_offset = (int16_t)roundToInt16(oy << 9); - c->yuv2rgb_v2r_coeff= (int16_t)roundToInt16(crv<<13); - c->yuv2rgb_v2g_coeff= (int16_t)roundToInt16(cgv<<13); - c->yuv2rgb_u2g_coeff= (int16_t)roundToInt16(cgu<<13); - c->yuv2rgb_u2b_coeff= (int16_t)roundToInt16(cbu<<13); + c->yuv2rgb_y_coeff = (int16_t)roundToInt16(cy << 13); + c->yuv2rgb_y_offset = (int16_t)roundToInt16(oy << 9); + c->yuv2rgb_v2r_coeff = (int16_t)roundToInt16(crv << 13); + c->yuv2rgb_v2g_coeff = (int16_t)roundToInt16(cgv << 13); + c->yuv2rgb_u2g_coeff = (int16_t)roundToInt16(cgu << 13); + c->yuv2rgb_u2b_coeff = (int16_t)roundToInt16(cbu << 13); //scale coefficients by cy crv = ((crv << 16) + 0x8000) / cy; @@ -667,28 +716,28 @@ av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4], int switch (bpp) { case 1: c->yuvTable = av_malloc(1024); - y_table = c->yuvTable; - yb = -(384<<16) - oy; - for (i = 0; i < 1024-110; i++) { - y_table[i+110] = av_clip_uint8((yb + 0x8000) >> 16) >> 7; - yb += cy; + y_table = c->yuvTable; + yb = -(384 << 16) - oy; + for (i = 0; i < 1024 - 110; i++) { + y_table[i + 110] = av_clip_uint8((yb + 0x8000) >> 16) >> 7; + yb += cy; } fill_table(c->table_gU, 1, cgu, y_table + yoffs); fill_gv_table(c->table_gV, 1, cgv); break; case 4: - case 4|128: - rbase = isRgb ? 3 : 0; - gbase = 1; - bbase = isRgb ? 0 : 3; - c->yuvTable = av_malloc(1024*3); - y_table = c->yuvTable; - yb = -(384<<16) - oy; - for (i = 0; i < 1024-110; i++) { - int yval = av_clip_uint8((yb + 0x8000) >> 16); - y_table[i+110 ] = (yval >> 7) << rbase; - y_table[i+ 37+1024] = ((yval + 43) / 85) << gbase; - y_table[i+110+2048] = (yval >> 7) << bbase; + case 4 | 128: + rbase = isRgb ? 3 : 0; + gbase = 1; + bbase = isRgb ? 0 : 3; + c->yuvTable = av_malloc(1024 * 3); + y_table = c->yuvTable; + yb = -(384 << 16) - oy; + for (i = 0; i < 1024 - 110; i++) { + int yval = av_clip_uint8((yb + 0x8000) >> 16); + y_table[i + 110] = (yval >> 7) << rbase; + y_table[i + 37 + 1024] = ((yval + 43) / 85) << gbase; + y_table[i + 110 + 2048] = (yval >> 7) << bbase; yb += cy; } fill_table(c->table_rV, 1, crv, y_table + yoffs); @@ -697,17 +746,17 @@ av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4], int fill_gv_table(c->table_gV, 1, cgv); break; case 8: - rbase = isRgb ? 5 : 0; - gbase = isRgb ? 2 : 3; - bbase = isRgb ? 0 : 6; - c->yuvTable = av_malloc(1024*3); - y_table = c->yuvTable; - yb = -(384<<16) - oy; - for (i = 0; i < 1024-38; i++) { - int yval = av_clip_uint8((yb + 0x8000) >> 16); - y_table[i+16 ] = ((yval + 18) / 36) << rbase; - y_table[i+16+1024] = ((yval + 18) / 36) << gbase; - y_table[i+37+2048] = ((yval + 43) / 85) << bbase; + rbase = isRgb ? 5 : 0; + gbase = isRgb ? 2 : 3; + bbase = isRgb ? 0 : 6; + c->yuvTable = av_malloc(1024 * 3); + y_table = c->yuvTable; + yb = -(384 << 16) - oy; + for (i = 0; i < 1024 - 38; i++) { + int yval = av_clip_uint8((yb + 0x8000) >> 16); + y_table[i + 16] = ((yval + 18) / 36) << rbase; + y_table[i + 16 + 1024] = ((yval + 18) / 36) << gbase; + y_table[i + 37 + 2048] = ((yval + 43) / 85) << bbase; yb += cy; } fill_table(c->table_rV, 1, crv, y_table + yoffs); @@ -716,21 +765,21 @@ av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4], int fill_gv_table(c->table_gV, 1, cgv); break; case 12: - rbase = isRgb ? 8 : 0; - gbase = 4; - bbase = isRgb ? 0 : 8; - c->yuvTable = av_malloc(1024*3*2); - y_table16 = c->yuvTable; - yb = -(384<<16) - oy; + rbase = isRgb ? 8 : 0; + gbase = 4; + bbase = isRgb ? 0 : 8; + c->yuvTable = av_malloc(1024 * 3 * 2); + y_table16 = c->yuvTable; + yb = -(384 << 16) - oy; for (i = 0; i < 1024; i++) { - uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16); - y_table16[i ] = (yval >> 4) << rbase; - y_table16[i+1024] = (yval >> 4) << gbase; - y_table16[i+2048] = (yval >> 4) << bbase; + uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16); + y_table16[i] = (yval >> 4) << rbase; + y_table16[i + 1024] = (yval >> 4) << gbase; + y_table16[i + 2048] = (yval >> 4) << bbase; yb += cy; } if (isNotNe) - for (i = 0; i < 1024*3; i++) + for (i = 0; i < 1024 * 3; i++) y_table16[i] = av_bswap16(y_table16[i]); fill_table(c->table_rV, 2, crv, y_table16 + yoffs); fill_table(c->table_gU, 2, cgu, y_table16 + yoffs + 1024); @@ -739,21 +788,21 @@ av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4], int break; case 15: case 16: - rbase = isRgb ? bpp - 5 : 0; - gbase = 5; - bbase = isRgb ? 0 : (bpp - 5); - c->yuvTable = av_malloc(1024*3*2); - y_table16 = c->yuvTable; - yb = -(384<<16) - oy; + rbase = isRgb ? bpp - 5 : 0; + gbase = 5; + bbase = isRgb ? 0 : (bpp - 5); + c->yuvTable = av_malloc(1024 * 3 * 2); + y_table16 = c->yuvTable; + yb = -(384 << 16) - oy; for (i = 0; i < 1024; i++) { - uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16); - y_table16[i ] = (yval >> 3) << rbase; - y_table16[i+1024] = (yval >> (18 - bpp)) << gbase; - y_table16[i+2048] = (yval >> 3) << bbase; + uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16); + y_table16[i] = (yval >> 3) << rbase; + y_table16[i + 1024] = (yval >> (18 - bpp)) << gbase; + y_table16[i + 2048] = (yval >> 3) << bbase; yb += cy; } - if(isNotNe) - for (i = 0; i < 1024*3; i++) + if (isNotNe) + for (i = 0; i < 1024 * 3; i++) y_table16[i] = av_bswap16(y_table16[i]); fill_table(c->table_rV, 2, crv, y_table16 + yoffs); fill_table(c->table_gU, 2, cgu, y_table16 + yoffs + 1024); @@ -763,11 +812,11 @@ av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4], int case 24: case 48: c->yuvTable = av_malloc(1024); - y_table = c->yuvTable; - yb = -(384<<16) - oy; + y_table = c->yuvTable; + yb = -(384 << 16) - oy; for (i = 0; i < 1024; i++) { - y_table[i] = av_clip_uint8((yb + 0x8000) >> 16); - yb += cy; + y_table[i] = av_clip_uint8((yb + 0x8000) >> 16); + yb += cy; } fill_table(c->table_rV, 1, crv, y_table + yoffs); fill_table(c->table_gU, 1, cgu, y_table + yoffs); @@ -775,21 +824,23 @@ av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4], int fill_gv_table(c->table_gV, 1, cgv); break; case 32: - base = (c->dstFormat == PIX_FMT_RGB32_1 || c->dstFormat == PIX_FMT_BGR32_1) ? 8 : 0; - rbase = base + (isRgb ? 16 : 0); - gbase = base + 8; - bbase = base + (isRgb ? 0 : 16); + base = (c->dstFormat == PIX_FMT_RGB32_1 || + c->dstFormat == PIX_FMT_BGR32_1) ? 8 : 0; + rbase = base + (isRgb ? 16 : 0); + gbase = base + 8; + bbase = base + (isRgb ? 0 : 16); needAlpha = CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat); if (!needAlpha) abase = (base + 24) & 31; - c->yuvTable = av_malloc(1024*3*4); - y_table32 = c->yuvTable; - yb = -(384<<16) - oy; + c->yuvTable = av_malloc(1024 * 3 * 4); + y_table32 = c->yuvTable; + yb = -(384 << 16) - oy; for (i = 0; i < 1024; i++) { - unsigned yval = av_clip_uint8((yb + 0x8000) >> 16); - y_table32[i ] = (yval << rbase) + (needAlpha ? 0 : (255u << abase)); - y_table32[i+1024] = yval << gbase; - y_table32[i+2048] = yval << bbase; + unsigned yval = av_clip_uint8((yb + 0x8000) >> 16); + y_table32[i] = (yval << rbase) + + (needAlpha ? 0 : (255u << abase)); + y_table32[i + 1024] = yval << gbase; + y_table32[i + 2048] = yval << bbase; yb += cy; } fill_table(c->table_rV, 4, crv, y_table32 + yoffs); From 0ad522afb3a3b3d22402ecb82dd4609f7655031b Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Tue, 21 Feb 2012 14:08:02 -0800 Subject: [PATCH 03/19] mov: Add support for MPEG2 HDV 720p24 (hdv4) --- libavformat/isom.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavformat/isom.c b/libavformat/isom.c index 51e89a0a62..d702d9a349 100644 --- a/libavformat/isom.c +++ b/libavformat/isom.c @@ -159,6 +159,7 @@ const AVCodecTag ff_codec_movvideo_tags[] = { { CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '1') }, /* MPEG2 HDV 720p30 */ { CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '2') }, /* MPEG2 HDV 1080i60 */ { CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '3') }, /* MPEG2 HDV 1080i50 */ + { CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '4') }, /* MPEG2 HDV 720p24 */ { CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '5') }, /* MPEG2 HDV 720p25 */ { CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '6') }, /* MPEG2 HDV 1080p24 */ { CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '7') }, /* MPEG2 HDV 1080p25 */ From b5696ff2b872b3556a71fe3591c245b4caff08b5 Mon Sep 17 00:00:00 2001 From: Christophe GISQUET Date: Tue, 21 Feb 2012 22:36:15 +0100 Subject: [PATCH 04/19] prores: use natural integer type for the codebook index The operations that use it require it to be promoted to a larger (natural) type and thus perform sign extension on it. While an optimal compiler may account for this, gcc 4.6 (for x86 Windows) fails. Using the natural integer type provides a 2% speedup for Win64 and 1% for Win32. Signed-off-by: Diego Biurrun --- libavcodec/proresdec.c | 2 +- libavcodec/proresenc.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/proresdec.c b/libavcodec/proresdec.c index 207fd9742e..8ca5f3d632 100644 --- a/libavcodec/proresdec.c +++ b/libavcodec/proresdec.c @@ -289,7 +289,7 @@ static int decode_picture_header(ProresContext *ctx, const uint8_t *buf, /** * Read an unsigned rice/exp golomb codeword. */ -static inline int decode_vlc_codeword(GetBitContext *gb, uint8_t codebook) +static inline int decode_vlc_codeword(GetBitContext *gb, unsigned codebook) { unsigned int rice_order, exp_order, switch_bits; unsigned int buf, code; diff --git a/libavcodec/proresenc.c b/libavcodec/proresenc.c index 7e3e066875..aa96b35e75 100644 --- a/libavcodec/proresenc.c +++ b/libavcodec/proresenc.c @@ -229,7 +229,7 @@ static void get_slice_data(ProresContext *ctx, const uint16_t *src, /** * Write an unsigned rice/exp golomb codeword. */ -static inline void encode_vlc_codeword(PutBitContext *pb, uint8_t codebook, int val) +static inline void encode_vlc_codeword(PutBitContext *pb, unsigned codebook, int val) { unsigned int rice_order, exp_order, switch_bits, switch_val; int exponent; @@ -393,7 +393,7 @@ static int encode_slice(AVCodecContext *avctx, const AVFrame *pic, return total_size; } -static inline int estimate_vlc(uint8_t codebook, int val) +static inline int estimate_vlc(unsigned codebook, int val) { unsigned int rice_order, exp_order, switch_bits, switch_val; int exponent; From 383a3b64cb617f77df0d1f13e431c455ebcecafb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Tue, 21 Feb 2012 12:03:56 +0200 Subject: [PATCH 05/19] movdec: Restart parsing root-level atoms at the right spot MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If parsing moov+mdat in a non-seekable file, we currently abort parsing directly after parsing the header of the mdat atom. If we want to continue parsing later (if looking to parse later fragments), we need to skip past the content of the mdat atom, otherwise we end up parsing the content of the mdat atom as root level atoms. Signed-off-by: Martin Storsjö --- libavformat/isom.h | 1 + libavformat/mov.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/libavformat/isom.h b/libavformat/isom.h index 32c4b3fd1d..214af589a5 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -143,6 +143,7 @@ typedef struct MOVContext { unsigned trex_count; int itunes_metadata; ///< metadata are itunes style int chapter_track; + int64_t next_root_atom; ///< offset of the next root atom } MOVContext; int ff_mp4_read_descr_len(AVIOContext *pb); diff --git a/libavformat/mov.c b/libavformat/mov.c index 2242ba7636..a2b2da0a22 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -350,8 +350,11 @@ static int mov_read_default(MOVContext *c, AVIOContext *pb, MOVAtom atom) if (err < 0) return err; if (c->found_moov && c->found_mdat && - (!pb->seekable || start_pos + a.size == avio_size(pb))) + (!pb->seekable || start_pos + a.size == avio_size(pb))) { + if (!pb->seekable) + c->next_root_atom = start_pos + a.size; return 0; + } left = a.size - avio_tell(pb) + start_pos; if (left > 0) /* skip garbage at atom end */ avio_skip(pb, left); @@ -2667,8 +2670,11 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt) sample = mov_find_next_sample(s, &st); if (!sample) { mov->found_mdat = 0; - if (s->pb->seekable|| - mov_read_default(mov, s->pb, (MOVAtom){ AV_RL32("root"), INT64_MAX }) < 0 || + if (!mov->next_root_atom) + return AVERROR_EOF; + avio_seek(s->pb, mov->next_root_atom, SEEK_SET); + mov->next_root_atom = 0; + if (mov_read_default(mov, s->pb, (MOVAtom){ AV_RL32("root"), INT64_MAX }) < 0 || s->pb->eof_reached) return AVERROR_EOF; av_dlog(s, "read fragments, offset 0x%"PRIx64"\n", avio_tell(s->pb)); From aa96d433e24cde44bf8009c809c6f41308ff8fd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Tue, 21 Feb 2012 12:16:18 +0200 Subject: [PATCH 06/19] movdec: Don't parse all fragments if ignidx is set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In nonseekable files, we already stop parsing the toplevel atoms after finding moov and one mdat. In large seekable files (or files that are seekable, but slowly, e.g. http), reading all the fragments at the start can take a considerable amount of time. This allows opting out from this behaviour. Signed-off-by: Martin Storsjö --- libavformat/mov.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index a2b2da0a22..c2f13b6316 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -350,8 +350,9 @@ static int mov_read_default(MOVContext *c, AVIOContext *pb, MOVAtom atom) if (err < 0) return err; if (c->found_moov && c->found_mdat && - (!pb->seekable || start_pos + a.size == avio_size(pb))) { - if (!pb->seekable) + ((!pb->seekable || c->fc->flags & AVFMT_FLAG_IGNIDX) || + start_pos + a.size == avio_size(pb))) { + if (!pb->seekable || c->fc->flags & AVFMT_FLAG_IGNIDX) c->next_root_atom = start_pos + a.size; return 0; } From 0a7ce3caa8a08d38f35b0e1aae8528a99781cb9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Wed, 22 Feb 2012 11:00:35 +0200 Subject: [PATCH 07/19] flvdec: Fix indentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also split a long line. Signed-off-by: Martin Storsjö --- libavformat/flvdec.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c index 1e1c29b391..70a7d20b13 100644 --- a/libavformat/flvdec.c +++ b/libavformat/flvdec.c @@ -204,8 +204,9 @@ static int parse_keyframes_index(AVFormatContext *s, AVIOContext *ioc, AVStream } if (!ret && timeslen == fileposlen) - for (i = 0; i < fileposlen; i++) - av_add_index_entry(vstream, filepositions[i], times[i]*1000, 0, 0, AVINDEX_KEYFRAME); + for (i = 0; i < fileposlen; i++) + av_add_index_entry(vstream, filepositions[i], times[i]*1000, + 0, 0, AVINDEX_KEYFRAME); else av_log(s, AV_LOG_WARNING, "Invalid keyframes object, skipping.\n"); From b70f04c2612f2685295b09ed7371fe694d52287e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Wed, 22 Feb 2012 11:26:42 +0200 Subject: [PATCH 08/19] flvdec: Ignore the index if the ignidx flag is set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavformat/flvdec.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c index 70a7d20b13..01c67b48a5 100644 --- a/libavformat/flvdec.c +++ b/libavformat/flvdec.c @@ -157,6 +157,9 @@ static int parse_keyframes_index(AVFormatContext *s, AVIOContext *ioc, AVStream return 0; } + if (s->flags & AVFMT_FLAG_IGNIDX) + return 0; + while (avio_tell(ioc) < max_pos - 2 && amf_get_string(ioc, str_val, sizeof(str_val)) > 0) { int64_t* current_array; From 0c7b8b758aa3038451bba5ce8f0d3ef1fad8649f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Thu, 2 Feb 2012 12:50:26 +0200 Subject: [PATCH 09/19] movenc: Buffer the mdat for the initial moov fragment, too MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows writing QuickTime-compatible fragmented mp4 (with a non-empty moov atom) to a non-seekable output. This buffers the mdat for the initial fragment just as it does for all normal fragments, too. Previously, the resulting atom structure was mdat,moov, moof,mdat ..., while it now is moov,mdat, moof,mdat. Signed-off-by: Martin Storsjö --- libavformat/movenc.c | 74 ++++++++++++++++++++++++++++++-------------- libavformat/movenc.h | 1 + 2 files changed, 51 insertions(+), 24 deletions(-) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 30c3061d74..d50a0e045e 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -96,9 +96,9 @@ static int mov_write_stco_tag(AVIOContext *pb, MOVTrack *track) avio_wb32(pb, track->entry); /* entry count */ for (i=0; ientry; i++) { if(mode64 == 1) - avio_wb64(pb, track->cluster[i].pos); + avio_wb64(pb, track->cluster[i].pos + track->data_offset); else - avio_wb32(pb, track->cluster[i].pos); + avio_wb32(pb, track->cluster[i].pos + track->data_offset); } return update_size(pb, pos); } @@ -2681,6 +2681,10 @@ static int mov_flush_fragment(AVFormatContext *s) if (!(mov->flags & FF_MOV_FLAG_EMPTY_MOOV) && mov->fragments == 0) { int64_t pos = avio_tell(s->pb); + int ret; + AVIOContext *moov_buf; + uint8_t *buf; + int buf_size; for (i = 0; i < mov->nb_streams; i++) if (!mov->tracks[i].entry) @@ -2688,10 +2692,24 @@ static int mov_flush_fragment(AVFormatContext *s) /* Don't write the initial moov unless all tracks have data */ if (i < mov->nb_streams) return 0; - avio_seek(s->pb, mov->mdat_pos, SEEK_SET); - avio_wb32(s->pb, mov->mdat_size + 8); - avio_seek(s->pb, pos, SEEK_SET); + + if ((ret = avio_open_dyn_buf(&moov_buf)) < 0) + return ret; + mov_write_moov_tag(moov_buf, mov, s); + buf_size = avio_close_dyn_buf(moov_buf, &buf); + av_free(buf); + for (i = 0; i < mov->nb_streams; i++) + mov->tracks[i].data_offset = pos + buf_size + 8; + mov_write_moov_tag(s->pb, mov, s); + + buf_size = avio_close_dyn_buf(mov->mdat_buf, &buf); + mov->mdat_buf = NULL; + avio_wb32(s->pb, buf_size + 8); + ffio_wfourcc(s->pb, "mdat"); + avio_write(s->pb, buf, buf_size); + av_free(buf); + mov->fragments++; mov->mdat_size = 0; for (i = 0; i < mov->nb_streams; i++) { @@ -2804,13 +2822,21 @@ static int mov_write_packet_internal(AVFormatContext *s, AVPacket *pkt) mov_flush_fragment(s); } - if (mov->flags & FF_MOV_FLAG_FRAGMENT && mov->fragments > 0) { - if (!trk->mdat_buf) { - int ret; - if ((ret = avio_open_dyn_buf(&trk->mdat_buf)) < 0) - return ret; + if (mov->flags & FF_MOV_FLAG_FRAGMENT) { + int ret; + if (mov->fragments > 0) { + if (!trk->mdat_buf) { + if ((ret = avio_open_dyn_buf(&trk->mdat_buf)) < 0) + return ret; + } + pb = trk->mdat_buf; + } else { + if (!mov->mdat_buf) { + if ((ret = avio_open_dyn_buf(&mov->mdat_buf)) < 0) + return ret; + } + pb = mov->mdat_buf; } - pb = trk->mdat_buf; } if (enc->codec_id == CODEC_ID_AMR_NB) { @@ -2972,11 +2998,18 @@ static int mov_write_header(AVFormatContext *s) AVDictionaryEntry *t; int i, hint_track = 0; - /* Non-seekable output is ok if EMPTY_MOOV is set, or if using the ismv - * format (which sets EMPTY_MOOV later in this function). If ism_lookahead + /* Set the FRAGMENT flag if any of the fragmentation methods are + * enabled. */ + if (mov->max_fragment_duration || mov->max_fragment_size || + mov->flags & (FF_MOV_FLAG_EMPTY_MOOV | + FF_MOV_FLAG_FRAG_KEYFRAME | + FF_MOV_FLAG_FRAG_CUSTOM)) + mov->flags |= FF_MOV_FLAG_FRAGMENT; + + /* Non-seekable output is ok if using fragmentation. If ism_lookahead * is enabled, we don't support non-seekable output at all. */ if (!s->pb->seekable && - ((!(mov->flags & FF_MOV_FLAG_EMPTY_MOOV) && + ((!(mov->flags & FF_MOV_FLAG_FRAGMENT) && !(s->oformat && !strcmp(s->oformat->name, "ismv"))) || mov->ism_lookahead)) { av_log(s, AV_LOG_ERROR, "muxer does not support non seekable output\n"); @@ -3116,18 +3149,11 @@ static int mov_write_header(AVFormatContext *s) FF_MOV_FLAG_FRAG_CUSTOM)) && !mov->max_fragment_duration && !mov->max_fragment_size) mov->max_fragment_duration = 5000000; - mov->flags |= FF_MOV_FLAG_EMPTY_MOOV | FF_MOV_FLAG_SEPARATE_MOOF; + mov->flags |= FF_MOV_FLAG_EMPTY_MOOV | FF_MOV_FLAG_SEPARATE_MOOF | + FF_MOV_FLAG_FRAGMENT; } - /* Set the FRAGMENT flag if any of the fragmentation methods are - * enabled. */ - if (mov->max_fragment_duration || mov->max_fragment_size || - mov->flags & (FF_MOV_FLAG_EMPTY_MOOV | - FF_MOV_FLAG_FRAG_KEYFRAME | - FF_MOV_FLAG_FRAG_CUSTOM)) - mov->flags |= FF_MOV_FLAG_FRAGMENT; - - if (!(mov->flags & FF_MOV_FLAG_EMPTY_MOOV)) + if (!(mov->flags & FF_MOV_FLAG_FRAGMENT)) mov_write_mdat_tag(pb, mov); if (t = av_dict_get(s->metadata, "creation_time", NULL, 0)) diff --git a/libavformat/movenc.h b/libavformat/movenc.h index b77fc80b2f..350dbe04f2 100644 --- a/libavformat/movenc.h +++ b/libavformat/movenc.h @@ -151,6 +151,7 @@ typedef struct MOVMuxContext { int max_fragment_duration; int max_fragment_size; int ism_lookahead; + AVIOContext *mdat_buf; } MOVMuxContext; #define FF_MOV_FLAG_RTP_HINT 1 From 147715ca10c1ea0b7a020933311d6a2615d684c9 Mon Sep 17 00:00:00 2001 From: Tim Walker Date: Wed, 22 Feb 2012 15:43:22 +0100 Subject: [PATCH 10/19] Add channel names to channel_names[] array for channels added in b2890f5 Signed-off-by: Justin Ruggles --- libavutil/audioconvert.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libavutil/audioconvert.c b/libavutil/audioconvert.c index 83f2d7c762..0a83b05ad9 100644 --- a/libavutil/audioconvert.c +++ b/libavutil/audioconvert.c @@ -48,6 +48,10 @@ static const char * const channel_names[] = { [17] = "TBR", /* top back right */ [29] = "DL", /* downmix left */ [30] = "DR", /* downmix right */ + [31] = "WL", /* wide left */ + [32] = "WR", /* wide right */ + [33] = "SDL", /* surround direct left */ + [34] = "SDR", /* surround direct right */ }; static const char *get_channel_name(int channel_id) From 6bbaf6e0dd09430b7f8ba7f114eebc24925e1bce Mon Sep 17 00:00:00 2001 From: Tim Walker Date: Wed, 22 Feb 2012 16:09:42 +0100 Subject: [PATCH 11/19] mlpdec_parser: fix a few channel layouts. Signed-off-by: Justin Ruggles --- libavcodec/mlp_parser.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libavcodec/mlp_parser.c b/libavcodec/mlp_parser.c index be71867c2d..3bf38c7f35 100644 --- a/libavcodec/mlp_parser.c +++ b/libavcodec/mlp_parser.c @@ -79,13 +79,13 @@ static const uint64_t thd_layout[13] = { AV_CH_LOW_FREQUENCY, // LFE AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT, // LRs AV_CH_TOP_FRONT_LEFT|AV_CH_TOP_FRONT_RIGHT, // LRvh - AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT, // LRc + AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER, // LRc AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT, // LRrs AV_CH_BACK_CENTER, // Cs AV_CH_TOP_BACK_CENTER, // Ts AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT, // LRsd - AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER, // LRw - AV_CH_TOP_BACK_CENTER, // Cvh + AV_CH_WIDE_LEFT|AV_CH_WIDE_RIGHT, // LRw + AV_CH_TOP_FRONT_CENTER, // Cvh AV_CH_LOW_FREQUENCY // LFE2 }; @@ -109,7 +109,8 @@ static int truehd_channels(int chanmap) static uint64_t truehd_layout(int chanmap) { - int layout = 0, i; + int i; + uint64_t layout = 0; for (i = 0; i < 13; i++) layout |= thd_layout[i] * ((chanmap >> i) & 1); From 58700edb94a3ddd7267fd7430d19b4a7e2a6b82b Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Tue, 21 Feb 2012 18:15:51 +0000 Subject: [PATCH 12/19] cdxl: correctly synchronize video timestamps to audio Signed-off-by: Paul B Mahol Signed-off-by: Justin Ruggles --- libavformat/cdxl.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/libavformat/cdxl.c b/libavformat/cdxl.c index 49077b4a36..b056d691c9 100644 --- a/libavformat/cdxl.c +++ b/libavformat/cdxl.c @@ -43,7 +43,7 @@ static int cdxl_read_header(AVFormatContext *s) CDXLDemuxContext *cdxl = s->priv_data; int ret; - if ((ret = av_parse_video_rate(&cdxl->fps, cdxl->framerate)) < 0) { + if (cdxl->framerate && (ret = av_parse_video_rate(&cdxl->fps, cdxl->framerate)) < 0) { av_log(s, AV_LOG_ERROR, "Could not parse framerate: %s.\n", cdxl->framerate); return ret; @@ -103,8 +103,9 @@ static int cdxl_read_packet(AVFormatContext *s, AVPacket *pkt) st->codec->codec_id = CODEC_ID_PCM_S8; st->codec->channels = cdxl->header[1] & 0x10 ? 2 : 1; st->codec->sample_rate = cdxl->sample_rate; + st->start_time = 0; cdxl->audio_stream_index = st->index; - avpriv_set_pts_info(st, 32, 1, cdxl->sample_rate); + avpriv_set_pts_info(st, 64, 1, cdxl->sample_rate); } ret = av_get_packet(pb, pkt, audio_size); @@ -125,8 +126,12 @@ static int cdxl_read_packet(AVFormatContext *s, AVPacket *pkt) st->codec->codec_id = CODEC_ID_CDXL; st->codec->width = width; st->codec->height = height; + st->start_time = 0; cdxl->video_stream_index = st->index; - avpriv_set_pts_info(st, 63, cdxl->fps.den, cdxl->fps.num); + if (cdxl->framerate) + avpriv_set_pts_info(st, 64, cdxl->fps.den, cdxl->fps.num); + else + avpriv_set_pts_info(st, 64, 1, cdxl->sample_rate); } if (av_new_packet(pkt, video_size + CDXL_HEADER_SIZE) < 0) @@ -140,6 +145,7 @@ static int cdxl_read_packet(AVFormatContext *s, AVPacket *pkt) pkt->stream_index = cdxl->video_stream_index; pkt->flags |= AV_PKT_FLAG_KEY; pkt->pos = pos; + pkt->duration = cdxl->framerate ? 1 : audio_size ? audio_size : 220; cdxl->read_chunk = audio_size; } @@ -151,7 +157,7 @@ static int cdxl_read_packet(AVFormatContext *s, AVPacket *pkt) #define OFFSET(x) offsetof(CDXLDemuxContext, x) static const AVOption cdxl_options[] = { { "sample_rate", "", OFFSET(sample_rate), AV_OPT_TYPE_INT, { .dbl = 11025 }, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, - { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, { .str = "10" }, 0, 0, AV_OPT_FLAG_DECODING_PARAM }, + { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, AV_OPT_FLAG_DECODING_PARAM }, { NULL }, }; From e30b3e59a4f3004337cb1623b2aac988ce52b93f Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Tue, 21 Feb 2012 10:36:27 -0800 Subject: [PATCH 13/19] rmdec: when using INT4 deinterleaving, error out if sub_packet_h <= 1. We read sub_packet_h / 2 packets per line of data (during deinterleaving), which equals zero if sub_packet_h <= 1, thus causing us to not read any data, leading to an infinite loop. Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind CC: libav-stable@libav.org --- libavformat/rmdec.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c index ee8abdd800..ed16b0715c 100644 --- a/libavformat/rmdec.c +++ b/libavformat/rmdec.c @@ -265,6 +265,7 @@ static int rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb, switch (ast->deint_id) { case DEINT_ID_INT4: if (ast->coded_framesize > ast->audio_framesize || + sub_packet_h <= 1 || ast->coded_framesize * sub_packet_h > (2 + (sub_packet_h & 1)) * ast->audio_framesize) return AVERROR_INVALIDDATA; break; From 0584e3ca9793b3ad1c6b50eca74c4cfa04244941 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 5 Jan 2012 16:55:33 +0100 Subject: [PATCH 14/19] lavf: don't set AVCodecContext.has_b_frames in compute_pkt_fields(). It is not supposed to be done outside lavc. This is basically a revert of 818062f2f346df30f4ec0c0c1f54e8025cc3a80a. It is unclear what issue this was supposed to fix, if it reappears again it will have to be fixed in a more proper place. The wtv-demux test change is because the sample starts with a B-frame. --- libavformat/utils.c | 4 ---- tests/ref/fate/wtv-demux | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/libavformat/utils.c b/libavformat/utils.c index 24175228ab..d6aab568b8 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -854,10 +854,6 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, if((s->flags & AVFMT_FLAG_IGNDTS) && pkt->pts != AV_NOPTS_VALUE) pkt->dts= AV_NOPTS_VALUE; - if (st->codec->codec_id != CODEC_ID_H264 && pc && pc->pict_type == AV_PICTURE_TYPE_B) - //FIXME Set low_delay = 0 when has_b_frames = 1 - st->codec->has_b_frames = 1; - /* do we have a video B-frame ? */ delay= st->codec->has_b_frames; presentation_delayed = 0; diff --git a/tests/ref/fate/wtv-demux b/tests/ref/fate/wtv-demux index d20d041432..6174604a35 100644 --- a/tests/ref/fate/wtv-demux +++ b/tests/ref/fate/wtv-demux @@ -33,9 +33,9 @@ 1, 7199998, 7199998, 240000, 576, 0xeb4b0d93 1, 7439998, 7439998, 240000, 576, 0xde1322f5 1, 7679998, 7679998, 240000, 576, 0xc3131f35 +0, 7886331, 9486442, 400000, 41980, 0xd4920915 1, 7919998, 7919998, 240000, 576, 0x708f1381 1, 8159998, 8159998, 240000, 576, 0x1f00137e -0, 8286442, 9486442, 400000, 41980, 0xd4920915 1, 8399998, 8399998, 240000, 576, 0x05131eb0 1, 8639998, 8639998, 240000, 576, 0x78151c22 0, 8686442, 8686442, 400000, 7228, 0x1b141fa3 From b142496c5630b9bc88fb9eaccae7f6bd62fb23e7 Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Tue, 21 Feb 2012 15:37:35 -0800 Subject: [PATCH 15/19] mov: Add more HDV and XDCAM FourCCs. Reference: VLC --- libavformat/isom.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libavformat/isom.c b/libavformat/isom.c index d702d9a349..77cfa8ff02 100644 --- a/libavformat/isom.c +++ b/libavformat/isom.c @@ -164,6 +164,8 @@ const AVCodecTag ff_codec_movvideo_tags[] = { { CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '6') }, /* MPEG2 HDV 1080p24 */ { CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '7') }, /* MPEG2 HDV 1080p25 */ { CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '8') }, /* MPEG2 HDV 1080p30 */ + { CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '9') }, /* MPEG2 HDV 720p60 JVC */ + { CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', 'a') }, /* MPEG2 HDV 720p50 */ { CODEC_ID_MPEG2VIDEO, MKTAG('m', 'x', '5', 'n') }, /* MPEG2 IMX NTSC 525/60 50mb/s produced by FCP */ { CODEC_ID_MPEG2VIDEO, MKTAG('m', 'x', '5', 'p') }, /* MPEG2 IMX PAL 625/50 50mb/s produced by FCP */ { CODEC_ID_MPEG2VIDEO, MKTAG('m', 'x', '4', 'n') }, /* MPEG2 IMX NTSC 525/60 40mb/s produced by FCP */ @@ -194,6 +196,8 @@ const AVCodecTag ff_codec_movvideo_tags[] = { { CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', 'v', 'd') }, /* XDCAM EX 1080p24 VBR */ { CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', 'v', 'e') }, /* XDCAM EX 1080p25 VBR */ { CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', 'v', 'f') }, /* XDCAM EX 1080p30 VBR */ + { CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', 'h', 'd') }, /* XDCAM HD 540p */ + { CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', 'h', '2') }, /* XDCAM HD422 540p */ { CODEC_ID_MPEG2VIDEO, MKTAG('A', 'V', 'm', 'p') }, /* AVID IMX PAL */ { CODEC_ID_JPEG2000, MKTAG('m', 'j', 'p', '2') }, /* JPEG 2000 produced by FCP */ From 1cd9a6154bc1ac1193c703cea980ed21c3e53792 Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Wed, 22 Feb 2012 11:05:42 -0800 Subject: [PATCH 16/19] aac: fix infinite loop on end-of-frame with sequence of 1-bits. Based-on-work-by: Ronald S. Bultje Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind CC: libav-stable@libav.org --- libavcodec/aacdec.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c index dd9eefca07..f491a098c3 100644 --- a/libavcodec/aacdec.c +++ b/libavcodec/aacdec.c @@ -973,19 +973,20 @@ static int decode_band_types(AACContext *ac, enum BandType band_type[120], av_log(ac->avctx, AV_LOG_ERROR, "invalid band type\n"); return -1; } - while ((sect_len_incr = get_bits(gb, bits)) == (1 << bits) - 1) + do { + sect_len_incr = get_bits(gb, bits); sect_end += sect_len_incr; - sect_end += sect_len_incr; - if (get_bits_left(gb) < 0) { - av_log(ac->avctx, AV_LOG_ERROR, overread_err); - return -1; - } - if (sect_end > ics->max_sfb) { - av_log(ac->avctx, AV_LOG_ERROR, - "Number of bands (%d) exceeds limit (%d).\n", - sect_end, ics->max_sfb); - return -1; - } + if (get_bits_left(gb) < 0) { + av_log(ac->avctx, AV_LOG_ERROR, overread_err); + return -1; + } + if (sect_end > ics->max_sfb) { + av_log(ac->avctx, AV_LOG_ERROR, + "Number of bands (%d) exceeds limit (%d).\n", + sect_end, ics->max_sfb); + return -1; + } + } while (sect_len_incr == (1 << bits) - 1); for (; k < sect_end; k++) { band_type [idx] = sect_band_type; band_type_run_end[idx++] = sect_end; From aac07a7a4c2c7a4a29cf6dbc88c1b9fdd191b99d Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Wed, 22 Feb 2012 11:33:24 -0800 Subject: [PATCH 17/19] rm: prevent infinite loops for index parsing. Specifically, prevent jumping back in the file for the next index, since this can lead to infinite loops where we jump between indexes referring to each other, and don't read indexes that don't fit in the file. Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind CC: libav-stable@libav.org --- libavformat/rmdec.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c index ed16b0715c..6775294d06 100644 --- a/libavformat/rmdec.c +++ b/libavformat/rmdec.c @@ -370,8 +370,19 @@ static int rm_read_index(AVFormatContext *s) st = s->streams[n]; break; } - if (n == s->nb_streams) + if (n == s->nb_streams) { + av_log(s, AV_LOG_ERROR, + "Invalid stream index %d for index at pos %"PRId64"\n", + str_id, avio_tell(pb)); goto skip; + } else if ((avio_size(pb) - avio_tell(pb)) / 14 < n_pkts) { + av_log(s, AV_LOG_ERROR, + "Nr. of packets in packet index for stream index %d " + "exceeds filesize (%"PRId64" at %"PRId64" = %d)\n", + str_id, avio_size(pb), avio_tell(pb), + (avio_size(pb) - avio_tell(pb)) / 14); + goto skip; + } for (n = 0; n < n_pkts; n++) { avio_skip(pb, 2); @@ -383,9 +394,12 @@ static int rm_read_index(AVFormatContext *s) } skip: - if (next_off && avio_tell(pb) != next_off && - avio_seek(pb, next_off, SEEK_SET) < 0) + if (next_off && avio_tell(pb) < next_off && + avio_seek(pb, next_off, SEEK_SET) < 0) { + av_log(s, AV_LOG_ERROR, + "Non-linear index detected, not supported\n"); return -1; + } } while (next_off); return 0; From 15b4b505c2700ea1ba88cedccc183b854c546e02 Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Tue, 21 Feb 2012 21:07:56 +0000 Subject: [PATCH 18/19] img2: split muxer and demuxer into separate files Signed-off-by: Paul B Mahol Signed-off-by: Diego Biurrun --- libavformat/Makefile | 8 +- libavformat/img2.c | 424 ------------------------------------------ libavformat/img2dec.c | 322 ++++++++++++++++++++++++++++++++ libavformat/img2enc.c | 151 +++++++++++++++ 4 files changed, 477 insertions(+), 428 deletions(-) create mode 100644 libavformat/img2dec.c create mode 100644 libavformat/img2enc.c diff --git a/libavformat/Makefile b/libavformat/Makefile index aa3cf7c1d8..5c0e34242e 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -106,10 +106,10 @@ OBJS-$(CONFIG_H264_MUXER) += rawenc.o OBJS-$(CONFIG_HLS_DEMUXER) += hls.o OBJS-$(CONFIG_IDCIN_DEMUXER) += idcin.o OBJS-$(CONFIG_IFF_DEMUXER) += iff.o -OBJS-$(CONFIG_IMAGE2_DEMUXER) += img2.o -OBJS-$(CONFIG_IMAGE2_MUXER) += img2.o -OBJS-$(CONFIG_IMAGE2PIPE_DEMUXER) += img2.o -OBJS-$(CONFIG_IMAGE2PIPE_MUXER) += img2.o +OBJS-$(CONFIG_IMAGE2_DEMUXER) += img2dec.o img2.o +OBJS-$(CONFIG_IMAGE2_MUXER) += img2enc.o img2.o +OBJS-$(CONFIG_IMAGE2PIPE_DEMUXER) += img2dec.o img2.o +OBJS-$(CONFIG_IMAGE2PIPE_MUXER) += img2enc.o img2.o OBJS-$(CONFIG_INGENIENT_DEMUXER) += ingenientdec.o rawdec.o OBJS-$(CONFIG_IPMOVIE_DEMUXER) += ipmovie.o OBJS-$(CONFIG_ISS_DEMUXER) += iss.o diff --git a/libavformat/img2.c b/libavformat/img2.c index 4c43e4406e..6915e433f6 100644 --- a/libavformat/img2.c +++ b/libavformat/img2.c @@ -20,30 +20,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libavutil/intreadwrite.h" #include "libavutil/avstring.h" -#include "libavutil/log.h" -#include "libavutil/opt.h" -#include "libavutil/pixdesc.h" -#include "libavutil/parseutils.h" -#include "avformat.h" -#include "avio_internal.h" #include "internal.h" -typedef struct { - const AVClass *class; /**< Class for private options. */ - int img_first; - int img_last; - int img_number; - int img_count; - int is_pipe; - char path[1024]; - char *pixel_format; /**< Set by a private option. */ - char *video_size; /**< Set by a private option. */ - char *framerate; /**< Set by a private option. */ - int loop; -} VideoData; - typedef struct { enum CodecID id; const char *str; @@ -89,31 +68,6 @@ static const IdStrMap img_tags[] = { { CODEC_ID_NONE , NULL} }; -static const int sizes[][2] = { - { 640, 480 }, - { 720, 480 }, - { 720, 576 }, - { 352, 288 }, - { 352, 240 }, - { 160, 128 }, - { 512, 384 }, - { 640, 352 }, - { 640, 240 }, -}; - -static int infer_size(int *width_ptr, int *height_ptr, int size) -{ - int i; - - for(i=0;i 0) - return 0; - return -1; - } - if (avio_check(buf, AVIO_FLAG_READ) > 0) - break; - } - if (first_index == 5) - goto fail; - - /* find the last image */ - last_index = first_index; - for(;;) { - range = 0; - for(;;) { - if (!range) - range1 = 1; - else - range1 = 2 * range; - if (av_get_frame_filename(buf, sizeof(buf), path, - last_index + range1) < 0) - goto fail; - if (avio_check(buf, AVIO_FLAG_READ) <= 0) - break; - range = range1; - /* just in case... */ - if (range >= (1 << 30)) - goto fail; - } - /* we are sure than image last_index + range exists */ - if (!range) - break; - last_index += range; - } - *pfirst_index = first_index; - *plast_index = last_index; - return 0; - fail: - return -1; -} - - -static int read_probe(AVProbeData *p) -{ - if (p->filename && ff_guess_image2_codec(p->filename)) { - if (av_filename_number_test(p->filename)) - return AVPROBE_SCORE_MAX; - else - return AVPROBE_SCORE_MAX/2; - } - return 0; -} - -static int read_header(AVFormatContext *s1) -{ - VideoData *s = s1->priv_data; - int first_index, last_index, ret = 0; - int width = 0, height = 0; - AVStream *st; - enum PixelFormat pix_fmt = PIX_FMT_NONE; - AVRational framerate; - - s1->ctx_flags |= AVFMTCTX_NOHEADER; - - st = avformat_new_stream(s1, NULL); - if (!st) { - return AVERROR(ENOMEM); - } - - if (s->pixel_format && (pix_fmt = av_get_pix_fmt(s->pixel_format)) == PIX_FMT_NONE) { - av_log(s1, AV_LOG_ERROR, "No such pixel format: %s.\n", s->pixel_format); - return AVERROR(EINVAL); - } - if (s->video_size && (ret = av_parse_video_size(&width, &height, s->video_size)) < 0) { - av_log(s, AV_LOG_ERROR, "Could not parse video size: %s.\n", s->video_size); - return ret; - } - if ((ret = av_parse_video_rate(&framerate, s->framerate)) < 0) { - av_log(s, AV_LOG_ERROR, "Could not parse framerate: %s.\n", s->framerate); - return ret; - } - - av_strlcpy(s->path, s1->filename, sizeof(s->path)); - s->img_number = 0; - s->img_count = 0; - - /* find format */ - if (s1->iformat->flags & AVFMT_NOFILE) - s->is_pipe = 0; - else{ - s->is_pipe = 1; - st->need_parsing = AVSTREAM_PARSE_FULL; - } - - avpriv_set_pts_info(st, 60, framerate.den, framerate.num); - - if (width && height) { - st->codec->width = width; - st->codec->height = height; - } - - if (!s->is_pipe) { - if (find_image_range(&first_index, &last_index, s->path) < 0) - return AVERROR(ENOENT); - s->img_first = first_index; - s->img_last = last_index; - s->img_number = first_index; - /* compute duration */ - st->start_time = 0; - st->duration = last_index - first_index + 1; - } - - if(s1->video_codec_id){ - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = s1->video_codec_id; - }else if(s1->audio_codec_id){ - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = s1->audio_codec_id; - }else{ - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = ff_guess_image2_codec(s->path); - } - if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO && pix_fmt != PIX_FMT_NONE) - st->codec->pix_fmt = pix_fmt; - - return 0; -} - -static int read_packet(AVFormatContext *s1, AVPacket *pkt) -{ - VideoData *s = s1->priv_data; - char filename[1024]; - int i; - int size[3]={0}, ret[3]={0}; - AVIOContext *f[3]; - AVCodecContext *codec= s1->streams[0]->codec; - - if (!s->is_pipe) { - /* loop over input */ - if (s->loop && s->img_number > s->img_last) { - s->img_number = s->img_first; - } - if (s->img_number > s->img_last) - return AVERROR_EOF; - if (av_get_frame_filename(filename, sizeof(filename), - s->path, s->img_number)<0 && s->img_number > 1) - return AVERROR(EIO); - for(i=0; i<3; i++){ - if (avio_open2(&f[i], filename, AVIO_FLAG_READ, - &s1->interrupt_callback, NULL) < 0) { - if(i==1) - break; - av_log(s1, AV_LOG_ERROR, "Could not open file : %s\n",filename); - return AVERROR(EIO); - } - size[i]= avio_size(f[i]); - - if(codec->codec_id != CODEC_ID_RAWVIDEO) - break; - filename[ strlen(filename) - 1 ]= 'U' + i; - } - - if(codec->codec_id == CODEC_ID_RAWVIDEO && !codec->width) - infer_size(&codec->width, &codec->height, size[0]); - } else { - f[0] = s1->pb; - if (f[0]->eof_reached) - return AVERROR(EIO); - size[0]= 4096; - } - - av_new_packet(pkt, size[0] + size[1] + size[2]); - pkt->stream_index = 0; - pkt->flags |= AV_PKT_FLAG_KEY; - - pkt->size= 0; - for(i=0; i<3; i++){ - if(size[i]){ - ret[i]= avio_read(f[i], pkt->data + pkt->size, size[i]); - if (!s->is_pipe) - avio_close(f[i]); - if(ret[i]>0) - pkt->size += ret[i]; - } - } - - if (ret[0] <= 0 || ret[1]<0 || ret[2]<0) { - av_free_packet(pkt); - return AVERROR(EIO); /* signal EOF */ - } else { - s->img_count++; - s->img_number++; - return 0; - } -} - -#if CONFIG_IMAGE2_MUXER || CONFIG_IMAGE2PIPE_MUXER -/******************************************************/ -/* image output */ - -static int write_header(AVFormatContext *s) -{ - VideoData *img = s->priv_data; - - img->img_number = 1; - av_strlcpy(img->path, s->filename, sizeof(img->path)); - - /* find format */ - if (s->oformat->flags & AVFMT_NOFILE) - img->is_pipe = 0; - else - img->is_pipe = 1; - - return 0; -} - -static int write_packet(AVFormatContext *s, AVPacket *pkt) -{ - VideoData *img = s->priv_data; - AVIOContext *pb[3]; - char filename[1024]; - AVCodecContext *codec= s->streams[ pkt->stream_index ]->codec; - int i; - - if (!img->is_pipe) { - if (av_get_frame_filename(filename, sizeof(filename), - img->path, img->img_number) < 0 && img->img_number>1) { - av_log(s, AV_LOG_ERROR, - "Could not get frame filename number %d from pattern '%s'\n", - img->img_number, img->path); - return AVERROR(EIO); - } - for(i=0; i<3; i++){ - if (avio_open2(&pb[i], filename, AVIO_FLAG_WRITE, - &s->interrupt_callback, NULL) < 0) { - av_log(s, AV_LOG_ERROR, "Could not open file : %s\n",filename); - return AVERROR(EIO); - } - - if(codec->codec_id != CODEC_ID_RAWVIDEO) - break; - filename[ strlen(filename) - 1 ]= 'U' + i; - } - } else { - pb[0] = s->pb; - } - - if(codec->codec_id == CODEC_ID_RAWVIDEO){ - int ysize = codec->width * codec->height; - avio_write(pb[0], pkt->data , ysize); - avio_write(pb[1], pkt->data + ysize, (pkt->size - ysize)/2); - avio_write(pb[2], pkt->data + ysize +(pkt->size - ysize)/2, (pkt->size - ysize)/2); - avio_flush(pb[1]); - avio_flush(pb[2]); - avio_close(pb[1]); - avio_close(pb[2]); - }else{ - if (ff_guess_image2_codec(s->filename) == CODEC_ID_JPEG2000) { - AVStream *st = s->streams[0]; - if(st->codec->extradata_size > 8 && - AV_RL32(st->codec->extradata+4) == MKTAG('j','p','2','h')){ - if(pkt->size < 8 || AV_RL32(pkt->data+4) != MKTAG('j','p','2','c')) - goto error; - avio_wb32(pb[0], 12); - ffio_wfourcc(pb[0], "jP "); - avio_wb32(pb[0], 0x0D0A870A); // signature - avio_wb32(pb[0], 20); - ffio_wfourcc(pb[0], "ftyp"); - ffio_wfourcc(pb[0], "jp2 "); - avio_wb32(pb[0], 0); - ffio_wfourcc(pb[0], "jp2 "); - avio_write(pb[0], st->codec->extradata, st->codec->extradata_size); - }else if(pkt->size < 8 || - (!st->codec->extradata_size && - AV_RL32(pkt->data+4) != MKTAG('j','P',' ',' '))){ // signature - error: - av_log(s, AV_LOG_ERROR, "malformed JPEG 2000 codestream\n"); - return -1; - } - } - avio_write(pb[0], pkt->data, pkt->size); - } - avio_flush(pb[0]); - if (!img->is_pipe) { - avio_close(pb[0]); - } - - img->img_number++; - return 0; -} - -#endif /* CONFIG_IMAGE2_MUXER || CONFIG_IMAGE2PIPE_MUXER */ - -#define OFFSET(x) offsetof(VideoData, x) -#define DEC AV_OPT_FLAG_DECODING_PARAM -static const AVOption options[] = { - { "pixel_format", "", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, - { "video_size", "", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, - { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, DEC }, - { "loop", "", OFFSET(loop), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 1, DEC }, - { NULL }, -}; - -/* input */ -#if CONFIG_IMAGE2_DEMUXER -static const AVClass img2_class = { - .class_name = "image2 demuxer", - .item_name = av_default_item_name, - .option = options, - .version = LIBAVUTIL_VERSION_INT, -}; -AVInputFormat ff_image2_demuxer = { - .name = "image2", - .long_name = NULL_IF_CONFIG_SMALL("image2 sequence"), - .priv_data_size = sizeof(VideoData), - .read_probe = read_probe, - .read_header = read_header, - .read_packet = read_packet, - .flags = AVFMT_NOFILE, - .priv_class = &img2_class, -}; -#endif -#if CONFIG_IMAGE2PIPE_DEMUXER -static const AVClass img2pipe_class = { - .class_name = "image2pipe demuxer", - .item_name = av_default_item_name, - .option = options, - .version = LIBAVUTIL_VERSION_INT, -}; -AVInputFormat ff_image2pipe_demuxer = { - .name = "image2pipe", - .long_name = NULL_IF_CONFIG_SMALL("piped image2 sequence"), - .priv_data_size = sizeof(VideoData), - .read_header = read_header, - .read_packet = read_packet, - .priv_class = &img2pipe_class, -}; -#endif - -/* output */ -#if CONFIG_IMAGE2_MUXER -AVOutputFormat ff_image2_muxer = { - .name = "image2", - .long_name = NULL_IF_CONFIG_SMALL("image2 sequence"), - .extensions = "bmp,dpx,jpeg,jpg,ljpg,pam,pbm,pcx,pgm,pgmyuv,png," - "ppm,sgi,tga,tif,tiff,jp2,xwd,sun,ras,rs,im1,im8,im24," - "sunras", - .priv_data_size = sizeof(VideoData), - .video_codec = CODEC_ID_MJPEG, - .write_header = write_header, - .write_packet = write_packet, - .flags = AVFMT_NOTIMESTAMPS | AVFMT_NODIMENSIONS | AVFMT_NOFILE -}; -#endif -#if CONFIG_IMAGE2PIPE_MUXER -AVOutputFormat ff_image2pipe_muxer = { - .name = "image2pipe", - .long_name = NULL_IF_CONFIG_SMALL("piped image2 sequence"), - .priv_data_size = sizeof(VideoData), - .video_codec = CODEC_ID_MJPEG, - .write_header = write_header, - .write_packet = write_packet, - .flags = AVFMT_NOTIMESTAMPS | AVFMT_NODIMENSIONS -}; -#endif diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c new file mode 100644 index 0000000000..b4b9723bcd --- /dev/null +++ b/libavformat/img2dec.c @@ -0,0 +1,322 @@ +/* + * Image format + * Copyright (c) 2000, 2001, 2002 Fabrice Bellard + * Copyright (c) 2004 Michael Niedermayer + * + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/avstring.h" +#include "libavutil/log.h" +#include "libavutil/opt.h" +#include "libavutil/pixdesc.h" +#include "libavutil/parseutils.h" +#include "avformat.h" +#include "internal.h" + +typedef struct { + const AVClass *class; /**< Class for private options. */ + int img_first; + int img_last; + int img_number; + int img_count; + int is_pipe; + char path[1024]; + char *pixel_format; /**< Set by a private option. */ + char *video_size; /**< Set by a private option. */ + char *framerate; /**< Set by a private option. */ + int loop; +} VideoDemuxData; + +static const int sizes[][2] = { + { 640, 480 }, + { 720, 480 }, + { 720, 576 }, + { 352, 288 }, + { 352, 240 }, + { 160, 128 }, + { 512, 384 }, + { 640, 352 }, + { 640, 240 }, +}; + +static int infer_size(int *width_ptr, int *height_ptr, int size) +{ + int i; + + for(i=0;i 0) + return 0; + return -1; + } + if (avio_check(buf, AVIO_FLAG_READ) > 0) + break; + } + if (first_index == 5) + goto fail; + + /* find the last image */ + last_index = first_index; + for(;;) { + range = 0; + for(;;) { + if (!range) + range1 = 1; + else + range1 = 2 * range; + if (av_get_frame_filename(buf, sizeof(buf), path, + last_index + range1) < 0) + goto fail; + if (avio_check(buf, AVIO_FLAG_READ) <= 0) + break; + range = range1; + /* just in case... */ + if (range >= (1 << 30)) + goto fail; + } + /* we are sure than image last_index + range exists */ + if (!range) + break; + last_index += range; + } + *pfirst_index = first_index; + *plast_index = last_index; + return 0; + fail: + return -1; +} + + +static int read_probe(AVProbeData *p) +{ + if (p->filename && ff_guess_image2_codec(p->filename)) { + if (av_filename_number_test(p->filename)) + return AVPROBE_SCORE_MAX; + else + return AVPROBE_SCORE_MAX/2; + } + return 0; +} + +static int read_header(AVFormatContext *s1) +{ + VideoDemuxData *s = s1->priv_data; + int first_index, last_index, ret = 0; + int width = 0, height = 0; + AVStream *st; + enum PixelFormat pix_fmt = PIX_FMT_NONE; + AVRational framerate; + + s1->ctx_flags |= AVFMTCTX_NOHEADER; + + st = avformat_new_stream(s1, NULL); + if (!st) { + return AVERROR(ENOMEM); + } + + if (s->pixel_format && (pix_fmt = av_get_pix_fmt(s->pixel_format)) == PIX_FMT_NONE) { + av_log(s1, AV_LOG_ERROR, "No such pixel format: %s.\n", s->pixel_format); + return AVERROR(EINVAL); + } + if (s->video_size && (ret = av_parse_video_size(&width, &height, s->video_size)) < 0) { + av_log(s, AV_LOG_ERROR, "Could not parse video size: %s.\n", s->video_size); + return ret; + } + if ((ret = av_parse_video_rate(&framerate, s->framerate)) < 0) { + av_log(s, AV_LOG_ERROR, "Could not parse framerate: %s.\n", s->framerate); + return ret; + } + + av_strlcpy(s->path, s1->filename, sizeof(s->path)); + s->img_number = 0; + s->img_count = 0; + + /* find format */ + if (s1->iformat->flags & AVFMT_NOFILE) + s->is_pipe = 0; + else{ + s->is_pipe = 1; + st->need_parsing = AVSTREAM_PARSE_FULL; + } + + avpriv_set_pts_info(st, 60, framerate.den, framerate.num); + + if (width && height) { + st->codec->width = width; + st->codec->height = height; + } + + if (!s->is_pipe) { + if (find_image_range(&first_index, &last_index, s->path) < 0) + return AVERROR(ENOENT); + s->img_first = first_index; + s->img_last = last_index; + s->img_number = first_index; + /* compute duration */ + st->start_time = 0; + st->duration = last_index - first_index + 1; + } + + if(s1->video_codec_id){ + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codec->codec_id = s1->video_codec_id; + }else if(s1->audio_codec_id){ + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codec->codec_id = s1->audio_codec_id; + }else{ + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codec->codec_id = ff_guess_image2_codec(s->path); + } + if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO && pix_fmt != PIX_FMT_NONE) + st->codec->pix_fmt = pix_fmt; + + return 0; +} + +static int read_packet(AVFormatContext *s1, AVPacket *pkt) +{ + VideoDemuxData *s = s1->priv_data; + char filename[1024]; + int i; + int size[3]={0}, ret[3]={0}; + AVIOContext *f[3]; + AVCodecContext *codec= s1->streams[0]->codec; + + if (!s->is_pipe) { + /* loop over input */ + if (s->loop && s->img_number > s->img_last) { + s->img_number = s->img_first; + } + if (s->img_number > s->img_last) + return AVERROR_EOF; + if (av_get_frame_filename(filename, sizeof(filename), + s->path, s->img_number)<0 && s->img_number > 1) + return AVERROR(EIO); + for(i=0; i<3; i++){ + if (avio_open2(&f[i], filename, AVIO_FLAG_READ, + &s1->interrupt_callback, NULL) < 0) { + if(i==1) + break; + av_log(s1, AV_LOG_ERROR, "Could not open file : %s\n",filename); + return AVERROR(EIO); + } + size[i]= avio_size(f[i]); + + if(codec->codec_id != CODEC_ID_RAWVIDEO) + break; + filename[ strlen(filename) - 1 ]= 'U' + i; + } + + if(codec->codec_id == CODEC_ID_RAWVIDEO && !codec->width) + infer_size(&codec->width, &codec->height, size[0]); + } else { + f[0] = s1->pb; + if (f[0]->eof_reached) + return AVERROR(EIO); + size[0]= 4096; + } + + av_new_packet(pkt, size[0] + size[1] + size[2]); + pkt->stream_index = 0; + pkt->flags |= AV_PKT_FLAG_KEY; + + pkt->size= 0; + for(i=0; i<3; i++){ + if(size[i]){ + ret[i]= avio_read(f[i], pkt->data + pkt->size, size[i]); + if (!s->is_pipe) + avio_close(f[i]); + if(ret[i]>0) + pkt->size += ret[i]; + } + } + + if (ret[0] <= 0 || ret[1]<0 || ret[2]<0) { + av_free_packet(pkt); + return AVERROR(EIO); /* signal EOF */ + } else { + s->img_count++; + s->img_number++; + return 0; + } +} + +#define OFFSET(x) offsetof(VideoDemuxData, x) +#define DEC AV_OPT_FLAG_DECODING_PARAM +static const AVOption options[] = { + { "pixel_format", "", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, + { "video_size", "", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, + { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, DEC }, + { "loop", "", OFFSET(loop), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 1, DEC }, + { NULL }, +}; + +#if CONFIG_IMAGE2_DEMUXER +static const AVClass img2_class = { + .class_name = "image2 demuxer", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; +AVInputFormat ff_image2_demuxer = { + .name = "image2", + .long_name = NULL_IF_CONFIG_SMALL("image2 sequence"), + .priv_data_size = sizeof(VideoDemuxData), + .read_probe = read_probe, + .read_header = read_header, + .read_packet = read_packet, + .flags = AVFMT_NOFILE, + .priv_class = &img2_class, +}; +#endif +#if CONFIG_IMAGE2PIPE_DEMUXER +static const AVClass img2pipe_class = { + .class_name = "image2pipe demuxer", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; +AVInputFormat ff_image2pipe_demuxer = { + .name = "image2pipe", + .long_name = NULL_IF_CONFIG_SMALL("piped image2 sequence"), + .priv_data_size = sizeof(VideoDemuxData), + .read_header = read_header, + .read_packet = read_packet, + .priv_class = &img2pipe_class, +}; +#endif diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c new file mode 100644 index 0000000000..8fbe37e33e --- /dev/null +++ b/libavformat/img2enc.c @@ -0,0 +1,151 @@ +/* + * Image format + * Copyright (c) 2000, 2001, 2002 Fabrice Bellard + * Copyright (c) 2004 Michael Niedermayer + * + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/intreadwrite.h" +#include "libavutil/avstring.h" +#include "libavutil/log.h" +#include "avformat.h" +#include "avio_internal.h" +#include "internal.h" + +typedef struct { + int img_number; + int is_pipe; + char path[1024]; +} VideoMuxData; + +static int write_header(AVFormatContext *s) +{ + VideoMuxData *img = s->priv_data; + + img->img_number = 1; + av_strlcpy(img->path, s->filename, sizeof(img->path)); + + /* find format */ + if (s->oformat->flags & AVFMT_NOFILE) + img->is_pipe = 0; + else + img->is_pipe = 1; + + return 0; +} + +static int write_packet(AVFormatContext *s, AVPacket *pkt) +{ + VideoMuxData *img = s->priv_data; + AVIOContext *pb[3]; + char filename[1024]; + AVCodecContext *codec= s->streams[ pkt->stream_index ]->codec; + int i; + + if (!img->is_pipe) { + if (av_get_frame_filename(filename, sizeof(filename), + img->path, img->img_number) < 0 && img->img_number>1) { + av_log(s, AV_LOG_ERROR, + "Could not get frame filename number %d from pattern '%s'\n", + img->img_number, img->path); + return AVERROR(EIO); + } + for(i=0; i<3; i++){ + if (avio_open2(&pb[i], filename, AVIO_FLAG_WRITE, + &s->interrupt_callback, NULL) < 0) { + av_log(s, AV_LOG_ERROR, "Could not open file : %s\n",filename); + return AVERROR(EIO); + } + + if(codec->codec_id != CODEC_ID_RAWVIDEO) + break; + filename[ strlen(filename) - 1 ]= 'U' + i; + } + } else { + pb[0] = s->pb; + } + + if(codec->codec_id == CODEC_ID_RAWVIDEO){ + int ysize = codec->width * codec->height; + avio_write(pb[0], pkt->data , ysize); + avio_write(pb[1], pkt->data + ysize, (pkt->size - ysize)/2); + avio_write(pb[2], pkt->data + ysize +(pkt->size - ysize)/2, (pkt->size - ysize)/2); + avio_flush(pb[1]); + avio_flush(pb[2]); + avio_close(pb[1]); + avio_close(pb[2]); + }else{ + if(ff_guess_image2_codec(s->filename) == CODEC_ID_JPEG2000){ + AVStream *st = s->streams[0]; + if(st->codec->extradata_size > 8 && + AV_RL32(st->codec->extradata+4) == MKTAG('j','p','2','h')){ + if(pkt->size < 8 || AV_RL32(pkt->data+4) != MKTAG('j','p','2','c')) + goto error; + avio_wb32(pb[0], 12); + ffio_wfourcc(pb[0], "jP "); + avio_wb32(pb[0], 0x0D0A870A); // signature + avio_wb32(pb[0], 20); + ffio_wfourcc(pb[0], "ftyp"); + ffio_wfourcc(pb[0], "jp2 "); + avio_wb32(pb[0], 0); + ffio_wfourcc(pb[0], "jp2 "); + avio_write(pb[0], st->codec->extradata, st->codec->extradata_size); + }else if(pkt->size < 8 || + (!st->codec->extradata_size && + AV_RL32(pkt->data+4) != MKTAG('j','P',' ',' '))){ // signature + error: + av_log(s, AV_LOG_ERROR, "malformed JPEG 2000 codestream\n"); + return -1; + } + } + avio_write(pb[0], pkt->data, pkt->size); + } + avio_flush(pb[0]); + if (!img->is_pipe) { + avio_close(pb[0]); + } + + img->img_number++; + return 0; +} + +#if CONFIG_IMAGE2_MUXER +AVOutputFormat ff_image2_muxer = { + .name = "image2", + .long_name = NULL_IF_CONFIG_SMALL("image2 sequence"), + .extensions = "bmp,dpx,jpeg,jpg,ljpg,pam,pbm,pcx,pgm,pgmyuv,png," + "ppm,sgi,tga,tif,tiff,jp2,xwd,sun,ras,rs,im1,im8,im24," + "sunras", + .priv_data_size = sizeof(VideoMuxData), + .video_codec = CODEC_ID_MJPEG, + .write_header = write_header, + .write_packet = write_packet, + .flags = AVFMT_NOTIMESTAMPS | AVFMT_NODIMENSIONS | AVFMT_NOFILE +}; +#endif +#if CONFIG_IMAGE2PIPE_MUXER +AVOutputFormat ff_image2pipe_muxer = { + .name = "image2pipe", + .long_name = NULL_IF_CONFIG_SMALL("piped image2 sequence"), + .priv_data_size = sizeof(VideoMuxData), + .video_codec = CODEC_ID_MJPEG, + .write_header = write_header, + .write_packet = write_packet, + .flags = AVFMT_NOTIMESTAMPS | AVFMT_NODIMENSIONS +}; +#endif From 562ebc30775db243941db3c96396e7bf8a0e0a44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C3=ABl=20Carr=C3=A9?= Date: Mon, 6 Feb 2012 16:08:08 -0500 Subject: [PATCH 19/19] dxva2: don't check for DXVA_PictureParameters->wDecodedPictureIndex This structure is well defined by Microsoft at: http://msdn.microsoft.com/en-us/library/windows/hardware/ff564012(v=vs.85).aspx Thus, the wDecodedPictureIndex member is guaranteed to exist. Also, both the MPEG-2 and VC-1 hwaccel decoders depend on this struct member, but only the VC-1 decoder was disabled if the check failed. Signed-off-by: Diego Biurrun --- configure | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/configure b/configure index 5c0e56c4c0..5e62e22f36 100755 --- a/configure +++ b/configure @@ -1378,7 +1378,7 @@ truehd_decoder_select="mlp_decoder" tscc_decoder_select="zlib" twinvq_decoder_select="mdct lsp sinewin" vc1_decoder_select="h263_decoder h264chroma" -vc1_dxva2_hwaccel_deps="dxva2api_h DXVA_PictureParameters_wDecodedPictureIndex" +vc1_dxva2_hwaccel_deps="dxva2api_h" vc1_dxva2_hwaccel_select="dxva2 vc1_decoder" vc1_vaapi_hwaccel_select="vaapi vc1_decoder" vc1_vdpau_decoder_select="vdpau vc1_decoder" @@ -2885,8 +2885,6 @@ check_header vdpau/vdpau.h check_header vdpau/vdpau_x11.h check_header X11/extensions/XvMClib.h -check_struct dxva2api.h DXVA_PictureParameters wDecodedPictureIndex - disabled zlib || check_lib zlib.h zlibVersion -lz || disable zlib disabled bzlib || check_lib2 bzlib.h BZ2_bzlibVersion -lbz2 || disable bzlib