1From: https://github.com/descampsa/yuv2rgb
2# yuv2rgb
3C library for fast image conversion between yuv420p and rgb24.
4
5This is a simple library for optimized image conversion between YUV420p and rgb24.
6It was done mainly as an exercise to learn to use sse intrinsics, so there may still be room for optimization.
7
8For each conversion, a standard c optimized function and two sse function (with aligned and unaligned memory) are implemented.
9The sse version requires only SSE2, which is available on any reasonably recent CPU.
10The library also supports the three different YUV (YCrCb to be correct) color spaces that exist (see comments in code), and others can be added simply.
11
12There is a simple test program, that convert a raw YUV file to rgb ppm format, and measure computation time.
13Optionally, it also compares the result and computation time with the ffmpeg implementation (that uses MMX), and with the IPP functions.
14
15To compile, simply do :
16
17    mkdir build
18    cd build
19    cmake -DCMAKE_BUILD_TYPE=Release ..
20    make
21
22The test program only support raw YUV files for the YUV420 format, and ppm for the RGB24 format.
23To generate a raw yuv file, you can use avconv:
24
25    avconv -i example.jpg -c:v rawvideo -pix_fmt yuv420p example.yuv
26
27To generate the rgb file, you can use the ImageMagick convert program:
28
29    convert example.jpg example.ppm
30
31Then, for YUV420 to RGB24 conversion, use the test program like that:
32
33    ./test_yuv_rgb yuv2rgb image.yuv 4096 2160 image
34
35The second and third parameters are image width and height (that are needed because not available in the raw YUV file), and fourth parameter is the output filename template (several output files will be generated, named for example output_sse.ppm, output_av.ppm, etc.)
36
37Similarly, for RGB24 to YUV420 conversion:
38
39    ./test_yuv_rgb yuv2rgb image.ppm image
40
41On my computer, the test program on a 4K image give the following for yuv2rgb:
42
43    Time will be measured in each configuration for 100 iterations...
44    Processing time (std) : 2.630193 sec
45    Processing time (sse2_unaligned) : 0.704394 sec
46    Processing time (ffmpeg_unaligned) : 1.221432 sec
47    Processing time (ipp_unaligned) : 0.636274 sec
48    Processing time (sse2_aligned) : 0.606648 sec
49    Processing time (ffmpeg_aligned) : 1.227100 sec
50    Processing time (ipp_aligned) : 0.636951 sec
51
52And for rgb2yuv:
53
54    Time will be measured in each configuration for 100 iterations...
55    Processing time (std) : 2.588675 sec
56    Processing time (sse2_unaligned) : 0.676625 sec
57    Processing time (ffmpeg_unaligned) : 3.385816 sec
58    Processing time (ipp_unaligned) : 0.593890 sec
59    Processing time (sse2_aligned) : 0.640630 sec
60    Processing time (ffmpeg_aligned) : 3.397952 sec
61    Processing time (ipp_aligned) : 0.579043 sec
62
63configuration : gcc 4.9.2, swscale 3.0.0, IPP 9.0.1, intel i7-5500U
64