Skip to content

Commit ddf96c7

Browse files
committedApr 1, 2015
Fix some minor details from 6d61375
1 parent 6d61375 commit ddf96c7

File tree

4 files changed

+37
-30
lines changed

4 files changed

+37
-30
lines changed
 

Diff for: ‎minetest.conf.example

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@
177177
# pixels when scaling down, at the cost of blurring some
178178
# edge pixels when images are scaled by non-integer sizes.
179179
#gui_scaling_filter = false
180-
# When gui_scaling_filter = true, all GUI images need to be
180+
# When gui_scaling_filter is true, all GUI images need to be
181181
# filtered in software, but some images are generated directly
182-
# to hardare (e.g. render-to-texture for nodes in inventory).
182+
# to hardware (e.g. render-to-texture for nodes in inventory).
183183
# When gui_scaling_filter_txr2img is true, copy those images
184184
# from hardware to software for scaling. When false, fall back
185185
# to the old scaling method, for video drivers that don't

Diff for: ‎src/guiFormSpecMenu.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -1308,8 +1308,10 @@ void GUIFormSpecMenu::parseImageButton(parserData* data,std::string element,
13081308
}
13091309

13101310
e->setUseAlphaChannel(true);
1311-
e->setImage(guiScalingImageButton(Environment->getVideoDriver(), texture, geom.X, geom.Y));
1312-
e->setPressedImage(guiScalingImageButton(Environment->getVideoDriver(), pressed_texture, geom.X, geom.Y));
1311+
e->setImage(guiScalingImageButton(
1312+
Environment->getVideoDriver(), texture, geom.X, geom.Y));
1313+
e->setPressedImage(guiScalingImageButton(
1314+
Environment->getVideoDriver(), pressed_texture, geom.X, geom.Y));
13131315
e->setScaleImage(true);
13141316
e->setNotClipped(noclip);
13151317
e->setDrawBorder(drawborder);

Diff for: ‎src/guiscalingfilter.cpp

+27-22
Original file line numberDiff line numberDiff line change
@@ -28,54 +28,58 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2828
* converting textures back into images repeatedly, and some don't even
2929
* allow it at all.
3030
*/
31-
std::map<io::path, video::IImage *> imgCache;
31+
std::map<io::path, video::IImage *> g_imgCache;
3232

3333
/* Maintain a static cache of all pre-scaled textures. These need to be
3434
* cleared as well when the cached images.
3535
*/
36-
std::map<io::path, video::ITexture *> txrCache;
36+
std::map<io::path, video::ITexture *> g_txrCache;
3737

3838
/* Manually insert an image into the cache, useful to avoid texture-to-image
3939
* conversion whenever we can intercept it.
4040
*/
41-
void guiScalingCache(io::path key, video::IVideoDriver *driver, video::IImage *value) {
41+
void guiScalingCache(io::path key, video::IVideoDriver *driver, video::IImage *value)
42+
{
4243
if (!g_settings->getBool("gui_scaling_filter"))
4344
return;
4445
video::IImage *copied = driver->createImage(value->getColorFormat(),
4546
value->getDimension());
4647
value->copyTo(copied);
47-
imgCache[key] = copied;
48+
g_imgCache[key] = copied;
4849
}
4950

5051
// Manually clear the cache, e.g. when switching to different worlds.
51-
void guiScalingCacheClear(video::IVideoDriver *driver) {
52-
for (std::map<io::path, video::IImage *>::iterator it = imgCache.begin();
53-
it != imgCache.end(); it++) {
52+
void guiScalingCacheClear(video::IVideoDriver *driver)
53+
{
54+
for (std::map<io::path, video::IImage *>::iterator it = g_imgCache.begin();
55+
it != g_imgCache.end(); it++) {
5456
if (it->second != NULL)
5557
it->second->drop();
5658
}
57-
imgCache.clear();
58-
for (std::map<io::path, video::ITexture *>::iterator it = txrCache.begin();
59-
it != txrCache.end(); it++) {
59+
g_imgCache.clear();
60+
for (std::map<io::path, video::ITexture *>::iterator it = g_txrCache.begin();
61+
it != g_txrCache.end(); it++) {
6062
if (it->second != NULL)
6163
driver->removeTexture(it->second);
6264
}
63-
txrCache.clear();
65+
g_txrCache.clear();
6466
}
6567

6668
/* Get a cached, high-quality pre-scaled texture for display purposes. If the
6769
* texture is not already cached, attempt to create it. Returns a pre-scaled texture,
6870
* or the original texture if unable to pre-scale it.
6971
*/
70-
video::ITexture *guiScalingResizeCached(video::IVideoDriver *driver, video::ITexture *src,
71-
const core::rect<s32> &srcrect, const core::rect<s32> &destrect) {
72+
video::ITexture *guiScalingResizeCached(video::IVideoDriver *driver,
73+
video::ITexture *src, const core::rect<s32> &srcrect,
74+
const core::rect<s32> &destrect)
75+
{
7276

7377
if (!g_settings->getBool("gui_scaling_filter"))
7478
return src;
7579

7680
// Calculate scaled texture name.
7781
char rectstr[200];
78-
sprintf(rectstr, "%d:%d:%d:%d:%d:%d",
82+
snprintf(rectstr, sizeof(rectstr), "%d:%d:%d:%d:%d:%d",
7983
srcrect.UpperLeftCorner.X,
8084
srcrect.UpperLeftCorner.Y,
8185
srcrect.getWidth(),
@@ -86,20 +90,20 @@ video::ITexture *guiScalingResizeCached(video::IVideoDriver *driver, video::ITex
8690
io::path scalename = origname + "@guiScalingFilter:" + rectstr;
8791

8892
// Search for existing scaled texture.
89-
video::ITexture *scaled = txrCache[scalename];
93+
video::ITexture *scaled = g_txrCache[scalename];
9094
if (scaled)
9195
return scaled;
9296

9397
// Try to find the texture converted to an image in the cache.
9498
// If the image was not found, try to extract it from the texture.
95-
video::IImage* srcimg = imgCache[origname];
99+
video::IImage* srcimg = g_imgCache[origname];
96100
if (srcimg == NULL) {
97101
if (!g_settings->getBool("gui_scaling_filter_txr2img"))
98102
return src;
99103
srcimg = driver->createImageFromData(src->getColorFormat(),
100104
src->getSize(), src->lock(), false);
101105
src->unlock();
102-
imgCache[origname] = srcimg;
106+
g_imgCache[origname] = srcimg;
103107
}
104108

105109
// Create a new destination image and scale the source into it.
@@ -125,16 +129,17 @@ video::ITexture *guiScalingResizeCached(video::IVideoDriver *driver, video::ITex
125129
// Convert the scaled image back into a texture.
126130
scaled = driver->addTexture(scalename, destimg, NULL);
127131
destimg->drop();
128-
txrCache[scalename] = scaled;
132+
g_txrCache[scalename] = scaled;
129133

130134
return scaled;
131135
}
132136

133137
/* Convenience wrapper for guiScalingResizeCached that accepts parameters that
134138
* are available at GUI imagebutton creation time.
135139
*/
136-
video::ITexture *guiScalingImageButton(video::IVideoDriver *driver, video::ITexture *src,
137-
s32 width, s32 height) {
140+
video::ITexture *guiScalingImageButton(video::IVideoDriver *driver,
141+
video::ITexture *src, s32 width, s32 height)
142+
{
138143
return guiScalingResizeCached(driver, src,
139144
core::rect<s32>(0, 0, src->getSize().Width, src->getSize().Height),
140145
core::rect<s32>(0, 0, width, height));
@@ -146,8 +151,8 @@ video::ITexture *guiScalingImageButton(video::IVideoDriver *driver, video::IText
146151
void draw2DImageFilterScaled(video::IVideoDriver *driver, video::ITexture *txr,
147152
const core::rect<s32> &destrect, const core::rect<s32> &srcrect,
148153
const core::rect<s32> *cliprect, const video::SColor *const colors,
149-
bool usealpha) {
150-
154+
bool usealpha)
155+
{
151156
// Attempt to pre-scale image in software in high quality.
152157
video::ITexture *scaled = guiScalingResizeCached(driver, txr, srcrect, destrect);
153158

Diff for: ‎src/imagefilters.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3131
* transparent. Should be 127 for 3d where alpha is threshold, but 0 for
3232
* 2d where alpha is blended.
3333
*/
34-
void imageCleanTransparent(video::IImage *src, u32 threshold) {
35-
34+
void imageCleanTransparent(video::IImage *src, u32 threshold)
35+
{
3636
core::dimension2d<u32> dim = src->getDimension();
3737

3838
// Walk each pixel looking for fully transparent ones.
@@ -85,8 +85,8 @@ void imageCleanTransparent(video::IImage *src, u32 threshold) {
8585
* filter is designed to produce the most accurate results for both upscaling
8686
* and downscaling.
8787
*/
88-
void imageScaleNNAA(video::IImage *src, const core::rect<s32> &srcrect, video::IImage *dest) {
89-
88+
void imageScaleNNAA(video::IImage *src, const core::rect<s32> &srcrect, video::IImage *dest)
89+
{
9090
double sx, sy, minsx, maxsx, minsy, maxsy, area, ra, ga, ba, aa, pw, ph, pa;
9191
u32 dy, dx;
9292
video::SColor pxl;

0 commit comments

Comments
 (0)
Please sign in to comment.