From 41a2d518d0ad7c18a274841234abf1dee3ff6517 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 17 Jul 2014 10:34:41 -0600 Subject: 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 --- NxWidgets/libnxwidgets/src/cimage.cxx | 41 +++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 12 deletions(-) (limited to 'NxWidgets/libnxwidgets') 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); } } -- cgit v1.2.3