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) {
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];
@ -66,18 +66,18 @@ BImage::BImage(BImageControl *c, unsigned int w, unsigned int h) {
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;
}
@ -103,8 +103,7 @@ Pixmap BImage::render_solid(const BTexture &texture) {
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);
}
@ -159,7 +158,7 @@ Pixmap BImage::render_solid(const BTexture &texture) {
Pixmap BImage::render_gradient(const BTexture &texture) {
int inverted = 0;
bool inverted = False;
interlaced = texture.texture() & BTexture::Interlaced;
@ -167,12 +166,12 @@ Pixmap BImage::render_gradient(const BTexture &texture) {
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);
@ -191,9 +190,7 @@ Pixmap BImage::render_gradient(const BTexture &texture) {
if (inverted) invert();
Pixmap pixmap = renderPixmap();
return pixmap;
return renderPixmap();
}
@ -461,6 +458,8 @@ XImage *BImage::renderXImage(void) {
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:
@ -478,23 +477,18 @@ XImage *BImage::renderXImage(void) {
}
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]];
@ -542,15 +536,20 @@ XImage *BImage::renderXImage(void) {
break;
default:
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;
}
@ -571,7 +570,9 @@ Pixmap BImage::renderPixmap(void) {
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;

View file

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

View file

@ -65,8 +65,7 @@ BImageControl *ctrl = 0;
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;
@ -364,8 +363,7 @@ BImageControl::~BImageControl(void) {
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);
@ -381,9 +379,8 @@ BImageControl::~BImageControl(void) {
//#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) {
@ -405,8 +402,8 @@ Pixmap BImageControl::searchCache(const unsigned int width,
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++;
@ -514,9 +511,8 @@ void BImageControl::getGradientBuffers(unsigned int w,
unsigned int **ybuf)
{
if (w > grad_buffer_width) {
if (grad_xbuffer) {
if (grad_xbuffer)
delete [] grad_xbuffer;
}
grad_buffer_width = w;
@ -524,9 +520,8 @@ void BImageControl::getGradientBuffers(unsigned int w,
}
if (h > grad_buffer_height) {
if (grad_ybuffer) {
if (grad_ybuffer)
delete [] grad_ybuffer;
}
grad_buffer_height = h;

View file

@ -116,8 +116,6 @@ void BTexture::setDescription(const string &d) {
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)
@ -128,9 +126,7 @@ void BTexture::setDescription(const string &d) {
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);

View file

@ -39,6 +39,8 @@ extern "C" {
#endif // HAVE_STDIO_H
}
#include <cctype>
#include "../src/i18n.hh"
#include "../src/GCCache.hh"
#include "../src/Texture.hh"
@ -51,8 +53,6 @@ I18n i18n;
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;
@ -115,9 +115,12 @@ bsetroot::bsetroot(int argc, char **argv, char *dpy_name)
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();
}
@ -289,8 +292,31 @@ void bsetroot::modula(int x, int y) {
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));

View file

@ -27,12 +27,13 @@
#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 &);