BImage::BImage(BImageControl *c, unsigned int w, unsigned int h) {
control = c;
- width = ((signed) w > 0) ? w : 1;
- height = ((signed) h > 0) ? h : 1;
+ width = (w > 0) ? w : 1;
+ height = (h > 0) ? h : 1;
red = new unsigned char[width * height];
green = new unsigned char[width * height];
BImage::~BImage(void) {
- if (red) delete [] red;
- if (green) delete [] green;
- if (blue) delete [] blue;
+ delete [] red;
+ delete [] green;
+ delete [] blue;
}
Pixmap BImage::render(const BTexture &texture) {
- if ((texture.texture() & BTexture::Parent_Relative))
+ if (texture.texture() & BTexture::Parent_Relative)
return ParentRelative;
- else if ((texture.texture() & BTexture::Solid))
+ else if (texture.texture() & BTexture::Solid)
return render_solid(texture);
- else if ((texture.texture() & BTexture::Gradient))
+ else if (texture.texture() & BTexture::Gradient)
return render_gradient(texture);
return None;
}
if (texture.texture() & BTexture::Interlaced) {
BPen peninterlace(texture.colorTo());
- register unsigned int i = 0;
- for (; i < height; i += 2)
+ for (unsigned int i = 0; i < height; i += 2)
XDrawLine(display, pixmap, peninterlace.gc(), 0, i, width, i);
}
Pixmap BImage::render_gradient(const BTexture &texture) {
- int inverted = 0;
+ bool inverted = False;
interlaced = texture.texture() & BTexture::Interlaced;
from = texture.colorTo();
to = texture.color();
- if (! (texture.texture() & BTexture::Invert)) inverted = 1;
+ if (! (texture.texture() & BTexture::Invert)) inverted = True;
} else {
from = texture.color();
to = texture.colorTo();
- if (texture.texture() & BTexture::Invert) inverted = 1;
+ if (texture.texture() & BTexture::Invert) inverted = True;
}
control->getGradientBuffers(width, height, &xtable, &ytable);
if (inverted) invert();
- Pixmap pixmap = renderPixmap();
-
- return pixmap;
+ return renderPixmap();
}
unsigned int o = image->bits_per_pixel +
((image->byte_order == MSBFirst) ? 1 : 0);
+ bool unsupported = False;
+
if (control->doDither() && width > 1 && height > 1) {
switch (control->getVisual()->c_class) {
case TrueColor:
}
default:
- fprintf(stderr, i18n(ImageSet, ImageUnsupVisual,
- "BImage::renderXImage: unsupported visual\n"));
- delete [] d;
- XDestroyImage(image);
- return (XImage *) 0;
+ unsupported = True;
}
} else {
- register unsigned int x, y, r, g, b, offset;
-
+ unsigned int x, y, r, g, b, offset;
unsigned char *pixel_data = d, *ppixel_data = d;
unsigned long pixel;
switch (control->getVisual()->c_class) {
case StaticColor:
case PseudoColor:
- for (y = 0, offset = 0; y < height; y++) {
- for (x = 0; x < width; x++, offset++) {
+ for (y = 0, offset = 0; y < height; ++y) {
+ for (x = 0; x < width; ++x, ++offset) {
r = red_table[red[offset]];
g = green_table[green[offset]];
b = blue_table[blue[offset]];
break;
default:
- fprintf(stderr, i18n(ImageSet, ImageUnsupVisual,
- "BImage::renderXImage: unsupported visual\n"));
- delete [] d;
- XDestroyImage(image);
- return (XImage *) 0;
+ unsupported = True;
}
}
+ if (unsupported) {
+ fprintf(stderr, i18n(ImageSet, ImageUnsupVisual,
+ "BImage::renderXImage: unsupported visual\n"));
+ delete [] d;
+ XDestroyImage(image);
+ return (XImage *) 0;
+ }
+
image->data = (char *) d;
+
return image;
}
if (! image) {
XFreePixmap(control->getBaseDisplay()->getXDisplay(), pixmap);
return None;
- } else if (! image->data) {
+ }
+
+ if (! image->data) {
XDestroyImage(image);
XFreePixmap(control->getBaseDisplay()->getXDisplay(), pixmap);
return None;
class BImageControl;
class BTexture;
-class BImageCache;
class BImage {
private:
#endif
Pixmap renderPixmap(void);
+ Pixmap render_solid(const BTexture &texture);
+ Pixmap render_gradient(const BTexture &texture);
XImage *renderXImage(void);
~BImage(void);
Pixmap render(const BTexture &texture);
- Pixmap render_solid(const BTexture &texture);
- Pixmap render_gradient(const BTexture &texture);
-
- // static methods for the builtin cache
- static unsigned long maximumCacheSize(void);
- static void setMaximumCacheSize(const unsigned long cache_max);
-
- static unsigned long cacheTimeout(void);
- static void setCacheTimeout(const unsigned long cache_timeout);
-
-private:
- // global image cache
- static BImageCache *imagecache;
};
BImageControl::BImageControl(BaseDisplay *dpy, const ScreenInfo *scrn,
bool _dither, int _cpc,
unsigned long cache_timeout,
- unsigned long cmax)
-{
+ unsigned long cmax) {
if (! ctrl) ctrl = this;
basedisplay = dpy;
if (colors) {
unsigned long *pixels = new unsigned long [ncolors];
- int i;
- for (i = 0; i < ncolors; i++)
+ for (int i = 0; i < ncolors; i++)
*(pixels + i) = (*(colors + i)).pixel;
XFreeColors(basedisplay->getXDisplay(), colormap, pixels, ncolors, 0);
//#endif
CacheContainer::iterator it = cache.begin();
const CacheContainer::iterator end = cache.end();
- for (; it != end; ++it) {
- XFreePixmap(basedisplay->getXDisplay(), (*it).pixmap);
- }
+ for (; it != end; ++it)
+ XFreePixmap(basedisplay->getXDisplay(), it->pixmap);
}
#ifdef TIMEDCACHE
if (timer) {
const CacheContainer::iterator end = cache.end();
for (; it != end; ++it) {
CachedImage& tmp = *it;
- if ((tmp.width == width) && (tmp.height == height) &&
- (tmp.texture == texture) && (tmp.pixel1 == c1.pixel()))
+ if (tmp.width == width && tmp.height == height &&
+ tmp.texture == texture && tmp.pixel1 == c1.pixel())
if (texture & BTexture::Gradient) {
if (tmp.pixel2 == c2.pixel()) {
tmp.count++;
unsigned int **ybuf)
{
if (w > grad_buffer_width) {
- if (grad_xbuffer) {
+ if (grad_xbuffer)
delete [] grad_xbuffer;
- }
grad_buffer_width = w;
}
if (h > grad_buffer_height) {
- if (grad_ybuffer) {
+ if (grad_ybuffer)
delete [] grad_ybuffer;
- }
grad_buffer_height = h;
addTexture(BTexture::PipeCross);
else if (descr.find("elliptic") != string::npos)
addTexture(BTexture::Elliptic);
- else if (descr.find("diagonal") != string::npos)
- addTexture(BTexture::Diagonal);
else if (descr.find("horizontal") != string::npos)
addTexture(BTexture::Horizontal);
else if (descr.find("vertical") != string::npos)
addTexture(BTexture::Solid);
}
- if (descr.find("raised") != string::npos)
- addTexture(BTexture::Raised);
- else if (descr.find("sunken") != string::npos)
+ if (descr.find("sunken") != string::npos)
addTexture(BTexture::Sunken);
else if (descr.find("flat") != string::npos)
addTexture(BTexture::Flat);
#endif // HAVE_STDIO_H
}
+#include <cctype>
+
#include "../src/i18n.hh"
#include "../src/GCCache.hh"
#include "../src/Texture.hh"
bsetroot::bsetroot(int argc, char **argv, char *dpy_name)
: BaseDisplay(argv[0], dpy_name) {
- grad = fore = back = (char *) 0;
-
bool mod = False, sol = False, grd = False;
int mod_x = 0, mod_y = 0;
for (unsigned int s = 0; s < getNumberOfScreens(); ++s)
img_ctrl[s] = new BImageControl(this, getScreenInfo(s), True);
- if (sol && fore) solid();
- else if (mod && mod_x && mod_y && fore && back) modula(mod_x, mod_y);
- else if (grd && grad && fore && back) gradient();
+ if (sol && ! fore.empty())
+ solid();
+ else if (mod && mod_x && mod_y && ! (fore.empty() || back.empty()))
+ modula(mod_x, mod_y);
+ else if (grd && ! (grad.empty() || fore.empty() || back.empty()))
+ gradient();
else usage();
}
void bsetroot::gradient(void) {
+ /*
+ we have to be sure that neither raised nor sunken is specified otherwise
+ odd looking borders appear. So we convert to lowercase then look for
+ 'raised' or 'sunken' in the description and erase them. To be paranoid
+ the search is done in a loop.
+ */
+ std::string descr;
+ descr.reserve(grad.size());
+
+ std::string::const_iterator it = grad.begin(), end = grad.end();
+ for (; it != end; ++it)
+ descr += std::tolower(*it);
+
+ std::string::size_type pos;
+ while ((pos = descr.find("raised")) != std::string::npos)
+ descr.erase(pos, 6); // 6 is strlen raised
+
+ while ((pos = descr.find("sunken")) != std::string::npos)
+ descr.erase(pos, 6);
+
+ // now add on 'flat' to prevent the bevels from being added
+ descr += "flat";
+
for (unsigned int screen = 0; screen < getNumberOfScreens(); screen++) {
- BTexture texture(grad, this, screen, img_ctrl[screen]);
+ BTexture texture(descr, this, screen, img_ctrl[screen]);
const ScreenInfo *screen_info = getScreenInfo(screen);
texture.setColor(BColor(fore, this, screen));
#include "../src/BaseDisplay.hh"
#include "../src/Image.hh"
+#include <string>
class bsetroot : public BaseDisplay {
private:
BImageControl **img_ctrl;
- char *fore, *back, *grad;
+ std::string fore, back, grad;
// no copying!!
bsetroot(const bsetroot &);