Use a APPLY_ALL_COMP macro to unify single/multiple channel processing. Make declaration on compress_rowXX function more similar. Call directly encode_state_run from templates. Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx> --- common/quic.c | 21 ------ common/quic_rgb_tmpl.c | 110 ++++++++++++---------------- common/quic_tmpl.c | 158 +++++++++++++++++++++-------------------- 3 files changed, 128 insertions(+), 161 deletions(-) diff --git a/common/quic.c b/common/quic.c index 04f3999..8259185 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 b4b4c3f..0cdf010 100644 --- a/common/quic_rgb_tmpl.c +++ b/common/quic_rgb_tmpl.c @@ -103,6 +103,9 @@ #define UNCOMPRESS_PIX_START(pix) ((pix)->pad = 0) #endif +#define CHANNEL_ARG_ +#define CHANNEL_ + #define SAME_PIXEL(p1, p2) \ (GET_r(p1) == GET_r(p2) && GET_g(p1) == GET_g(p2) && \ GET_b(p1) == GET_b(p2)) @@ -143,11 +146,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])) { \ @@ -158,7 +162,7 @@ if (SAME_PIXEL(&prev_row[i - 1], &prev_row[i])) { #ifdef COMPRESS_IMP -static void FNAME(compress_row0_seg)(Encoder *encoder, int i, +static void FNAME(compress_row0_seg)(Encoder *encoder, CHANNEL_ARG_ int i, const PIXEL * const cur_row, const int end, const unsigned int waitmask, @@ -178,9 +182,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 +197,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 +205,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; } @@ -215,7 +213,7 @@ static void FNAME(compress_row0_seg)(Encoder *encoder, int i, #undef COMPRESS_ONE_ROW0_0 #undef COMPRESS_ONE_ROW0 -static void FNAME(compress_row0)(Encoder *encoder, const PIXEL *cur_row, +static void FNAME(compress_row0)(Encoder *encoder, CHANNEL_ARG_ const PIXEL *cur_row, unsigned int width) { CommonState *state = &encoder->rgb_state; @@ -225,7 +223,7 @@ 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, + FNAME(compress_row0_seg)(encoder, CHANNEL_ pos, cur_row, pos + state->wmileft, bppmask[state->wmidx], bpc, bpc_mask); width -= state->wmileft; pos += state->wmileft; @@ -237,7 +235,7 @@ static void FNAME(compress_row0)(Encoder *encoder, const PIXEL *cur_row, } if (width) { - FNAME(compress_row0_seg)(encoder, pos, cur_row, pos + width, + FNAME(compress_row0_seg)(encoder, CHANNEL_ pos, cur_row, pos + width, bppmask[state->wmidx], bpc, bpc_mask); if (DEFwmimax > (int)state->wmidx) { state->wmileft -= width; @@ -261,7 +259,7 @@ 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, +static void FNAME(compress_row_seg)(Encoder *encoder, CHANNEL_ARG_ int i, const PIXEL * const prev_row, const PIXEL * const cur_row, const int end, @@ -284,9 +282,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--; @@ -302,9 +298,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); @@ -313,9 +307,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; @@ -329,16 +321,16 @@ 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; } } -static void FNAME(compress_row)(Encoder *encoder, +static void FNAME(compress_row)(Encoder *encoder, CHANNEL_ARG_ const PIXEL * const prev_row, const PIXEL * const cur_row, unsigned int width) @@ -351,9 +343,8 @@ 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], + FNAME(compress_row_seg)(encoder, CHANNEL_ pos, prev_row, cur_row, + pos + state->wmileft, bppmask[state->wmidx], bpc, bpc_mask); width -= state->wmileft; pos += state->wmileft; @@ -365,7 +356,7 @@ static void FNAME(compress_row)(Encoder *encoder, } if (width) { - FNAME(compress_row_seg)(encoder, pos, prev_row, cur_row, pos + width, + FNAME(compress_row_seg)(encoder, CHANNEL_ pos, prev_row, cur_row, pos + width, bppmask[state->wmidx], bpc, bpc_mask); if (DEFwmimax > (int)state->wmidx) { state->wmileft -= width; @@ -379,14 +370,14 @@ static void FNAME(compress_row)(Encoder *encoder, #endif -#define UNCOMPRESS_ONE_ROW0_0(channel) \ +#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) \ +#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, \ @@ -395,7 +386,7 @@ static void FNAME(compress_row)(Encoder *encoder, bpc_mask)); \ decode_eatbits(encoder, codewordlen); -static void FNAME(uncompress_row0_seg)(Encoder *encoder, int i, +static void FNAME(uncompress_row0_seg)(Encoder *encoder, CHANNEL_ARG_ int i, PIXEL * const cur_row, const int end, const unsigned int waitmask, @@ -418,9 +409,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; @@ -438,9 +427,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); @@ -450,14 +437,12 @@ 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; } -static void FNAME(uncompress_row0)(Encoder *encoder, +static void FNAME(uncompress_row0)(Encoder *encoder, CHANNEL_ARG_ PIXEL * const cur_row, unsigned int width) @@ -469,7 +454,7 @@ 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, + FNAME(uncompress_row0_seg)(encoder, CHANNEL_ pos, cur_row, pos + state->wmileft, bppmask[state->wmidx], bpc, bpc_mask); @@ -483,7 +468,7 @@ static void FNAME(uncompress_row0)(Encoder *encoder, } if (width) { - FNAME(uncompress_row0_seg)(encoder, pos, cur_row, pos + width, + FNAME(uncompress_row0_seg)(encoder, CHANNEL_ pos, cur_row, pos + width, bppmask[state->wmidx], bpc, bpc_mask); if (DEFwmimax > (int)state->wmidx) { state->wmileft -= width; @@ -503,7 +488,7 @@ static void FNAME(uncompress_row0)(Encoder *encoder, GET_##channel(prev_row)) & bpc_mask); \ decode_eatbits(encoder, codewordlen); -#define UNCOMPRESS_ONE(channel) \ +#define UNCOMPRESS_ONE(channel) \ correlate_row_##channel[i] = (BYTE)golomb_decoding(find_bucket(channel_##channel, \ correlate_row_##channel[i - 1])->bestcode, \ encoder->io_word, \ @@ -512,7 +497,7 @@ static void FNAME(uncompress_row0)(Encoder *encoder, &cur_row[i]); \ decode_eatbits(encoder, codewordlen); -static void FNAME(uncompress_row_seg)(Encoder *encoder, +static void FNAME(uncompress_row_seg)(Encoder *encoder, CHANNEL_ARG_ const PIXEL * const prev_row, PIXEL * const cur_row, int i, @@ -539,9 +524,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; @@ -559,9 +542,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); @@ -573,9 +554,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; @@ -585,7 +564,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]); @@ -602,7 +581,7 @@ do_run: } } -static void FNAME(uncompress_row)(Encoder *encoder, +static void FNAME(uncompress_row)(Encoder *encoder, CHANNEL_ARG_ const PIXEL * const prev_row, PIXEL * const cur_row, unsigned int width) @@ -615,7 +594,7 @@ 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, + FNAME(uncompress_row_seg)(encoder, CHANNEL_ prev_row, cur_row, pos, pos + state->wmileft, bpc, bpc_mask); pos += state->wmileft; width -= state->wmileft; @@ -627,7 +606,7 @@ static void FNAME(uncompress_row)(Encoder *encoder, } if (width) { - FNAME(uncompress_row_seg)(encoder, prev_row, cur_row, pos, + FNAME(uncompress_row_seg)(encoder, CHANNEL_ prev_row, cur_row, pos, pos + width, bpc, bpc_mask); if (DEFwmimax > (int)state->wmidx) { state->wmileft -= width; @@ -672,3 +651,6 @@ static void FNAME(uncompress_row)(Encoder *encoder, #undef GET_b #undef UNCOMPRESS_PIX_START #undef UPDATE_MODEL_COMP +#undef CHANNEL_ARG_ +#undef CHANNEL_ +#undef APPLY_ALL_COMP diff --git a/common/quic_tmpl.c b/common/quic_tmpl.c index dec23e6..37b15cf 100644 --- a/common/quic_tmpl.c +++ b/common/quic_tmpl.c @@ -40,6 +40,9 @@ #define BPC 8 #define BPC_MASK 0xffU +#define CHANNEL_ARG_ Channel *channel_a, +#define CHANNEL_ channel_a, + #define SET_a(pix, val) ((pix)->a = val) #define GET_a(pix) ((pix)->a) @@ -47,40 +50,26 @@ (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 \ -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) { \ - goto do_run; \ - } \ -} +#define _PIXEL_B(channel, prev) ((unsigned int)GET_##channel(prev)) /* 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) >> 1)) & 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] 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) >> 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) \ @@ -89,16 +78,26 @@ 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) #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__) + +#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(compress_row0_seg)(Encoder *encoder, Channel *channel_a, int i, +static void FNAME(compress_row0_seg)(Encoder *encoder, CHANNEL_ARG_ int i, const PIXEL * const cur_row, const int end, const unsigned int waitmask, @@ -112,7 +111,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--; @@ -127,7 +126,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); @@ -135,7 +134,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; } @@ -143,17 +142,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, +static void FNAME(compress_row0)(Encoder *encoder, CHANNEL_ARG_ 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, + FNAME(compress_row0_seg)(encoder, CHANNEL_ pos, cur_row, pos + state->wmileft, bppmask[state->wmidx], bpc, bpc_mask); width -= state->wmileft; pos += state->wmileft; @@ -165,7 +164,7 @@ static void FNAME(compress_row0)(Encoder *encoder, Channel *channel, const PIXEL } if (width) { - FNAME(compress_row0_seg)(encoder, channel, pos, cur_row, pos + width, + FNAME(compress_row0_seg)(encoder, CHANNEL_ pos, cur_row, pos + width, bppmask[state->wmidx], bpc, bpc_mask); if (DEFwmimax > (int)state->wmidx) { state->wmileft -= width; @@ -183,12 +182,13 @@ static void FNAME(compress_row0)(Encoder *encoder, Channel *channel, const PIXEL golomb_coding(encoder, correlate_row_##channel[0], \ 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); \ - golomb_coding(encoder, correlate_row_##channel[index], \ +#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(compress_row_seg)(Encoder *encoder, Channel *channel_a, int i, +static void FNAME(compress_row_seg)(Encoder *encoder, CHANNEL_ARG_ int i, const PIXEL * const prev_row, const PIXEL * const cur_row, const int end, @@ -205,7 +205,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--; @@ -221,7 +221,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); @@ -230,7 +230,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; @@ -244,29 +244,29 @@ 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; } } -static void FNAME(compress_row)(Encoder *encoder, Channel *channel, +static void FNAME(compress_row)(Encoder *encoder, CHANNEL_ARG_ 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, + FNAME(compress_row_seg)(encoder, CHANNEL_ pos, prev_row, cur_row, pos + state->wmileft, bppmask[state->wmidx], bpc, bpc_mask); width -= state->wmileft; @@ -279,7 +279,7 @@ static void FNAME(compress_row)(Encoder *encoder, Channel *channel, } if (width) { - FNAME(compress_row_seg)(encoder, channel, pos, prev_row, cur_row, pos + width, + FNAME(compress_row_seg)(encoder, CHANNEL_ pos, prev_row, cur_row, pos + width, bppmask[state->wmidx], bpc, bpc_mask); if (DEFwmimax > (int)state->wmidx) { state->wmileft -= width; @@ -293,22 +293,23 @@ static void FNAME(compress_row)(Encoder *encoder, Channel *channel, #define UNCOMPRESS_PIX_START(row) do { } while (0) -#define UNCOMPRESS_ONE_ROW0_0(channel) \ +#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, \ +#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); \ + 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, +static void FNAME(uncompress_row0_seg)(Encoder *encoder, CHANNEL_ARG_ int i, PIXEL * const cur_row, const int end, const unsigned int waitmask, @@ -325,7 +326,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; @@ -343,7 +344,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); @@ -353,25 +354,26 @@ 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; } -static void FNAME(uncompress_row0)(Encoder *encoder, Channel *channel, +static void FNAME(uncompress_row0)(Encoder *encoder, CHANNEL_ARG_ 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], + FNAME(uncompress_row0_seg)(encoder, CHANNEL_ pos, cur_row, + pos + state->wmileft, + bppmask[state->wmidx], bpc, bpc_mask); pos += state->wmileft; width -= state->wmileft; @@ -383,7 +385,7 @@ static void FNAME(uncompress_row0)(Encoder *encoder, Channel *channel, } if (width) { - FNAME(uncompress_row0_seg)(encoder, channel, pos, cur_row, pos + width, + FNAME(uncompress_row0_seg)(encoder, CHANNEL_ pos, cur_row, pos + width, bppmask[state->wmidx], bpc, bpc_mask); if (DEFwmimax > (int)state->wmidx) { state->wmileft -= width; @@ -403,14 +405,15 @@ static void FNAME(uncompress_row0)(Encoder *encoder, Channel *channel, 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); \ - FNAME(correlate)(&prev_row[i], &cur_row[i], correlate_row_##channel[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_a, +static void FNAME(uncompress_row_seg)(Encoder *encoder, CHANNEL_ARG_ const PIXEL * const prev_row, PIXEL * const cur_row, int i, @@ -431,7 +434,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; @@ -449,7 +452,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); @@ -461,7 +464,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; @@ -471,7 +474,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]); @@ -486,20 +489,20 @@ do_run: } } -static void FNAME(uncompress_row)(Encoder *encoder, Channel *channel, +static void FNAME(uncompress_row)(Encoder *encoder, CHANNEL_ARG_ 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, + FNAME(uncompress_row_seg)(encoder, CHANNEL_ prev_row, cur_row, pos, pos + state->wmileft, bpc, bpc_mask); pos += state->wmileft; width -= state->wmileft; @@ -511,7 +514,7 @@ static void FNAME(uncompress_row)(Encoder *encoder, Channel *channel, } if (width) { - FNAME(uncompress_row_seg)(encoder, channel, prev_row, cur_row, pos, + FNAME(uncompress_row_seg)(encoder, CHANNEL_ prev_row, cur_row, pos, pos + width, bpc, bpc_mask); if (DEFwmimax > (int)state->wmidx) { state->wmileft -= width; @@ -527,6 +530,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 @@ -543,6 +547,8 @@ 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 +#undef CHANNEL_ARG_ +#undef CHANNEL_ +#undef APPLY_ALL_COMP -- 2.17.1 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel