Skip to content

Commit

Permalink
vwebp: Fix bug when Dispose then NoBlend frames
Browse files Browse the repository at this point in the history
The graphical bug happens when there is a frame disposed to background
color, followed by another frame that does not blend, and their areas
don't fully overlap. Only the previous frame clears its part of the
viewport. The fix consists in clearing the screen for the previous and
the current frame if needed.

Change-Id: I3425cf7297f0c7b2cf13a3a61b517cc0b1c031d8
  • Loading branch information
y-guyon authored and jzern committed Aug 3, 2018
1 parent 423f257 commit 009562b
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions examples/vwebp.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,24 @@ static void DrawBackground(void) {
}
}

// Draw background in a scissored rectangle.
static void DrawBackgroundScissored(int window_x, int window_y, int frame_w,
int frame_h) {
// Only update the requested area, not the whole canvas.
window_x = window_x * kParams.viewport_width / kParams.canvas_width;
window_y = window_y * kParams.viewport_height / kParams.canvas_height;
frame_w = frame_w * kParams.viewport_width / kParams.canvas_width;
frame_h = frame_h * kParams.viewport_height / kParams.canvas_height;

// glScissor() takes window coordinates (0,0 at bottom left).
window_y = kParams.viewport_height - window_y - frame_h;

glEnable(GL_SCISSOR_TEST);
glScissor(window_x, window_y, frame_w, frame_h);
DrawBackground();
glDisable(GL_SCISSOR_TEST);
}

static void HandleDisplay(void) {
const WebPDecBuffer* const pic = kParams.pic;
const WebPIterator* const curr = &kParams.curr_frame;
Expand All @@ -351,36 +369,20 @@ static void HandleDisplay(void) {

if (kParams.only_deltas) {
DrawBackground();
} else if (prev->dispose_method == WEBP_MUX_DISPOSE_BACKGROUND ||
curr->blend_method == WEBP_MUX_NO_BLEND) {
// glScissor() takes window coordinates (0,0 at bottom left).
int window_x, window_y;
int frame_w, frame_h;
} else {
// The rectangle of the previous frame might be different than the current
// frame, so we may need to DrawBackgroundScissored for both.
if (prev->dispose_method == WEBP_MUX_DISPOSE_BACKGROUND) {
// Clear the previous frame rectangle.
window_x = prev->x_offset;
window_y = kParams.canvas_height - prev->y_offset - prev->height;
frame_w = prev->width;
frame_h = prev->height;
} else { // curr->blend_method == WEBP_MUX_NO_BLEND.
DrawBackgroundScissored(prev->x_offset, prev->y_offset, prev->width,
prev->height);
}
if (curr->blend_method == WEBP_MUX_NO_BLEND) {
// We simulate no-blending behavior by first clearing the current frame
// rectangle (to a checker-board) and then alpha-blending against it.
window_x = curr->x_offset;
window_y = kParams.canvas_height - curr->y_offset - curr->height;
frame_w = curr->width;
frame_h = curr->height;
// rectangle and then alpha-blending against it.
DrawBackgroundScissored(curr->x_offset, curr->y_offset, curr->width,
curr->height);
}
glEnable(GL_SCISSOR_TEST);
// Only update the requested area, not the whole canvas.
window_x = window_x * kParams.viewport_width / kParams.canvas_width;
window_y = window_y * kParams.viewport_height / kParams.canvas_height;
frame_w = frame_w * kParams.viewport_width / kParams.canvas_width;
frame_h = frame_h * kParams.viewport_height / kParams.canvas_height;
glScissor(window_x, window_y, frame_w, frame_h);

DrawBackground();

glDisable(GL_SCISSOR_TEST);
}

*prev = *curr;
Expand Down

0 comments on commit 009562b

Please sign in to comment.