[PATCH spice-common 2/6] quic: Continue template unification

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Define SAME_PIXEL also for single channel.
Define _PIXEL_A in single channel similarly to rgb.
Define COMPRESS_xx/UNCOMPRESS_xx macros in a more similar way,
using channel name.

Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx>
---
 common/quic_rgb_tmpl.c |  18 +++---
 common/quic_tmpl.c     | 141 +++++++++++++++++++++--------------------
 2 files changed, 83 insertions(+), 76 deletions(-)

diff --git a/common/quic_rgb_tmpl.c b/common/quic_rgb_tmpl.c
index e0a05ca..b4b4c3f 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                                                                \
@@ -212,6 +212,9 @@ static void FNAME(compress_row0_seg)(Encoder *encoder, int i,
     state->waitcnt = stopidx - end;
 }
 
+#undef COMPRESS_ONE_ROW0_0
+#undef COMPRESS_ONE_ROW0
+
 static void FNAME(compress_row0)(Encoder *encoder, const PIXEL *cur_row,
                                  unsigned int width)
 {
@@ -645,8 +648,6 @@ static void FNAME(uncompress_row)(Encoder *encoder,
 #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
@@ -670,3 +671,4 @@ static void FNAME(uncompress_row)(Encoder *encoder,
 #undef SET_b
 #undef GET_b
 #undef UNCOMPRESS_PIX_START
+#undef UPDATE_MODEL_COMP
diff --git a/common/quic_tmpl.c b/common/quic_tmpl.c
index 8069909..dec23e6 100644
--- a/common/quic_tmpl.c
+++ b/common/quic_tmpl.c
@@ -43,7 +43,10 @@
 #define SET_a(pix, val) ((pix)->a = val)
 #define GET_a(pix) ((pix)->a)
 
-#define _PIXEL_A ((unsigned int)curr[-1].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 ((unsigned int)prev[0].a)
 
 #define RLE_PRED_IMP                                                       \
@@ -56,13 +59,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,46 +73,46 @@ 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) >> 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) >> 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)
+#define COMPRESS_ONE_ROW0(channel, index)                                                 \
+    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--;
@@ -124,7 +127,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);
@@ -132,7 +135,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;
 }
@@ -175,17 +178,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,
@@ -193,7 +196,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;
@@ -201,14 +205,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 {
@@ -218,7 +221,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);
@@ -227,7 +230,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;
 
@@ -238,14 +241,14 @@ 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);
+                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;
     }
 }
@@ -291,28 +294,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,\
+    correlate_row_##channel[0] = (BYTE)golomb_decoding(find_bucket(channel_##channel,                              \
+                                                                  correlate_row_##channel[-1])->bestcode,\
                                                       encoder->io_word, &codewordlen);                  \
-    SET_a(&cur_row[0], (BYTE)family.xlatL2U[channel->correlate_row[0]]);                                \
+    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,     \
+    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], channel->correlate_row[i], bpc_mask);                                                \
+    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);
@@ -321,7 +325,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;
@@ -335,14 +339,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);
     }
@@ -351,7 +353,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;
 }
@@ -394,21 +396,21 @@ static void FNAME(uncompress_row0)(Encoder *encoder, Channel *channel,
 }
 
 #define UNCOMPRESS_ONE_0(channel) \
-    channel->correlate_row[0] = (BYTE)golomb_decoding(find_bucket(channel,                              \
-                                                                  channel->correlate_row[-1])->bestcode,\
+    correlate_row_##channel[0] = (BYTE)golomb_decoding(find_bucket(channel_##channel,                              \
+                                                                  correlate_row_##channel[-1])->bestcode,\
                                                       encoder->io_word, &codewordlen);                  \
-    SET_a(&cur_row[0], (family.xlatL2U[channel->correlate_row[0]] +                                     \
-                  GET_a(prev_row)) & bpc_mask);                                                         \
+    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,     \
+    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], channel->correlate_row[i], bpc_mask);                           \
+    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,
@@ -416,7 +418,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;
@@ -428,7 +431,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;
@@ -445,9 +448,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);
@@ -459,7 +461,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;
@@ -469,7 +471,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]);
@@ -541,3 +543,6 @@ static void FNAME(uncompress_row)(Encoder *encoder, Channel *channel,
 #undef UNCOMPRESS_ONE_ROW0_0
 #undef UNCOMPRESS_ONE_0
 #undef UNCOMPRESS_ONE
+#undef SAME_PIXEL
+#undef SET_a
+#undef GET_a
-- 
2.17.1

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux Virtualization]     [Linux Virtualization]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]