Bug 797526 - some assertions in nsDOMClassInfo should be fatal in debug builds -...
[gecko.git] / media / webrtc / trunk / src / common_video / libyuv / include / libyuv.h
blobbf106f14b2f6bc48a1fce0aa259d36f1b2fb3dc3
1 /*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
12 * WebRTC's Wrapper to libyuv.
15 #ifndef WEBRTC_COMMON_VIDEO_LIBYUV_INCLUDE_LIBYUV_H_
16 #define WEBRTC_COMMON_VIDEO_LIBYUV_INCLUDE_LIBYUV_H_
18 #include "common_types.h" // RawVideoTypes.
19 #include "typedefs.h"
21 namespace webrtc {
23 // TODO(mikhal): 1. Sync libyuv and WebRtc meaning of stride.
24 // 2. Reorder parameters for consistency.
26 // Supported video types.
27 enum VideoType {
28 kUnknown,
29 kI420,
30 kIYUV,
31 kRGB24,
32 kABGR,
33 kARGB,
34 kARGB4444,
35 kRGB565,
36 kARGB1555,
37 kYUY2,
38 kYV12,
39 kUYVY,
40 kMJPG,
41 kNV21,
42 kNV12,
43 kBGRA,
46 // Conversion between the RawVideoType and the LibYuv videoType.
47 // TODO(wu): Consolidate types into one type throughout WebRtc.
48 VideoType RawVideoTypeToCommonVideoVideoType(RawVideoType type);
50 // Supported rotation
51 // Direction of rotation - clockwise.
52 enum VideoRotationMode {
53 kRotateNone = 0,
54 kRotate90 = 90,
55 kRotate180 = 180,
56 kRotate270 = 270,
59 // Calculate the required buffer size.
60 // Input:
61 // - type - The type of the designated video frame.
62 // - width - frame width in pixels.
63 // - height - frame height in pixels.
64 // Return value: The required size in bytes to accommodate the specified
65 // video frame or -1 in case of an error .
66 int CalcBufferSize(VideoType type, int width, int height);
68 // Compute required buffer size when converting from one type to another.
69 // Input:
70 // - src_video_type - Type of the existing video frame.
71 // - dst_video_type - Type of the designated video frame.
72 // - length - length in bytes of the data.
73 // Return value: The required size in bytes to accommodate the specified
74 // converted video frame or -1 in case of an error.
75 int CalcBufferSize(VideoType src_video_type,
76 VideoType dst_video_type,
77 int length);
78 // TODO (mikhal): Merge the two functions above.
81 // Convert To I420
82 // Input:
83 // - src_video_type : Type of input video.
84 // - src_frame : Pointer to a source frame.
85 // - crop_x/crop_y : Starting positions for cropping (0 for no crop).
86 // - src/dst_width : src/dst width in pixels.
87 // - src/dst_height : src/dst height in pixels.
88 // - sample_size : Required only for the parsing of MJPG (set to 0 else).
89 // - dst_stride : Number of bytes in a row of the dst Y plane.
90 // - rotate : Rotation mode of output image.
91 // Output:
92 // - dst_frame : Pointer to a destination frame.
93 // Return value: 0 if OK, < 0 otherwise.
95 int ConvertToI420(VideoType src_video_type,
96 const uint8_t* src_frame,
97 int crop_x, int crop_y,
98 int src_width, int src_height,
99 int sample_size,
100 int dst_width, int dst_height, int dst_stride,
101 VideoRotationMode rotation,
102 uint8_t* dst_frame);
104 // Convert From I420
105 // Input:
106 // - src_frame : Pointer to a source frame.
107 // - src_stride : Number of bytes in a row of the src Y plane.
108 // - dst_video_type : Type of output video.
109 // - dst_sample_size : Required only for the parsing of MJPG.
110 // - width : Width in pixels.
111 // - height : Height in pixels.
112 // - dst_frame : Pointer to a destination frame.
113 // Return value: 0 if OK, < 0 otherwise.
114 int ConvertFromI420(const uint8_t* src_frame, int src_stride,
115 VideoType dst_video_type, int dst_sample_size,
116 int width, int height,
117 uint8_t* dst_frame);
118 // ConvertFrom YV12.
119 // Interface - same as above.
120 int ConvertFromYV12(const uint8_t* src_frame, int src_stride,
121 VideoType dst_video_type, int dst_sample_size,
122 int width, int height,
123 uint8_t* dst_frame);
125 // The following list describes designated conversion functions which
126 // are not covered by the previous general functions.
127 // Input and output descriptions mostly match the above descriptions, and are
128 // therefore omitted.
129 // Possible additional input value - dst_stride - stride of the dst frame.
131 int ConvertI420ToARGB4444(const uint8_t* src_frame,
132 uint8_t* dst_frame,
133 int width,
134 int height,
135 int dst_stride);
136 int ConvertI420ToRGB565(const uint8_t* src_frame,
137 uint8_t* dst_frame,
138 int width,
139 int height);
140 int ConvertI420ToARGB1555(const uint8_t* src_frame,
141 uint8_t* dst_frame,
142 int width,
143 int height,
144 int dst_stride);
145 int ConvertRGB24ToARGB(const uint8_t* src_frame,
146 uint8_t* dst_frame,
147 int width, int height,
148 int dst_stride);
149 int ConvertNV12ToRGB565(const uint8_t* src_frame,
150 uint8_t* dst_frame,
151 int width, int height);
153 // Mirror functions
154 // The following 2 functions perform mirroring on a given image
155 // (LeftRight/UpDown).
156 // Input:
157 // - width : Image width in pixels.
158 // - height : Image height in pixels.
159 // - src_frame : Pointer to a source frame.
160 // - dst_frame : Pointer to a destination frame.
161 // Return value: 0 if OK, < 0 otherwise.
162 int MirrorI420LeftRight(const uint8_t* src_frame,
163 uint8_t* dst_frame,
164 int width, int height);
165 int MirrorI420UpDown(const uint8_t* src_frame,
166 uint8_t* dst_frame,
167 int width, int height);
169 // Mirror functions + conversion
170 // Input:
171 // - src_frame : Pointer to source frame.
172 // - dst_frame : Pointer to destination frame.
173 // - src_width : Width of input buffer.
174 // - src_height : Height of input buffer.
175 // - src_color_space : Color space to convert from, I420 if no
176 // conversion should be done.
177 // Return value: 0 if OK, < 0 otherwise.
178 int ConvertToI420AndMirrorUpDown(const uint8_t* src_frame,
179 uint8_t* dst_frame,
180 int src_width,
181 int src_height,
182 VideoType src_video_type);
184 // Compute PSNR for an I420 frame (all planes).
185 double I420PSNR(const uint8_t* ref_frame,
186 const uint8_t* test_frame,
187 int width, int height);
188 // Compute SSIM for an I420 frame (all planes).
189 double I420SSIM(const uint8_t* ref_frame,
190 const uint8_t* test_frame,
191 int width, int height);
194 #endif // WEBRTC_COMMON_VIDEO_LIBYUV_INCLUDE_LIBYUV_H_