|
| 1 | +/* |
| 2 | + * SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +#ifndef CUOSD_H |
| 19 | +#define CUOSD_H |
| 20 | + |
| 21 | +typedef struct |
| 22 | +{ |
| 23 | +} cuOSDContext; |
| 24 | + |
| 25 | +typedef cuOSDContext *cuOSDContext_t; |
| 26 | + |
| 27 | +enum class cuOSDClockFormat : int |
| 28 | +{ |
| 29 | + None = 0, |
| 30 | + YYMMDD_HHMMSS = 1, |
| 31 | + YYMMDD = 2, |
| 32 | + HHMMSS = 3 |
| 33 | +}; |
| 34 | + |
| 35 | +enum class cuOSDImageFormat : int |
| 36 | +{ |
| 37 | + None = 0, |
| 38 | + RGB = 1, |
| 39 | + RGBA = 2, |
| 40 | + BlockLinearNV12 = 3, |
| 41 | + PitchLinearNV12 = 4 |
| 42 | +}; |
| 43 | + |
| 44 | +enum class cuOSDTextBackend : int |
| 45 | +{ |
| 46 | + None = 0, |
| 47 | + PangoCairo = 1, |
| 48 | + StbTrueType = 2 |
| 49 | +}; |
| 50 | + |
| 51 | +typedef struct _cuOSDColor |
| 52 | +{ |
| 53 | + unsigned char r; |
| 54 | + unsigned char g; |
| 55 | + unsigned char b; |
| 56 | + unsigned char a; |
| 57 | +} cuOSDColor; |
| 58 | + |
| 59 | +// cuosd_context_create: support online generate text bitmap with required font. |
| 60 | +cuOSDContext_t cuosd_context_create(); |
| 61 | + |
| 62 | +// set context text rendering backend |
| 63 | +void cuosd_set_text_backend(cuOSDContext_t context, cuOSDTextBackend text_backend); |
| 64 | + |
| 65 | +// cuosd_context_destroy: deallocate all resource related to allocated cuOSD context |
| 66 | +void cuosd_context_destroy(cuOSDContext_t context); |
| 67 | + |
| 68 | +// cuosd_measure_text: API to get tight width, height and upper offset from the given text's tight bounding box |
| 69 | +void cuosd_measure_text(cuOSDContext_t context, const char *utf8_text, int font_size, const char *font, int *width, |
| 70 | + int *height, int *yoffset); |
| 71 | + |
| 72 | +// cuosd_draw_text: draw utf8 text on given cuOSD context. |
| 73 | +// x, y stands for left upper corner of the text's bounding box. |
| 74 | +// bg_color stands for textbox background color in case alpha != 0 |
| 75 | +// Draw nothing if font_size <=0, font_size is scaled by 3 and clamped to 10 - 500 pixels by default |
| 76 | +void cuosd_draw_text(cuOSDContext_t context, const char *utf8_text, int font_size, const char *font, int x, int y, |
| 77 | + cuOSDColor border_color, cuOSDColor bg_color = {0, 0, 0, 0}); |
| 78 | + |
| 79 | +// cuosd_draw_clock: draw clock element on given cuOSD context. |
| 80 | +// x, y stands for left upper corner of the text's bounding box. 3 clock formats are supported: |
| 81 | +// YYMMDD_HHMMSS, YYMMDD, HHMMSS |
| 82 | +// Draw nothing if font_size <=0, font_size is scaled by 3 and clamped to 10 - 500 pixels by default |
| 83 | +void cuosd_draw_clock(cuOSDContext_t context, cuOSDClockFormat format, long time, int font_size, const char *font, |
| 84 | + int x, int y, cuOSDColor border_color, cuOSDColor bg_color = {0, 0, 0, 0}); |
| 85 | + |
| 86 | +// cuosd_draw_line: draw line element on given cuOSD context. |
| 87 | +// x0, y0 stands for start point coordinate of the line, and x1, y1 stands for end point coordinate of the line. |
| 88 | +void cuosd_draw_line(cuOSDContext_t context, int x0, int y0, int x1, int y1, int thickness, cuOSDColor color, |
| 89 | + bool interpolation = true); |
| 90 | + |
| 91 | +// cuosd_draw_arrow: draw arrow element on given cuOSD context. |
| 92 | +// x0, y0 stands for start point coordinate of the arrow, and x1, y1 stands for end point coordinate of the arrow. |
| 93 | +void cuosd_draw_arrow(cuOSDContext_t context, int x0, int y0, int x1, int y1, int arrow_size, int thickness, |
| 94 | + cuOSDColor color, bool interpolation = false); |
| 95 | + |
| 96 | +// cuosd_draw_point: draw point element on given cuOSD context. |
| 97 | +// cx, cy stands for center point coordinate of the point. |
| 98 | +void cuosd_draw_point(cuOSDContext_t context, int cx, int cy, int radius, cuOSDColor color); |
| 99 | + |
| 100 | +// cuosd_draw_circle: draw circle element on given cuOSD context. |
| 101 | +// cx, cy stands for center point coordinate of the circle. |
| 102 | +// thickness stands for border width when thickness > 0; stands for filled mode when thickness = -1. |
| 103 | +// bg_color stands for inner color inside hollow circle in case alpha != 0 |
| 104 | +void cuosd_draw_circle(cuOSDContext_t context, int cx, int cy, int radius, int thickness, cuOSDColor border_color, |
| 105 | + cuOSDColor bg_color = {0, 0, 0, 0}); |
| 106 | + |
| 107 | +// cuosd_draw_rectangle: draw rectangle element on given cuOSD context. |
| 108 | +// thickness stands for border width when thickness > 0; stands for filled mode when thickness = -1. |
| 109 | +// bg_color stands for inner color inside hollow rectangle in case alpha != 0 |
| 110 | +void cuosd_draw_rectangle(cuOSDContext_t context, int left, int top, int right, int bottom, int thickness, |
| 111 | + cuOSDColor border_color, cuOSDColor bg_color = {0, 0, 0, 0}); |
| 112 | + |
| 113 | +// cuosd_draw_boxblur: Mean filtering in the region of interest |
| 114 | +// The region of interest is first scaled to 32x32, filtered, and then scaled to the region of interest by nearest neighbor interpolation |
| 115 | +// It is executed by a separate kernel function that is independent from the other drawing functions |
| 116 | +void cuosd_draw_boxblur(cuOSDContext_t context, int left, int top, int right, int bottom, int kernel_size = 7); |
| 117 | + |
| 118 | +// cuosd_draw_rotationbox: draw rotated rectangle element on given cuOSD context. |
| 119 | +// yaw: rotation angle from y-axis, clockwise +, unit in rad. |
| 120 | +void cuosd_draw_rotationbox(cuOSDContext_t _context, int cx, int cy, int width, int height, float yaw, int thickness, |
| 121 | + cuOSDColor border_color, bool interpolation = false, cuOSDColor bg_color = {0, 0, 0, 0}); |
| 122 | + |
| 123 | +// cuosd_draw_segmentmask: draw segmentation mask on given cuOSD context. |
| 124 | +// d_seg: device pointer of segmentation mask, alpha in seg_color is ignored. |
| 125 | +// thickness should > 0 for drawing border, threshold: Threshold for binarization |
| 126 | +// 1. resize mask rect to object rect of given left, top, right, bottom. |
| 127 | +// 2. set the alpha to 127 if mask value > threshold, else alpha = 0. |
| 128 | +void cuosd_draw_segmentmask(cuOSDContext_t context, int left, int top, int right, int bottom, int thickness, |
| 129 | + float *d_seg, int seg_width, int seg_height, float seg_threshold, cuOSDColor border_color, |
| 130 | + cuOSDColor seg_color = {0, 0, 0, 0}); |
| 131 | + |
| 132 | +// cuosd_draw_rgba_source: draw color from rgba source image on given cuOSD context. |
| 133 | +// cx, cy stands for center point coordinate of the incoming rgba source image. |
| 134 | +void cuosd_draw_rgba_source(cuOSDContext_t context, void *d_src, int cx, int cy, int w, int h); |
| 135 | + |
| 136 | +// cuosd_draw_nv12_source: draw color from nv12 source image on given cuOSD context. |
| 137 | +// cx, cy stands for center point coordinate of the incoming nv12 source image. |
| 138 | +// mask_color: pixel with mask Y-U-V to be considered as transparent, and apply uniform mask A for none-transparent pixels |
| 139 | +void cuosd_draw_nv12_source(cuOSDContext_t context, void *d_src0, void *d_src1, int cx, int cy, int w, int h, |
| 140 | + cuOSDColor mask_color, bool block_linear = false); |
| 141 | + |
| 142 | +// cuosd_apply: calculate bounding box of all elements and transfer drawing commands to GPU. |
| 143 | +// If format is RGBA, data0 is RGBA buffer, and data1 must be nullptr. |
| 144 | +// If format is BlockLinearNV12, data0 and data1 is cudaSurfaceObject_t for Luma(Y) plane and Chroma(UV) plane |
| 145 | +// If format is PitchLinearNV12, data0 is Luma(Y) plane buffer, and data1 is Chroma(UV) plane buffer |
| 146 | +void cuosd_apply(cuOSDContext_t context, void *data0, void *data1, int width, int stride, int height, |
| 147 | + cuOSDImageFormat format, void *stream = nullptr, bool launch_and_clear = true); |
| 148 | + |
| 149 | +// clear all pushed commands |
| 150 | +void cuosd_clear(cuOSDContext_t context); |
| 151 | + |
| 152 | +// cuosd_launch: launch drawing kernel in async manner. |
| 153 | +// If format is RGBA, data0 is RGBA buffer, and data1 must be nullptr. |
| 154 | +// If format is BlockLinearNV12, data0 and data1 is cudaSurfaceObject_t for Luma(Y) plane and Chroma(UV) plane |
| 155 | +// If format is PitchLinearNV12, data0 is Luma(Y) plane buffer, and data1 is Chroma(UV) plane buffer |
| 156 | +void cuosd_launch(cuOSDContext_t context, void *data0, void *data1, int width, int stride, int height, |
| 157 | + cuOSDImageFormat format, void *stream = nullptr); |
| 158 | + |
| 159 | +#endif // CUOSD_H |
0 commit comments