diff options
author | fluxgen <fluxgen> | 2004-10-06 09:30:54 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2004-10-06 09:30:54 (GMT) |
commit | 997d7d72244911c7224775f2e4c0f62a1dcd32ef (patch) | |
tree | 766e3ad980c0d1476cd51c3ce7feccbf2b46b73c | |
parent | fa8c8699d412dce1536839400587d1e74d769718 (diff) | |
download | fluxbox-997d7d72244911c7224775f2e4c0f62a1dcd32ef.zip fluxbox-997d7d72244911c7224775f2e4c0f62a1dcd32ef.tar.bz2 |
allocate red, green and blue buffers only for gradients
-rw-r--r-- | src/FbTk/TextureRender.cc | 73 | ||||
-rw-r--r-- | src/FbTk/TextureRender.hh | 4 |
2 files changed, 43 insertions, 34 deletions
diff --git a/src/FbTk/TextureRender.cc b/src/FbTk/TextureRender.cc index dc51d35..c278c2a 100644 --- a/src/FbTk/TextureRender.cc +++ b/src/FbTk/TextureRender.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: TextureRender.cc,v 1.11 2004/08/31 15:26:39 rathnor Exp $ | 25 | // $Id: TextureRender.cc,v 1.12 2004/10/06 09:30:54 fluxgen Exp $ |
26 | 26 | ||
27 | #include "TextureRender.hh" | 27 | #include "TextureRender.hh" |
28 | 28 | ||
@@ -49,11 +49,13 @@ TextureRender::TextureRender(ImageControl &imgctrl, | |||
49 | control(imgctrl), | 49 | control(imgctrl), |
50 | colors(_colors), | 50 | colors(_colors), |
51 | ncolors(ncolors), | 51 | ncolors(ncolors), |
52 | cpc(imgctrl.colorsPerChannel()), | ||
53 | cpccpc(cpc * cpc), | ||
54 | red(0), green(0), blue(0), | ||
55 | width(static_cast<signed>((w > 0 ? w : 1))), height(static_cast<signed>(h > 0 ? h : 1)), | ||
52 | xtable(0), ytable(0) { | 56 | xtable(0), ytable(0) { |
53 | 57 | ||
54 | _FB_USES_NLS; | 58 | _FB_USES_NLS; |
55 | width = ((signed) w > 0) ? w : 1; | ||
56 | height = ((signed) h > 0) ? h : 1; | ||
57 | // clamp to "normal" size | 59 | // clamp to "normal" size |
58 | if (width > 3200) { | 60 | if (width > 3200) { |
59 | cerr<<"TextureRender: "<<_FBTKTEXT(Error, BigWidth, "Warning! Width > 3200 setting Width = 3200", "Image width seems too big, clamping")<<endl; | 61 | cerr<<"TextureRender: "<<_FBTKTEXT(Error, BigWidth, "Warning! Width > 3200 setting Width = 3200", "Image width seems too big, clamping")<<endl; |
@@ -65,30 +67,6 @@ TextureRender::TextureRender(ImageControl &imgctrl, | |||
65 | height = 3200; | 67 | height = 3200; |
66 | } | 68 | } |
67 | 69 | ||
68 | red = new(nothrow) unsigned char[width * height]; | ||
69 | if (red == 0) { | ||
70 | char sbuf[128]; | ||
71 | sprintf(sbuf, "%d", width*height); | ||
72 | throw string("TextureRender::TextureRender(): " + string(_FBTKTEXT(Error, OutOfMemoryRed, "Out of memory while allocating red buffer.", "")) + string(sbuf)); | ||
73 | } | ||
74 | |||
75 | |||
76 | green = new(nothrow) unsigned char[width * height]; | ||
77 | if (green == 0) { | ||
78 | char sbuf[128]; | ||
79 | sprintf(sbuf, "%d", width*height); | ||
80 | throw string("TextureRender::TextureRender(): " +string(_FBTKTEXT(Error, OutOfMemoryGreen, "Out of memory while allocating green buffer.", ""))+ string(sbuf)); | ||
81 | } | ||
82 | |||
83 | blue = new(nothrow) unsigned char[width * height]; | ||
84 | if (blue == 0) { | ||
85 | char sbuf[128]; | ||
86 | sprintf(sbuf, "%d", width*height); | ||
87 | throw string("TextureRender::TextureRender(): " +string(_FBTKTEXT(Error, OutOfMemoryBlue, "Out of memory while allocating blue buffer.", ""))+ string(sbuf)); | ||
88 | } | ||
89 | |||
90 | cpc = imgctrl.colorsPerChannel(); | ||
91 | cpccpc = cpc * cpc; | ||
92 | 70 | ||
93 | imgctrl.colorTables(&red_table, &green_table, &blue_table, | 71 | imgctrl.colorTables(&red_table, &green_table, &blue_table, |
94 | &red_offset, &green_offset, &blue_offset, | 72 | &red_offset, &green_offset, &blue_offset, |
@@ -98,9 +76,9 @@ TextureRender::TextureRender(ImageControl &imgctrl, | |||
98 | 76 | ||
99 | 77 | ||
100 | TextureRender::~TextureRender() { | 78 | TextureRender::~TextureRender() { |
101 | delete [] red; | 79 | if (red != 0) delete [] red; |
102 | delete [] green; | 80 | if (green != 0) delete [] green; |
103 | delete [] blue; | 81 | if (blue != 0) delete [] blue; |
104 | } | 82 | } |
105 | 83 | ||
106 | 84 | ||
@@ -111,12 +89,39 @@ Pixmap TextureRender::render(const FbTk::Texture &texture) { | |||
111 | return ParentRelative; | 89 | return ParentRelative; |
112 | else if (texture.type() & FbTk::Texture::SOLID) | 90 | else if (texture.type() & FbTk::Texture::SOLID) |
113 | return renderSolid(texture); | 91 | return renderSolid(texture); |
114 | else if (texture.type() & FbTk::Texture::GRADIENT) | 92 | else if (texture.type() & FbTk::Texture::GRADIENT) { |
93 | allocateColorTables(); | ||
115 | return renderGradient(texture); | 94 | return renderGradient(texture); |
95 | } | ||
116 | 96 | ||
117 | return None; | 97 | return None; |
118 | } | 98 | } |
119 | 99 | ||
100 | void TextureRender::allocateColorTables() { | ||
101 | red = new(nothrow) unsigned char[width * height]; | ||
102 | if (red == 0) { | ||
103 | char sbuf[128]; | ||
104 | sprintf(sbuf, "%d", width*height); | ||
105 | throw string("TextureRender::TextureRender(): " + string(_FBTKTEXT(Error, OutOfMemoryRed, "Out of memory while allocating red buffer.", "")) + string(sbuf)); | ||
106 | } | ||
107 | |||
108 | |||
109 | green = new(nothrow) unsigned char[width * height]; | ||
110 | if (green == 0) { | ||
111 | char sbuf[128]; | ||
112 | sprintf(sbuf, "%d", width*height); | ||
113 | throw string("TextureRender::TextureRender(): " +string(_FBTKTEXT(Error, OutOfMemoryGreen, "Out of memory while allocating green buffer.", ""))+ string(sbuf)); | ||
114 | } | ||
115 | |||
116 | blue = new(nothrow) unsigned char[width * height]; | ||
117 | if (blue == 0) { | ||
118 | char sbuf[128]; | ||
119 | sprintf(sbuf, "%d", width*height); | ||
120 | throw string("TextureRender::TextureRender(): " +string(_FBTKTEXT(Error, OutOfMemoryBlue, "Out of memory while allocating blue buffer.", ""))+ string(sbuf)); | ||
121 | } | ||
122 | |||
123 | |||
124 | } | ||
120 | 125 | ||
121 | Pixmap TextureRender::renderSolid(const FbTk::Texture &texture) { | 126 | Pixmap TextureRender::renderSolid(const FbTk::Texture &texture) { |
122 | 127 | ||
@@ -300,7 +305,7 @@ XImage *TextureRender::renderXImage() { | |||
300 | 305 | ||
301 | o = image->bits_per_pixel + ((image->byte_order == MSBFirst) ? 1 : 0); | 306 | o = image->bits_per_pixel + ((image->byte_order == MSBFirst) ? 1 : 0); |
302 | 307 | ||
303 | if (control.doDither() && width > 1 && height > 1) { | 308 | if (control.doDither()) { |
304 | unsigned char dither4[4][4] = { | 309 | unsigned char dither4[4][4] = { |
305 | {0, 4, 1, 5}, | 310 | {0, 4, 1, 5}, |
306 | {6, 2, 7, 3}, | 311 | {6, 2, 7, 3}, |
@@ -564,7 +569,9 @@ XImage *TextureRender::renderXImage() { | |||
564 | XDestroyImage(image); | 569 | XDestroyImage(image); |
565 | return (XImage *) 0; | 570 | return (XImage *) 0; |
566 | } | 571 | } |
567 | } else { | 572 | } else { // end do dither |
573 | |||
574 | // no dither: | ||
568 | switch (control.visual()->c_class) { | 575 | switch (control.visual()->c_class) { |
569 | case StaticColor: | 576 | case StaticColor: |
570 | case PseudoColor: | 577 | case PseudoColor: |
diff --git a/src/FbTk/TextureRender.hh b/src/FbTk/TextureRender.hh index f07a5c7..0139dcb 100644 --- a/src/FbTk/TextureRender.hh +++ b/src/FbTk/TextureRender.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: TextureRender.hh,v 1.2 2003/04/28 22:27:29 fluxgen Exp $ | 25 | // $Id: TextureRender.hh,v 1.3 2004/10/06 09:30:54 fluxgen Exp $ |
26 | 26 | ||
27 | #ifndef FBTK_TEXTURRENDER_HH | 27 | #ifndef FBTK_TEXTURRENDER_HH |
28 | #define FBTK_TEXTURRENDER_HH | 28 | #define FBTK_TEXTURRENDER_HH |
@@ -54,6 +54,8 @@ public: | |||
54 | /// scales and renders a pixmap | 54 | /// scales and renders a pixmap |
55 | Pixmap renderPixmap(const FbTk::Texture &src_texture); | 55 | Pixmap renderPixmap(const FbTk::Texture &src_texture); |
56 | private: | 56 | private: |
57 | /// allocates red, green and blue for gradient rendering | ||
58 | void allocateColorTables(); | ||
57 | /** | 59 | /** |
58 | Render to pixmap | 60 | Render to pixmap |
59 | @return rendered pixmap | 61 | @return rendered pixmap |