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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
#include "glyph.hpp"
#include "glyph_cache.hpp"
#include "agg_traits.hpp"
#include "opengl/data_traits.hpp"
namespace graphics
{
Glyph::Info::Info()
: Resource::Info(Resource::EGlyph)
{}
Glyph::Info::Info(GlyphKey const & key,
GlyphCache * cache)
: Resource::Info(Resource::EGlyph),
m_key(key),
m_cache(cache)
{
m_metrics = m_cache->getGlyphMetrics(m_key);
}
Resource::Info const & Glyph::Info::cacheKey() const
{
return *this;
}
m2::PointU const Glyph::Info::resourceSize() const
{
return m2::PointU(m_metrics.m_width + 4,
m_metrics.m_height + 4);
}
Resource * Glyph::Info::createResource(m2::RectU const & texRect,
uint8_t pipelineID) const
{
return new Glyph(*this,
texRect,
pipelineID);
}
bool Glyph::Info::lessThan(Resource::Info const * r) const
{
if (m_category != r->m_category)
return m_category < r->m_category;
Glyph::Info const * ri = static_cast<Glyph::Info const *>(r);
if (m_key != ri->m_key)
return m_key < ri->m_key;
return false;
}
Glyph::Glyph(Info const & info,
m2::RectU const & texRect,
int pipelineID)
: Resource(EGlyph,
texRect,
pipelineID),
m_info(info)
{
m_bitmap = m_info.m_cache->getGlyphBitmap(m_info.m_key);
}
void Glyph::render(void * dst)
{
m2::RectU const & rect = m_texRect;
DATA_TRAITS::view_t v = gil::interleaved_view(
rect.SizeX(), rect.SizeY(),
(DATA_TRAITS::pixel_t*)dst,
sizeof(DATA_TRAITS::pixel_t) * rect.SizeX()
);
DATA_TRAITS::pixel_t pxTranslucent;
gil::get_color(pxTranslucent, gil::red_t()) = m_info.m_key.m_color.r / DATA_TRAITS::channelScaleFactor;
gil::get_color(pxTranslucent, gil::green_t()) = m_info.m_key.m_color.g / DATA_TRAITS::channelScaleFactor;
gil::get_color(pxTranslucent, gil::blue_t()) = m_info.m_key.m_color.b / DATA_TRAITS::channelScaleFactor;
gil::get_color(pxTranslucent, gil::alpha_t()) = 0;
for (size_t y = 0; y < 2; ++y)
for (size_t x = 0; x < rect.SizeX(); ++x)
v(x, y) = pxTranslucent;
for (size_t y = rect.SizeY() - 2; y < rect.SizeY(); ++y)
for (size_t x = 0; x < rect.SizeX(); ++x)
v(x, y) = pxTranslucent;
for (size_t y = 2; y < rect.SizeY() - 2; ++y)
{
v(0, y) = pxTranslucent;
v(1, y) = pxTranslucent;
v(rect.SizeX() - 2, y) = pxTranslucent;
v(rect.SizeX() - 1, y) = pxTranslucent;
}
if ((m_info.m_metrics.m_width != 0)
&& (m_info.m_metrics.m_height != 0))
{
gil::gray8c_view_t srcView = gil::interleaved_view(
m_info.m_metrics.m_width,
m_info.m_metrics.m_height,
(gil::gray8_pixel_t*)&m_bitmap->m_data[0],
m_bitmap->m_pitch
);
DATA_TRAITS::pixel_t c;
gil::get_color(c, gil::red_t()) = m_info.m_key.m_color.r / DATA_TRAITS::channelScaleFactor;
gil::get_color(c, gil::green_t()) = m_info.m_key.m_color.g / DATA_TRAITS::channelScaleFactor;
gil::get_color(c, gil::blue_t()) = m_info.m_key.m_color.b / DATA_TRAITS::channelScaleFactor;
gil::get_color(c, gil::alpha_t()) = m_info.m_key.m_color.a / DATA_TRAITS::channelScaleFactor;
for (size_t y = 2; y < rect.SizeY() - 2; ++y)
for (size_t x = 2; x < rect.SizeX() - 2; ++x)
{
gil::get_color(c, gil::alpha_t()) = srcView(x - 2, y - 2) / DATA_TRAITS::channelScaleFactor;
v(x, y) = c;
}
}
}
Resource::Info const * Glyph::info() const
{
return &m_info;
}
}
|