From 8acbca729c2bca966c0e4b91701654532af2f55c Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Tue, 14 May 2013 02:27:30 +0200 Subject: add tiling support to liveview --- liveview/liveview.cpp | 10 ++++++---- liveview/liveviewpaintengine.cpp | 18 +++++++++++++----- nekowatchlet/nekowatchlet.pro | 4 +++- qmapwatchlet/qmapwatchlet.pro | 3 ++- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/liveview/liveview.cpp b/liveview/liveview.cpp index c36f944..58bfb83 100644 --- a/liveview/liveview.cpp +++ b/liveview/liveview.cpp @@ -54,9 +54,9 @@ int LiveView::metric(PaintDeviceMetric metric) const case PdmHeightMM: return 24; case PdmNumColors: - return 65536; + return 256; case PdmDepth: - return 16; + return 8; case PdmDpiX: case PdmPhysicalDpiX: return 136; @@ -167,7 +167,8 @@ QImage* LiveView::image() void LiveView::renderImage(int x, int y, const QImage &image) { - QByteArray data = encodeImage(image); + qDebug() << "Rendering image at" << x << 'x' << y << "of size" << image.size(); + QByteArray data = encodeImage(image.copy(0,0,64,64)); if (!data.isEmpty()) { displayBitmap(x, y, data); } @@ -226,7 +227,7 @@ QByteArray LiveView::encodeImage(const QImage& image) const { QBuffer buffer; buffer.open(QIODevice::WriteOnly); - if (image.save(&buffer, "PNG")) { + if (image.save(&buffer, "PNG", 0)) { return buffer.buffer(); } else { qWarning() << "Failed to encode image"; @@ -286,6 +287,7 @@ void LiveView::displayBitmap(unsigned char x, unsigned char y, const QByteArray data[1] = y; data[2] = 1; // TODO Figure out what this is. Maybe format? data.append(image); + qDebug() << "Trying to send" << image.size() << "bytes"; send(Message(DisplayBitmap, data)); } diff --git a/liveview/liveviewpaintengine.cpp b/liveview/liveviewpaintengine.cpp index 9f7ffec..2370477 100644 --- a/liveview/liveviewpaintengine.cpp +++ b/liveview/liveviewpaintengine.cpp @@ -21,9 +21,17 @@ bool LiveViewPaintEngine::end() bool ret = WatchPaintEngine::end(); if (ret) { QRect rect = _damaged.boundingRect(); - if (!rect.isEmpty()) { - QImage sub_image = _watch->image()->copy(rect); - _watch->renderImage(rect.x(), rect.y(), sub_image); + + const int tile_size = 64; + // Have to make tiles + for (int x = rect.left(); x < rect.right(); x += tile_size) { + for (int y = rect.top(); y < rect.bottom(); y += tile_size) { + QRect tile(x, y, + qMin(x + tile_size, rect.right()), + qMin(y + tile_size, rect.bottom())); + QImage sub_image = _watch->image()->copy(tile); + _watch->renderImage(tile.x(), tile.y(), sub_image); + } } } return ret; @@ -35,7 +43,7 @@ void LiveViewPaintEngine::drawRects(const QRectF *rects, int rectCount) for (i = 0; i < rectCount; i++) { const QRectF& r = rects[i]; if (_hasBrush && fillsEntireImage(r.toRect()) && _isBrushBlack) { - //_watch->clear(); + _watch->clear(); _damaged = QRegion(); continue; } @@ -58,7 +66,7 @@ void LiveViewPaintEngine::drawRects(const QRect *rects, int rectCount) for (i = 0; i < rectCount; i++) { const QRect& r = rects[i]; if (_hasBrush && fillsEntireImage(r) && _isBrushBlack) { - //_watch->clear(); + _watch->clear(); _damaged = QRegion(); continue; } diff --git a/nekowatchlet/nekowatchlet.pro b/nekowatchlet/nekowatchlet.pro index fd9321a..5777390 100644 --- a/nekowatchlet/nekowatchlet.pro +++ b/nekowatchlet/nekowatchlet.pro @@ -6,7 +6,9 @@ SOURCES += nekowatchletplugin.cpp nekowatchlet.cpp HEADERS += nekowatchletplugin.h nekowatchlet.h -qml_files.files = metawatch-digital.qml Neko.qml icon.png neko.png +qml_files.files = metawatch-digital.qml liveview.qml \ + icon.png metawatch-digital-icon.png liveview-icon.png \ + Neko.qml neko.png neko-inv.png LIBS += -L$$OUT_PWD/../libsowatch/ -lsowatch INCLUDEPATH += $$PWD/../libsowatch diff --git a/qmapwatchlet/qmapwatchlet.pro b/qmapwatchlet/qmapwatchlet.pro index 9c9c095..240beac 100644 --- a/qmapwatchlet/qmapwatchlet.pro +++ b/qmapwatchlet/qmapwatchlet.pro @@ -11,7 +11,8 @@ SOURCES += qmapwatchletplugin.cpp qmapwatchlet.cpp mapview.cpp \ HEADERS += qmapwatchletplugin.h qmapwatchlet.h mapview.h \ compasswatchlet.h compassview.h -qml_files.files = map-metawatch-digital.qml map-icon.png arrow.png \ +qml_files.files = map-metawatch-digital.qml map-liveview.qml \ + map-icon.png map-metawatch-digital-icon.png map-liveview-icon.png arrow.png \ compass-metawatch-digital.qml compass-icon.png compass.png LIBS += -L$$OUT_PWD/../libsowatch/ -lsowatch -- cgit v1.2.3