aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/FbTk/ImageControl.cc41
-rw-r--r--src/FbTk/ImageControl.hh3
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 @@
22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23// DEALINGS IN THE SOFTWARE. 23// DEALINGS IN THE SOFTWARE.
24 24
25// $Id: ImageControl.cc,v 1.4 2003/08/18 09:55:11 fluxgen Exp $ 25// $Id: ImageControl.cc,v 1.5 2003/08/18 11:37:14 fluxgen Exp $
26 26
27#include "ImageControl.hh" 27#include "ImageControl.hh"
28 28
@@ -60,10 +60,15 @@ namespace FbTk {
60 60
61// lookup table for texture 61// lookup table for texture
62unsigned long *ImageControl::sqrt_table = 0; 62unsigned long *ImageControl::sqrt_table = 0;
63#ifdef TIMEDCACHE
64bool ImageControl::s_timed_cache = true;
65#else
66bool ImageControl::s_timed_cache = false;
67#endif // TIMEDCACHE
63 68
64namespace { // anonymous 69namespace { // anonymous
65 70
66unsigned long bsqrt(unsigned long x) { 71inline unsigned long bsqrt(unsigned long x) {
67 if (x <= 0) return 0; 72 if (x <= 0) return 0;
68 if (x == 1) return 1; 73 if (x == 1) return 1;
69 74
@@ -79,7 +84,6 @@ unsigned long bsqrt(unsigned long x) {
79 84
80}; // end anonymous namespace 85}; // end anonymous namespace
81 86
82
83ImageControl::ImageControl(int screen_num, bool dither, 87ImageControl::ImageControl(int screen_num, bool dither,
84 int cpc, unsigned long cache_timeout, unsigned long cmax): 88 int cpc, unsigned long cache_timeout, unsigned long cmax):
85 m_dither(dither), 89 m_dither(dither),
@@ -96,14 +100,13 @@ ImageControl::ImageControl(int screen_num, bool dither,
96 m_colormap = DefaultColormap(disp, screen_num); 100 m_colormap = DefaultColormap(disp, screen_num);
97 101
98 cache_max = cmax; 102 cache_max = cmax;
99#ifdef TIMEDCACHE 103
100 if (cache_timeout) { 104 if (cache_timeout && s_timed_cache) {
101 m_timer.setTimeout(cache_timeout); 105 m_timer.setTimeout(cache_timeout);
102 RefCount<Command> clean_cache(new SimpleCommand<ImageControl>(*this, &ImageControl::cleanCache)); 106 RefCount<Command> clean_cache(new SimpleCommand<ImageControl>(*this, &ImageControl::cleanCache));
103 m_timer.setCommand(clean_cache); 107 m_timer.setCommand(clean_cache);
104 m_timer.start(); 108 m_timer.start();
105 } 109 }
106#endif // TIMEDCACHE
107 110
108 createColorTable(); 111 createColorTable();
109} 112}
@@ -134,9 +137,6 @@ ImageControl::~ImageControl() {
134 } 137 }
135 138
136 if (cache.size() > 0) { 139 if (cache.size() > 0) {
137#ifdef DEBUG
138 cerr<<"FbTk::ImageContol: pixmap cache - releasing "<<cache.size()<<" pixmaps."<<endl;
139#endif // DEBUG
140 CacheList::iterator it = cache.begin(); 140 CacheList::iterator it = cache.begin();
141 CacheList::iterator it_end = cache.end(); 141 CacheList::iterator it_end = cache.end();
142 Display *disp = FbTk::App::instance()->display(); 142 Display *disp = FbTk::App::instance()->display();
@@ -210,12 +210,8 @@ Pixmap ImageControl::renderImage(unsigned int width, unsigned int height,
210 210
211 cache.push_back(tmp); 211 cache.push_back(tmp);
212 212
213 if ((unsigned) cache.size() > cache_max) { 213 if ((unsigned) cache.size() > cache_max)
214#ifdef DEBUG
215 cerr<<"FbTk::ImageControl::renderImage(): cache is large, forcing cleanout"<<endl;
216#endif // DEBUG
217 cleanCache(); 214 cleanCache();
218 }
219 215
220 return pixmap; 216 return pixmap;
221 } 217 }
@@ -235,12 +231,11 @@ void ImageControl::removeImage(Pixmap pixmap) {
235 if ((*it)->count) { 231 if ((*it)->count) {
236 (*it)->count--; 232 (*it)->count--;
237 233
238#ifdef TIMEDCACHE 234 if (s_timed_cache)
239 cleanCache();
240#else // !TIMEDCACHE
241 if (! (*it)->count)
242 cleanCache(); 235 cleanCache();
243#endif // TIMEDCACHE 236 else if (! (*it)->count)
237 cleanCache();
238
244 } 239 }
245 240
246 return; 241 return;
@@ -342,14 +337,14 @@ unsigned long ImageControl::getSqrt(unsigned int x) const {
342 if (! sqrt_table) { 337 if (! sqrt_table) {
343 // build sqrt table for use with elliptic gradient 338 // build sqrt table for use with elliptic gradient
344 339
345 sqrt_table = new unsigned long[(256 * 256 * 2) + 1]; 340 sqrt_table = new unsigned long[256 * 256 * 2 + 1];
346 int i = 0; 341 int i = 0;
347 342
348 for (; i < (256 * 256 * 2); i++) 343 for (; i < (256 * 256 * 2); i++)
349 *(sqrt_table + i) = bsqrt(i); 344 sqrt_table[i] = bsqrt(i);
350 } 345 }
351 346
352 return (*(sqrt_table + x)); 347 return sqrt_table[x];
353} 348}
354 349
355void ImageControl::cleanCache() { 350void ImageControl::cleanCache() {
@@ -534,7 +529,7 @@ void ImageControl::createColorTable() {
534 529
535 if (m_colors_per_channel < 2 || m_num_colors > static_cast<unsigned int>(1 << m_screen_depth)) { 530 if (m_colors_per_channel < 2 || m_num_colors > static_cast<unsigned int>(1 << m_screen_depth)) {
536 fprintf(stderr,"FbTk::ImageControl: invalid colormap size %d " 531 fprintf(stderr,"FbTk::ImageControl: invalid colormap size %d "
537 "(%d/%d/%d) - reducing", 532 "(%d/%d/%d) - reducing",
538 m_num_colors, m_colors_per_channel, m_colors_per_channel, 533 m_num_colors, m_colors_per_channel, m_colors_per_channel,
539 m_colors_per_channel); 534 m_colors_per_channel);
540 535
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 @@
22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23// DEALINGS IN THE SOFTWARE. 23// DEALINGS IN THE SOFTWARE.
24 24
25// $Id: ImageControl.hh,v 1.3 2003/08/11 15:59:49 fluxgen Exp $ 25// $Id: ImageControl.hh,v 1.4 2003/08/18 11:37:15 fluxgen Exp $
26 26
27#ifndef FBTK_IMAGECONTROL_HH 27#ifndef FBTK_IMAGECONTROL_HH
28#define FBTK_IMAGECONTROL_HH 28#define FBTK_IMAGECONTROL_HH
@@ -119,6 +119,7 @@ private:
119 typedef std::list<Cache *> CacheList; 119 typedef std::list<Cache *> CacheList;
120 120
121 mutable CacheList cache; 121 mutable CacheList cache;
122 static bool s_timed_cache;
122}; 123};
123 124
124}; // end namespace FbTk 125}; // end namespace FbTk