[Spice-commits] 15 commits - common/Makefile.am common/quic.c common/quic_rgb_tmpl.c common/quic_tmpl.c

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Jul 10 09:36:43 UTC 2018


 common/Makefile.am     |    1 
 common/quic.c          |   29 --
 common/quic_rgb_tmpl.c |  672 -------------------------------------------------
 common/quic_tmpl.c     |  473 +++++++++++++++++++++-------------
 4 files changed, 303 insertions(+), 872 deletions(-)

New commits:
commit f636ef42a0dfd84337345953bf02d19f70bf8937
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Tue Jul 10 11:02:22 2018 +0200

    quic: Remove duplicate file
    
    Now that the 2 template files are the same (except for whitespace differences),
    we can use a single file.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/common/Makefile.am b/common/Makefile.am
index 4b1ff68..748c1f2 100644
--- a/common/Makefile.am
+++ b/common/Makefile.am
@@ -133,7 +133,6 @@ EXTRA_DIST =				\
 	lz_compress_tmpl.c		\
 	lz_decompress_tmpl.c		\
 	quic_family_tmpl.c		\
-	quic_rgb_tmpl.c			\
 	quic_tmpl.c			\
 	snd_codec.h			\
 	$(NULL)
diff --git a/common/quic.c b/common/quic.c
index cf4f087..60818c2 100644
--- a/common/quic.c
+++ b/common/quic.c
@@ -626,16 +626,16 @@ typedef uint16_t rgb16_pixel_t;
 #include "quic_tmpl.c"
 
 #define QUIC_RGB32
-#include "quic_rgb_tmpl.c"
+#include "quic_tmpl.c"
 
 #define QUIC_RGB24
-#include "quic_rgb_tmpl.c"
+#include "quic_tmpl.c"
 
 #define QUIC_RGB16
-#include "quic_rgb_tmpl.c"
+#include "quic_tmpl.c"
 
 #define QUIC_RGB16_TO_32
-#include "quic_rgb_tmpl.c"
+#include "quic_tmpl.c"
 
 static void fill_model_structures(SPICE_GNUC_UNUSED Encoder *encoder, FamilyStat *family_stat,
                                   unsigned int rep_first, unsigned int first_size,
diff --git a/common/quic_rgb_tmpl.c b/common/quic_rgb_tmpl.c
deleted file mode 100644
index fbfd248..0000000
--- a/common/quic_rgb_tmpl.c
+++ /dev/null
@@ -1,669 +0,0 @@
-/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
-/*
-   Copyright (C) 2009 Red Hat, Inc.
-
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   This library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with this library; if not, see <http://www.gnu.org/licenses/>.
-*/
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#define COMPRESS_IMP
-
-#if defined(ONE_BYTE) || defined(FOUR_BYTE)
-#  define FARGS_DECL(arg1, ...) (Encoder *encoder, Channel *channel_a, arg1, ##__VA_ARGS__)
-#  define FARGS_CALL(arg1, ...) (encoder, channel_a, arg1, ##__VA_ARGS__)
-#  define UNCOMPRESS_PIX_START(row) do { } while (0)
-#  define SET_a(pix, val) ((pix)->a = val)
-#  define GET_a(pix) ((pix)->a)
-#  define SAME_PIXEL(p1, p2) (GET_a(p1) == GET_a(p2))
-#  define COPY_PIXEL(dest, src) \
-    SET_a(dest, GET_a(src));
-#  define DECLARE_STATE_VARIABLES \
-    CommonState *state = &channel_a->state
-#  define DECLARE_CHANNEL_VARIABLES \
-    BYTE * const correlate_row_a = channel_a->correlate_row
-#  define APPLY_ALL_COMP(macro, ...) \
-    macro(a, ## __VA_ARGS__)
-#else
-#  define FARGS_DECL(arg1, ...) (Encoder *encoder, arg1, ##__VA_ARGS__)
-#  define FARGS_CALL(arg1, ...) (encoder, arg1, ##__VA_ARGS__)
-#  define SAME_PIXEL(p1, p2)                               \
-    (GET_r(p1) == GET_r(p2) && GET_g(p1) == GET_g(p2) &&   \
-     GET_b(p1) == GET_b(p2))
-#  define COPY_PIXEL(dest, src) \
-    SET_r(dest, GET_r(src)); \
-    SET_g(dest, GET_g(src)); \
-    SET_b(dest, GET_b(src))
-#  define DECLARE_STATE_VARIABLES \
-    CommonState *state = &encoder->rgb_state
-#  define DECLARE_CHANNEL_VARIABLES \
-    Channel * const channel_r = encoder->channels; \
-    Channel * const channel_g = channel_r + 1; \
-    Channel * const channel_b = channel_g + 1; \
-    BYTE * const correlate_row_r = channel_r->correlate_row; \
-    BYTE * const correlate_row_g = channel_g->correlate_row; \
-    BYTE * const correlate_row_b = channel_b->correlate_row
-#  define APPLY_ALL_COMP(macro, ...) \
-    macro(r, ## __VA_ARGS__); \
-    macro(g, ## __VA_ARGS__); \
-    macro(b, ## __VA_ARGS__)
-#endif
-
-#ifdef ONE_BYTE
-#undef ONE_BYTE
-#define FNAME(name) quic_one_##name
-#define PIXEL one_byte_t
-#define BPC 8
-#endif
-
-#ifdef FOUR_BYTE
-#undef FOUR_BYTE
-#define FNAME(name) quic_four_##name
-#define PIXEL four_bytes_t
-#define BPC 8
-#endif
-
-#ifdef QUIC_RGB32
-#undef QUIC_RGB32
-#define PIXEL rgb32_pixel_t
-#define FNAME(name) quic_rgb32_##name
-#define BPC 8
-#define SET_r(pix, val) ((pix)->r = val)
-#define GET_r(pix) ((pix)->r)
-#define SET_g(pix, val) ((pix)->g = val)
-#define GET_g(pix) ((pix)->g)
-#define SET_b(pix, val) ((pix)->b = val)
-#define GET_b(pix) ((pix)->b)
-#define UNCOMPRESS_PIX_START(pix) ((pix)->pad = 0)
-#endif
-
-#ifdef QUIC_RGB24
-#undef QUIC_RGB24
-#define PIXEL rgb24_pixel_t
-#define FNAME(name) quic_rgb24_##name
-#define BPC 8
-#define SET_r(pix, val) ((pix)->r = val)
-#define GET_r(pix) ((pix)->r)
-#define SET_g(pix, val) ((pix)->g = val)
-#define GET_g(pix) ((pix)->g)
-#define SET_b(pix, val) ((pix)->b = val)
-#define GET_b(pix) ((pix)->b)
-#define UNCOMPRESS_PIX_START(pix)
-#endif
-
-#ifdef QUIC_RGB16
-#undef QUIC_RGB16
-#define PIXEL rgb16_pixel_t
-#define FNAME(name) quic_rgb16_##name
-#define BPC 5
-#define SET_r(pix, val) (*(pix) = (*(pix) & ~(0x1f << 10)) | ((val) << 10))
-#define GET_r(pix) ((*(pix) >> 10) & 0x1f)
-#define SET_g(pix, val) (*(pix) = (*(pix) & ~(0x1f << 5)) | ((val) << 5))
-#define GET_g(pix) ((*(pix) >> 5) & 0x1f)
-#define SET_b(pix, val) (*(pix) = (*(pix) & ~0x1f) | (val))
-#define GET_b(pix) (*(pix) & 0x1f)
-#define UNCOMPRESS_PIX_START(pix) (*(pix) = 0)
-#endif
-
-#ifdef QUIC_RGB16_TO_32
-#undef QUIC_RGB16_TO_32
-#define PIXEL rgb32_pixel_t
-#define FNAME(name) quic_rgb16_to_32_##name
-#define BPC 5
-#undef COMPRESS_IMP
-#define SET_r(pix, val) ((pix)->r = ((val) << 3) | (((val) & 0x1f) >> 2))
-#define GET_r(pix) ((pix)->r >> 3)
-#define SET_g(pix, val) ((pix)->g = ((val) << 3) | (((val) & 0x1f) >> 2))
-#define GET_g(pix) ((pix)->g >> 3)
-#define SET_b(pix, val) ((pix)->b = ((val) << 3) | (((val) & 0x1f) >> 2))
-#define GET_b(pix) ((pix)->b >> 3)
-#define UNCOMPRESS_PIX_START(pix) ((pix)->pad = 0)
-#endif
-
-#define FNAME_DECL(name) FNAME(name) FARGS_DECL
-#define FNAME_CALL(name) FNAME(name) FARGS_CALL
-
-#if BPC == 5
-#  define golomb_coding golomb_coding_5bpc
-#  define golomb_decoding golomb_decoding_5bpc
-#  define update_model update_model_5bpc
-#  define find_bucket find_bucket_5bpc
-#  define family family_5bpc
-#  define BPC_MASK 0x1fU
-#elif BPC == 8
-#  define golomb_coding golomb_coding_8bpc
-#  define golomb_decoding golomb_decoding_8bpc
-#  define update_model update_model_8bpc
-#  define find_bucket find_bucket_8bpc
-#  define family family_8bpc
-#  define BPC_MASK 0xffU
-#else
-#  error BPC must be 5 or 8
-#endif
-
-#define _PIXEL_A(channel, curr) ((unsigned int)GET_##channel((curr) - 1))
-#define _PIXEL_B(channel, prev) ((unsigned int)GET_##channel(prev))
-
-/*  a  */
-
-#define DECORRELATE_0(channel, curr, bpc_mask)\
-    family.xlatU2L[(unsigned)((int)GET_##channel(curr) - (int)_PIXEL_A(channel, curr)) & bpc_mask]
-
-#define CORRELATE_0(channel, curr, correlate, bpc_mask)\
-    ((family.xlatL2U[correlate] + _PIXEL_A(channel, curr)) & bpc_mask)
-
-
-/*  (a+b)/2  */
-#define DECORRELATE(channel, prev, curr, bpc_mask, r)                                           \
-    r = family.xlatU2L[(unsigned)((int)GET_##channel(curr) - (int)((_PIXEL_A(channel, curr) +   \
-                        _PIXEL_B(channel, prev)) >> 1)) & bpc_mask]
-
-#define CORRELATE(channel, prev, curr, correlate, bpc_mask, r)                                  \
-    SET_##channel(r, ((family.xlatL2U[correlate] +                                              \
-          (int)((_PIXEL_A(channel, curr) + _PIXEL_B(channel, prev)) >> 1)) & bpc_mask))
-
-
-#define COMPRESS_ONE_ROW0_0(channel)                                                  \
-    correlate_row_##channel[0] = family.xlatU2L[GET_##channel(cur_row)];              \
-    golomb_coding(encoder, correlate_row_##channel[0], find_bucket(channel_##channel, \
-                  correlate_row_##channel[-1])->bestcode)
-
-#define COMPRESS_ONE_ROW0(channel, index)                                                 \
-    correlate_row_##channel[index] = DECORRELATE_0(channel, &cur_row[index], bpc_mask);   \
-    golomb_coding(encoder, correlate_row_##channel[index], find_bucket(channel_##channel, \
-                  correlate_row_##channel[index -1])->bestcode)
-
-#define UPDATE_MODEL_COMP(channel, index)                                                             \
-    update_model(state, find_bucket(channel_##channel, correlate_row_##channel[index - 1]),        \
-                 correlate_row_##channel[index])
-#define UPDATE_MODEL(index) APPLY_ALL_COMP(UPDATE_MODEL_COMP, index)
-
-#define RLE_PRED_IMP                                                                \
-if (SAME_PIXEL(&prev_row[i - 1], &prev_row[i])) {                                   \
-    if (run_index != i && i > 2 && SAME_PIXEL(&cur_row[i - 1], &cur_row[i - 2])) {  \
-        goto do_run;                                                                \
-    }                                                                               \
-}
-
-#ifdef COMPRESS_IMP
-
-static void FNAME_DECL(compress_row0_seg)(int i,
-                                          const PIXEL * const cur_row,
-                                          const int end,
-                                          const unsigned int waitmask,
-                                          SPICE_GNUC_UNUSED const unsigned int bpc,
-                                          const unsigned int bpc_mask)
-{
-    DECLARE_STATE_VARIABLES;
-    DECLARE_CHANNEL_VARIABLES;
-    int stopidx;
-
-    spice_assert(end - i > 0);
-
-    if (i == 0) {
-        APPLY_ALL_COMP(COMPRESS_ONE_ROW0_0);
-
-        if (state->waitcnt) {
-            state->waitcnt--;
-        } else {
-            state->waitcnt = (tabrand(&state->tabrand_seed) & waitmask);
-            UPDATE_MODEL(0);
-        }
-        stopidx = ++i + state->waitcnt;
-    } else {
-        stopidx = i + state->waitcnt;
-    }
-
-    while (stopidx < end) {
-        for (; i <= stopidx; i++) {
-            APPLY_ALL_COMP(COMPRESS_ONE_ROW0, i);
-        }
-
-        UPDATE_MODEL(stopidx);
-        stopidx = i + (tabrand(&state->tabrand_seed) & waitmask);
-    }
-
-    for (; i < end; i++) {
-        APPLY_ALL_COMP(COMPRESS_ONE_ROW0, i);
-    }
-    state->waitcnt = stopidx - end;
-}
-
-#undef COMPRESS_ONE_ROW0_0
-#undef COMPRESS_ONE_ROW0
-
-static void FNAME_DECL(compress_row0)(const PIXEL *cur_row, unsigned int width)
-{
-    DECLARE_STATE_VARIABLES;
-    const unsigned int bpc = BPC;
-    const unsigned int bpc_mask = BPC_MASK;
-    int pos = 0;
-
-    while ((DEFwmimax > (int)state->wmidx) && (state->wmileft <= width)) {
-        if (state->wmileft) {
-            FNAME_CALL(compress_row0_seg)(pos, cur_row, pos + state->wmileft,
-                                          bppmask[state->wmidx], bpc, bpc_mask);
-            width -= state->wmileft;
-            pos += state->wmileft;
-        }
-
-        state->wmidx++;
-        set_wm_trigger(state);
-        state->wmileft = DEFwminext;
-    }
-
-    if (width) {
-        FNAME_CALL(compress_row0_seg)(pos, cur_row, pos + width,
-                                      bppmask[state->wmidx], bpc, bpc_mask);
-        if (DEFwmimax > (int)state->wmidx) {
-            state->wmileft -= width;
-        }
-    }
-
-    spice_assert((int)state->wmidx <= DEFwmimax);
-    spice_assert(state->wmidx <= 32);
-    spice_assert(DEFwminext > 0);
-}
-
-#define COMPRESS_ONE_0(channel) \
-    correlate_row_##channel[0] = family.xlatU2L[(unsigned)((int)GET_##channel(cur_row) -    \
-                                                (int)GET_##channel(prev_row) ) & bpc_mask]; \
-    golomb_coding(encoder, correlate_row_##channel[0],                                      \
-                  find_bucket(channel_##channel, correlate_row_##channel[-1])->bestcode)
-
-#define COMPRESS_ONE(channel, index)                                                            \
-    DECORRELATE(channel, &prev_row[index], &cur_row[index],bpc_mask,                            \
-               correlate_row_##channel[index]);                                                 \
-    golomb_coding(encoder, correlate_row_##channel[index],                                      \
-                 find_bucket(channel_##channel, correlate_row_##channel[index - 1])->bestcode)
-
-static void FNAME_DECL(compress_row_seg)(int i,
-                                         const PIXEL * const prev_row,
-                                         const PIXEL * const cur_row,
-                                         const int end,
-                                         const unsigned int waitmask,
-                                         SPICE_GNUC_UNUSED const unsigned int bpc,
-                                         const unsigned int bpc_mask)
-{
-    DECLARE_STATE_VARIABLES;
-    DECLARE_CHANNEL_VARIABLES;
-    int stopidx;
-    int run_index = 0;
-    int run_size;
-
-    spice_assert(end - i > 0);
-
-    if (i == 0) {
-        APPLY_ALL_COMP(COMPRESS_ONE_0);
-
-        if (state->waitcnt) {
-            state->waitcnt--;
-        } else {
-            state->waitcnt = (tabrand(&state->tabrand_seed) & waitmask);
-            UPDATE_MODEL(0);
-        }
-        stopidx = ++i + state->waitcnt;
-    } else {
-        stopidx = i + state->waitcnt;
-    }
-    for (;;) {
-        while (stopidx < end) {
-            for (; i <= stopidx; i++) {
-                RLE_PRED_IMP;
-                APPLY_ALL_COMP(COMPRESS_ONE, i);
-            }
-
-            UPDATE_MODEL(stopidx);
-            stopidx = i + (tabrand(&state->tabrand_seed) & waitmask);
-        }
-
-        for (; i < end; i++) {
-            RLE_PRED_IMP;
-            APPLY_ALL_COMP(COMPRESS_ONE, i);
-        }
-        state->waitcnt = stopidx - end;
-
-        return;
-
-do_run:
-        run_index = i;
-        state->waitcnt = stopidx - i;
-        run_size = 0;
-
-        while (SAME_PIXEL(&cur_row[i], &cur_row[i - 1])) {
-            run_size++;
-            if (++i == end) {
-                encode_state_run(encoder, state, run_size);
-                return;
-            }
-        }
-        encode_state_run(encoder, state, run_size);
-        stopidx = i + state->waitcnt;
-    }
-}
-
-static void FNAME_DECL(compress_row)(const PIXEL * const prev_row,
-                                     const PIXEL * const cur_row,
-                                     unsigned int width)
-
-{
-    DECLARE_STATE_VARIABLES;
-    const unsigned int bpc = BPC;
-    const unsigned int bpc_mask = BPC_MASK;
-    unsigned int pos = 0;
-
-    while ((DEFwmimax > (int)state->wmidx) && (state->wmileft <= width)) {
-        if (state->wmileft) {
-            FNAME_CALL(compress_row_seg)(pos, prev_row, cur_row,
-                                         pos + state->wmileft, bppmask[state->wmidx],
-                                         bpc, bpc_mask);
-            width -= state->wmileft;
-            pos += state->wmileft;
-        }
-
-        state->wmidx++;
-        set_wm_trigger(state);
-        state->wmileft = DEFwminext;
-    }
-
-    if (width) {
-        FNAME_CALL(compress_row_seg)(pos, prev_row, cur_row, pos + width,
-                                     bppmask[state->wmidx], bpc, bpc_mask);
-        if (DEFwmimax > (int)state->wmidx) {
-            state->wmileft -= width;
-        }
-    }
-
-    spice_assert((int)state->wmidx <= DEFwmimax);
-    spice_assert(state->wmidx <= 32);
-    spice_assert(DEFwminext > 0);
-}
-
-#endif
-
-#define UNCOMPRESS_ONE_ROW0_0(channel)                                                          \
-    correlate_row_##channel[0] = (BYTE)golomb_decoding(find_bucket(channel_##channel,           \
-                                                       correlate_row_##channel[-1])->bestcode,  \
-                                                       encoder->io_word, &codewordlen);         \
-    SET_##channel(&cur_row[0], (BYTE)family.xlatL2U[correlate_row_##channel[0]]);               \
-    decode_eatbits(encoder, codewordlen);
-
-#define UNCOMPRESS_ONE_ROW0(channel)                                                              \
-    correlate_row_##channel[i] = (BYTE)golomb_decoding(find_bucket(channel_##channel,             \
-                                                       correlate_row_##channel[i - 1])->bestcode, \
-                                                       encoder->io_word,                          \
-                                                       &codewordlen);                             \
-    SET_##channel(&cur_row[i], CORRELATE_0(channel, &cur_row[i], correlate_row_##channel[i],      \
-                  bpc_mask));                                                                     \
-    decode_eatbits(encoder, codewordlen);
-
-static void FNAME_DECL(uncompress_row0_seg)(int i,
-                                            PIXEL * const cur_row,
-                                            const int end,
-                                            const unsigned int waitmask,
-                                            SPICE_GNUC_UNUSED const unsigned int bpc,
-                                            const unsigned int bpc_mask)
-{
-    DECLARE_STATE_VARIABLES;
-    DECLARE_CHANNEL_VARIABLES;
-    int stopidx;
-
-    spice_assert(end - i > 0);
-
-    if (i == 0) {
-        unsigned int codewordlen;
-
-        UNCOMPRESS_PIX_START(&cur_row[i]);
-        APPLY_ALL_COMP(UNCOMPRESS_ONE_ROW0_0);
-
-        if (state->waitcnt) {
-            --state->waitcnt;
-        } else {
-            state->waitcnt = (tabrand(&state->tabrand_seed) & waitmask);
-            UPDATE_MODEL(0);
-        }
-        stopidx = ++i + state->waitcnt;
-    } else {
-        stopidx = i + state->waitcnt;
-    }
-
-    while (stopidx < end) {
-        for (; i <= stopidx; i++) {
-            unsigned int codewordlen;
-
-            UNCOMPRESS_PIX_START(&cur_row[i]);
-            APPLY_ALL_COMP(UNCOMPRESS_ONE_ROW0);
-        }
-        UPDATE_MODEL(stopidx);
-        stopidx = i + (tabrand(&state->tabrand_seed) & waitmask);
-    }
-
-    for (; i < end; i++) {
-        unsigned int codewordlen;
-
-        UNCOMPRESS_PIX_START(&cur_row[i]);
-        APPLY_ALL_COMP(UNCOMPRESS_ONE_ROW0);
-    }
-    state->waitcnt = stopidx - end;
-}
-
-static void FNAME_DECL(uncompress_row0)(PIXEL * const cur_row,
-                                        unsigned int width)
-
-{
-    DECLARE_STATE_VARIABLES;
-    const unsigned int bpc = BPC;
-    const unsigned int bpc_mask = BPC_MASK;
-    unsigned int pos = 0;
-
-    while ((DEFwmimax > (int)state->wmidx) && (state->wmileft <= width)) {
-        if (state->wmileft) {
-            FNAME_CALL(uncompress_row0_seg)(pos, cur_row,
-                                            pos + state->wmileft,
-                                            bppmask[state->wmidx],
-                                            bpc, bpc_mask);
-            pos += state->wmileft;
-            width -= state->wmileft;
-        }
-
-        state->wmidx++;
-        set_wm_trigger(state);
-        state->wmileft = DEFwminext;
-    }
-
-    if (width) {
-        FNAME_CALL(uncompress_row0_seg)(pos, cur_row, pos + width,
-                                        bppmask[state->wmidx], bpc, bpc_mask);
-        if (DEFwmimax > (int)state->wmidx) {
-            state->wmileft -= width;
-        }
-    }
-
-    spice_assert((int)state->wmidx <= DEFwmimax);
-    spice_assert(state->wmidx <= 32);
-    spice_assert(DEFwminext > 0);
-}
-
-#define UNCOMPRESS_ONE_0(channel) \
-    correlate_row_##channel[0] = (BYTE)golomb_decoding(find_bucket(channel_##channel,           \
-                                                       correlate_row_##channel[-1])->bestcode,  \
-                                                       encoder->io_word, &codewordlen);         \
-    SET_##channel(&cur_row[0], (family.xlatL2U[correlate_row_##channel[0]] +                    \
-                          GET_##channel(prev_row)) & bpc_mask);                                 \
-    decode_eatbits(encoder, codewordlen);
-
-#define UNCOMPRESS_ONE(channel)                                                                   \
-    correlate_row_##channel[i] = (BYTE)golomb_decoding(find_bucket(channel_##channel,             \
-                                                       correlate_row_##channel[i - 1])->bestcode, \
-                                                       encoder->io_word,                          \
-                                                       &codewordlen);                             \
-    CORRELATE(channel, &prev_row[i], &cur_row[i], correlate_row_##channel[i], bpc_mask,           \
-             &cur_row[i]);                                                                        \
-    decode_eatbits(encoder, codewordlen);
-
-static void FNAME_DECL(uncompress_row_seg)(const PIXEL * const prev_row,
-                                           PIXEL * const cur_row,
-                                           int i,
-                                           const int end,
-                                           SPICE_GNUC_UNUSED const unsigned int bpc,
-                                           const unsigned int bpc_mask)
-{
-    DECLARE_STATE_VARIABLES;
-    DECLARE_CHANNEL_VARIABLES;
-    const unsigned int waitmask = bppmask[state->wmidx];
-    int stopidx;
-    int run_index = 0;
-    int run_end;
-
-    spice_assert(end - i > 0);
-
-    if (i == 0) {
-        unsigned int codewordlen;
-
-        UNCOMPRESS_PIX_START(&cur_row[i]);
-        APPLY_ALL_COMP(UNCOMPRESS_ONE_0);
-
-        if (state->waitcnt) {
-            --state->waitcnt;
-        } else {
-            state->waitcnt = (tabrand(&state->tabrand_seed) & waitmask);
-            UPDATE_MODEL(0);
-        }
-        stopidx = ++i + state->waitcnt;
-    } else {
-        stopidx = i + state->waitcnt;
-    }
-    for (;;) {
-        while (stopidx < end) {
-            for (; i <= stopidx; i++) {
-                unsigned int codewordlen;
-                RLE_PRED_IMP;
-                UNCOMPRESS_PIX_START(&cur_row[i]);
-                APPLY_ALL_COMP(UNCOMPRESS_ONE);
-            }
-
-            UPDATE_MODEL(stopidx);
-
-            stopidx = i + (tabrand(&state->tabrand_seed) & waitmask);
-        }
-
-        for (; i < end; i++) {
-            unsigned int codewordlen;
-            RLE_PRED_IMP;
-            UNCOMPRESS_PIX_START(&cur_row[i]);
-            APPLY_ALL_COMP(UNCOMPRESS_ONE);
-        }
-
-        state->waitcnt = stopidx - end;
-
-        return;
-
-do_run:
-        state->waitcnt = stopidx - i;
-        run_index = i;
-        run_end = i + decode_state_run(encoder, state);
-
-        for (; i < run_end; i++) {
-            UNCOMPRESS_PIX_START(&cur_row[i]);
-            COPY_PIXEL(&cur_row[i], &cur_row[i - 1]);
-        }
-
-        if (i == end) {
-            return;
-        }
-
-        stopidx = i + state->waitcnt;
-    }
-}
-
-static void FNAME_DECL(uncompress_row)(const PIXEL * const prev_row,
-                                       PIXEL * const cur_row,
-                                       unsigned int width)
-
-{
-    DECLARE_STATE_VARIABLES;
-    const unsigned int bpc = BPC;
-    const unsigned int bpc_mask = BPC_MASK;
-    unsigned int pos = 0;
-
-    while ((DEFwmimax > (int)state->wmidx) && (state->wmileft <= width)) {
-        if (state->wmileft) {
-            FNAME_CALL(uncompress_row_seg)(prev_row, cur_row, pos,
-                                           pos + state->wmileft, bpc, bpc_mask);
-            pos += state->wmileft;
-            width -= state->wmileft;
-        }
-
-        state->wmidx++;
-        set_wm_trigger(state);
-        state->wmileft = DEFwminext;
-    }
-
-    if (width) {
-        FNAME_CALL(uncompress_row_seg)(prev_row, cur_row, pos,
-                                       pos + width, bpc, bpc_mask);
-        if (DEFwmimax > (int)state->wmidx) {
-            state->wmileft -= width;
-        }
-    }
-
-    spice_assert((int)state->wmidx <= DEFwmimax);
-    spice_assert(state->wmidx <= 32);
-    spice_assert(DEFwminext > 0);
-}
-
-#undef PIXEL
-#undef FARGS_CALL
-#undef FARGS_DECL
-#undef FNAME
-#undef FNAME_CALL
-#undef FNAME_DECL
-#undef _PIXEL_A
-#undef _PIXEL_B
-#undef SAME_PIXEL
-#undef RLE_PRED_IMP
-#undef UPDATE_MODEL
-#undef DECORRELATE_0
-#undef DECORRELATE
-#undef COMPRESS_ONE_0
-#undef COMPRESS_ONE
-#undef CORRELATE_0
-#undef CORRELATE
-#undef UNCOMPRESS_ONE_ROW0_0
-#undef UNCOMPRESS_ONE_ROW0
-#undef UNCOMPRESS_ONE_0
-#undef UNCOMPRESS_ONE
-#undef golomb_coding
-#undef golomb_decoding
-#undef update_model
-#undef find_bucket
-#undef family
-#undef BPC
-#undef BPC_MASK
-#undef COMPRESS_IMP
-#undef SET_r
-#undef GET_r
-#undef SET_g
-#undef GET_g
-#undef SET_b
-#undef GET_b
-#undef SET_a
-#undef GET_a
-#undef UNCOMPRESS_PIX_START
-#undef UPDATE_MODEL_COMP
-#undef APPLY_ALL_COMP
-#undef DECLARE_STATE_VARIABLES
-#undef DECLARE_CHANNEL_VARIABLES
-#undef COPY_PIXEL
commit 3618db77b5801e50538b053f989d3de44a65a7b0
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Tue Jul 10 11:02:21 2018 +0200

    quic: Unify rgb/non-rgb macro declarations
    
    This commit adds a common block of macro declarations at the top of
    quic_tmpl.c and quic_rgb_tmpl.c. This block is identical between the 2
    files, and is one big step towards making the 2 files identical.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/common/quic_rgb_tmpl.c b/common/quic_rgb_tmpl.c
index 29f1cab..fbfd248 100644
--- a/common/quic_rgb_tmpl.c
+++ b/common/quic_rgb_tmpl.c
@@ -21,28 +21,59 @@
 
 #define COMPRESS_IMP
 
-#define FARGS_DECL(arg1, ...) (Encoder *encoder, arg1, ##__VA_ARGS__)
-#define FARGS_CALL(arg1, ...) (encoder, arg1, ##__VA_ARGS__)
-#define SAME_PIXEL(p1, p2)                                 \
+#if defined(ONE_BYTE) || defined(FOUR_BYTE)
+#  define FARGS_DECL(arg1, ...) (Encoder *encoder, Channel *channel_a, arg1, ##__VA_ARGS__)
+#  define FARGS_CALL(arg1, ...) (encoder, channel_a, arg1, ##__VA_ARGS__)
+#  define UNCOMPRESS_PIX_START(row) do { } while (0)
+#  define SET_a(pix, val) ((pix)->a = val)
+#  define GET_a(pix) ((pix)->a)
+#  define SAME_PIXEL(p1, p2) (GET_a(p1) == GET_a(p2))
+#  define COPY_PIXEL(dest, src) \
+    SET_a(dest, GET_a(src));
+#  define DECLARE_STATE_VARIABLES \
+    CommonState *state = &channel_a->state
+#  define DECLARE_CHANNEL_VARIABLES \
+    BYTE * const correlate_row_a = channel_a->correlate_row
+#  define APPLY_ALL_COMP(macro, ...) \
+    macro(a, ## __VA_ARGS__)
+#else
+#  define FARGS_DECL(arg1, ...) (Encoder *encoder, arg1, ##__VA_ARGS__)
+#  define FARGS_CALL(arg1, ...) (encoder, arg1, ##__VA_ARGS__)
+#  define SAME_PIXEL(p1, p2)                               \
     (GET_r(p1) == GET_r(p2) && GET_g(p1) == GET_g(p2) &&   \
      GET_b(p1) == GET_b(p2))
-#define COPY_PIXEL(dest, src) \
+#  define COPY_PIXEL(dest, src) \
     SET_r(dest, GET_r(src)); \
     SET_g(dest, GET_g(src)); \
     SET_b(dest, GET_b(src))
-#define DECLARE_STATE_VARIABLES \
+#  define DECLARE_STATE_VARIABLES \
     CommonState *state = &encoder->rgb_state
-#define DECLARE_CHANNEL_VARIABLES \
+#  define DECLARE_CHANNEL_VARIABLES \
     Channel * const channel_r = encoder->channels; \
     Channel * const channel_g = channel_r + 1; \
     Channel * const channel_b = channel_g + 1; \
     BYTE * const correlate_row_r = channel_r->correlate_row; \
     BYTE * const correlate_row_g = channel_g->correlate_row; \
     BYTE * const correlate_row_b = channel_b->correlate_row
-#define APPLY_ALL_COMP(macro, ...) \
+#  define APPLY_ALL_COMP(macro, ...) \
     macro(r, ## __VA_ARGS__); \
     macro(g, ## __VA_ARGS__); \
     macro(b, ## __VA_ARGS__)
+#endif
+
+#ifdef ONE_BYTE
+#undef ONE_BYTE
+#define FNAME(name) quic_one_##name
+#define PIXEL one_byte_t
+#define BPC 8
+#endif
+
+#ifdef FOUR_BYTE
+#undef FOUR_BYTE
+#define FNAME(name) quic_four_##name
+#define PIXEL four_bytes_t
+#define BPC 8
+#endif
 
 #ifdef QUIC_RGB32
 #undef QUIC_RGB32
@@ -91,7 +122,7 @@
 #define PIXEL rgb32_pixel_t
 #define FNAME(name) quic_rgb16_to_32_##name
 #define BPC 5
-#define COMPRESS_IMP
+#undef COMPRESS_IMP
 #define SET_r(pix, val) ((pix)->r = ((val) << 3) | (((val) & 0x1f) >> 2))
 #define GET_r(pix) ((pix)->r >> 3)
 #define SET_g(pix, val) ((pix)->g = ((val) << 3) | (((val) & 0x1f) >> 2))
@@ -628,6 +659,8 @@ static void FNAME_DECL(uncompress_row)(const PIXEL * const prev_row,
 #undef GET_g
 #undef SET_b
 #undef GET_b
+#undef SET_a
+#undef GET_a
 #undef UNCOMPRESS_PIX_START
 #undef UPDATE_MODEL_COMP
 #undef APPLY_ALL_COMP
diff --git a/common/quic_tmpl.c b/common/quic_tmpl.c
index 96db766..c2a1b66 100644
--- a/common/quic_tmpl.c
+++ b/common/quic_tmpl.c
@@ -19,28 +19,53 @@
 #include <config.h>
 #endif
 
-#define FARGS_DECL(...) (Encoder *encoder, Channel *channel_a, ##__VA_ARGS__)
-#define FARGS_CALL(...) (encoder, channel_a, ##__VA_ARGS__)
-#define UNCOMPRESS_PIX_START(row) do { } while (0)
-#define SET_a(pix, val) ((pix)->a = val)
-#define GET_a(pix) ((pix)->a)
-#define SAME_PIXEL(p1, p2)                                 \
-     (GET_a(p1) == GET_a(p2))
-#define COPY_PIXEL(dest, src) \
+#define COMPRESS_IMP
+
+#if defined(ONE_BYTE) || defined(FOUR_BYTE)
+#  define FARGS_DECL(arg1, ...) (Encoder *encoder, Channel *channel_a, arg1, ##__VA_ARGS__)
+#  define FARGS_CALL(arg1, ...) (encoder, channel_a, arg1, ##__VA_ARGS__)
+#  define UNCOMPRESS_PIX_START(row) do { } while (0)
+#  define SET_a(pix, val) ((pix)->a = val)
+#  define GET_a(pix) ((pix)->a)
+#  define SAME_PIXEL(p1, p2) (GET_a(p1) == GET_a(p2))
+#  define COPY_PIXEL(dest, src) \
     SET_a(dest, GET_a(src));
-#define DECLARE_STATE_VARIABLES \
+#  define DECLARE_STATE_VARIABLES \
     CommonState *state = &channel_a->state
-#define DECLARE_CHANNEL_VARIABLES \
+#  define DECLARE_CHANNEL_VARIABLES \
     BYTE * const correlate_row_a = channel_a->correlate_row
-#define APPLY_ALL_COMP(macro, ...) \
+#  define APPLY_ALL_COMP(macro, ...) \
     macro(a, ## __VA_ARGS__)
+#else
+#  define FARGS_DECL(arg1, ...) (Encoder *encoder, arg1, ##__VA_ARGS__)
+#  define FARGS_CALL(arg1, ...) (encoder, arg1, ##__VA_ARGS__)
+#  define SAME_PIXEL(p1, p2)                               \
+    (GET_r(p1) == GET_r(p2) && GET_g(p1) == GET_g(p2) &&   \
+     GET_b(p1) == GET_b(p2))
+#  define COPY_PIXEL(dest, src) \
+    SET_r(dest, GET_r(src)); \
+    SET_g(dest, GET_g(src)); \
+    SET_b(dest, GET_b(src))
+#  define DECLARE_STATE_VARIABLES \
+    CommonState *state = &encoder->rgb_state
+#  define DECLARE_CHANNEL_VARIABLES \
+    Channel * const channel_r = encoder->channels; \
+    Channel * const channel_g = channel_r + 1; \
+    Channel * const channel_b = channel_g + 1; \
+    BYTE * const correlate_row_r = channel_r->correlate_row; \
+    BYTE * const correlate_row_g = channel_g->correlate_row; \
+    BYTE * const correlate_row_b = channel_b->correlate_row
+#  define APPLY_ALL_COMP(macro, ...) \
+    macro(r, ## __VA_ARGS__); \
+    macro(g, ## __VA_ARGS__); \
+    macro(b, ## __VA_ARGS__)
+#endif
 
 #ifdef ONE_BYTE
 #undef ONE_BYTE
 #define FNAME(name) quic_one_##name
 #define PIXEL one_byte_t
 #define BPC 8
-
 #endif
 
 #ifdef FOUR_BYTE
@@ -48,13 +73,76 @@
 #define FNAME(name) quic_four_##name
 #define PIXEL four_bytes_t
 #define BPC 8
+#endif
+
+#ifdef QUIC_RGB32
+#undef QUIC_RGB32
+#define PIXEL rgb32_pixel_t
+#define FNAME(name) quic_rgb32_##name
+#define BPC 8
+#define SET_r(pix, val) ((pix)->r = val)
+#define GET_r(pix) ((pix)->r)
+#define SET_g(pix, val) ((pix)->g = val)
+#define GET_g(pix) ((pix)->g)
+#define SET_b(pix, val) ((pix)->b = val)
+#define GET_b(pix) ((pix)->b)
+#define UNCOMPRESS_PIX_START(pix) ((pix)->pad = 0)
+#endif
 
+#ifdef QUIC_RGB24
+#undef QUIC_RGB24
+#define PIXEL rgb24_pixel_t
+#define FNAME(name) quic_rgb24_##name
+#define BPC 8
+#define SET_r(pix, val) ((pix)->r = val)
+#define GET_r(pix) ((pix)->r)
+#define SET_g(pix, val) ((pix)->g = val)
+#define GET_g(pix) ((pix)->g)
+#define SET_b(pix, val) ((pix)->b = val)
+#define GET_b(pix) ((pix)->b)
+#define UNCOMPRESS_PIX_START(pix)
+#endif
+
+#ifdef QUIC_RGB16
+#undef QUIC_RGB16
+#define PIXEL rgb16_pixel_t
+#define FNAME(name) quic_rgb16_##name
+#define BPC 5
+#define SET_r(pix, val) (*(pix) = (*(pix) & ~(0x1f << 10)) | ((val) << 10))
+#define GET_r(pix) ((*(pix) >> 10) & 0x1f)
+#define SET_g(pix, val) (*(pix) = (*(pix) & ~(0x1f << 5)) | ((val) << 5))
+#define GET_g(pix) ((*(pix) >> 5) & 0x1f)
+#define SET_b(pix, val) (*(pix) = (*(pix) & ~0x1f) | (val))
+#define GET_b(pix) (*(pix) & 0x1f)
+#define UNCOMPRESS_PIX_START(pix) (*(pix) = 0)
+#endif
+
+#ifdef QUIC_RGB16_TO_32
+#undef QUIC_RGB16_TO_32
+#define PIXEL rgb32_pixel_t
+#define FNAME(name) quic_rgb16_to_32_##name
+#define BPC 5
+#undef COMPRESS_IMP
+#define SET_r(pix, val) ((pix)->r = ((val) << 3) | (((val) & 0x1f) >> 2))
+#define GET_r(pix) ((pix)->r >> 3)
+#define SET_g(pix, val) ((pix)->g = ((val) << 3) | (((val) & 0x1f) >> 2))
+#define GET_g(pix) ((pix)->g >> 3)
+#define SET_b(pix, val) ((pix)->b = ((val) << 3) | (((val) & 0x1f) >> 2))
+#define GET_b(pix) ((pix)->b >> 3)
+#define UNCOMPRESS_PIX_START(pix) ((pix)->pad = 0)
 #endif
 
 #define FNAME_DECL(name) FNAME(name) FARGS_DECL
 #define FNAME_CALL(name) FNAME(name) FARGS_CALL
 
-#if BPC == 8
+#if BPC == 5
+#  define golomb_coding golomb_coding_5bpc
+#  define golomb_decoding golomb_decoding_5bpc
+#  define update_model update_model_5bpc
+#  define find_bucket find_bucket_5bpc
+#  define family family_5bpc
+#  define BPC_MASK 0x1fU
+#elif BPC == 8
 #  define golomb_coding golomb_coding_8bpc
 #  define golomb_decoding golomb_decoding_8bpc
 #  define update_model update_model_8bpc
@@ -62,7 +150,7 @@
 #  define family family_8bpc
 #  define BPC_MASK 0xffU
 #else
-#  error BPC must be 8
+#  error BPC must be 5 or 8
 #endif
 
 #define _PIXEL_A(channel, curr) ((unsigned int)GET_##channel((curr) - 1))
@@ -111,6 +199,8 @@ if (SAME_PIXEL(&prev_row[i - 1], &prev_row[i])) {
     }                                                                               \
 }
 
+#ifdef COMPRESS_IMP
+
 static void FNAME_DECL(compress_row0_seg)(int i,
                                           const PIXEL * const cur_row,
                                           const int end,
@@ -302,6 +392,8 @@ static void FNAME_DECL(compress_row)(const PIXEL * const prev_row,
     spice_assert(DEFwminext > 0);
 }
 
+#endif
+
 #define UNCOMPRESS_ONE_ROW0_0(channel)                                                                      \
     correlate_row_##channel[0] = (BYTE)golomb_decoding(find_bucket(channel_##channel,                       \
                                                                    correlate_row_##channel[-1])->bestcode,  \
@@ -559,6 +651,13 @@ static void FNAME_DECL(uncompress_row)(const PIXEL * const prev_row,
 #undef family
 #undef BPC
 #undef BPC_MASK
+#undef COMPRESS_IMP
+#undef SET_r
+#undef GET_r
+#undef SET_g
+#undef GET_g
+#undef SET_b
+#undef GET_b
 #undef SET_a
 #undef GET_a
 #undef UNCOMPRESS_PIX_START
commit 79a6ca2a5156e074808682318a0550d5ea641569
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Tue Jul 10 11:02:20 2018 +0200

    quic: Reorder macro declarations
    
    This commit reorders the macro declarations at the beginning of
    quic_tmpl.c and quic_rgb_tmpl.c so that they follow a similar order.
    This does the same for the #undef at the end of both file.
    This commit is only code movement, and should not add/remove anything
    which was not there before. The next commit will unify the macro
    declarations and #undef.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/common/quic_rgb_tmpl.c b/common/quic_rgb_tmpl.c
index 2221201..29f1cab 100644
--- a/common/quic_rgb_tmpl.c
+++ b/common/quic_rgb_tmpl.c
@@ -19,15 +19,36 @@
 #include <config.h>
 #endif
 
+#define COMPRESS_IMP
+
 #define FARGS_DECL(arg1, ...) (Encoder *encoder, arg1, ##__VA_ARGS__)
 #define FARGS_CALL(arg1, ...) (encoder, arg1, ##__VA_ARGS__)
+#define SAME_PIXEL(p1, p2)                                 \
+    (GET_r(p1) == GET_r(p2) && GET_g(p1) == GET_g(p2) &&   \
+     GET_b(p1) == GET_b(p2))
+#define COPY_PIXEL(dest, src) \
+    SET_r(dest, GET_r(src)); \
+    SET_g(dest, GET_g(src)); \
+    SET_b(dest, GET_b(src))
+#define DECLARE_STATE_VARIABLES \
+    CommonState *state = &encoder->rgb_state
+#define DECLARE_CHANNEL_VARIABLES \
+    Channel * const channel_r = encoder->channels; \
+    Channel * const channel_g = channel_r + 1; \
+    Channel * const channel_b = channel_g + 1; \
+    BYTE * const correlate_row_r = channel_r->correlate_row; \
+    BYTE * const correlate_row_g = channel_g->correlate_row; \
+    BYTE * const correlate_row_b = channel_b->correlate_row
+#define APPLY_ALL_COMP(macro, ...) \
+    macro(r, ## __VA_ARGS__); \
+    macro(g, ## __VA_ARGS__); \
+    macro(b, ## __VA_ARGS__)
 
 #ifdef QUIC_RGB32
 #undef QUIC_RGB32
 #define PIXEL rgb32_pixel_t
 #define FNAME(name) quic_rgb32_##name
 #define BPC 8
-#define COMPRESS_IMP
 #define SET_r(pix, val) ((pix)->r = val)
 #define GET_r(pix) ((pix)->r)
 #define SET_g(pix, val) ((pix)->g = val)
@@ -42,7 +63,6 @@
 #define PIXEL rgb24_pixel_t
 #define FNAME(name) quic_rgb24_##name
 #define BPC 8
-#define COMPRESS_IMP
 #define SET_r(pix, val) ((pix)->r = val)
 #define GET_r(pix) ((pix)->r)
 #define SET_g(pix, val) ((pix)->g = val)
@@ -57,7 +77,6 @@
 #define PIXEL rgb16_pixel_t
 #define FNAME(name) quic_rgb16_##name
 #define BPC 5
-#define COMPRESS_IMP
 #define SET_r(pix, val) (*(pix) = (*(pix) & ~(0x1f << 10)) | ((val) << 10))
 #define GET_r(pix) ((*(pix) >> 10) & 0x1f)
 #define SET_g(pix, val) (*(pix) = (*(pix) & ~(0x1f << 5)) | ((val) << 5))
@@ -72,6 +91,7 @@
 #define PIXEL rgb32_pixel_t
 #define FNAME(name) quic_rgb16_to_32_##name
 #define BPC 5
+#define COMPRESS_IMP
 #define SET_r(pix, val) ((pix)->r = ((val) << 3) | (((val) & 0x1f) >> 2))
 #define GET_r(pix) ((pix)->r >> 3)
 #define SET_g(pix, val) ((pix)->g = ((val) << 3) | (((val) & 0x1f) >> 2))
@@ -84,23 +104,6 @@
 #define FNAME_DECL(name) FNAME(name) FARGS_DECL
 #define FNAME_CALL(name) FNAME(name) FARGS_CALL
 
-#define SAME_PIXEL(p1, p2)                                 \
-    (GET_r(p1) == GET_r(p2) && GET_g(p1) == GET_g(p2) &&   \
-     GET_b(p1) == GET_b(p2))
-#define COPY_PIXEL(dest, src) \
-    SET_r(dest, GET_r(src)); \
-    SET_g(dest, GET_g(src)); \
-    SET_b(dest, GET_b(src))
-#define DECLARE_STATE_VARIABLES \
-    CommonState *state = &encoder->rgb_state
-#define DECLARE_CHANNEL_VARIABLES \
-    Channel * const channel_r = encoder->channels; \
-    Channel * const channel_g = channel_r + 1; \
-    Channel * const channel_b = channel_g + 1; \
-    BYTE * const correlate_row_r = channel_r->correlate_row; \
-    BYTE * const correlate_row_g = channel_g->correlate_row; \
-    BYTE * const correlate_row_b = channel_b->correlate_row
-
 #if BPC == 5
 #  define golomb_coding golomb_coding_5bpc
 #  define golomb_decoding golomb_decoding_5bpc
@@ -156,11 +159,6 @@
                  correlate_row_##channel[index])
 #define UPDATE_MODEL(index) APPLY_ALL_COMP(UPDATE_MODEL_COMP, index)
 
-#define APPLY_ALL_COMP(macro, ...) \
-    macro(r, ## __VA_ARGS__); \
-    macro(g, ## __VA_ARGS__); \
-    macro(b, ## __VA_ARGS__)
-
 #define RLE_PRED_IMP                                                                \
 if (SAME_PIXEL(&prev_row[i - 1], &prev_row[i])) {                                   \
     if (run_index != i && i > 2 && SAME_PIXEL(&cur_row[i - 1], &cur_row[i - 2])) {  \
@@ -212,6 +210,9 @@ static void FNAME_DECL(compress_row0_seg)(int i,
     state->waitcnt = stopidx - end;
 }
 
+#undef COMPRESS_ONE_ROW0_0
+#undef COMPRESS_ONE_ROW0
+
 static void FNAME_DECL(compress_row0)(const PIXEL *cur_row, unsigned int width)
 {
     DECLARE_STATE_VARIABLES;
@@ -605,8 +606,6 @@ static void FNAME_DECL(uncompress_row)(const PIXEL * const prev_row,
 #undef UPDATE_MODEL
 #undef DECORRELATE_0
 #undef DECORRELATE
-#undef COMPRESS_ONE_ROW0_0
-#undef COMPRESS_ONE_ROW0
 #undef COMPRESS_ONE_0
 #undef COMPRESS_ONE
 #undef CORRELATE_0
diff --git a/common/quic_tmpl.c b/common/quic_tmpl.c
index 525eb99..96db766 100644
--- a/common/quic_tmpl.c
+++ b/common/quic_tmpl.c
@@ -19,37 +19,41 @@
 #include <config.h>
 #endif
 
+#define FARGS_DECL(...) (Encoder *encoder, Channel *channel_a, ##__VA_ARGS__)
+#define FARGS_CALL(...) (encoder, channel_a, ##__VA_ARGS__)
+#define UNCOMPRESS_PIX_START(row) do { } while (0)
+#define SET_a(pix, val) ((pix)->a = val)
+#define GET_a(pix) ((pix)->a)
+#define SAME_PIXEL(p1, p2)                                 \
+     (GET_a(p1) == GET_a(p2))
+#define COPY_PIXEL(dest, src) \
+    SET_a(dest, GET_a(src));
+#define DECLARE_STATE_VARIABLES \
+    CommonState *state = &channel_a->state
+#define DECLARE_CHANNEL_VARIABLES \
+    BYTE * const correlate_row_a = channel_a->correlate_row
+#define APPLY_ALL_COMP(macro, ...) \
+    macro(a, ## __VA_ARGS__)
+
 #ifdef ONE_BYTE
 #undef ONE_BYTE
 #define FNAME(name) quic_one_##name
 #define PIXEL one_byte_t
+#define BPC 8
+
 #endif
 
 #ifdef FOUR_BYTE
 #undef FOUR_BYTE
 #define FNAME(name) quic_four_##name
 #define PIXEL four_bytes_t
+#define BPC 8
+
 #endif
 
-#define FARGS_DECL(...) (Encoder *encoder, Channel *channel_a, ##__VA_ARGS__)
-#define FARGS_CALL(...) (encoder, channel_a, ##__VA_ARGS__)
 #define FNAME_DECL(name) FNAME(name) FARGS_DECL
 #define FNAME_CALL(name) FNAME(name) FARGS_CALL
 
-#define BPC 8
-
-#define SET_a(pix, val) ((pix)->a = val)
-#define GET_a(pix) ((pix)->a)
-
-#define SAME_PIXEL(p1, p2)                                 \
-     (GET_a(p1) == GET_a(p2))
-#define COPY_PIXEL(dest, src) \
-    SET_a(dest, GET_a(src));
-#define DECLARE_STATE_VARIABLES \
-    CommonState *state = &channel_a->state
-#define DECLARE_CHANNEL_VARIABLES \
-    BYTE * const correlate_row_a = channel_a->correlate_row
-
 #if BPC == 8
 #  define golomb_coding golomb_coding_8bpc
 #  define golomb_decoding golomb_decoding_8bpc
@@ -64,13 +68,6 @@
 #define _PIXEL_A(channel, curr) ((unsigned int)GET_##channel((curr) - 1))
 #define _PIXEL_B(channel, prev) ((unsigned int)GET_##channel(prev))
 
-#define RLE_PRED_IMP                                                       \
-if (SAME_PIXEL(&prev_row[i - 1], &prev_row[i])) {                                   \
-    if (run_index != i && i > 2 && SAME_PIXEL(&cur_row[i - 1], &cur_row[i - 2])) {  \
-        goto do_run;                                                       \
-    }                                                                      \
-}
-
 /*  a  */
 
 #define DECORRELATE_0(channel, curr, bpc_mask)\
@@ -107,8 +104,12 @@ if (SAME_PIXEL(&prev_row[i - 1], &prev_row[i])) {
                  correlate_row_##channel[index])
 #define UPDATE_MODEL(index) APPLY_ALL_COMP(UPDATE_MODEL_COMP, index)
 
-#define APPLY_ALL_COMP(macro, ...) \
-    macro(a, ## __VA_ARGS__)
+#define RLE_PRED_IMP                                                                \
+if (SAME_PIXEL(&prev_row[i - 1], &prev_row[i])) {                                   \
+    if (run_index != i && i > 2 && SAME_PIXEL(&cur_row[i - 1], &cur_row[i - 2])) {  \
+        goto do_run;                                                                \
+    }                                                                               \
+}
 
 static void FNAME_DECL(compress_row0_seg)(int i,
                                           const PIXEL * const cur_row,
@@ -301,8 +302,6 @@ static void FNAME_DECL(compress_row)(const PIXEL * const prev_row,
     spice_assert(DEFwminext > 0);
 }
 
-#define UNCOMPRESS_PIX_START(row) do { } while (0)
-
 #define UNCOMPRESS_ONE_ROW0_0(channel)                                                                      \
     correlate_row_##channel[0] = (BYTE)golomb_decoding(find_bucket(channel_##channel,                       \
                                                                    correlate_row_##channel[-1])->bestcode,  \
@@ -542,10 +541,17 @@ static void FNAME_DECL(uncompress_row)(const PIXEL * const prev_row,
 #undef _PIXEL_B
 #undef SAME_PIXEL
 #undef RLE_PRED_IMP
+#undef UPDATE_MODEL
 #undef DECORRELATE_0
 #undef DECORRELATE
+#undef COMPRESS_ONE_0
+#undef COMPRESS_ONE
 #undef CORRELATE_0
 #undef CORRELATE
+#undef UNCOMPRESS_ONE_ROW0_0
+#undef UNCOMPRESS_ONE_ROW0
+#undef UNCOMPRESS_ONE_0
+#undef UNCOMPRESS_ONE
 #undef golomb_coding
 #undef golomb_decoding
 #undef update_model
@@ -553,17 +559,10 @@ static void FNAME_DECL(uncompress_row)(const PIXEL * const prev_row,
 #undef family
 #undef BPC
 #undef BPC_MASK
-#undef UPDATE_MODEL
-#undef UNCOMPRESS_PIX_START
-#undef UPDATE_MODEL_COMP
-#undef COMPRESS_ONE_0
-#undef COMPRESS_ONE
-#undef UNCOMPRESS_ONE_ROW0
-#undef UNCOMPRESS_ONE_ROW0_0
-#undef UNCOMPRESS_ONE_0
-#undef UNCOMPRESS_ONE
 #undef SET_a
 #undef GET_a
+#undef UNCOMPRESS_PIX_START
+#undef UPDATE_MODEL_COMP
 #undef APPLY_ALL_COMP
 #undef DECLARE_STATE_VARIABLES
 #undef DECLARE_CHANNEL_VARIABLES
commit 291475318f46bbff46c8e8431e7b4257af357fa8
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Tue Jul 10 11:02:19 2018 +0200

    quic: Introduce COPY_PIXEL macro
    
    Define and reuse a COPY_PIXEL macro to copy a pixel.
    This will help in making quic_tmpl.c and quic_rgb_tmpl.c identical.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/common/quic_rgb_tmpl.c b/common/quic_rgb_tmpl.c
index 3625728..2221201 100644
--- a/common/quic_rgb_tmpl.c
+++ b/common/quic_rgb_tmpl.c
@@ -87,6 +87,10 @@
 #define SAME_PIXEL(p1, p2)                                 \
     (GET_r(p1) == GET_r(p2) && GET_g(p1) == GET_g(p2) &&   \
      GET_b(p1) == GET_b(p2))
+#define COPY_PIXEL(dest, src) \
+    SET_r(dest, GET_r(src)); \
+    SET_g(dest, GET_g(src)); \
+    SET_b(dest, GET_b(src))
 #define DECLARE_STATE_VARIABLES \
     CommonState *state = &encoder->rgb_state
 #define DECLARE_CHANNEL_VARIABLES \
@@ -541,9 +545,7 @@ do_run:
 
         for (; i < run_end; i++) {
             UNCOMPRESS_PIX_START(&cur_row[i]);
-            SET_r(&cur_row[i], GET_r(&cur_row[i - 1]));
-            SET_g(&cur_row[i], GET_g(&cur_row[i - 1]));
-            SET_b(&cur_row[i], GET_b(&cur_row[i - 1]));
+            COPY_PIXEL(&cur_row[i], &cur_row[i - 1]);
         }
 
         if (i == end) {
@@ -632,3 +634,4 @@ static void FNAME_DECL(uncompress_row)(const PIXEL * const prev_row,
 #undef APPLY_ALL_COMP
 #undef DECLARE_STATE_VARIABLES
 #undef DECLARE_CHANNEL_VARIABLES
+#undef COPY_PIXEL
diff --git a/common/quic_tmpl.c b/common/quic_tmpl.c
index d21f059..525eb99 100644
--- a/common/quic_tmpl.c
+++ b/common/quic_tmpl.c
@@ -43,6 +43,8 @@
 
 #define SAME_PIXEL(p1, p2)                                 \
      (GET_a(p1) == GET_a(p2))
+#define COPY_PIXEL(dest, src) \
+    SET_a(dest, GET_a(src));
 #define DECLARE_STATE_VARIABLES \
     CommonState *state = &channel_a->state
 #define DECLARE_CHANNEL_VARIABLES \
@@ -483,7 +485,7 @@ do_run:
 
         for (; i < run_end; i++) {
             UNCOMPRESS_PIX_START(&cur_row[i]);
-            SET_a(&cur_row[i], GET_a(&cur_row[i - 1]));
+            COPY_PIXEL(&cur_row[i], &cur_row[i - 1]);
         }
 
         if (i == end) {
@@ -565,3 +567,4 @@ static void FNAME_DECL(uncompress_row)(const PIXEL * const prev_row,
 #undef APPLY_ALL_COMP
 #undef DECLARE_STATE_VARIABLES
 #undef DECLARE_CHANNEL_VARIABLES
+#undef COPY_PIXEL
commit c0cc563e10863d73935319f8ef9dd7ef4a5a4d3c
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Tue Jul 10 11:02:18 2018 +0200

    quic: Add DECLARE_*_VARIABLES macros
    
    They will help unify quic_rgb_tmpl.c and quic_tmpl.c
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/common/quic_rgb_tmpl.c b/common/quic_rgb_tmpl.c
index fcb56ff..3625728 100644
--- a/common/quic_rgb_tmpl.c
+++ b/common/quic_rgb_tmpl.c
@@ -87,6 +87,15 @@
 #define SAME_PIXEL(p1, p2)                                 \
     (GET_r(p1) == GET_r(p2) && GET_g(p1) == GET_g(p2) &&   \
      GET_b(p1) == GET_b(p2))
+#define DECLARE_STATE_VARIABLES \
+    CommonState *state = &encoder->rgb_state
+#define DECLARE_CHANNEL_VARIABLES \
+    Channel * const channel_r = encoder->channels; \
+    Channel * const channel_g = channel_r + 1; \
+    Channel * const channel_b = channel_g + 1; \
+    BYTE * const correlate_row_r = channel_r->correlate_row; \
+    BYTE * const correlate_row_g = channel_g->correlate_row; \
+    BYTE * const correlate_row_b = channel_b->correlate_row
 
 #if BPC == 5
 #  define golomb_coding golomb_coding_5bpc
@@ -164,14 +173,8 @@ static void FNAME_DECL(compress_row0_seg)(int i,
                                           SPICE_GNUC_UNUSED const unsigned int bpc,
                                           const unsigned int bpc_mask)
 {
-    CommonState *state = &encoder->rgb_state;
-    Channel * const channel_r = encoder->channels;
-    Channel * const channel_g = channel_r + 1;
-    Channel * const channel_b = channel_g + 1;
-
-    BYTE * const correlate_row_r = channel_r->correlate_row;
-    BYTE * const correlate_row_g = channel_g->correlate_row;
-    BYTE * const correlate_row_b = channel_b->correlate_row;
+    DECLARE_STATE_VARIABLES;
+    DECLARE_CHANNEL_VARIABLES;
     int stopidx;
 
     spice_assert(end - i > 0);
@@ -207,7 +210,7 @@ static void FNAME_DECL(compress_row0_seg)(int i,
 
 static void FNAME_DECL(compress_row0)(const PIXEL *cur_row, unsigned int width)
 {
-    CommonState *state = &encoder->rgb_state;
+    DECLARE_STATE_VARIABLES;
     const unsigned int bpc = BPC;
     const unsigned int bpc_mask = BPC_MASK;
     int pos = 0;
@@ -258,14 +261,8 @@ static void FNAME_DECL(compress_row_seg)(int i,
                                          SPICE_GNUC_UNUSED const unsigned int bpc,
                                          const unsigned int bpc_mask)
 {
-    CommonState *state = &encoder->rgb_state;
-    Channel * const channel_r = encoder->channels;
-    Channel * const channel_g = channel_r + 1;
-    Channel * const channel_b = channel_g + 1;
-
-    BYTE * const correlate_row_r = channel_r->correlate_row;
-    BYTE * const correlate_row_g = channel_g->correlate_row;
-    BYTE * const correlate_row_b = channel_b->correlate_row;
+    DECLARE_STATE_VARIABLES;
+    DECLARE_CHANNEL_VARIABLES;
     int stopidx;
     int run_index = 0;
     int run_size;
@@ -326,7 +323,7 @@ static void FNAME_DECL(compress_row)(const PIXEL * const prev_row,
                                      unsigned int width)
 
 {
-    CommonState *state = &encoder->rgb_state;
+    DECLARE_STATE_VARIABLES;
     const unsigned int bpc = BPC;
     const unsigned int bpc_mask = BPC_MASK;
     unsigned int pos = 0;
@@ -383,14 +380,8 @@ static void FNAME_DECL(uncompress_row0_seg)(int i,
                                             SPICE_GNUC_UNUSED const unsigned int bpc,
                                             const unsigned int bpc_mask)
 {
-    CommonState *state = &encoder->rgb_state;
-    Channel * const channel_r = encoder->channels;
-    Channel * const channel_g = channel_r + 1;
-    Channel * const channel_b = channel_g + 1;
-
-    BYTE * const correlate_row_r = channel_r->correlate_row;
-    BYTE * const correlate_row_g = channel_g->correlate_row;
-    BYTE * const correlate_row_b = channel_b->correlate_row;
+    DECLARE_STATE_VARIABLES;
+    DECLARE_CHANNEL_VARIABLES;
     int stopidx;
 
     spice_assert(end - i > 0);
@@ -436,7 +427,7 @@ static void FNAME_DECL(uncompress_row0)(PIXEL * const cur_row,
                                         unsigned int width)
 
 {
-    CommonState *state = &encoder->rgb_state;
+    DECLARE_STATE_VARIABLES;
     const unsigned int bpc = BPC;
     const unsigned int bpc_mask = BPC_MASK;
     unsigned int pos = 0;
@@ -493,14 +484,8 @@ static void FNAME_DECL(uncompress_row_seg)(const PIXEL * const prev_row,
                                            SPICE_GNUC_UNUSED const unsigned int bpc,
                                            const unsigned int bpc_mask)
 {
-    CommonState *state = &encoder->rgb_state;
-    Channel * const channel_r = encoder->channels;
-    Channel * const channel_g = channel_r + 1;
-    Channel * const channel_b = channel_g + 1;
-
-    BYTE * const correlate_row_r = channel_r->correlate_row;
-    BYTE * const correlate_row_g = channel_g->correlate_row;
-    BYTE * const correlate_row_b = channel_b->correlate_row;
+    DECLARE_STATE_VARIABLES;
+    DECLARE_CHANNEL_VARIABLES;
     const unsigned int waitmask = bppmask[state->wmidx];
     int stopidx;
     int run_index = 0;
@@ -574,7 +559,7 @@ static void FNAME_DECL(uncompress_row)(const PIXEL * const prev_row,
                                        unsigned int width)
 
 {
-    CommonState *state = &encoder->rgb_state;
+    DECLARE_STATE_VARIABLES;
     const unsigned int bpc = BPC;
     const unsigned int bpc_mask = BPC_MASK;
     unsigned int pos = 0;
@@ -645,3 +630,5 @@ static void FNAME_DECL(uncompress_row)(const PIXEL * const prev_row,
 #undef UNCOMPRESS_PIX_START
 #undef UPDATE_MODEL_COMP
 #undef APPLY_ALL_COMP
+#undef DECLARE_STATE_VARIABLES
+#undef DECLARE_CHANNEL_VARIABLES
diff --git a/common/quic_tmpl.c b/common/quic_tmpl.c
index 225a292..d21f059 100644
--- a/common/quic_tmpl.c
+++ b/common/quic_tmpl.c
@@ -43,6 +43,11 @@
 
 #define SAME_PIXEL(p1, p2)                                 \
      (GET_a(p1) == GET_a(p2))
+#define DECLARE_STATE_VARIABLES \
+    CommonState *state = &channel_a->state
+#define DECLARE_CHANNEL_VARIABLES \
+    BYTE * const correlate_row_a = channel_a->correlate_row
+
 #if BPC == 8
 #  define golomb_coding golomb_coding_8bpc
 #  define golomb_decoding golomb_decoding_8bpc
@@ -110,8 +115,8 @@ static void FNAME_DECL(compress_row0_seg)(int i,
                                           SPICE_GNUC_UNUSED const unsigned int bpc,
                                           const unsigned int bpc_mask)
 {
-    CommonState *state = &channel_a->state;
-    BYTE * const correlate_row_a = channel_a->correlate_row;
+    DECLARE_STATE_VARIABLES;
+    DECLARE_CHANNEL_VARIABLES;
     int stopidx;
 
     spice_assert(end - i > 0);
@@ -150,7 +155,7 @@ static void FNAME_DECL(compress_row0_seg)(int i,
 
 static void FNAME_DECL(compress_row0)(const PIXEL *cur_row, unsigned int width)
 {
-    CommonState *state = &channel_a->state;
+    DECLARE_STATE_VARIABLES;
     const unsigned int bpc = BPC;
     const unsigned int bpc_mask = BPC_MASK;
     int pos = 0;
@@ -200,8 +205,8 @@ static void FNAME_DECL(compress_row_seg)(int i,
                                          SPICE_GNUC_UNUSED const unsigned int bpc,
                                          const unsigned int bpc_mask)
 {
-    CommonState *state = &channel_a->state;
-    BYTE * const correlate_row_a = channel_a->correlate_row;
+    DECLARE_STATE_VARIABLES;
+    DECLARE_CHANNEL_VARIABLES;
     int stopidx;
     int run_index = 0;
     int run_size;
@@ -262,7 +267,7 @@ static void FNAME_DECL(compress_row)(const PIXEL * const prev_row,
                                      unsigned int width)
 
 {
-    CommonState *state = &channel_a->state;
+    DECLARE_STATE_VARIABLES;
     const unsigned int bpc = BPC;
     const unsigned int bpc_mask = BPC_MASK;
     unsigned int pos = 0;
@@ -318,8 +323,8 @@ static void FNAME_DECL(uncompress_row0_seg)(int i,
                                             SPICE_GNUC_UNUSED const unsigned int bpc,
                                             const unsigned int bpc_mask)
 {
-    CommonState *state = &channel_a->state;
-    BYTE * const correlate_row_a = channel_a->correlate_row;
+    DECLARE_STATE_VARIABLES;
+    DECLARE_CHANNEL_VARIABLES;
     int stopidx;
 
     spice_assert(end - i > 0);
@@ -361,10 +366,11 @@ static void FNAME_DECL(uncompress_row0_seg)(int i,
     state->waitcnt = stopidx - end;
 }
 
-static void FNAME_DECL(uncompress_row0)(PIXEL * const cur_row, unsigned int width)
+static void FNAME_DECL(uncompress_row0)(PIXEL * const cur_row,
+                                        unsigned int width)
 
 {
-    CommonState *state = &channel_a->state;
+    DECLARE_STATE_VARIABLES;
     const unsigned int bpc = BPC;
     const unsigned int bpc_mask = BPC_MASK;
     unsigned int pos = 0;
@@ -420,8 +426,8 @@ static void FNAME_DECL(uncompress_row_seg)(const PIXEL * const prev_row,
                                            SPICE_GNUC_UNUSED const unsigned int bpc,
                                            const unsigned int bpc_mask)
 {
-    CommonState *state = &channel_a->state;
-    BYTE * const correlate_row_a = channel_a->correlate_row;
+    DECLARE_STATE_VARIABLES;
+    DECLARE_CHANNEL_VARIABLES;
     const unsigned int waitmask = bppmask[state->wmidx];
     int stopidx;
     int run_index = 0;
@@ -493,7 +499,7 @@ static void FNAME_DECL(uncompress_row)(const PIXEL * const prev_row,
                                        unsigned int width)
 
 {
-    CommonState *state = &channel_a->state;
+    DECLARE_STATE_VARIABLES;
     const unsigned int bpc = BPC;
     const unsigned int bpc_mask = BPC_MASK;
     unsigned int pos = 0;
@@ -557,3 +563,5 @@ static void FNAME_DECL(uncompress_row)(const PIXEL * const prev_row,
 #undef SET_a
 #undef GET_a
 #undef APPLY_ALL_COMP
+#undef DECLARE_STATE_VARIABLES
+#undef DECLARE_CHANNEL_VARIABLES
commit 8b21fc5ea1dca1af39597cd375537d56400dba53
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Tue Jul 10 11:02:17 2018 +0200

    quic: Move all golomb decoding macros in a single place
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/common/quic_rgb_tmpl.c b/common/quic_rgb_tmpl.c
index 3af1d2e..fcb56ff 100644
--- a/common/quic_rgb_tmpl.c
+++ b/common/quic_rgb_tmpl.c
@@ -26,13 +26,7 @@
 #undef QUIC_RGB32
 #define PIXEL rgb32_pixel_t
 #define FNAME(name) quic_rgb32_##name
-#define golomb_coding golomb_coding_8bpc
-#define golomb_decoding golomb_decoding_8bpc
-#define update_model update_model_8bpc
-#define find_bucket find_bucket_8bpc
-#define family family_8bpc
 #define BPC 8
-#define BPC_MASK 0xffU
 #define COMPRESS_IMP
 #define SET_r(pix, val) ((pix)->r = val)
 #define GET_r(pix) ((pix)->r)
@@ -47,13 +41,7 @@
 #undef QUIC_RGB24
 #define PIXEL rgb24_pixel_t
 #define FNAME(name) quic_rgb24_##name
-#define golomb_coding golomb_coding_8bpc
-#define golomb_decoding golomb_decoding_8bpc
-#define update_model update_model_8bpc
-#define find_bucket find_bucket_8bpc
-#define family family_8bpc
 #define BPC 8
-#define BPC_MASK 0xffU
 #define COMPRESS_IMP
 #define SET_r(pix, val) ((pix)->r = val)
 #define GET_r(pix) ((pix)->r)
@@ -68,13 +56,7 @@
 #undef QUIC_RGB16
 #define PIXEL rgb16_pixel_t
 #define FNAME(name) quic_rgb16_##name
-#define golomb_coding golomb_coding_5bpc
-#define golomb_decoding golomb_decoding_5bpc
-#define update_model update_model_5bpc
-#define find_bucket find_bucket_5bpc
-#define family family_5bpc
 #define BPC 5
-#define BPC_MASK 0x1fU
 #define COMPRESS_IMP
 #define SET_r(pix, val) (*(pix) = (*(pix) & ~(0x1f << 10)) | ((val) << 10))
 #define GET_r(pix) ((*(pix) >> 10) & 0x1f)
@@ -89,14 +71,7 @@
 #undef QUIC_RGB16_TO_32
 #define PIXEL rgb32_pixel_t
 #define FNAME(name) quic_rgb16_to_32_##name
-#define golomb_coding golomb_coding_5bpc
-#define golomb_decoding golomb_decoding_5bpc
-#define update_model update_model_5bpc
-#define find_bucket find_bucket_5bpc
-#define family family_5bpc
 #define BPC 5
-#define BPC_MASK 0x1fU
-
 #define SET_r(pix, val) ((pix)->r = ((val) << 3) | (((val) & 0x1f) >> 2))
 #define GET_r(pix) ((pix)->r >> 3)
 #define SET_g(pix, val) ((pix)->g = ((val) << 3) | (((val) & 0x1f) >> 2))
@@ -113,6 +88,23 @@
     (GET_r(p1) == GET_r(p2) && GET_g(p1) == GET_g(p2) &&   \
      GET_b(p1) == GET_b(p2))
 
+#if BPC == 5
+#  define golomb_coding golomb_coding_5bpc
+#  define golomb_decoding golomb_decoding_5bpc
+#  define update_model update_model_5bpc
+#  define find_bucket find_bucket_5bpc
+#  define family family_5bpc
+#  define BPC_MASK 0x1fU
+#elif BPC == 8
+#  define golomb_coding golomb_coding_8bpc
+#  define golomb_decoding golomb_decoding_8bpc
+#  define update_model update_model_8bpc
+#  define find_bucket find_bucket_8bpc
+#  define family family_8bpc
+#  define BPC_MASK 0xffU
+#else
+#  error BPC must be 5 or 8
+#endif
 
 #define _PIXEL_A(channel, curr) ((unsigned int)GET_##channel((curr) - 1))
 #define _PIXEL_B(channel, prev) ((unsigned int)GET_##channel(prev))
diff --git a/common/quic_tmpl.c b/common/quic_tmpl.c
index a7be9af..225a292 100644
--- a/common/quic_tmpl.c
+++ b/common/quic_tmpl.c
@@ -36,20 +36,23 @@
 #define FNAME_DECL(name) FNAME(name) FARGS_DECL
 #define FNAME_CALL(name) FNAME(name) FARGS_CALL
 
-#define golomb_coding golomb_coding_8bpc
-#define golomb_decoding golomb_decoding_8bpc
-#define update_model update_model_8bpc
-#define find_bucket find_bucket_8bpc
-#define family family_8bpc
-
 #define BPC 8
-#define BPC_MASK 0xffU
 
 #define SET_a(pix, val) ((pix)->a = val)
 #define GET_a(pix) ((pix)->a)
 
 #define SAME_PIXEL(p1, p2)                                 \
      (GET_a(p1) == GET_a(p2))
+#if BPC == 8
+#  define golomb_coding golomb_coding_8bpc
+#  define golomb_decoding golomb_decoding_8bpc
+#  define update_model update_model_8bpc
+#  define find_bucket find_bucket_8bpc
+#  define family family_8bpc
+#  define BPC_MASK 0xffU
+#else
+#  error BPC must be 8
+#endif
 
 #define _PIXEL_A(channel, curr) ((unsigned int)GET_##channel((curr) - 1))
 #define _PIXEL_B(channel, prev) ((unsigned int)GET_##channel(prev))
commit 0046ee5e8170bb9e71e7504f6226b79d988768b3
Author: Christophe Fergeau <cfergeau at redhat.com>
Date:   Tue Jul 10 11:02:16 2018 +0200

    quic: Wrap declaration/call of quic method in macros
    
    This allows to pass an additional 'channel' argument when needed, and
    should eventually let us unify quic_tmpl.c and quic_rgb_tmpl.c
    
    Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>
    Acked-by: Frediano Ziglio <fziglio at redhat.com>

diff --git a/common/quic_rgb_tmpl.c b/common/quic_rgb_tmpl.c
index 5dbc873..3af1d2e 100644
--- a/common/quic_rgb_tmpl.c
+++ b/common/quic_rgb_tmpl.c
@@ -19,6 +19,9 @@
 #include <config.h>
 #endif
 
+#define FARGS_DECL(arg1, ...) (Encoder *encoder, arg1, ##__VA_ARGS__)
+#define FARGS_CALL(arg1, ...) (encoder, arg1, ##__VA_ARGS__)
+
 #ifdef QUIC_RGB32
 #undef QUIC_RGB32
 #define PIXEL rgb32_pixel_t
@@ -103,6 +106,9 @@
 #define UNCOMPRESS_PIX_START(pix) ((pix)->pad = 0)
 #endif
 
+#define FNAME_DECL(name) FNAME(name) FARGS_DECL
+#define FNAME_CALL(name) FNAME(name) FARGS_CALL
+
 #define SAME_PIXEL(p1, p2)                                 \
     (GET_r(p1) == GET_r(p2) && GET_g(p1) == GET_g(p2) &&   \
      GET_b(p1) == GET_b(p2))
@@ -159,12 +165,12 @@ if (SAME_PIXEL(&prev_row[i - 1], &prev_row[i])) {
 
 #ifdef COMPRESS_IMP
 
-static void FNAME(compress_row0_seg)(Encoder *encoder, int i,
-                                     const PIXEL * const cur_row,
-                                     const int end,
-                                     const unsigned int waitmask,
-                                     SPICE_GNUC_UNUSED const unsigned int bpc,
-                                     const unsigned int bpc_mask)
+static void FNAME_DECL(compress_row0_seg)(int i,
+                                          const PIXEL * const cur_row,
+                                          const int end,
+                                          const unsigned int waitmask,
+                                          SPICE_GNUC_UNUSED const unsigned int bpc,
+                                          const unsigned int bpc_mask)
 {
     CommonState *state = &encoder->rgb_state;
     Channel * const channel_r = encoder->channels;
@@ -207,8 +213,7 @@ static void FNAME(compress_row0_seg)(Encoder *encoder, int i,
     state->waitcnt = stopidx - end;
 }
 
-static void FNAME(compress_row0)(Encoder *encoder, const PIXEL *cur_row,
-                                 unsigned int width)
+static void FNAME_DECL(compress_row0)(const PIXEL *cur_row, unsigned int width)
 {
     CommonState *state = &encoder->rgb_state;
     const unsigned int bpc = BPC;
@@ -217,8 +222,8 @@ static void FNAME(compress_row0)(Encoder *encoder, const PIXEL *cur_row,
 
     while ((DEFwmimax > (int)state->wmidx) && (state->wmileft <= width)) {
         if (state->wmileft) {
-            FNAME(compress_row0_seg)(encoder, pos, cur_row, pos + state->wmileft,
-                                     bppmask[state->wmidx], bpc, bpc_mask);
+            FNAME_CALL(compress_row0_seg)(pos, cur_row, pos + state->wmileft,
+                                          bppmask[state->wmidx], bpc, bpc_mask);
             width -= state->wmileft;
             pos += state->wmileft;
         }
@@ -229,8 +234,8 @@ static void FNAME(compress_row0)(Encoder *encoder, const PIXEL *cur_row,
     }
 
     if (width) {
-        FNAME(compress_row0_seg)(encoder, pos, cur_row, pos + width,
-                                 bppmask[state->wmidx], bpc, bpc_mask);
+        FNAME_CALL(compress_row0_seg)(pos, cur_row, pos + width,
+                                      bppmask[state->wmidx], bpc, bpc_mask);
         if (DEFwmimax > (int)state->wmidx) {
             state->wmileft -= width;
         }
@@ -253,13 +258,13 @@ static void FNAME(compress_row0)(Encoder *encoder, const PIXEL *cur_row,
     golomb_coding(encoder, correlate_row_##channel[index],                                      \
                  find_bucket(channel_##channel, correlate_row_##channel[index - 1])->bestcode)
 
-static void FNAME(compress_row_seg)(Encoder *encoder, int i,
-                                    const PIXEL * const prev_row,
-                                    const PIXEL * const cur_row,
-                                    const int end,
-                                    const unsigned int waitmask,
-                                    SPICE_GNUC_UNUSED const unsigned int bpc,
-                                    const unsigned int bpc_mask)
+static void FNAME_DECL(compress_row_seg)(int i,
+                                         const PIXEL * const prev_row,
+                                         const PIXEL * const cur_row,
+                                         const int end,
+                                         const unsigned int waitmask,
+                                         SPICE_GNUC_UNUSED const unsigned int bpc,
+                                         const unsigned int bpc_mask)
 {
     CommonState *state = &encoder->rgb_state;
     Channel * const channel_r = encoder->channels;
@@ -324,10 +329,9 @@ do_run:
     }
 }
 
-static void FNAME(compress_row)(Encoder *encoder,
-                                const PIXEL * const prev_row,
-                                const PIXEL * const cur_row,
-                                unsigned int width)
+static void FNAME_DECL(compress_row)(const PIXEL * const prev_row,
+                                     const PIXEL * const cur_row,
+                                     unsigned int width)
 
 {
     CommonState *state = &encoder->rgb_state;
@@ -337,10 +341,9 @@ static void FNAME(compress_row)(Encoder *encoder,
 
     while ((DEFwmimax > (int)state->wmidx) && (state->wmileft <= width)) {
         if (state->wmileft) {
-            FNAME(compress_row_seg)(encoder, pos, prev_row, cur_row,
-                                    pos + state->wmileft,
-                                    bppmask[state->wmidx],
-                                    bpc, bpc_mask);
+            FNAME_CALL(compress_row_seg)(pos, prev_row, cur_row,
+                                         pos + state->wmileft, bppmask[state->wmidx],
+                                         bpc, bpc_mask);
             width -= state->wmileft;
             pos += state->wmileft;
         }
@@ -351,8 +354,8 @@ static void FNAME(compress_row)(Encoder *encoder,
     }
 
     if (width) {
-        FNAME(compress_row_seg)(encoder, pos, prev_row, cur_row, pos + width,
-                                bppmask[state->wmidx], bpc, bpc_mask);
+        FNAME_CALL(compress_row_seg)(pos, prev_row, cur_row, pos + width,
+                                     bppmask[state->wmidx], bpc, bpc_mask);
         if (DEFwmimax > (int)state->wmidx) {
             state->wmileft -= width;
         }
@@ -381,12 +384,12 @@ static void FNAME(compress_row)(Encoder *encoder,
                   bpc_mask));                                                                     \
     decode_eatbits(encoder, codewordlen);
 
-static void FNAME(uncompress_row0_seg)(Encoder *encoder, int i,
-                                       PIXEL * const cur_row,
-                                       const int end,
-                                       const unsigned int waitmask,
-                                       SPICE_GNUC_UNUSED const unsigned int bpc,
-                                       const unsigned int bpc_mask)
+static void FNAME_DECL(uncompress_row0_seg)(int i,
+                                            PIXEL * const cur_row,
+                                            const int end,
+                                            const unsigned int waitmask,
+                                            SPICE_GNUC_UNUSED const unsigned int bpc,
+                                            const unsigned int bpc_mask)
 {
     CommonState *state = &encoder->rgb_state;
     Channel * const channel_r = encoder->channels;
@@ -437,9 +440,8 @@ static void FNAME(uncompress_row0_seg)(Encoder *encoder, int i,
     state->waitcnt = stopidx - end;
 }
 
-static void FNAME(uncompress_row0)(Encoder *encoder,
-                                   PIXEL * const cur_row,
-                                   unsigned int width)
+static void FNAME_DECL(uncompress_row0)(PIXEL * const cur_row,
+                                        unsigned int width)
 
 {
     CommonState *state = &encoder->rgb_state;
@@ -449,10 +451,10 @@ static void FNAME(uncompress_row0)(Encoder *encoder,
 
     while ((DEFwmimax > (int)state->wmidx) && (state->wmileft <= width)) {
         if (state->wmileft) {
-            FNAME(uncompress_row0_seg)(encoder, pos, cur_row,
-                                       pos + state->wmileft,
-                                       bppmask[state->wmidx],
-                                       bpc, bpc_mask);
+            FNAME_CALL(uncompress_row0_seg)(pos, cur_row,
+                                            pos + state->wmileft,
+                                            bppmask[state->wmidx],
+                                            bpc, bpc_mask);
             pos += state->wmileft;
             width -= state->wmileft;
         }
@@ -463,8 +465,8 @@ static void FNAME(uncompress_row0)(Encoder *encoder,
     }
 
     if (width) {
-        FNAME(uncompress_row0_seg)(encoder, pos, cur_row, pos + width,
-                                   bppmask[state->wmidx], bpc, bpc_mask);
+        FNAME_CALL(uncompress_row0_seg)(pos, cur_row, pos + width,
+                                        bppmask[state->wmidx], bpc, bpc_mask);
         if (DEFwmimax > (int)state->wmidx) {
             state->wmileft -= width;
         }
@@ -492,13 +494,12 @@ static void FNAME(uncompress_row0)(Encoder *encoder,
              &cur_row[i]);                                                                        \
     decode_eatbits(encoder, codewordlen);
 
-static void FNAME(uncompress_row_seg)(Encoder *encoder,
-                                      const PIXEL * const prev_row,
-                                      PIXEL * const cur_row,
-                                      int i,
-                                      const int end,
-                                      SPICE_GNUC_UNUSED const unsigned int bpc,
-                                      const unsigned int bpc_mask)
+static void FNAME_DECL(uncompress_row_seg)(const PIXEL * const prev_row,
+                                           PIXEL * const cur_row,
+                                           int i,
+                                           const int end,
+                                           SPICE_GNUC_UNUSED const unsigned int bpc,
+                                           const unsigned int bpc_mask)
 {
     CommonState *state = &encoder->rgb_state;
     Channel * const channel_r = encoder->channels;
@@ -576,10 +577,9 @@ do_run:
     }
 }
 
-static void FNAME(uncompress_row)(Encoder *encoder,
-                                  const PIXEL * const prev_row,
-                                  PIXEL * const cur_row,
-                                  unsigned int width)
+static void FNAME_DECL(uncompress_row)(const PIXEL * const prev_row,
+                                       PIXEL * const cur_row,
+                                       unsigned int width)
 
 {
     CommonState *state = &encoder->rgb_state;
@@ -589,8 +589,8 @@ static void FNAME(uncompress_row)(Encoder *encoder,
 
     while ((DEFwmimax > (int)state->wmidx) && (state->wmileft <= width)) {
         if (state->wmileft) {
-            FNAME(uncompress_row_seg)(encoder, prev_row, cur_row, pos,
-                                      pos + state->wmileft, bpc, bpc_mask);
+            FNAME_CALL(uncompress_row_seg)(prev_row, cur_row, pos,
+                                           pos + state->wmileft, bpc, bpc_mask);
             pos += state->wmileft;
             width -= state->wmileft;
         }
@@ -601,8 +601,8 @@ static void FNAME(uncompress_row)(Encoder *encoder,
     }
 
     if (width) {
-        FNAME(uncompress_row_seg)(encoder, prev_row, cur_row, pos,
-                                  pos + width, bpc, bpc_mask);
+        FNAME_CALL(uncompress_row_seg)(prev_row, cur_row, pos,
+                                       pos + width, bpc, bpc_mask);
         if (DEFwmimax > (int)state->wmidx) {
             state->wmileft -= width;
         }
@@ -614,7 +614,11 @@ static void FNAME(uncompress_row)(Encoder *encoder,
 }
 
 #undef PIXEL
+#undef FARGS_CALL
+#undef FARGS_DECL
 #undef FNAME
+#undef FNAME_CALL
+#undef FNAME_DECL
 #undef _PIXEL_A
 #undef _PIXEL_B
 #undef SAME_PIXEL
diff --git a/common/quic_tmpl.c b/common/quic_tmpl.c
index 7a009f9..a7be9af 100644
--- a/common/quic_tmpl.c
+++ b/common/quic_tmpl.c
@@ -31,6 +31,11 @@
 #define PIXEL four_bytes_t
 #endif
 
+#define FARGS_DECL(...) (Encoder *encoder, Channel *channel_a, ##__VA_ARGS__)
+#define FARGS_CALL(...) (encoder, channel_a, ##__VA_ARGS__)
+#define FNAME_DECL(name) FNAME(name) FARGS_DECL
+#define FNAME_CALL(name) FNAME(name) FARGS_CALL
+
 #define golomb_coding golomb_coding_8bpc
 #define golomb_decoding golomb_decoding_8bpc
 #define update_model update_model_8bpc
@@ -95,12 +100,12 @@ if (SAME_PIXEL(&prev_row[i - 1], &prev_row[i])) {
 #define APPLY_ALL_COMP(macro, ...) \
     macro(a, ## __VA_ARGS__)
 
-static void FNAME(compress_row0_seg)(Encoder *encoder, Channel *channel_a, int i,
-                                     const PIXEL * const cur_row,
-                                     const int end,
-                                     const unsigned int waitmask,
-                                     SPICE_GNUC_UNUSED const unsigned int bpc,
-                                     const unsigned int bpc_mask)
+static void FNAME_DECL(compress_row0_seg)(int i,
+                                          const PIXEL * const cur_row,
+                                          const int end,
+                                          const unsigned int waitmask,
+                                          SPICE_GNUC_UNUSED const unsigned int bpc,
+                                          const unsigned int bpc_mask)
 {
     CommonState *state = &channel_a->state;
     BYTE * const correlate_row_a = channel_a->correlate_row;
@@ -140,18 +145,17 @@ static void FNAME(compress_row0_seg)(Encoder *encoder, Channel *channel_a, int i
 #undef COMPRESS_ONE_ROW0_0
 #undef COMPRESS_ONE_ROW0
 
-static void FNAME(compress_row0)(Encoder *encoder, Channel *channel, const PIXEL *cur_row,
-                                 unsigned int width)
+static void FNAME_DECL(compress_row0)(const PIXEL *cur_row, unsigned int width)
 {
-    CommonState *state = &channel->state;
+    CommonState *state = &channel_a->state;
     const unsigned int bpc = BPC;
     const unsigned int bpc_mask = BPC_MASK;
     int pos = 0;
 
     while ((DEFwmimax > (int)state->wmidx) && (state->wmileft <= width)) {
         if (state->wmileft) {
-            FNAME(compress_row0_seg)(encoder, channel, pos, cur_row, pos + state->wmileft,
-                                     bppmask[state->wmidx], bpc, bpc_mask);
+            FNAME_CALL(compress_row0_seg)(pos, cur_row, pos + state->wmileft,
+                                          bppmask[state->wmidx], bpc, bpc_mask);
             width -= state->wmileft;
             pos += state->wmileft;
         }
@@ -162,8 +166,8 @@ static void FNAME(compress_row0)(Encoder *encoder, Channel *channel, const PIXEL
     }
 
     if (width) {
-        FNAME(compress_row0_seg)(encoder, channel, pos, cur_row, pos + width,
-                                 bppmask[state->wmidx], bpc, bpc_mask);
+        FNAME_CALL(compress_row0_seg)(pos, cur_row, pos + width,
+                                      bppmask[state->wmidx], bpc, bpc_mask);
         if (DEFwmimax > (int)state->wmidx) {
             state->wmileft -= width;
         }
@@ -185,13 +189,13 @@ static void FNAME(compress_row0)(Encoder *encoder, Channel *channel, const PIXEL
      golomb_coding(encoder, correlate_row_##channel[index],                                            \
                    find_bucket(channel_##channel, correlate_row_##channel[index - 1])->bestcode)
 
-static void FNAME(compress_row_seg)(Encoder *encoder, Channel *channel_a, int i,
-                                    const PIXEL * const prev_row,
-                                    const PIXEL * const cur_row,
-                                    const int end,
-                                    const unsigned int waitmask,
-                                    SPICE_GNUC_UNUSED const unsigned int bpc,
-                                    const unsigned int bpc_mask)
+static void FNAME_DECL(compress_row_seg)(int i,
+                                         const PIXEL * const prev_row,
+                                         const PIXEL * const cur_row,
+                                         const int end,
+                                         const unsigned int waitmask,
+                                         SPICE_GNUC_UNUSED const unsigned int bpc,
+                                         const unsigned int bpc_mask)
 {
     CommonState *state = &channel_a->state;
     BYTE * const correlate_row_a = channel_a->correlate_row;
@@ -250,22 +254,21 @@ do_run:
     }
 }
 
-static void FNAME(compress_row)(Encoder *encoder, Channel *channel,
-                                const PIXEL * const prev_row,
-                                const PIXEL * const cur_row,
-                                unsigned int width)
+static void FNAME_DECL(compress_row)(const PIXEL * const prev_row,
+                                     const PIXEL * const cur_row,
+                                     unsigned int width)
 
 {
-    CommonState *state = &channel->state;
+    CommonState *state = &channel_a->state;
     const unsigned int bpc = BPC;
     const unsigned int bpc_mask = BPC_MASK;
     unsigned int pos = 0;
 
     while ((DEFwmimax > (int)state->wmidx) && (state->wmileft <= width)) {
         if (state->wmileft) {
-            FNAME(compress_row_seg)(encoder, channel, pos, prev_row, cur_row,
-                                    pos + state->wmileft, bppmask[state->wmidx],
-                                    bpc, bpc_mask);
+            FNAME_CALL(compress_row_seg)(pos, prev_row, cur_row,
+                                         pos + state->wmileft, bppmask[state->wmidx],
+                                         bpc, bpc_mask);
             width -= state->wmileft;
             pos += state->wmileft;
         }
@@ -276,8 +279,8 @@ static void FNAME(compress_row)(Encoder *encoder, Channel *channel,
     }
 
     if (width) {
-        FNAME(compress_row_seg)(encoder, channel, pos, prev_row, cur_row, pos + width,
-                                bppmask[state->wmidx], bpc, bpc_mask);
+        FNAME_CALL(compress_row_seg)(pos, prev_row, cur_row, pos + width,
+                                     bppmask[state->wmidx], bpc, bpc_mask);
         if (DEFwmimax > (int)state->wmidx) {
             state->wmileft -= width;
         }
@@ -305,12 +308,12 @@ static void FNAME(compress_row)(Encoder *encoder, Channel *channel,
                   bpc_mask));                                                                                  \
     decode_eatbits(encoder, codewordlen);
 
-static void FNAME(uncompress_row0_seg)(Encoder *encoder, Channel *channel_a, int i,
-                                       PIXEL * const cur_row,
-                                       const int end,
-                                       const unsigned int waitmask,
-                                       SPICE_GNUC_UNUSED const unsigned int bpc,
-                                       const unsigned int bpc_mask)
+static void FNAME_DECL(uncompress_row0_seg)(int i,
+                                            PIXEL * const cur_row,
+                                            const int end,
+                                            const unsigned int waitmask,
+                                            SPICE_GNUC_UNUSED const unsigned int bpc,
+                                            const unsigned int bpc_mask)
 {
     CommonState *state = &channel_a->state;
     BYTE * const correlate_row_a = channel_a->correlate_row;
@@ -355,21 +358,20 @@ static void FNAME(uncompress_row0_seg)(Encoder *encoder, Channel *channel_a, int
     state->waitcnt = stopidx - end;
 }
 
-static void FNAME(uncompress_row0)(Encoder *encoder, Channel *channel,
-                                   PIXEL * const cur_row,
-                                   unsigned int width)
+static void FNAME_DECL(uncompress_row0)(PIXEL * const cur_row, unsigned int width)
 
 {
-    CommonState *state = &channel->state;
+    CommonState *state = &channel_a->state;
     const unsigned int bpc = BPC;
     const unsigned int bpc_mask = BPC_MASK;
     unsigned int pos = 0;
 
     while ((DEFwmimax > (int)state->wmidx) && (state->wmileft <= width)) {
         if (state->wmileft) {
-            FNAME(uncompress_row0_seg)(encoder, channel, pos, cur_row,
-                                       pos + state->wmileft, bppmask[state->wmidx],
-                                       bpc, bpc_mask);
+            FNAME_CALL(uncompress_row0_seg)(pos, cur_row,
+                                            pos + state->wmileft,
+                                            bppmask[state->wmidx],
+                                            bpc, bpc_mask);
             pos += state->wmileft;
             width -= state->wmileft;
         }
@@ -380,8 +382,8 @@ static void FNAME(uncompress_row0)(Encoder *encoder, Channel *channel,
     }
 
     if (width) {
-        FNAME(uncompress_row0_seg)(encoder, channel, pos, cur_row, pos + width,
-                                   bppmask[state->wmidx], bpc, bpc_mask);
+        FNAME_CALL(uncompress_row0_seg)(pos, cur_row, pos + width,
+                                        bppmask[state->wmidx], bpc, bpc_mask);
         if (DEFwmimax > (int)state->wmidx) {
             state->wmileft -= width;
         }
@@ -408,13 +410,12 @@ static void FNAME(uncompress_row0)(Encoder *encoder, Channel *channel,
               &cur_row[i]);                                                                                   \
     decode_eatbits(encoder, codewordlen);
 
-static void FNAME(uncompress_row_seg)(Encoder *encoder, Channel *channel_a,
-                                      const PIXEL * const prev_row,
-                                      PIXEL * const cur_row,
-                                      int i,
-                                      const int end,
-                                      SPICE_GNUC_UNUSED const unsigned int bpc,
-                                      const unsigned int bpc_mask)
+static void FNAME_DECL(uncompress_row_seg)(const PIXEL * const prev_row,
+                                           PIXEL * const cur_row,
+                                           int i,
+                                           const int end,
+                                           SPICE_GNUC_UNUSED const unsigned int bpc,
+                                           const unsigned int bpc_mask)
 {
     CommonState *state = &channel_a->state;
     BYTE * const correlate_row_a = channel_a->correlate_row;
@@ -484,21 +485,20 @@ do_run:
     }
 }
 
-static void FNAME(uncompress_row)(Encoder *encoder, Channel *channel,
-                                  const PIXEL * const prev_row,
-                                  PIXEL * const cur_row,
-                                  unsigned int width)
+static void FNAME_DECL(uncompress_row)(const PIXEL * const prev_row,
+                                       PIXEL * const cur_row,
+                                       unsigned int width)
 
 {
-    CommonState *state = &channel->state;
+    CommonState *state = &channel_a->state;
     const unsigned int bpc = BPC;
     const unsigned int bpc_mask = BPC_MASK;
     unsigned int pos = 0;
 
     while ((DEFwmimax > (int)state->wmidx) && (state->wmileft <= width)) {
         if (state->wmileft) {
-            FNAME(uncompress_row_seg)(encoder, channel, prev_row, cur_row, pos,
-                                      pos + state->wmileft, bpc, bpc_mask);
+            FNAME_CALL(uncompress_row_seg)(prev_row, cur_row, pos,
+                                           pos + state->wmileft, bpc, bpc_mask);
             pos += state->wmileft;
             width -= state->wmileft;
         }
@@ -509,8 +509,8 @@ static void FNAME(uncompress_row)(Encoder *encoder, Channel *channel,
     }
 
     if (width) {
-        FNAME(uncompress_row_seg)(encoder, channel, prev_row, cur_row, pos,
-                                  pos + width, bpc, bpc_mask);
+        FNAME_CALL(uncompress_row_seg)(prev_row, cur_row, pos,
+                                       pos + width, bpc, bpc_mask);
         if (DEFwmimax > (int)state->wmidx) {
             state->wmileft -= width;
         }
@@ -522,7 +522,11 @@ static void FNAME(uncompress_row)(Encoder *encoder, Channel *channel,
 }
 
 #undef PIXEL
+#undef FARGS_CALL
+#undef FARGS_DECL
 #undef FNAME
+#undef FNAME_CALL
+#undef FNAME_DECL
 #undef _PIXEL_A
 #undef _PIXEL_B
 #undef SAME_PIXEL
commit a2d32a1fdd95e3a303ff61a41547a4831f3fc024
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Tue Jul 10 11:02:15 2018 +0200

    quic: Add APPLY_ALL_COMP macro to iterate over channels
    
    Use a APPLY_ALL_COMP macro to unify single/multiple channel processing.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/common/quic_rgb_tmpl.c b/common/quic_rgb_tmpl.c
index 0243252..5dbc873 100644
--- a/common/quic_rgb_tmpl.c
+++ b/common/quic_rgb_tmpl.c
@@ -143,11 +143,12 @@
 #define UPDATE_MODEL_COMP(channel, index)                                                             \
     update_model(state, find_bucket(channel_##channel, correlate_row_##channel[index - 1]),        \
                  correlate_row_##channel[index])
-#define UPDATE_MODEL(index)                                                            \
-    UPDATE_MODEL_COMP(r, index); \
-    UPDATE_MODEL_COMP(g, index); \
-    UPDATE_MODEL_COMP(b, index)
+#define UPDATE_MODEL(index) APPLY_ALL_COMP(UPDATE_MODEL_COMP, index)
 
+#define APPLY_ALL_COMP(macro, ...) \
+    macro(r, ## __VA_ARGS__); \
+    macro(g, ## __VA_ARGS__); \
+    macro(b, ## __VA_ARGS__)
 
 #define RLE_PRED_IMP                                                                \
 if (SAME_PIXEL(&prev_row[i - 1], &prev_row[i])) {                                   \
@@ -178,9 +179,7 @@ static void FNAME(compress_row0_seg)(Encoder *encoder, int i,
     spice_assert(end - i > 0);
 
     if (i == 0) {
-        COMPRESS_ONE_ROW0_0(r);
-        COMPRESS_ONE_ROW0_0(g);
-        COMPRESS_ONE_ROW0_0(b);
+        APPLY_ALL_COMP(COMPRESS_ONE_ROW0_0);
 
         if (state->waitcnt) {
             state->waitcnt--;
@@ -195,9 +194,7 @@ static void FNAME(compress_row0_seg)(Encoder *encoder, int i,
 
     while (stopidx < end) {
         for (; i <= stopidx; i++) {
-            COMPRESS_ONE_ROW0(r, i);
-            COMPRESS_ONE_ROW0(g, i);
-            COMPRESS_ONE_ROW0(b, i);
+            APPLY_ALL_COMP(COMPRESS_ONE_ROW0, i);
         }
 
         UPDATE_MODEL(stopidx);
@@ -205,9 +202,7 @@ static void FNAME(compress_row0_seg)(Encoder *encoder, int i,
     }
 
     for (; i < end; i++) {
-        COMPRESS_ONE_ROW0(r, i);
-        COMPRESS_ONE_ROW0(g, i);
-        COMPRESS_ONE_ROW0(b, i);
+        APPLY_ALL_COMP(COMPRESS_ONE_ROW0, i);
     }
     state->waitcnt = stopidx - end;
 }
@@ -281,9 +276,7 @@ static void FNAME(compress_row_seg)(Encoder *encoder, int i,
     spice_assert(end - i > 0);
 
     if (i == 0) {
-        COMPRESS_ONE_0(r);
-        COMPRESS_ONE_0(g);
-        COMPRESS_ONE_0(b);
+        APPLY_ALL_COMP(COMPRESS_ONE_0);
 
         if (state->waitcnt) {
             state->waitcnt--;
@@ -299,9 +292,7 @@ static void FNAME(compress_row_seg)(Encoder *encoder, int i,
         while (stopidx < end) {
             for (; i <= stopidx; i++) {
                 RLE_PRED_IMP;
-                COMPRESS_ONE(r, i);
-                COMPRESS_ONE(g, i);
-                COMPRESS_ONE(b, i);
+                APPLY_ALL_COMP(COMPRESS_ONE, i);
             }
 
             UPDATE_MODEL(stopidx);
@@ -310,9 +301,7 @@ static void FNAME(compress_row_seg)(Encoder *encoder, int i,
 
         for (; i < end; i++) {
             RLE_PRED_IMP;
-            COMPRESS_ONE(r, i);
-            COMPRESS_ONE(g, i);
-            COMPRESS_ONE(b, i);
+            APPLY_ALL_COMP(COMPRESS_ONE, i);
         }
         state->waitcnt = stopidx - end;
 
@@ -415,9 +404,7 @@ static void FNAME(uncompress_row0_seg)(Encoder *encoder, int i,
         unsigned int codewordlen;
 
         UNCOMPRESS_PIX_START(&cur_row[i]);
-        UNCOMPRESS_ONE_ROW0_0(r);
-        UNCOMPRESS_ONE_ROW0_0(g);
-        UNCOMPRESS_ONE_ROW0_0(b);
+        APPLY_ALL_COMP(UNCOMPRESS_ONE_ROW0_0);
 
         if (state->waitcnt) {
             --state->waitcnt;
@@ -435,9 +422,7 @@ static void FNAME(uncompress_row0_seg)(Encoder *encoder, int i,
             unsigned int codewordlen;
 
             UNCOMPRESS_PIX_START(&cur_row[i]);
-            UNCOMPRESS_ONE_ROW0(r);
-            UNCOMPRESS_ONE_ROW0(g);
-            UNCOMPRESS_ONE_ROW0(b);
+            APPLY_ALL_COMP(UNCOMPRESS_ONE_ROW0);
         }
         UPDATE_MODEL(stopidx);
         stopidx = i + (tabrand(&state->tabrand_seed) & waitmask);
@@ -447,9 +432,7 @@ static void FNAME(uncompress_row0_seg)(Encoder *encoder, int i,
         unsigned int codewordlen;
 
         UNCOMPRESS_PIX_START(&cur_row[i]);
-        UNCOMPRESS_ONE_ROW0(r);
-        UNCOMPRESS_ONE_ROW0(g);
-        UNCOMPRESS_ONE_ROW0(b);
+        APPLY_ALL_COMP(UNCOMPRESS_ONE_ROW0);
     }
     state->waitcnt = stopidx - end;
 }
@@ -536,9 +519,7 @@ static void FNAME(uncompress_row_seg)(Encoder *encoder,
         unsigned int codewordlen;
 
         UNCOMPRESS_PIX_START(&cur_row[i]);
-        UNCOMPRESS_ONE_0(r);
-        UNCOMPRESS_ONE_0(g);
-        UNCOMPRESS_ONE_0(b);
+        APPLY_ALL_COMP(UNCOMPRESS_ONE_0);
 
         if (state->waitcnt) {
             --state->waitcnt;
@@ -556,9 +537,7 @@ static void FNAME(uncompress_row_seg)(Encoder *encoder,
                 unsigned int codewordlen;
                 RLE_PRED_IMP;
                 UNCOMPRESS_PIX_START(&cur_row[i]);
-                UNCOMPRESS_ONE(r);
-                UNCOMPRESS_ONE(g);
-                UNCOMPRESS_ONE(b);
+                APPLY_ALL_COMP(UNCOMPRESS_ONE);
             }
 
             UPDATE_MODEL(stopidx);
@@ -570,9 +549,7 @@ static void FNAME(uncompress_row_seg)(Encoder *encoder,
             unsigned int codewordlen;
             RLE_PRED_IMP;
             UNCOMPRESS_PIX_START(&cur_row[i]);
-            UNCOMPRESS_ONE(r);
-            UNCOMPRESS_ONE(g);
-            UNCOMPRESS_ONE(b);
+            APPLY_ALL_COMP(UNCOMPRESS_ONE);
         }
 
         state->waitcnt = stopidx - end;
@@ -671,3 +648,4 @@ static void FNAME(uncompress_row)(Encoder *encoder,
 #undef GET_b
 #undef UNCOMPRESS_PIX_START
 #undef UPDATE_MODEL_COMP
+#undef APPLY_ALL_COMP
diff --git a/common/quic_tmpl.c b/common/quic_tmpl.c
index b55abd1..7a009f9 100644
--- a/common/quic_tmpl.c
+++ b/common/quic_tmpl.c
@@ -90,7 +90,10 @@ if (SAME_PIXEL(&prev_row[i - 1], &prev_row[i])) {
 #define UPDATE_MODEL_COMP(channel, index)                                                   \
     update_model(state, find_bucket(channel_##channel, correlate_row_##channel[index - 1]), \
                  correlate_row_##channel[index])
-#define UPDATE_MODEL(index) UPDATE_MODEL_COMP(a, index)
+#define UPDATE_MODEL(index) APPLY_ALL_COMP(UPDATE_MODEL_COMP, index)
+
+#define APPLY_ALL_COMP(macro, ...) \
+    macro(a, ## __VA_ARGS__)
 
 static void FNAME(compress_row0_seg)(Encoder *encoder, Channel *channel_a, int i,
                                      const PIXEL * const cur_row,
@@ -106,7 +109,7 @@ static void FNAME(compress_row0_seg)(Encoder *encoder, Channel *channel_a, int i
     spice_assert(end - i > 0);
 
     if (i == 0) {
-        COMPRESS_ONE_ROW0_0(a);
+        APPLY_ALL_COMP(COMPRESS_ONE_ROW0_0);
 
         if (state->waitcnt) {
             state->waitcnt--;
@@ -121,7 +124,7 @@ static void FNAME(compress_row0_seg)(Encoder *encoder, Channel *channel_a, int i
 
     while (stopidx < end) {
         for (; i <= stopidx; i++) {
-            COMPRESS_ONE_ROW0(a, i);
+            APPLY_ALL_COMP(COMPRESS_ONE_ROW0, i);
         }
 
         UPDATE_MODEL(stopidx);
@@ -129,7 +132,7 @@ static void FNAME(compress_row0_seg)(Encoder *encoder, Channel *channel_a, int i
     }
 
     for (; i < end; i++) {
-        COMPRESS_ONE_ROW0(a, i);
+        APPLY_ALL_COMP(COMPRESS_ONE_ROW0, i);
     }
     state->waitcnt = stopidx - end;
 }
@@ -199,7 +202,7 @@ static void FNAME(compress_row_seg)(Encoder *encoder, Channel *channel_a, int i,
     spice_assert(end - i > 0);
 
     if (i == 0) {
-        COMPRESS_ONE_0(a);
+        APPLY_ALL_COMP(COMPRESS_ONE_0);
 
         if (state->waitcnt) {
             state->waitcnt--;
@@ -215,7 +218,7 @@ static void FNAME(compress_row_seg)(Encoder *encoder, Channel *channel_a, int i,
         while (stopidx < end) {
             for (; i <= stopidx; i++) {
                 RLE_PRED_IMP;
-                COMPRESS_ONE(a, i);
+                APPLY_ALL_COMP(COMPRESS_ONE, i);
             }
 
             UPDATE_MODEL(stopidx);
@@ -224,7 +227,7 @@ static void FNAME(compress_row_seg)(Encoder *encoder, Channel *channel_a, int i,
 
         for (; i < end; i++) {
             RLE_PRED_IMP;
-            COMPRESS_ONE(a, i);
+            APPLY_ALL_COMP(COMPRESS_ONE, i);
         }
         state->waitcnt = stopidx - end;
 
@@ -319,7 +322,7 @@ static void FNAME(uncompress_row0_seg)(Encoder *encoder, Channel *channel_a, int
         unsigned int codewordlen;
 
         UNCOMPRESS_PIX_START(&cur_row[i]);
-        UNCOMPRESS_ONE_ROW0_0(a);
+        APPLY_ALL_COMP(UNCOMPRESS_ONE_ROW0_0);
 
         if (state->waitcnt) {
             --state->waitcnt;
@@ -337,7 +340,7 @@ static void FNAME(uncompress_row0_seg)(Encoder *encoder, Channel *channel_a, int
             unsigned int codewordlen;
 
             UNCOMPRESS_PIX_START(&cur_row[i]);
-            UNCOMPRESS_ONE_ROW0(a);
+            APPLY_ALL_COMP(UNCOMPRESS_ONE_ROW0);
         }
         UPDATE_MODEL(stopidx);
         stopidx = i + (tabrand(&state->tabrand_seed) & waitmask);
@@ -347,7 +350,7 @@ static void FNAME(uncompress_row0_seg)(Encoder *encoder, Channel *channel_a, int
         unsigned int codewordlen;
 
         UNCOMPRESS_PIX_START(&cur_row[i]);
-        UNCOMPRESS_ONE_ROW0(a);
+        APPLY_ALL_COMP(UNCOMPRESS_ONE_ROW0);
     }
     state->waitcnt = stopidx - end;
 }
@@ -426,7 +429,7 @@ static void FNAME(uncompress_row_seg)(Encoder *encoder, Channel *channel_a,
         unsigned int codewordlen;
 
         UNCOMPRESS_PIX_START(&cur_row[i]);
-        UNCOMPRESS_ONE_0(a);
+        APPLY_ALL_COMP(UNCOMPRESS_ONE_0);
 
         if (state->waitcnt) {
             --state->waitcnt;
@@ -444,7 +447,7 @@ static void FNAME(uncompress_row_seg)(Encoder *encoder, Channel *channel_a,
                 unsigned int codewordlen;
                 RLE_PRED_IMP;
                 UNCOMPRESS_PIX_START(&cur_row[i]);
-                UNCOMPRESS_ONE(a);
+                APPLY_ALL_COMP(UNCOMPRESS_ONE);
             }
 
             UPDATE_MODEL(stopidx);
@@ -456,7 +459,7 @@ static void FNAME(uncompress_row_seg)(Encoder *encoder, Channel *channel_a,
             unsigned int codewordlen;
             RLE_PRED_IMP;
             UNCOMPRESS_PIX_START(&cur_row[i]);
-            UNCOMPRESS_ONE(a);
+            APPLY_ALL_COMP(UNCOMPRESS_ONE);
         }
 
         state->waitcnt = stopidx - end;
@@ -546,3 +549,4 @@ static void FNAME(uncompress_row)(Encoder *encoder, Channel *channel,
 #undef UNCOMPRESS_ONE
 #undef SET_a
 #undef GET_a
+#undef APPLY_ALL_COMP
commit e3609f06a3056c0b48f21a0c1f22272562972042
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Tue Jul 10 11:02:14 2018 +0200

    quic: Add CORRELATE*/DECORRELATE* macros
    
    This will help to unify quic_tmpl.c and quic_rgb_tmpl.c
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/common/quic_tmpl.c b/common/quic_tmpl.c
index 8d585fd..b55abd1 100644
--- a/common/quic_tmpl.c
+++ b/common/quic_tmpl.c
@@ -57,31 +57,23 @@ if (SAME_PIXEL(&prev_row[i - 1], &prev_row[i])) {
 }
 
 /*  a  */
-static inline BYTE FNAME(decorrelate_0)(const PIXEL * const curr, const unsigned int bpc_mask)
-{
-    return family.xlatU2L[(unsigned)((int)GET_a(curr) - (int)_PIXEL_A(a, curr)) & bpc_mask];
-}
 
-static inline void FNAME(correlate_0)(PIXEL *curr, const BYTE correlate,
-                                      const unsigned int bpc_mask)
-{
-    curr->a = (family.xlatL2U[correlate] + _PIXEL_A(a, curr)) & bpc_mask;
-}
+#define DECORRELATE_0(channel, curr, bpc_mask)\
+    family.xlatU2L[(unsigned)((int)GET_##channel(curr) - (int)_PIXEL_A(channel, curr)) & bpc_mask]
+
+#define CORRELATE_0(channel, curr, correlate, bpc_mask)\
+    ((family.xlatL2U[correlate] + _PIXEL_A(channel, curr)) & bpc_mask)
 
 
 /*  (a+b)/2  */
-static inline BYTE FNAME(decorrelate)(const PIXEL *const prev, const PIXEL * const curr,
-                                      const unsigned int bpc_mask)
-{
-    return family.xlatU2L[(unsigned)((int)curr->a - (int)((_PIXEL_A(a, curr) + _PIXEL_B(a, prev)) >> 1)) & bpc_mask];
-}
+#define DECORRELATE(channel, prev, curr, bpc_mask, r)                                          \
+    r = family.xlatU2L[(unsigned)((int)GET_##channel(curr) - (int)((_PIXEL_A(channel, curr) +  \
+    _PIXEL_B(channel, prev)) >> 1)) & bpc_mask]
 
+#define CORRELATE(channel, prev, curr, correlate, bpc_mask, r)                                  \
+    SET_##channel(r, ((family.xlatL2U[correlate] +                                              \
+         (int)((_PIXEL_A(channel, curr) + _PIXEL_B(channel, prev)) >> 1)) & bpc_mask))
 
-static inline void FNAME(correlate)(const PIXEL *prev, PIXEL *curr, const BYTE correlate,
-                                    const unsigned int bpc_mask)
-{
-    curr->a = (family.xlatL2U[correlate] + (int)((_PIXEL_A(a, curr) + _PIXEL_B(a, prev)) >> 1)) & bpc_mask;
-}
 
 #define COMPRESS_ONE_ROW0_0(channel)                                    \
     correlate_row_##channel[0] = family.xlatU2L[GET_##channel(cur_row)];\
@@ -90,7 +82,7 @@ static inline void FNAME(correlate)(const PIXEL *prev, PIXEL *curr, const BYTE c
                               correlate_row_##channel[-1])->bestcode)
 
 #define COMPRESS_ONE_ROW0(channel, index)                                               \
-    correlate_row_##channel[index] = FNAME(decorrelate_0)(&cur_row[index], bpc_mask);   \
+    correlate_row_##channel[index] = DECORRELATE_0(channel, &cur_row[index], bpc_mask); \
     golomb_coding(encoder, correlate_row_##channel[index],                              \
                   find_bucket(channel_##channel,                                        \
                               correlate_row_##channel[index - 1])->bestcode)
@@ -186,7 +178,7 @@ static void FNAME(compress_row0)(Encoder *encoder, Channel *channel, const PIXEL
                   find_bucket(channel_##channel, correlate_row_##channel[-1])->bestcode)
 
 #define COMPRESS_ONE(channel, index)                                                                   \
-     correlate_row_##channel[index] = FNAME(decorrelate)(&prev_row[index], &cur_row[index], bpc_mask); \
+     DECORRELATE(channel, &prev_row[index], &cur_row[index],bpc_mask, correlate_row_##channel[index]); \
      golomb_coding(encoder, correlate_row_##channel[index],                                            \
                    find_bucket(channel_##channel, correlate_row_##channel[index - 1])->bestcode)
 
@@ -306,7 +298,8 @@ static void FNAME(compress_row)(Encoder *encoder, Channel *channel,
     correlate_row_##channel[i] = (BYTE)golomb_decoding(find_bucket(channel_##channel,                          \
                                                                    correlate_row_##channel[i - 1])->bestcode,  \
                                                        encoder->io_word, &codewordlen);                        \
-    FNAME(correlate_0)(&cur_row[i], correlate_row_##channel[i], bpc_mask);                                     \
+    SET_##channel(&cur_row[i], CORRELATE_0(channel, &cur_row[i], correlate_row_##channel[i],                   \
+                  bpc_mask));                                                                                  \
     decode_eatbits(encoder, codewordlen);
 
 static void FNAME(uncompress_row0_seg)(Encoder *encoder, Channel *channel_a, int i,
@@ -408,7 +401,8 @@ static void FNAME(uncompress_row0)(Encoder *encoder, Channel *channel,
     correlate_row_##channel[i] = (BYTE)golomb_decoding(find_bucket(channel_##channel,                         \
                                                                    correlate_row_##channel[i - 1])->bestcode, \
                                                        encoder->io_word, &codewordlen);                       \
-    FNAME(correlate)(&prev_row[i], &cur_row[i], correlate_row_##channel[i], bpc_mask);                        \
+    CORRELATE(channel, &prev_row[i], &cur_row[i], correlate_row_##channel[i], bpc_mask,                       \
+              &cur_row[i]);                                                                                   \
     decode_eatbits(encoder, codewordlen);
 
 static void FNAME(uncompress_row_seg)(Encoder *encoder, Channel *channel_a,
@@ -530,6 +524,10 @@ static void FNAME(uncompress_row)(Encoder *encoder, Channel *channel,
 #undef _PIXEL_B
 #undef SAME_PIXEL
 #undef RLE_PRED_IMP
+#undef DECORRELATE_0
+#undef DECORRELATE
+#undef CORRELATE_0
+#undef CORRELATE
 #undef golomb_coding
 #undef golomb_decoding
 #undef update_model
commit 394b5d31c0e83a99a1beb664696a408519905077
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Tue Jul 10 11:02:13 2018 +0200

    quic: Call directly encode_state_run from templates.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/common/quic.c b/common/quic.c
index 6ed316c..cf4f087 100644
--- a/common/quic.c
+++ b/common/quic.c
@@ -540,16 +540,6 @@ static void encode_state_run(Encoder *encoder, CommonState *state, unsigned int
     }
 }
 
-static void encode_run(Encoder *encoder, unsigned int runlen) //todo: try use end of line
-{
-    encode_state_run(encoder, &encoder->rgb_state, runlen);
-}
-
-static void encode_channel_run(Encoder *encoder, Channel *channel, unsigned int runlen)
-{
-    encode_state_run(encoder, &channel->state, runlen);
-}
-
 
 /* decoding routine: reads bits from the input and returns a run length. */
 /* argument is the number of pixels left to end-of-line (bound on run length) */
@@ -593,17 +583,6 @@ static int decode_state_run(Encoder *encoder, CommonState *state)
     return runlen;
 }
 
-static int decode_run(Encoder *encoder)
-{
-    return decode_state_run(encoder, &encoder->rgb_state);
-}
-
-
-static int decode_channel_run(Encoder *encoder, Channel *channel)
-{
-    return decode_state_run(encoder, &channel->state);
-}
-
 static inline void init_decode_io(Encoder *encoder)
 {
     encoder->io_next_word = encoder->io_word = GUINT32_FROM_LE(*(encoder->io_now++));
diff --git a/common/quic_rgb_tmpl.c b/common/quic_rgb_tmpl.c
index 2e76645..0243252 100644
--- a/common/quic_rgb_tmpl.c
+++ b/common/quic_rgb_tmpl.c
@@ -326,11 +326,11 @@ do_run:
         while (SAME_PIXEL(&cur_row[i], &cur_row[i - 1])) {
             run_size++;
             if (++i == end) {
-                encode_run(encoder, run_size);
+                encode_state_run(encoder, state, run_size);
                 return;
             }
         }
-        encode_run(encoder, run_size);
+        encode_state_run(encoder, state, run_size);
         stopidx = i + state->waitcnt;
     }
 }
@@ -582,7 +582,7 @@ static void FNAME(uncompress_row_seg)(Encoder *encoder,
 do_run:
         state->waitcnt = stopidx - i;
         run_index = i;
-        run_end = i + decode_run(encoder);
+        run_end = i + decode_state_run(encoder, state);
 
         for (; i < run_end; i++) {
             UNCOMPRESS_PIX_START(&cur_row[i]);
diff --git a/common/quic_tmpl.c b/common/quic_tmpl.c
index 68acf0f..8d585fd 100644
--- a/common/quic_tmpl.c
+++ b/common/quic_tmpl.c
@@ -246,11 +246,11 @@ do_run:
         while (SAME_PIXEL(&cur_row[i], &cur_row[i - 1])) {
             run_size++;
             if (++i == end) {
-                encode_channel_run(encoder, channel_a, run_size);
+                encode_state_run(encoder, state, run_size);
                 return;
             }
         }
-        encode_channel_run(encoder, channel_a, run_size);
+        encode_state_run(encoder, state, run_size);
         stopidx = i + state->waitcnt;
     }
 }
@@ -472,7 +472,7 @@ static void FNAME(uncompress_row_seg)(Encoder *encoder, Channel *channel_a,
 do_run:
         state->waitcnt = stopidx - i;
         run_index = i;
-        run_end = i + decode_channel_run(encoder, channel_a);
+        run_end = i + decode_state_run(encoder, state);
 
         for (; i < run_end; i++) {
             UNCOMPRESS_PIX_START(&cur_row[i]);
commit 7a535a6141fd7317ddc50611322e320a4abe7b69
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Tue Jul 10 11:02:12 2018 +0200

    quic: Add missing #undef SET_a/GET_a
    
    These macros were added to quic_tmpl.c in 815223861 but without the
    corresponding #undef. This commit adds them for consistency.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/common/quic_tmpl.c b/common/quic_tmpl.c
index 9a991cd..68acf0f 100644
--- a/common/quic_tmpl.c
+++ b/common/quic_tmpl.c
@@ -546,3 +546,5 @@ static void FNAME(uncompress_row)(Encoder *encoder, Channel *channel,
 #undef UNCOMPRESS_ONE_ROW0_0
 #undef UNCOMPRESS_ONE_0
 #undef UNCOMPRESS_ONE
+#undef SET_a
+#undef GET_a
commit 7a6980def8ea566c8dbe8e65fe1a8355d00a889c
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Tue Jul 10 11:02:11 2018 +0200

    quic: Make {UN, }COMPRESS_xx macros closer
    
    Define COMPRESS_xx/UNCOMPRESS_xx macros in a more similar way between
    quic_tmpl.c and quic_rgb_tmpl.c using channel suffixes. Instead of
    having #define COMPRESS(channel) do_something(channel), we'll now have
     #define COMPRESS(channel) do_something(channel_##channel), and call it
    with COMPRESS(a)
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/common/quic_tmpl.c b/common/quic_tmpl.c
index 3087466..9a991cd 100644
--- a/common/quic_tmpl.c
+++ b/common/quic_tmpl.c
@@ -83,36 +83,38 @@ static inline void FNAME(correlate)(const PIXEL *prev, PIXEL *curr, const BYTE c
     curr->a = (family.xlatL2U[correlate] + (int)((_PIXEL_A(a, curr) + _PIXEL_B(a, prev)) >> 1)) & bpc_mask;
 }
 
-#define COMPRESS_ONE_ROW0_0(channel)                                 \
-    channel->correlate_row[0] = family.xlatU2L[cur_row->a];          \
-    golomb_coding(encoder, channel->correlate_row[0],                \
-                  find_bucket(channel,                               \
-                              channel->correlate_row[-1])->bestcode)
+#define COMPRESS_ONE_ROW0_0(channel)                                    \
+    correlate_row_##channel[0] = family.xlatU2L[GET_##channel(cur_row)];\
+    golomb_coding(encoder, correlate_row_##channel[0],                  \
+                  find_bucket(channel_##channel,                        \
+                              correlate_row_##channel[-1])->bestcode)
 
 #define COMPRESS_ONE_ROW0(channel, index)                                               \
-    channel->correlate_row[index] = FNAME(decorrelate_0)(&cur_row[index], bpc_mask);    \
-    golomb_coding(encoder, channel->correlate_row[index],                               \
-                  find_bucket(channel,                                                  \
-                              channel->correlate_row[index - 1])->bestcode)
+    correlate_row_##channel[index] = FNAME(decorrelate_0)(&cur_row[index], bpc_mask);   \
+    golomb_coding(encoder, correlate_row_##channel[index],                              \
+                  find_bucket(channel_##channel,                                        \
+                              correlate_row_##channel[index - 1])->bestcode)
 
-#define UPDATE_MODEL(index)                                                             \
-    update_model(state, find_bucket(channel, channel->correlate_row[index - 1]),        \
-                 channel->correlate_row[index]);
+#define UPDATE_MODEL_COMP(channel, index)                                                   \
+    update_model(state, find_bucket(channel_##channel, correlate_row_##channel[index - 1]), \
+                 correlate_row_##channel[index])
+#define UPDATE_MODEL(index) UPDATE_MODEL_COMP(a, index)
 
-static void FNAME(compress_row0_seg)(Encoder *encoder, Channel *channel, int i,
+static void FNAME(compress_row0_seg)(Encoder *encoder, Channel *channel_a, int i,
                                      const PIXEL * const cur_row,
                                      const int end,
                                      const unsigned int waitmask,
                                      SPICE_GNUC_UNUSED const unsigned int bpc,
                                      const unsigned int bpc_mask)
 {
-    CommonState *state = &channel->state;
+    CommonState *state = &channel_a->state;
+    BYTE * const correlate_row_a = channel_a->correlate_row;
     int stopidx;
 
     spice_assert(end - i > 0);
 
     if (i == 0) {
-        COMPRESS_ONE_ROW0_0(channel);
+        COMPRESS_ONE_ROW0_0(a);
 
         if (state->waitcnt) {
             state->waitcnt--;
@@ -127,7 +129,7 @@ static void FNAME(compress_row0_seg)(Encoder *encoder, Channel *channel, int i,
 
     while (stopidx < end) {
         for (; i <= stopidx; i++) {
-            COMPRESS_ONE_ROW0(channel, i);
+            COMPRESS_ONE_ROW0(a, i);
         }
 
         UPDATE_MODEL(stopidx);
@@ -135,7 +137,7 @@ static void FNAME(compress_row0_seg)(Encoder *encoder, Channel *channel, int i,
     }
 
     for (; i < end; i++) {
-        COMPRESS_ONE_ROW0(channel, i);
+        COMPRESS_ONE_ROW0(a, i);
     }
     state->waitcnt = stopidx - end;
 }
@@ -178,17 +180,17 @@ static void FNAME(compress_row0)(Encoder *encoder, Channel *channel, const PIXEL
 }
 
 #define COMPRESS_ONE_0(channel) \
-    channel->correlate_row[0] = family.xlatU2L[(unsigned)((int)GET_a(cur_row) -                 \
-                                                          (int)GET_a(prev_row) ) & bpc_mask];   \
-    golomb_coding(encoder, channel->correlate_row[0],                                           \
-                  find_bucket(channel, channel->correlate_row[-1])->bestcode)
+    correlate_row_##channel[0] = family.xlatU2L[(unsigned)((int)GET_##channel(cur_row) -              \
+                                                          (int)GET_##channel(prev_row) ) & bpc_mask]; \
+    golomb_coding(encoder, correlate_row_##channel[0],                                                \
+                  find_bucket(channel_##channel, correlate_row_##channel[-1])->bestcode)
 
-#define COMPRESS_ONE(channel, index)                                                                  \
-     channel->correlate_row[index] = FNAME(decorrelate)(&prev_row[index], &cur_row[index], bpc_mask); \
-     golomb_coding(encoder, channel->correlate_row[index],                                            \
-                  find_bucket(channel, channel->correlate_row[index - 1])->bestcode)
+#define COMPRESS_ONE(channel, index)                                                                   \
+     correlate_row_##channel[index] = FNAME(decorrelate)(&prev_row[index], &cur_row[index], bpc_mask); \
+     golomb_coding(encoder, correlate_row_##channel[index],                                            \
+                   find_bucket(channel_##channel, correlate_row_##channel[index - 1])->bestcode)
 
-static void FNAME(compress_row_seg)(Encoder *encoder, Channel *channel, int i,
+static void FNAME(compress_row_seg)(Encoder *encoder, Channel *channel_a, int i,
                                     const PIXEL * const prev_row,
                                     const PIXEL * const cur_row,
                                     const int end,
@@ -196,7 +198,8 @@ static void FNAME(compress_row_seg)(Encoder *encoder, Channel *channel, int i,
                                     SPICE_GNUC_UNUSED const unsigned int bpc,
                                     const unsigned int bpc_mask)
 {
-    CommonState *state = &channel->state;
+    CommonState *state = &channel_a->state;
+    BYTE * const correlate_row_a = channel_a->correlate_row;
     int stopidx;
     int run_index = 0;
     int run_size;
@@ -204,14 +207,13 @@ static void FNAME(compress_row_seg)(Encoder *encoder, Channel *channel, int i,
     spice_assert(end - i > 0);
 
     if (i == 0) {
-        COMPRESS_ONE_0(channel);
+        COMPRESS_ONE_0(a);
 
         if (state->waitcnt) {
             state->waitcnt--;
         } else {
             state->waitcnt = (tabrand(&state->tabrand_seed) & waitmask);
-            update_model(state, find_bucket(channel, channel->correlate_row[-1]),
-                         channel->correlate_row[0]);
+            UPDATE_MODEL(0);
         }
         stopidx = ++i + state->waitcnt;
     } else {
@@ -221,7 +223,7 @@ static void FNAME(compress_row_seg)(Encoder *encoder, Channel *channel, int i,
         while (stopidx < end) {
             for (; i <= stopidx; i++) {
                 RLE_PRED_IMP;
-                COMPRESS_ONE(channel, i);
+                COMPRESS_ONE(a, i);
             }
 
             UPDATE_MODEL(stopidx);
@@ -230,7 +232,7 @@ static void FNAME(compress_row_seg)(Encoder *encoder, Channel *channel, int i,
 
         for (; i < end; i++) {
             RLE_PRED_IMP;
-            COMPRESS_ONE(channel, i);
+            COMPRESS_ONE(a, i);
         }
         state->waitcnt = stopidx - end;
 
@@ -244,11 +246,11 @@ do_run:
         while (SAME_PIXEL(&cur_row[i], &cur_row[i - 1])) {
             run_size++;
             if (++i == end) {
-                encode_channel_run(encoder, channel, run_size);
+                encode_channel_run(encoder, channel_a, run_size);
                 return;
             }
         }
-        encode_channel_run(encoder, channel, run_size);
+        encode_channel_run(encoder, channel_a, run_size);
         stopidx = i + state->waitcnt;
     }
 }
@@ -293,29 +295,29 @@ static void FNAME(compress_row)(Encoder *encoder, Channel *channel,
 
 #define UNCOMPRESS_PIX_START(row) do { } while (0)
 
-#define UNCOMPRESS_ONE_ROW0_0(channel)                                                                  \
-    channel->correlate_row[0] = (BYTE)golomb_decoding(find_bucket(channel,                              \
-                                                                  channel->correlate_row[-1])->bestcode,\
-                                                      encoder->io_word, &codewordlen);                  \
-    SET_a(&cur_row[0], (BYTE)family.xlatL2U[channel->correlate_row[0]]);                                \
+#define UNCOMPRESS_ONE_ROW0_0(channel)                                                                      \
+    correlate_row_##channel[0] = (BYTE)golomb_decoding(find_bucket(channel_##channel,                       \
+                                                                   correlate_row_##channel[-1])->bestcode,  \
+                                                       encoder->io_word, &codewordlen);                     \
+    SET_##channel(&cur_row[0], (BYTE)family.xlatL2U[correlate_row_##channel[0]]);                           \
     decode_eatbits(encoder, codewordlen);
 
-#define UNCOMPRESS_ONE_ROW0(channel)                                                                            \
-    channel->correlate_row[i] = (BYTE)golomb_decoding(find_bucket(channel,                                      \
-                                                                  channel->correlate_row[i - 1])->bestcode,     \
-                                                                  encoder->io_word,                             \
-                                                                  &codewordlen);                                \
-    FNAME(correlate_0)(&cur_row[i], channel->correlate_row[i], bpc_mask);                                                \
+#define UNCOMPRESS_ONE_ROW0(channel)                                                                           \
+    correlate_row_##channel[i] = (BYTE)golomb_decoding(find_bucket(channel_##channel,                          \
+                                                                   correlate_row_##channel[i - 1])->bestcode,  \
+                                                       encoder->io_word, &codewordlen);                        \
+    FNAME(correlate_0)(&cur_row[i], correlate_row_##channel[i], bpc_mask);                                     \
     decode_eatbits(encoder, codewordlen);
 
-static void FNAME(uncompress_row0_seg)(Encoder *encoder, Channel *channel, int i,
+static void FNAME(uncompress_row0_seg)(Encoder *encoder, Channel *channel_a, int i,
                                        PIXEL * const cur_row,
                                        const int end,
                                        const unsigned int waitmask,
                                        SPICE_GNUC_UNUSED const unsigned int bpc,
                                        const unsigned int bpc_mask)
 {
-    CommonState *state = &channel->state;
+    CommonState *state = &channel_a->state;
+    BYTE * const correlate_row_a = channel_a->correlate_row;
     int stopidx;
 
     spice_assert(end - i > 0);
@@ -324,7 +326,7 @@ static void FNAME(uncompress_row0_seg)(Encoder *encoder, Channel *channel, int i
         unsigned int codewordlen;
 
         UNCOMPRESS_PIX_START(&cur_row[i]);
-        UNCOMPRESS_ONE_ROW0_0(channel);
+        UNCOMPRESS_ONE_ROW0_0(a);
 
         if (state->waitcnt) {
             --state->waitcnt;
@@ -338,14 +340,12 @@ static void FNAME(uncompress_row0_seg)(Encoder *encoder, Channel *channel, int i
     }
 
     while (stopidx < end) {
-
         for (; i <= stopidx; i++) {
             unsigned int codewordlen;
 
             UNCOMPRESS_PIX_START(&cur_row[i]);
-            UNCOMPRESS_ONE_ROW0(channel);
+            UNCOMPRESS_ONE_ROW0(a);
         }
-
         UPDATE_MODEL(stopidx);
         stopidx = i + (tabrand(&state->tabrand_seed) & waitmask);
     }
@@ -354,7 +354,7 @@ static void FNAME(uncompress_row0_seg)(Encoder *encoder, Channel *channel, int i
         unsigned int codewordlen;
 
         UNCOMPRESS_PIX_START(&cur_row[i]);
-        UNCOMPRESS_ONE_ROW0(channel);
+        UNCOMPRESS_ONE_ROW0(a);
     }
     state->waitcnt = stopidx - end;
 }
@@ -396,22 +396,22 @@ static void FNAME(uncompress_row0)(Encoder *encoder, Channel *channel,
     spice_assert(DEFwminext > 0);
 }
 
-#define UNCOMPRESS_ONE_0(channel) \
-    channel->correlate_row[0] = (BYTE)golomb_decoding(find_bucket(channel,                              \
-                                                                  channel->correlate_row[-1])->bestcode,\
-                                                      encoder->io_word, &codewordlen);                  \
-    SET_a(&cur_row[0], (family.xlatL2U[channel->correlate_row[0]] +                                     \
-                  GET_a(prev_row)) & bpc_mask);                                                         \
+#define UNCOMPRESS_ONE_0(channel)                                                                          \
+    correlate_row_##channel[0] = (BYTE)golomb_decoding(find_bucket(channel_##channel,                      \
+                                                                   correlate_row_##channel[-1])->bestcode, \
+                                                       encoder->io_word, &codewordlen);                    \
+    SET_##channel(&cur_row[0], (family.xlatL2U[correlate_row_##channel[0]] +                               \
+                  GET_##channel(prev_row)) & bpc_mask);                                                    \
     decode_eatbits(encoder, codewordlen);
 
-#define UNCOMPRESS_ONE(channel)                                                                                 \
-    channel->correlate_row[i] = (BYTE)golomb_decoding(find_bucket(channel,                                      \
-                                                                  channel->correlate_row[i - 1])->bestcode,     \
-                                                      encoder->io_word, &codewordlen);                          \
-    FNAME(correlate)(&prev_row[i], &cur_row[i], channel->correlate_row[i], bpc_mask);                           \
+#define UNCOMPRESS_ONE(channel)                                                                               \
+    correlate_row_##channel[i] = (BYTE)golomb_decoding(find_bucket(channel_##channel,                         \
+                                                                   correlate_row_##channel[i - 1])->bestcode, \
+                                                       encoder->io_word, &codewordlen);                       \
+    FNAME(correlate)(&prev_row[i], &cur_row[i], correlate_row_##channel[i], bpc_mask);                        \
     decode_eatbits(encoder, codewordlen);
 
-static void FNAME(uncompress_row_seg)(Encoder *encoder, Channel *channel,
+static void FNAME(uncompress_row_seg)(Encoder *encoder, Channel *channel_a,
                                       const PIXEL * const prev_row,
                                       PIXEL * const cur_row,
                                       int i,
@@ -419,7 +419,8 @@ static void FNAME(uncompress_row_seg)(Encoder *encoder, Channel *channel,
                                       SPICE_GNUC_UNUSED const unsigned int bpc,
                                       const unsigned int bpc_mask)
 {
-    CommonState *state = &channel->state;
+    CommonState *state = &channel_a->state;
+    BYTE * const correlate_row_a = channel_a->correlate_row;
     const unsigned int waitmask = bppmask[state->wmidx];
     int stopidx;
     int run_index = 0;
@@ -431,7 +432,7 @@ static void FNAME(uncompress_row_seg)(Encoder *encoder, Channel *channel,
         unsigned int codewordlen;
 
         UNCOMPRESS_PIX_START(&cur_row[i]);
-        UNCOMPRESS_ONE_0(channel);
+        UNCOMPRESS_ONE_0(a);
 
         if (state->waitcnt) {
             --state->waitcnt;
@@ -448,9 +449,8 @@ static void FNAME(uncompress_row_seg)(Encoder *encoder, Channel *channel,
             for (; i <= stopidx; i++) {
                 unsigned int codewordlen;
                 RLE_PRED_IMP;
-
                 UNCOMPRESS_PIX_START(&cur_row[i]);
-                UNCOMPRESS_ONE(channel);
+                UNCOMPRESS_ONE(a);
             }
 
             UPDATE_MODEL(stopidx);
@@ -462,7 +462,7 @@ static void FNAME(uncompress_row_seg)(Encoder *encoder, Channel *channel,
             unsigned int codewordlen;
             RLE_PRED_IMP;
             UNCOMPRESS_PIX_START(&cur_row[i]);
-            UNCOMPRESS_ONE(channel);
+            UNCOMPRESS_ONE(a);
         }
 
         state->waitcnt = stopidx - end;
@@ -472,7 +472,7 @@ static void FNAME(uncompress_row_seg)(Encoder *encoder, Channel *channel,
 do_run:
         state->waitcnt = stopidx - i;
         run_index = i;
-        run_end = i + decode_channel_run(encoder, channel);
+        run_end = i + decode_channel_run(encoder, channel_a);
 
         for (; i < run_end; i++) {
             UNCOMPRESS_PIX_START(&cur_row[i]);
@@ -539,6 +539,7 @@ static void FNAME(uncompress_row)(Encoder *encoder, Channel *channel,
 #undef BPC_MASK
 #undef UPDATE_MODEL
 #undef UNCOMPRESS_PIX_START
+#undef UPDATE_MODEL_COMP
 #undef COMPRESS_ONE_0
 #undef COMPRESS_ONE
 #undef UNCOMPRESS_ONE_ROW0
commit 1ca7e2d7658b14d0f6ab004d69c684a6cb5af8be
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Tue Jul 10 11:02:10 2018 +0200

    quic: Add SAME_PIXEL macro
    
    This helps making the code in quic_tmpl.c and quic_rgb_tmpl.c more
    similar.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/common/quic_tmpl.c b/common/quic_tmpl.c
index 72966cf..3087466 100644
--- a/common/quic_tmpl.c
+++ b/common/quic_tmpl.c
@@ -43,12 +43,15 @@
 #define SET_a(pix, val) ((pix)->a = val)
 #define GET_a(pix) ((pix)->a)
 
+#define SAME_PIXEL(p1, p2)                                 \
+     (GET_a(p1) == GET_a(p2))
+
 #define _PIXEL_A(channel, curr) ((unsigned int)GET_##channel((curr) - 1))
 #define _PIXEL_B(channel, prev) ((unsigned int)GET_##channel(prev))
 
 #define RLE_PRED_IMP                                                       \
-if (prev_row[i - 1].a == prev_row[i].a) {                                  \
-    if (run_index != i && i > 2 && cur_row[i - 1].a == cur_row[i - 2].a) { \
+if (SAME_PIXEL(&prev_row[i - 1], &prev_row[i])) {                                   \
+    if (run_index != i && i > 2 && SAME_PIXEL(&cur_row[i - 1], &cur_row[i - 2])) {  \
         goto do_run;                                                       \
     }                                                                      \
 }
@@ -238,7 +241,7 @@ do_run:
         state->waitcnt = stopidx - i;
         run_size = 0;
 
-        while (cur_row[i].a == cur_row[i - 1].a) {
+        while (SAME_PIXEL(&cur_row[i], &cur_row[i - 1])) {
             run_size++;
             if (++i == end) {
                 encode_channel_run(encoder, channel, run_size);
@@ -525,6 +528,7 @@ static void FNAME(uncompress_row)(Encoder *encoder, Channel *channel,
 #undef FNAME
 #undef _PIXEL_A
 #undef _PIXEL_B
+#undef SAME_PIXEL
 #undef RLE_PRED_IMP
 #undef golomb_coding
 #undef golomb_decoding
commit 499b10e494e487130d54a833990e6e23f35bfabd
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Tue Jul 10 11:02:09 2018 +0200

    quic: Rework PIXEL_A/PIXEL_B macros
    
    This makes them identical to their counterparts in quic_rgb_tmpl.c
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/common/quic_tmpl.c b/common/quic_tmpl.c
index 8069909..72966cf 100644
--- a/common/quic_tmpl.c
+++ b/common/quic_tmpl.c
@@ -43,8 +43,8 @@
 #define SET_a(pix, val) ((pix)->a = val)
 #define GET_a(pix) ((pix)->a)
 
-#define _PIXEL_A ((unsigned int)curr[-1].a)
-#define _PIXEL_B ((unsigned int)prev[0].a)
+#define _PIXEL_A(channel, curr) ((unsigned int)GET_##channel((curr) - 1))
+#define _PIXEL_B(channel, prev) ((unsigned int)GET_##channel(prev))
 
 #define RLE_PRED_IMP                                                       \
 if (prev_row[i - 1].a == prev_row[i].a) {                                  \
@@ -56,13 +56,13 @@ if (prev_row[i - 1].a == prev_row[i].a) {                                  \
 /*  a  */
 static inline BYTE FNAME(decorrelate_0)(const PIXEL * const curr, const unsigned int bpc_mask)
 {
-    return family.xlatU2L[(unsigned)((int)curr[0].a - (int)_PIXEL_A) & bpc_mask];
+    return family.xlatU2L[(unsigned)((int)GET_a(curr) - (int)_PIXEL_A(a, curr)) & bpc_mask];
 }
 
 static inline void FNAME(correlate_0)(PIXEL *curr, const BYTE correlate,
                                       const unsigned int bpc_mask)
 {
-    curr->a = (family.xlatL2U[correlate] + _PIXEL_A) & bpc_mask;
+    curr->a = (family.xlatL2U[correlate] + _PIXEL_A(a, curr)) & bpc_mask;
 }
 
 
@@ -70,14 +70,14 @@ static inline void FNAME(correlate_0)(PIXEL *curr, const BYTE correlate,
 static inline BYTE FNAME(decorrelate)(const PIXEL *const prev, const PIXEL * const curr,
                                       const unsigned int bpc_mask)
 {
-    return family.xlatU2L[(unsigned)((int)curr->a - (int)((_PIXEL_A + _PIXEL_B) >> 1)) & bpc_mask];
+    return family.xlatU2L[(unsigned)((int)curr->a - (int)((_PIXEL_A(a, curr) + _PIXEL_B(a, prev)) >> 1)) & bpc_mask];
 }
 
 
 static inline void FNAME(correlate)(const PIXEL *prev, PIXEL *curr, const BYTE correlate,
                                     const unsigned int bpc_mask)
 {
-    curr->a = (family.xlatL2U[correlate] + (int)((_PIXEL_A + _PIXEL_B) >> 1)) & bpc_mask;
+    curr->a = (family.xlatL2U[correlate] + (int)((_PIXEL_A(a, curr) + _PIXEL_B(a, prev)) >> 1)) & bpc_mask;
 }
 
 #define COMPRESS_ONE_ROW0_0(channel)                                 \
commit 946d3dda2276ca8bf1b9986142d8ed36b4e72753
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Tue Jul 10 11:02:08 2018 +0200

    quic: Add UPDATE_MODEL_COMP macro to iterate over channels
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/common/quic_rgb_tmpl.c b/common/quic_rgb_tmpl.c
index e0a05ca..2e76645 100644
--- a/common/quic_rgb_tmpl.c
+++ b/common/quic_rgb_tmpl.c
@@ -140,13 +140,13 @@
     golomb_coding(encoder, correlate_row_##channel[index], find_bucket(channel_##channel, \
                   correlate_row_##channel[index -1])->bestcode)
 
+#define UPDATE_MODEL_COMP(channel, index)                                                             \
+    update_model(state, find_bucket(channel_##channel, correlate_row_##channel[index - 1]),        \
+                 correlate_row_##channel[index])
 #define UPDATE_MODEL(index)                                                            \
-    update_model(state, find_bucket(channel_r, correlate_row_r[index - 1]),            \
-                correlate_row_r[index]);                                               \
-    update_model(state, find_bucket(channel_g, correlate_row_g[index - 1]),            \
-                correlate_row_g[index]);                                               \
-    update_model(state, find_bucket(channel_b, correlate_row_b[index - 1]),            \
-                correlate_row_b[index]);
+    UPDATE_MODEL_COMP(r, index); \
+    UPDATE_MODEL_COMP(g, index); \
+    UPDATE_MODEL_COMP(b, index)
 
 
 #define RLE_PRED_IMP                                                                \
@@ -670,3 +670,4 @@ static void FNAME(uncompress_row)(Encoder *encoder,
 #undef SET_b
 #undef GET_b
 #undef UNCOMPRESS_PIX_START
+#undef UPDATE_MODEL_COMP


More information about the Spice-commits mailing list