Note: We no longer publish the latest version of our code here. We primarily use a kumc-bmi github organization. The heron ETL repository, in particular, is not public. Peers in the informatics community should see MultiSiteDev for details on requesting access.

source: webrtc/webrtc/common_video/libyuv/include/webrtc_libyuv.h @ 0:4bda6873e34c

pub_scrub_3792 tip
Last change on this file since 0:4bda6873e34c was 0:4bda6873e34c, checked in by Michael Prittie <mprittie@…>, 6 years ago

Scrubbed password for publication.

File size: 6.2 KB
Line 
1/*
2 *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 *
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 */
10
11/*
12 * WebRTC's wrapper to libyuv.
13 */
14
15#ifndef WEBRTC_COMMON_VIDEO_LIBYUV_INCLUDE_WEBRTC_LIBYUV_H_
16#define WEBRTC_COMMON_VIDEO_LIBYUV_INCLUDE_WEBRTC_LIBYUV_H_
17
18#include <stdio.h>
19
20#include "webrtc/common_types.h"  // RawVideoTypes.
21#include "webrtc/common_video/interface/i420_video_frame.h"
22#include "webrtc/typedefs.h"
23
24namespace webrtc {
25
26// Supported video types.
27enum 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,
44};
45
46// This is the max PSNR value our algorithms can return.
47const double kPerfectPSNR = 48.0f;
48
49// Conversion between the RawVideoType and the LibYuv videoType.
50// TODO(wu): Consolidate types into one type throughout WebRtc.
51VideoType RawVideoTypeToCommonVideoVideoType(RawVideoType type);
52
53// Supported rotation
54// Direction of rotation - clockwise.
55enum VideoRotationMode {
56  kRotateNone = 0,
57  kRotate90 = 90,
58  kRotate180 = 180,
59  kRotate270 = 270,
60};
61
62// Align integer values.
63// Input:
64//   - value     : Input value to be aligned.
65//   - alignment : Alignment basis (power of 2).
66// Return value: An aligned form of the input value.
67int AlignInt(int value, int alignment);
68
69// Align stride values for I420 Video frames.
70// Input:
71//   - width    : Image width.
72//   - stride_y : Pointer to the stride of the y plane.
73//   - stride_uv: Pointer to the stride of the u and v planes (setting identical
74//                values for both).
75// Setting 16 byte alignment.
76void Calc16ByteAlignedStride(int width, int* stride_y, int* stride_uv);
77
78// Calculate the required buffer size.
79// Input:
80//   - type         :The type of the designated video frame.
81//   - width        :frame width in pixels.
82//   - height       :frame height in pixels.
83// Return value:    :The required size in bytes to accommodate the specified
84//                   video frame or -1 in case of an error .
85int CalcBufferSize(VideoType type, int width, int height);
86
87// TODO(mikhal): Add unit test for these two functions and determine location.
88// Print I420VideoFrame to file
89// Input:
90//    - frame       : Reference to video frame.
91//    - file        : pointer to file object. It is assumed that the file is
92//                    already open for writing.
93// Return value: 0 if OK, < 0 otherwise.
94int PrintI420VideoFrame(const I420VideoFrame& frame, FILE* file);
95
96// Extract buffer from I420VideoFrame (consecutive planes, no stride)
97// Input:
98//   - frame       : Reference to video frame.
99//   - size        : pointer to the size of the allocated buffer. If size is
100//                   insufficient, an error will be returned.
101//   - buffer      : Pointer to buffer
102// Return value: length of buffer if OK, < 0 otherwise.
103int ExtractBuffer(const I420VideoFrame& input_frame,
104                  int size, uint8_t* buffer);
105// Convert To I420
106// Input:
107//   - src_video_type   : Type of input video.
108//   - src_frame        : Pointer to a source frame.
109//   - crop_x/crop_y    : Starting positions for cropping (0 for no crop).
110//   - src_width        : src width in pixels.
111//   - src_height       : src height in pixels.
112//   - sample_size      : Required only for the parsing of MJPG (set to 0 else).
113//   - rotate           : Rotation mode of output image.
114// Output:
115//   - dst_frame        : Reference to a destination frame.
116// Return value: 0 if OK, < 0 otherwise.
117
118int ConvertToI420(VideoType src_video_type,
119                  const uint8_t* src_frame,
120                  int crop_x, int crop_y,
121                  int src_width, int src_height,
122                  int sample_size,
123                  VideoRotationMode rotation,
124                  I420VideoFrame* dst_frame);
125
126// Convert From I420
127// Input:
128//   - src_frame        : Reference to a source frame.
129//   - dst_video_type   : Type of output video.
130//   - dst_sample_size  : Required only for the parsing of MJPG.
131//   - dst_frame        : Pointer to a destination frame.
132// Return value: 0 if OK, < 0 otherwise.
133// It is assumed that source and destination have equal height.
134int ConvertFromI420(const I420VideoFrame& src_frame,
135                    VideoType dst_video_type, int dst_sample_size,
136                    uint8_t* dst_frame);
137// ConvertFrom YV12.
138// Interface - same as above.
139int ConvertFromYV12(const I420VideoFrame& src_frame,
140                    VideoType dst_video_type, int dst_sample_size,
141                    uint8_t* dst_frame);
142
143// The following list describes designated conversion functions which
144// are not covered by the previous general functions.
145// Input and output descriptions mostly match the above descriptions, and are
146// therefore omitted.
147int ConvertRGB24ToARGB(const uint8_t* src_frame,
148                       uint8_t* dst_frame,
149                       int width, int height,
150                       int dst_stride);
151int ConvertNV12ToRGB565(const uint8_t* src_frame,
152                        uint8_t* dst_frame,
153                        int width, int height);
154
155// Mirror functions
156// The following 2 functions perform mirroring on a given image
157// (LeftRight/UpDown).
158// Input:
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// It is assumed that src and dst frames have equal dimensions.
163int MirrorI420LeftRight(const I420VideoFrame* src_frame,
164                        I420VideoFrame* dst_frame);
165int MirrorI420UpDown(const I420VideoFrame* src_frame,
166                     I420VideoFrame* dst_frame);
167
168// Compute PSNR for an I420 frame (all planes).
169// Returns the PSNR in decibel, to a maximum of kInfinitePSNR.
170double I420PSNR(const I420VideoFrame* ref_frame,
171                const I420VideoFrame* test_frame);
172// Compute SSIM for an I420 frame (all planes).
173double I420SSIM(const I420VideoFrame* ref_frame,
174                const I420VideoFrame* test_frame);
175}
176
177#endif  // WEBRTC_COMMON_VIDEO_LIBYUV_INCLUDE_WEBRTC_LIBYUV_H_
Note: See TracBrowser for help on using the repository browser.