Browse code

swscale: K&R formatting cosmetics (part I)

Diego Biurrun authored on 2012/02/22 04:09:31
Showing 4 changed files
... ...
@@ -19,12 +19,12 @@
19 19
  */
20 20
 
21 21
 #include "libavutil/avutil.h"
22
-#include "libavutil/pixfmt.h"
23 22
 #include "libavutil/opt.h"
23
+#include "libavutil/pixfmt.h"
24 24
 #include "swscale.h"
25 25
 #include "swscale_internal.h"
26 26
 
27
-static const char * sws_context_to_name(void * ptr)
27
+static const char *sws_context_to_name(void *ptr)
28 28
 {
29 29
     return "swscaler";
30 30
 }
... ...
@@ -34,34 +34,34 @@ static const char * sws_context_to_name(void * ptr)
34 34
 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
35 35
 
36 36
 static const AVOption options[] = {
37
-    { "sws_flags", "scaler/cpu flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.dbl = DEFAULT }, 0, UINT_MAX, VE, "sws_flags" },
38
-    { "fast_bilinear", "fast bilinear", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_FAST_BILINEAR }, INT_MIN, INT_MAX, VE, "sws_flags" },
39
-    { "bilinear", "bilinear", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_BILINEAR }, INT_MIN, INT_MAX, VE, "sws_flags" },
40
-    { "bicubic", "bicubic", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_BICUBIC }, INT_MIN, INT_MAX, VE, "sws_flags" },
41
-    { "experimental", "experimental", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_X }, INT_MIN, INT_MAX, VE, "sws_flags" },
42
-    { "neighbor", "nearest neighbor", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_POINT }, INT_MIN, INT_MAX, VE, "sws_flags" },
43
-    { "area", "averaging area", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_AREA }, INT_MIN, INT_MAX, VE, "sws_flags" },
44
-    { "bicublin", "luma bicubic, chroma bilinear", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_BICUBLIN }, INT_MIN, INT_MAX, VE, "sws_flags" },
45
-    { "gauss", "gaussian", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_GAUSS }, INT_MIN, INT_MAX, VE, "sws_flags" },
46
-    { "sinc", "sinc", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_SINC }, INT_MIN, INT_MAX, VE, "sws_flags" },
47
-    { "lanczos", "lanczos", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_LANCZOS }, INT_MIN, INT_MAX, VE, "sws_flags" },
48
-    { "spline", "natural bicubic spline", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_SPLINE }, INT_MIN, INT_MAX, VE, "sws_flags" },
49
-    { "print_info", "print info", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_PRINT_INFO }, INT_MIN, INT_MAX, VE, "sws_flags" },
50
-    { "accurate_rnd", "accurate rounding", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_ACCURATE_RND }, INT_MIN, INT_MAX, VE, "sws_flags" },
51
-    { "full_chroma_int", "full chroma interpolation", 0 , AV_OPT_TYPE_CONST, {.dbl = SWS_FULL_CHR_H_INT }, INT_MIN, INT_MAX, VE, "sws_flags" },
52
-    { "full_chroma_inp", "full chroma input", 0 , AV_OPT_TYPE_CONST, {.dbl = SWS_FULL_CHR_H_INP }, INT_MIN, INT_MAX, VE, "sws_flags" },
53
-    { "bitexact", "", 0 , AV_OPT_TYPE_CONST, {.dbl = SWS_BITEXACT }, INT_MIN, INT_MAX, VE, "sws_flags" },
37
+    { "sws_flags",       "scaler/cpu flags",              OFFSET(flags),     AV_OPT_TYPE_FLAGS,  { .dbl = DEFAULT            }, 0,       UINT_MAX,       VE, "sws_flags" },
38
+    { "fast_bilinear",   "fast bilinear",                 0,                 AV_OPT_TYPE_CONST,  { .dbl = SWS_FAST_BILINEAR  }, INT_MIN, INT_MAX,        VE, "sws_flags" },
39
+    { "bilinear",        "bilinear",                      0,                 AV_OPT_TYPE_CONST,  { .dbl = SWS_BILINEAR       }, INT_MIN, INT_MAX,        VE, "sws_flags" },
40
+    { "bicubic",         "bicubic",                       0,                 AV_OPT_TYPE_CONST,  { .dbl = SWS_BICUBIC        }, INT_MIN, INT_MAX,        VE, "sws_flags" },
41
+    { "experimental",    "experimental",                  0,                 AV_OPT_TYPE_CONST,  { .dbl = SWS_X              }, INT_MIN, INT_MAX,        VE, "sws_flags" },
42
+    { "neighbor",        "nearest neighbor",              0,                 AV_OPT_TYPE_CONST,  { .dbl = SWS_POINT          }, INT_MIN, INT_MAX,        VE, "sws_flags" },
43
+    { "area",            "averaging area",                0,                 AV_OPT_TYPE_CONST,  { .dbl = SWS_AREA           }, INT_MIN, INT_MAX,        VE, "sws_flags" },
44
+    { "bicublin",        "luma bicubic, chroma bilinear", 0,                 AV_OPT_TYPE_CONST,  { .dbl = SWS_BICUBLIN       }, INT_MIN, INT_MAX,        VE, "sws_flags" },
45
+    { "gauss",           "gaussian",                      0,                 AV_OPT_TYPE_CONST,  { .dbl = SWS_GAUSS          }, INT_MIN, INT_MAX,        VE, "sws_flags" },
46
+    { "sinc",            "sinc",                          0,                 AV_OPT_TYPE_CONST,  { .dbl = SWS_SINC           }, INT_MIN, INT_MAX,        VE, "sws_flags" },
47
+    { "lanczos",         "lanczos",                       0,                 AV_OPT_TYPE_CONST,  { .dbl = SWS_LANCZOS        }, INT_MIN, INT_MAX,        VE, "sws_flags" },
48
+    { "spline",          "natural bicubic spline",        0,                 AV_OPT_TYPE_CONST,  { .dbl = SWS_SPLINE         }, INT_MIN, INT_MAX,        VE, "sws_flags" },
49
+    { "print_info",      "print info",                    0,                 AV_OPT_TYPE_CONST,  { .dbl = SWS_PRINT_INFO     }, INT_MIN, INT_MAX,        VE, "sws_flags" },
50
+    { "accurate_rnd",    "accurate rounding",             0,                 AV_OPT_TYPE_CONST,  { .dbl = SWS_ACCURATE_RND   }, INT_MIN, INT_MAX,        VE, "sws_flags" },
51
+    { "full_chroma_int", "full chroma interpolation",     0,                 AV_OPT_TYPE_CONST,  { .dbl = SWS_FULL_CHR_H_INT }, INT_MIN, INT_MAX,        VE, "sws_flags" },
52
+    { "full_chroma_inp", "full chroma input",             0,                 AV_OPT_TYPE_CONST,  { .dbl = SWS_FULL_CHR_H_INP }, INT_MIN, INT_MAX,        VE, "sws_flags" },
53
+    { "bitexact",        "",                              0,                 AV_OPT_TYPE_CONST,  { .dbl = SWS_BITEXACT       }, INT_MIN, INT_MAX,        VE, "sws_flags" },
54 54
 
55
-    { "srcw", "source width"      , OFFSET(srcW), AV_OPT_TYPE_INT, {.dbl = 16 }, 1, INT_MAX, VE },
56
-    { "srch", "source height"     , OFFSET(srcH), AV_OPT_TYPE_INT, {.dbl = 16 }, 1, INT_MAX, VE },
57
-    { "dstw", "destination width" , OFFSET(dstW), AV_OPT_TYPE_INT, {.dbl = 16 }, 1, INT_MAX, VE },
58
-    { "dsth", "destination height", OFFSET(dstH), AV_OPT_TYPE_INT, {.dbl = 16 }, 1, INT_MAX, VE },
59
-    { "src_format", "source format"     , OFFSET(srcFormat), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, PIX_FMT_NB-1, VE },
60
-    { "dst_format", "destination format", OFFSET(dstFormat), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, PIX_FMT_NB-1, VE },
61
-    { "src_range" , "source range"      , OFFSET(srcRange) , AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, 1, VE },
62
-    { "dst_range" , "destination range" , OFFSET(dstRange) , AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, 1, VE },
63
-    { "param0" , "scaler param 0" , OFFSET(param[0]) , AV_OPT_TYPE_DOUBLE, {.dbl = SWS_PARAM_DEFAULT}, INT_MIN, INT_MAX, VE },
64
-    { "param1" , "scaler param 1" , OFFSET(param[1]) , AV_OPT_TYPE_DOUBLE, {.dbl = SWS_PARAM_DEFAULT}, INT_MIN, INT_MAX, VE },
55
+    { "srcw",            "source width",                  OFFSET(srcW),      AV_OPT_TYPE_INT,    { .dbl = 16                 }, 1,       INT_MAX,        VE },
56
+    { "srch",            "source height",                 OFFSET(srcH),      AV_OPT_TYPE_INT,    { .dbl = 16                 }, 1,       INT_MAX,        VE },
57
+    { "dstw",            "destination width",             OFFSET(dstW),      AV_OPT_TYPE_INT,    { .dbl = 16                 }, 1,       INT_MAX,        VE },
58
+    { "dsth",            "destination height",            OFFSET(dstH),      AV_OPT_TYPE_INT,    { .dbl = 16                 }, 1,       INT_MAX,        VE },
59
+    { "src_format",      "source format",                 OFFSET(srcFormat), AV_OPT_TYPE_INT,    { .dbl = DEFAULT            }, 0,       PIX_FMT_NB - 1, VE },
60
+    { "dst_format",      "destination format",            OFFSET(dstFormat), AV_OPT_TYPE_INT,    { .dbl = DEFAULT            }, 0,       PIX_FMT_NB - 1, VE },
61
+    { "src_range",       "source range",                  OFFSET(srcRange),  AV_OPT_TYPE_INT,    { .dbl = DEFAULT            }, 0,       1,              VE },
62
+    { "dst_range",       "destination range",             OFFSET(dstRange),  AV_OPT_TYPE_INT,    { .dbl = DEFAULT            }, 0,       1,              VE },
63
+    { "param0",          "scaler param 0",                OFFSET(param[0]),  AV_OPT_TYPE_DOUBLE, { .dbl = SWS_PARAM_DEFAULT  }, INT_MIN, INT_MAX,        VE },
64
+    { "param1",          "scaler param 1",                OFFSET(param[1]),  AV_OPT_TYPE_DOUBLE, { .dbl = SWS_PARAM_DEFAULT  }, INT_MIN, INT_MAX,        VE },
65 65
 
66 66
     { NULL }
67 67
 };
... ...
@@ -22,48 +22,58 @@
22 22
  * License along with Libav; if not, write to the Free Software
23 23
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 24
  */
25
+
25 26
 #include <inttypes.h>
26
-#include "config.h"
27
+
27 28
 #include "libavutil/bswap.h"
29
+#include "config.h"
28 30
 #include "rgb2rgb.h"
29 31
 #include "swscale.h"
30 32
 #include "swscale_internal.h"
31 33
 
34
+void (*rgb32tobgr24)(const uint8_t *src, uint8_t *dst, int src_size);
35
+void (*rgb32tobgr16)(const uint8_t *src, uint8_t *dst, int src_size);
36
+void (*rgb32tobgr15)(const uint8_t *src, uint8_t *dst, int src_size);
32 37
 void (*rgb24tobgr32)(const uint8_t *src, uint8_t *dst, int src_size);
38
+void (*rgb24tobgr24)(const uint8_t *src, uint8_t *dst, int src_size);
33 39
 void (*rgb24tobgr16)(const uint8_t *src, uint8_t *dst, int src_size);
34 40
 void (*rgb24tobgr15)(const uint8_t *src, uint8_t *dst, int src_size);
35
-void (*rgb32tobgr24)(const uint8_t *src, uint8_t *dst, int src_size);
41
+void (*rgb16tobgr24)(const uint8_t *src, uint8_t *dst, int src_size);
42
+void (*rgb15tobgr24)(const uint8_t *src, uint8_t *dst, int src_size);
43
+
36 44
 void (*rgb32to16)(const uint8_t *src, uint8_t *dst, int src_size);
37 45
 void (*rgb32to15)(const uint8_t *src, uint8_t *dst, int src_size);
38
-void (*rgb15to16)(const uint8_t *src, uint8_t *dst, int src_size);
39
-void (*rgb15tobgr24)(const uint8_t *src, uint8_t *dst, int src_size);
40
-void (*rgb15to32)(const uint8_t *src, uint8_t *dst, int src_size);
41
-void (*rgb16to15)(const uint8_t *src, uint8_t *dst, int src_size);
42
-void (*rgb16tobgr24)(const uint8_t *src, uint8_t *dst, int src_size);
43
-void (*rgb16to32)(const uint8_t *src, uint8_t *dst, int src_size);
44
-void (*rgb24tobgr24)(const uint8_t *src, uint8_t *dst, int src_size);
45 46
 void (*rgb24to16)(const uint8_t *src, uint8_t *dst, int src_size);
46 47
 void (*rgb24to15)(const uint8_t *src, uint8_t *dst, int src_size);
48
+void (*rgb16to32)(const uint8_t *src, uint8_t *dst, int src_size);
49
+void (*rgb16to15)(const uint8_t *src, uint8_t *dst, int src_size);
50
+void (*rgb15to16)(const uint8_t *src, uint8_t *dst, int src_size);
51
+void (*rgb15to32)(const uint8_t *src, uint8_t *dst, int src_size);
52
+
47 53
 void (*shuffle_bytes_2103)(const uint8_t *src, uint8_t *dst, int src_size);
48
-void (*rgb32tobgr16)(const uint8_t *src, uint8_t *dst, int src_size);
49
-void (*rgb32tobgr15)(const uint8_t *src, uint8_t *dst, int src_size);
50 54
 
51
-void (*yv12toyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
55
+void (*yv12toyuy2)(const uint8_t *ysrc, const uint8_t *usrc,
56
+                   const uint8_t *vsrc, uint8_t *dst,
52 57
                    int width, int height,
53 58
                    int lumStride, int chromStride, int dstStride);
54
-void (*yv12touyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
59
+void (*yv12touyvy)(const uint8_t *ysrc, const uint8_t *usrc,
60
+                   const uint8_t *vsrc, uint8_t *dst,
55 61
                    int width, int height,
56 62
                    int lumStride, int chromStride, int dstStride);
57
-void (*yuv422ptoyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
63
+void (*yuv422ptoyuy2)(const uint8_t *ysrc, const uint8_t *usrc,
64
+                      const uint8_t *vsrc, uint8_t *dst,
58 65
                       int width, int height,
59 66
                       int lumStride, int chromStride, int dstStride);
60
-void (*yuv422ptouyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
67
+void (*yuv422ptouyvy)(const uint8_t *ysrc, const uint8_t *usrc,
68
+                      const uint8_t *vsrc, uint8_t *dst,
61 69
                       int width, int height,
62 70
                       int lumStride, int chromStride, int dstStride);
63
-void (*yuy2toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
71
+void (*yuy2toyv12)(const uint8_t *src, uint8_t *ydst,
72
+                   uint8_t *udst, uint8_t *vdst,
64 73
                    int width, int height,
65 74
                    int lumStride, int chromStride, int srcStride);
66
-void (*rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
75
+void (*rgb24toyv12)(const uint8_t *src, uint8_t *ydst,
76
+                    uint8_t *udst, uint8_t *vdst,
67 77
                     int width, int height,
68 78
                     int lumStride, int chromStride, int srcStride);
69 79
 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,
76 76
                     int width, int height,
77 77
                     int srcStride1, int srcStride2,
78 78
                     int dstStride1, int dstStride2);
79
-void (*yvu9_to_yuy2)(const uint8_t *src1, const uint8_t *src2, const uint8_t *src3,
80
-                     uint8_t *dst,
79
+void (*yvu9_to_yuy2)(const uint8_t *src1, const uint8_t *src2,
80
+                     const uint8_t *src3, uint8_t *dst,
81 81
                      int width, int height,
82 82
                      int srcStride1, int srcStride2,
83 83
                      int srcStride3, int dstStride);
84
-void (*uyvytoyuv420)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src,
85
-                     int width, int height,
84
+void (*uyvytoyuv420)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
85
+                     const uint8_t *src, int width, int height,
86 86
                      int lumStride, int chromStride, int srcStride);
87
-void (*uyvytoyuv422)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src,
88
-                     int width, int height,
87
+void (*uyvytoyuv422)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
88
+                     const uint8_t *src, int width, int height,
89 89
                      int lumStride, int chromStride, int srcStride);
90
-void (*yuyvtoyuv420)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src,
91
-                     int width, int height,
90
+void (*yuyvtoyuv420)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
91
+                     const uint8_t *src, int width, int height,
92 92
                      int lumStride, int chromStride, int srcStride);
93
-void (*yuyvtoyuv422)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src,
94
-                     int width, int height,
93
+void (*yuyvtoyuv422)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
94
+                     const uint8_t *src, int width, int height,
95 95
                      int lumStride, int chromStride, int srcStride);
96 96
 
97 97
 #define RGB2YUV_SHIFT 8
98
-#define BY ((int)( 0.098*(1<<RGB2YUV_SHIFT)+0.5))
99
-#define BV ((int)(-0.071*(1<<RGB2YUV_SHIFT)+0.5))
100
-#define BU ((int)( 0.439*(1<<RGB2YUV_SHIFT)+0.5))
101
-#define GY ((int)( 0.504*(1<<RGB2YUV_SHIFT)+0.5))
102
-#define GV ((int)(-0.368*(1<<RGB2YUV_SHIFT)+0.5))
103
-#define GU ((int)(-0.291*(1<<RGB2YUV_SHIFT)+0.5))
104
-#define RY ((int)( 0.257*(1<<RGB2YUV_SHIFT)+0.5))
105
-#define RV ((int)( 0.439*(1<<RGB2YUV_SHIFT)+0.5))
106
-#define RU ((int)(-0.148*(1<<RGB2YUV_SHIFT)+0.5))
98
+#define BY ((int)( 0.098 * (1 << RGB2YUV_SHIFT) + 0.5))
99
+#define BV ((int)(-0.071 * (1 << RGB2YUV_SHIFT) + 0.5))
100
+#define BU ((int)( 0.439 * (1 << RGB2YUV_SHIFT) + 0.5))
101
+#define GY ((int)( 0.504 * (1 << RGB2YUV_SHIFT) + 0.5))
102
+#define GV ((int)(-0.368 * (1 << RGB2YUV_SHIFT) + 0.5))
103
+#define GU ((int)(-0.291 * (1 << RGB2YUV_SHIFT) + 0.5))
104
+#define RY ((int)( 0.257 * (1 << RGB2YUV_SHIFT) + 0.5))
105
+#define RV ((int)( 0.439 * (1 << RGB2YUV_SHIFT) + 0.5))
106
+#define RU ((int)(-0.148 * (1 << RGB2YUV_SHIFT) + 0.5))
107 107
 
108 108
 //plain C versions
109 109
 #include "rgb2rgb_template.c"
110 110
 
111
-
112 111
 /*
113
- RGB15->RGB16 original by Strepto/Astral
114
- ported to gcc & bugfixed : A'rpi
115
- MMX2, 3DNOW optimization by Nick Kurshev
116
- 32-bit C version, and and&add trick by Michael Niedermayer
117
-*/
112
+ * RGB15->RGB16 original by Strepto/Astral
113
+ * ported to gcc & bugfixed : A'rpi
114
+ * MMX2, 3DNOW optimization by Nick Kurshev
115
+ * 32-bit C version, and and&add trick by Michael Niedermayer
116
+ */
118 117
 
119 118
 void sws_rgb2rgb_init(void)
120 119
 {
... ...
@@ -127,16 +136,16 @@ void rgb32to24(const uint8_t *src, uint8_t *dst, int src_size)
127 127
 {
128 128
     int i, num_pixels = src_size >> 2;
129 129
 
130
-    for (i=0; i<num_pixels; i++) {
130
+    for (i = 0; i < num_pixels; i++) {
131 131
 #if HAVE_BIGENDIAN
132 132
         /* RGB32 (= A,B,G,R) -> BGR24 (= B,G,R) */
133
-        dst[3*i + 0] = src[4*i + 1];
134
-        dst[3*i + 1] = src[4*i + 2];
135
-        dst[3*i + 2] = src[4*i + 3];
133
+        dst[3 * i + 0] = src[4 * i + 1];
134
+        dst[3 * i + 1] = src[4 * i + 2];
135
+        dst[3 * i + 2] = src[4 * i + 3];
136 136
 #else
137
-        dst[3*i + 0] = src[4*i + 2];
138
-        dst[3*i + 1] = src[4*i + 1];
139
-        dst[3*i + 2] = src[4*i + 0];
137
+        dst[3 * i + 0] = src[4 * i + 2];
138
+        dst[3 * i + 1] = src[4 * i + 1];
139
+        dst[3 * i + 2] = src[4 * i + 0];
140 140
 #endif
141 141
     }
142 142
 }
... ...
@@ -144,39 +153,40 @@ void rgb32to24(const uint8_t *src, uint8_t *dst, int src_size)
144 144
 void rgb24to32(const uint8_t *src, uint8_t *dst, int src_size)
145 145
 {
146 146
     int i;
147
-    for (i=0; 3*i<src_size; i++) {
147
+
148
+    for (i = 0; 3 * i < src_size; i++) {
148 149
 #if HAVE_BIGENDIAN
149
-        /* RGB24 (= R,G,B) -> BGR32 (= A,R,G,B) */
150
-        dst[4*i + 0] = 255;
151
-        dst[4*i + 1] = src[3*i + 0];
152
-        dst[4*i + 2] = src[3*i + 1];
153
-        dst[4*i + 3] = src[3*i + 2];
150
+        /* RGB24 (= R, G, B) -> BGR32 (= A, R, G, B) */
151
+        dst[4 * i + 0] = 255;
152
+        dst[4 * i + 1] = src[3 * i + 0];
153
+        dst[4 * i + 2] = src[3 * i + 1];
154
+        dst[4 * i + 3] = src[3 * i + 2];
154 155
 #else
155
-        dst[4*i + 0] = src[3*i + 2];
156
-        dst[4*i + 1] = src[3*i + 1];
157
-        dst[4*i + 2] = src[3*i + 0];
158
-        dst[4*i + 3] = 255;
156
+        dst[4 * i + 0] = src[3 * i + 2];
157
+        dst[4 * i + 1] = src[3 * i + 1];
158
+        dst[4 * i + 2] = src[3 * i + 0];
159
+        dst[4 * i + 3] = 255;
159 160
 #endif
160 161
     }
161 162
 }
162 163
 
163 164
 void rgb16tobgr32(const uint8_t *src, uint8_t *dst, int src_size)
164 165
 {
165
-    uint8_t *d = dst;
166
-    const uint16_t *s = (const uint16_t *)src;
166
+    uint8_t *d          = dst;
167
+    const uint16_t *s   = (const uint16_t *)src;
167 168
     const uint16_t *end = s + src_size / 2;
168 169
 
169 170
     while (s < end) {
170 171
         register uint16_t bgr = *s++;
171 172
 #if HAVE_BIGENDIAN
172 173
         *d++ = 255;
173
-        *d++ = (bgr&0x1F)<<3;
174
-        *d++ = (bgr&0x7E0)>>3;
175
-        *d++ = (bgr&0xF800)>>8;
174
+        *d++ = (bgr & 0x1F)   << 3;
175
+        *d++ = (bgr & 0x7E0)  >> 3;
176
+        *d++ = (bgr & 0xF800) >> 8;
176 177
 #else
177
-        *d++ = (bgr&0xF800)>>8;
178
-        *d++ = (bgr&0x7E0)>>3;
179
-        *d++ = (bgr&0x1F)<<3;
178
+        *d++ = (bgr & 0xF800) >> 8;
179
+        *d++ = (bgr & 0x7E0)  >> 3;
180
+        *d++ = (bgr & 0x1F)   << 3;
180 181
         *d++ = 255;
181 182
 #endif
182 183
     }
... ...
@@ -184,34 +194,34 @@ void rgb16tobgr32(const uint8_t *src, uint8_t *dst, int src_size)
184 184
 
185 185
 void rgb12to15(const uint8_t *src, uint8_t *dst, int src_size)
186 186
 {
187
-    uint16_t *d = (uint16_t *)dst;
188
-    const uint16_t *s = (const uint16_t *)src;
189 187
     uint16_t rgb, r, g, b;
188
+    uint16_t *d         = (uint16_t *)dst;
189
+    const uint16_t *s   = (const uint16_t *)src;
190 190
     const uint16_t *end = s + src_size / 2;
191 191
 
192 192
     while (s < end) {
193
-        rgb = *s++;
194
-        r = rgb & 0xF00;
195
-        g = rgb & 0x0F0;
196
-        b = rgb & 0x00F;
197
-        r = (r << 3) | ((r & 0x800) >> 1);
198
-        g = (g << 2) | ((g & 0x080) >> 2);
199
-        b = (b << 1) | ( b          >> 3);
193
+        rgb  = *s++;
194
+        r    = rgb & 0xF00;
195
+        g    = rgb & 0x0F0;
196
+        b    = rgb & 0x00F;
197
+        r    = (r << 3) | ((r & 0x800) >> 1);
198
+        g    = (g << 2) | ((g & 0x080) >> 2);
199
+        b    = (b << 1) | ( b          >> 3);
200 200
         *d++ = r | g | b;
201 201
     }
202 202
 }
203 203
 
204 204
 void rgb16to24(const uint8_t *src, uint8_t *dst, int src_size)
205 205
 {
206
-    uint8_t *d = dst;
207
-    const uint16_t *s = (const uint16_t *)src;
206
+    uint8_t *d          = dst;
207
+    const uint16_t *s   = (const uint16_t *)src;
208 208
     const uint16_t *end = s + src_size / 2;
209 209
 
210 210
     while (s < end) {
211 211
         register uint16_t bgr = *s++;
212
-        *d++ = (bgr&0xF800)>>8;
213
-        *d++ = (bgr&0x7E0)>>3;
214
-        *d++ = (bgr&0x1F)<<3;
212
+        *d++ = (bgr & 0xF800) >> 8;
213
+        *d++ = (bgr & 0x7E0)  >> 3;
214
+        *d++ = (bgr & 0x1F)   << 3;
215 215
     }
216 216
 }
217 217
 
... ...
@@ -219,9 +229,9 @@ void rgb16tobgr16(const uint8_t *src, uint8_t *dst, int src_size)
219 219
 {
220 220
     int i, num_pixels = src_size >> 1;
221 221
 
222
-    for (i=0; i<num_pixels; i++) {
223
-        unsigned rgb = ((const uint16_t*)src)[i];
224
-        ((uint16_t*)dst)[i] = (rgb>>11) | (rgb&0x7E0) | (rgb<<11);
222
+    for (i = 0; i < num_pixels; i++) {
223
+        unsigned rgb         = ((const uint16_t *)src)[i];
224
+        ((uint16_t *)dst)[i] = (rgb >> 11) | (rgb & 0x7E0) | (rgb << 11);
225 225
     }
226 226
 }
227 227
 
... ...
@@ -229,29 +239,29 @@ void rgb16tobgr15(const uint8_t *src, uint8_t *dst, int src_size)
229 229
 {
230 230
     int i, num_pixels = src_size >> 1;
231 231
 
232
-    for (i=0; i<num_pixels; i++) {
233
-        unsigned rgb = ((const uint16_t*)src)[i];
234
-        ((uint16_t*)dst)[i] = (rgb>>11) | ((rgb&0x7C0)>>1) | ((rgb&0x1F)<<10);
232
+    for (i = 0; i < num_pixels; i++) {
233
+        unsigned rgb         = ((const uint16_t *)src)[i];
234
+        ((uint16_t *)dst)[i] = (rgb >> 11) | ((rgb & 0x7C0) >> 1) | ((rgb & 0x1F) << 10);
235 235
     }
236 236
 }
237 237
 
238 238
 void rgb15tobgr32(const uint8_t *src, uint8_t *dst, int src_size)
239 239
 {
240
-    uint8_t *d = dst;
241
-    const uint16_t *s = (const uint16_t *)src;
240
+    uint8_t *d          = dst;
241
+    const uint16_t *s   = (const uint16_t *)src;
242 242
     const uint16_t *end = s + src_size / 2;
243 243
 
244 244
     while (s < end) {
245 245
         register uint16_t bgr = *s++;
246 246
 #if HAVE_BIGENDIAN
247 247
         *d++ = 255;
248
-        *d++ = (bgr&0x1F)<<3;
249
-        *d++ = (bgr&0x3E0)>>2;
250
-        *d++ = (bgr&0x7C00)>>7;
248
+        *d++ = (bgr & 0x1F)   << 3;
249
+        *d++ = (bgr & 0x3E0)  >> 2;
250
+        *d++ = (bgr & 0x7C00) >> 7;
251 251
 #else
252
-        *d++ = (bgr&0x7C00)>>7;
253
-        *d++ = (bgr&0x3E0)>>2;
254
-        *d++ = (bgr&0x1F)<<3;
252
+        *d++ = (bgr & 0x7C00) >> 7;
253
+        *d++ = (bgr & 0x3E0)  >> 2;
254
+        *d++ = (bgr & 0x1F)   << 3;
255 255
         *d++ = 255;
256 256
 #endif
257 257
     }
... ...
@@ -259,15 +269,15 @@ void rgb15tobgr32(const uint8_t *src, uint8_t *dst, int src_size)
259 259
 
260 260
 void rgb15to24(const uint8_t *src, uint8_t *dst, int src_size)
261 261
 {
262
-    uint8_t *d = dst;
263
-    const uint16_t *s = (const uint16_t *)src;
262
+    uint8_t *d          = dst;
263
+    const uint16_t *s   = (const uint16_t *)src;
264 264
     const uint16_t *end = s + src_size / 2;
265 265
 
266 266
     while (s < end) {
267 267
         register uint16_t bgr = *s++;
268
-        *d++ = (bgr&0x7C00)>>7;
269
-        *d++ = (bgr&0x3E0)>>2;
270
-        *d++ = (bgr&0x1F)<<3;
268
+        *d++ = (bgr & 0x7C00) >> 7;
269
+        *d++ = (bgr & 0x3E0)  >> 2;
270
+        *d++ = (bgr & 0x1F)   << 3;
271 271
     }
272 272
 }
273 273
 
... ...
@@ -275,9 +285,9 @@ void rgb15tobgr16(const uint8_t *src, uint8_t *dst, int src_size)
275 275
 {
276 276
     int i, num_pixels = src_size >> 1;
277 277
 
278
-    for (i=0; i<num_pixels; i++) {
279
-        unsigned rgb = ((const uint16_t*)src)[i];
280
-        ((uint16_t*)dst)[i] = ((rgb&0x7C00)>>10) | ((rgb&0x3E0)<<1) | (rgb<<11);
278
+    for (i = 0; i < num_pixels; i++) {
279
+        unsigned rgb         = ((const uint16_t *)src)[i];
280
+        ((uint16_t *)dst)[i] = ((rgb & 0x7C00) >> 10) | ((rgb & 0x3E0) << 1) | (rgb << 11);
281 281
     }
282 282
 }
283 283
 
... ...
@@ -285,22 +295,22 @@ void rgb15tobgr15(const uint8_t *src, uint8_t *dst, int src_size)
285 285
 {
286 286
     int i, num_pixels = src_size >> 1;
287 287
 
288
-    for (i=0; i<num_pixels; i++) {
289
-        unsigned rgb = ((const uint16_t*)src)[i];
290
-        unsigned br  = rgb & 0x7C1F;
291
-        ((uint16_t*)dst)[i] = (br>>10) | (rgb&0x3E0) | (br<<10);
288
+    for (i = 0; i < num_pixels; i++) {
289
+        unsigned rgb         = ((const uint16_t *)src)[i];
290
+        unsigned br          = rgb & 0x7C1F;
291
+        ((uint16_t *)dst)[i] = (br >> 10) | (rgb & 0x3E0) | (br << 10);
292 292
     }
293 293
 }
294 294
 
295 295
 void rgb12tobgr12(const uint8_t *src, uint8_t *dst, int src_size)
296 296
 {
297
-    uint16_t *d = (uint16_t*)dst;
298
-    uint16_t *s = (uint16_t*)src;
297
+    uint16_t *d = (uint16_t *)dst;
298
+    uint16_t *s = (uint16_t *)src;
299 299
     int i, num_pixels = src_size >> 1;
300 300
 
301 301
     for (i = 0; i < num_pixels; i++) {
302 302
         unsigned rgb = s[i];
303
-        d[i] = (rgb << 8 | rgb & 0xF0 | rgb >> 8) & 0xFFF;
303
+        d[i]         = (rgb << 8 | rgb & 0xF0 | rgb >> 8) & 0xFFF;
304 304
     }
305 305
 }
306 306
 
... ...
@@ -308,21 +318,22 @@ void bgr8torgb8(const uint8_t *src, uint8_t *dst, int src_size)
308 308
 {
309 309
     int i, num_pixels = src_size;
310 310
 
311
-    for (i=0; i<num_pixels; i++) {
311
+    for (i = 0; i < num_pixels; i++) {
312 312
         register uint8_t rgb = src[i];
313 313
         unsigned r           = (rgb & 0x07);
314 314
         unsigned g           = (rgb & 0x38) >> 3;
315 315
         unsigned b           = (rgb & 0xC0) >> 6;
316
-        dst[i] = ((b<<1)&0x07) | ((g&0x07)<<3) | ((r&0x03)<<6);
316
+        dst[i]               = ((b << 1) & 0x07) | ((g & 0x07) << 3) | ((r & 0x03) << 6);
317 317
     }
318 318
 }
319 319
 
320 320
 #define DEFINE_SHUFFLE_BYTES(a, b, c, d)                                \
321
-void shuffle_bytes_##a##b##c##d(const uint8_t *src, uint8_t *dst, int src_size) \
321
+void shuffle_bytes_ ## a ## b ## c ## d(const uint8_t *src,             \
322
+                                        uint8_t *dst, int src_size)     \
322 323
 {                                                                       \
323
-    int i;                                                             \
324
+    int i;                                                              \
324 325
                                                                         \
325
-    for (i = 0; i < src_size; i+=4) {                                   \
326
+    for (i = 0; i < src_size; i += 4) {                                 \
326 327
         dst[i + 0] = src[i + a];                                        \
327 328
         dst[i + 1] = src[i + b];                                        \
328 329
         dst[i + 2] = src[i + c];                                        \
... ...
@@ -26,266 +26,286 @@
26 26
 
27 27
 #include <stddef.h>
28 28
 
29
-static inline void rgb24tobgr32_c(const uint8_t *src, uint8_t *dst, int src_size)
29
+static inline void rgb24tobgr32_c(const uint8_t *src, uint8_t *dst,
30
+                                  int src_size)
30 31
 {
31
-    uint8_t *dest = dst;
32
-    const uint8_t *s = src;
32
+    uint8_t *dest      = dst;
33
+    const uint8_t *s   = src;
33 34
     const uint8_t *end = s + src_size;
34 35
 
35 36
     while (s < end) {
36 37
 #if HAVE_BIGENDIAN
37
-        /* RGB24 (= R,G,B) -> RGB32 (= A,B,G,R) */
38
-        *dest++ = 255;
39
-        *dest++ = s[2];
40
-        *dest++ = s[1];
41
-        *dest++ = s[0];
42
-        s+=3;
38
+        /* RGB24 (= R, G, B) -> RGB32 (= A, B, G, R) */
39
+        *dest++  = 255;
40
+        *dest++  = s[2];
41
+        *dest++  = s[1];
42
+        *dest++  = s[0];
43
+        s       += 3;
43 44
 #else
44
-        *dest++ = *s++;
45
-        *dest++ = *s++;
46
-        *dest++ = *s++;
47
-        *dest++ = 255;
45
+        *dest++  = *s++;
46
+        *dest++  = *s++;
47
+        *dest++  = *s++;
48
+        *dest++  = 255;
48 49
 #endif
49 50
     }
50 51
 }
51 52
 
52
-static inline void rgb32tobgr24_c(const uint8_t *src, uint8_t *dst, int src_size)
53
+static inline void rgb32tobgr24_c(const uint8_t *src, uint8_t *dst,
54
+                                  int src_size)
53 55
 {
54
-    uint8_t *dest = dst;
55
-    const uint8_t *s = src;
56
+    uint8_t *dest      = dst;
57
+    const uint8_t *s   = src;
56 58
     const uint8_t *end = s + src_size;
57 59
 
58 60
     while (s < end) {
59 61
 #if HAVE_BIGENDIAN
60
-        /* RGB32 (= A,B,G,R) -> RGB24 (= R,G,B) */
62
+        /* RGB32 (= A, B, G, R) -> RGB24 (= R, G, B) */
61 63
         s++;
62
-        dest[2] = *s++;
63
-        dest[1] = *s++;
64
-        dest[0] = *s++;
65
-        dest += 3;
64
+        dest[2]  = *s++;
65
+        dest[1]  = *s++;
66
+        dest[0]  = *s++;
67
+        dest    += 3;
66 68
 #else
67
-        *dest++ = *s++;
68
-        *dest++ = *s++;
69
-        *dest++ = *s++;
69
+        *dest++  = *s++;
70
+        *dest++  = *s++;
71
+        *dest++  = *s++;
70 72
         s++;
71 73
 #endif
72 74
     }
73 75
 }
74 76
 
75 77
 /*
76
- original by Strepto/Astral
77
- ported to gcc & bugfixed: A'rpi
78
- MMX2, 3DNOW optimization by Nick Kurshev
79
- 32-bit C version, and and&add trick by Michael Niedermayer
80
-*/
78
+ * original by Strepto/Astral
79
+ * ported to gcc & bugfixed: A'rpi
80
+ * MMX2, 3DNOW optimization by Nick Kurshev
81
+ * 32-bit C version, and and&add trick by Michael Niedermayer
82
+ */
81 83
 static inline void rgb15to16_c(const uint8_t *src, uint8_t *dst, int src_size)
82 84
 {
83
-    register const uint8_t* s=src;
84
-    register uint8_t* d=dst;
85
+    register uint8_t *d         = dst;
86
+    register const uint8_t *s   = src;
85 87
     register const uint8_t *end = s + src_size;
86 88
     const uint8_t *mm_end       = end - 3;
87 89
 
88 90
     while (s < mm_end) {
89
-        register unsigned x= *((const uint32_t *)s);
90
-        *((uint32_t *)d) = (x&0x7FFF7FFF) + (x&0x7FE07FE0);
91
-        d+=4;
92
-        s+=4;
91
+        register unsigned x = *((const uint32_t *)s);
92
+        *((uint32_t *)d)    = (x & 0x7FFF7FFF) + (x & 0x7FE07FE0);
93
+        d += 4;
94
+        s += 4;
93 95
     }
94 96
     if (s < end) {
95
-        register unsigned short x= *((const uint16_t *)s);
96
-        *((uint16_t *)d) = (x&0x7FFF) + (x&0x7FE0);
97
+        register unsigned short x = *((const uint16_t *)s);
98
+        *((uint16_t *)d)          = (x & 0x7FFF) + (x & 0x7FE0);
97 99
     }
98 100
 }
99 101
 
100 102
 static inline void rgb16to15_c(const uint8_t *src, uint8_t *dst, int src_size)
101 103
 {
102
-    register const uint8_t* s=src;
103
-    register uint8_t* d=dst;
104
+    register uint8_t *d         = dst;
105
+    register const uint8_t *s   = src;
104 106
     register const uint8_t *end = s + src_size;
105 107
     const uint8_t *mm_end       = end - 3;
106 108
 
107 109
     while (s < mm_end) {
108
-        register uint32_t x= *((const uint32_t*)s);
109
-        *((uint32_t *)d) = ((x>>1)&0x7FE07FE0) | (x&0x001F001F);
110
-        s+=4;
111
-        d+=4;
110
+        register uint32_t x  = *((const uint32_t *)s);
111
+        *((uint32_t *)d)     = ((x >> 1) & 0x7FE07FE0) | (x & 0x001F001F);
112
+        s                   += 4;
113
+        d                   += 4;
112 114
     }
113 115
     if (s < end) {
114
-        register uint16_t x= *((const uint16_t*)s);
115
-        *((uint16_t *)d) = ((x>>1)&0x7FE0) | (x&0x001F);
116
+        register uint16_t x = *((const uint16_t *)s);
117
+        *((uint16_t *)d)    = ((x >> 1) & 0x7FE0) | (x & 0x001F);
116 118
     }
117 119
 }
118 120
 
119 121
 static inline void rgb32to16_c(const uint8_t *src, uint8_t *dst, int src_size)
120 122
 {
121
-    const uint8_t *s = src;
122
-    uint16_t *d = (uint16_t *)dst;
123
+    uint16_t *d        = (uint16_t *)dst;
124
+    const uint8_t *s   = src;
123 125
     const uint8_t *end = s + src_size;
124 126
 
125 127
     while (s < end) {
126
-        register int rgb = *(const uint32_t*)s; s += 4;
127
-        *d++ = ((rgb&0xFF)>>3) + ((rgb&0xFC00)>>5) + ((rgb&0xF80000)>>8);
128
+        register int rgb  = *(const uint32_t *)s;
129
+        s                += 4;
130
+        *d++              = ((rgb & 0xFF)     >> 3) +
131
+                            ((rgb & 0xFC00)   >> 5) +
132
+                            ((rgb & 0xF80000) >> 8);
128 133
     }
129 134
 }
130 135
 
131
-static inline void rgb32tobgr16_c(const uint8_t *src, uint8_t *dst, int src_size)
136
+static inline void rgb32tobgr16_c(const uint8_t *src, uint8_t *dst,
137
+                                  int src_size)
132 138
 {
133
-    const uint8_t *s = src;
134
-    uint16_t *d = (uint16_t *)dst;
139
+    uint16_t *d        = (uint16_t *)dst;
140
+    const uint8_t *s   = src;
135 141
     const uint8_t *end = s + src_size;
136 142
 
137 143
     while (s < end) {
138
-        register int rgb = *(const uint32_t*)s; s += 4;
139
-        *d++ = ((rgb&0xF8)<<8) + ((rgb&0xFC00)>>5) + ((rgb&0xF80000)>>19);
144
+        register int rgb  = *(const uint32_t *)s;
145
+        s                += 4;
146
+        *d++              = ((rgb & 0xF8)     << 8) +
147
+                            ((rgb & 0xFC00)   >> 5) +
148
+                            ((rgb & 0xF80000) >> 19);
140 149
     }
141 150
 }
142 151
 
143 152
 static inline void rgb32to15_c(const uint8_t *src, uint8_t *dst, int src_size)
144 153
 {
145
-    const uint8_t *s = src;
146
-    uint16_t *d = (uint16_t *)dst;
154
+    uint16_t *d        = (uint16_t *)dst;
155
+    const uint8_t *s   = src;
147 156
     const uint8_t *end = s + src_size;
148 157
 
149 158
     while (s < end) {
150
-        register int rgb = *(const uint32_t*)s; s += 4;
151
-        *d++ = ((rgb&0xFF)>>3) + ((rgb&0xF800)>>6) + ((rgb&0xF80000)>>9);
159
+        register int rgb  = *(const uint32_t *)s;
160
+        s                += 4;
161
+        *d++              = ((rgb & 0xFF)     >> 3) +
162
+                            ((rgb & 0xF800)   >> 6) +
163
+                            ((rgb & 0xF80000) >> 9);
152 164
     }
153 165
 }
154 166
 
155
-static inline void rgb32tobgr15_c(const uint8_t *src, uint8_t *dst, int src_size)
167
+static inline void rgb32tobgr15_c(const uint8_t *src, uint8_t *dst,
168
+                                  int src_size)
156 169
 {
157
-    const uint8_t *s = src;
158
-    uint16_t *d = (uint16_t *)dst;
170
+    uint16_t *d        = (uint16_t *)dst;
171
+    const uint8_t *s   = src;
159 172
     const uint8_t *end = s + src_size;
160 173
 
161 174
     while (s < end) {
162
-        register int rgb = *(const uint32_t*)s; s += 4;
163
-        *d++ = ((rgb&0xF8)<<7) + ((rgb&0xF800)>>6) + ((rgb&0xF80000)>>19);
175
+        register int rgb  = *(const uint32_t *)s;
176
+        s                += 4;
177
+        *d++              = ((rgb & 0xF8)     <<  7) +
178
+                            ((rgb & 0xF800)   >>  6) +
179
+                            ((rgb & 0xF80000) >> 19);
164 180
     }
165 181
 }
166 182
 
167
-static inline void rgb24tobgr16_c(const uint8_t *src, uint8_t *dst, int src_size)
183
+static inline void rgb24tobgr16_c(const uint8_t *src, uint8_t *dst,
184
+                                  int src_size)
168 185
 {
169
-    const uint8_t *s = src;
170
-    uint16_t *d = (uint16_t *)dst;
186
+    uint16_t *d        = (uint16_t *)dst;
187
+    const uint8_t *s   = src;
171 188
     const uint8_t *end = s + src_size;
172 189
 
173 190
     while (s < end) {
174 191
         const int b = *s++;
175 192
         const int g = *s++;
176 193
         const int r = *s++;
177
-        *d++ = (b>>3) | ((g&0xFC)<<3) | ((r&0xF8)<<8);
194
+        *d++        = (b >> 3) | ((g & 0xFC) << 3) | ((r & 0xF8) << 8);
178 195
     }
179 196
 }
180 197
 
181 198
 static inline void rgb24to16_c(const uint8_t *src, uint8_t *dst, int src_size)
182 199
 {
183
-    const uint8_t *s = src;
184
-    uint16_t *d = (uint16_t *)dst;
200
+    uint16_t *d        = (uint16_t *)dst;
201
+    const uint8_t *s   = src;
185 202
     const uint8_t *end = s + src_size;
186 203
 
187 204
     while (s < end) {
188 205
         const int r = *s++;
189 206
         const int g = *s++;
190 207
         const int b = *s++;
191
-        *d++ = (b>>3) | ((g&0xFC)<<3) | ((r&0xF8)<<8);
208
+        *d++        = (b >> 3) | ((g & 0xFC) << 3) | ((r & 0xF8) << 8);
192 209
     }
193 210
 }
194 211
 
195
-static inline void rgb24tobgr15_c(const uint8_t *src, uint8_t *dst, int src_size)
212
+static inline void rgb24tobgr15_c(const uint8_t *src, uint8_t *dst,
213
+                                  int src_size)
196 214
 {
197
-    const uint8_t *s = src;
198
-    uint16_t *d = (uint16_t *)dst;
215
+    uint16_t *d        = (uint16_t *)dst;
216
+    const uint8_t *s   = src;
199 217
     const uint8_t *end = s + src_size;
200 218
 
201 219
     while (s < end) {
202 220
         const int b = *s++;
203 221
         const int g = *s++;
204 222
         const int r = *s++;
205
-        *d++ = (b>>3) | ((g&0xF8)<<2) | ((r&0xF8)<<7);
223
+        *d++        = (b >> 3) | ((g & 0xF8) << 2) | ((r & 0xF8) << 7);
206 224
     }
207 225
 }
208 226
 
209 227
 static inline void rgb24to15_c(const uint8_t *src, uint8_t *dst, int src_size)
210 228
 {
211
-    const uint8_t *s = src;
212
-    uint16_t *d = (uint16_t *)dst;
229
+    uint16_t *d        = (uint16_t *)dst;
230
+    const uint8_t *s   = src;
213 231
     const uint8_t *end = s + src_size;
214 232
 
215 233
     while (s < end) {
216 234
         const int r = *s++;
217 235
         const int g = *s++;
218 236
         const int b = *s++;
219
-        *d++ = (b>>3) | ((g&0xF8)<<2) | ((r&0xF8)<<7);
237
+        *d++        = (b >> 3) | ((g & 0xF8) << 2) | ((r & 0xF8) << 7);
220 238
     }
221 239
 }
222 240
 
223 241
 /*
224
-  I use less accurate approximation here by simply left-shifting the input
225
-  value and filling the low order bits with zeroes. This method improves PNG
226
-  compression but this scheme cannot reproduce white exactly, since it does
227
-  not generate an all-ones maximum value; the net effect is to darken the
228
-  image slightly.
229
-
230
-  The better method should be "left bit replication":
231
-
232
-   4 3 2 1 0
233
-   ---------
234
-   1 1 0 1 1
235
-
236
-   7 6 5 4 3  2 1 0
237
-   ----------------
238
-   1 1 0 1 1  1 1 0
239
-   |=======|  |===|
240
-       |      leftmost bits repeated to fill open bits
241
-       |
242
-   original bits
243
-*/
244
-static inline void rgb15tobgr24_c(const uint8_t *src, uint8_t *dst, int src_size)
245
-{
246
-    uint8_t *d = dst;
247
-    const uint16_t *s = (const uint16_t*)src;
242
+ * I use less accurate approximation here by simply left-shifting the input
243
+ * value and filling the low order bits with zeroes. This method improves PNG
244
+ * compression but this scheme cannot reproduce white exactly, since it does
245
+ * not generate an all-ones maximum value; the net effect is to darken the
246
+ * image slightly.
247
+ *
248
+ * The better method should be "left bit replication":
249
+ *
250
+ *  4 3 2 1 0
251
+ *  ---------
252
+ *  1 1 0 1 1
253
+ *
254
+ *  7 6 5 4 3  2 1 0
255
+ *  ----------------
256
+ *  1 1 0 1 1  1 1 0
257
+ *  |=======|  |===|
258
+ *      |      leftmost bits repeated to fill open bits
259
+ *      |
260
+ *  original bits
261
+ */
262
+static inline void rgb15tobgr24_c(const uint8_t *src, uint8_t *dst,
263
+                                  int src_size)
264
+{
265
+    uint8_t *d          = dst;
266
+    const uint16_t *s   = (const uint16_t *)src;
248 267
     const uint16_t *end = s + src_size / 2;
249 268
 
250 269
     while (s < end) {
251 270
         register uint16_t bgr = *s++;
252
-        *d++ = (bgr&0x1F)<<3;
253
-        *d++ = (bgr&0x3E0)>>2;
254
-        *d++ = (bgr&0x7C00)>>7;
271
+        *d++ = (bgr & 0x1F)   << 3;
272
+        *d++ = (bgr & 0x3E0)  >> 2;
273
+        *d++ = (bgr & 0x7C00) >> 7;
255 274
     }
256 275
 }
257 276
 
258
-static inline void rgb16tobgr24_c(const uint8_t *src, uint8_t *dst, int src_size)
277
+static inline void rgb16tobgr24_c(const uint8_t *src, uint8_t *dst,
278
+                                  int src_size)
259 279
 {
260
-    uint8_t *d = (uint8_t *)dst;
261
-    const uint16_t *s = (const uint16_t *)src;
280
+    uint8_t *d          = (uint8_t *)dst;
281
+    const uint16_t *s   = (const uint16_t *)src;
262 282
     const uint16_t *end = s + src_size / 2;
263 283
 
264 284
     while (s < end) {
265 285
         register uint16_t bgr = *s++;
266
-        *d++ = (bgr&0x1F)<<3;
267
-        *d++ = (bgr&0x7E0)>>3;
268
-        *d++ = (bgr&0xF800)>>8;
286
+        *d++ = (bgr & 0x1F)   << 3;
287
+        *d++ = (bgr & 0x7E0)  >> 3;
288
+        *d++ = (bgr & 0xF800) >> 8;
269 289
     }
270 290
 }
271 291
 
272 292
 static inline void rgb15to32_c(const uint8_t *src, uint8_t *dst, int src_size)
273 293
 {
274
-    uint8_t *d = dst;
275
-    const uint16_t *s = (const uint16_t *)src;
294
+    uint8_t *d          = dst;
295
+    const uint16_t *s   = (const uint16_t *)src;
276 296
     const uint16_t *end = s + src_size / 2;
277 297
 
278 298
     while (s < end) {
279 299
         register uint16_t bgr = *s++;
280 300
 #if HAVE_BIGENDIAN
281 301
         *d++ = 255;
282
-        *d++ = (bgr&0x7C00)>>7;
283
-        *d++ = (bgr&0x3E0)>>2;
284
-        *d++ = (bgr&0x1F)<<3;
302
+        *d++ = (bgr & 0x7C00) >> 7;
303
+        *d++ = (bgr & 0x3E0)  >> 2;
304
+        *d++ = (bgr & 0x1F)   << 3;
285 305
 #else
286
-        *d++ = (bgr&0x1F)<<3;
287
-        *d++ = (bgr&0x3E0)>>2;
288
-        *d++ = (bgr&0x7C00)>>7;
306
+        *d++ = (bgr & 0x1F)   << 3;
307
+        *d++ = (bgr & 0x3E0)  >> 2;
308
+        *d++ = (bgr & 0x7C00) >> 7;
289 309
         *d++ = 255;
290 310
 #endif
291 311
     }
... ...
@@ -293,46 +313,49 @@ static inline void rgb15to32_c(const uint8_t *src, uint8_t *dst, int src_size)
293 293
 
294 294
 static inline void rgb16to32_c(const uint8_t *src, uint8_t *dst, int src_size)
295 295
 {
296
-    uint8_t *d = dst;
297
-    const uint16_t *s = (const uint16_t*)src;
296
+    uint8_t *d          = dst;
297
+    const uint16_t *s   = (const uint16_t *)src;
298 298
     const uint16_t *end = s + src_size / 2;
299 299
 
300 300
     while (s < end) {
301 301
         register uint16_t bgr = *s++;
302 302
 #if HAVE_BIGENDIAN
303 303
         *d++ = 255;
304
-        *d++ = (bgr&0xF800)>>8;
305
-        *d++ = (bgr&0x7E0)>>3;
306
-        *d++ = (bgr&0x1F)<<3;
304
+        *d++ = (bgr & 0xF800) >> 8;
305
+        *d++ = (bgr & 0x7E0)  >> 3;
306
+        *d++ = (bgr & 0x1F)   << 3;
307 307
 #else
308
-        *d++ = (bgr&0x1F)<<3;
309
-        *d++ = (bgr&0x7E0)>>3;
310
-        *d++ = (bgr&0xF800)>>8;
308
+        *d++ = (bgr & 0x1F)   << 3;
309
+        *d++ = (bgr & 0x7E0)  >> 3;
310
+        *d++ = (bgr & 0xF800) >> 8;
311 311
         *d++ = 255;
312 312
 #endif
313 313
     }
314 314
 }
315 315
 
316
-static inline void shuffle_bytes_2103_c(const uint8_t *src, uint8_t *dst, int src_size)
316
+static inline void shuffle_bytes_2103_c(const uint8_t *src, uint8_t *dst,
317
+                                        int src_size)
317 318
 {
318
-    int idx = 15 - src_size;
319
-    const uint8_t *s = src-idx;
320
-    uint8_t *d = dst-idx;
321
-    for (; idx<15; idx+=4) {
322
-        register int v = *(const uint32_t *)&s[idx], g = v & 0xff00ff00;
323
-        v &= 0xff00ff;
324
-        *(uint32_t *)&d[idx] = (v>>16) + g + (v<<16);
319
+    int idx          = 15  - src_size;
320
+    const uint8_t *s = src - idx;
321
+    uint8_t *d       = dst - idx;
322
+
323
+    for (; idx < 15; idx += 4) {
324
+        register int v        = *(const uint32_t *)&s[idx], g = v & 0xff00ff00;
325
+        v                    &= 0xff00ff;
326
+        *(uint32_t *)&d[idx]  = (v >> 16) + g + (v << 16);
325 327
     }
326 328
 }
327 329
 
328 330
 static inline void rgb24tobgr24_c(const uint8_t *src, uint8_t *dst, int src_size)
329 331
 {
330 332
     unsigned i;
331
-    for (i=0; i<src_size; i+=3) {
333
+
334
+    for (i = 0; i < src_size; i += 3) {
332 335
         register uint8_t x = src[i + 2];
333
-        dst[i + 1] = src[i + 1];
334
-        dst[i + 2] = src[i + 0];
335
-        dst[i + 0] = x;
336
+        dst[i + 1]         = src[i + 1];
337
+        dst[i + 2]         = src[i + 0];
338
+        dst[i + 0]         = x;
336 339
     }
337 340
 }
338 341
 
... ...
@@ -344,9 +367,10 @@ static inline void yuvPlanartoyuy2_c(const uint8_t *ysrc, const uint8_t *usrc,
344 344
 {
345 345
     int y, i;
346 346
     const int chromWidth = width >> 1;
347
-    for (y=0; y<height; y++) {
347
+
348
+    for (y = 0; y < height; y++) {
348 349
 #if HAVE_FAST_64BIT
349
-        uint64_t *ldst = (uint64_t *) dst;
350
+        uint64_t *ldst = (uint64_t *)dst;
350 351
         const uint8_t *yc = ysrc, *uc = usrc, *vc = vsrc;
351 352
         for (i = 0; i < chromWidth; i += 2) {
352 353
             uint64_t k = yc[0] + (uc[0] << 8) +
... ...
@@ -354,28 +378,29 @@ static inline void yuvPlanartoyuy2_c(const uint8_t *ysrc, const uint8_t *usrc,
354 354
             uint64_t l = yc[2] + (uc[1] << 8) +
355 355
                          (yc[3] << 16) + (vc[1] << 24);
356 356
             *ldst++ = k + (l << 32);
357
-            yc += 4;
358
-            uc += 2;
359
-            vc += 2;
357
+            yc     += 4;
358
+            uc     += 2;
359
+            vc     += 2;
360 360
         }
361 361
 
362 362
 #else
363
-        int *idst = (int32_t *) dst;
363
+        int *idst = (int32_t *)dst;
364 364
         const uint8_t *yc = ysrc, *uc = usrc, *vc = vsrc;
365
+
365 366
         for (i = 0; i < chromWidth; i++) {
366 367
 #if HAVE_BIGENDIAN
367
-            *idst++ = (yc[0] << 24)+ (uc[0] << 16) +
368
-                (yc[1] << 8) + (vc[0] << 0);
368
+            *idst++ = (yc[0] << 24) + (uc[0] << 16) +
369
+                      (yc[1] <<  8) + (vc[0] <<  0);
369 370
 #else
370 371
             *idst++ = yc[0] + (uc[0] << 8) +
371
-                (yc[1] << 16) + (vc[0] << 24);
372
+                      (yc[1] << 16) + (vc[0] << 24);
372 373
 #endif
373 374
             yc += 2;
374 375
             uc++;
375 376
             vc++;
376 377
         }
377 378
 #endif
378
-        if ((y&(vertLumPerChroma-1)) == vertLumPerChroma-1) {
379
+        if ((y & (vertLumPerChroma - 1)) == vertLumPerChroma - 1) {
379 380
             usrc += chromStride;
380 381
             vsrc += chromStride;
381 382
         }
... ...
@@ -390,9 +415,8 @@ static inline void yuvPlanartoyuy2_c(const uint8_t *ysrc, const uint8_t *usrc,
390 390
  */
391 391
 static inline void yv12toyuy2_c(const uint8_t *ysrc, const uint8_t *usrc,
392 392
                                 const uint8_t *vsrc, uint8_t *dst,
393
-                                int width, int height,
394
-                                int lumStride, int chromStride,
395
-                                int dstStride)
393
+                                int width, int height, int lumStride,
394
+                                int chromStride, int dstStride)
396 395
 {
397 396
     //FIXME interpolate chroma
398 397
     yuvPlanartoyuy2_c(ysrc, usrc, vsrc, dst, width, height, lumStride,
... ...
@@ -407,9 +431,10 @@ static inline void yuvPlanartouyvy_c(const uint8_t *ysrc, const uint8_t *usrc,
407 407
 {
408 408
     int y, i;
409 409
     const int chromWidth = width >> 1;
410
-    for (y=0; y<height; y++) {
410
+
411
+    for (y = 0; y < height; y++) {
411 412
 #if HAVE_FAST_64BIT
412
-        uint64_t *ldst = (uint64_t *) dst;
413
+        uint64_t *ldst = (uint64_t *)dst;
413 414
         const uint8_t *yc = ysrc, *uc = usrc, *vc = vsrc;
414 415
         for (i = 0; i < chromWidth; i += 2) {
415 416
             uint64_t k = uc[0] + (yc[0] << 8) +
... ...
@@ -417,33 +442,34 @@ static inline void yuvPlanartouyvy_c(const uint8_t *ysrc, const uint8_t *usrc,
417 417
             uint64_t l = uc[1] + (yc[2] << 8) +
418 418
                          (vc[1] << 16) + (yc[3] << 24);
419 419
             *ldst++ = k + (l << 32);
420
-            yc += 4;
421
-            uc += 2;
422
-            vc += 2;
420
+            yc     += 4;
421
+            uc     += 2;
422
+            vc     += 2;
423 423
         }
424 424
 
425 425
 #else
426
-        int *idst = (int32_t *) dst;
426
+        int *idst = (int32_t *)dst;
427 427
         const uint8_t *yc = ysrc, *uc = usrc, *vc = vsrc;
428
+
428 429
         for (i = 0; i < chromWidth; i++) {
429 430
 #if HAVE_BIGENDIAN
430
-            *idst++ = (uc[0] << 24)+ (yc[0] << 16) +
431
-                (vc[0] << 8) + (yc[1] << 0);
431
+            *idst++ = (uc[0] << 24) + (yc[0] << 16) +
432
+                      (vc[0] <<  8) + (yc[1] <<  0);
432 433
 #else
433 434
             *idst++ = uc[0] + (yc[0] << 8) +
434
-               (vc[0] << 16) + (yc[1] << 24);
435
+                      (vc[0] << 16) + (yc[1] << 24);
435 436
 #endif
436 437
             yc += 2;
437 438
             uc++;
438 439
             vc++;
439 440
         }
440 441
 #endif
441
-        if ((y&(vertLumPerChroma-1)) == vertLumPerChroma-1) {
442
+        if ((y & (vertLumPerChroma - 1)) == vertLumPerChroma - 1) {
442 443
             usrc += chromStride;
443 444
             vsrc += chromStride;
444 445
         }
445 446
         ysrc += lumStride;
446
-        dst += dstStride;
447
+        dst  += dstStride;
447 448
     }
448 449
 }
449 450
 
... ...
@@ -453,9 +479,8 @@ static inline void yuvPlanartouyvy_c(const uint8_t *ysrc, const uint8_t *usrc,
453 453
  */
454 454
 static inline void yv12touyvy_c(const uint8_t *ysrc, const uint8_t *usrc,
455 455
                                 const uint8_t *vsrc, uint8_t *dst,
456
-                                int width, int height,
457
-                                int lumStride, int chromStride,
458
-                                int dstStride)
456
+                                int width, int height, int lumStride,
457
+                                int chromStride, int dstStride)
459 458
 {
460 459
     //FIXME interpolate chroma
461 460
     yuvPlanartouyvy_c(ysrc, usrc, vsrc, dst, width, height, lumStride,
... ...
@@ -467,9 +492,8 @@ static inline void yv12touyvy_c(const uint8_t *ysrc, const uint8_t *usrc,
467 467
  */
468 468
 static inline void yuv422ptouyvy_c(const uint8_t *ysrc, const uint8_t *usrc,
469 469
                                    const uint8_t *vsrc, uint8_t *dst,
470
-                                   int width, int height,
471
-                                   int lumStride, int chromStride,
472
-                                   int dstStride)
470
+                                   int width, int height, int lumStride,
471
+                                   int chromStride, int dstStride)
473 472
 {
474 473
     yuvPlanartouyvy_c(ysrc, usrc, vsrc, dst, width, height, lumStride,
475 474
                       chromStride, dstStride, 1);
... ...
@@ -480,9 +504,8 @@ static inline void yuv422ptouyvy_c(const uint8_t *ysrc, const uint8_t *usrc,
480 480
  */
481 481
 static inline void yuv422ptoyuy2_c(const uint8_t *ysrc, const uint8_t *usrc,
482 482
                                    const uint8_t *vsrc, uint8_t *dst,
483
-                                   int width, int height,
484
-                                   int lumStride, int chromStride,
485
-                                   int dstStride)
483
+                                   int width, int height, int lumStride,
484
+                                   int chromStride, int dstStride)
486 485
 {
487 486
     yuvPlanartoyuy2_c(ysrc, usrc, vsrc, dst, width, height, lumStride,
488 487
                       chromStride, dstStride, 1);
... ...
@@ -494,26 +517,26 @@ static inline void yuv422ptoyuy2_c(const uint8_t *ysrc, const uint8_t *usrc,
494 494
  */
495 495
 static inline void yuy2toyv12_c(const uint8_t *src, uint8_t *ydst,
496 496
                                 uint8_t *udst, uint8_t *vdst,
497
-                                int width, int height,
498
-                                int lumStride, int chromStride,
499
-                                int srcStride)
497
+                                int width, int height, int lumStride,
498
+                                int chromStride, int srcStride)
500 499
 {
501 500
     int y;
502 501
     const int chromWidth = width >> 1;
503
-    for (y=0; y<height; y+=2) {
502
+
503
+    for (y = 0; y < height; y += 2) {
504 504
         int i;
505
-        for (i=0; i<chromWidth; i++) {
506
-            ydst[2*i+0]     = src[4*i+0];
507
-            udst[i]     = src[4*i+1];
508
-            ydst[2*i+1]     = src[4*i+2];
509
-            vdst[i]     = src[4*i+3];
505
+        for (i = 0; i < chromWidth; i++) {
506
+            ydst[2 * i + 0] = src[4 * i + 0];
507
+            udst[i]         = src[4 * i + 1];
508
+            ydst[2 * i + 1] = src[4 * i + 2];
509
+            vdst[i]         = src[4 * i + 3];
510 510
         }
511 511
         ydst += lumStride;
512 512
         src  += srcStride;
513 513
 
514
-        for (i=0; i<chromWidth; i++) {
515
-            ydst[2*i+0]     = src[4*i+0];
516
-            ydst[2*i+1]     = src[4*i+2];
514
+        for (i = 0; i < chromWidth; i++) {
515
+            ydst[2 * i + 0] = src[4 * i + 0];
516
+            ydst[2 * i + 1] = src[4 * i + 2];
517 517
         }
518 518
         udst += chromStride;
519 519
         vdst += chromStride;
... ...
@@ -525,46 +548,46 @@ static inline void yuy2toyv12_c(const uint8_t *src, uint8_t *ydst,
525 525
 static inline void planar2x_c(const uint8_t *src, uint8_t *dst, int srcWidth,
526 526
                               int srcHeight, int srcStride, int dstStride)
527 527
 {
528
-    int x,y;
528
+    int x, y;
529 529
 
530
-    dst[0]= src[0];
530
+    dst[0] = src[0];
531 531
 
532 532
     // first line
533
-    for (x=0; x<srcWidth-1; x++) {
534
-        dst[2*x+1]= (3*src[x] +   src[x+1])>>2;
535
-        dst[2*x+2]= (  src[x] + 3*src[x+1])>>2;
533
+    for (x = 0; x < srcWidth - 1; x++) {
534
+        dst[2 * x + 1] = (3 * src[x] + src[x + 1]) >> 2;
535
+        dst[2 * x + 2] = (src[x] + 3 * src[x + 1]) >> 2;
536 536
     }
537
-    dst[2*srcWidth-1]= src[srcWidth-1];
537
+    dst[2 * srcWidth - 1] = src[srcWidth - 1];
538 538
 
539
-    dst+= dstStride;
539
+    dst += dstStride;
540 540
 
541
-    for (y=1; y<srcHeight; y++) {
541
+    for (y = 1; y < srcHeight; y++) {
542 542
         const int mmxSize = 1;
543 543
 
544
-        dst[0        ]= (3*src[0] +   src[srcStride])>>2;
545
-        dst[dstStride]= (  src[0] + 3*src[srcStride])>>2;
544
+        dst[0]         = (src[0] * 3 + src[srcStride]) >> 2;
545
+        dst[dstStride] = (src[0] + 3 * src[srcStride]) >> 2;
546 546
 
547
-        for (x=mmxSize-1; x<srcWidth-1; x++) {
548
-            dst[2*x          +1]= (3*src[x+0] +   src[x+srcStride+1])>>2;
549
-            dst[2*x+dstStride+2]= (  src[x+0] + 3*src[x+srcStride+1])>>2;
550
-            dst[2*x+dstStride+1]= (  src[x+1] + 3*src[x+srcStride  ])>>2;
551
-            dst[2*x          +2]= (3*src[x+1] +   src[x+srcStride  ])>>2;
547
+        for (x = mmxSize - 1; x < srcWidth - 1; x++) {
548
+            dst[2 * x + 1]             = (src[x + 0] * 3 + src[x + srcStride + 1]) >> 2;
549
+            dst[2 * x + dstStride + 2] = (src[x + 0] + 3 * src[x + srcStride + 1]) >> 2;
550
+            dst[2 * x + dstStride + 1] = (src[x + 1] + 3 * src[x + srcStride])     >> 2;
551
+            dst[2 * x + 2]             = (src[x + 1] * 3 + src[x + srcStride])     >> 2;
552 552
         }
553
-        dst[srcWidth*2 -1            ]= (3*src[srcWidth-1] +   src[srcWidth-1 + srcStride])>>2;
554
-        dst[srcWidth*2 -1 + dstStride]= (  src[srcWidth-1] + 3*src[srcWidth-1 + srcStride])>>2;
553
+        dst[srcWidth * 2 - 1]             = (src[srcWidth - 1] * 3 + src[srcWidth - 1 + srcStride]) >> 2;
554
+        dst[srcWidth * 2 - 1 + dstStride] = (src[srcWidth - 1] + 3 * src[srcWidth - 1 + srcStride]) >> 2;
555 555
 
556
-        dst+=dstStride*2;
557
-        src+=srcStride;
556
+        dst += dstStride * 2;
557
+        src += srcStride;
558 558
     }
559 559
 
560 560
     // last line
561
-    dst[0]= src[0];
561
+    dst[0] = src[0];
562 562
 
563
-    for (x=0; x<srcWidth-1; x++) {
564
-        dst[2*x+1]= (3*src[x] +   src[x+1])>>2;
565
-        dst[2*x+2]= (  src[x] + 3*src[x+1])>>2;
563
+    for (x = 0; x < srcWidth - 1; x++) {
564
+        dst[2 * x + 1] = (src[x] * 3 + src[x + 1]) >> 2;
565
+        dst[2 * x + 2] = (src[x] + 3 * src[x + 1]) >> 2;
566 566
     }
567
-    dst[2*srcWidth-1]= src[srcWidth-1];
567
+    dst[2 * srcWidth - 1] = src[srcWidth - 1];
568 568
 }
569 569
 
570 570
 /**
... ...
@@ -575,26 +598,26 @@ static inline void planar2x_c(const uint8_t *src, uint8_t *dst, int srcWidth,
575 575
  */
576 576
 static inline void uyvytoyv12_c(const uint8_t *src, uint8_t *ydst,
577 577
                                 uint8_t *udst, uint8_t *vdst,
578
-                                int width, int height,
579
-                                int lumStride, int chromStride,
580
-                                int srcStride)
578
+                                int width, int height, int lumStride,
579
+                                int chromStride, int srcStride)
581 580
 {
582 581
     int y;
583 582
     const int chromWidth = width >> 1;
584
-    for (y=0; y<height; y+=2) {
583
+
584
+    for (y = 0; y < height; y += 2) {
585 585
         int i;
586
-        for (i=0; i<chromWidth; i++) {
587
-            udst[i]     = src[4*i+0];
588
-            ydst[2*i+0] = src[4*i+1];
589
-            vdst[i]     = src[4*i+2];
590
-            ydst[2*i+1] = src[4*i+3];
586
+        for (i = 0; i < chromWidth; i++) {
587
+            udst[i]         = src[4 * i + 0];
588
+            ydst[2 * i + 0] = src[4 * i + 1];
589
+            vdst[i]         = src[4 * i + 2];
590
+            ydst[2 * i + 1] = src[4 * i + 3];
591 591
         }
592 592
         ydst += lumStride;
593 593
         src  += srcStride;
594 594
 
595
-        for (i=0; i<chromWidth; i++) {
596
-            ydst[2*i+0] = src[4*i+1];
597
-            ydst[2*i+1] = src[4*i+3];
595
+        for (i = 0; i < chromWidth; i++) {
596
+            ydst[2 * i + 0] = src[4 * i + 1];
597
+            ydst[2 * i + 1] = src[4 * i + 3];
598 598
         }
599 599
         udst += chromStride;
600 600
         vdst += chromStride;
... ...
@@ -619,44 +642,44 @@ void rgb24toyv12_c(const uint8_t *src, uint8_t *ydst, uint8_t *udst,
619 619
 
620 620
     for (y = 0; y < height; y += 2) {
621 621
         int i;
622
-        for (i=0; i<chromWidth; i++) {
623
-            unsigned int b = src[6*i+0];
624
-            unsigned int g = src[6*i+1];
625
-            unsigned int r = src[6*i+2];
622
+        for (i = 0; i < chromWidth; i++) {
623
+            unsigned int b = src[6 * i + 0];
624
+            unsigned int g = src[6 * i + 1];
625
+            unsigned int r = src[6 * i + 2];
626 626
 
627
-            unsigned int Y  =  ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16;
628
-            unsigned int V  =  ((RV*r + GV*g + BV*b)>>RGB2YUV_SHIFT) + 128;
629
-            unsigned int U  =  ((RU*r + GU*g + BU*b)>>RGB2YUV_SHIFT) + 128;
627
+            unsigned int Y = ((RY * r + GY * g + BY * b) >> RGB2YUV_SHIFT) +  16;
628
+            unsigned int V = ((RV * r + GV * g + BV * b) >> RGB2YUV_SHIFT) + 128;
629
+            unsigned int U = ((RU * r + GU * g + BU * b) >> RGB2YUV_SHIFT) + 128;
630 630
 
631 631
             udst[i]     = U;
632 632
             vdst[i]     = V;
633
-            ydst[2*i]   = Y;
633
+            ydst[2 * i] = Y;
634 634
 
635
-            b = src[6*i+3];
636
-            g = src[6*i+4];
637
-            r = src[6*i+5];
635
+            b = src[6 * i + 3];
636
+            g = src[6 * i + 4];
637
+            r = src[6 * i + 5];
638 638
 
639
-            Y  =  ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16;
640
-            ydst[2*i+1]     = Y;
639
+            Y = ((RY * r + GY * g + BY * b) >> RGB2YUV_SHIFT) + 16;
640
+            ydst[2 * i + 1] = Y;
641 641
         }
642 642
         ydst += lumStride;
643 643
         src  += srcStride;
644 644
 
645
-        for (i=0; i<chromWidth; i++) {
646
-            unsigned int b = src[6*i+0];
647
-            unsigned int g = src[6*i+1];
648
-            unsigned int r = src[6*i+2];
645
+        for (i = 0; i < chromWidth; i++) {
646
+            unsigned int b = src[6 * i + 0];
647
+            unsigned int g = src[6 * i + 1];
648
+            unsigned int r = src[6 * i + 2];
649 649
 
650
-            unsigned int Y  =  ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16;
650
+            unsigned int Y = ((RY * r + GY * g + BY * b) >> RGB2YUV_SHIFT) + 16;
651 651
 
652
-            ydst[2*i]     = Y;
652
+            ydst[2 * i] = Y;
653 653
 
654
-            b = src[6*i+3];
655
-            g = src[6*i+4];
656
-            r = src[6*i+5];
654
+            b = src[6 * i + 3];
655
+            g = src[6 * i + 4];
656
+            r = src[6 * i + 5];
657 657
 
658
-            Y  =  ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16;
659
-            ydst[2*i+1]     = Y;
658
+            Y = ((RY * r + GY * g + BY * b) >> RGB2YUV_SHIFT) + 16;
659
+            ydst[2 * i + 1] = Y;
660 660
         }
661 661
         udst += chromStride;
662 662
         vdst += chromStride;
... ...
@@ -666,17 +689,16 @@ void rgb24toyv12_c(const uint8_t *src, uint8_t *ydst, uint8_t *udst,
666 666
 }
667 667
 
668 668
 static void interleaveBytes_c(const uint8_t *src1, const uint8_t *src2,
669
-                              uint8_t *dest, int width,
670
-                              int height, int src1Stride,
671
-                              int src2Stride, int dstStride)
669
+                              uint8_t *dest, int width, int height,
670
+                              int src1Stride, int src2Stride, int dstStride)
672 671
 {
673 672
     int h;
674 673
 
675
-    for (h=0; h < height; h++) {
674
+    for (h = 0; h < height; h++) {
676 675
         int w;
677
-        for (w=0; w < width; w++) {
678
-            dest[2*w+0] = src1[w];
679
-            dest[2*w+1] = src2[w];
676
+        for (w = 0; w < width; w++) {
677
+            dest[2 * w + 0] = src1[w];
678
+            dest[2 * w + 1] = src2[w];
680 679
         }
681 680
         dest += dstStride;
682 681
         src1 += src1Stride;
... ...
@@ -694,15 +716,15 @@ static inline void vu9_to_vu12_c(const uint8_t *src1, const uint8_t *src2,
694 694
     int w = width  / 2;
695 695
     int h = height / 2;
696 696
 
697
-    for (y=0;y<h;y++) {
698
-        const uint8_t* s1=src1+srcStride1*(y>>1);
699
-        uint8_t* d=dst1+dstStride1*y;
697
+    for (y = 0; y < h; y++) {
698
+        const uint8_t *s1 = src1 + srcStride1 * (y >> 1);
699
+        uint8_t *d        = dst1 + dstStride1 *  y;
700 700
         for (x = 0; x < w; x++)
701 701
             d[2 * x] = d[2 * x + 1] = s1[x];
702 702
     }
703
-    for (y=0;y<h;y++) {
704
-        const uint8_t* s2=src2+srcStride2*(y>>1);
705
-        uint8_t* d=dst2+dstStride2*y;
703
+    for (y = 0; y < h; y++) {
704
+        const uint8_t *s2 = src2 + srcStride2 * (y >> 1);
705
+        uint8_t *d        = dst2 + dstStride2 *  y;
706 706
         for (x = 0; x < w; x++)
707 707
             d[2 * x] = d[2 * x + 1] = s2[x];
708 708
     }
... ...
@@ -718,33 +740,32 @@ static inline void yvu9_to_yuy2_c(const uint8_t *src1, const uint8_t *src2,
718 718
     int w = width / 2;
719 719
     int h = height;
720 720
 
721
-    for (y=0;y<h;y++) {
722
-        const uint8_t* yp=src1+srcStride1*y;
723
-        const uint8_t* up=src2+srcStride2*(y>>2);
724
-        const uint8_t* vp=src3+srcStride3*(y>>2);
725
-        uint8_t* d=dst+dstStride*y;
721
+    for (y = 0; y < h; y++) {
722
+        const uint8_t *yp = src1 + srcStride1 *  y;
723
+        const uint8_t *up = src2 + srcStride2 * (y >> 2);
724
+        const uint8_t *vp = src3 + srcStride3 * (y >> 2);
725
+        uint8_t *d        = dst  + dstStride  *  y;
726 726
         for (x = 0; x < w; x++) {
727
-            const int x2 = x<<2;
728
-            d[8*x+0] = yp[x2];
729
-            d[8*x+1] = up[x];
730
-            d[8*x+2] = yp[x2+1];
731
-            d[8*x+3] = vp[x];
732
-            d[8*x+4] = yp[x2+2];
733
-            d[8*x+5] = up[x];
734
-            d[8*x+6] = yp[x2+3];
735
-            d[8*x+7] = vp[x];
727
+            const int x2 = x << 2;
728
+            d[8 * x + 0] = yp[x2];
729
+            d[8 * x + 1] = up[x];
730
+            d[8 * x + 2] = yp[x2 + 1];
731
+            d[8 * x + 3] = vp[x];
732
+            d[8 * x + 4] = yp[x2 + 2];
733
+            d[8 * x + 5] = up[x];
734
+            d[8 * x + 6] = yp[x2 + 3];
735
+            d[8 * x + 7] = vp[x];
736 736
         }
737 737
     }
738 738
 }
739 739
 
740 740
 static void extract_even_c(const uint8_t *src, uint8_t *dst, int count)
741 741
 {
742
-    dst +=   count;
743
-    src += 2*count;
744
-    count= - count;
745
-
746
-    while(count<0) {
747
-        dst[count]= src[2*count];
742
+    dst   +=  count;
743
+    src   +=  count * 2;
744
+    count  = -count;
745
+    while (count < 0) {
746
+        dst[count] = src[2 * count];
748 747
         count++;
749 748
     }
750 749
 }
... ...
@@ -752,13 +773,13 @@ static void extract_even_c(const uint8_t *src, uint8_t *dst, int count)
752 752
 static void extract_even2_c(const uint8_t *src, uint8_t *dst0, uint8_t *dst1,
753 753
                             int count)
754 754
 {
755
-    dst0+=   count;
756
-    dst1+=   count;
757
-    src += 4*count;
758
-    count= - count;
759
-    while(count<0) {
760
-        dst0[count]= src[4*count+0];
761
-        dst1[count]= src[4*count+2];
755
+    dst0  +=  count;
756
+    dst1  +=  count;
757
+    src   +=  count * 4;
758
+    count  = -count;
759
+    while (count < 0) {
760
+        dst0[count] = src[4 * count + 0];
761
+        dst1[count] = src[4 * count + 2];
762 762
         count++;
763 763
     }
764 764
 }
... ...
@@ -766,14 +787,14 @@ static void extract_even2_c(const uint8_t *src, uint8_t *dst0, uint8_t *dst1,
766 766
 static void extract_even2avg_c(const uint8_t *src0, const uint8_t *src1,
767 767
                                uint8_t *dst0, uint8_t *dst1, int count)
768 768
 {
769
-    dst0 +=   count;
770
-    dst1 +=   count;
771
-    src0 += 4*count;
772
-    src1 += 4*count;
773
-    count= - count;
774
-    while(count<0) {
775
-        dst0[count]= (src0[4*count+0]+src1[4*count+0])>>1;
776
-        dst1[count]= (src0[4*count+2]+src1[4*count+2])>>1;
769
+    dst0  +=  count;
770
+    dst1  +=  count;
771
+    src0  +=  count * 4;
772
+    src1  +=  count * 4;
773
+    count  = -count;
774
+    while (count < 0) {
775
+        dst0[count] = (src0[4 * count + 0] + src1[4 * count + 0]) >> 1;
776
+        dst1[count] = (src0[4 * count + 2] + src1[4 * count + 2]) >> 1;
777 777
         count++;
778 778
     }
779 779
 }
... ...
@@ -781,14 +802,14 @@ static void extract_even2avg_c(const uint8_t *src0, const uint8_t *src1,
781 781
 static void extract_odd2_c(const uint8_t *src, uint8_t *dst0, uint8_t *dst1,
782 782
                            int count)
783 783
 {
784
-    dst0+=   count;
785
-    dst1+=   count;
786
-    src += 4*count;
787
-    count= - count;
784
+    dst0  +=  count;
785
+    dst1  +=  count;
786
+    src   +=  count * 4;
787
+    count  = -count;
788 788
     src++;
789
-    while(count<0) {
790
-        dst0[count]= src[4*count+0];
791
-        dst1[count]= src[4*count+2];
789
+    while (count < 0) {
790
+        dst0[count] = src[4 * count + 0];
791
+        dst1[count] = src[4 * count + 2];
792 792
         count++;
793 793
     }
794 794
 }
... ...
@@ -796,16 +817,16 @@ static void extract_odd2_c(const uint8_t *src, uint8_t *dst0, uint8_t *dst1,
796 796
 static void extract_odd2avg_c(const uint8_t *src0, const uint8_t *src1,
797 797
                               uint8_t *dst0, uint8_t *dst1, int count)
798 798
 {
799
-    dst0 +=   count;
800
-    dst1 +=   count;
801
-    src0 += 4*count;
802
-    src1 += 4*count;
803
-    count= - count;
799
+    dst0  +=  count;
800
+    dst1  +=  count;
801
+    src0  +=  count * 4;
802
+    src1  +=  count * 4;
803
+    count  = -count;
804 804
     src0++;
805 805
     src1++;
806
-    while(count<0) {
807
-        dst0[count]= (src0[4*count+0]+src1[4*count+0])>>1;
808
-        dst1[count]= (src0[4*count+2]+src1[4*count+2])>>1;
806
+    while (count < 0) {
807
+        dst0[count] = (src0[4 * count + 0] + src1[4 * count + 0]) >> 1;
808
+        dst1[count] = (src0[4 * count + 2] + src1[4 * count + 2]) >> 1;
809 809
         count++;
810 810
     }
811 811
 }
... ...
@@ -815,18 +836,18 @@ static void yuyvtoyuv420_c(uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
815 815
                            int lumStride, int chromStride, int srcStride)
816 816
 {
817 817
     int y;
818
-    const int chromWidth= -((-width)>>1);
818
+    const int chromWidth = -((-width) >> 1);
819 819
 
820
-    for (y=0; y<height; y++) {
820
+    for (y = 0; y < height; y++) {
821 821
         extract_even_c(src, ydst, width);
822
-        if(y&1) {
822
+        if (y & 1) {
823 823
             extract_odd2avg_c(src - srcStride, src, udst, vdst, chromWidth);
824
-            udst+= chromStride;
825
-            vdst+= chromStride;
824
+            udst += chromStride;
825
+            vdst += chromStride;
826 826
         }
827 827
 
828
-        src += srcStride;
829
-        ydst+= lumStride;
828
+        src  += srcStride;
829
+        ydst += lumStride;
830 830
     }
831 831
 }
832 832
 
... ...
@@ -835,16 +856,16 @@ static void yuyvtoyuv422_c(uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
835 835
                            int lumStride, int chromStride, int srcStride)
836 836
 {
837 837
     int y;
838
-    const int chromWidth= -((-width)>>1);
838
+    const int chromWidth = -((-width) >> 1);
839 839
 
840
-    for (y=0; y<height; y++) {
840
+    for (y = 0; y < height; y++) {
841 841
         extract_even_c(src, ydst, width);
842 842
         extract_odd2_c(src, udst, vdst, chromWidth);
843 843
 
844
-        src += srcStride;
845
-        ydst+= lumStride;
846
-        udst+= chromStride;
847
-        vdst+= chromStride;
844
+        src  += srcStride;
845
+        ydst += lumStride;
846
+        udst += chromStride;
847
+        vdst += chromStride;
848 848
     }
849 849
 }
850 850
 
... ...
@@ -853,18 +874,18 @@ static void uyvytoyuv420_c(uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
853 853
                            int lumStride, int chromStride, int srcStride)
854 854
 {
855 855
     int y;
856
-    const int chromWidth= -((-width)>>1);
856
+    const int chromWidth = -((-width) >> 1);
857 857
 
858
-    for (y=0; y<height; y++) {
858
+    for (y = 0; y < height; y++) {
859 859
         extract_even_c(src + 1, ydst, width);
860
-        if(y&1) {
860
+        if (y & 1) {
861 861
             extract_even2avg_c(src - srcStride, src, udst, vdst, chromWidth);
862
-            udst+= chromStride;
863
-            vdst+= chromStride;
862
+            udst += chromStride;
863
+            vdst += chromStride;
864 864
         }
865 865
 
866
-        src += srcStride;
867
-        ydst+= lumStride;
866
+        src  += srcStride;
867
+        ydst += lumStride;
868 868
     }
869 869
 }
870 870
 
... ...
@@ -873,16 +894,16 @@ static void uyvytoyuv422_c(uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
873 873
                            int lumStride, int chromStride, int srcStride)
874 874
 {
875 875
     int y;
876
-    const int chromWidth= -((-width)>>1);
876
+    const int chromWidth = -((-width) >> 1);
877 877
 
878
-    for (y=0; y<height; y++) {
878
+    for (y = 0; y < height; y++) {
879 879
         extract_even_c(src + 1, ydst, width);
880 880
         extract_even2_c(src, udst, vdst, chromWidth);
881 881
 
882
-        src += srcStride;
883
-        ydst+= lumStride;
884
-        udst+= chromStride;
885
-        vdst+= chromStride;
882
+        src  += srcStride;
883
+        ydst += lumStride;
884
+        udst += chromStride;
885
+        vdst += chromStride;
886 886
     }
887 887
 }
888 888
 
... ...
@@ -28,12 +28,12 @@
28 28
 #include <inttypes.h>
29 29
 #include <assert.h>
30 30
 
31
+#include "libavutil/cpu.h"
32
+#include "libavutil/bswap.h"
31 33
 #include "config.h"
32 34
 #include "rgb2rgb.h"
33 35
 #include "swscale.h"
34 36
 #include "swscale_internal.h"
35
-#include "libavutil/cpu.h"
36
-#include "libavutil/bswap.h"
37 37
 
38 38
 extern const uint8_t dither_4x4_16[4][8];
39 39
 extern const uint8_t dither_8x8_32[8][8];
... ...
@@ -41,14 +41,14 @@ extern const uint8_t dither_8x8_73[8][8];
41 41
 extern const uint8_t dither_8x8_220[8][8];
42 42
 
43 43
 const int32_t ff_yuv2rgb_coeffs[8][4] = {
44
-    {117504, 138453, 13954, 34903}, /* no sequence_display_extension */
45
-    {117504, 138453, 13954, 34903}, /* ITU-R Rec. 709 (1990) */
46
-    {104597, 132201, 25675, 53279}, /* unspecified */
47
-    {104597, 132201, 25675, 53279}, /* reserved */
48
-    {104448, 132798, 24759, 53109}, /* FCC */
49
-    {104597, 132201, 25675, 53279}, /* ITU-R Rec. 624-4 System B, G */
50
-    {104597, 132201, 25675, 53279}, /* SMPTE 170M */
51
-    {117579, 136230, 16907, 35559}  /* SMPTE 240M (1987) */
44
+    { 117504, 138453, 13954, 34903 }, /* no sequence_display_extension */
45
+    { 117504, 138453, 13954, 34903 }, /* ITU-R Rec. 709 (1990) */
46
+    { 104597, 132201, 25675, 53279 }, /* unspecified */
47
+    { 104597, 132201, 25675, 53279 }, /* reserved */
48
+    { 104448, 132798, 24759, 53109 }, /* FCC */
49
+    { 104597, 132201, 25675, 53279 }, /* ITU-R Rec. 624-4 System B, G */
50
+    { 104597, 132201, 25675, 53279 }, /* SMPTE 170M */
51
+    { 117579, 136230, 16907, 35559 }  /* SMPTE 240M (1987) */
52 52
 };
53 53
 
54 54
 const int *sws_getCoefficients(int colorspace)
... ...
@@ -65,503 +65,548 @@ const int *sws_getCoefficients(int colorspace)
65 65
     g = (void *)(c->table_gU[U] + c->table_gV[V]);  \
66 66
     b = (void *)c->table_bU[U];
67 67
 
68
-#define PUTRGB(dst,src,i)            \
69
-    Y = src[2*i];                    \
70
-    dst[2*i  ] = r[Y] + g[Y] + b[Y]; \
71
-    Y = src[2*i+1];                  \
72
-    dst[2*i+1] = r[Y] + g[Y] + b[Y];
73
-
74
-#define PUTRGB24(dst,src,i)                                  \
75
-    Y = src[2*i];                                            \
76
-    dst[6*i+0] = r[Y]; dst[6*i+1] = g[Y]; dst[6*i+2] = b[Y]; \
77
-    Y = src[2*i+1];                                          \
78
-    dst[6*i+3] = r[Y]; dst[6*i+4] = g[Y]; dst[6*i+5] = b[Y];
79
-
80
-#define PUTBGR24(dst,src,i)                                  \
81
-    Y = src[2*i];                                            \
82
-    dst[6*i+0] = b[Y]; dst[6*i+1] = g[Y]; dst[6*i+2] = r[Y]; \
83
-    Y = src[2*i+1];                                          \
84
-    dst[6*i+3] = b[Y]; dst[6*i+4] = g[Y]; dst[6*i+5] = r[Y];
85
-
86
-#define PUTRGBA(dst,ysrc,asrc,i,s)                      \
87
-    Y = ysrc[2*i];                                      \
88
-    dst[2*i  ] = r[Y] + g[Y] + b[Y] + (asrc[2*i  ]<<s); \
89
-    Y = ysrc[2*i+1];                                    \
90
-    dst[2*i+1] = r[Y] + g[Y] + b[Y] + (asrc[2*i+1]<<s);
91
-
92
-#define PUTRGB48(dst,src,i)             \
93
-    Y = src[2*i];                       \
94
-    dst[12*i+ 0] = dst[12*i+ 1] = r[Y]; \
95
-    dst[12*i+ 2] = dst[12*i+ 3] = g[Y]; \
96
-    dst[12*i+ 4] = dst[12*i+ 5] = b[Y]; \
97
-    Y = src[2*i+1];                     \
98
-    dst[12*i+ 6] = dst[12*i+ 7] = r[Y]; \
99
-    dst[12*i+ 8] = dst[12*i+ 9] = g[Y]; \
100
-    dst[12*i+10] = dst[12*i+11] = b[Y];
101
-
102
-#define PUTBGR48(dst,src,i)             \
103
-    Y = src[2*i];                       \
104
-    dst[12*i+ 0] = dst[12*i+ 1] = b[Y]; \
105
-    dst[12*i+ 2] = dst[12*i+ 3] = g[Y]; \
106
-    dst[12*i+ 4] = dst[12*i+ 5] = r[Y]; \
107
-    Y = src[2*i+1];                     \
108
-    dst[12*i+ 6] = dst[12*i+ 7] = b[Y]; \
109
-    dst[12*i+ 8] = dst[12*i+ 9] = g[Y]; \
110
-    dst[12*i+10] = dst[12*i+11] = r[Y];
111
-
112
-#define YUV2RGBFUNC(func_name, dst_type, alpha) \
113
-static int func_name(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, \
114
-                     int srcSliceH, uint8_t* dst[], int dstStride[]) \
115
-{\
116
-    int y;\
117
-\
118
-    if (!alpha && c->srcFormat == PIX_FMT_YUV422P) {\
119
-        srcStride[1] *= 2;\
120
-        srcStride[2] *= 2;\
121
-    }\
122
-    for (y=0; y<srcSliceH; y+=2) {\
123
-        dst_type *dst_1 = (dst_type*)(dst[0] + (y+srcSliceY  )*dstStride[0]);\
124
-        dst_type *dst_2 = (dst_type*)(dst[0] + (y+srcSliceY+1)*dstStride[0]);\
125
-        dst_type av_unused *r, *b;\
126
-        dst_type *g;\
127
-        const uint8_t *py_1 = src[0] + y*srcStride[0];\
128
-        const uint8_t *py_2 = py_1 + srcStride[0];\
129
-        const uint8_t *pu = src[1] + (y>>1)*srcStride[1];\
130
-        const uint8_t *pv = src[2] + (y>>1)*srcStride[2];\
131
-        const uint8_t av_unused *pa_1, *pa_2;\
132
-        unsigned int h_size = c->dstW>>3;\
133
-        if (alpha) {\
134
-            pa_1 = src[3] + y*srcStride[3];\
135
-            pa_2 = pa_1 + srcStride[3];\
136
-        }\
137
-        while (h_size--) {\
138
-            int av_unused U, V;\
139
-            int Y;\
140
-
141
-#define ENDYUV2RGBLINE(dst_delta)\
142
-            pu += 4;\
143
-            pv += 4;\
144
-            py_1 += 8;\
145
-            py_2 += 8;\
146
-            dst_1 += dst_delta;\
147
-            dst_2 += dst_delta;\
148
-        }\
149
-        if (c->dstW & 4) {\
150
-            int av_unused Y, U, V;\
151
-
152
-#define ENDYUV2RGBFUNC()\
153
-        }\
154
-    }\
155
-    return srcSliceH;\
156
-}
68
+#define PUTRGB(dst, src, i)                         \
69
+    Y              = src[2 * i];                    \
70
+    dst[2 * i]     = r[Y] + g[Y] + b[Y];            \
71
+    Y              = src[2 * i + 1];                \
72
+    dst[2 * i + 1] = r[Y] + g[Y] + b[Y];
73
+
74
+#define PUTRGB24(dst, src, i)                       \
75
+    Y              = src[2 * i];                    \
76
+    dst[6 * i + 0] = r[Y];                          \
77
+    dst[6 * i + 1] = g[Y];                          \
78
+    dst[6 * i + 2] = b[Y];                          \
79
+    Y              = src[2 * i + 1];                \
80
+    dst[6 * i + 3] = r[Y];                          \
81
+    dst[6 * i + 4] = g[Y];                          \
82
+    dst[6 * i + 5] = b[Y];
83
+
84
+#define PUTBGR24(dst, src, i)                       \
85
+    Y              = src[2 * i];                    \
86
+    dst[6 * i + 0] = b[Y];                          \
87
+    dst[6 * i + 1] = g[Y];                          \
88
+    dst[6 * i + 2] = r[Y];                          \
89
+    Y              = src[2 * i + 1];                \
90
+    dst[6 * i + 3] = b[Y];                          \
91
+    dst[6 * i + 4] = g[Y];                          \
92
+    dst[6 * i + 5] = r[Y];
93
+
94
+#define PUTRGBA(dst, ysrc, asrc, i, s)                                  \
95
+    Y              = ysrc[2 * i];                                       \
96
+    dst[2 * i]     = r[Y] + g[Y] + b[Y] + (asrc[2 * i]     << s);       \
97
+    Y              = ysrc[2 * i + 1];                                   \
98
+    dst[2 * i + 1] = r[Y] + g[Y] + b[Y] + (asrc[2 * i + 1] << s);
99
+
100
+#define PUTRGB48(dst, src, i)                       \
101
+    Y                = src[ 2 * i];                 \
102
+    dst[12 * i +  0] = dst[12 * i +  1] = r[Y];     \
103
+    dst[12 * i +  2] = dst[12 * i +  3] = g[Y];     \
104
+    dst[12 * i +  4] = dst[12 * i +  5] = b[Y];     \
105
+    Y                = src[ 2 * i + 1];             \
106
+    dst[12 * i +  6] = dst[12 * i +  7] = r[Y];     \
107
+    dst[12 * i +  8] = dst[12 * i +  9] = g[Y];     \
108
+    dst[12 * i + 10] = dst[12 * i + 11] = b[Y];
109
+
110
+#define PUTBGR48(dst, src, i)                       \
111
+    Y                = src[2 * i];                  \
112
+    dst[12 * i +  0] = dst[12 * i +  1] = b[Y];     \
113
+    dst[12 * i +  2] = dst[12 * i +  3] = g[Y];     \
114
+    dst[12 * i +  4] = dst[12 * i +  5] = r[Y];     \
115
+    Y                = src[2  * i +  1];            \
116
+    dst[12 * i +  6] = dst[12 * i +  7] = b[Y];     \
117
+    dst[12 * i +  8] = dst[12 * i +  9] = g[Y];     \
118
+    dst[12 * i + 10] = dst[12 * i + 11] = r[Y];
119
+
120
+#define YUV2RGBFUNC(func_name, dst_type, alpha)                             \
121
+    static int func_name(SwsContext *c, const uint8_t *src[],               \
122
+                         int srcStride[], int srcSliceY, int srcSliceH,     \
123
+                         uint8_t *dst[], int dstStride[])                   \
124
+    {                                                                       \
125
+        int y;                                                              \
126
+                                                                            \
127
+        if (!alpha && c->srcFormat == PIX_FMT_YUV422P) {                    \
128
+            srcStride[1] *= 2;                                              \
129
+            srcStride[2] *= 2;                                              \
130
+        }                                                                   \
131
+        for (y = 0; y < srcSliceH; y += 2) {                                \
132
+            dst_type *dst_1 =                                               \
133
+                (dst_type *)(dst[0] + (y + srcSliceY)     * dstStride[0]);  \
134
+            dst_type *dst_2 =                                               \
135
+                (dst_type *)(dst[0] + (y + srcSliceY + 1) * dstStride[0]);  \
136
+            dst_type av_unused *r, *g, *b;                                  \
137
+            const uint8_t *py_1 = src[0] +  y       * srcStride[0];         \
138
+            const uint8_t *py_2 = py_1   +            srcStride[0];         \
139
+            const uint8_t *pu   = src[1] + (y >> 1) * srcStride[1];         \
140
+            const uint8_t *pv   = src[2] + (y >> 1) * srcStride[2];         \
141
+            const uint8_t av_unused *pa_1, *pa_2;                           \
142
+            unsigned int h_size = c->dstW >> 3;                             \
143
+            if (alpha) {                                                    \
144
+                pa_1 = src[3] + y * srcStride[3];                           \
145
+                pa_2 = pa_1   +     srcStride[3];                           \
146
+            }                                                               \
147
+            while (h_size--) {                                              \
148
+                int av_unused U, V, Y;                                      \
149
+
150
+#define ENDYUV2RGBLINE(dst_delta)                   \
151
+    pu    += 4;                                     \
152
+    pv    += 4;                                     \
153
+    py_1  += 8;                                     \
154
+    py_2  += 8;                                     \
155
+    dst_1 += dst_delta;                             \
156
+    dst_2 += dst_delta;                             \
157
+    }                                               \
158
+    if (c->dstW & 4) {                              \
159
+        int av_unused Y, U, V;                      \
160
+
161
+#define ENDYUV2RGBFUNC()                            \
162
+            }                                       \
163
+        }                                           \
164
+        return srcSliceH;                           \
165
+    }
157 166
 
158
-#define CLOSEYUV2RGBFUNC(dst_delta)\
159
-    ENDYUV2RGBLINE(dst_delta)\
167
+#define CLOSEYUV2RGBFUNC(dst_delta)                 \
168
+    ENDYUV2RGBLINE(dst_delta)                       \
160 169
     ENDYUV2RGBFUNC()
161 170
 
162 171
 YUV2RGBFUNC(yuv2rgb_c_48, uint8_t, 0)
163 172
     LOADCHROMA(0);
164
-    PUTRGB48(dst_1,py_1,0);
165
-    PUTRGB48(dst_2,py_2,0);
173
+    PUTRGB48(dst_1, py_1, 0);
174
+    PUTRGB48(dst_2, py_2, 0);
166 175
 
167 176
     LOADCHROMA(1);
168
-    PUTRGB48(dst_2,py_2,1);
169
-    PUTRGB48(dst_1,py_1,1);
177
+    PUTRGB48(dst_2, py_2, 1);
178
+    PUTRGB48(dst_1, py_1, 1);
170 179
 
171 180
     LOADCHROMA(2);
172
-    PUTRGB48(dst_1,py_1,2);
173
-    PUTRGB48(dst_2,py_2,2);
181
+    PUTRGB48(dst_1, py_1, 2);
182
+    PUTRGB48(dst_2, py_2, 2);
174 183
 
175 184
     LOADCHROMA(3);
176
-    PUTRGB48(dst_2,py_2,3);
177
-    PUTRGB48(dst_1,py_1,3);
185
+    PUTRGB48(dst_2, py_2, 3);
186
+    PUTRGB48(dst_1, py_1, 3);
178 187
 ENDYUV2RGBLINE(48)
179 188
     LOADCHROMA(0);
180
-    PUTRGB48(dst_1,py_1,0);
181
-    PUTRGB48(dst_2,py_2,0);
189
+    PUTRGB48(dst_1, py_1, 0);
190
+    PUTRGB48(dst_2, py_2, 0);
182 191
 
183 192
     LOADCHROMA(1);
184
-    PUTRGB48(dst_2,py_2,1);
185
-    PUTRGB48(dst_1,py_1,1);
193
+    PUTRGB48(dst_2, py_2, 1);
194
+    PUTRGB48(dst_1, py_1, 1);
186 195
 ENDYUV2RGBFUNC()
187 196
 
188 197
 YUV2RGBFUNC(yuv2rgb_c_bgr48, uint8_t, 0)
189 198
     LOADCHROMA(0);
190
-    PUTBGR48(dst_1,py_1,0);
191
-    PUTBGR48(dst_2,py_2,0);
199
+    PUTBGR48(dst_1, py_1, 0);
200
+    PUTBGR48(dst_2, py_2, 0);
192 201
 
193 202
     LOADCHROMA(1);
194
-    PUTBGR48(dst_2,py_2,1);
195
-    PUTBGR48(dst_1,py_1,1);
203
+    PUTBGR48(dst_2, py_2, 1);
204
+    PUTBGR48(dst_1, py_1, 1);
196 205
 
197 206
     LOADCHROMA(2);
198
-    PUTBGR48(dst_1,py_1,2);
199
-    PUTBGR48(dst_2,py_2,2);
207
+    PUTBGR48(dst_1, py_1, 2);
208
+    PUTBGR48(dst_2, py_2, 2);
200 209
 
201 210
     LOADCHROMA(3);
202
-    PUTBGR48(dst_2,py_2,3);
203
-    PUTBGR48(dst_1,py_1,3);
211
+    PUTBGR48(dst_2, py_2, 3);
212
+    PUTBGR48(dst_1, py_1, 3);
204 213
 ENDYUV2RGBLINE(48)
205 214
     LOADCHROMA(0);
206
-    PUTBGR48(dst_1,py_1,0);
207
-    PUTBGR48(dst_2,py_2,0);
215
+    PUTBGR48(dst_1, py_1, 0);
216
+    PUTBGR48(dst_2, py_2, 0);
208 217
 
209 218
     LOADCHROMA(1);
210
-    PUTBGR48(dst_2,py_2,1);
211
-    PUTBGR48(dst_1,py_1,1);
219
+    PUTBGR48(dst_2, py_2, 1);
220
+    PUTBGR48(dst_1, py_1, 1);
212 221
 ENDYUV2RGBFUNC()
213 222
 
214 223
 YUV2RGBFUNC(yuv2rgb_c_32, uint32_t, 0)
215 224
     LOADCHROMA(0);
216
-    PUTRGB(dst_1,py_1,0);
217
-    PUTRGB(dst_2,py_2,0);
225
+    PUTRGB(dst_1, py_1, 0);
226
+    PUTRGB(dst_2, py_2, 0);
218 227
 
219 228
     LOADCHROMA(1);
220
-    PUTRGB(dst_2,py_2,1);
221
-    PUTRGB(dst_1,py_1,1);
229
+    PUTRGB(dst_2, py_2, 1);
230
+    PUTRGB(dst_1, py_1, 1);
222 231
 
223 232
     LOADCHROMA(2);
224
-    PUTRGB(dst_1,py_1,2);
225
-    PUTRGB(dst_2,py_2,2);
233
+    PUTRGB(dst_1, py_1, 2);
234
+    PUTRGB(dst_2, py_2, 2);
226 235
 
227 236
     LOADCHROMA(3);
228
-    PUTRGB(dst_2,py_2,3);
229
-    PUTRGB(dst_1,py_1,3);
237
+    PUTRGB(dst_2, py_2, 3);
238
+    PUTRGB(dst_1, py_1, 3);
230 239
 ENDYUV2RGBLINE(8)
231 240
     LOADCHROMA(0);
232
-    PUTRGB(dst_1,py_1,0);
233
-    PUTRGB(dst_2,py_2,0);
241
+    PUTRGB(dst_1, py_1, 0);
242
+    PUTRGB(dst_2, py_2, 0);
234 243
 
235 244
     LOADCHROMA(1);
236
-    PUTRGB(dst_2,py_2,1);
237
-    PUTRGB(dst_1,py_1,1);
245
+    PUTRGB(dst_2, py_2, 1);
246
+    PUTRGB(dst_1, py_1, 1);
238 247
 ENDYUV2RGBFUNC()
239 248
 
240 249
 YUV2RGBFUNC(yuva2rgba_c, uint32_t, 1)
241 250
     LOADCHROMA(0);
242
-    PUTRGBA(dst_1,py_1,pa_1,0,24);
243
-    PUTRGBA(dst_2,py_2,pa_2,0,24);
251
+    PUTRGBA(dst_1, py_1, pa_1, 0, 24);
252
+    PUTRGBA(dst_2, py_2, pa_2, 0, 24);
244 253
 
245 254
     LOADCHROMA(1);
246
-    PUTRGBA(dst_2,py_2,pa_1,1,24);
247
-    PUTRGBA(dst_1,py_1,pa_2,1,24);
255
+    PUTRGBA(dst_2, py_2, pa_1, 1, 24);
256
+    PUTRGBA(dst_1, py_1, pa_2, 1, 24);
248 257
 
249 258
     LOADCHROMA(2);
250
-    PUTRGBA(dst_1,py_1,pa_1,2,24);
251
-    PUTRGBA(dst_2,py_2,pa_2,2,24);
259
+    PUTRGBA(dst_1, py_1, pa_1, 2, 24);
260
+    PUTRGBA(dst_2, py_2, pa_2, 2, 24);
252 261
 
253 262
     LOADCHROMA(3);
254
-    PUTRGBA(dst_2,py_2,pa_1,3,24);
255
-    PUTRGBA(dst_1,py_1,pa_2,3,24);
256
-    pa_1 += 8;\
257
-    pa_2 += 8;\
263
+    PUTRGBA(dst_2, py_2, pa_1, 3, 24);
264
+    PUTRGBA(dst_1, py_1, pa_2, 3, 24);
265
+    pa_1 += 8; \
266
+    pa_2 += 8; \
258 267
 ENDYUV2RGBLINE(8)
259 268
     LOADCHROMA(0);
260
-    PUTRGBA(dst_1,py_1,pa_1,0,24);
261
-    PUTRGBA(dst_2,py_2,pa_2,0,24);
269
+    PUTRGBA(dst_1, py_1, pa_1, 0, 24);
270
+    PUTRGBA(dst_2, py_2, pa_2, 0, 24);
262 271
 
263 272
     LOADCHROMA(1);
264
-    PUTRGBA(dst_2,py_2,pa_1,1,24);
265
-    PUTRGBA(dst_1,py_1,pa_2,1,24);
273
+    PUTRGBA(dst_2, py_2, pa_1, 1, 24);
274
+    PUTRGBA(dst_1, py_1, pa_2, 1, 24);
266 275
 ENDYUV2RGBFUNC()
267 276
 
268 277
 YUV2RGBFUNC(yuva2argb_c, uint32_t, 1)
269 278
     LOADCHROMA(0);
270
-    PUTRGBA(dst_1,py_1,pa_1,0,0);
271
-    PUTRGBA(dst_2,py_2,pa_2,0,0);
279
+    PUTRGBA(dst_1, py_1, pa_1, 0, 0);
280
+    PUTRGBA(dst_2, py_2, pa_2, 0, 0);
272 281
 
273 282
     LOADCHROMA(1);
274
-    PUTRGBA(dst_2,py_2,pa_2,1,0);
275
-    PUTRGBA(dst_1,py_1,pa_1,1,0);
283
+    PUTRGBA(dst_2, py_2, pa_2, 1, 0);
284
+    PUTRGBA(dst_1, py_1, pa_1, 1, 0);
276 285
 
277 286
     LOADCHROMA(2);
278
-    PUTRGBA(dst_1,py_1,pa_1,2,0);
279
-    PUTRGBA(dst_2,py_2,pa_2,2,0);
287
+    PUTRGBA(dst_1, py_1, pa_1, 2, 0);
288
+    PUTRGBA(dst_2, py_2, pa_2, 2, 0);
280 289
 
281 290
     LOADCHROMA(3);
282
-    PUTRGBA(dst_2,py_2,pa_2,3,0);
283
-    PUTRGBA(dst_1,py_1,pa_1,3,0);
284
-    pa_1 += 8;\
285
-    pa_2 += 8;\
291
+    PUTRGBA(dst_2, py_2, pa_2, 3, 0);
292
+    PUTRGBA(dst_1, py_1, pa_1, 3, 0);
293
+    pa_1 += 8; \
294
+    pa_2 += 8; \
286 295
 ENDYUV2RGBLINE(8)
287 296
     LOADCHROMA(0);
288
-    PUTRGBA(dst_1,py_1,pa_1,0,0);
289
-    PUTRGBA(dst_2,py_2,pa_2,0,0);
297
+    PUTRGBA(dst_1, py_1, pa_1, 0, 0);
298
+    PUTRGBA(dst_2, py_2, pa_2, 0, 0);
290 299
 
291 300
     LOADCHROMA(1);
292
-    PUTRGBA(dst_2,py_2,pa_2,1,0);
293
-    PUTRGBA(dst_1,py_1,pa_1,1,0);
301
+    PUTRGBA(dst_2, py_2, pa_2, 1, 0);
302
+    PUTRGBA(dst_1, py_1, pa_1, 1, 0);
294 303
 ENDYUV2RGBFUNC()
295 304
 
296 305
 YUV2RGBFUNC(yuv2rgb_c_24_rgb, uint8_t, 0)
297 306
     LOADCHROMA(0);
298
-    PUTRGB24(dst_1,py_1,0);
299
-    PUTRGB24(dst_2,py_2,0);
307
+    PUTRGB24(dst_1, py_1, 0);
308
+    PUTRGB24(dst_2, py_2, 0);
300 309
 
301 310
     LOADCHROMA(1);
302
-    PUTRGB24(dst_2,py_2,1);
303
-    PUTRGB24(dst_1,py_1,1);
311
+    PUTRGB24(dst_2, py_2, 1);
312
+    PUTRGB24(dst_1, py_1, 1);
304 313
 
305 314
     LOADCHROMA(2);
306
-    PUTRGB24(dst_1,py_1,2);
307
-    PUTRGB24(dst_2,py_2,2);
315
+    PUTRGB24(dst_1, py_1, 2);
316
+    PUTRGB24(dst_2, py_2, 2);
308 317
 
309 318
     LOADCHROMA(3);
310
-    PUTRGB24(dst_2,py_2,3);
311
-    PUTRGB24(dst_1,py_1,3);
319
+    PUTRGB24(dst_2, py_2, 3);
320
+    PUTRGB24(dst_1, py_1, 3);
312 321
 ENDYUV2RGBLINE(24)
313 322
     LOADCHROMA(0);
314
-    PUTRGB24(dst_1,py_1,0);
315
-    PUTRGB24(dst_2,py_2,0);
323
+    PUTRGB24(dst_1, py_1, 0);
324
+    PUTRGB24(dst_2, py_2, 0);
316 325
 
317 326
     LOADCHROMA(1);
318
-    PUTRGB24(dst_2,py_2,1);
319
-    PUTRGB24(dst_1,py_1,1);
327
+    PUTRGB24(dst_2, py_2, 1);
328
+    PUTRGB24(dst_1, py_1, 1);
320 329
 ENDYUV2RGBFUNC()
321 330
 
322 331
 // only trivial mods from yuv2rgb_c_24_rgb
323 332
 YUV2RGBFUNC(yuv2rgb_c_24_bgr, uint8_t, 0)
324 333
     LOADCHROMA(0);
325
-    PUTBGR24(dst_1,py_1,0);
326
-    PUTBGR24(dst_2,py_2,0);
334
+    PUTBGR24(dst_1, py_1, 0);
335
+    PUTBGR24(dst_2, py_2, 0);
327 336
 
328 337
     LOADCHROMA(1);
329
-    PUTBGR24(dst_2,py_2,1);
330
-    PUTBGR24(dst_1,py_1,1);
338
+    PUTBGR24(dst_2, py_2, 1);
339
+    PUTBGR24(dst_1, py_1, 1);
331 340
 
332 341
     LOADCHROMA(2);
333
-    PUTBGR24(dst_1,py_1,2);
334
-    PUTBGR24(dst_2,py_2,2);
342
+    PUTBGR24(dst_1, py_1, 2);
343
+    PUTBGR24(dst_2, py_2, 2);
335 344
 
336 345
     LOADCHROMA(3);
337
-    PUTBGR24(dst_2,py_2,3);
338
-    PUTBGR24(dst_1,py_1,3);
346
+    PUTBGR24(dst_2, py_2, 3);
347
+    PUTBGR24(dst_1, py_1, 3);
339 348
 ENDYUV2RGBLINE(24)
340 349
     LOADCHROMA(0);
341
-    PUTBGR24(dst_1,py_1,0);
342
-    PUTBGR24(dst_2,py_2,0);
350
+    PUTBGR24(dst_1, py_1, 0);
351
+    PUTBGR24(dst_2, py_2, 0);
343 352
 
344 353
     LOADCHROMA(1);
345
-    PUTBGR24(dst_2,py_2,1);
346
-    PUTBGR24(dst_1,py_1,1);
354
+    PUTBGR24(dst_2, py_2, 1);
355
+    PUTBGR24(dst_1, py_1, 1);
347 356
 ENDYUV2RGBFUNC()
348 357
 
349 358
 // This is exactly the same code as yuv2rgb_c_32 except for the types of
350 359
 // r, g, b, dst_1, dst_2
351 360
 YUV2RGBFUNC(yuv2rgb_c_16, uint16_t, 0)
352 361
     LOADCHROMA(0);
353
-    PUTRGB(dst_1,py_1,0);
354
-    PUTRGB(dst_2,py_2,0);
362
+    PUTRGB(dst_1, py_1, 0);
363
+    PUTRGB(dst_2, py_2, 0);
355 364
 
356 365
     LOADCHROMA(1);
357
-    PUTRGB(dst_2,py_2,1);
358
-    PUTRGB(dst_1,py_1,1);
366
+    PUTRGB(dst_2, py_2, 1);
367
+    PUTRGB(dst_1, py_1, 1);
359 368
 
360 369
     LOADCHROMA(2);
361
-    PUTRGB(dst_1,py_1,2);
362
-    PUTRGB(dst_2,py_2,2);
370
+    PUTRGB(dst_1, py_1, 2);
371
+    PUTRGB(dst_2, py_2, 2);
363 372
 
364 373
     LOADCHROMA(3);
365
-    PUTRGB(dst_2,py_2,3);
366
-    PUTRGB(dst_1,py_1,3);
374
+    PUTRGB(dst_2, py_2, 3);
375
+    PUTRGB(dst_1, py_1, 3);
367 376
 CLOSEYUV2RGBFUNC(8)
368 377
 
369 378
 // r, g, b, dst_1, dst_2
370 379
 YUV2RGBFUNC(yuv2rgb_c_12_ordered_dither, uint16_t, 0)
371
-    const uint8_t *d16 = dither_4x4_16[y&3];
372
-#define PUTRGB12(dst,src,i,o)                                   \
373
-    Y = src[2*i];                                               \
374
-    dst[2*i]   = r[Y+d16[0+o]] + g[Y+d16[0+o]] + b[Y+d16[0+o]]; \
375
-    Y = src[2*i+1];                                             \
376
-    dst[2*i+1] = r[Y+d16[1+o]] + g[Y+d16[1+o]] + b[Y+d16[1+o]];
380
+    const uint8_t *d16 = dither_4x4_16[y & 3];
381
+
382
+#define PUTRGB12(dst, src, i, o)                    \
383
+    Y              = src[2 * i];                    \
384
+    dst[2 * i]     = r[Y + d16[0 + o]] +            \
385
+                     g[Y + d16[0 + o]] +            \
386
+                     b[Y + d16[0 + o]];             \
387
+    Y              = src[2 * i + 1];                \
388
+    dst[2 * i + 1] = r[Y + d16[1 + o]] +            \
389
+                     g[Y + d16[1 + o]] +            \
390
+                     b[Y + d16[1 + o]];
377 391
 
378 392
     LOADCHROMA(0);
379
-    PUTRGB12(dst_1,py_1,0,0);
380
-    PUTRGB12(dst_2,py_2,0,0+8);
393
+    PUTRGB12(dst_1, py_1, 0, 0);
394
+    PUTRGB12(dst_2, py_2, 0, 0 + 8);
381 395
 
382 396
     LOADCHROMA(1);
383
-    PUTRGB12(dst_2,py_2,1,2+8);
384
-    PUTRGB12(dst_1,py_1,1,2);
397
+    PUTRGB12(dst_2, py_2, 1, 2 + 8);
398
+    PUTRGB12(dst_1, py_1, 1, 2);
385 399
 
386 400
     LOADCHROMA(2);
387
-    PUTRGB12(dst_1,py_1,2,4);
388
-    PUTRGB12(dst_2,py_2,2,4+8);
401
+    PUTRGB12(dst_1, py_1, 2, 4);
402
+    PUTRGB12(dst_2, py_2, 2, 4 + 8);
389 403
 
390 404
     LOADCHROMA(3);
391
-    PUTRGB12(dst_2,py_2,3,6+8);
392
-    PUTRGB12(dst_1,py_1,3,6);
405
+    PUTRGB12(dst_2, py_2, 3, 6 + 8);
406
+    PUTRGB12(dst_1, py_1, 3, 6);
393 407
 CLOSEYUV2RGBFUNC(8)
394 408
 
395 409
 // r, g, b, dst_1, dst_2
396 410
 YUV2RGBFUNC(yuv2rgb_c_8_ordered_dither, uint8_t, 0)
397
-    const uint8_t *d32 = dither_8x8_32[y&7];
398
-    const uint8_t *d64 = dither_8x8_73[y&7];
399
-#define PUTRGB8(dst,src,i,o)                                    \
400
-    Y = src[2*i];                                               \
401
-    dst[2*i]   = r[Y+d32[0+o]] + g[Y+d32[0+o]] + b[Y+d64[0+o]]; \
402
-    Y = src[2*i+1];                                             \
403
-    dst[2*i+1] = r[Y+d32[1+o]] + g[Y+d32[1+o]] + b[Y+d64[1+o]];
411
+    const uint8_t *d32 = dither_8x8_32[y & 7];
412
+    const uint8_t *d64 = dither_8x8_73[y & 7];
413
+
414
+#define PUTRGB8(dst, src, i, o)                     \
415
+    Y              = src[2 * i];                    \
416
+    dst[2 * i]     = r[Y + d32[0 + o]] +            \
417
+                     g[Y + d32[0 + o]] +            \
418
+                     b[Y + d64[0 + o]];             \
419
+    Y              = src[2 * i + 1];                \
420
+    dst[2 * i + 1] = r[Y + d32[1 + o]] +            \
421
+                     g[Y + d32[1 + o]] +            \
422
+                     b[Y + d64[1 + o]];
404 423
 
405 424
     LOADCHROMA(0);
406
-    PUTRGB8(dst_1,py_1,0,0);
407
-    PUTRGB8(dst_2,py_2,0,0+8);
425
+    PUTRGB8(dst_1, py_1, 0, 0);
426
+    PUTRGB8(dst_2, py_2, 0, 0 + 8);
408 427
 
409 428
     LOADCHROMA(1);
410
-    PUTRGB8(dst_2,py_2,1,2+8);
411
-    PUTRGB8(dst_1,py_1,1,2);
429
+    PUTRGB8(dst_2, py_2, 1, 2 + 8);
430
+    PUTRGB8(dst_1, py_1, 1, 2);
412 431
 
413 432
     LOADCHROMA(2);
414
-    PUTRGB8(dst_1,py_1,2,4);
415
-    PUTRGB8(dst_2,py_2,2,4+8);
433
+    PUTRGB8(dst_1, py_1, 2, 4);
434
+    PUTRGB8(dst_2, py_2, 2, 4 + 8);
416 435
 
417 436
     LOADCHROMA(3);
418
-    PUTRGB8(dst_2,py_2,3,6+8);
419
-    PUTRGB8(dst_1,py_1,3,6);
437
+    PUTRGB8(dst_2, py_2, 3, 6 + 8);
438
+    PUTRGB8(dst_1, py_1, 3, 6);
420 439
 CLOSEYUV2RGBFUNC(8)
421 440
 
422 441
 YUV2RGBFUNC(yuv2rgb_c_4_ordered_dither, uint8_t, 0)
423
-    const uint8_t *d64 =  dither_8x8_73[y&7];
424
-    const uint8_t *d128 = dither_8x8_220[y&7];
442
+    const uint8_t * d64 = dither_8x8_73[y & 7];
443
+    const uint8_t *d128 = dither_8x8_220[y & 7];
425 444
     int acc;
426 445
 
427
-#define PUTRGB4D(dst,src,i,o)                                     \
428
-    Y = src[2*i];                                                 \
429
-    acc = r[Y+d128[0+o]] + g[Y+d64[0+o]] + b[Y+d128[0+o]];        \
430
-    Y = src[2*i+1];                                               \
431
-    acc |= (r[Y+d128[1+o]] + g[Y+d64[1+o]] + b[Y+d128[1+o]])<<4;  \
432
-    dst[i]= acc;
446
+#define PUTRGB4D(dst, src, i, o)                    \
447
+    Y      = src[2 * i];                            \
448
+    acc    = r[Y + d128[0 + o]] +                   \
449
+             g[Y +  d64[0 + o]] +                   \
450
+             b[Y + d128[0 + o]];                    \
451
+    Y      = src[2 * i + 1];                        \
452
+    acc   |= (r[Y + d128[1 + o]] +                  \
453
+              g[Y +  d64[1 + o]] +                  \
454
+              b[Y + d128[1 + o]]) << 4;             \
455
+    dst[i] = acc;
433 456
 
434 457
     LOADCHROMA(0);
435
-    PUTRGB4D(dst_1,py_1,0,0);
436
-    PUTRGB4D(dst_2,py_2,0,0+8);
458
+    PUTRGB4D(dst_1, py_1, 0, 0);
459
+    PUTRGB4D(dst_2, py_2, 0, 0 + 8);
437 460
 
438 461
     LOADCHROMA(1);
439
-    PUTRGB4D(dst_2,py_2,1,2+8);
440
-    PUTRGB4D(dst_1,py_1,1,2);
462
+    PUTRGB4D(dst_2, py_2, 1, 2 + 8);
463
+    PUTRGB4D(dst_1, py_1, 1, 2);
441 464
 
442 465
     LOADCHROMA(2);
443
-    PUTRGB4D(dst_1,py_1,2,4);
444
-    PUTRGB4D(dst_2,py_2,2,4+8);
466
+    PUTRGB4D(dst_1, py_1, 2, 4);
467
+    PUTRGB4D(dst_2, py_2, 2, 4 + 8);
445 468
 
446 469
     LOADCHROMA(3);
447
-    PUTRGB4D(dst_2,py_2,3,6+8);
448
-    PUTRGB4D(dst_1,py_1,3,6);
470
+    PUTRGB4D(dst_2, py_2, 3, 6 + 8);
471
+    PUTRGB4D(dst_1, py_1, 3, 6);
449 472
 CLOSEYUV2RGBFUNC(4)
450 473
 
451 474
 YUV2RGBFUNC(yuv2rgb_c_4b_ordered_dither, uint8_t, 0)
452
-    const uint8_t *d64 =  dither_8x8_73[y&7];
453
-    const uint8_t *d128 = dither_8x8_220[y&7];
454
-
455
-#define PUTRGB4DB(dst,src,i,o)                                    \
456
-    Y = src[2*i];                                                 \
457
-    dst[2*i]   = r[Y+d128[0+o]] + g[Y+d64[0+o]] + b[Y+d128[0+o]]; \
458
-    Y = src[2*i+1];                                               \
459
-    dst[2*i+1] = r[Y+d128[1+o]] + g[Y+d64[1+o]] + b[Y+d128[1+o]];
475
+    const uint8_t *d64  = dither_8x8_73[y & 7];
476
+    const uint8_t *d128 = dither_8x8_220[y & 7];
477
+
478
+#define PUTRGB4DB(dst, src, i, o)                   \
479
+    Y              = src[2 * i];                    \
480
+    dst[2 * i]     = r[Y + d128[0 + o]] +           \
481
+                     g[Y +  d64[0 + o]] +           \
482
+                     b[Y + d128[0 + o]];            \
483
+    Y              = src[2 * i + 1];                \
484
+    dst[2 * i + 1] = r[Y + d128[1 + o]] +           \
485
+                     g[Y +  d64[1 + o]] +           \
486
+                     b[Y + d128[1 + o]];
460 487
 
461 488
     LOADCHROMA(0);
462
-    PUTRGB4DB(dst_1,py_1,0,0);
463
-    PUTRGB4DB(dst_2,py_2,0,0+8);
489
+    PUTRGB4DB(dst_1, py_1, 0, 0);
490
+    PUTRGB4DB(dst_2, py_2, 0, 0 + 8);
464 491
 
465 492
     LOADCHROMA(1);
466
-    PUTRGB4DB(dst_2,py_2,1,2+8);
467
-    PUTRGB4DB(dst_1,py_1,1,2);
493
+    PUTRGB4DB(dst_2, py_2, 1, 2 + 8);
494
+    PUTRGB4DB(dst_1, py_1, 1, 2);
468 495
 
469 496
     LOADCHROMA(2);
470
-    PUTRGB4DB(dst_1,py_1,2,4);
471
-    PUTRGB4DB(dst_2,py_2,2,4+8);
497
+    PUTRGB4DB(dst_1, py_1, 2, 4);
498
+    PUTRGB4DB(dst_2, py_2, 2, 4 + 8);
472 499
 
473 500
     LOADCHROMA(3);
474
-    PUTRGB4DB(dst_2,py_2,3,6+8);
475
-    PUTRGB4DB(dst_1,py_1,3,6);
501
+    PUTRGB4DB(dst_2, py_2, 3, 6 + 8);
502
+    PUTRGB4DB(dst_1, py_1, 3, 6);
476 503
 CLOSEYUV2RGBFUNC(8)
477 504
 
478 505
 YUV2RGBFUNC(yuv2rgb_c_1_ordered_dither, uint8_t, 0)
479
-        const uint8_t *d128 = dither_8x8_220[y&7];
480
-        char out_1 = 0, out_2 = 0;
481
-        g= c->table_gU[128] + c->table_gV[128];
506
+    const uint8_t *d128 = dither_8x8_220[y & 7];
507
+    char out_1 = 0, out_2 = 0;
508
+    g = c->table_gU[128] + c->table_gV[128];
482 509
 
483
-#define PUTRGB1(out,src,i,o)    \
484
-    Y = src[2*i];               \
485
-    out+= out + g[Y+d128[0+o]]; \
486
-    Y = src[2*i+1];             \
487
-    out+= out + g[Y+d128[1+o]];
510
+#define PUTRGB1(out, src, i, o)                     \
511
+    Y    = src[2 * i];                              \
512
+    out += out + g[Y + d128[0 + o]];                \
513
+    Y    = src[2 * i + 1];                          \
514
+    out += out + g[Y + d128[1 + o]];
488 515
 
489
-    PUTRGB1(out_1,py_1,0,0);
490
-    PUTRGB1(out_2,py_2,0,0+8);
516
+    PUTRGB1(out_1, py_1, 0, 0);
517
+    PUTRGB1(out_2, py_2, 0, 0 + 8);
491 518
 
492
-    PUTRGB1(out_2,py_2,1,2+8);
493
-    PUTRGB1(out_1,py_1,1,2);
519
+    PUTRGB1(out_2, py_2, 1, 2 + 8);
520
+    PUTRGB1(out_1, py_1, 1, 2);
494 521
 
495
-    PUTRGB1(out_1,py_1,2,4);
496
-    PUTRGB1(out_2,py_2,2,4+8);
522
+    PUTRGB1(out_1, py_1, 2, 4);
523
+    PUTRGB1(out_2, py_2, 2, 4 + 8);
497 524
 
498
-    PUTRGB1(out_2,py_2,3,6+8);
499
-    PUTRGB1(out_1,py_1,3,6);
525
+    PUTRGB1(out_2, py_2, 3, 6 + 8);
526
+    PUTRGB1(out_1, py_1, 3, 6);
500 527
 
501
-    dst_1[0]= out_1;
502
-    dst_2[0]= out_2;
528
+    dst_1[0] = out_1;
529
+    dst_2[0] = out_2;
503 530
 CLOSEYUV2RGBFUNC(1)
504 531
 
505 532
 SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c)
506 533
 {
507 534
     SwsFunc t = NULL;
508 535
 
509
-    if (HAVE_MMX) {
536
+    if (HAVE_MMX)
510 537
         t = ff_yuv2rgb_init_mmx(c);
511
-    } else if (HAVE_VIS) {
538
+    else if (HAVE_VIS)
512 539
         t = ff_yuv2rgb_init_vis(c);
513
-    } else if (HAVE_ALTIVEC) {
540
+    else if (HAVE_ALTIVEC)
514 541
         t = ff_yuv2rgb_init_altivec(c);
515
-    } else if (ARCH_BFIN) {
542
+    else if (ARCH_BFIN)
516 543
         t = ff_yuv2rgb_get_func_ptr_bfin(c);
517
-    }
518 544
 
519 545
     if (t)
520 546
         return t;
521 547
 
522
-    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));
548
+    av_log(c, AV_LOG_WARNING,
549
+           "No accelerated colorspace conversion found from %s to %s.\n",
550
+           sws_format_name(c->srcFormat), sws_format_name(c->dstFormat));
523 551
 
524 552
     switch (c->dstFormat) {
525 553
     case PIX_FMT_BGR48BE:
526
-    case PIX_FMT_BGR48LE:    return yuv2rgb_c_bgr48;
554
+    case PIX_FMT_BGR48LE:
555
+        return yuv2rgb_c_bgr48;
527 556
     case PIX_FMT_RGB48BE:
528
-    case PIX_FMT_RGB48LE:    return yuv2rgb_c_48;
557
+    case PIX_FMT_RGB48LE:
558
+        return yuv2rgb_c_48;
529 559
     case PIX_FMT_ARGB:
530
-    case PIX_FMT_ABGR:       if (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX_FMT_YUVA420P) return yuva2argb_c;
560
+    case PIX_FMT_ABGR:
561
+        if (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX_FMT_YUVA420P)
562
+            return yuva2argb_c;
531 563
     case PIX_FMT_RGBA:
532
-    case PIX_FMT_BGRA:       return (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX_FMT_YUVA420P) ? yuva2rgba_c : yuv2rgb_c_32;
533
-    case PIX_FMT_RGB24:      return yuv2rgb_c_24_rgb;
534
-    case PIX_FMT_BGR24:      return yuv2rgb_c_24_bgr;
564
+    case PIX_FMT_BGRA:
565
+        if (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX_FMT_YUVA420P)
566
+            return yuva2rgba_c;
567
+        else
568
+            return yuv2rgb_c_32;
569
+    case PIX_FMT_RGB24:
570
+        return yuv2rgb_c_24_rgb;
571
+    case PIX_FMT_BGR24:
572
+        return yuv2rgb_c_24_bgr;
535 573
     case PIX_FMT_RGB565:
536 574
     case PIX_FMT_BGR565:
537 575
     case PIX_FMT_RGB555:
538
-    case PIX_FMT_BGR555:     return yuv2rgb_c_16;
576
+    case PIX_FMT_BGR555:
577
+        return yuv2rgb_c_16;
539 578
     case PIX_FMT_RGB444:
540
-    case PIX_FMT_BGR444:     return yuv2rgb_c_12_ordered_dither;
579
+    case PIX_FMT_BGR444:
580
+        return yuv2rgb_c_12_ordered_dither;
541 581
     case PIX_FMT_RGB8:
542
-    case PIX_FMT_BGR8:       return yuv2rgb_c_8_ordered_dither;
582
+    case PIX_FMT_BGR8:
583
+        return yuv2rgb_c_8_ordered_dither;
543 584
     case PIX_FMT_RGB4:
544
-    case PIX_FMT_BGR4:       return yuv2rgb_c_4_ordered_dither;
585
+    case PIX_FMT_BGR4:
586
+        return yuv2rgb_c_4_ordered_dither;
545 587
     case PIX_FMT_RGB4_BYTE:
546
-    case PIX_FMT_BGR4_BYTE:  return yuv2rgb_c_4b_ordered_dither;
547
-    case PIX_FMT_MONOBLACK:  return yuv2rgb_c_1_ordered_dither;
588
+    case PIX_FMT_BGR4_BYTE:
589
+        return yuv2rgb_c_4b_ordered_dither;
590
+    case PIX_FMT_MONOBLACK:
591
+        return yuv2rgb_c_1_ordered_dither;
548 592
     default:
549 593
         assert(0);
550 594
     }
551 595
     return NULL;
552 596
 }
553 597
 
554
-static void fill_table(uint8_t* table[256], const int elemsize, const int inc, void *y_tab)
598
+static void fill_table(uint8_t *table[256], const int elemsize,
599
+                       const int inc, void *y_tab)
555 600
 {
556 601
     int i;
557
-    int64_t cb = 0;
602
+    int64_t cb       = 0;
558 603
     uint8_t *y_table = y_tab;
559 604
 
560 605
     y_table -= elemsize * (inc >> 9);
561 606
 
562 607
     for (i = 0; i < 256; i++) {
563 608
         table[i] = y_table + elemsize * (cb >> 16);
564
-        cb += inc;
609
+        cb      += inc;
565 610
     }
566 611
 }
567 612
 
... ...
@@ -569,44 +614,49 @@ static void fill_gv_table(int table[256], const int elemsize, const int inc)
569 569
 {
570 570
     int i;
571 571
     int64_t cb = 0;
572
-    int off = -(inc >> 9);
572
+    int off    = -(inc >> 9);
573 573
 
574 574
     for (i = 0; i < 256; i++) {
575 575
         table[i] = elemsize * (off + (cb >> 16));
576
-        cb += inc;
576
+        cb      += inc;
577 577
     }
578 578
 }
579 579
 
580 580
 static uint16_t roundToInt16(int64_t f)
581 581
 {
582
-    int r= (f + (1<<15))>>16;
583
-         if (r<-0x7FFF) return 0x8000;
584
-    else if (r> 0x7FFF) return 0x7FFF;
585
-    else                return r;
582
+    int r = (f + (1 << 15)) >> 16;
583
+
584
+    if (r < -0x7FFF)
585
+        return 0x8000;
586
+    else if (r > 0x7FFF)
587
+        return 0x7FFF;
588
+    else
589
+        return r;
586 590
 }
587 591
 
588
-av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4], int fullRange,
589
-                                     int brightness, int contrast, int saturation)
592
+av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4],
593
+                                     int fullRange, int brightness,
594
+                                     int contrast, int saturation)
590 595
 {
591
-    const int isRgb =      c->dstFormat==PIX_FMT_RGB32
592
-                        || c->dstFormat==PIX_FMT_RGB32_1
593
-                        || c->dstFormat==PIX_FMT_BGR24
594
-                        || c->dstFormat==PIX_FMT_RGB565BE
595
-                        || c->dstFormat==PIX_FMT_RGB565LE
596
-                        || c->dstFormat==PIX_FMT_RGB555BE
597
-                        || c->dstFormat==PIX_FMT_RGB555LE
598
-                        || c->dstFormat==PIX_FMT_RGB444BE
599
-                        || c->dstFormat==PIX_FMT_RGB444LE
600
-                        || c->dstFormat==PIX_FMT_RGB8
601
-                        || c->dstFormat==PIX_FMT_RGB4
602
-                        || c->dstFormat==PIX_FMT_RGB4_BYTE
603
-                        || c->dstFormat==PIX_FMT_MONOBLACK;
604
-    const int isNotNe =    c->dstFormat==PIX_FMT_NE(RGB565LE,RGB565BE)
605
-                        || c->dstFormat==PIX_FMT_NE(RGB555LE,RGB555BE)
606
-                        || c->dstFormat==PIX_FMT_NE(RGB444LE,RGB444BE)
607
-                        || c->dstFormat==PIX_FMT_NE(BGR565LE,BGR565BE)
608
-                        || c->dstFormat==PIX_FMT_NE(BGR555LE,BGR555BE)
609
-                        || c->dstFormat==PIX_FMT_NE(BGR444LE,BGR444BE);
596
+    const int isRgb = c->dstFormat == PIX_FMT_RGB32     ||
597
+                      c->dstFormat == PIX_FMT_RGB32_1   ||
598
+                      c->dstFormat == PIX_FMT_BGR24     ||
599
+                      c->dstFormat == PIX_FMT_RGB565BE  ||
600
+                      c->dstFormat == PIX_FMT_RGB565LE  ||
601
+                      c->dstFormat == PIX_FMT_RGB555BE  ||
602
+                      c->dstFormat == PIX_FMT_RGB555LE  ||
603
+                      c->dstFormat == PIX_FMT_RGB444BE  ||
604
+                      c->dstFormat == PIX_FMT_RGB444LE  ||
605
+                      c->dstFormat == PIX_FMT_RGB8      ||
606
+                      c->dstFormat == PIX_FMT_RGB4      ||
607
+                      c->dstFormat == PIX_FMT_RGB4_BYTE ||
608
+                      c->dstFormat == PIX_FMT_MONOBLACK;
609
+    const int isNotNe = c->dstFormat == PIX_FMT_NE(RGB565LE, RGB565BE) ||
610
+                        c->dstFormat == PIX_FMT_NE(RGB555LE, RGB555BE) ||
611
+                        c->dstFormat == PIX_FMT_NE(RGB444LE, RGB444BE) ||
612
+                        c->dstFormat == PIX_FMT_NE(BGR565LE, BGR565BE) ||
613
+                        c->dstFormat == PIX_FMT_NE(BGR555LE, BGR555BE) ||
614
+                        c->dstFormat == PIX_FMT_NE(BGR444LE, BGR444BE);
610 615
     const int bpp = c->dstFormatBpp;
611 616
     uint8_t *y_table;
612 617
     uint16_t *y_table16;
... ...
@@ -618,43 +668,42 @@ av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4], int
618 618
     int64_t cbu =  inv_table[1];
619 619
     int64_t cgu = -inv_table[2];
620 620
     int64_t cgv = -inv_table[3];
621
-    int64_t cy  = 1<<16;
621
+    int64_t cy  = 1 << 16;
622 622
     int64_t oy  = 0;
623
-
624
-    int64_t yb = 0;
623
+    int64_t yb  = 0;
625 624
 
626 625
     if (!fullRange) {
627
-        cy = (cy*255) / 219;
628
-        oy = 16<<16;
626
+        cy = (cy * 255) / 219;
627
+        oy = 16 << 16;
629 628
     } else {
630
-        crv = (crv*224) / 255;
631
-        cbu = (cbu*224) / 255;
632
-        cgu = (cgu*224) / 255;
633
-        cgv = (cgv*224) / 255;
629
+        crv = (crv * 224) / 255;
630
+        cbu = (cbu * 224) / 255;
631
+        cgu = (cgu * 224) / 255;
632
+        cgv = (cgv * 224) / 255;
634 633
     }
635 634
 
636
-    cy  = (cy *contrast             ) >> 16;
637
-    crv = (crv*contrast * saturation) >> 32;
638
-    cbu = (cbu*contrast * saturation) >> 32;
639
-    cgu = (cgu*contrast * saturation) >> 32;
640
-    cgv = (cgv*contrast * saturation) >> 32;
641
-    oy -= 256*brightness;
642
-
643
-    c->uOffset=   0x0400040004000400LL;
644
-    c->vOffset=   0x0400040004000400LL;
645
-    c->yCoeff=    roundToInt16(cy *8192) * 0x0001000100010001ULL;
646
-    c->vrCoeff=   roundToInt16(crv*8192) * 0x0001000100010001ULL;
647
-    c->ubCoeff=   roundToInt16(cbu*8192) * 0x0001000100010001ULL;
648
-    c->vgCoeff=   roundToInt16(cgv*8192) * 0x0001000100010001ULL;
649
-    c->ugCoeff=   roundToInt16(cgu*8192) * 0x0001000100010001ULL;
650
-    c->yOffset=   roundToInt16(oy *   8) * 0x0001000100010001ULL;
651
-
652
-    c->yuv2rgb_y_coeff  = (int16_t)roundToInt16(cy <<13);
653
-    c->yuv2rgb_y_offset = (int16_t)roundToInt16(oy << 9);
654
-    c->yuv2rgb_v2r_coeff= (int16_t)roundToInt16(crv<<13);
655
-    c->yuv2rgb_v2g_coeff= (int16_t)roundToInt16(cgv<<13);
656
-    c->yuv2rgb_u2g_coeff= (int16_t)roundToInt16(cgu<<13);
657
-    c->yuv2rgb_u2b_coeff= (int16_t)roundToInt16(cbu<<13);
635
+    cy   = (cy  * contrast)              >> 16;
636
+    crv  = (crv * contrast * saturation) >> 32;
637
+    cbu  = (cbu * contrast * saturation) >> 32;
638
+    cgu  = (cgu * contrast * saturation) >> 32;
639
+    cgv  = (cgv * contrast * saturation) >> 32;
640
+    oy  -= 256 * brightness;
641
+
642
+    c->uOffset = 0x0400040004000400LL;
643
+    c->vOffset = 0x0400040004000400LL;
644
+    c->yCoeff  = roundToInt16(cy  * 8192) * 0x0001000100010001ULL;
645
+    c->vrCoeff = roundToInt16(crv * 8192) * 0x0001000100010001ULL;
646
+    c->ubCoeff = roundToInt16(cbu * 8192) * 0x0001000100010001ULL;
647
+    c->vgCoeff = roundToInt16(cgv * 8192) * 0x0001000100010001ULL;
648
+    c->ugCoeff = roundToInt16(cgu * 8192) * 0x0001000100010001ULL;
649
+    c->yOffset = roundToInt16(oy  *    8) * 0x0001000100010001ULL;
650
+
651
+    c->yuv2rgb_y_coeff   = (int16_t)roundToInt16(cy  << 13);
652
+    c->yuv2rgb_y_offset  = (int16_t)roundToInt16(oy  <<  9);
653
+    c->yuv2rgb_v2r_coeff = (int16_t)roundToInt16(crv << 13);
654
+    c->yuv2rgb_v2g_coeff = (int16_t)roundToInt16(cgv << 13);
655
+    c->yuv2rgb_u2g_coeff = (int16_t)roundToInt16(cgu << 13);
656
+    c->yuv2rgb_u2b_coeff = (int16_t)roundToInt16(cbu << 13);
658 657
 
659 658
     //scale coefficients by cy
660 659
     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
667 667
     switch (bpp) {
668 668
     case 1:
669 669
         c->yuvTable = av_malloc(1024);
670
-        y_table = c->yuvTable;
671
-        yb = -(384<<16) - oy;
672
-        for (i = 0; i < 1024-110; i++) {
673
-            y_table[i+110] = av_clip_uint8((yb + 0x8000) >> 16) >> 7;
674
-            yb += cy;
670
+        y_table     = c->yuvTable;
671
+        yb = -(384 << 16) - oy;
672
+        for (i = 0; i < 1024 - 110; i++) {
673
+            y_table[i + 110]  = av_clip_uint8((yb + 0x8000) >> 16) >> 7;
674
+            yb               += cy;
675 675
         }
676 676
         fill_table(c->table_gU, 1, cgu, y_table + yoffs);
677 677
         fill_gv_table(c->table_gV, 1, cgv);
678 678
         break;
679 679
     case 4:
680
-    case 4|128:
681
-        rbase = isRgb ? 3 : 0;
682
-        gbase = 1;
683
-        bbase = isRgb ? 0 : 3;
684
-        c->yuvTable = av_malloc(1024*3);
685
-        y_table = c->yuvTable;
686
-        yb = -(384<<16) - oy;
687
-        for (i = 0; i < 1024-110; i++) {
688
-            int yval = av_clip_uint8((yb + 0x8000) >> 16);
689
-            y_table[i+110     ] =  (yval >> 7)       << rbase;
690
-            y_table[i+ 37+1024] = ((yval + 43) / 85) << gbase;
691
-            y_table[i+110+2048] =  (yval >> 7)       << bbase;
680
+    case 4 | 128:
681
+        rbase       = isRgb ? 3 : 0;
682
+        gbase       = 1;
683
+        bbase       = isRgb ? 0 : 3;
684
+        c->yuvTable = av_malloc(1024 * 3);
685
+        y_table     = c->yuvTable;
686
+        yb = -(384 << 16) - oy;
687
+        for (i = 0; i < 1024 - 110; i++) {
688
+            int yval                = av_clip_uint8((yb + 0x8000) >> 16);
689
+            y_table[i + 110]        = (yval >> 7)        << rbase;
690
+            y_table[i +  37 + 1024] = ((yval + 43) / 85) << gbase;
691
+            y_table[i + 110 + 2048] = (yval >> 7)        << bbase;
692 692
             yb += cy;
693 693
         }
694 694
         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
697 697
         fill_gv_table(c->table_gV, 1, cgv);
698 698
         break;
699 699
     case 8:
700
-        rbase = isRgb ? 5 : 0;
701
-        gbase = isRgb ? 2 : 3;
702
-        bbase = isRgb ? 0 : 6;
703
-        c->yuvTable = av_malloc(1024*3);
704
-        y_table = c->yuvTable;
705
-        yb = -(384<<16) - oy;
706
-        for (i = 0; i < 1024-38; i++) {
707
-            int yval = av_clip_uint8((yb + 0x8000) >> 16);
708
-            y_table[i+16     ] = ((yval + 18) / 36) << rbase;
709
-            y_table[i+16+1024] = ((yval + 18) / 36) << gbase;
710
-            y_table[i+37+2048] = ((yval + 43) / 85) << bbase;
700
+        rbase       = isRgb ? 5 : 0;
701
+        gbase       = isRgb ? 2 : 3;
702
+        bbase       = isRgb ? 0 : 6;
703
+        c->yuvTable = av_malloc(1024 * 3);
704
+        y_table     = c->yuvTable;
705
+        yb = -(384 << 16) - oy;
706
+        for (i = 0; i < 1024 - 38; i++) {
707
+            int yval               = av_clip_uint8((yb + 0x8000) >> 16);
708
+            y_table[i + 16]        = ((yval + 18) / 36) << rbase;
709
+            y_table[i + 16 + 1024] = ((yval + 18) / 36) << gbase;
710
+            y_table[i + 37 + 2048] = ((yval + 43) / 85) << bbase;
711 711
             yb += cy;
712 712
         }
713 713
         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
716 716
         fill_gv_table(c->table_gV, 1, cgv);
717 717
         break;
718 718
     case 12:
719
-        rbase = isRgb ? 8 : 0;
720
-        gbase = 4;
721
-        bbase = isRgb ? 0 : 8;
722
-        c->yuvTable = av_malloc(1024*3*2);
723
-        y_table16 = c->yuvTable;
724
-        yb = -(384<<16) - oy;
719
+        rbase       = isRgb ? 8 : 0;
720
+        gbase       = 4;
721
+        bbase       = isRgb ? 0 : 8;
722
+        c->yuvTable = av_malloc(1024 * 3 * 2);
723
+        y_table16   = c->yuvTable;
724
+        yb = -(384 << 16) - oy;
725 725
         for (i = 0; i < 1024; i++) {
726
-            uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16);
727
-            y_table16[i     ] = (yval >> 4) << rbase;
728
-            y_table16[i+1024] = (yval >> 4) << gbase;
729
-            y_table16[i+2048] = (yval >> 4) << bbase;
726
+            uint8_t yval        = av_clip_uint8((yb + 0x8000) >> 16);
727
+            y_table16[i]        = (yval >> 4) << rbase;
728
+            y_table16[i + 1024] = (yval >> 4) << gbase;
729
+            y_table16[i + 2048] = (yval >> 4) << bbase;
730 730
             yb += cy;
731 731
         }
732 732
         if (isNotNe)
733
-            for (i = 0; i < 1024*3; i++)
733
+            for (i = 0; i < 1024 * 3; i++)
734 734
                 y_table16[i] = av_bswap16(y_table16[i]);
735 735
         fill_table(c->table_rV, 2, crv, y_table16 + yoffs);
736 736
         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
739 739
         break;
740 740
     case 15:
741 741
     case 16:
742
-        rbase = isRgb ? bpp - 5 : 0;
743
-        gbase = 5;
744
-        bbase = isRgb ? 0 : (bpp - 5);
745
-        c->yuvTable = av_malloc(1024*3*2);
746
-        y_table16 = c->yuvTable;
747
-        yb = -(384<<16) - oy;
742
+        rbase       = isRgb ? bpp - 5 : 0;
743
+        gbase       = 5;
744
+        bbase       = isRgb ? 0 : (bpp - 5);
745
+        c->yuvTable = av_malloc(1024 * 3 * 2);
746
+        y_table16   = c->yuvTable;
747
+        yb = -(384 << 16) - oy;
748 748
         for (i = 0; i < 1024; i++) {
749
-            uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16);
750
-            y_table16[i     ] = (yval >> 3)          << rbase;
751
-            y_table16[i+1024] = (yval >> (18 - bpp)) << gbase;
752
-            y_table16[i+2048] = (yval >> 3)          << bbase;
749
+            uint8_t yval        = av_clip_uint8((yb + 0x8000) >> 16);
750
+            y_table16[i]        = (yval >> 3)          << rbase;
751
+            y_table16[i + 1024] = (yval >> (18 - bpp)) << gbase;
752
+            y_table16[i + 2048] = (yval >> 3)          << bbase;
753 753
             yb += cy;
754 754
         }
755
-        if(isNotNe)
756
-            for (i = 0; i < 1024*3; i++)
755
+        if (isNotNe)
756
+            for (i = 0; i < 1024 * 3; i++)
757 757
                 y_table16[i] = av_bswap16(y_table16[i]);
758 758
         fill_table(c->table_rV, 2, crv, y_table16 + yoffs);
759 759
         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
763 763
     case 24:
764 764
     case 48:
765 765
         c->yuvTable = av_malloc(1024);
766
-        y_table = c->yuvTable;
767
-        yb = -(384<<16) - oy;
766
+        y_table     = c->yuvTable;
767
+        yb = -(384 << 16) - oy;
768 768
         for (i = 0; i < 1024; i++) {
769
-            y_table[i] = av_clip_uint8((yb + 0x8000) >> 16);
770
-            yb += cy;
769
+            y_table[i]  = av_clip_uint8((yb + 0x8000) >> 16);
770
+            yb         += cy;
771 771
         }
772 772
         fill_table(c->table_rV, 1, crv, y_table + yoffs);
773 773
         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
775 775
         fill_gv_table(c->table_gV, 1, cgv);
776 776
         break;
777 777
     case 32:
778
-        base = (c->dstFormat == PIX_FMT_RGB32_1 || c->dstFormat == PIX_FMT_BGR32_1) ? 8 : 0;
779
-        rbase = base + (isRgb ? 16 : 0);
780
-        gbase = base + 8;
781
-        bbase = base + (isRgb ? 0 : 16);
778
+        base      = (c->dstFormat == PIX_FMT_RGB32_1 ||
779
+                     c->dstFormat == PIX_FMT_BGR32_1) ? 8 : 0;
780
+        rbase     = base + (isRgb ? 16 : 0);
781
+        gbase     = base + 8;
782
+        bbase     = base + (isRgb ? 0 : 16);
782 783
         needAlpha = CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat);
783 784
         if (!needAlpha)
784 785
             abase = (base + 24) & 31;
785
-        c->yuvTable = av_malloc(1024*3*4);
786
-        y_table32 = c->yuvTable;
787
-        yb = -(384<<16) - oy;
786
+        c->yuvTable = av_malloc(1024 * 3 * 4);
787
+        y_table32   = c->yuvTable;
788
+        yb = -(384 << 16) - oy;
788 789
         for (i = 0; i < 1024; i++) {
789
-            unsigned yval = av_clip_uint8((yb + 0x8000) >> 16);
790
-            y_table32[i     ] = (yval << rbase) + (needAlpha ? 0 : (255u << abase));
791
-            y_table32[i+1024] = yval << gbase;
792
-            y_table32[i+2048] = yval << bbase;
790
+            unsigned yval       = av_clip_uint8((yb + 0x8000) >> 16);
791
+            y_table32[i]        = (yval << rbase) +
792
+                                  (needAlpha ? 0 : (255u << abase));
793
+            y_table32[i + 1024] =  yval << gbase;
794
+            y_table32[i + 2048] =  yval << bbase;
793 795
             yb += cy;
794 796
         }
795 797
         fill_table(c->table_rV, 4, crv, y_table32 + yoffs);