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.
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.
23 // TODO(mikhal): 1. Sync libyuv and WebRtc meaning of stride.
24 // 2. Reorder parameters for consistency.
26 // Supported video types.
46 // Conversion between the RawVideoType and the LibYuv videoType.
47 // TODO(wu): Consolidate types into one type throughout WebRtc.
48 VideoType
RawVideoTypeToCommonVideoVideoType(RawVideoType type
);
51 // Direction of rotation - clockwise.
52 enum VideoRotationMode
{
59 // Calculate the required buffer size.
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.
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
,
78 // TODO (mikhal): Merge the two functions above.
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.
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
,
100 int dst_width
, int dst_height
, int dst_stride
,
101 VideoRotationMode rotation
,
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
,
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
,
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
,
136 int ConvertI420ToRGB565(const uint8_t* src_frame
,
140 int ConvertI420ToARGB1555(const uint8_t* src_frame
,
145 int ConvertRGB24ToARGB(const uint8_t* src_frame
,
147 int width
, int height
,
149 int ConvertNV12ToRGB565(const uint8_t* src_frame
,
151 int width
, int height
);
154 // The following 2 functions perform mirroring on a given image
155 // (LeftRight/UpDown).
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
,
164 int width
, int height
);
165 int MirrorI420UpDown(const uint8_t* src_frame
,
167 int width
, int height
);
169 // Mirror functions + conversion
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
,
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_