Skip to content

Commit

Permalink
Fix some flicker when scrolling text in Pixel Overlay model
Browse files Browse the repository at this point in the history
When scrolling text across the Pixel Overlay model, the channel
output code would sometimes grab the frame in the middle of the
clear() call.  This was causing occasional flicker.  Now, we
double buffer and only need to clear our buffer before drawing on
it again and then copying the whole buffer into place.  This still
doesn't fix 'tearing' that may occur because the scroll is not gen
locked to the channel output code, but it is better than before.

(cherry picked from commit c02a5d6)
  • Loading branch information
cpinkham committed Dec 20, 2019
1 parent 9f00617 commit 847ed41
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/PixelOverlay.cpp
Expand Up @@ -66,7 +66,7 @@ PixelOverlayModel::PixelOverlayModel(FPPChannelMemoryMapControlBlock *b,
char *cdm,
uint32_t *pm)
: block(b), name(n), chanDataMap(cdm), pixelMap(pm),
updateThread(nullptr),threadKeepRunning(false),
updateThread(nullptr),threadKeepRunning(false), overlayBuffer(nullptr),
imageData(nullptr), imageDataRows(0), imageDataCols(0)
{
}
Expand All @@ -79,6 +79,9 @@ PixelOverlayModel::~PixelOverlayModel() {
if (imageData) {
free(imageData);
}
if (overlayBuffer) {
free(overlayBuffer);
}
}

int PixelOverlayModel::getWidth() const {
Expand Down Expand Up @@ -293,6 +296,10 @@ void PixelOverlayModel::doText(const std::string &msg,
np[2] = b;
}
}

if (!overlayBuffer)
overlayBuffer = (uint8_t*)malloc(block->channelCount);

copyImageData(x, y);
lock();
threadKeepRunning = true;
Expand Down Expand Up @@ -336,7 +343,7 @@ void PixelOverlayModel::doImageMovementThread(const std::string &direction, int

void PixelOverlayModel::copyImageData(int xoff, int yoff) {
if (imageData) {
clear();
memset(overlayBuffer, 0, block->channelCount);
int h, w;
getSize(w, h);
for (int y = 0; y < imageDataRows; ++y) {
Expand All @@ -351,9 +358,13 @@ void PixelOverlayModel::copyImageData(int xoff, int yoff) {
continue;
}
uint8_t *p = &imageData[idx + (x*3)];
setPixelValue(nx, ny, p[0], p[1], p[2]);
int c = (ny*getWidth()*3) + nx*3;
overlayBuffer[c++] = p[0];
overlayBuffer[c++] = p[1];
overlayBuffer[c++] = p[2];
}
}
setData(overlayBuffer);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/PixelOverlay.h
Expand Up @@ -128,6 +128,7 @@ class PixelOverlayModel {

std::thread *updateThread;
volatile bool threadKeepRunning;
uint8_t *overlayBuffer;
uint8_t *imageData;
int imageDataRows;
int imageDataCols;
Expand Down

0 comments on commit 847ed41

Please sign in to comment.