Commit c4276a7f authored by Michael Niedermayer's avatar Michael Niedermayer

avcodec/scpr: Avoid per pixel y checks in decode_run_i

about 1% faster
Signed-off-by: 's avatarMichael Niedermayer <michael@niedermayer.cc>
parent 20564d23
...@@ -89,12 +89,12 @@ static int decode_run_i(AVCodecContext *avctx, uint32_t ptype, int run, ...@@ -89,12 +89,12 @@ static int decode_run_i(AVCodecContext *avctx, uint32_t ptype, int run,
uint32_t lx = *plx, uint32_t lx = *plx,
ly = *ply; ly = *ply;
if (y >= avctx->height)
return AVERROR_INVALIDDATA;
switch (ptype) { switch (ptype) {
case 0: case 0:
while (run-- > 0) { while (run-- > 0) {
if (y >= avctx->height)
return AVERROR_INVALIDDATA;
dst[y * linesize + x] = clr; dst[y * linesize + x] = clr;
lx = x; lx = x;
ly = y; ly = y;
...@@ -102,14 +102,13 @@ static int decode_run_i(AVCodecContext *avctx, uint32_t ptype, int run, ...@@ -102,14 +102,13 @@ static int decode_run_i(AVCodecContext *avctx, uint32_t ptype, int run,
if (x >= avctx->width) { if (x >= avctx->width) {
x = 0; x = 0;
(y)++; (y)++;
if (y >= avctx->height && run)
return AVERROR_INVALIDDATA;
} }
} }
break; break;
case 1: case 1:
while (run-- > 0) { while (run-- > 0) {
if (y >= avctx->height)
return AVERROR_INVALIDDATA;
dst[y * linesize + x] = dst[ly * linesize + lx]; dst[y * linesize + x] = dst[ly * linesize + lx];
lx = x; lx = x;
ly = y; ly = y;
...@@ -117,15 +116,17 @@ static int decode_run_i(AVCodecContext *avctx, uint32_t ptype, int run, ...@@ -117,15 +116,17 @@ static int decode_run_i(AVCodecContext *avctx, uint32_t ptype, int run,
if (x >= avctx->width) { if (x >= avctx->width) {
x = 0; x = 0;
(y)++; (y)++;
if (y >= avctx->height && run)
return AVERROR_INVALIDDATA;
} }
} }
clr = dst[ly * linesize + lx]; clr = dst[ly * linesize + lx];
break; break;
case 2: case 2:
while (run-- > 0) { if (y < 1)
if (y < 1 || y >= avctx->height) return AVERROR_INVALIDDATA;
return AVERROR_INVALIDDATA;
while (run-- > 0) {
clr = dst[y * linesize + x + off + 1]; clr = dst[y * linesize + x + off + 1];
dst[y * linesize + x] = clr; dst[y * linesize + x] = clr;
lx = x; lx = x;
...@@ -134,19 +135,20 @@ static int decode_run_i(AVCodecContext *avctx, uint32_t ptype, int run, ...@@ -134,19 +135,20 @@ static int decode_run_i(AVCodecContext *avctx, uint32_t ptype, int run,
if (x >= avctx->width) { if (x >= avctx->width) {
x = 0; x = 0;
(y)++; (y)++;
if (y >= avctx->height && run)
return AVERROR_INVALIDDATA;
} }
} }
break; break;
case 4: case 4:
if (y < 1 || (y == 1 && x == 0))
return AVERROR_INVALIDDATA;
while (run-- > 0) { while (run-- > 0) {
uint8_t *odst = (uint8_t *)dst; uint8_t *odst = (uint8_t *)dst;
int off1 = (ly * linesize + lx) * 4; int off1 = (ly * linesize + lx) * 4;
int off2 = ((y * linesize + x) + off) * 4; int off2 = ((y * linesize + x) + off) * 4;
if (y < 1 || y >= avctx->height ||
(y == 1 && x == 0))
return AVERROR_INVALIDDATA;
if (x == 0) { if (x == 0) {
z = backstep * 4; z = backstep * 4;
} else { } else {
...@@ -170,15 +172,16 @@ static int decode_run_i(AVCodecContext *avctx, uint32_t ptype, int run, ...@@ -170,15 +172,16 @@ static int decode_run_i(AVCodecContext *avctx, uint32_t ptype, int run,
if (x >= avctx->width) { if (x >= avctx->width) {
x = 0; x = 0;
(y)++; (y)++;
if (y >= avctx->height && run)
return AVERROR_INVALIDDATA;
} }
} }
break; break;
case 5: case 5:
while (run-- > 0) { if (y < 1 || (y == 1 && x == 0))
if (y < 1 || y >= avctx->height || return AVERROR_INVALIDDATA;
(y == 1 && x == 0))
return AVERROR_INVALIDDATA;
while (run-- > 0) {
if (x == 0) { if (x == 0) {
z = backstep; z = backstep;
} else { } else {
...@@ -193,6 +196,8 @@ static int decode_run_i(AVCodecContext *avctx, uint32_t ptype, int run, ...@@ -193,6 +196,8 @@ static int decode_run_i(AVCodecContext *avctx, uint32_t ptype, int run,
if (x >= avctx->width) { if (x >= avctx->width) {
x = 0; x = 0;
(y)++; (y)++;
if (y >= avctx->height && run)
return AVERROR_INVALIDDATA;
} }
} }
break; break;
......
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