[rkward-cvs] SF.net SVN: rkward-code:[4645] branches/development_branches/ rkward_graphpics_device/rkward/rbackend/rkwarddevice
tfry at users.sf.net
tfry at users.sf.net
Sat Mar 30 13:47:13 UTC 2013
Revision: 4645
http://sourceforge.net/p/rkward/code/4645
Author: tfry
Date: 2013-03-30 13:47:12 +0000 (Sat, 30 Mar 2013)
Log Message:
-----------
Implement raster
Modified Paths:
--------------
branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp
branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice.h
branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_backendtransmitter.cpp
branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_frontendtransmitter.cpp
branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_protocol_shared.h
branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_setup.cpp
branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp
Modified: branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp
===================================================================
--- branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp 2013-03-29 19:32:47 UTC (rev 4644)
+++ branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp 2013-03-30 13:47:12 UTC (rev 4645)
@@ -77,7 +77,7 @@
RK_DEBUG (GRAPHICS_DEVICE, DL_ERROR, "Graphics device number %d already exists while trying to create it", devnum);
closeDevice (devnum);
}
- RKGraphicsDevice* dev = new RKGraphicsDevice (width, height, title.isEmpty () ? i18n ("Graphics Device Number %1").arg (QString (devnum+1)) : title, antialias);
+ RKGraphicsDevice* dev = new RKGraphicsDevice (width, height, title.isEmpty () ? i18n ("Graphics Device Number %1").arg (QString::number (devnum+1)) : title, antialias);
devices.insert (devnum, dev);
return (dev);
}
@@ -181,6 +181,20 @@
triggerUpdate ();
}
+void RKGraphicsDevice::image (const QImage& image, const QRectF& target_rect, double rot, bool interpolate) {
+ RK_TRACE (GRAPHICS_DEVICE);
+
+ painter.save ();
+ QRectF tr = target_rect;
+ painter.translate (tr.x (), tr.y ());
+ tr.moveTo (0, 0);
+ painter.rotate (-rot);
+ painter.setRenderHint (QPainter::SmoothPixmapTransform, interpolate);
+ painter.drawImage (tr, image, image.rect ());
+ painter.restore ();
+ triggerUpdate ();
+}
+
void RKGraphicsDevice::setActive (bool active) {
RK_TRACE (GRAPHICS_DEVICE);
Modified: branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice.h
===================================================================
--- branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice.h 2013-03-29 19:32:47 UTC (rev 4644)
+++ branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice.h 2013-03-30 13:47:12 UTC (rev 4645)
@@ -48,6 +48,7 @@
void polygon (const QPolygonF& pol, const QPen& pen, const QBrush &brush);
void polyline (const QPolygonF& pol, const QPen& pen);
void clear (const QColor& col=QColor());
+ void image (const QImage &image, const QRectF &target_rect, double rot, bool interpolate);
void setActive (bool active);
void triggerUpdate ();
void locator ();
Modified: branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_backendtransmitter.cpp
===================================================================
--- branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_backendtransmitter.cpp 2013-03-29 19:32:47 UTC (rev 4644)
+++ branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_backendtransmitter.cpp 2013-03-30 13:47:12 UTC (rev 4645)
@@ -72,10 +72,13 @@
void RKGraphicsDeviceBackendTransmitter::run () {
RK_TRACE (GRAPHICS_DEVICE);
+ bool more_left = false;
while (alive) {
- msleep (10); // it's ok to be lazy. If a request expects a reply, RKGraphicsDataStreamReadGuard will take care of pushing everything, itself. Essentially, this thread's job is simply to make sure we don't lag *too* far behind.
+ msleep (more_left ? 10 : 50); // it's ok to be lazy. If a request expects a reply, RKGraphicsDataStreamReadGuard will take care of pushing everything, itself. Essentially, this thread's job is simply to make sure we don't lag *too* far behind.
+ // See note in RKRBackend::handleRequest(): sleeping short is CPU-intensive
mutex.lock ();
connection->waitForBytesWritten (100);
+ more_left = connection->bytesToWrite ();
mutex.unlock ();
}
Modified: branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_frontendtransmitter.cpp
===================================================================
--- branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_frontendtransmitter.cpp 2013-03-29 19:32:47 UTC (rev 4644)
+++ branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_frontendtransmitter.cpp 2013-03-30 13:47:12 UTC (rev 4645)
@@ -81,6 +81,12 @@
connect (connection, SIGNAL (readyRead ()), this, SLOT (newData ()));
}
+static QRgb readRgb (QDataStream &instream) {
+ quint8 r, g, b, a;
+ instream >> r >> g >> b >> a;
+ return qRgba (r, g, b, a);
+}
+
static QColor readColor (QDataStream &instream) {
quint8 r, g, b, a;
instream >> r >> g >> b >> a;
@@ -247,6 +253,20 @@
quint8 m;
streamer.instream >> m;
if (m == 0) device->triggerUpdate ();
+ } else if (opcode == RKDRaster) {
+ quint32 w, h;
+ streamer.instream >> w >> h;
+ QImage image (w, h, QImage::Format_ARGB32);
+ for (quint32 col = 0; col < h; ++col) {
+ for (quint32 row = 0; row < w; ++row) {
+ image.setPixel (row, col, readRgb (streamer.instream));
+ }
+ }
+ QRectF target;
+ double rotation;
+ bool interpolate;
+ streamer.instream >> target >> rotation >> interpolate;
+ device->image (image, target.normalized (), rotation, interpolate);
} else if (opcode == RKDLocator) {
device->locator ();
#warning TODO keep track of status
Modified: branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_protocol_shared.h
===================================================================
--- branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_protocol_shared.h 2013-03-29 19:32:47 UTC (rev 4644)
+++ branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_protocol_shared.h 2013-03-30 13:47:12 UTC (rev 4645)
@@ -75,11 +75,12 @@
RKDDeActivate, // 10
RKDClip,
RKDMode,
+ RKDRaster,
// Synchronous operations
RKDStrWidthUTF8,
- RKDMetricInfo,
- RKDLocator, // 15
+ RKDMetricInfo, // 15
+ RKDLocator,
RKDNewPageConfirm,
// Protocol operations
Modified: branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_setup.cpp
===================================================================
--- branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_setup.cpp 2013-03-29 19:32:47 UTC (rev 4644)
+++ branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_setup.cpp 2013-03-30 13:47:12 UTC (rev 4645)
@@ -146,7 +146,7 @@
dev->haveTransparency = 2;
dev->haveTransparentBg = 2; // FIXME. Do we really? Check.
- dev->haveRaster = 1;
+ dev->haveRaster = 2;
dev->haveCapture = 1;
dev->haveLocator = 2;
@@ -180,6 +180,7 @@
dev->size = NULL; // RKD_Size;
// dev->onexit = RKD_OnExit; NULL is OK
// dev->getEvent = SEXP (*getEvent)(SEXP, const char *);
+ dev->raster = RKD_Raster;
dev->newFrameConfirm = RKD_NewFrameConfirm;
return true;
Modified: branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp
===================================================================
--- branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp 2013-03-29 19:32:47 UTC (rev 4644)
+++ branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp 2013-03-30 13:47:12 UTC (rev 4645)
@@ -276,6 +276,24 @@
connectoin << (qint8) mode; */
}
+static void RKD_Raster (unsigned int *raster, int w, int h, double x, double y, double width, double height, double rot, Rboolean interpolate, const pGEcontext gc, pDevDesc dev) {
+ Q_UNUSED (gc);
+
+ RKGraphicsDataStreamWriteGuard wguard;
+ WRITE_HEADER (RKDRaster, dev);
+
+ 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]);
+ }
+ }
+ RKD_OUT_STREAM << QRectF (x, y, width, height) << rot << (bool) interpolate;
+}
+
static Rboolean RKD_Locator (double *x, double *y, pDevDesc dev) {
{
RKGraphicsDataStreamWriteGuard wguard;
@@ -304,3 +322,4 @@
return (Rboolean) TRUE;
// Return value FALSE: Let R ask, instead
}
+
More information about the rkward-tracker
mailing list