1// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#if defined(_MSC_VER)
6#include <intrin.h>
7#else
8#include <mmintrin.h>
9#endif
10
11#include "media/base/simd/convert_yuv_to_rgb.h"
12#include "media/base/simd/yuv_to_rgb_table.h"
13#include "media/base/yuv_convert.h"
14
15namespace media {
16
17void ConvertYUVToRGB32_MMX(const uint8* yplane,
18                           const uint8* uplane,
19                           const uint8* vplane,
20                           uint8* rgbframe,
21                           int width,
22                           int height,
23                           int ystride,
24                           int uvstride,
25                           int rgbstride,
26                           YUVType yuv_type) {
27  unsigned int y_shift = GetVerticalShift(yuv_type);
28  for (int y = 0; y < height; ++y) {
29    uint8* rgb_row = rgbframe + y * rgbstride;
30    const uint8* y_ptr = yplane + y * ystride;
31    const uint8* u_ptr = uplane + (y >> y_shift) * uvstride;
32    const uint8* v_ptr = vplane + (y >> y_shift) * uvstride;
33
34    ConvertYUVToRGB32Row_MMX(y_ptr,
35                             u_ptr,
36                             v_ptr,
37                             rgb_row,
38                             width,
39                             GetLookupTable(yuv_type));
40  }
41
42  EmptyRegisterState();
43}
44
45void ConvertYUVAToARGB_MMX(const uint8* yplane,
46                           const uint8* uplane,
47                           const uint8* vplane,
48                           const uint8* aplane,
49                           uint8* rgbframe,
50                           int width,
51                           int height,
52                           int ystride,
53                           int uvstride,
54                           int astride,
55                           int rgbstride,
56                           YUVType yuv_type) {
57  unsigned int y_shift = GetVerticalShift(yuv_type);
58  for (int y = 0; y < height; ++y) {
59    uint8* rgb_row = rgbframe + y * rgbstride;
60    const uint8* y_ptr = yplane + y * ystride;
61    const uint8* u_ptr = uplane + (y >> y_shift) * uvstride;
62    const uint8* v_ptr = vplane + (y >> y_shift) * uvstride;
63    const uint8* a_ptr = aplane + y * astride;
64
65    ConvertYUVAToARGBRow_MMX(y_ptr,
66                             u_ptr,
67                             v_ptr,
68                             a_ptr,
69                             rgb_row,
70                             width,
71                             GetLookupTable(yuv_type));
72  }
73
74  EmptyRegisterState();
75}
76
77void ConvertYUVToRGB32_SSE(const uint8* yplane,
78                           const uint8* uplane,
79                           const uint8* vplane,
80                           uint8* rgbframe,
81                           int width,
82                           int height,
83                           int ystride,
84                           int uvstride,
85                           int rgbstride,
86                           YUVType yuv_type) {
87  unsigned int y_shift = GetVerticalShift(yuv_type);
88  for (int y = 0; y < height; ++y) {
89    uint8* rgb_row = rgbframe + y * rgbstride;
90    const uint8* y_ptr = yplane + y * ystride;
91    const uint8* u_ptr = uplane + (y >> y_shift) * uvstride;
92    const uint8* v_ptr = vplane + (y >> y_shift) * uvstride;
93
94    ConvertYUVToRGB32Row_SSE(y_ptr,
95                             u_ptr,
96                             v_ptr,
97                             rgb_row,
98                             width,
99                             GetLookupTable(yuv_type));
100  }
101
102  EmptyRegisterState();
103}
104
105}  // namespace media
106