From c072663493f8077506b3277765affbb7675510c9 Mon Sep 17 00:00:00 2001 From: James Zern Date: Tue, 17 Jun 2014 23:21:49 -0700 Subject: [PATCH] webpmux: warn when odd frame offsets are used offsets are stored as (x/2, y/2) Change-Id: Ic8f727ab7996a84c1f8c57f4f6dbaf8701bf8eae --- examples/webpmux.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/examples/webpmux.c b/examples/webpmux.c index ec261c60..a828fd7a 100644 --- a/examples/webpmux.c +++ b/examples/webpmux.c @@ -371,6 +371,14 @@ static void PrintHelp(void) { printf(" and is assumed to be\nvalid.\n"); } +static void WarnAboutOddOffset(const WebPMuxFrameInfo* const info) { + if ((info->x_offset | info->y_offset) & 1) { + fprintf(stderr, "Warning: odd offsets will be snapped to even values" + " (%d, %d) -> (%d, %d)\n", info->x_offset, info->y_offset, + info->x_offset & ~1, info->y_offset & ~1); + } +} + static int ReadFileToWebPData(const char* const filename, WebPData* const webp_data) { const uint8_t* data; @@ -444,6 +452,9 @@ static int ParseFrameArgs(const char* args, WebPMuxFrameInfo* const info) { default: return 0; } + + WarnAboutOddOffset(info); + // Note: The sanity of the following conversion is checked by // WebPMuxPushFrame(). info->dispose_method = (WebPMuxAnimDispose)dispose_method; @@ -456,7 +467,10 @@ static int ParseFrameArgs(const char* args, WebPMuxFrameInfo* const info) { } static int ParseFragmentArgs(const char* args, WebPMuxFrameInfo* const info) { - return (sscanf(args, "+%d+%d", &info->x_offset, &info->y_offset) == 2); + const int ok = + (sscanf(args, "+%d+%d", &info->x_offset, &info->y_offset) == 2); + if (ok) WarnAboutOddOffset(info); + return ok; } static int ParseBgcolorArgs(const char* args, uint32_t* const bgcolor) {