|
|
@ -488,15 +488,31 @@ static int encode_422_bitstream(HYuvContext *s, int offset, int count) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static int encode_plane_bitstream(HYuvContext *s, int count, int plane) |
|
|
|
static int encode_plane_bitstream(HYuvContext *s, int width, int plane) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int i; |
|
|
|
int i, count = width/2; |
|
|
|
|
|
|
|
|
|
|
|
if (s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb) >> 3) < count * s->bps / 2) { |
|
|
|
if (s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb) >> 3) < count * s->bps / 2) { |
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); |
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define LOADEND\ |
|
|
|
|
|
|
|
int y0 = s->temp[0][width-1]; |
|
|
|
|
|
|
|
#define LOADEND_14\ |
|
|
|
|
|
|
|
int y0 = s->temp16[0][width-1] & mask; |
|
|
|
|
|
|
|
#define LOADEND_16\ |
|
|
|
|
|
|
|
int y0 = s->temp16[0][width-1]; |
|
|
|
|
|
|
|
#define STATEND\ |
|
|
|
|
|
|
|
s->stats[plane][y0]++; |
|
|
|
|
|
|
|
#define STATEND_16\ |
|
|
|
|
|
|
|
s->stats[plane][y0>>2]++; |
|
|
|
|
|
|
|
#define WRITEEND\ |
|
|
|
|
|
|
|
put_bits(&s->pb, s->len[plane][y0], s->bits[plane][y0]); |
|
|
|
|
|
|
|
#define WRITEEND_16\ |
|
|
|
|
|
|
|
put_bits(&s->pb, s->len[plane][y0>>2], s->bits[plane][y0>>2]);\
|
|
|
|
|
|
|
|
put_bits(&s->pb, 2, y0&3); |
|
|
|
|
|
|
|
|
|
|
|
#define LOAD2\ |
|
|
|
#define LOAD2\ |
|
|
|
int y0 = s->temp[0][2 * i];\
|
|
|
|
int y0 = s->temp[0][2 * i];\
|
|
|
|
int y1 = s->temp[0][2 * i + 1]; |
|
|
|
int y1 = s->temp[0][2 * i + 1]; |
|
|
@ -521,14 +537,16 @@ static int encode_plane_bitstream(HYuvContext *s, int count, int plane) |
|
|
|
put_bits(&s->pb, s->len[plane][y1>>2], s->bits[plane][y1>>2]);\
|
|
|
|
put_bits(&s->pb, s->len[plane][y1>>2], s->bits[plane][y1>>2]);\
|
|
|
|
put_bits(&s->pb, 2, y1&3); |
|
|
|
put_bits(&s->pb, 2, y1&3); |
|
|
|
|
|
|
|
|
|
|
|
count /= 2; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (s->bps <= 8) { |
|
|
|
if (s->bps <= 8) { |
|
|
|
if (s->flags & CODEC_FLAG_PASS1) { |
|
|
|
if (s->flags & CODEC_FLAG_PASS1) { |
|
|
|
for (i = 0; i < count; i++) { |
|
|
|
for (i = 0; i < count; i++) { |
|
|
|
LOAD2; |
|
|
|
LOAD2; |
|
|
|
STAT2; |
|
|
|
STAT2; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (width&1) { |
|
|
|
|
|
|
|
LOADEND; |
|
|
|
|
|
|
|
STATEND; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (s->avctx->flags2 & CODEC_FLAG2_NO_OUTPUT) |
|
|
|
if (s->avctx->flags2 & CODEC_FLAG2_NO_OUTPUT) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
@ -539,11 +557,20 @@ static int encode_plane_bitstream(HYuvContext *s, int count, int plane) |
|
|
|
STAT2; |
|
|
|
STAT2; |
|
|
|
WRITE2; |
|
|
|
WRITE2; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (width&1) { |
|
|
|
|
|
|
|
LOADEND; |
|
|
|
|
|
|
|
STATEND; |
|
|
|
|
|
|
|
WRITEEND; |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
for (i = 0; i < count; i++) { |
|
|
|
for (i = 0; i < count; i++) { |
|
|
|
LOAD2; |
|
|
|
LOAD2; |
|
|
|
WRITE2; |
|
|
|
WRITE2; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (width&1) { |
|
|
|
|
|
|
|
LOADEND; |
|
|
|
|
|
|
|
WRITEEND; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (s->bps <= 14) { |
|
|
|
} else if (s->bps <= 14) { |
|
|
|
int mask = s->n - 1; |
|
|
|
int mask = s->n - 1; |
|
|
@ -552,6 +579,10 @@ static int encode_plane_bitstream(HYuvContext *s, int count, int plane) |
|
|
|
LOAD2_14; |
|
|
|
LOAD2_14; |
|
|
|
STAT2; |
|
|
|
STAT2; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (width&1) { |
|
|
|
|
|
|
|
LOADEND_14; |
|
|
|
|
|
|
|
STATEND; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (s->avctx->flags2 & CODEC_FLAG2_NO_OUTPUT) |
|
|
|
if (s->avctx->flags2 & CODEC_FLAG2_NO_OUTPUT) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
@ -562,11 +593,20 @@ static int encode_plane_bitstream(HYuvContext *s, int count, int plane) |
|
|
|
STAT2; |
|
|
|
STAT2; |
|
|
|
WRITE2; |
|
|
|
WRITE2; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (width&1) { |
|
|
|
|
|
|
|
LOADEND_14; |
|
|
|
|
|
|
|
STATEND; |
|
|
|
|
|
|
|
WRITEEND; |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
for (i = 0; i < count; i++) { |
|
|
|
for (i = 0; i < count; i++) { |
|
|
|
LOAD2_14; |
|
|
|
LOAD2_14; |
|
|
|
WRITE2; |
|
|
|
WRITE2; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (width&1) { |
|
|
|
|
|
|
|
LOADEND_14; |
|
|
|
|
|
|
|
WRITEEND; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (s->flags & CODEC_FLAG_PASS1) { |
|
|
|
if (s->flags & CODEC_FLAG_PASS1) { |
|
|
@ -574,6 +614,10 @@ static int encode_plane_bitstream(HYuvContext *s, int count, int plane) |
|
|
|
LOAD2_16; |
|
|
|
LOAD2_16; |
|
|
|
STAT2_16; |
|
|
|
STAT2_16; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (width&1) { |
|
|
|
|
|
|
|
LOADEND_16; |
|
|
|
|
|
|
|
STATEND_16; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (s->avctx->flags2 & CODEC_FLAG2_NO_OUTPUT) |
|
|
|
if (s->avctx->flags2 & CODEC_FLAG2_NO_OUTPUT) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
@ -584,11 +628,20 @@ static int encode_plane_bitstream(HYuvContext *s, int count, int plane) |
|
|
|
STAT2_16; |
|
|
|
STAT2_16; |
|
|
|
WRITE2_16; |
|
|
|
WRITE2_16; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (width&1) { |
|
|
|
|
|
|
|
LOADEND_16; |
|
|
|
|
|
|
|
STATEND_16; |
|
|
|
|
|
|
|
WRITEEND_16; |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
for (i = 0; i < count; i++) { |
|
|
|
for (i = 0; i < count; i++) { |
|
|
|
LOAD2_16; |
|
|
|
LOAD2_16; |
|
|
|
WRITE2_16; |
|
|
|
WRITE2_16; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (width&1) { |
|
|
|
|
|
|
|
LOADEND_16; |
|
|
|
|
|
|
|
WRITEEND_16; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
#undef LOAD2 |
|
|
|
#undef LOAD2 |
|
|
|