1 /* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #ifndef TENSORFLOW_LITE_SUPPORT_CC_TASK_VISION_UTILS_FRAME_BUFFER_UTILS_INTERFACE_H_
17 #define TENSORFLOW_LITE_SUPPORT_CC_TASK_VISION_UTILS_FRAME_BUFFER_UTILS_INTERFACE_H_
18 
19 #include "absl/status/status.h"
20 #include "tensorflow_lite_support/cc/task/vision/core/frame_buffer.h"
21 
22 namespace tflite {
23 namespace task {
24 namespace vision {
25 
26 // Interface for the FrameBuffer image processing library.
27 class FrameBufferUtilsInterface {
28  public:
29   virtual ~FrameBufferUtilsInterface() = default;
30 
31   // Crops `buffer` to the specified points.
32   //
33   // The coordinate system has its origin at the upper left corner, and
34   // positive values extend down and to the right from it. After cropping,
35   // the top left point becomes (0, 0). The new width and height are
36   // (x1 - x0 + 1, y1 - y0 + 1).
37   //
38   // The `output_buffer` should have metadata populated and its backing buffer
39   // should be big enough to store the operation result.
40   virtual absl::Status Crop(const FrameBuffer& buffer, int x0, int y0, int x1,
41                             int y1, FrameBuffer* output_buffer) = 0;
42 
43   // Resizes `buffer` to the size of the given `output_buffer`.
44   //
45   // The resize dimension is determined based on the size of `output_buffer`.
46   //
47   // The `output_buffer` should have metadata populated and its backing buffer
48   // should be big enough to store the operation result.
49   virtual absl::Status Resize(const FrameBuffer& buffer,
50                               FrameBuffer* output_buffer) = 0;
51 
52   // Rotates `buffer` counter-clockwise by the given `angle_deg` (in degrees).
53   //
54   // When rotating by 90 degrees, the top-right corner of `buffer` becomes
55   // the top-left corner of `output_buffer`. The given angle must be a multiple
56   // of 90 degrees.
57   //
58   // The `output_buffer` should have metadata populated and its backing buffer
59   // should be big enough to store the operation result.
60   virtual absl::Status Rotate(const FrameBuffer& buffer, int angle_deg,
61                               FrameBuffer* output_buffer) = 0;
62 
63   // Flips `buffer` horizontally.
64   //
65   // The `output_buffer` should have metadata populated and its backing buffer
66   // should be big enough to store the operation result.
67   virtual absl::Status FlipHorizontally(const FrameBuffer& buffer,
68                                         FrameBuffer* output_buffer) = 0;
69 
70   // Flips `buffer` vertically.
71   //
72   // The `output_buffer` should have metadata populated and its backing buffer
73   // should be big enough to store the operation result.
74   virtual absl::Status FlipVertically(const FrameBuffer& buffer,
75                                       FrameBuffer* output_buffer) = 0;
76 
77   // Converts `buffer`'s format to the format of the given `output_buffer`.
78   //
79   // The `output_buffer` should have metadata populated and its backing buffer
80   // should be big enough to store the operation result.
81   virtual absl::Status Convert(const FrameBuffer& buffer,
82                                FrameBuffer* output_buffer) = 0;
83 };
84 }  // namespace vision
85 }  // namespace task
86 }  // namespace tflite
87 
88 #endif  // TENSORFLOW_LITE_SUPPORT_CC_TASK_VISION_UTILS_FRAME_BUFFER_UTILS_INTERFACE_H_
89