Commit ce8807c2 authored by Paul B Mahol's avatar Paul B Mahol

avcodec/scpr: refactor repeated code into decode_units()

parent aeb73c73
...@@ -297,14 +297,41 @@ static int decode_unit(SCPRContext *s, PixelModel *pixel, unsigned step, unsigne ...@@ -297,14 +297,41 @@ static int decode_unit(SCPRContext *s, PixelModel *pixel, unsigned step, unsigne
return 0; return 0;
} }
static int decode_units(SCPRContext *s, unsigned *r, unsigned *g, unsigned *b,
int *cx, int *cx1)
{
const int cxshift = s->cxshift;
int ret;
ret = decode_unit(s, &s->pixel_model[0][*cx + *cx1], 400, r);
if (ret < 0)
return ret;
*cx1 = (*cx << 6) & 0xFC0;
*cx = *r >> cxshift;
ret = decode_unit(s, &s->pixel_model[1][*cx + *cx1], 400, g);
if (ret < 0)
return ret;
*cx1 = (*cx << 6) & 0xFC0;
*cx = *g >> cxshift;
ret = decode_unit(s, &s->pixel_model[2][*cx + *cx1], 400, b);
if (ret < 0)
return ret;
*cx1 = (*cx << 6) & 0xFC0;
*cx = *b >> cxshift;
return 0;
}
static int decompress_i(AVCodecContext *avctx, uint32_t *dst, int linesize) static int decompress_i(AVCodecContext *avctx, uint32_t *dst, int linesize)
{ {
SCPRContext *s = avctx->priv_data; SCPRContext *s = avctx->priv_data;
GetByteContext *gb = &s->gb; GetByteContext *gb = &s->gb;
int cx = 0, cx1 = 0, k = 0, clr = 0; int cx = 0, cx1 = 0, k = 0, clr = 0;
int run, r, g, b, off, y = 0, x = 0, z, ret; int run, off, y = 0, x = 0, z, ret;
unsigned backstep = linesize - avctx->width; unsigned r, g, b, backstep = linesize - avctx->width;
const int cxshift = s->cxshift;
unsigned lx, ly, ptype; unsigned lx, ly, ptype;
reinit_tables(s); reinit_tables(s);
...@@ -312,25 +339,10 @@ static int decompress_i(AVCodecContext *avctx, uint32_t *dst, int linesize) ...@@ -312,25 +339,10 @@ static int decompress_i(AVCodecContext *avctx, uint32_t *dst, int linesize)
init_rangecoder(&s->rc, gb); init_rangecoder(&s->rc, gb);
while (k < avctx->width + 1) { while (k < avctx->width + 1) {
ret = decode_unit(s, &s->pixel_model[0][cx + cx1], 400, &r); ret = decode_units(s, &r, &g, &b, &cx, &cx1);
if (ret < 0) if (ret < 0)
return ret; return ret;
cx1 = (cx << 6) & 0xFC0;
cx = r >> cxshift;
ret = decode_unit(s, &s->pixel_model[1][cx + cx1], 400, &g);
if (ret < 0)
return ret;
cx1 = (cx << 6) & 0xFC0;
cx = g >> cxshift;
ret = decode_unit(s, &s->pixel_model[2][cx + cx1], 400, &b);
if (ret < 0)
return ret;
cx1 = (cx << 6) & 0xFC0;
cx = b >> cxshift;
ret = decode_value(s, s->run_model[0], 256, 400, &run); ret = decode_value(s, s->run_model[0], 256, 400, &run);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -361,19 +373,7 @@ static int decompress_i(AVCodecContext *avctx, uint32_t *dst, int linesize) ...@@ -361,19 +373,7 @@ static int decompress_i(AVCodecContext *avctx, uint32_t *dst, int linesize)
if (ret < 0) if (ret < 0)
return ret; return ret;
if (ptype == 0) { if (ptype == 0) {
ret = decode_unit(s, &s->pixel_model[0][cx + cx1], 400, &r); ret = decode_units(s, &r, &g, &b, &cx, &cx1);
if (ret < 0)
return ret;
cx1 = (cx << 6) & 0xFC0;
cx = r >> cxshift;
ret = decode_unit(s, &s->pixel_model[1][cx + cx1], 400, &g);
if (ret < 0)
return ret;
cx1 = (cx << 6) & 0xFC0;
cx = g >> cxshift;
ret = decode_unit(s, &s->pixel_model[2][cx + cx1], 400, &b);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -514,7 +514,6 @@ static int decompress_p(AVCodecContext *avctx, ...@@ -514,7 +514,6 @@ static int decompress_p(AVCodecContext *avctx,
GetByteContext *gb = &s->gb; GetByteContext *gb = &s->gb;
int ret, temp, min, max, x, y, cx = 0, cx1 = 0; int ret, temp, min, max, x, y, cx = 0, cx1 = 0;
int backstep = linesize - avctx->width; int backstep = linesize - avctx->width;
const int cxshift = s->cxshift;
if (bytestream2_get_byte(gb) == 0) if (bytestream2_get_byte(gb) == 0)
return 0; return 0;
...@@ -588,27 +587,15 @@ static int decompress_p(AVCodecContext *avctx, ...@@ -588,27 +587,15 @@ static int decompress_p(AVCodecContext *avctx,
} }
} }
} else { } else {
int run, r, g, b, z, bx = x * 16 + sx1, by = y * 16 + sy1; int run, z, bx = x * 16 + sx1, by = y * 16 + sy1;
unsigned clr, ptype = 0; unsigned r, g, b, clr, ptype = 0;
for (; by < y * 16 + sy2 && by < avctx->height;) { for (; by < y * 16 + sy2 && by < avctx->height;) {
ret = decode_value(s, s->op_model[ptype], 6, 1000, &ptype); ret = decode_value(s, s->op_model[ptype], 6, 1000, &ptype);
if (ret < 0) if (ret < 0)
return ret; return ret;
if (ptype == 0) { if (ptype == 0) {
ret = decode_unit(s, &s->pixel_model[0][cx + cx1], 400, &r); ret = decode_units(s, &r, &g, &b, &cx, &cx1);
if (ret < 0)
return ret;
cx1 = (cx << 6) & 0xFC0;
cx = r >> cxshift;
ret = decode_unit(s, &s->pixel_model[1][cx + cx1], 400, &g);
if (ret < 0)
return ret;
cx1 = (cx << 6) & 0xFC0;
cx = g >> cxshift;
ret = decode_unit(s, &s->pixel_model[2][cx + cx1], 400, &b);
if (ret < 0) if (ret < 0)
return ret; return ret;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment