- add sources.
[platform/framework/web/crosswalk.git] / src / media / base / yuv_convert.h
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 #ifndef MEDIA_BASE_YUV_CONVERT_H_
6 #define MEDIA_BASE_YUV_CONVERT_H_
7
8 #include "base/basictypes.h"
9 #include "media/base/media_export.h"
10
11 // Visual Studio 2010 does not support MMX intrinsics on x64.
12 // Some win64 yuv_convert code paths use SSE+MMX yasm, so without rewriting
13 // them, we use yasm EmptyRegisterState_MMX in place of _mm_empty() or
14 // hide the versions implemented with heavy use of MMX intrinsics.
15 // TODO(wolenetz): Use MMX intrinsics when compiling win64 with Visual
16 // Studio 2012? http://crbug.com/173450
17 #if defined(ARCH_CPU_X86_FAMILY) && \
18     !(defined(ARCH_CPU_X86_64) && defined(COMPILER_MSVC))
19 #define MEDIA_MMX_INTRINSICS_AVAILABLE
20 #endif
21
22 namespace media {
23
24 // Type of YUV surface.
25 // The value of these enums matter as they are used to shift vertical indices.
26 enum YUVType {
27   YV16 = 0,  // YV16 is half width and full height chroma channels.
28   YV12 = 1,  // YV12 is half width and half height chroma channels.
29 };
30
31 // Mirror means flip the image horizontally, as in looking in a mirror.
32 // Rotate happens after mirroring.
33 enum Rotate {
34   ROTATE_0,           // Rotation off.
35   ROTATE_90,          // Rotate clockwise.
36   ROTATE_180,         // Rotate upside down.
37   ROTATE_270,         // Rotate counter clockwise.
38   MIRROR_ROTATE_0,    // Mirror horizontally.
39   MIRROR_ROTATE_90,   // Mirror then Rotate clockwise.
40   MIRROR_ROTATE_180,  // Mirror vertically.
41   MIRROR_ROTATE_270,  // Transpose.
42 };
43
44 // Filter affects how scaling looks.
45 enum ScaleFilter {
46   FILTER_NONE = 0,        // No filter (point sampled).
47   FILTER_BILINEAR_H = 1,  // Bilinear horizontal filter.
48   FILTER_BILINEAR_V = 2,  // Bilinear vertical filter.
49   FILTER_BILINEAR = 3,    // Bilinear filter.
50 };
51
52 MEDIA_EXPORT void InitializeCPUSpecificYUVConversions();
53
54 // Convert a frame of YUV to 32 bit ARGB.
55 // Pass in YV16/YV12 depending on source format
56 MEDIA_EXPORT void ConvertYUVToRGB32(const uint8* yplane,
57                                     const uint8* uplane,
58                                     const uint8* vplane,
59                                     uint8* rgbframe,
60                                     int width,
61                                     int height,
62                                     int ystride,
63                                     int uvstride,
64                                     int rgbstride,
65                                     YUVType yuv_type);
66
67 // Convert a frame of YUVA to 32 bit ARGB.
68 // Pass in YV12A
69 MEDIA_EXPORT void ConvertYUVAToARGB(const uint8* yplane,
70                                     const uint8* uplane,
71                                     const uint8* vplane,
72                                     const uint8* aplane,
73                                     uint8* rgbframe,
74                                     int width,
75                                     int height,
76                                     int ystride,
77                                     int uvstride,
78                                     int astride,
79                                     int rgbstride,
80                                     YUVType yuv_type);
81
82 // Scale a frame of YUV to 32 bit ARGB.
83 // Supports rotation and mirroring.
84 MEDIA_EXPORT void ScaleYUVToRGB32(const uint8* yplane,
85                                   const uint8* uplane,
86                                   const uint8* vplane,
87                                   uint8* rgbframe,
88                                   int source_width,
89                                   int source_height,
90                                   int width,
91                                   int height,
92                                   int ystride,
93                                   int uvstride,
94                                   int rgbstride,
95                                   YUVType yuv_type,
96                                   Rotate view_rotate,
97                                   ScaleFilter filter);
98
99 // Biliner Scale a frame of YV12 to 32 bits ARGB on a specified rectangle.
100 // |yplane|, etc and |rgbframe| should point to the top-left pixels of the
101 // source and destination buffers.
102 MEDIA_EXPORT void ScaleYUVToRGB32WithRect(const uint8* yplane,
103                                           const uint8* uplane,
104                                           const uint8* vplane,
105                                           uint8* rgbframe,
106                                           int source_width,
107                                           int source_height,
108                                           int dest_width,
109                                           int dest_height,
110                                           int dest_rect_left,
111                                           int dest_rect_top,
112                                           int dest_rect_right,
113                                           int dest_rect_bottom,
114                                           int ystride,
115                                           int uvstride,
116                                           int rgbstride);
117
118 MEDIA_EXPORT void ConvertRGB32ToYUV(const uint8* rgbframe,
119                                     uint8* yplane,
120                                     uint8* uplane,
121                                     uint8* vplane,
122                                     int width,
123                                     int height,
124                                     int rgbstride,
125                                     int ystride,
126                                     int uvstride);
127
128 MEDIA_EXPORT void ConvertRGB24ToYUV(const uint8* rgbframe,
129                                     uint8* yplane,
130                                     uint8* uplane,
131                                     uint8* vplane,
132                                     int width,
133                                     int height,
134                                     int rgbstride,
135                                     int ystride,
136                                     int uvstride);
137
138 MEDIA_EXPORT void ConvertYUY2ToYUV(const uint8* src,
139                                    uint8* yplane,
140                                    uint8* uplane,
141                                    uint8* vplane,
142                                    int width,
143                                    int height);
144
145 MEDIA_EXPORT void ConvertNV21ToYUV(const uint8* src,
146                                    uint8* yplane,
147                                    uint8* uplane,
148                                    uint8* vplane,
149                                    int width,
150                                    int height);
151
152 // Empty SIMD register state after calling optimized scaler functions.
153 MEDIA_EXPORT void EmptyRegisterState();
154
155 }  // namespace media
156
157 #endif  // MEDIA_BASE_YUV_CONVERT_H_