00001 /* 00002 * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. 00003 * 00004 * Redistribution and use in source and binary forms, with or without 00005 * modification, are permitted provided that the following conditions 00006 * are met: 00007 * 1. Redistributions of source code must retain the above copyright 00008 * notice, this list of conditions and the following disclaimer. 00009 * 2. Redistributions in binary form must reproduce the above copyright 00010 * notice, this list of conditions and the following disclaimer in 00011 * the documentation and/or other materials provided with the 00012 * distribution. 00013 * 3. The names of its contributors may not be used to endorse or promote 00014 * products derived from this software without specific prior written 00015 * permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00018 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00019 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00020 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00021 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00022 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00023 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00024 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00025 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00026 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00027 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00028 */ 00029 00030 00031 /** 00032 * @file nvosd.h 00033 * @brief NVOSD library to be used to draw rectangles and text over the frame 00034 * for given parameters. 00035 */ 00036 00037 #ifndef __NVOSD_DEFS__ 00038 #define __NVOSD_DEFS__ 00039 00040 #ifdef __cplusplus 00041 extern "C" 00042 { 00043 #endif 00044 00045 /** 00046 * Holds the color parameters of the box or text to be overlayed. 00047 */ 00048 typedef struct _NvOSD_ColorParams { 00049 double red; /**< Holds red component of color. 00050 Value should be in the range 0-1. */ 00051 00052 double green; /**< Holds green component of color. 00053 Value should be in the range 0-1.*/ 00054 00055 double blue; /**< Holds blue component of color. 00056 Value should be in the range 0-1.*/ 00057 00058 double alpha; /**< Holds alpha component of color. 00059 Value should be in the range 0-1.*/ 00060 }NvOSD_ColorParams; 00061 00062 00063 /** 00064 * Holds the font parameters of the text to be overlayed. 00065 */ 00066 typedef struct _NvOSD_FontParams { 00067 char * font_name; /**< Holds pointer to the string containing 00068 font name. */ 00069 00070 unsigned int font_size; /**< Holds size of the font. */ 00071 00072 NvOSD_ColorParams font_color; /**< Holds font color. */ 00073 }NvOSD_FontParams; 00074 00075 00076 /** 00077 * Holds the text parameters of the text to be overlayed. 00078 */ 00079 00080 typedef struct _NvOSD_TextParams { 00081 char * display_text; /**< Holds the text to be overlayed. */ 00082 00083 unsigned int x_offset; /**< Holds horizontal offset w.r.t top left pixel of 00084 the frame. */ 00085 unsigned int y_offset; /**< Holds vertical offset w.r.t top left pixel of 00086 the frame. */ 00087 00088 NvOSD_FontParams font_params;/**< font_params. */ 00089 }NvOSD_TextParams; 00090 00091 00092 /** 00093 * Holds the box parameters of the box to be overlayed. 00094 */ 00095 typedef struct _NvOSD_RectParams { 00096 unsigned int left; /**< Holds left coordinate of the box in pixels. */ 00097 00098 unsigned int top; /**< Holds top coordinate of the box in pixels. */ 00099 00100 unsigned int width; /**< Holds width of the box in pixels. */ 00101 00102 unsigned int height; /**< Holds height of the box in pixels. */ 00103 00104 unsigned int border_width; /**< Holds border_width of the box in pixels. */ 00105 00106 NvOSD_ColorParams border_color; /**< Holds color params of the border 00107 of the box. */ 00108 00109 unsigned int has_bg_color; /**< Holds boolean value indicating whether box 00110 has background color. */ 00111 00112 unsigned int reserved; /**< reserved field for future usage. 00113 For internal purpose only */ 00114 00115 NvOSD_ColorParams bg_color; /**< Holds background color of the box. */ 00116 }NvOSD_RectParams; 00117 00118 /** 00119 * List modes used to overlay boxes and text 00120 */ 00121 typedef enum{ 00122 MODE_CPU, /**< Selects CPU for OSD processing. 00123 Works with RGBA data only */ 00124 MODE_GPU, /**< Selects GPU for OSD processing. 00125 Yet to be implemented */ 00126 MODE_HW /**< Selects NV HW engine for rectangle draw and mask. 00127 This mode works with YUV and RGB data both. 00128 It does not consider alpha parameter. 00129 Not applicable for drawing text. */ 00130 } NvOSD_Mode; 00131 00132 /** 00133 * Create nvosd context 00134 * 00135 * @param[in] mode Mode in which nvosd should process the data, 00136 * one of NvOSD_Mode 00137 * @returns A pointer to NvOSD context, NULL in case of failure. 00138 */ 00139 void *nvosd_create_context(void); 00140 00141 /** 00142 * Destroy nvosd context 00143 * 00144 * @param[in] nvosd_ctx A pointer to NvOSD context. 00145 */ 00146 00147 void nvosd_destroy_context(void *nvosd_ctx); 00148 00149 /** 00150 * Set clock parameters for the given context. 00151 * 00152 * The clock is overlayed when nvosd_put_text() is called. 00153 * If no other text is to be overlayed nvosd_put_text should be called with 00154 * @a num_strings as 0 and @a text_params_list as NULL. 00155 * 00156 * @param[in] nvosd_ctx A pointer to NvOSD context 00157 * @param[in] clk_params A pointer to NvOSD_TextParams structure for the clock 00158 * to be overlayed, NULL to disable the clock. 00159 */ 00160 void nvosd_set_clock_params(void *nvosd_ctx, NvOSD_TextParams *clk_params); 00161 00162 00163 /** 00164 * Overlay clock and given text at given location on a buffer. 00165 * 00166 * To overlay the clock user needs to set clock params using 00167 * nvosd_set_clock_params(). 00168 * User should ensure that the length of @a text_params_list should be at least 00169 * @a num_strings. 00170 * 00171 * @note Currently only #MODE_CPU is supported. Specifying other modes wil have 00172 * no effect. 00173 * 00174 * @param[in] nvosd_ctx A pointer to NvOSD context. 00175 * @param[in] mode Mode selection to draw the text. 00176 * @param[in] fd DMABUF FD of buffer on which text is to be overlayed. 00177 * @param[in] num_strings Number of strings to be overlayed. 00178 * @param[in] text_params_list A pointer to an array of NvOSD_TextParams 00179 * structure for the clock and text to be overlayed. 00180 * 00181 * @returns 0 for success, -1 for failure. 00182 */ 00183 int nvosd_put_text(void *nvosd_ctx, NvOSD_Mode mode, int fd, int num_strings, 00184 NvOSD_TextParams *text_params_list); 00185 00186 00187 /** 00188 * Overlay boxes at given location on a buffer. 00189 * 00190 * Boxes can be configured with 00191 * a. only border 00192 * To draw boxes with only border user needs to set @a border_width and set 00193 * @a has_bg_color to 0 for the given box. 00194 * b. border and background color 00195 * To draw boxes with border and background color user needs to set @a 00196 * border_width and set @a has_bg_color to 1 and specify background color 00197 * parameters for the given box. 00198 * c. Solid fill acting as mask region. 00199 * To draw boxes with Solid fill acting as mask region user needs to set @a 00200 * border_width to 0. @a has_bg_color to 1 for the given box. 00201 * 00202 * 00203 * User should ensure that the length of @a rect_params_list should be at least 00204 * @a num_rects. 00205 * 00206 * @param[in] nvosd_ctx A pointer to NvOSD context. 00207 * @param[in] mode Mode selection to draw the boxes. 00208 * @param[in] fd DMABUF FD of buffer on which boxes are to be overlayed. 00209 * @param[in] num_rects Number of boxes to be overlayed. 00210 * @param[in] rect_params_list A pointer to an array of NvOSD_TextParams 00211 * structure for the clock and text to be overlayed. 00212 * 00213 * @returns 0 for success, -1 for failure. 00214 */ 00215 int nvosd_draw_rectangles(void *nvosd_ctx, NvOSD_Mode mode, int fd, 00216 int num_rects, NvOSD_RectParams *rect_params_list); 00217 00218 #ifdef __cplusplus 00219 } 00220 #endif 00221 00222 #endif