Fix some minor details from 6d61375

This commit is contained in:
kwolekr 2015-04-01 00:19:10 -04:00
parent 6d61375cc7
commit ddf96c7a17
4 changed files with 37 additions and 30 deletions

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

@ -1308,8 +1308,10 @@ void GUIFormSpecMenu::parseImageButton(parserData* data,std::string element,
} }
e->setUseAlphaChannel(true); e->setUseAlphaChannel(true);
e->setImage(guiScalingImageButton(Environment->getVideoDriver(), texture, geom.X, geom.Y)); e->setImage(guiScalingImageButton(
e->setPressedImage(guiScalingImageButton(Environment->getVideoDriver(), pressed_texture, geom.X, geom.Y)); Environment->getVideoDriver(), texture, geom.X, geom.Y));
e->setPressedImage(guiScalingImageButton(
Environment->getVideoDriver(), pressed_texture, geom.X, geom.Y));
e->setScaleImage(true); e->setScaleImage(true);
e->setNotClipped(noclip); e->setNotClipped(noclip);
e->setDrawBorder(drawborder); e->setDrawBorder(drawborder);

@ -28,54 +28,58 @@ with this program; if not, write to the Free Software Foundation, Inc.,
* converting textures back into images repeatedly, and some don't even * converting textures back into images repeatedly, and some don't even
* allow it at all. * allow it at all.
*/ */
std::map<io::path, video::IImage *> imgCache; std::map<io::path, video::IImage *> g_imgCache;
/* Maintain a static cache of all pre-scaled textures. These need to be /* Maintain a static cache of all pre-scaled textures. These need to be
* cleared as well when the cached images. * cleared as well when the cached images.
*/ */
std::map<io::path, video::ITexture *> txrCache; std::map<io::path, video::ITexture *> g_txrCache;
/* Manually insert an image into the cache, useful to avoid texture-to-image /* Manually insert an image into the cache, useful to avoid texture-to-image
* conversion whenever we can intercept it. * conversion whenever we can intercept it.
*/ */
void guiScalingCache(io::path key, video::IVideoDriver *driver, video::IImage *value) { void guiScalingCache(io::path key, video::IVideoDriver *driver, video::IImage *value)
{
if (!g_settings->getBool("gui_scaling_filter")) if (!g_settings->getBool("gui_scaling_filter"))
return; return;
video::IImage *copied = driver->createImage(value->getColorFormat(), video::IImage *copied = driver->createImage(value->getColorFormat(),
value->getDimension()); value->getDimension());
value->copyTo(copied); value->copyTo(copied);
imgCache[key] = copied; g_imgCache[key] = copied;
} }
// Manually clear the cache, e.g. when switching to different worlds. // Manually clear the cache, e.g. when switching to different worlds.
void guiScalingCacheClear(video::IVideoDriver *driver) { void guiScalingCacheClear(video::IVideoDriver *driver)
for (std::map<io::path, video::IImage *>::iterator it = imgCache.begin(); {
it != imgCache.end(); it++) { for (std::map<io::path, video::IImage *>::iterator it = g_imgCache.begin();
it != g_imgCache.end(); it++) {
if (it->second != NULL) if (it->second != NULL)
it->second->drop(); it->second->drop();
} }
imgCache.clear(); g_imgCache.clear();
for (std::map<io::path, video::ITexture *>::iterator it = txrCache.begin(); for (std::map<io::path, video::ITexture *>::iterator it = g_txrCache.begin();
it != txrCache.end(); it++) { it != g_txrCache.end(); it++) {
if (it->second != NULL) if (it->second != NULL)
driver->removeTexture(it->second); driver->removeTexture(it->second);
} }
txrCache.clear(); g_txrCache.clear();
} }
/* Get a cached, high-quality pre-scaled texture for display purposes. If the /* Get a cached, high-quality pre-scaled texture for display purposes. If the
* texture is not already cached, attempt to create it. Returns a pre-scaled texture, * texture is not already cached, attempt to create it. Returns a pre-scaled texture,
* or the original texture if unable to pre-scale it. * or the original texture if unable to pre-scale it.
*/ */
video::ITexture *guiScalingResizeCached(video::IVideoDriver *driver, video::ITexture *src, video::ITexture *guiScalingResizeCached(video::IVideoDriver *driver,
const core::rect<s32> &srcrect, const core::rect<s32> &destrect) { video::ITexture *src, const core::rect<s32> &srcrect,
const core::rect<s32> &destrect)
{
if (!g_settings->getBool("gui_scaling_filter")) if (!g_settings->getBool("gui_scaling_filter"))
return src; return src;
// Calculate scaled texture name. // Calculate scaled texture name.
char rectstr[200]; char rectstr[200];
sprintf(rectstr, "%d:%d:%d:%d:%d:%d", snprintf(rectstr, sizeof(rectstr), "%d:%d:%d:%d:%d:%d",
srcrect.UpperLeftCorner.X, srcrect.UpperLeftCorner.X,
srcrect.UpperLeftCorner.Y, srcrect.UpperLeftCorner.Y,
srcrect.getWidth(), srcrect.getWidth(),
@ -86,20 +90,20 @@ video::ITexture *guiScalingResizeCached(video::IVideoDriver *driver, video::ITex
io::path scalename = origname + "@guiScalingFilter:" + rectstr; io::path scalename = origname + "@guiScalingFilter:" + rectstr;
// Search for existing scaled texture. // Search for existing scaled texture.
video::ITexture *scaled = txrCache[scalename]; video::ITexture *scaled = g_txrCache[scalename];
if (scaled) if (scaled)
return scaled; return scaled;
// Try to find the texture converted to an image in the cache. // Try to find the texture converted to an image in the cache.
// If the image was not found, try to extract it from the texture. // If the image was not found, try to extract it from the texture.
video::IImage* srcimg = imgCache[origname]; video::IImage* srcimg = g_imgCache[origname];
if (srcimg == NULL) { if (srcimg == NULL) {
if (!g_settings->getBool("gui_scaling_filter_txr2img")) if (!g_settings->getBool("gui_scaling_filter_txr2img"))
return src; return src;
srcimg = driver->createImageFromData(src->getColorFormat(), srcimg = driver->createImageFromData(src->getColorFormat(),
src->getSize(), src->lock(), false); src->getSize(), src->lock(), false);
src->unlock(); src->unlock();
imgCache[origname] = srcimg; g_imgCache[origname] = srcimg;
} }
// Create a new destination image and scale the source into it. // Create a new destination image and scale the source into it.
@ -125,7 +129,7 @@ video::ITexture *guiScalingResizeCached(video::IVideoDriver *driver, video::ITex
// Convert the scaled image back into a texture. // Convert the scaled image back into a texture.
scaled = driver->addTexture(scalename, destimg, NULL); scaled = driver->addTexture(scalename, destimg, NULL);
destimg->drop(); destimg->drop();
txrCache[scalename] = scaled; g_txrCache[scalename] = scaled;
return scaled; return scaled;
} }
@ -133,8 +137,9 @@ video::ITexture *guiScalingResizeCached(video::IVideoDriver *driver, video::ITex
/* Convenience wrapper for guiScalingResizeCached that accepts parameters that /* Convenience wrapper for guiScalingResizeCached that accepts parameters that
* are available at GUI imagebutton creation time. * are available at GUI imagebutton creation time.
*/ */
video::ITexture *guiScalingImageButton(video::IVideoDriver *driver, video::ITexture *src, video::ITexture *guiScalingImageButton(video::IVideoDriver *driver,
s32 width, s32 height) { video::ITexture *src, s32 width, s32 height)
{
return guiScalingResizeCached(driver, src, return guiScalingResizeCached(driver, src,
core::rect<s32>(0, 0, src->getSize().Width, src->getSize().Height), core::rect<s32>(0, 0, src->getSize().Width, src->getSize().Height),
core::rect<s32>(0, 0, width, height)); core::rect<s32>(0, 0, width, height));
@ -146,8 +151,8 @@ video::ITexture *guiScalingImageButton(video::IVideoDriver *driver, video::IText
void draw2DImageFilterScaled(video::IVideoDriver *driver, video::ITexture *txr, void draw2DImageFilterScaled(video::IVideoDriver *driver, video::ITexture *txr,
const core::rect<s32> &destrect, const core::rect<s32> &srcrect, const core::rect<s32> &destrect, const core::rect<s32> &srcrect,
const core::rect<s32> *cliprect, const video::SColor *const colors, const core::rect<s32> *cliprect, const video::SColor *const colors,
bool usealpha) { bool usealpha)
{
// Attempt to pre-scale image in software in high quality. // Attempt to pre-scale image in software in high quality.
video::ITexture *scaled = guiScalingResizeCached(driver, txr, srcrect, destrect); video::ITexture *scaled = guiScalingResizeCached(driver, txr, srcrect, destrect);

@ -31,8 +31,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
* transparent. Should be 127 for 3d where alpha is threshold, but 0 for * transparent. Should be 127 for 3d where alpha is threshold, but 0 for
* 2d where alpha is blended. * 2d where alpha is blended.
*/ */
void imageCleanTransparent(video::IImage *src, u32 threshold) { void imageCleanTransparent(video::IImage *src, u32 threshold)
{
core::dimension2d<u32> dim = src->getDimension(); core::dimension2d<u32> dim = src->getDimension();
// Walk each pixel looking for fully transparent ones. // Walk each pixel looking for fully transparent ones.
@ -85,8 +85,8 @@ void imageCleanTransparent(video::IImage *src, u32 threshold) {
* filter is designed to produce the most accurate results for both upscaling * filter is designed to produce the most accurate results for both upscaling
* and downscaling. * and downscaling.
*/ */
void imageScaleNNAA(video::IImage *src, const core::rect<s32> &srcrect, video::IImage *dest) { void imageScaleNNAA(video::IImage *src, const core::rect<s32> &srcrect, video::IImage *dest)
{
double sx, sy, minsx, maxsx, minsy, maxsy, area, ra, ga, ba, aa, pw, ph, pa; double sx, sy, minsx, maxsx, minsy, maxsy, area, ra, ga, ba, aa, pw, ph, pa;
u32 dy, dx; u32 dy, dx;
video::SColor pxl; video::SColor pxl;