sync with blackbox-cvs

This commit is contained in:
Dana Jansens 2002-08-08 23:07:24 +00:00
parent 2d5e1c55f1
commit 01096f8674
6 changed files with 77 additions and 70 deletions

View file

@ -44,8 +44,8 @@ using std::min;
BImage::BImage(BImageControl *c, unsigned int w, unsigned int h) { BImage::BImage(BImageControl *c, unsigned int w, unsigned int h) {
control = c; control = c;
width = ((signed) w > 0) ? w : 1; width = (w > 0) ? w : 1;
height = ((signed) h > 0) ? h : 1; height = (h > 0) ? h : 1;
red = new unsigned char[width * height]; red = new unsigned char[width * height];
green = new unsigned char[width * height]; green = new unsigned char[width * height];
@ -66,18 +66,18 @@ BImage::BImage(BImageControl *c, unsigned int w, unsigned int h) {
BImage::~BImage(void) { BImage::~BImage(void) {
if (red) delete [] red; delete [] red;
if (green) delete [] green; delete [] green;
if (blue) delete [] blue; delete [] blue;
} }
Pixmap BImage::render(const BTexture &texture) { Pixmap BImage::render(const BTexture &texture) {
if ((texture.texture() & BTexture::Parent_Relative)) if (texture.texture() & BTexture::Parent_Relative)
return ParentRelative; return ParentRelative;
else if ((texture.texture() & BTexture::Solid)) else if (texture.texture() & BTexture::Solid)
return render_solid(texture); return render_solid(texture);
else if ((texture.texture() & BTexture::Gradient)) else if (texture.texture() & BTexture::Gradient)
return render_gradient(texture); return render_gradient(texture);
return None; return None;
} }
@ -103,8 +103,7 @@ Pixmap BImage::render_solid(const BTexture &texture) {
if (texture.texture() & BTexture::Interlaced) { if (texture.texture() & BTexture::Interlaced) {
BPen peninterlace(texture.colorTo()); BPen peninterlace(texture.colorTo());
register unsigned int i = 0; for (unsigned int i = 0; i < height; i += 2)
for (; i < height; i += 2)
XDrawLine(display, pixmap, peninterlace.gc(), 0, i, width, i); XDrawLine(display, pixmap, peninterlace.gc(), 0, i, width, i);
} }
@ -159,7 +158,7 @@ Pixmap BImage::render_solid(const BTexture &texture) {
Pixmap BImage::render_gradient(const BTexture &texture) { Pixmap BImage::render_gradient(const BTexture &texture) {
int inverted = 0; bool inverted = False;
interlaced = texture.texture() & BTexture::Interlaced; interlaced = texture.texture() & BTexture::Interlaced;
@ -167,12 +166,12 @@ Pixmap BImage::render_gradient(const BTexture &texture) {
from = texture.colorTo(); from = texture.colorTo();
to = texture.color(); to = texture.color();
if (! (texture.texture() & BTexture::Invert)) inverted = 1; if (! (texture.texture() & BTexture::Invert)) inverted = True;
} else { } else {
from = texture.color(); from = texture.color();
to = texture.colorTo(); to = texture.colorTo();
if (texture.texture() & BTexture::Invert) inverted = 1; if (texture.texture() & BTexture::Invert) inverted = True;
} }
control->getGradientBuffers(width, height, &xtable, &ytable); control->getGradientBuffers(width, height, &xtable, &ytable);
@ -191,9 +190,7 @@ Pixmap BImage::render_gradient(const BTexture &texture) {
if (inverted) invert(); if (inverted) invert();
Pixmap pixmap = renderPixmap(); return renderPixmap();
return pixmap;
} }
@ -461,6 +458,8 @@ XImage *BImage::renderXImage(void) {
unsigned int o = image->bits_per_pixel + unsigned int o = image->bits_per_pixel +
((image->byte_order == MSBFirst) ? 1 : 0); ((image->byte_order == MSBFirst) ? 1 : 0);
bool unsupported = False;
if (control->doDither() && width > 1 && height > 1) { if (control->doDither() && width > 1 && height > 1) {
switch (control->getVisual()->c_class) { switch (control->getVisual()->c_class) {
case TrueColor: case TrueColor:
@ -478,23 +477,18 @@ XImage *BImage::renderXImage(void) {
} }
default: default:
fprintf(stderr, i18n(ImageSet, ImageUnsupVisual, unsupported = True;
"BImage::renderXImage: unsupported visual\n"));
delete [] d;
XDestroyImage(image);
return (XImage *) 0;
} }
} else { } 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 char *pixel_data = d, *ppixel_data = d;
unsigned long pixel; unsigned long pixel;
switch (control->getVisual()->c_class) { switch (control->getVisual()->c_class) {
case StaticColor: case StaticColor:
case PseudoColor: case PseudoColor:
for (y = 0, offset = 0; y < height; y++) { for (y = 0, offset = 0; y < height; ++y) {
for (x = 0; x < width; x++, offset++) { for (x = 0; x < width; ++x, ++offset) {
r = red_table[red[offset]]; r = red_table[red[offset]];
g = green_table[green[offset]]; g = green_table[green[offset]];
b = blue_table[blue[offset]]; b = blue_table[blue[offset]];
@ -542,15 +536,20 @@ XImage *BImage::renderXImage(void) {
break; break;
default: default:
fprintf(stderr, i18n(ImageSet, ImageUnsupVisual, unsupported = True;
"BImage::renderXImage: unsupported visual\n"));
delete [] d;
XDestroyImage(image);
return (XImage *) 0;
} }
} }
if (unsupported) {
fprintf(stderr, i18n(ImageSet, ImageUnsupVisual,
"BImage::renderXImage: unsupported visual\n"));
delete [] d;
XDestroyImage(image);
return (XImage *) 0;
}
image->data = (char *) d; image->data = (char *) d;
return image; return image;
} }
@ -571,7 +570,9 @@ Pixmap BImage::renderPixmap(void) {
if (! image) { if (! image) {
XFreePixmap(control->getBaseDisplay()->getXDisplay(), pixmap); XFreePixmap(control->getBaseDisplay()->getXDisplay(), pixmap);
return None; return None;
} else if (! image->data) { }
if (! image->data) {
XDestroyImage(image); XDestroyImage(image);
XFreePixmap(control->getBaseDisplay()->getXDisplay(), pixmap); XFreePixmap(control->getBaseDisplay()->getXDisplay(), pixmap);
return None; return None;

View file

@ -37,7 +37,6 @@ extern "C" {
class BImageControl; class BImageControl;
class BTexture; class BTexture;
class BImageCache;
class BImage { class BImage {
private: private:
@ -59,6 +58,8 @@ private:
#endif #endif
Pixmap renderPixmap(void); Pixmap renderPixmap(void);
Pixmap render_solid(const BTexture &texture);
Pixmap render_gradient(const BTexture &texture);
XImage *renderXImage(void); XImage *renderXImage(void);
@ -80,19 +81,6 @@ public:
~BImage(void); ~BImage(void);
Pixmap render(const BTexture &texture); 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;
}; };

View file

@ -65,8 +65,7 @@ BImageControl *ctrl = 0;
BImageControl::BImageControl(BaseDisplay *dpy, const ScreenInfo *scrn, BImageControl::BImageControl(BaseDisplay *dpy, const ScreenInfo *scrn,
bool _dither, int _cpc, bool _dither, int _cpc,
unsigned long cache_timeout, unsigned long cache_timeout,
unsigned long cmax) unsigned long cmax) {
{
if (! ctrl) ctrl = this; if (! ctrl) ctrl = this;
basedisplay = dpy; basedisplay = dpy;
@ -364,8 +363,7 @@ BImageControl::~BImageControl(void) {
if (colors) { if (colors) {
unsigned long *pixels = new unsigned long [ncolors]; unsigned long *pixels = new unsigned long [ncolors];
int i; for (int i = 0; i < ncolors; i++)
for (i = 0; i < ncolors; i++)
*(pixels + i) = (*(colors + i)).pixel; *(pixels + i) = (*(colors + i)).pixel;
XFreeColors(basedisplay->getXDisplay(), colormap, pixels, ncolors, 0); XFreeColors(basedisplay->getXDisplay(), colormap, pixels, ncolors, 0);
@ -381,9 +379,8 @@ BImageControl::~BImageControl(void) {
//#endif //#endif
CacheContainer::iterator it = cache.begin(); CacheContainer::iterator it = cache.begin();
const CacheContainer::iterator end = cache.end(); const CacheContainer::iterator end = cache.end();
for (; it != end; ++it) { for (; it != end; ++it)
XFreePixmap(basedisplay->getXDisplay(), (*it).pixmap); XFreePixmap(basedisplay->getXDisplay(), it->pixmap);
}
} }
#ifdef TIMEDCACHE #ifdef TIMEDCACHE
if (timer) { if (timer) {
@ -405,8 +402,8 @@ Pixmap BImageControl::searchCache(const unsigned int width,
const CacheContainer::iterator end = cache.end(); const CacheContainer::iterator end = cache.end();
for (; it != end; ++it) { for (; it != end; ++it) {
CachedImage& tmp = *it; CachedImage& tmp = *it;
if ((tmp.width == width) && (tmp.height == height) && if (tmp.width == width && tmp.height == height &&
(tmp.texture == texture) && (tmp.pixel1 == c1.pixel())) tmp.texture == texture && tmp.pixel1 == c1.pixel())
if (texture & BTexture::Gradient) { if (texture & BTexture::Gradient) {
if (tmp.pixel2 == c2.pixel()) { if (tmp.pixel2 == c2.pixel()) {
tmp.count++; tmp.count++;
@ -514,9 +511,8 @@ void BImageControl::getGradientBuffers(unsigned int w,
unsigned int **ybuf) unsigned int **ybuf)
{ {
if (w > grad_buffer_width) { if (w > grad_buffer_width) {
if (grad_xbuffer) { if (grad_xbuffer)
delete [] grad_xbuffer; delete [] grad_xbuffer;
}
grad_buffer_width = w; grad_buffer_width = w;
@ -524,9 +520,8 @@ void BImageControl::getGradientBuffers(unsigned int w,
} }
if (h > grad_buffer_height) { if (h > grad_buffer_height) {
if (grad_ybuffer) { if (grad_ybuffer)
delete [] grad_ybuffer; delete [] grad_ybuffer;
}
grad_buffer_height = h; grad_buffer_height = h;

View file

@ -116,8 +116,6 @@ void BTexture::setDescription(const string &d) {
addTexture(BTexture::PipeCross); addTexture(BTexture::PipeCross);
else if (descr.find("elliptic") != string::npos) else if (descr.find("elliptic") != string::npos)
addTexture(BTexture::Elliptic); addTexture(BTexture::Elliptic);
else if (descr.find("diagonal") != string::npos)
addTexture(BTexture::Diagonal);
else if (descr.find("horizontal") != string::npos) else if (descr.find("horizontal") != string::npos)
addTexture(BTexture::Horizontal); addTexture(BTexture::Horizontal);
else if (descr.find("vertical") != string::npos) else if (descr.find("vertical") != string::npos)
@ -128,9 +126,7 @@ void BTexture::setDescription(const string &d) {
addTexture(BTexture::Solid); addTexture(BTexture::Solid);
} }
if (descr.find("raised") != string::npos) if (descr.find("sunken") != string::npos)
addTexture(BTexture::Raised);
else if (descr.find("sunken") != string::npos)
addTexture(BTexture::Sunken); addTexture(BTexture::Sunken);
else if (descr.find("flat") != string::npos) else if (descr.find("flat") != string::npos)
addTexture(BTexture::Flat); addTexture(BTexture::Flat);

View file

@ -39,6 +39,8 @@ extern "C" {
#endif // HAVE_STDIO_H #endif // HAVE_STDIO_H
} }
#include <cctype>
#include "../src/i18n.hh" #include "../src/i18n.hh"
#include "../src/GCCache.hh" #include "../src/GCCache.hh"
#include "../src/Texture.hh" #include "../src/Texture.hh"
@ -51,8 +53,6 @@ I18n i18n;
bsetroot::bsetroot(int argc, char **argv, char *dpy_name) bsetroot::bsetroot(int argc, char **argv, char *dpy_name)
: BaseDisplay(argv[0], dpy_name) { : BaseDisplay(argv[0], dpy_name) {
grad = fore = back = (char *) 0;
bool mod = False, sol = False, grd = False; bool mod = False, sol = False, grd = False;
int mod_x = 0, mod_y = 0; int mod_x = 0, mod_y = 0;
@ -115,9 +115,12 @@ bsetroot::bsetroot(int argc, char **argv, char *dpy_name)
for (unsigned int s = 0; s < getNumberOfScreens(); ++s) for (unsigned int s = 0; s < getNumberOfScreens(); ++s)
img_ctrl[s] = new BImageControl(this, getScreenInfo(s), True); img_ctrl[s] = new BImageControl(this, getScreenInfo(s), True);
if (sol && fore) solid(); if (sol && ! fore.empty())
else if (mod && mod_x && mod_y && fore && back) modula(mod_x, mod_y); solid();
else if (grd && grad && fore && back) gradient(); 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(); else usage();
} }
@ -289,8 +292,31 @@ void bsetroot::modula(int x, int y) {
void bsetroot::gradient(void) { 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++) { 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); const ScreenInfo *screen_info = getScreenInfo(screen);
texture.setColor(BColor(fore, this, screen)); texture.setColor(BColor(fore, this, screen));

View file

@ -27,12 +27,13 @@
#include "../src/BaseDisplay.hh" #include "../src/BaseDisplay.hh"
#include "../src/Image.hh" #include "../src/Image.hh"
#include <string>
class bsetroot : public BaseDisplay { class bsetroot : public BaseDisplay {
private: private:
BImageControl **img_ctrl; BImageControl **img_ctrl;
char *fore, *back, *grad; std::string fore, back, grad;
// no copying!! // no copying!!
bsetroot(const bsetroot &); bsetroot(const bsetroot &);