all repos — fluxbox @ 997d7d72244911c7224775f2e4c0f62a1dcd32ef

custom fork of the fluxbox windowmanager

allocate red, green and blue buffers only for gradients
fluxgen fluxgen
commit

997d7d72244911c7224775f2e4c0f62a1dcd32ef

parent

fa8c8699d412dce1536839400587d1e74d769718

2 files changed, 43 insertions(+), 34 deletions(-)

jump to
M src/FbTk/TextureRender.ccsrc/FbTk/TextureRender.cc

@@ -22,7 +22,7 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING

// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: TextureRender.cc,v 1.11 2004/08/31 15:26:39 rathnor Exp $ +// $Id: TextureRender.cc,v 1.12 2004/10/06 09:30:54 fluxgen Exp $ #include "TextureRender.hh"

@@ -49,11 +49,13 @@ XColor *_colors, size_t num_colors):

control(imgctrl), colors(_colors), ncolors(ncolors), + cpc(imgctrl.colorsPerChannel()), + cpccpc(cpc * cpc), + red(0), green(0), blue(0), + width(static_cast<signed>((w > 0 ? w : 1))), height(static_cast<signed>(h > 0 ? h : 1)), xtable(0), ytable(0) { _FB_USES_NLS; - width = ((signed) w > 0) ? w : 1; - height = ((signed) h > 0) ? h : 1; // clamp to "normal" size if (width > 3200) { cerr<<"TextureRender: "<<_FBTKTEXT(Error, BigWidth, "Warning! Width > 3200 setting Width = 3200", "Image width seems too big, clamping")<<endl;

@@ -65,6 +67,37 @@ cerr<<"TextureRender: "<<_FBTKTEXT(Error, BigHeight, "Warning! Height > 3200 setting Height = 3200", "Image height seems too big, clamping")<<endl;

height = 3200; } + + imgctrl.colorTables(&red_table, &green_table, &blue_table, + &red_offset, &green_offset, &blue_offset, + &red_bits, &green_bits, &blue_bits); + +} + + +TextureRender::~TextureRender() { + if (red != 0) delete [] red; + if (green != 0) delete [] green; + if (blue != 0) delete [] blue; +} + + +Pixmap TextureRender::render(const FbTk::Texture &texture) { + if (texture.pixmap().drawable() != 0) + return renderPixmap(texture); + else if (texture.type() & FbTk::Texture::PARENTRELATIVE) + return ParentRelative; + else if (texture.type() & FbTk::Texture::SOLID) + return renderSolid(texture); + else if (texture.type() & FbTk::Texture::GRADIENT) { + allocateColorTables(); + return renderGradient(texture); + } + + return None; +} + +void TextureRender::allocateColorTables() { red = new(nothrow) unsigned char[width * height]; if (red == 0) { char sbuf[128];

@@ -87,36 +120,8 @@ sprintf(sbuf, "%d", width*height);

throw string("TextureRender::TextureRender(): " +string(_FBTKTEXT(Error, OutOfMemoryBlue, "Out of memory while allocating blue buffer.", ""))+ string(sbuf)); } - cpc = imgctrl.colorsPerChannel(); - cpccpc = cpc * cpc; - imgctrl.colorTables(&red_table, &green_table, &blue_table, - &red_offset, &green_offset, &blue_offset, - &red_bits, &green_bits, &blue_bits); - -} - - -TextureRender::~TextureRender() { - delete [] red; - delete [] green; - delete [] blue; } - - -Pixmap TextureRender::render(const FbTk::Texture &texture) { - if (texture.pixmap().drawable() != 0) - return renderPixmap(texture); - else if (texture.type() & FbTk::Texture::PARENTRELATIVE) - return ParentRelative; - else if (texture.type() & FbTk::Texture::SOLID) - return renderSolid(texture); - else if (texture.type() & FbTk::Texture::GRADIENT) - return renderGradient(texture); - - return None; -} - Pixmap TextureRender::renderSolid(const FbTk::Texture &texture) {

@@ -300,7 +305,7 @@ unsigned long pixel;

o = image->bits_per_pixel + ((image->byte_order == MSBFirst) ? 1 : 0); - if (control.doDither() && width > 1 && height > 1) { + if (control.doDither()) { unsigned char dither4[4][4] = { {0, 4, 1, 5}, {6, 2, 7, 3},

@@ -564,7 +569,9 @@ delete [] d;

XDestroyImage(image); return (XImage *) 0; } -} else { +} else { // end do dither + + // no dither: switch (control.visual()->c_class) { case StaticColor: case PseudoColor:
M src/FbTk/TextureRender.hhsrc/FbTk/TextureRender.hh

@@ -22,7 +22,7 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING

// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: TextureRender.hh,v 1.2 2003/04/28 22:27:29 fluxgen Exp $ +// $Id: TextureRender.hh,v 1.3 2004/10/06 09:30:54 fluxgen Exp $ #ifndef FBTK_TEXTURRENDER_HH #define FBTK_TEXTURRENDER_HH

@@ -54,6 +54,8 @@ Pixmap renderGradient(const FbTk::Texture &src_texture);

/// scales and renders a pixmap Pixmap renderPixmap(const FbTk::Texture &src_texture); private: + /// allocates red, green and blue for gradient rendering + void allocateColorTables(); /** Render to pixmap @return rendered pixmap