[education/rkward] rkward/rbackend/rkwarddevice: Allow fully transparent as a color value (useful for gradients)

Thomas Friedrichsmeier null at kde.org
Thu Mar 24 21:02:51 GMT 2022


Git commit 025f0df477185dd710627ac47560e6a3d10cc60d by Thomas Friedrichsmeier.
Committed on 23/03/2022 at 20:27.
Pushed by tfry into branch 'master'.

Allow fully transparent as a color value (useful for gradients)

M  +2    -4    rkward/rbackend/rkwarddevice/rkgraphicsdevice_frontendtransmitter.cpp
M  +2    -4    rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp

https://invent.kde.org/education/rkward/commit/025f0df477185dd710627ac47560e6a3d10cc60d

diff --git a/rkward/rbackend/rkwarddevice/rkgraphicsdevice_frontendtransmitter.cpp b/rkward/rbackend/rkwarddevice/rkgraphicsdevice_frontendtransmitter.cpp
index 39d0ed3f..22cc0734 100644
--- a/rkward/rbackend/rkwarddevice/rkgraphicsdevice_frontendtransmitter.cpp
+++ b/rkward/rbackend/rkwarddevice/rkgraphicsdevice_frontendtransmitter.cpp
@@ -94,8 +94,7 @@ static QRgb readRgb (QDataStream &instream) {
 static QColor readColor (QDataStream &instream) {
 	quint8 r, g, b, a;
 	instream >> r >> g >> b >> a;
-	if (a == 0x00) return QColor ();
-	return QColor (r, g, b, a);
+	return QColor(r, g, b, a);
 }
 
 static QPen readSimplePen (QDataStream &instream) {
@@ -103,7 +102,7 @@ static QPen readSimplePen (QDataStream &instream) {
 	double lwd;
 	qint32 lty;
 	instream >> lwd >> lty;
-	if (!col.isValid () || (lty == -1L)) return QPen (Qt::NoPen);
+	if ((col.alpha() == 0) || (lty == -1L)) return QPen(Qt::NoPen);
 
 	lwd = qMax (double(qreal(1.0)), lwd);	// minimum 1 px as in X11 device
 	QPen ret;
@@ -140,7 +139,6 @@ static QBrush readBrush(QDataStream &instream, RKGraphicsDevice *dev) {
 	instream >> filltype;
 	if (filltype  == ColorFill) {
 		QColor col = readColor(instream);
-		if (!col.isValid()) return QBrush();
 		return QBrush(col);
 	} else {
 		qint16 pattern_num;
diff --git a/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp b/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp
index 63beb698..e5864351 100644
--- a/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp
+++ b/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp
@@ -167,8 +167,7 @@ public:
 
 // I'd love to convert to QColor, directly, but that's in QtGui, not QtCore. QRgb used different byte ordering
 #define WRITE_COLOR_BYTES(col) \
-	if (col == NA_INTEGER) RKD_OUT_STREAM << (quint8) 0xFF << (quint8) 0xFF << (quint8) 0xFF << (quint8) 0x00; \
-	else RKD_OUT_STREAM << (quint8) R_RED (col) << (quint8) R_GREEN (col) << (quint8) R_BLUE (col) << (quint8) R_ALPHA (col)
+	RKD_OUT_STREAM << (quint8) R_RED (col) << (quint8) R_GREEN (col) << (quint8) R_BLUE (col) << (quint8) R_ALPHA (col)
 #define WRITE_HEADER_NUM(x,devnum) \
 	RKD_OUT_STREAM << (qint8) x << (quint8) devnum
 #define WRITE_HEADER(x,dev) \
@@ -467,14 +466,13 @@ static void RKD_Raster (unsigned int *raster, int w, int h, double x, double y,
 	RKGraphicsDataStreamWriteGuard wguard;
 	WRITE_HEADER (RKDRaster, dev);
 
-	int *_raster = reinterpret_cast<int*> (raster);	// shut up warning in WRITE_COLOR_BYTES. It's just four separate bytes, anyway
 	quint32 _w = qMin (w, 1 << 15);	// skip stuff exceeding reasonable limits to keep protocol simple
 	RKD_OUT_STREAM << _w;
 	quint32 _h = qMin (h, 1 << 15);
 	RKD_OUT_STREAM << _h;
 	for (quint32 col = 0; col < _h; ++col) {
 		for (quint32 row = 0; row < _w; ++row) {
-			WRITE_COLOR_BYTES (_raster[(col*_w) + row]);
+			WRITE_COLOR_BYTES (raster[(col*_w) + row]);
 		}
 	}
 	RKD_OUT_STREAM << QRectF (x, y, width, height) << rot << (bool) interpolate;



More information about the rkward-tracker mailing list