[FFmpeg-devel] [PATCH] avcodec/speedhq: fix decoding 422 subsampling when width is not multiple of 16
Paul B Mahol
onemda at gmail.com
Mon Mar 1 16:41:22 EET 2021
Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
libavcodec/speedhq.c | 42 ++++++++++++++++++++++++++++++++++++++++--
1 file changed, 40 insertions(+), 2 deletions(-)
diff --git a/libavcodec/speedhq.c b/libavcodec/speedhq.c
index 759fc6dfc5..2a2fc42efa 100644
--- a/libavcodec/speedhq.c
+++ b/libavcodec/speedhq.c
@@ -283,6 +283,7 @@ static int decode_speedhq_field(const SHQContext *s, const uint8_t *buf, int buf
int linesize_cb = frame->linesize[1] * line_stride;
int linesize_cr = frame->linesize[2] * line_stride;
int linesize_a;
+ GetBitContext gb;
if (s->alpha_type != SHQ_NO_ALPHA)
linesize_a = frame->linesize[3] * line_stride;
@@ -304,7 +305,6 @@ static int decode_speedhq_field(const SHQContext *s, const uint8_t *buf, int buf
}
for (slice_number = 0; slice_number < 4; slice_number++) {
- GetBitContext gb;
uint32_t slice_begin, slice_end;
int x, y;
@@ -333,7 +333,7 @@ static int decode_speedhq_field(const SHQContext *s, const uint8_t *buf, int buf
dest_a = frame->data[3] + frame->linesize[3] * (y + field_number);
}
- for (x = 0; x < frame->width; x += 16) {
+ for (x = 0; x < frame->width - 8 * (s->subsampling != SHQ_SUBSAMPLING_444); x += 16) {
/* Decode the four luma blocks. */
if ((ret = decode_dct_block(s, &gb, last_dc, 0, dest_y, linesize_y)) < 0)
return ret;
@@ -402,6 +402,44 @@ static int decode_speedhq_field(const SHQContext *s, const uint8_t *buf, int buf
}
}
+ if (s->subsampling == SHQ_SUBSAMPLING_444)
+ return 0;
+
+ if (!(frame->width & 15))
+ return 0;
+
+ for (int y = 0; y < frame->height; y += 16 * line_stride) {
+ int last_dc[4] = { 1024, 1024, 1024, 1024 };
+ uint8_t *dest_y, *dest_cb, *dest_cr;
+ int x = frame->width - 8;
+
+ dest_y = frame->data[0] + frame->linesize[0] * (y + field_number) + x;
+ if (s->subsampling == SHQ_SUBSAMPLING_420) {
+ dest_cb = frame->data[1] + frame->linesize[1] * (y/2 + field_number) + x / 2;
+ dest_cr = frame->data[2] + frame->linesize[2] * (y/2 + field_number) + x / 2;
+ } else if (s->subsampling == SHQ_SUBSAMPLING_422) {
+ dest_cb = frame->data[1] + frame->linesize[1] * (y + field_number) + x / 2;
+ dest_cr = frame->data[2] + frame->linesize[2] * (y + field_number) + x / 2;
+ }
+
+ if ((ret = decode_dct_block(s, &gb, last_dc, 0, dest_y, linesize_y)) < 0)
+ return ret;
+ if ((ret = decode_dct_block(s, &gb, last_dc, 0, dest_y + 8, linesize_y)) < 0)
+ return ret;
+ if ((ret = decode_dct_block(s, &gb, last_dc, 0, dest_y + 8 * linesize_y, linesize_y)) < 0)
+ return ret;
+ if ((ret = decode_dct_block(s, &gb, last_dc, 0, dest_y + 8 * linesize_y + 8, linesize_y)) < 0)
+ return ret;
+ if ((ret = decode_dct_block(s, &gb, last_dc, 1, dest_cb, linesize_cb)) < 0)
+ return ret;
+ if ((ret = decode_dct_block(s, &gb, last_dc, 2, dest_cr, linesize_cr)) < 0)
+ return ret;
+ if ((ret = decode_dct_block(s, &gb, last_dc, 1, dest_cb + 8 * linesize_cb, linesize_cb)) < 0)
+ return ret;
+ if ((ret = decode_dct_block(s, &gb, last_dc, 2, dest_cr + 8 * linesize_cr, linesize_cr)) < 0)
+ return ret;
+ }
+
return 0;
}
--
2.17.1
More information about the ffmpeg-devel
mailing list