Use NxWidgets::CScaledBitmap to scale icons in the NxWM taskbar

This commit is contained in:
Gregory Nutt 2013-10-15 14:29:06 -06:00
parent 341458e123
commit d9d02140d8
8 changed files with 129 additions and 29 deletions

View file

@ -390,4 +390,6 @@
* NxWidgets::CScaledImage: This new class is a wrapper for an class
the exports IBitMap. It will perform scaling via bi-linear interpolation
so that images can be scaled to any size desired (2013-10-15).
* NxWM::CTaskbar:: Can now be configured to scale taskbasr icons using
NxWidgets::CScaledImage (2013-10-15)

22
Kconfig
View file

@ -420,6 +420,28 @@ config NXWM_TASKBAR_WIDTH
Task bar thickness (either vertical or horizontal). Default: 25 + 2*2
endif
config NXWM_TASKBAR_ICONSCALE
bool "Scale Icons"
default n
---help---
Enable scaling of icons in the task bar
if NXWM_TASKBAR_ICONSCALE
config NXWM_TASKBAR_ICONWIDTH
int "Icon Width (pixels)"
default 50
---help---
Scaled width of each taskbar ICON in pixels.
config NXWM_TASKBAR_ICONHEIGHT
int "Icon Height (rows)"
default 42
---help---
Scaled height of each taskbar ICON in pixels.
endif #NXWM_TASKBAR_ICONSCALE
config NXWM_DISABLE_MINIMIZE
bool "Disable Minimize Button"
default n

View file

@ -75,7 +75,7 @@ namespace NXWidgets
FAR IBitmap *m_bitmap; /**< The bitmap that is being scaled */
struct nxgl_size_s m_size; /**< Scaled size of the image */
FAR uint8_t *m_rowCache[2]; /**< Two cached rows of the image */
unsigned int m_row; /**< Row number of the first cached row */
int m_row; /**< Row number of the first cached row */
b16_t m_xScale; /**< X scale factor */
b16_t m_yScale; /**< Y scale factor */
@ -167,7 +167,7 @@ namespace NXWidgets
* @return The bitmap's height (in rows).
*/
inline const nxgl_coord_t getHeight(void) const;
const nxgl_coord_t getHeight(void) const;
/**
* Get the bitmap's width (in bytes).

View file

@ -192,7 +192,7 @@ bool CRlePaletteBitmap::getRun(nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t widt
{
// Check ranges. Casts to unsigned int are ugly but permit one-sided comparisons
if (((unsigned int)x < (unsigned int)width) &&
if (((unsigned int)x < (unsigned int)m_bitmap->width) &&
((unsigned int)(x + width) <= (unsigned int)m_bitmap->width))
{
// Seek to the requested row

View file

@ -81,16 +81,17 @@ CScaledBitmap::CScaledBitmap(IBitmap *bitmap, struct nxgl_size_s &newSize)
// yImage = yRequested * oldHeight / newHeight
// = yRequested * yScale
m_xScale = itob16((uint32_t)m_bitmap->getHeight()) / newSize.h;
m_yScale = itob16((uint32_t)m_bitmap->getHeight()) / newSize.h;
// Allocate and initialize the row cache
size_t stride = bitmap->getStride();
m_rowCache[0] = new uint8_t(stride);
m_rowCache[1] = new uint8_t(stride);
m_rowCache[0] = new uint8_t[stride];
m_rowCache[1] = new uint8_t[stride];
// Read the first two rows into the cache
m_row = m_bitmap->getWidth(); // Set to an impossible value
cacheRows(0);
}
@ -100,6 +101,8 @@ CScaledBitmap::CScaledBitmap(IBitmap *bitmap, struct nxgl_size_s &newSize)
CScaledBitmap::~CScaledBitmap(void)
{
// Delete the allocated row cache memory
if (m_rowCache[0])
{
delete m_rowCache[0];
@ -108,6 +111,13 @@ CScaledBitmap::~CScaledBitmap(void)
if (m_rowCache[1])
{
delete m_rowCache[1];
}
// We are also responsible for deleting the contained IBitmap
if (m_bitmap)
{
delete m_bitmap;
}
}
@ -372,7 +382,7 @@ bool CScaledBitmap::cacheRows(unsigned int row)
row = bitmapHeight - 1;
}
if (!m_bitmap->getRun(0, row, bitmapWidth, &m_rowCache[1]))
if (!m_bitmap->getRun(0, row, bitmapWidth, m_rowCache[1]))
{
gdbg("Failed to read bitmap row %d\n", row);
return false;
@ -391,7 +401,7 @@ bool CScaledBitmap::cacheRows(unsigned int row)
row = bitmapHeight - 1;
}
if (!m_bitmap->getRun(0, row, bitmapWidth, &m_rowCache[0]))
if (!m_bitmap->getRun(0, row, bitmapWidth, m_rowCache[0]))
{
gdbg("Failed to read bitmap row %d\n", row);
return false;
@ -408,7 +418,7 @@ bool CScaledBitmap::cacheRows(unsigned int row)
row = bitmapHeight - 1;
}
if (!m_bitmap->getRun(0, row, bitmapWidth, &m_rowCache[1]))
if (!m_bitmap->getRun(0, row, bitmapWidth, m_rowCache[1]))
{
gdbg("Failed to read bitmap row %d\n", row);
return false;
@ -432,21 +442,33 @@ bool CScaledBitmap::scaleColor(FAR const struct rgbcolor_s &incolor1,
FAR const struct rgbcolor_s &incolor2,
b16_t fraction, FAR struct rgbcolor_s &outcolor)
{
unsigned int red;
unsigned int green;
unsigned int blue;
b16_t remainder = b16ONE - fraction;
red = (unsigned int)incolor1.r * fraction +
(unsigned int)incolor2.r * remainder;
green = (unsigned int)incolor1.g * fraction +
(unsigned int)incolor2.g * remainder;
blue = (unsigned int)incolor1.b * fraction +
(unsigned int)incolor2.b * remainder;
uint8_t component;
b16_t red;
b16_t green;
b16_t blue;
outcolor.r = red < 256 ? red : 255;
outcolor.g = green < 256 ? green : 255;
outcolor.b = blue < 256 ? blue : 255;
// A fraction of < 0.5 would mean to use use mostly color1; a fraction
// greater than 0.5 would men to use mostly color2
b16_t remainder = b16ONE - fraction;
// Interpolate each color value (converting to b15)
red = (b16_t)incolor1.r * remainder + (b16_t)incolor2.r * fraction;
green = (b16_t)incolor1.g * remainder + (b16_t)incolor2.g * fraction;
blue = (b16_t)incolor1.b * remainder + (b16_t)incolor2.b * fraction;
// Return the integer, interpolated values, clipping to the range of
// uint8_t
component = b16toi(red);
outcolor.r = component < 256 ? component : 255;
component = b16toi(green);
outcolor.g = component < 256 ? component : 255;
component = b16toi(blue);
outcolor.b = component < 256 ? component : 255;
return true;
}

View file

@ -92,8 +92,8 @@ namespace NxWM
struct STaskbarSlot
{
IApplication *app; /**< A reference to the icon */
NXWidgets::CImage *image; /**< The icon image that goes with the application */
IApplication *app; /**< A reference to the application */
NXWidgets::CImage *image; /**< The icon image for the application */
};
/**

View file

@ -223,6 +223,24 @@
# define CONFIG_NXWM_TASKBAR_TOP 1
#endif
// Taskbar ICON scaling
#ifdef CONFIG_NXWM_TASKBAR_ICONSCALE
# ifndef CONFIG_NXWM_TASKBAR_ICONWIDTH
# error Scaling requires CONFIG_NXWM_TASKBAR_ICONWIDTH
# define CONFIG_NXWM_TASKBAR_ICONWIDTH 50
# endif
# ifndef CONFIG_NXWM_TASKBAR_ICONHEIGHT
# error Scaling requires CONFIG_NXWM_TASKBAR_ICONHEIGHT
# define CONFIG_NXWM_TASKBAR_ICONHEIGHT 42
# endif
#else
# undef CONFIG_NXWM_TASKBAR_ICONWIDTH
# define CONFIG_NXWM_TASKBAR_ICONWIDTH 25 // Used below
# undef CONFIG_NXWM_TASKBAR_ICONHEIGHT
# define CONFIG_NXWM_TASKBAR_ICONHEIGHT 21 // Used below (NOT)
#endif
/**
* At present, all icons are 25 pixels in "width" and, hence require a
* task bar of at least that size.
@ -230,9 +248,11 @@
#ifndef CONFIG_NXWM_TASKBAR_WIDTH
# if defined(CONFIG_NXWM_TASKBAR_TOP) || defined(CONFIG_NXWM_TASKBAR_BOTTOM)
# define CONFIG_NXWM_TASKBAR_WIDTH (25+2*CONFIG_NXWM_TASKBAR_HSPACING)
# define CONFIG_NXWM_TASKBAR_WIDTH \
(CONFIG_NXWM_TASKBAR_ICONWIDTH+2*CONFIG_NXWM_TASKBAR_HSPACING)
# else
# define CONFIG_NXWM_TASKBAR_WIDTH (25+2*CONFIG_NXWM_TASKBAR_VSPACING)
# define CONFIG_NXWM_TASKBAR_WIDTH \
(CONFIG_NXWM_TASKBAR_ICONWIDTH+2*CONFIG_NXWM_TASKBAR_VSPACING)
# endif
#endif

View file

@ -46,6 +46,7 @@
#include "crect.hxx"
#include "cwidgetcontrol.hxx"
#include "cnxtkwindow.hxx"
#include "cscaledbitmap.hxx"
#include "cwindowmessenger.hxx"
#include "ctaskbar.hxx"
@ -456,12 +457,43 @@ bool CTaskbar::startApplication(IApplication *app, bool minimized)
NXWidgets::IBitmap *bitmap = app->getIcon();
#ifdef CONFIG_NXWM_TASKBAR_ICONSCALE
// Create a CScaledBitmap to scale the bitmap icon
NXWidgets::CScaledBitmap *scaler = (NXWidgets::CScaledBitmap *)0;
if (bitmap)
{
// Create a CScaledBitmap to scale the bitmap icon
struct nxgl_size_s iconSize;
iconSize.w = CONFIG_NXWM_TASKBAR_ICONWIDTH;
iconSize.h = CONFIG_NXWM_TASKBAR_ICONHEIGHT;
scaler = new NXWidgets::CScaledBitmap(bitmap, iconSize);
if (!scaler)
{
return false;
}
}
#endif
// Create a CImage instance to manage the applications icon. Assume the
// minimum size in case no bitmap is provided (bitmap == NULL)
int w = 1;
int h = 1;
#ifdef CONFIG_NXWM_TASKBAR_ICONSCALE
if (scaler)
{
w = scaler->getWidth();
h = scaler->getHeight();
}
NXWidgets::CImage *image =
new NXWidgets::CImage(control, 0, 0, w, h, scaler, 0);
#else
if (bitmap)
{
w = bitmap->getWidth();
@ -471,6 +503,8 @@ bool CTaskbar::startApplication(IApplication *app, bool minimized)
NXWidgets::CImage *image =
new NXWidgets::CImage(control, 0, 0, w, h, bitmap, 0);
#endif
if (!image)
{
return false;
@ -490,8 +524,8 @@ bool CTaskbar::startApplication(IApplication *app, bool minimized)
// the task bar
struct STaskbarSlot slot;
slot.app = app;
slot.image = image;
slot.app = app;
slot.image = image;
m_slots.push_back(slot);
// Initialize the application states