summaryrefslogtreecommitdiffstats
path: root/media/base/simd/convert_rgb_to_yuv.cc
blob: 2bd6930381b4a9035e6ab41b7024dbac319ff833 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "media/base/simd/convert_rgb_to_yuv.h"

#include "build/build_config.h"
#include "media/base/cpu_features.h"
#include "media/base/simd/convert_rgb_to_yuv_ssse3.h"

namespace media {

void ConvertRGB32ToYUV_SSSE3(const uint8* rgbframe,
                             uint8* yplane,
                             uint8* uplane,
                             uint8* vplane,
                             int width,
                             int height,
                             int rgbstride,
                             int ystride,
                             int uvstride) {
#ifdef ENABLE_SUBSAMPLING
  for (; height >= 2; height -= 2) {
    ConvertARGBToYUVEven_SSSE3(rgbframe, yplane, uplane, vplane, width);
    rgbframe += rgbstride;
    yplane += ystride;

    ConvertARGBToYUVOdd_SSSE3(rgbframe, yplane, uplane, vplane, width);
    rgbframe += rgbstride;
    yplane += ystride;

    uplane += uvstride;
    vplane += uvstride;
  }

  if (height)
    ConvertARGBToYUVEven_SSSE3(rgbframe, yplane, uplane, vplane, width);
#else
  for (; height >= 2; height -= 2) {
    ConvertARGBToYUVRow_SSSE3(rgbframe, yplane, uplane, vplane, width);
    rgbframe += rgbstride;
    yplane += ystride;

    ConvertARGBToYUVRow_SSSE3(rgbframe, yplane, NULL, NULL, width);
    rgbframe += rgbstride;
    yplane += ystride;

    uplane += uvstride;
    vplane += uvstride;
  }

  if (height)
    ConvertARGBToYUVRow_SSSE3(rgbframe, yplane, uplane, vplane, width);
#endif
}

void ConvertRGB24ToYUV_SSSE3(const uint8* rgbframe,
                             uint8* yplane,
                             uint8* uplane,
                             uint8* vplane,
                             int width,
                             int height,
                             int rgbstride,
                             int ystride,
                             int uvstride) {
#ifdef ENABLE_SUBSAMPLING
  for (; height >= 2; height -= 2) {
    ConvertRGBToYUVEven_SSSE3(rgbframe, yplane, uplane, vplane, width);
    rgbframe += rgbstride;
    yplane += ystride;

    ConvertRGBToYUVOdd_SSSE3(rgbframe, yplane, uplane, vplane, width);
    rgbframe += rgbstride;
    yplane += ystride;

    uplane += uvstride;
    vplane += uvstride;
  }

  if (height)
    ConvertRGBToYUVEven_SSSE3(rgbframe, yplane, uplane, vplane, width);
#else
  for (; height >= 2; height -= 2) {
    ConvertRGBToYUVRow_SSSE3(rgbframe, yplane, uplane, vplane, width);
    rgbframe += rgbstride;
    yplane += ystride;

    ConvertRGBToYUVRow_SSSE3(rgbframe, yplane, NULL, NULL, width);
    rgbframe += rgbstride;
    yplane += ystride;

    uplane += uvstride;
    vplane += uvstride;
  }

  if (height)
    ConvertRGBToYUVRow_SSSE3(rgbframe, yplane, uplane, vplane, width);
#endif
}

}  // namespace media