aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorAaron Suen <warr1024@gmail.com>2015-03-09 09:32:11 -0400
committerkwolekr <kwolekr@minetest.net>2015-04-01 00:01:05 -0400
commit6d61375cc72bad5c569d25c253adca4e3701dd27 (patch)
tree790accab0443ebcff77790da83a306d713045b01 /src/client
parentb4247dff2e003dd8c5ea5a1f3ae349d0bfab90bc (diff)
downloadminetest-6d61375cc72bad5c569d25c253adca4e3701dd27.tar.gz
minetest-6d61375cc72bad5c569d25c253adca4e3701dd27.tar.bz2
minetest-6d61375cc72bad5c569d25c253adca4e3701dd27.zip
Clean scaling pre-filter for formspec/HUD.
Diffstat (limited to 'src/client')
-rw-r--r--src/client/tile.cpp61
-rw-r--r--src/client/tile.h16
2 files changed, 10 insertions, 67 deletions
diff --git a/src/client/tile.cpp b/src/client/tile.cpp
index b7f63502d..283b262a6 100644
--- a/src/client/tile.cpp
+++ b/src/client/tile.cpp
@@ -34,6 +34,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "gamedef.h"
#include "strfnd.h"
#include "util/string.h" // for parseColorString()
+#include "imagefilters.h"
+#include "guiscalingfilter.h"
#ifdef __ANDROID__
#include <GLES/gl.h>
@@ -223,58 +225,9 @@ public:
}
}
- /* Apply the "clean transparent" filter to textures, removing borders on transparent textures.
- * PNG optimizers discard RGB values of fully-transparent pixels, but filters may expose the
- * replacement colors at borders by blending to them; this filter compensates for that by
- * filling in those RGB values from nearby pixels.
- */
- if (g_settings->getBool("texture_clean_transparent")) {
- const core::dimension2d<u32> dim = toadd->getDimension();
-
- // Walk each pixel looking for ones that will show as transparent.
- for (u32 ctrx = 0; ctrx < dim.Width; ctrx++)
- for (u32 ctry = 0; ctry < dim.Height; ctry++) {
- irr::video::SColor c = toadd->getPixel(ctrx, ctry);
- if (c.getAlpha() > 127)
- continue;
-
- // Sample size and total weighted r, g, b values.
- u32 ss = 0, sr = 0, sg = 0, sb = 0;
-
- // Walk each neighbor pixel (clipped to image bounds).
- for (u32 sx = (ctrx < 1) ? 0 : (ctrx - 1);
- sx <= (ctrx + 1) && sx < dim.Width; sx++)
- for (u32 sy = (ctry < 1) ? 0 : (ctry - 1);
- sy <= (ctry + 1) && sy < dim.Height; sy++) {
-
- // Ignore the center pixel (its RGB is already
- // presumed meaningless).
- if ((sx == ctrx) && (sy == ctry))
- continue;
-
- // Ignore other nearby pixels that would be
- // transparent upon display.
- irr::video::SColor d = toadd->getPixel(sx, sy);
- if(d.getAlpha() < 128)
- continue;
-
- // Add one weighted sample.
- ss++;
- sr += d.getRed();
- sg += d.getGreen();
- sb += d.getBlue();
- }
-
- // If we found any neighbor RGB data, set pixel to average
- // weighted by alpha.
- if (ss > 0) {
- c.setRed(sr / ss);
- c.setGreen(sg / ss);
- c.setBlue(sb / ss);
- toadd->setPixel(ctrx, ctry, c);
- }
- }
- }
+ // Apply the "clean transparent" filter, if configured.
+ if (g_settings->getBool("texture_clean_transparent"))
+ imageCleanTransparent(toadd, 127);
if (need_to_grab)
toadd->grab();
@@ -670,6 +623,7 @@ u32 TextureSource::generateTexture(const std::string &name)
#endif
// Create texture from resulting image
tex = driver->addTexture(name.c_str(), img);
+ guiScalingCache(io::path(name.c_str()), driver, img);
img->drop();
}
@@ -776,6 +730,7 @@ void TextureSource::rebuildImagesAndTextures()
video::ITexture *t = NULL;
if (img) {
t = driver->addTexture(ti->name.c_str(), img);
+ guiScalingCache(io::path(ti->name.c_str()), driver, img);
img->drop();
}
video::ITexture *t_old = ti->texture;
@@ -896,6 +851,8 @@ video::ITexture* TextureSource::generateTextureFromMesh(
rawImage->copyToScaling(inventory_image);
rawImage->drop();
+ guiScalingCache(io::path(params.rtt_texture_name.c_str()), driver, inventory_image);
+
video::ITexture *rtt = driver->addTexture(params.rtt_texture_name.c_str(), inventory_image);
inventory_image->drop();
diff --git a/src/client/tile.h b/src/client/tile.h
index eadfdc2a5..38f8bb623 100644
--- a/src/client/tile.h
+++ b/src/client/tile.h
@@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "threads.h"
#include <string>
#include <vector>
+#include "util/numeric.h"
class IGameDef;
@@ -135,21 +136,6 @@ public:
IWritableTextureSource* createTextureSource(IrrlichtDevice *device);
#ifdef __ANDROID__
-/**
- * @param size get next npot2 value
- * @return npot2 value
- */
-inline unsigned int npot2(unsigned int size)
-{
- if (size == 0) return 0;
- unsigned int npot = 1;
-
- while ((size >>= 1) > 0) {
- npot <<= 1;
- }
- return npot;
-}
-
video::IImage * Align2Npot2(video::IImage * image, video::IVideoDriver* driver);
#endif