From 98013ee6f7b61b39c14a24e74751b0b6c2673375 Mon Sep 17 00:00:00 2001 From: fluxgen Date: Mon, 18 Aug 2003 11:37:15 +0000 Subject: minor cleaning --- src/FbTk/ImageControl.cc | 41 ++++++++++++++++++----------------------- src/FbTk/ImageControl.hh | 3 ++- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/FbTk/ImageControl.cc b/src/FbTk/ImageControl.cc index 3e9b96a..915dc1c 100644 --- a/src/FbTk/ImageControl.cc +++ b/src/FbTk/ImageControl.cc @@ -22,7 +22,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: ImageControl.cc,v 1.4 2003/08/18 09:55:11 fluxgen Exp $ +// $Id: ImageControl.cc,v 1.5 2003/08/18 11:37:14 fluxgen Exp $ #include "ImageControl.hh" @@ -60,10 +60,15 @@ namespace FbTk { // lookup table for texture unsigned long *ImageControl::sqrt_table = 0; +#ifdef TIMEDCACHE +bool ImageControl::s_timed_cache = true; +#else +bool ImageControl::s_timed_cache = false; +#endif // TIMEDCACHE namespace { // anonymous -unsigned long bsqrt(unsigned long x) { +inline unsigned long bsqrt(unsigned long x) { if (x <= 0) return 0; if (x == 1) return 1; @@ -79,7 +84,6 @@ unsigned long bsqrt(unsigned long x) { }; // end anonymous namespace - ImageControl::ImageControl(int screen_num, bool dither, int cpc, unsigned long cache_timeout, unsigned long cmax): m_dither(dither), @@ -96,14 +100,13 @@ ImageControl::ImageControl(int screen_num, bool dither, m_colormap = DefaultColormap(disp, screen_num); cache_max = cmax; -#ifdef TIMEDCACHE - if (cache_timeout) { + + if (cache_timeout && s_timed_cache) { m_timer.setTimeout(cache_timeout); RefCount clean_cache(new SimpleCommand(*this, &ImageControl::cleanCache)); m_timer.setCommand(clean_cache); m_timer.start(); } -#endif // TIMEDCACHE createColorTable(); } @@ -134,9 +137,6 @@ ImageControl::~ImageControl() { } if (cache.size() > 0) { -#ifdef DEBUG - cerr<<"FbTk::ImageContol: pixmap cache - releasing "<display(); @@ -210,12 +210,8 @@ Pixmap ImageControl::renderImage(unsigned int width, unsigned int height, cache.push_back(tmp); - if ((unsigned) cache.size() > cache_max) { -#ifdef DEBUG - cerr<<"FbTk::ImageControl::renderImage(): cache is large, forcing cleanout"< cache_max) cleanCache(); - } return pixmap; } @@ -235,12 +231,11 @@ void ImageControl::removeImage(Pixmap pixmap) { if ((*it)->count) { (*it)->count--; -#ifdef TIMEDCACHE - cleanCache(); -#else // !TIMEDCACHE - if (! (*it)->count) + if (s_timed_cache) cleanCache(); -#endif // TIMEDCACHE + else if (! (*it)->count) + cleanCache(); + } return; @@ -342,14 +337,14 @@ unsigned long ImageControl::getSqrt(unsigned int x) const { if (! sqrt_table) { // build sqrt table for use with elliptic gradient - sqrt_table = new unsigned long[(256 * 256 * 2) + 1]; + sqrt_table = new unsigned long[256 * 256 * 2 + 1]; int i = 0; for (; i < (256 * 256 * 2); i++) - *(sqrt_table + i) = bsqrt(i); + sqrt_table[i] = bsqrt(i); } - return (*(sqrt_table + x)); + return sqrt_table[x]; } void ImageControl::cleanCache() { @@ -534,7 +529,7 @@ void ImageControl::createColorTable() { if (m_colors_per_channel < 2 || m_num_colors > static_cast(1 << m_screen_depth)) { fprintf(stderr,"FbTk::ImageControl: invalid colormap size %d " - "(%d/%d/%d) - reducing", + "(%d/%d/%d) - reducing", m_num_colors, m_colors_per_channel, m_colors_per_channel, m_colors_per_channel); diff --git a/src/FbTk/ImageControl.hh b/src/FbTk/ImageControl.hh index 9fe0a0a..c43c5a0 100644 --- a/src/FbTk/ImageControl.hh +++ b/src/FbTk/ImageControl.hh @@ -22,7 +22,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: ImageControl.hh,v 1.3 2003/08/11 15:59:49 fluxgen Exp $ +// $Id: ImageControl.hh,v 1.4 2003/08/18 11:37:15 fluxgen Exp $ #ifndef FBTK_IMAGECONTROL_HH #define FBTK_IMAGECONTROL_HH @@ -119,6 +119,7 @@ private: typedef std::list CacheList; mutable CacheList cache; + static bool s_timed_cache; }; }; // end namespace FbTk -- cgit v0.11.2