xref: /aosp_15_r20/external/libultrahdr/lib/include/ultrahdr/editorhelper.h (revision 89a0ef05262152531a00a15832a2d3b1e3990773)
1 /*
2  * Copyright 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ULTRAHDR_EDITORHELPER_H
18 #define ULTRAHDR_EDITORHELPER_H
19 
20 #include "ultrahdr_api.h"
21 #include "ultrahdr/ultrahdrcommon.h"
22 
23 namespace ultrahdr {
24 
25 /*!\brief uhdr image effect descriptor */
26 typedef struct uhdr_effect_desc {
27   virtual std::string to_string() = 0;
28 
29   virtual ~uhdr_effect_desc() = default;
30 } uhdr_effect_desc_t; /**< alias for struct uhdr_effect_desc */
31 
32 /*!\brief mirror effect descriptor */
33 typedef struct uhdr_mirror_effect : uhdr_effect_desc {
34   uhdr_mirror_effect(uhdr_mirror_direction_t direction);
35 
to_stringuhdr_mirror_effect36   std::string to_string() {
37     return "effect : mirror, metadata : direction - " + ((m_direction == UHDR_MIRROR_HORIZONTAL)
38                                                              ? std::string{"horizontal"}
39                                                              : std::string{"vertical"});
40   }
41 
42   uhdr_mirror_direction_t m_direction;
43 
44   void (*m_mirror_uint8_t)(uint8_t*, uint8_t*, int, int, int, int, uhdr_mirror_direction_t);
45   void (*m_mirror_uint16_t)(uint16_t*, uint16_t*, int, int, int, int, uhdr_mirror_direction_t);
46   void (*m_mirror_uint32_t)(uint32_t*, uint32_t*, int, int, int, int, uhdr_mirror_direction_t);
47   void (*m_mirror_uint64_t)(uint64_t*, uint64_t*, int, int, int, int, uhdr_mirror_direction_t);
48 } uhdr_mirror_effect_t; /**< alias for struct uhdr_mirror_effect */
49 
50 /*!\brief rotate effect descriptor */
51 typedef struct uhdr_rotate_effect : uhdr_effect_desc {
52   uhdr_rotate_effect(int degree);
53 
to_stringuhdr_rotate_effect54   std::string to_string() {
55     return "effect : rotate, metadata : degree - " + std::to_string(m_degree);
56   }
57 
58   int m_degree;
59 
60   void (*m_rotate_uint8_t)(uint8_t*, uint8_t*, int, int, int, int, int);
61   void (*m_rotate_uint16_t)(uint16_t*, uint16_t*, int, int, int, int, int);
62   void (*m_rotate_uint32_t)(uint32_t*, uint32_t*, int, int, int, int, int);
63   void (*m_rotate_uint64_t)(uint64_t*, uint64_t*, int, int, int, int, int);
64 } uhdr_rotate_effect_t; /**< alias for struct uhdr_rotate_effect */
65 
66 /*!\brief crop effect descriptor */
67 typedef struct uhdr_crop_effect : uhdr_effect_desc {
68   uhdr_crop_effect(int left, int right, int top, int bottom);
69 
to_stringuhdr_crop_effect70   std::string to_string() {
71     return "effect : crop, metadata : left, right, top, bottom - " + std::to_string(m_left) + " ," +
72            std::to_string(m_right) + " ," + std::to_string(m_top) + " ," + std::to_string(m_bottom);
73   }
74 
75   int m_left;
76   int m_right;
77   int m_top;
78   int m_bottom;
79 
80   void (*m_crop_uint8_t)(uint8_t*, uint8_t*, int, int, int, int, int, int);
81   void (*m_crop_uint16_t)(uint16_t*, uint16_t*, int, int, int, int, int, int);
82   void (*m_crop_uint32_t)(uint32_t*, uint32_t*, int, int, int, int, int, int);
83   void (*m_crop_uint64_t)(uint64_t*, uint64_t*, int, int, int, int, int, int);
84 } uhdr_crop_effect_t; /**< alias for struct uhdr_crop_effect */
85 
86 /*!\brief resize effect descriptor */
87 typedef struct uhdr_resize_effect : uhdr_effect_desc {
88   uhdr_resize_effect(int width, int height);
89 
to_stringuhdr_resize_effect90   std::string to_string() {
91     return "effect : resize, metadata : dimensions w, h" + std::to_string(m_width) + " ," +
92            std::to_string(m_height);
93   }
94 
95   int m_width;
96   int m_height;
97 
98   void (*m_resize_uint8_t)(uint8_t*, uint8_t*, int, int, int, int, int, int);
99   void (*m_resize_uint16_t)(uint16_t*, uint16_t*, int, int, int, int, int, int);
100   void (*m_resize_uint32_t)(uint32_t*, uint32_t*, int, int, int, int, int, int);
101   void (*m_resize_uint64_t)(uint64_t*, uint64_t*, int, int, int, int, int, int);
102 } uhdr_resize_effect_t; /**< alias for struct uhdr_resize_effect */
103 
104 template <typename T>
105 extern void rotate_buffer_clockwise(T* src_buffer, T* dst_buffer, int src_w, int src_h,
106                                     int src_stride, int dst_stride, int degree);
107 
108 template <typename T>
109 extern void mirror_buffer(T* src_buffer, T* dst_buffer, int src_w, int src_h, int src_stride,
110                           int dst_stride, uhdr_mirror_direction_t direction);
111 
112 template <typename T>
113 extern void resize_buffer(T* src_buffer, T* dst_buffer, int src_w, int src_h, int dst_w, int dst_h,
114                           int src_stride, int dst_stride);
115 
116 std::unique_ptr<uhdr_raw_image_ext_t> resize_image(uhdr_raw_image_t* src, int dst_w, int dst_h);
117 
118 #if (defined(UHDR_ENABLE_INTRINSICS) && (defined(__ARM_NEON__) || defined(__ARM_NEON)))
119 template <typename T>
120 extern void mirror_buffer_neon(T* src_buffer, T* dst_buffer, int src_w, int src_h, int src_stride,
121                                int dst_stride, uhdr_mirror_direction_t direction);
122 
123 template <typename T>
124 extern void rotate_buffer_clockwise_neon(T* src_buffer, T* dst_buffer, int src_w, int src_h,
125                                          int src_stride, int dst_stride, int degrees);
126 #endif
127 
128 #ifdef UHDR_ENABLE_GLES
129 
130 std::unique_ptr<uhdr_raw_image_ext_t> apply_resize_gles(uhdr_raw_image_t* src, int dst_w, int dst_h,
131                                                         uhdr_opengl_ctxt* gl_ctxt,
132                                                         GLuint* srcTexture);
133 
134 std::unique_ptr<uhdr_raw_image_ext_t> apply_mirror_gles(ultrahdr::uhdr_mirror_effect_t* desc,
135                                                         uhdr_raw_image_t* src,
136                                                         uhdr_opengl_ctxt* gl_ctxt,
137                                                         GLuint* srcTexture);
138 
139 std::unique_ptr<uhdr_raw_image_ext_t> apply_rotate_gles(ultrahdr::uhdr_rotate_effect_t* desc,
140                                                         uhdr_raw_image_t* src,
141                                                         uhdr_opengl_ctxt* gl_ctxt,
142                                                         GLuint* srcTexture);
143 
144 std::unique_ptr<uhdr_raw_image_ext_t> apply_crop_gles(uhdr_raw_image_t* src, int left, int top,
145                                                       int wd, int ht, uhdr_opengl_ctxt* gl_ctxt,
146                                                       GLuint* srcTexture);
147 #endif
148 
149 std::unique_ptr<uhdr_raw_image_ext_t> apply_rotate(ultrahdr::uhdr_rotate_effect_t* desc,
150                                                    uhdr_raw_image_t* src, void* gl_ctxt = nullptr,
151                                                    void* texture = nullptr);
152 
153 std::unique_ptr<uhdr_raw_image_ext_t> apply_mirror(ultrahdr::uhdr_mirror_effect_t* desc,
154                                                    uhdr_raw_image_t* src, void* gl_ctxt = nullptr,
155                                                    void* texture = nullptr);
156 
157 std::unique_ptr<uhdr_raw_image_ext_t> apply_resize(ultrahdr::uhdr_resize_effect_t* desc,
158                                                    uhdr_raw_image* src, int dst_w, int dst_h,
159                                                    void* gl_ctxt = nullptr,
160                                                    void* texture = nullptr);
161 
162 std::unique_ptr<uhdr_raw_image_ext_t> apply_crop(ultrahdr::uhdr_crop_effect_t* desc,
163                                                  uhdr_raw_image_t* src, int left, int top, int wd,
164                                                  int ht, void* gl_ctxt = nullptr,
165                                                  void* texture = nullptr);
166 
167 }  // namespace ultrahdr
168 
169 #endif  // ULTRAHDR_EDITORHELPER_H
170