Jetson Inference
DNN Vision Library
cudaFont.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef __CUDA_FONT_H__
24 #define __CUDA_FONT_H__
25 
26 #include "cudaUtility.h"
27 
28 #include <string>
29 #include <vector>
30 
31 
40 float adaptFontSize( uint32_t dimension );
41 
42 
47 class cudaFont
48 {
49 public:
54  static cudaFont* Create( float size=32.0f );
55 
61  static cudaFont* Create( const char* font, float size );
62 
70  static cudaFont* Create( const std::vector<std::string>& fonts, float size );
71 
75  ~cudaFont();
76 
80  bool OverlayText( float4* image, uint32_t width, uint32_t height,
81  const char* str, int x, int y,
82  const float4& color=make_float4(0, 0, 0, 255),
83  const float4& background=make_float4(0, 0, 0, 0),
84  int backgroundPadding=5 );
85 
89  bool OverlayText( float4* image, uint32_t width, uint32_t height,
90  const std::vector< std::pair< std::string, int2 > >& text,
91  const float4& color=make_float4(0, 0, 0, 255),
92  const float4& background=make_float4(0, 0, 0, 0),
93  int backgroundPadding=5 );
94 
95 protected:
96  cudaFont();
97  bool init( const char* font, float size );
98 
99  uint8_t* mFontMapCPU;
100  uint8_t* mFontMapGPU;
101 
104 
105  void* mCommandCPU;
106  void* mCommandGPU;
108 
109  float4* mRectsCPU;
110  float4* mRectsGPU;
112 
113  static const uint32_t MaxCommands = 1024;
114  static const uint32_t FirstGlyph = 32;
115  static const uint32_t LastGlyph = 255;
116  static const uint32_t NumGlyphs = LastGlyph - FirstGlyph;
117 
118  struct GlyphInfo
119  {
120  uint16_t x;
121  uint16_t y;
122  uint16_t width;
123  uint16_t height;
124 
125  float xAdvance;
126  float xOffset;
127  float yOffset;
129 };
130 
131 #endif
static const uint32_t LastGlyph
Definition: cudaFont.h:115
uint16_t width
Definition: cudaFont.h:122
float xOffset
Definition: cudaFont.h:126
struct cudaFont::GlyphInfo mGlyphInfo[NumGlyphs]
uint16_t height
Definition: cudaFont.h:123
int mFontMapHeight
Definition: cudaFont.h:103
uint8_t * mFontMapGPU
Definition: cudaFont.h:100
~cudaFont()
Destructor.
float adaptFontSize(uint32_t dimension)
Determine an appropriate font size given a particular dimension to use (typically an image&#39;s width)...
TTF font rasterization and image overlay rendering using CUDA.
Definition: cudaFont.h:47
bool init(const char *font, float size)
static const uint32_t FirstGlyph
Definition: cudaFont.h:114
float xAdvance
Definition: cudaFont.h:125
bool OverlayText(float4 *image, uint32_t width, uint32_t height, const char *str, int x, int y, const float4 &color=make_float4(0, 0, 0, 255), const float4 &background=make_float4(0, 0, 0, 0), int backgroundPadding=5)
Render text overlay onto image.
void * mCommandGPU
Definition: cudaFont.h:106
int mCmdIndex
Definition: cudaFont.h:107
void * mCommandCPU
Definition: cudaFont.h:105
int mRectIndex
Definition: cudaFont.h:111
int mFontMapWidth
Definition: cudaFont.h:102
float yOffset
Definition: cudaFont.h:127
uint8_t * mFontMapCPU
Definition: cudaFont.h:99
static cudaFont * Create(float size=32.0f)
Create new CUDA font overlay object using baked fonts.
uint16_t y
Definition: cudaFont.h:121
uint16_t x
Definition: cudaFont.h:120
Definition: cudaFont.h:118
static const uint32_t MaxCommands
Definition: cudaFont.h:113
static const uint32_t NumGlyphs
Definition: cudaFont.h:116
float4 * mRectsCPU
Definition: cudaFont.h:109
float4 * mRectsGPU
Definition: cudaFont.h:110