docs/html/cudaFont_8h_source.html
| | 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
27 #include "cudaUtility.h"
28 #include "imageFormat.h"
29
30 #include <string>
31 #include <vector>
32
33
42 float adaptFontSize( uint32_t dimension );
43
44
50 {
51 public:
56static cudaFont* Create( float size=32.0f );
57
63static cudaFont* Create( const char* font, float size );
64
72static cudaFont* Create( const std::vector<std::string>& fonts, float size );
73
77~cudaFont();
78
82bool OverlayText( void* image, imageFormat format,
83 uint32_t width, uint32_t height,
84const char* str, int x, int y,
85const float4& color=make_float4(0, 0, 0, 255),
86const float4& background=make_float4(0, 0, 0, 0),
87int backgroundPadding=5 );
88
92bool OverlayText( void* image, imageFormat format,
93 uint32_t width, uint32_t height,
94const std::vector< std::pair< std::string, int2 > >& text,
95const float4& color=make_float4(0, 0, 0, 255),
96const float4& background=make_float4(0, 0, 0, 0),
97int backgroundPadding=5 );
98
102template<typename T> bool OverlayText( T* image, uint32_t width, uint32_t height,
103const char* str, int x, int y,
104const float4& color=make_float4(0, 0, 0, 255),
105const float4& background=make_float4(0, 0, 0, 0),
106int backgroundPadding=5 )
107 {
108return OverlayText(image, imageFormatFromType<T>(), width, height, str, x, y, color, background, backgroundPadding);
109 }
110
114template<typename T> bool OverlayText( T* image, uint32_t width, uint32_t height,
115const std::vector< std::pair< std::string, int2 > >& text,
116const float4& color=make_float4(0, 0, 0, 255),
117const float4& background=make_float4(0, 0, 0, 0),
118int backgroundPadding=5 )
119 {
120return OverlayText(image, imageFormatFromType<T>(), width, height, text, color, background, backgroundPadding);
121 }
122
126inline float GetSize() const { return mSize; }
127
131 int4 TextExtents( const char* str, int x=0, int y=0 );
132
133
134 protected:
135cudaFont();
136bool init( const char* font, float size );
137
139
140 uint8_t* mFontMapCPU;
141 uint8_t* mFontMapGPU;
142
143int mFontMapWidth;
144int mFontMapHeight;
145
146void* mCommandCPU;
147void* mCommandGPU;
149
152intmRectIndex;
153
154static const uint32_t MaxCommands = 1024;
155static const uint32_t FirstGlyph = 32;
156static const uint32_t LastGlyph = 255;
157static const uint32_t NumGlyphs = LastGlyph - FirstGlyph;
158
160 {
165
169 } mGlyphInfo[NumGlyphs];
170 };
171
172 #endif
bool OverlayText(T *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.
Definition: cudaFont.h:102
static cudaFont * Create(float size=32.0f)
Create new CUDA font overlay object using baked fonts.
bool OverlayText(T *image, uint32_t width, uint32_t height, const std::vector< std::pair< std::string, int2 > > &text, 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.
Definition: cudaFont.h:114
static const uint32_t FirstGlyph
Definition: cudaFont.h:155
uchar3 color
The RGB color of the point.
Definition: cudaPointCloud.h:11
int mRectIndex
Definition: cudaFont.h:152
~cudaFont()
Destructor.
float GetSize() const
Return the size of the font (height in pixels)
Definition: cudaFont.h:126
void * mCommandCPU
Definition: cudaFont.h:146
bool init(const char *font, float size)
uint16_t width
Definition: cudaFont.h:163
static const uint32_t NumGlyphs
Definition: cudaFont.h:157
Definition: cudaFont.h:159
cudaFont()
int mFontMapHeight
Definition: cudaFont.h:144
static const uint32_t LastGlyph
Definition: cudaFont.h:156
int4 TextExtents(const char *str, int x=0, int y=0)
Return the bounding rectangle of the given text string.
float adaptFontSize(uint32_t dimension)
Determine an appropriate font size given a particular dimension to use (typically an image's width).
float4 * mRectsCPU
Definition: cudaFont.h:150
uint8_t * mFontMapCPU
Definition: cudaFont.h:140
struct cudaFont::GlyphInfo mGlyphInfo[NumGlyphs]
uint8_t * mFontMapGPU
Definition: cudaFont.h:141
uint16_t y
Definition: cudaFont.h:162
uint16_t x
Definition: cudaFont.h:161
float xAdvance
Definition: cudaFont.h:166
float4 * mRectsGPU
Definition: cudaFont.h:151
__host__ __device__ float4 make_float4(float s)
Definition: cudaMath.h:248
TTF font rasterization and image overlay rendering using CUDA.
Definition: cudaFont.h:49
float mSize
Definition: cudaFont.h:138
void * mCommandGPU
Definition: cudaFont.h:147
bool OverlayText(void *image, imageFormat format, 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.
float xOffset
Definition: cudaFont.h:167
uint16_t height
Definition: cudaFont.h:164
float yOffset
Definition: cudaFont.h:168
static const uint32_t MaxCommands
Definition: cudaFont.h:154
int mCmdIndex
Definition: cudaFont.h:148
imageFormat
The imageFormat enum is used to identify the pixel format and colorspace of an image.
Definition: imageFormat.h:49
int mFontMapWidth
Definition: cudaFont.h:143