summaryrefslogtreecommitdiff
path: root/ui/qt/color_utils.cpp
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2015-12-31 20:14:08 -0800
committerGuy Harris <guy@alum.mit.edu>2016-01-01 04:15:29 +0000
commitee9f102aa9ec36b28992512d840f971be4eba571 (patch)
tree8251e2c26ba9f6c3680633a03901dd386c3d349d /ui/qt/color_utils.cpp
parent93f9416c3660b87896e8b59a4d952fb851002bb5 (diff)
downloadwireshark-ee9f102aa9ec36b28992512d840f971be4eba571.tar.gz
No need for toolkit-dependent color initialization.
We're not allocating colors ourselves in GTK+ (and haven't been doing so since at least 1.12), and all color_t values are valid colors, so we don't need any toolkit-specific processing to fill in a color_t. While we're at it, catch read errors when reading color filter files. Change-Id: Ieb520d141cf15e371a31a01459d466c95ba2209b Reviewed-on: https://code.wireshark.org/review/12985 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'ui/qt/color_utils.cpp')
-rw-r--r--ui/qt/color_utils.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/ui/qt/color_utils.cpp b/ui/qt/color_utils.cpp
index e6576b0938..204aa59f80 100644
--- a/ui/qt/color_utils.cpp
+++ b/ui/qt/color_utils.cpp
@@ -54,8 +54,21 @@ ColorUtils::ColorUtils(QObject *parent) :
{
}
+//
+// A color_t has RGB values in [0,65535].
+// Qt RGB colors have RGB values in [0,255].
+//
+// 65535/255 = 257 = 0x0101, so converting from [0,255] to
+// [0,65535] involves just shifting the 8-bit value left 8 bits
+// and ORing them together.
+//
+// Converting from [0,65535] to [0,255] without rounding involves
+// just shifting the 16-bit value right 8 bits; I guess you could
+// round them by adding 0x80 to the value before shifting.
+//
QColor ColorUtils::fromColorT (const color_t *color) {
if (!color) return QColor();
+ // Convert [0,65535] values to [0,255] values
return QColor(color->red >> 8, color->green >> 8, color->blue >> 8);
}
@@ -67,6 +80,8 @@ QColor ColorUtils::fromColorT(color_t color)
const color_t ColorUtils::toColorT(const QColor color)
{
color_t colort;
+
+ // Convert [0,255] values to [0,65535] values
colort.red = (color.red() << 8) | color.red();
colort.green = (color.green() << 8) | color.green();
colort.blue = (color.blue() << 8) | color.blue();