1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
| void FastWatermark::Nv12AddDateWatermark(unsigned char* nv12Buf, int width, int height, const char *text){
unsigned int picSize = width * height * 3 / 2;
int x = m_x_pos;
for (const char* p = text; *p; p++) {
// if (FT_Load_Char(face, *p, FT_LOAD_RENDER)) {
// mylog(E, "Failed to load glyph %c", *p);
// continue;
// }
// FT_GlyphSlot slot = face->glyph;
auto it = glyphCache.find(*p);
if (it == glyphCache.end()) {
mylog(E, "Glyph not found in cache: %c", *p);
assert(false);
continue;
}
const CachedGlyph& glyph = it->second;
int y_pos = m_y_pos - glyph.bitmap_top;
for (int i = 0; i < glyph.height; i++) {
for (int j = 0; j < glyph.width; j++) {
uint8_t alpha = glyph.bitmap[i * glyph.pitch + j];
if (alpha > 0) {
uint32_t index = (y_pos + i) * width + x + j;
if (index >= picSize) continue; // 边界检查
float alpha_ratio = alpha / 255.0f;
nv12Buf[index] = static_cast<uint8_t>(
(1.0f - alpha_ratio) * nv12Buf[index] + alpha_ratio * 255
);
}
}
}
x += glyph.advance;
}
}
|