[Spice-devel] [spice-common v2 07/13] quic: Introduce CommonState *state variable in templates
Christophe Fergeau
cfergeau at redhat.com
Wed Aug 2 08:15:04 UTC 2017
Most functions in quic_tmpl.c/quic_rgb_tmpl.c have only superficial
differences. One of them is using channel->state or encoder->rgb_state.
This commit adds a local CommonState *state in all template methods
which will be used instead of channel->state or encoder->rgb_state.
This makes it easier to spot the common code between the 2 template
files...
Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>
---
common/quic_rgb_tmpl.c | 190 +++++++++++++++++++++++++-----------------------
common/quic_tmpl.c | 194 +++++++++++++++++++++++++------------------------
2 files changed, 200 insertions(+), 184 deletions(-)
diff --git a/common/quic_rgb_tmpl.c b/common/quic_rgb_tmpl.c
index 96d3a94..309ab64 100644
--- a/common/quic_rgb_tmpl.c
+++ b/common/quic_rgb_tmpl.c
@@ -145,12 +145,12 @@
&codeword, &codewordlen); \
encode(encoder, codeword, codewordlen);
-#define UPDATE_MODEL(index) \
- update_model(&encoder->rgb_state, find_bucket(channel_r, correlate_row_r[index - 1]), \
+#define UPDATE_MODEL(index) \
+ update_model(state, find_bucket(channel_r, correlate_row_r[index - 1]), \
correlate_row_r[index]); \
- update_model(&encoder->rgb_state, find_bucket(channel_g, correlate_row_g[index - 1]), \
+ update_model(state, find_bucket(channel_g, correlate_row_g[index - 1]), \
correlate_row_g[index]); \
- update_model(&encoder->rgb_state, find_bucket(channel_b, correlate_row_b[index - 1]), \
+ update_model(state, find_bucket(channel_b, correlate_row_b[index - 1]), \
correlate_row_b[index]);
@@ -170,6 +170,7 @@ static void FNAME(compress_row0_seg)(Encoder *encoder, 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;
@@ -188,15 +189,15 @@ static void FNAME(compress_row0_seg)(Encoder *encoder, int i,
COMPRESS_ONE_ROW0_0(g);
COMPRESS_ONE_ROW0_0(b);
- if (encoder->rgb_state.waitcnt) {
- encoder->rgb_state.waitcnt--;
+ if (state->waitcnt) {
+ state->waitcnt--;
} else {
- encoder->rgb_state.waitcnt = (tabrand(&encoder->rgb_state.tabrand_seed) & waitmask);
+ state->waitcnt = (tabrand(&state->tabrand_seed) & waitmask);
UPDATE_MODEL(0);
}
- stopidx = ++i + encoder->rgb_state.waitcnt;
+ stopidx = ++i + state->waitcnt;
} else {
- stopidx = i + encoder->rgb_state.waitcnt;
+ stopidx = i + state->waitcnt;
}
while (stopidx < end) {
@@ -208,7 +209,7 @@ static void FNAME(compress_row0_seg)(Encoder *encoder, int i,
}
UPDATE_MODEL(stopidx);
- stopidx = i + (tabrand(&encoder->rgb_state.tabrand_seed) & waitmask);
+ stopidx = i + (tabrand(&state->tabrand_seed) & waitmask);
}
for (; i < end; i++) {
@@ -218,39 +219,40 @@ static void FNAME(compress_row0_seg)(Encoder *encoder, int i,
COMPRESS_ONE_ROW0(g, i);
COMPRESS_ONE_ROW0(b, i);
}
- encoder->rgb_state.waitcnt = stopidx - end;
+ state->waitcnt = stopidx - end;
}
static void FNAME(compress_row0)(Encoder *encoder, const PIXEL *cur_row,
unsigned int width)
{
+ CommonState *state = &encoder->rgb_state;
const unsigned int bpc = BPC;
const unsigned int bpc_mask = BPC_MASK;
int pos = 0;
- while ((DEFwmimax > (int)encoder->rgb_state.wmidx) && (encoder->rgb_state.wmileft <= width)) {
- if (encoder->rgb_state.wmileft) {
- FNAME(compress_row0_seg)(encoder, pos, cur_row, pos + encoder->rgb_state.wmileft,
- bppmask[encoder->rgb_state.wmidx], bpc, bpc_mask);
- width -= encoder->rgb_state.wmileft;
- pos += encoder->rgb_state.wmileft;
+ 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);
+ width -= state->wmileft;
+ pos += state->wmileft;
}
- encoder->rgb_state.wmidx++;
- set_wm_trigger(&encoder->rgb_state);
- encoder->rgb_state.wmileft = DEFwminext;
+ state->wmidx++;
+ set_wm_trigger(state);
+ state->wmileft = DEFwminext;
}
if (width) {
FNAME(compress_row0_seg)(encoder, pos, cur_row, pos + width,
- bppmask[encoder->rgb_state.wmidx], bpc, bpc_mask);
- if (DEFwmimax > (int)encoder->rgb_state.wmidx) {
- encoder->rgb_state.wmileft -= width;
+ bppmask[state->wmidx], bpc, bpc_mask);
+ if (DEFwmimax > (int)state->wmidx) {
+ state->wmileft -= width;
}
}
- spice_assert((int)encoder->rgb_state.wmidx <= DEFwmimax);
- spice_assert(encoder->rgb_state.wmidx <= 32);
+ spice_assert((int)state->wmidx <= DEFwmimax);
+ spice_assert(state->wmidx <= 32);
spice_assert(DEFwminext > 0);
}
@@ -278,6 +280,7 @@ static void FNAME(compress_row_seg)(Encoder *encoder, 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;
@@ -298,15 +301,15 @@ static void FNAME(compress_row_seg)(Encoder *encoder, int i,
COMPRESS_ONE_0(g);
COMPRESS_ONE_0(b);
- if (encoder->rgb_state.waitcnt) {
- encoder->rgb_state.waitcnt--;
+ if (state->waitcnt) {
+ state->waitcnt--;
} else {
- encoder->rgb_state.waitcnt = (tabrand(&encoder->rgb_state.tabrand_seed) & waitmask);
+ state->waitcnt = (tabrand(&state->tabrand_seed) & waitmask);
UPDATE_MODEL(0);
}
- stopidx = ++i + encoder->rgb_state.waitcnt;
+ stopidx = ++i + state->waitcnt;
} else {
- stopidx = i + encoder->rgb_state.waitcnt;
+ stopidx = i + state->waitcnt;
}
for (;;) {
while (stopidx < end) {
@@ -319,7 +322,7 @@ static void FNAME(compress_row_seg)(Encoder *encoder, int i,
}
UPDATE_MODEL(stopidx);
- stopidx = i + (tabrand(&encoder->rgb_state.tabrand_seed) & waitmask);
+ stopidx = i + (tabrand(&state->tabrand_seed) & waitmask);
}
for (; i < end; i++) {
@@ -329,13 +332,13 @@ static void FNAME(compress_row_seg)(Encoder *encoder, int i,
COMPRESS_ONE(g, i);
COMPRESS_ONE(b, i);
}
- encoder->rgb_state.waitcnt = stopidx - end;
+ state->waitcnt = stopidx - end;
return;
do_run:
run_index = i;
- encoder->rgb_state.waitcnt = stopidx - i;
+ state->waitcnt = stopidx - i;
run_size = 0;
while (SAME_PIXEL(&cur_row[i], &cur_row[i - 1])) {
@@ -346,7 +349,7 @@ do_run:
}
}
encode_run(encoder, run_size);
- stopidx = i + encoder->rgb_state.waitcnt;
+ stopidx = i + state->waitcnt;
}
}
@@ -356,35 +359,36 @@ static void FNAME(compress_row)(Encoder *encoder,
unsigned int width)
{
+ CommonState *state = &encoder->rgb_state;
const unsigned int bpc = BPC;
const unsigned int bpc_mask = BPC_MASK;
unsigned int pos = 0;
- while ((DEFwmimax > (int)encoder->rgb_state.wmidx) && (encoder->rgb_state.wmileft <= width)) {
- if (encoder->rgb_state.wmileft) {
+ while ((DEFwmimax > (int)state->wmidx) && (state->wmileft <= width)) {
+ if (state->wmileft) {
FNAME(compress_row_seg)(encoder, pos, prev_row, cur_row,
- pos + encoder->rgb_state.wmileft,
- bppmask[encoder->rgb_state.wmidx],
+ pos + state->wmileft,
+ bppmask[state->wmidx],
bpc, bpc_mask);
- width -= encoder->rgb_state.wmileft;
- pos += encoder->rgb_state.wmileft;
+ width -= state->wmileft;
+ pos += state->wmileft;
}
- encoder->rgb_state.wmidx++;
- set_wm_trigger(&encoder->rgb_state);
- encoder->rgb_state.wmileft = DEFwminext;
+ state->wmidx++;
+ set_wm_trigger(state);
+ state->wmileft = DEFwminext;
}
if (width) {
FNAME(compress_row_seg)(encoder, pos, prev_row, cur_row, pos + width,
- bppmask[encoder->rgb_state.wmidx], bpc, bpc_mask);
- if (DEFwmimax > (int)encoder->rgb_state.wmidx) {
- encoder->rgb_state.wmileft -= width;
+ bppmask[state->wmidx], bpc, bpc_mask);
+ if (DEFwmimax > (int)state->wmidx) {
+ state->wmileft -= width;
}
}
- spice_assert((int)encoder->rgb_state.wmidx <= DEFwmimax);
- spice_assert(encoder->rgb_state.wmidx <= 32);
+ spice_assert((int)state->wmidx <= DEFwmimax);
+ spice_assert(state->wmidx <= 32);
spice_assert(DEFwminext > 0);
}
@@ -413,6 +417,7 @@ static void FNAME(uncompress_row0_seg)(Encoder *encoder, 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;
@@ -432,15 +437,15 @@ static void FNAME(uncompress_row0_seg)(Encoder *encoder, int i,
UNCOMPRESS_ONE_ROW0_0(g);
UNCOMPRESS_ONE_ROW0_0(b);
- if (encoder->rgb_state.waitcnt) {
- --encoder->rgb_state.waitcnt;
+ if (state->waitcnt) {
+ --state->waitcnt;
} else {
- encoder->rgb_state.waitcnt = (tabrand(&encoder->rgb_state.tabrand_seed) & waitmask);
+ state->waitcnt = (tabrand(&state->tabrand_seed) & waitmask);
UPDATE_MODEL(0);
}
- stopidx = ++i + encoder->rgb_state.waitcnt;
+ stopidx = ++i + state->waitcnt;
} else {
- stopidx = i + encoder->rgb_state.waitcnt;
+ stopidx = i + state->waitcnt;
}
while (stopidx < end) {
@@ -453,7 +458,7 @@ static void FNAME(uncompress_row0_seg)(Encoder *encoder, int i,
UNCOMPRESS_ONE_ROW0(b);
}
UPDATE_MODEL(stopidx);
- stopidx = i + (tabrand(&encoder->rgb_state.tabrand_seed) & waitmask);
+ stopidx = i + (tabrand(&state->tabrand_seed) & waitmask);
}
for (; i < end; i++) {
@@ -464,7 +469,7 @@ static void FNAME(uncompress_row0_seg)(Encoder *encoder, int i,
UNCOMPRESS_ONE_ROW0(g);
UNCOMPRESS_ONE_ROW0(b);
}
- encoder->rgb_state.waitcnt = stopidx - end;
+ state->waitcnt = stopidx - end;
}
static void FNAME(uncompress_row0)(Encoder *encoder,
@@ -472,35 +477,36 @@ static void FNAME(uncompress_row0)(Encoder *encoder,
unsigned int width)
{
+ CommonState *state = &encoder->rgb_state;
const unsigned int bpc = BPC;
const unsigned int bpc_mask = BPC_MASK;
unsigned int pos = 0;
- while ((DEFwmimax > (int)encoder->rgb_state.wmidx) && (encoder->rgb_state.wmileft <= width)) {
- if (encoder->rgb_state.wmileft) {
+ while ((DEFwmimax > (int)state->wmidx) && (state->wmileft <= width)) {
+ if (state->wmileft) {
FNAME(uncompress_row0_seg)(encoder, pos, cur_row,
- pos + encoder->rgb_state.wmileft,
- bppmask[encoder->rgb_state.wmidx],
+ pos + state->wmileft,
+ bppmask[state->wmidx],
bpc, bpc_mask);
- pos += encoder->rgb_state.wmileft;
- width -= encoder->rgb_state.wmileft;
+ pos += state->wmileft;
+ width -= state->wmileft;
}
- encoder->rgb_state.wmidx++;
- set_wm_trigger(&encoder->rgb_state);
- encoder->rgb_state.wmileft = DEFwminext;
+ state->wmidx++;
+ set_wm_trigger(state);
+ state->wmileft = DEFwminext;
}
if (width) {
FNAME(uncompress_row0_seg)(encoder, pos, cur_row, pos + width,
- bppmask[encoder->rgb_state.wmidx], bpc, bpc_mask);
- if (DEFwmimax > (int)encoder->rgb_state.wmidx) {
- encoder->rgb_state.wmileft -= width;
+ bppmask[state->wmidx], bpc, bpc_mask);
+ if (DEFwmimax > (int)state->wmidx) {
+ state->wmileft -= width;
}
}
- spice_assert((int)encoder->rgb_state.wmidx <= DEFwmimax);
- spice_assert(encoder->rgb_state.wmidx <= 32);
+ spice_assert((int)state->wmidx <= DEFwmimax);
+ spice_assert(state->wmidx <= 32);
spice_assert(DEFwminext > 0);
}
@@ -529,6 +535,7 @@ static void FNAME(uncompress_row_seg)(Encoder *encoder,
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;
@@ -536,7 +543,7 @@ static void FNAME(uncompress_row_seg)(Encoder *encoder,
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;
- const unsigned int waitmask = bppmask[encoder->rgb_state.wmidx];
+ const unsigned int waitmask = bppmask[state->wmidx];
int stopidx;
int run_index = 0;
int run_end;
@@ -551,15 +558,15 @@ static void FNAME(uncompress_row_seg)(Encoder *encoder,
UNCOMPRESS_ONE_0(g);
UNCOMPRESS_ONE_0(b);
- if (encoder->rgb_state.waitcnt) {
- --encoder->rgb_state.waitcnt;
+ if (state->waitcnt) {
+ --state->waitcnt;
} else {
- encoder->rgb_state.waitcnt = (tabrand(&encoder->rgb_state.tabrand_seed) & waitmask);
+ state->waitcnt = (tabrand(&state->tabrand_seed) & waitmask);
UPDATE_MODEL(0);
}
- stopidx = ++i + encoder->rgb_state.waitcnt;
+ stopidx = ++i + state->waitcnt;
} else {
- stopidx = i + encoder->rgb_state.waitcnt;
+ stopidx = i + state->waitcnt;
}
for (;;) {
while (stopidx < end) {
@@ -574,7 +581,7 @@ static void FNAME(uncompress_row_seg)(Encoder *encoder,
UPDATE_MODEL(stopidx);
- stopidx = i + (tabrand(&encoder->rgb_state.tabrand_seed) & waitmask);
+ stopidx = i + (tabrand(&state->tabrand_seed) & waitmask);
}
for (; i < end; i++) {
@@ -586,12 +593,12 @@ static void FNAME(uncompress_row_seg)(Encoder *encoder,
UNCOMPRESS_ONE(b);
}
- encoder->rgb_state.waitcnt = stopidx - end;
+ state->waitcnt = stopidx - end;
return;
do_run:
- encoder->rgb_state.waitcnt = stopidx - i;
+ state->waitcnt = stopidx - i;
run_index = i;
run_end = i + decode_run(encoder);
@@ -606,7 +613,7 @@ do_run:
return;
}
- stopidx = i + encoder->rgb_state.waitcnt;
+ stopidx = i + state->waitcnt;
}
}
@@ -616,33 +623,34 @@ static void FNAME(uncompress_row)(Encoder *encoder,
unsigned int width)
{
+ CommonState *state = &encoder->rgb_state;
const unsigned int bpc = BPC;
const unsigned int bpc_mask = BPC_MASK;
unsigned int pos = 0;
- while ((DEFwmimax > (int)encoder->rgb_state.wmidx) && (encoder->rgb_state.wmileft <= width)) {
- if (encoder->rgb_state.wmileft) {
+ while ((DEFwmimax > (int)state->wmidx) && (state->wmileft <= width)) {
+ if (state->wmileft) {
FNAME(uncompress_row_seg)(encoder, prev_row, cur_row, pos,
- pos + encoder->rgb_state.wmileft, bpc, bpc_mask);
- pos += encoder->rgb_state.wmileft;
- width -= encoder->rgb_state.wmileft;
+ pos + state->wmileft, bpc, bpc_mask);
+ pos += state->wmileft;
+ width -= state->wmileft;
}
- encoder->rgb_state.wmidx++;
- set_wm_trigger(&encoder->rgb_state);
- encoder->rgb_state.wmileft = DEFwminext;
+ state->wmidx++;
+ set_wm_trigger(state);
+ state->wmileft = DEFwminext;
}
if (width) {
FNAME(uncompress_row_seg)(encoder, prev_row, cur_row, pos,
pos + width, bpc, bpc_mask);
- if (DEFwmimax > (int)encoder->rgb_state.wmidx) {
- encoder->rgb_state.wmileft -= width;
+ if (DEFwmimax > (int)state->wmidx) {
+ state->wmileft -= width;
}
}
- spice_assert((int)encoder->rgb_state.wmidx <= DEFwmimax);
- spice_assert(encoder->rgb_state.wmidx <= 32);
+ spice_assert((int)state->wmidx <= DEFwmimax);
+ spice_assert(state->wmidx <= 32);
spice_assert(DEFwminext > 0);
}
diff --git a/common/quic_tmpl.c b/common/quic_tmpl.c
index 1d3a346..5ca96fd 100644
--- a/common/quic_tmpl.c
+++ b/common/quic_tmpl.c
@@ -86,6 +86,7 @@ static void FNAME(compress_row0_seg)(Encoder *encoder, Channel *channel, int i,
SPICE_GNUC_UNUSED const unsigned int bpc,
const unsigned int bpc_mask)
{
+ CommonState *state = &channel->state;
BYTE * const decorrelate_drow = channel->correlate_row;
int stopidx;
@@ -99,16 +100,16 @@ static void FNAME(compress_row0_seg)(Encoder *encoder, Channel *channel, int i,
&codeword, &codewordlen);
encode(encoder, codeword, codewordlen);
- if (channel->state.waitcnt) {
- channel->state.waitcnt--;
+ if (state->waitcnt) {
+ state->waitcnt--;
} else {
- channel->state.waitcnt = (tabrand(&channel->state.tabrand_seed) & waitmask);
- update_model(&channel->state, find_bucket(channel, decorrelate_drow[-1]),
+ state->waitcnt = (tabrand(&state->tabrand_seed) & waitmask);
+ update_model(state, find_bucket(channel, decorrelate_drow[-1]),
decorrelate_drow[i]);
}
- stopidx = ++i + channel->state.waitcnt;
+ stopidx = ++i + state->waitcnt;
} else {
- stopidx = i + channel->state.waitcnt;
+ stopidx = i + state->waitcnt;
}
while (stopidx < end) {
@@ -121,9 +122,9 @@ static void FNAME(compress_row0_seg)(Encoder *encoder, Channel *channel, int i,
encode(encoder, codeword, codewordlen);
}
- update_model(&channel->state, find_bucket(channel, decorrelate_drow[stopidx - 1]),
+ update_model(state, find_bucket(channel, decorrelate_drow[stopidx - 1]),
decorrelate_drow[stopidx]);
- stopidx = i + (tabrand(&channel->state.tabrand_seed) & waitmask);
+ stopidx = i + (tabrand(&state->tabrand_seed) & waitmask);
}
for (; i < end; i++) {
@@ -133,39 +134,40 @@ static void FNAME(compress_row0_seg)(Encoder *encoder, Channel *channel, int i,
&codeword, &codewordlen);
encode(encoder, codeword, codewordlen);
}
- channel->state.waitcnt = stopidx - end;
+ state->waitcnt = stopidx - end;
}
static void FNAME(compress_row0)(Encoder *encoder, Channel *channel, const PIXEL *cur_row,
unsigned int width)
{
+ CommonState *state = &channel->state;
const unsigned int bpc = BPC;
const unsigned int bpc_mask = BPC_MASK;
int pos = 0;
- while ((DEFwmimax > (int)channel->state.wmidx) && (channel->state.wmileft <= width)) {
- if (channel->state.wmileft) {
- FNAME(compress_row0_seg)(encoder, channel, pos, cur_row, pos + channel->state.wmileft,
- bppmask[channel->state.wmidx], bpc, bpc_mask);
- width -= channel->state.wmileft;
- pos += channel->state.wmileft;
+ 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);
+ width -= state->wmileft;
+ pos += state->wmileft;
}
- channel->state.wmidx++;
- set_wm_trigger(&channel->state);
- channel->state.wmileft = DEFwminext;
+ state->wmidx++;
+ set_wm_trigger(state);
+ state->wmileft = DEFwminext;
}
if (width) {
FNAME(compress_row0_seg)(encoder, channel, pos, cur_row, pos + width,
- bppmask[channel->state.wmidx], bpc, bpc_mask);
- if (DEFwmimax > (int)channel->state.wmidx) {
- channel->state.wmileft -= width;
+ bppmask[state->wmidx], bpc, bpc_mask);
+ if (DEFwmimax > (int)state->wmidx) {
+ state->wmileft -= width;
}
}
- spice_assert((int)channel->state.wmidx <= DEFwmimax);
- spice_assert(channel->state.wmidx <= 32);
+ spice_assert((int)state->wmidx <= DEFwmimax);
+ spice_assert(state->wmidx <= 32);
spice_assert(DEFwminext > 0);
}
@@ -177,6 +179,7 @@ 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;
BYTE * const decorrelate_drow = channel->correlate_row;
int stopidx;
int run_index = 0;
@@ -196,16 +199,16 @@ static void FNAME(compress_row_seg)(Encoder *encoder, Channel *channel, int i,
&codewordlen);
encode(encoder, codeword, codewordlen);
- if (channel->state.waitcnt) {
- channel->state.waitcnt--;
+ if (state->waitcnt) {
+ state->waitcnt--;
} else {
- channel->state.waitcnt = (tabrand(&channel->state.tabrand_seed) & waitmask);
- update_model(&channel->state, find_bucket(channel, decorrelate_drow[-1]),
+ state->waitcnt = (tabrand(&state->tabrand_seed) & waitmask);
+ update_model(state, find_bucket(channel, decorrelate_drow[-1]),
decorrelate_drow[0]);
}
- stopidx = ++i + channel->state.waitcnt;
+ stopidx = ++i + state->waitcnt;
} else {
- stopidx = i + channel->state.waitcnt;
+ stopidx = i + state->waitcnt;
}
for (;;) {
while (stopidx < end) {
@@ -219,9 +222,9 @@ static void FNAME(compress_row_seg)(Encoder *encoder, Channel *channel, int i,
encode(encoder, codeword, codewordlen);
}
- update_model(&channel->state, find_bucket(channel, decorrelate_drow[stopidx - 1]),
+ update_model(state, find_bucket(channel, decorrelate_drow[stopidx - 1]),
decorrelate_drow[stopidx]);
- stopidx = i + (tabrand(&channel->state.tabrand_seed) & waitmask);
+ stopidx = i + (tabrand(&state->tabrand_seed) & waitmask);
}
for (; i < end; i++) {
@@ -233,13 +236,13 @@ static void FNAME(compress_row_seg)(Encoder *encoder, Channel *channel, int i,
&codeword, &codewordlen);
encode(encoder, codeword, codewordlen);
}
- channel->state.waitcnt = stopidx - end;
+ state->waitcnt = stopidx - end;
return;
do_run:
run_index = i;
- channel->state.waitcnt = stopidx - i;
+ state->waitcnt = stopidx - i;
run_size = 0;
while (cur_row[i].a == cur_row[i - 1].a) {
@@ -250,7 +253,7 @@ do_run:
}
}
encode_channel_run(encoder, channel, run_size);
- stopidx = i + channel->state.waitcnt;
+ stopidx = i + state->waitcnt;
}
}
@@ -260,34 +263,35 @@ static void FNAME(compress_row)(Encoder *encoder, Channel *channel,
unsigned int width)
{
+ CommonState *state = &channel->state;
const unsigned int bpc = BPC;
const unsigned int bpc_mask = BPC_MASK;
unsigned int pos = 0;
- while ((DEFwmimax > (int)channel->state.wmidx) && (channel->state.wmileft <= width)) {
- if (channel->state.wmileft) {
+ while ((DEFwmimax > (int)state->wmidx) && (state->wmileft <= width)) {
+ if (state->wmileft) {
FNAME(compress_row_seg)(encoder, channel, pos, prev_row, cur_row,
- pos + channel->state.wmileft, bppmask[channel->state.wmidx],
+ pos + state->wmileft, bppmask[state->wmidx],
bpc, bpc_mask);
- width -= channel->state.wmileft;
- pos += channel->state.wmileft;
+ width -= state->wmileft;
+ pos += state->wmileft;
}
- channel->state.wmidx++;
- set_wm_trigger(&channel->state);
- channel->state.wmileft = DEFwminext;
+ state->wmidx++;
+ set_wm_trigger(state);
+ state->wmileft = DEFwminext;
}
if (width) {
FNAME(compress_row_seg)(encoder, channel, pos, prev_row, cur_row, pos + width,
- bppmask[channel->state.wmidx], bpc, bpc_mask);
- if (DEFwmimax > (int)channel->state.wmidx) {
- channel->state.wmileft -= width;
+ bppmask[state->wmidx], bpc, bpc_mask);
+ if (DEFwmimax > (int)state->wmidx) {
+ state->wmileft -= width;
}
}
- spice_assert((int)channel->state.wmidx <= DEFwmimax);
- spice_assert(channel->state.wmidx <= 32);
+ spice_assert((int)state->wmidx <= DEFwmimax);
+ spice_assert(state->wmidx <= 32);
spice_assert(DEFwminext > 0);
}
@@ -299,6 +303,7 @@ static void FNAME(uncompress_row0_seg)(Encoder *encoder, Channel *channel, int i
SPICE_GNUC_UNUSED const unsigned int bpc,
const unsigned int bpc_mask)
{
+ CommonState *state = &channel->state;
int stopidx;
spice_assert(end - i > 0);
@@ -312,16 +317,16 @@ static void FNAME(uncompress_row0_seg)(Encoder *encoder, Channel *channel, int i
cur_row[0].a = (BYTE)family.xlatL2U[correlate_row[0]];
decode_eatbits(encoder, codewordlen);
- if (channel->state.waitcnt) {
- --channel->state.waitcnt;
+ if (state->waitcnt) {
+ --state->waitcnt;
} else {
- channel->state.waitcnt = (tabrand(&channel->state.tabrand_seed) & waitmask);
- update_model(&channel->state, find_bucket(channel, correlate_row[-1]),
+ state->waitcnt = (tabrand(&state->tabrand_seed) & waitmask);
+ update_model(state, find_bucket(channel, correlate_row[-1]),
correlate_row[0]);
}
- stopidx = ++i + channel->state.waitcnt;
+ stopidx = ++i + state->waitcnt;
} else {
- stopidx = i + channel->state.waitcnt;
+ stopidx = i + state->waitcnt;
}
while (stopidx < end) {
@@ -337,9 +342,9 @@ static void FNAME(uncompress_row0_seg)(Encoder *encoder, Channel *channel, int i
decode_eatbits(encoder, codewordlen);
}
- update_model(&channel->state, pbucket, correlate_row[stopidx]);
+ update_model(state, pbucket, correlate_row[stopidx]);
- stopidx = i + (tabrand(&channel->state.tabrand_seed) & waitmask);
+ stopidx = i + (tabrand(&state->tabrand_seed) & waitmask);
}
for (; i < end; i++) {
@@ -351,7 +356,7 @@ static void FNAME(uncompress_row0_seg)(Encoder *encoder, Channel *channel, int i
FNAME(correlate_0)(&cur_row[i], correlate_row[i], bpc_mask);
decode_eatbits(encoder, codewordlen);
}
- channel->state.waitcnt = stopidx - end;
+ state->waitcnt = stopidx - end;
}
static void FNAME(uncompress_row0)(Encoder *encoder, Channel *channel,
@@ -359,35 +364,36 @@ static void FNAME(uncompress_row0)(Encoder *encoder, Channel *channel,
unsigned int width)
{
+ CommonState *state = &channel->state;
const unsigned int bpc = BPC;
const unsigned int bpc_mask = BPC_MASK;
BYTE * const correlate_row = channel->correlate_row;
unsigned int pos = 0;
- while ((DEFwmimax > (int)channel->state.wmidx) && (channel->state.wmileft <= width)) {
- if (channel->state.wmileft) {
+ while ((DEFwmimax > (int)state->wmidx) && (state->wmileft <= width)) {
+ if (state->wmileft) {
FNAME(uncompress_row0_seg)(encoder, channel, pos, correlate_row, cur_row,
- pos + channel->state.wmileft, bppmask[channel->state.wmidx],
+ pos + state->wmileft, bppmask[state->wmidx],
bpc, bpc_mask);
- pos += channel->state.wmileft;
- width -= channel->state.wmileft;
+ pos += state->wmileft;
+ width -= state->wmileft;
}
- channel->state.wmidx++;
- set_wm_trigger(&channel->state);
- channel->state.wmileft = DEFwminext;
+ state->wmidx++;
+ set_wm_trigger(state);
+ state->wmileft = DEFwminext;
}
if (width) {
FNAME(uncompress_row0_seg)(encoder, channel, pos, correlate_row, cur_row, pos + width,
- bppmask[channel->state.wmidx], bpc, bpc_mask);
- if (DEFwmimax > (int)channel->state.wmidx) {
- channel->state.wmileft -= width;
+ bppmask[state->wmidx], bpc, bpc_mask);
+ if (DEFwmimax > (int)state->wmidx) {
+ state->wmileft -= width;
}
}
- spice_assert((int)channel->state.wmidx <= DEFwmimax);
- spice_assert(channel->state.wmidx <= 32);
+ spice_assert((int)state->wmidx <= DEFwmimax);
+ spice_assert(state->wmidx <= 32);
spice_assert(DEFwminext > 0);
}
@@ -400,7 +406,8 @@ static void FNAME(uncompress_row_seg)(Encoder *encoder, Channel *channel,
SPICE_GNUC_UNUSED const unsigned int bpc,
const unsigned int bpc_mask)
{
- const unsigned int waitmask = bppmask[channel->state.wmidx];
+ CommonState *state = &channel->state;
+ const unsigned int waitmask = bppmask[state->wmidx];
int stopidx;
int run_index = 0;
int run_end;
@@ -415,16 +422,16 @@ static void FNAME(uncompress_row_seg)(Encoder *encoder, Channel *channel,
cur_row[0].a = (family.xlatL2U[correlate_row[0]] + prev_row[0].a) & bpc_mask;
decode_eatbits(encoder, codewordlen);
- if (channel->state.waitcnt) {
- --channel->state.waitcnt;
+ if (state->waitcnt) {
+ --state->waitcnt;
} else {
- channel->state.waitcnt = (tabrand(&channel->state.tabrand_seed) & waitmask);
- update_model(&channel->state, find_bucket(channel, correlate_row[-1]),
+ state->waitcnt = (tabrand(&state->tabrand_seed) & waitmask);
+ update_model(state, find_bucket(channel, correlate_row[-1]),
correlate_row[0]);
}
- stopidx = ++i + channel->state.waitcnt;
+ stopidx = ++i + state->waitcnt;
} else {
- stopidx = i + channel->state.waitcnt;
+ stopidx = i + state->waitcnt;
}
for (;;) {
while (stopidx < end) {
@@ -440,9 +447,9 @@ static void FNAME(uncompress_row_seg)(Encoder *encoder, Channel *channel,
decode_eatbits(encoder, codewordlen);
}
- update_model(&channel->state, pbucket, correlate_row[stopidx]);
+ update_model(state, pbucket, correlate_row[stopidx]);
- stopidx = i + (tabrand(&channel->state.tabrand_seed) & waitmask);
+ stopidx = i + (tabrand(&state->tabrand_seed) & waitmask);
}
for (; i < end; i++) {
@@ -455,12 +462,12 @@ static void FNAME(uncompress_row_seg)(Encoder *encoder, Channel *channel,
decode_eatbits(encoder, codewordlen);
}
- channel->state.waitcnt = stopidx - end;
+ state->waitcnt = stopidx - end;
return;
do_run:
- channel->state.waitcnt = stopidx - i;
+ state->waitcnt = stopidx - i;
run_index = i;
run_end = i + decode_channel_run(encoder, channel);
@@ -472,7 +479,7 @@ do_run:
return;
}
- stopidx = i + channel->state.waitcnt;
+ stopidx = i + state->waitcnt;
}
}
@@ -482,34 +489,35 @@ static void FNAME(uncompress_row)(Encoder *encoder, Channel *channel,
unsigned int width)
{
+ CommonState *state = &channel->state;
const unsigned int bpc = BPC;
const unsigned int bpc_mask = BPC_MASK;
BYTE * const correlate_row = channel->correlate_row;
unsigned int pos = 0;
- while ((DEFwmimax > (int)channel->state.wmidx) && (channel->state.wmileft <= width)) {
- if (channel->state.wmileft) {
+ while ((DEFwmimax > (int)state->wmidx) && (state->wmileft <= width)) {
+ if (state->wmileft) {
FNAME(uncompress_row_seg)(encoder, channel, correlate_row, prev_row, cur_row, pos,
- pos + channel->state.wmileft, bpc, bpc_mask);
- pos += channel->state.wmileft;
- width -= channel->state.wmileft;
+ pos + state->wmileft, bpc, bpc_mask);
+ pos += state->wmileft;
+ width -= state->wmileft;
}
- channel->state.wmidx++;
- set_wm_trigger(&channel->state);
- channel->state.wmileft = DEFwminext;
+ state->wmidx++;
+ set_wm_trigger(state);
+ state->wmileft = DEFwminext;
}
if (width) {
FNAME(uncompress_row_seg)(encoder, channel, correlate_row, prev_row, cur_row, pos,
pos + width, bpc, bpc_mask);
- if (DEFwmimax > (int)channel->state.wmidx) {
- channel->state.wmileft -= width;
+ if (DEFwmimax > (int)state->wmidx) {
+ state->wmileft -= width;
}
}
- spice_assert((int)channel->state.wmidx <= DEFwmimax);
- spice_assert(channel->state.wmidx <= 32);
+ spice_assert((int)state->wmidx <= DEFwmimax);
+ spice_assert(state->wmidx <= 32);
spice_assert(DEFwminext > 0);
}
--
2.13.3
More information about the Spice-devel
mailing list