Back to Jetson Inference

Jetson Inference: jetson

docs/html/cudaFont_8h_source.html

latest15.6 KB
Original Source

| | 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

49 class cudaFont

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

138float mSize;

139

140 uint8_t* mFontMapCPU;

141 uint8_t* mFontMapGPU;

142

143int mFontMapWidth;

144int mFontMapHeight;

145

146void* mCommandCPU;

147void* mCommandGPU;

148intmCmdIndex;

149

150 float4* mRectsCPU;

151 float4* mRectsGPU;

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

159struct GlyphInfo

160 {

161 uint16_t x;

162 uint16_t y;

163 uint16_t width;

164 uint16_t height;

165

166float xAdvance;

167float xOffset;

168float yOffset;

169 } mGlyphInfo[NumGlyphs];

170 };

171

172 #endif

cudaFont::OverlayText

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

cudaFont::Create

static cudaFont * Create(float size=32.0f)

Create new CUDA font overlay object using baked fonts.

cudaFont::OverlayText

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

cudaFont::FirstGlyph

static const uint32_t FirstGlyph

Definition: cudaFont.h:155

cudaUtility.h

color

uchar3 color

The RGB color of the point.

Definition: cudaPointCloud.h:11

cudaFont::mRectIndex

int mRectIndex

Definition: cudaFont.h:152

cudaFont::~cudaFont

~cudaFont()

Destructor.

cudaFont::GetSize

float GetSize() const

Return the size of the font (height in pixels)

Definition: cudaFont.h:126

cudaFont::mCommandCPU

void * mCommandCPU

Definition: cudaFont.h:146

cudaFont::init

bool init(const char *font, float size)

cudaFont::GlyphInfo::width

uint16_t width

Definition: cudaFont.h:163

cudaFont::NumGlyphs

static const uint32_t NumGlyphs

Definition: cudaFont.h:157

cudaFont::GlyphInfo

Definition: cudaFont.h:159

cudaFont::cudaFont

cudaFont()

cudaFont::mFontMapHeight

int mFontMapHeight

Definition: cudaFont.h:144

cudaFont::LastGlyph

static const uint32_t LastGlyph

Definition: cudaFont.h:156

cudaFont::TextExtents

int4 TextExtents(const char *str, int x=0, int y=0)

Return the bounding rectangle of the given text string.

adaptFontSize

float adaptFontSize(uint32_t dimension)

Determine an appropriate font size given a particular dimension to use (typically an image's width).

cudaFont::mRectsCPU

float4 * mRectsCPU

Definition: cudaFont.h:150

cudaFont::mFontMapCPU

uint8_t * mFontMapCPU

Definition: cudaFont.h:140

cudaFont::mGlyphInfo

struct cudaFont::GlyphInfo mGlyphInfo[NumGlyphs]

cudaFont::mFontMapGPU

uint8_t * mFontMapGPU

Definition: cudaFont.h:141

cudaFont::GlyphInfo::y

uint16_t y

Definition: cudaFont.h:162

cudaFont::GlyphInfo::x

uint16_t x

Definition: cudaFont.h:161

cudaFont::GlyphInfo::xAdvance

float xAdvance

Definition: cudaFont.h:166

cudaFont::mRectsGPU

float4 * mRectsGPU

Definition: cudaFont.h:151

make_float4

__host__ __device__ float4 make_float4(float s)

Definition: cudaMath.h:248

cudaFont

TTF font rasterization and image overlay rendering using CUDA.

Definition: cudaFont.h:49

cudaFont::mSize

float mSize

Definition: cudaFont.h:138

cudaFont::mCommandGPU

void * mCommandGPU

Definition: cudaFont.h:147

cudaFont::OverlayText

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.

cudaFont::GlyphInfo::xOffset

float xOffset

Definition: cudaFont.h:167

cudaFont::GlyphInfo::height

uint16_t height

Definition: cudaFont.h:164

cudaFont::GlyphInfo::yOffset

float yOffset

Definition: cudaFont.h:168

cudaFont::MaxCommands

static const uint32_t MaxCommands

Definition: cudaFont.h:154

cudaFont::mCmdIndex

int mCmdIndex

Definition: cudaFont.h:148

imageFormat.h

imageFormat

imageFormat

The imageFormat enum is used to identify the pixel format and colorspace of an image.

Definition: imageFormat.h:49

cudaFont::mFontMapWidth

int mFontMapWidth

Definition: cudaFont.h:143