25 #define BITSTREAM_READER_LE
42 if (src_size < avctx->
width * avctx->
height * (int64_t)bpp) {
52 for (h = 0; h < avctx->
height; h++) {
53 memcpy(dst, src, avctx->
width * bpp);
54 src += avctx->
width * bpp;
68 if (src_size < avctx->
width * avctx->
height * 9LL / 8) {
83 for (h = 0; h < avctx->
height; h += 4) {
84 for (w = 0; w < avctx->
width; w += 4) {
89 U[w >> 2] = src[16] + 0x80;
90 V[w >> 2] = src[17] + 0x80;
111 if (src_size < avctx->
width * avctx->
height * 3LL / 2) {
124 for (h = 0; h < avctx->
height; h += 2) {
125 for (w = 0; w < avctx->
width; w += 2) {
128 U[w >> 1] = src[4] + 0x80;
129 V[w >> 1] = src[5] + 0x80;
148 if (src_size < avctx->
width * avctx->
height * 3LL) {
160 for (h = 0; h < avctx->
height; h++) {
161 for (w = 0; w < avctx->
width; w++) {
163 U[w] = *src++ ^ 0x80;
164 V[w] = *src++ ^ 0x80;
174 static const uint8_t def_lru[8] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xA0, 0xC0, 0xFF };
185 memmove(lru + 1, lru,
sizeof(*lru) * (8 - 1));
188 memmove(lru + 1, lru,
sizeof(*lru) * (c - 1));
203 memmove(lru + 1, lru,
sizeof(*lru) * (6 - 1));
206 memmove(lru + 1, lru,
sizeof(*lru) * (c - 1));
222 memcpy(lru[2], def_lru_555, 8 *
sizeof(*
def_lru));
224 for (y = 0; y <
height; y++) {
225 for (x = 0; x <
width; x++) {
229 dst[x * 3 + 0] = (r << 3) | (r >> 2);
230 dst[x * 3 + 1] = is_565 ? (g << 2) | (g >> 4) : (g << 3) | (g >> 2);
231 dst[x * 3 + 2] = (b << 3) | (b >> 2);
245 int nslices, slice, slice_height;
246 uint32_t off, slice_size;
251 nslices = bytestream2_get_le16(&gb);
252 off =
FFALIGN(nslices * 4 + 2, 16);
253 if (src_size < off) {
258 if (!nslices || avctx->
height % nslices) {
264 slice_height = avctx->
height / nslices;
270 for (slice = 0; slice < nslices; slice++) {
271 slice_size = bytestream2_get_le32(&gb);
272 if (slice_size > src_size - off) {
274 "invalid slice size %"PRIu32
" (only %"PRIu32
" bytes left)\n",
275 slice_size, src_size - off);
278 if (slice_size <= 16) {
283 if (
AV_RL32(src + off) != slice_size - 16) {
285 "Slice sizes mismatch: got %"PRIu32
" instead of %"PRIu32
"\n",
286 AV_RL32(src + off), slice_size - 16);
288 if ((ret =
init_get_bits8(&gb2, src + off + 16, slice_size - 16)) < 0)
293 dst += pic->
linesize[0] * slice_height;
306 for (i = 0; i < 3; i++)
309 for (y = 0; y <
height; y++) {
310 for (x = 0; x <
width; x++) {
327 int nslices, slice, slice_height;
328 uint32_t off, slice_size;
333 nslices = bytestream2_get_le16(&gb);
334 off =
FFALIGN(nslices * 4 + 2, 16);
335 if (src_size < off) {
340 if (!nslices || avctx->
height % nslices) {
346 slice_height = avctx->
height / nslices;
352 for (slice = 0; slice < nslices; slice++) {
353 slice_size = bytestream2_get_le32(&gb);
354 if (slice_size > src_size - off) {
356 "invalid slice size %"PRIu32
" (only %"PRIu32
" bytes left)\n",
357 slice_size, src_size - off);
360 if (slice_size <= 16) {
366 if (
AV_RL32(src + off) != slice_size - 16) {
368 "Slice sizes mismatch: got %"PRIu32
" instead of %"PRIu32
"\n",
369 AV_RL32(src + off), slice_size - 16);
371 if ((ret =
init_get_bits8(&gb2, src + off + 16, slice_size - 16)) < 0)
376 dst += pic->
linesize[0] * slice_height;
385 int ystride,
int ustride,
int vstride)
390 for (i = 0; i < 3; i++)
393 for (y = 0; y <
height; y += 4) {
394 for (x = 0; x <
width; x += 4) {
395 for (j = 0; j < 4; j++)
396 for (i = 0; i < 4; i++)
397 Y[x + i + j * ystride] =
decode_sym(gb, lru[0]);
415 int nslices, slice, slice_height;
417 uint32_t off, slice_size;
422 nslices = bytestream2_get_le16(&gb);
423 off =
FFALIGN(nslices * 4 + 2, 16);
424 if (src_size < off) {
449 for (slice = 0; slice < nslices; slice++) {
450 slice_size = bytestream2_get_le32(&gb);
451 next_y = ((slice + 1) * avctx->
height) / nslices;
452 slice_height = (next_y & ~3) - (cur_y & ~3);
453 if (slice_size > src_size - off) {
455 "invalid slice size %"PRIu32
" (only %"PRIu32
" bytes left)\n",
456 slice_size, src_size - off);
459 if (slice_size <= 16) {
464 if (
AV_RL32(src + off) != slice_size - 16) {
466 "Slice sizes mismatch: got %"PRIu32
" instead of %"PRIu32
"\n",
467 AV_RL32(src + off), slice_size - 16);
469 if ((ret =
init_get_bits8(&gb2, src + off + 16, slice_size - 16)) < 0)
475 Y += pic->
linesize[0] * slice_height;
476 U += pic->
linesize[1] * (slice_height >> 2);
477 V += pic->
linesize[2] * (slice_height >> 2);
487 int ystride,
int ustride,
int vstride)
492 for (i = 0; i < 3; i++)
495 for (y = 0; y <
height; y+=2) {
496 for (x = 0; x <
width; x += 2) {
497 Y[x + 0 + 0 * ystride] =
decode_sym(gb, lru[0]);
498 Y[x + 1 + 0 * ystride] =
decode_sym(gb, lru[0]);
499 Y[x + 0 + 1 * ystride] =
decode_sym(gb, lru[0]);
500 Y[x + 1 + 1 * ystride] =
decode_sym(gb, lru[0]);
518 int nslices, slice, slice_height;
520 uint32_t off, slice_size;
525 nslices = bytestream2_get_le16(&gb);
526 off =
FFALIGN(nslices * 4 + 2, 16);
527 if (src_size < off) {
552 for (slice = 0; slice < nslices; slice++) {
553 slice_size = bytestream2_get_le32(&gb);
554 next_y = ((slice + 1) * avctx->
height) / nslices;
555 slice_height = (next_y & ~1) - (cur_y & ~1);
556 if (slice_size > src_size - off) {
558 "invalid slice size %"PRIu32
" (only %"PRIu32
" bytes left)\n",
559 slice_size, src_size - off);
562 if (slice_size <= 16) {
567 if (
AV_RL32(src + off) != slice_size - 16) {
569 "Slice sizes mismatch: got %"PRIu32
" instead of %"PRIu32
"\n",
570 AV_RL32(src + off), slice_size - 16);
572 if ((ret =
init_get_bits8(&gb2, src + off + 16, slice_size - 16)) < 0)
578 Y += pic->
linesize[0] * slice_height;
579 U += pic->
linesize[1] * (slice_height >> 1);
580 V += pic->
linesize[2] * (slice_height >> 1);
590 int ystride,
int ustride,
int vstride)
595 for (i = 0; i < 3; i++)
598 for (y = 0; y <
height; y++) {
599 for (x = 0; x <
width; x++) {
618 int nslices, slice, slice_height;
619 uint32_t off, slice_size;
624 nslices = bytestream2_get_le16(&gb);
625 off =
FFALIGN(nslices * 4 + 2, 16);
626 if (src_size < off) {
631 if (!nslices || avctx->
height % nslices) {
637 slice_height = avctx->
height / nslices;
647 for (slice = 0; slice < nslices; slice++) {
648 slice_size = bytestream2_get_le32(&gb);
649 if (slice_size > src_size - off) {
651 "invalid slice size %"PRIu32
" (only %"PRIu32
" bytes left)\n",
652 slice_size, src_size - off);
655 if (slice_size <= 16) {
660 if (
AV_RL32(src + off) != slice_size - 16) {
662 "Slice sizes mismatch: got %"PRIu32
" instead of %"PRIu32
"\n",
663 AV_RL32(src + off), slice_size - 16);
665 if ((ret =
init_get_bits8(&gb2, src + off + 16, slice_size - 16)) < 0)
671 Y += pic->
linesize[0] * slice_height;
672 U += pic->
linesize[1] * slice_height;
673 V += pic->
linesize[2] * slice_height;
687 if (avpkt->
size < 16) {