Commit 1603369c authored by JP Dinger's avatar JP Dinger

Skins2: x11_display: Replace PUT_PIXEL and BLEND_PIXEL macros with templates....

Skins2: x11_display: Replace PUT_PIXEL and BLEND_PIXEL macros with templates. Could use more testing and possibly more refactoring.
parent bd76a752
...@@ -17,9 +17,9 @@ ...@@ -17,9 +17,9 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License along
* along with this program; if not, write to the Free Software * with this program; if not, write to the Free Software Foundation, Inc.,
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/ *****************************************************************************/
#ifdef X11_SKINS #ifdef X11_SKINS
...@@ -31,24 +31,27 @@ ...@@ -31,24 +31,27 @@
#include "x11_display.hpp" #include "x11_display.hpp"
#include "../src/logger.hpp" #include "../src/logger.hpp"
// Macro to compute a pixel value template<class type> type X11Display::putPixel(type r, type g, type b) const
#define PUT_PIXEL(value, r, g, b, type) \ {
value = \ return ( (r >> m_redRightShift) << m_redLeftShift ) |
( ((type)r >> m_redRightShift) << m_redLeftShift ) | \ ( (g >> m_greenRightShift) << m_greenLeftShift ) |
( ((type)g >> m_greenRightShift) << m_greenLeftShift ) | \ ( (b >> m_blueRightShift) << m_blueLeftShift );
( ((type)b >> m_blueRightShift) << m_blueLeftShift ); }
// Macro to blend a pixel with another color template<class type>
#define BLEND_PIXEL(value, r, g, b, a, type) \ type X11Display::blendPixel(type v,type r, type g, type b, type a) const
uint16_t temp; \ {
temp = ((uint8_t)((value >> m_redLeftShift) << m_redRightShift)); \ uint16_t temp;
uint8_t red = r + ( temp * (255 - a) ) / 255; \
temp = ((uint8_t)((value >> m_greenLeftShift) << m_greenRightShift)); \ temp = ((uint8_t)((v >> m_redLeftShift) << m_redRightShift));
uint8_t green = g + ( temp * (255 - a) ) / 255; \ uint8_t red = r + ( temp * (255 - a) ) / 255;
temp = ((uint8_t)((value >> m_blueLeftShift) << m_blueRightShift)); \ temp = ((uint8_t)((v >> m_greenLeftShift) << m_greenRightShift));
uint8_t blue = b + ( temp * (255 - a) ) / 255; \ uint8_t green = g + ( temp * (255 - a) ) / 255;
PUT_PIXEL(value, red, green, blue, type) temp = ((uint8_t)((v >> m_blueLeftShift) << m_blueRightShift));
uint8_t blue = b + ( temp * (255 - a) ) / 255;
return putPixel<type>(red,green,blue);
}
X11Display::X11Display( intf_thread_t *pIntf ): SkinObject( pIntf ), X11Display::X11Display( intf_thread_t *pIntf ): SkinObject( pIntf ),
m_mainWindow( 0 ), m_gc( NULL ), m_colormap( 0 ) m_mainWindow( 0 ), m_gc( NULL ), m_colormap( 0 )
...@@ -287,11 +290,7 @@ void X11Display::getShifts( uint32_t mask, int &rLeftShift, ...@@ -287,11 +290,7 @@ void X11Display::getShifts( uint32_t mask, int &rLeftShift,
void X11Display::blendPixel8( uint8_t *pPixel, uint8_t r, uint8_t g, void X11Display::blendPixel8( uint8_t *pPixel, uint8_t r, uint8_t g,
uint8_t b, uint8_t a ) const uint8_t b, uint8_t a ) const
{ {
uint8_t value = 255 - *pPixel; *pPixel = 255 - blendPixel<uint8_t>(255 - *pPixel,r,g,b,a);
BLEND_PIXEL(value, r, g, b, a, uint8_t)
*pPixel = 255 - value;
} }
...@@ -300,7 +299,7 @@ void X11Display::blendPixel16MSB( uint8_t *pPixel, uint8_t r, uint8_t g, ...@@ -300,7 +299,7 @@ void X11Display::blendPixel16MSB( uint8_t *pPixel, uint8_t r, uint8_t g,
{ {
uint16_t value = pPixel[1] | pPixel[0] << 8; uint16_t value = pPixel[1] | pPixel[0] << 8;
BLEND_PIXEL(value, r, g, b, a, uint16_t) value = blendPixel<uint16_t>(value,r,g,b,a);
pPixel[1] = value; value >>= 8; pPixel[1] = value; value >>= 8;
pPixel[0] = value; pPixel[0] = value;
...@@ -312,7 +311,7 @@ void X11Display::blendPixel16LSB( uint8_t *pPixel, uint8_t r, uint8_t g, ...@@ -312,7 +311,7 @@ void X11Display::blendPixel16LSB( uint8_t *pPixel, uint8_t r, uint8_t g,
{ {
uint16_t value = pPixel[0] | pPixel[1] << 8; uint16_t value = pPixel[0] | pPixel[1] << 8;
BLEND_PIXEL(value, r, g, b, a, uint16_t) value = blendPixel<uint16_t>(value,r,g,b,a);
pPixel[0] = value; value >>= 8; pPixel[0] = value; value >>= 8;
pPixel[1] = value; pPixel[1] = value;
...@@ -325,7 +324,7 @@ void X11Display::blendPixel32MSB( uint8_t *pPixel, uint8_t r, uint8_t g, ...@@ -325,7 +324,7 @@ void X11Display::blendPixel32MSB( uint8_t *pPixel, uint8_t r, uint8_t g,
uint32_t value = pPixel[3] | pPixel[2] << 8 | pPixel[1] << 16 | uint32_t value = pPixel[3] | pPixel[2] << 8 | pPixel[1] << 16 |
pPixel[0] << 24; pPixel[0] << 24;
BLEND_PIXEL(value, r, g, b, a, uint32_t) value = blendPixel<uint32_t>(value,r,g,b,a);
pPixel[3] = value; value >>= 8; pPixel[3] = value; value >>= 8;
pPixel[2] = value; value >>= 8; pPixel[2] = value; value >>= 8;
...@@ -340,7 +339,7 @@ void X11Display::blendPixel32LSB( uint8_t *pPixel, uint8_t r, uint8_t g, ...@@ -340,7 +339,7 @@ void X11Display::blendPixel32LSB( uint8_t *pPixel, uint8_t r, uint8_t g,
uint32_t value = pPixel[0] | pPixel[1] << 8 | pPixel[2] << 16 | uint32_t value = pPixel[0] | pPixel[1] << 8 | pPixel[2] << 16 |
pPixel[3] << 24; pPixel[3] << 24;
BLEND_PIXEL(value, r, g, b, a, uint32_t) value = blendPixel<uint32_t>(value,r,g,b,a);
pPixel[0] = value; value >>= 8; pPixel[0] = value; value >>= 8;
pPixel[1] = value; value >>= 8; pPixel[1] = value; value >>= 8;
...@@ -352,20 +351,14 @@ void X11Display::blendPixel32LSB( uint8_t *pPixel, uint8_t r, uint8_t g, ...@@ -352,20 +351,14 @@ void X11Display::blendPixel32LSB( uint8_t *pPixel, uint8_t r, uint8_t g,
void X11Display::putPixel8( uint8_t *pPixel, uint8_t r, uint8_t g, void X11Display::putPixel8( uint8_t *pPixel, uint8_t r, uint8_t g,
uint8_t b, uint8_t a ) const uint8_t b, uint8_t a ) const
{ {
uint8_t value = 255 - *pPixel; *pPixel = 255 - putPixel<uint8_t>(r,g,b);
PUT_PIXEL(value, r, g, b, uint8_t)
*pPixel = 255 - value;
} }
void X11Display::putPixel16MSB( uint8_t *pPixel, uint8_t r, uint8_t g, void X11Display::putPixel16MSB( uint8_t *pPixel, uint8_t r, uint8_t g,
uint8_t b, uint8_t a ) const uint8_t b, uint8_t a ) const
{ {
uint16_t value = pPixel[1] | pPixel[0] << 8; uint16_t value = putPixel<uint16_t>(r, g, b);
PUT_PIXEL(value, r, g, b, uint16_t)
pPixel[1] = value; value >>= 8; pPixel[1] = value; value >>= 8;
pPixel[0] = value; pPixel[0] = value;
...@@ -375,10 +368,7 @@ void X11Display::putPixel16MSB( uint8_t *pPixel, uint8_t r, uint8_t g, ...@@ -375,10 +368,7 @@ void X11Display::putPixel16MSB( uint8_t *pPixel, uint8_t r, uint8_t g,
void X11Display::putPixel16LSB( uint8_t *pPixel, uint8_t r, uint8_t g, void X11Display::putPixel16LSB( uint8_t *pPixel, uint8_t r, uint8_t g,
uint8_t b, uint8_t a ) const uint8_t b, uint8_t a ) const
{ {
uint16_t value = pPixel[0] | pPixel[1] << 8; uint16_t value = putPixel<uint16_t>(r,g,b);
PUT_PIXEL(value, r, g, b, uint16_t)
pPixel[0] = value; value >>= 8; pPixel[0] = value; value >>= 8;
pPixel[1] = value; pPixel[1] = value;
} }
...@@ -387,10 +377,7 @@ void X11Display::putPixel16LSB( uint8_t *pPixel, uint8_t r, uint8_t g, ...@@ -387,10 +377,7 @@ void X11Display::putPixel16LSB( uint8_t *pPixel, uint8_t r, uint8_t g,
void X11Display::putPixel32MSB( uint8_t *pPixel, uint8_t r, uint8_t g, void X11Display::putPixel32MSB( uint8_t *pPixel, uint8_t r, uint8_t g,
uint8_t b, uint8_t a ) const uint8_t b, uint8_t a ) const
{ {
uint32_t value = pPixel[3] | pPixel[2] << 8 | pPixel[1] << 16 | uint32_t value = putPixel<uint32_t>(r,g,b);
pPixel[0] << 24;
PUT_PIXEL(value, r, g, b, uint32_t)
pPixel[3] = value; value >>= 8; pPixel[3] = value; value >>= 8;
pPixel[2] = value; value >>= 8; pPixel[2] = value; value >>= 8;
...@@ -402,10 +389,7 @@ void X11Display::putPixel32MSB( uint8_t *pPixel, uint8_t r, uint8_t g, ...@@ -402,10 +389,7 @@ void X11Display::putPixel32MSB( uint8_t *pPixel, uint8_t r, uint8_t g,
void X11Display::putPixel32LSB( uint8_t *pPixel, uint8_t r, uint8_t g, void X11Display::putPixel32LSB( uint8_t *pPixel, uint8_t r, uint8_t g,
uint8_t b, uint8_t a ) const uint8_t b, uint8_t a ) const
{ {
uint32_t value = pPixel[0] | pPixel[1] << 8 | pPixel[2] << 16 | uint32_t value = putPixel<uint32_t>(r,g,b);
pPixel[3] << 24;
PUT_PIXEL(value, r, g, b, uint32_t)
pPixel[0] = value; value >>= 8; pPixel[0] = value; value >>= 8;
pPixel[1] = value; value >>= 8; pPixel[1] = value; value >>= 8;
...@@ -417,9 +401,7 @@ void X11Display::putPixel32LSB( uint8_t *pPixel, uint8_t r, uint8_t g, ...@@ -417,9 +401,7 @@ void X11Display::putPixel32LSB( uint8_t *pPixel, uint8_t r, uint8_t g,
unsigned long X11Display::getPixelValue( uint8_t r, uint8_t g, uint8_t b ) unsigned long X11Display::getPixelValue( uint8_t r, uint8_t g, uint8_t b )
const const
{ {
unsigned long value; unsigned long value = putPixel<unsigned long>(r,g,b);
PUT_PIXEL(value, r, g, b, uint32_t)
if( m_pixelSize == 1 ) if( m_pixelSize == 1 )
{ {
......
...@@ -94,6 +94,10 @@ private: ...@@ -94,6 +94,10 @@ private:
/// Pointer on the right implementation of putPixel /// Pointer on the right implementation of putPixel
MakePixelFunc_t putPixelImpl; MakePixelFunc_t putPixelImpl;
template<class type> type putPixel(type r, type g, type b) const;
template<class type>
type blendPixel(type v,type r, type g, type b,type a) const;
/// Calculate shifts from a color mask /// Calculate shifts from a color mask
void getShifts( uint32_t mask, int &rLeftShift, void getShifts( uint32_t mask, int &rLeftShift,
int &rRightShift ) const; int &rRightShift ) const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment