xref: /aosp_15_r20/external/webrtc/rtc_tools/frame_analyzer/video_geometry_aligner.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2018 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 #ifndef RTC_TOOLS_FRAME_ANALYZER_VIDEO_GEOMETRY_ALIGNER_H_
12 #define RTC_TOOLS_FRAME_ANALYZER_VIDEO_GEOMETRY_ALIGNER_H_
13 
14 #include "api/video/video_frame_buffer.h"
15 #include "rtc_tools/video_file_reader.h"
16 
17 namespace webrtc {
18 namespace test {
19 
20 struct CropRegion {
21   // Each value represents how much to crop from each side. Left is where x=0,
22   // and top is where y=0. All values equal to zero represents no cropping.
23   int left = 0;
24   int right = 0;
25   int top = 0;
26   int bottom = 0;
27 };
28 
29 // Crops and zooms in on the cropped region so that the returned frame has the
30 // same resolution as the input frame.
31 rtc::scoped_refptr<I420BufferInterface> CropAndZoom(
32     const CropRegion& crop_region,
33     const rtc::scoped_refptr<I420BufferInterface>& frame);
34 
35 // Calculate the optimal cropping region on the reference frame to maximize SSIM
36 // to the test frame.
37 CropRegion CalculateCropRegion(
38     const rtc::scoped_refptr<I420BufferInterface>& reference_frame,
39     const rtc::scoped_refptr<I420BufferInterface>& test_frame);
40 
41 // Returns a cropped and zoomed version of the reference frame that matches up
42 // to the test frame. This is a simple helper function on top of
43 // CalculateCropRegion() and CropAndZoom().
44 rtc::scoped_refptr<I420BufferInterface> AdjustCropping(
45     const rtc::scoped_refptr<I420BufferInterface>& reference_frame,
46     const rtc::scoped_refptr<I420BufferInterface>& test_frame);
47 
48 // Returns a cropped and zoomed version of the reference video that matches up
49 // to the test video. Frames are individually adjusted for cropping.
50 rtc::scoped_refptr<Video> AdjustCropping(
51     const rtc::scoped_refptr<Video>& reference_video,
52     const rtc::scoped_refptr<Video>& test_video);
53 
54 }  // namespace test
55 }  // namespace webrtc
56 
57 #endif  // RTC_TOOLS_FRAME_ANALYZER_VIDEO_GEOMETRY_ALIGNER_H_
58