summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-07-17 10:34:41 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-07-17 10:34:41 -0600
commit41a2d518d0ad7c18a274841234abf1dee3ff6517 (patch)
treef572a97be529f04cf3b64a125243fb7e33d77bed
parent78b05ab186731b3c0abfa05bbe7a7328e2098c0e (diff)
downloadnuttx-41a2d518d0ad7c18a274841234abf1dee3ff6517.tar.gz
nuttx-41a2d518d0ad7c18a274841234abf1dee3ff6517.tar.bz2
nuttx-41a2d518d0ad7c18a274841234abf1dee3ff6517.zip
NxWidgets::CImage: Cannot use NxWidgets::CGraphicsPort:drawBitmapGreyScale() because it does not respect transparent or background colors in its current form. The end result is that makes the image background grey as well as the image
-rw-r--r--NxWidgets/libnxwidgets/src/cimage.cxx41
1 files changed, 29 insertions, 12 deletions
diff --git a/NxWidgets/libnxwidgets/src/cimage.cxx b/NxWidgets/libnxwidgets/src/cimage.cxx
index 713078f22..291552217 100644
--- a/NxWidgets/libnxwidgets/src/cimage.cxx
+++ b/NxWidgets/libnxwidgets/src/cimage.cxx
@@ -273,30 +273,47 @@ void CImage::drawContents(CGraphicsPort *port, bool selected)
return;
}
- // Replace any transparent pixels with the background color.
- // Then we can use the faster opaque drawBitmap() function.
+ // Pre-process special pixel values... Then we can use the faster
+ // opaque drawBitmap() function.
ptr = &buffer[m_origin.x];
for (int i = 0; i < nLeftPixels; i++, ptr++)
{
+ // Replace any transparent pixels with the background color.
+
if (*ptr == CONFIG_NXWIDGETS_TRANSPARENT_COLOR)
{
*ptr = backColor;
}
+
+ // Convert pixels (other than the background color) to grey
+ // scale if the image is disabled. We can't use
+ // CGraphicsPort::drawBitmapGreyColor because it does not
+ // (yet) understand transparent pixels and has no idea what it
+ // should do with background colors.
+
+ else if (*ptr != backColor && !isEnabled())
+ {
+ // Get the next RGB pixel and break out the individual
+ // components
+
+ nxwidget_pixel_t rgb = *ptr;
+ nxwidget_pixel_t r = RGB2RED(rgb);
+ nxwidget_pixel_t g = RGB2GREEN(rgb);
+ nxwidget_pixel_t b = RGB2BLUE(rgb);
+
+ // A truly accurate greyscale conversion would be complex.
+ // Let's just average.
+
+ nxwidget_pixel_t avg = (r + g + b) / 3;
+ *ptr = MKRGB(avg, avg, avg);
+ }
}
// And put these on the display
- if (isEnabled())
- {
- port->drawBitmap(rect.getX(), destRow, rect.getWidth(), 1,
- &bitmap, 0, 0);
- }
- else
- {
- port->drawBitmapGreyScale(rect.getX(), destRow,
- rect.getWidth(), 1, &bitmap, 0, 0);
- }
+ port->drawBitmap(rect.getX(), destRow, rect.getWidth(), 1,
+ &bitmap, 0, 0);
}
}