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 // todo: move this to ultrahdr_api.h 24 /*!\brief List of supported mirror directions */ 25 typedef enum uhdr_mirror_direction { 26 UHDR_MIRROR_VERTICAL, /**< flip image over x axis */ 27 UHDR_MIRROR_HORIZONTAL, /**< flip image over y axis */ 28 } uhdr_mirror_direction_t; /**< alias for enum uhdr_mirror_direction */ 29 30 namespace ultrahdr { 31 32 /*!\brief uhdr image effect descriptor */ 33 typedef struct uhdr_effect_desc { 34 virtual std::string to_string() = 0; 35 36 virtual ~uhdr_effect_desc() = default; 37 } uhdr_effect_desc_t; /**< alias for struct uhdr_effect_desc */ 38 39 /*!\brief mirror effect descriptor */ 40 typedef struct uhdr_mirror_effect : uhdr_effect_desc { 41 uhdr_mirror_effect(uhdr_mirror_direction_t direction); 42 to_stringuhdr_mirror_effect43 std::string to_string() { 44 return "effect : mirror, metadata : direction - " + ((m_direction == UHDR_MIRROR_HORIZONTAL) 45 ? std::string{"horizontal"} 46 : std::string{"vertical"}); 47 } 48 49 uhdr_mirror_direction_t m_direction; 50 51 void (*m_mirror_uint8_t)(uint8_t*, uint8_t*, int, int, int, int, uhdr_mirror_direction_t); 52 void (*m_mirror_uint16_t)(uint16_t*, uint16_t*, int, int, int, int, uhdr_mirror_direction_t); 53 void (*m_mirror_uint32_t)(uint32_t*, uint32_t*, int, int, int, int, uhdr_mirror_direction_t); 54 void (*m_mirror_uint64_t)(uint64_t*, uint64_t*, int, int, int, int, uhdr_mirror_direction_t); 55 } uhdr_mirror_effect_t; /**< alias for struct uhdr_mirror_effect */ 56 57 /*!\brief rotate effect descriptor */ 58 typedef struct uhdr_rotate_effect : uhdr_effect_desc { 59 uhdr_rotate_effect(int degree); 60 to_stringuhdr_rotate_effect61 std::string to_string() { 62 return "effect : rotate, metadata : degree - " + std::to_string(m_degree); 63 } 64 65 int m_degree; 66 67 void (*m_rotate_uint8_t)(uint8_t*, uint8_t*, int, int, int, int, int); 68 void (*m_rotate_uint16_t)(uint16_t*, uint16_t*, int, int, int, int, int); 69 void (*m_rotate_uint32_t)(uint32_t*, uint32_t*, int, int, int, int, int); 70 void (*m_rotate_uint64_t)(uint64_t*, uint64_t*, int, int, int, int, int); 71 } uhdr_rotate_effect_t; /**< alias for struct uhdr_rotate_effect */ 72 73 /*!\brief crop effect descriptor */ 74 typedef struct uhdr_crop_effect : uhdr_effect_desc { uhdr_crop_effectuhdr_crop_effect75 uhdr_crop_effect(int left, int right, int top, int bottom) 76 : m_left{left}, m_right{right}, m_top{top}, m_bottom{bottom} {} 77 to_stringuhdr_crop_effect78 std::string to_string() { 79 return "effect : crop, metadata : left, right, top, bottom - " + std::to_string(m_left) + " ," + 80 std::to_string(m_right) + " ," + std::to_string(m_top) + " ," + std::to_string(m_bottom); 81 } 82 83 int m_left; 84 int m_right; 85 int m_top; 86 int m_bottom; 87 } uhdr_crop_effect_t; /**< alias for struct uhdr_crop_effect */ 88 89 /*!\brief resize effect descriptor */ 90 typedef struct uhdr_resize_effect : uhdr_effect_desc { 91 uhdr_resize_effect(int width, int height); 92 to_stringuhdr_resize_effect93 std::string to_string() { 94 return "effect : resize, metadata : dimensions w, h" + std::to_string(m_width) + " ," + 95 std::to_string(m_height); 96 } 97 98 int m_width; 99 int m_height; 100 101 void (*m_resize_uint8_t)(uint8_t*, uint8_t*, int, int, int, int, int, int); 102 void (*m_resize_uint16_t)(uint16_t*, uint16_t*, int, int, int, int, int, int); 103 void (*m_resize_uint32_t)(uint32_t*, uint32_t*, int, int, int, int, int, int); 104 void (*m_resize_uint64_t)(uint64_t*, uint64_t*, int, int, int, int, int, int); 105 } uhdr_resize_effect_t; /**< alias for struct uhdr_resize_effect */ 106 107 template <typename T> 108 extern void rotate_buffer_clockwise(T* src_buffer, T* dst_buffer, int src_w, int src_h, 109 int src_stride, int dst_stride, int degree); 110 111 template <typename T> 112 extern void mirror_buffer(T* src_buffer, T* dst_buffer, int src_w, int src_h, int src_stride, 113 int dst_stride, uhdr_mirror_direction_t direction); 114 115 template <typename T> 116 extern void resize_buffer(T* src_buffer, T* dst_buffer, int src_w, int src_h, int dst_w, int dst_h, 117 int src_stride, int dst_stride); 118 119 #if (defined(UHDR_ENABLE_INTRINSICS) && (defined(__ARM_NEON__) || defined(__ARM_NEON))) 120 template <typename T> 121 extern void mirror_buffer_neon(T* src_buffer, T* dst_buffer, int src_w, int src_h, int src_stride, 122 int dst_stride, uhdr_mirror_direction_t direction); 123 124 template <typename T> 125 extern void rotate_buffer_clockwise_neon(T* src_buffer, T* dst_buffer, int src_w, int src_h, 126 int src_stride, int dst_stride, int degrees); 127 #endif 128 129 std::unique_ptr<uhdr_raw_image_ext_t> apply_rotate(ultrahdr::uhdr_rotate_effect_t* desc, 130 uhdr_raw_image_t* src); 131 132 std::unique_ptr<uhdr_raw_image_ext_t> apply_mirror(ultrahdr::uhdr_mirror_effect_t* desc, 133 uhdr_raw_image_t* src); 134 135 std::unique_ptr<uhdr_raw_image_ext_t> apply_resize(ultrahdr::uhdr_resize_effect_t* desc, 136 uhdr_raw_image* src, int dst_w, int dst_h); 137 138 void apply_crop(uhdr_raw_image_t* src, int left, int top, int wd, int ht); 139 140 } // namespace ultrahdr 141 142 #endif // ULTRAHDR_EDITORHELPER_H 143