Realtime decoding speed raises from 1.08 to 1.84 for 1504x846, 25391 kb/s, 24 fps video.
Unified · Split
| @@ -58,6 +58,7 @@ typedef struct PixletContext { · 57 unmodified lines | |||
| 58 | int16_t *filter[2]; | 58 | int16_t *filter[2]; |
| 59 | int16_t *prediction; | 59 | int16_t *prediction; |
| 60 | int64_t scaling[4][2][NB_LEVELS]; | 60 | int64_t scaling[4][2][NB_LEVELS]; |
| 61 | uint16_t lut[65536]; | ||
| 61 | SubBand band[4][NB_LEVELS * 3 + 1]; | 62 | SubBand band[4][NB_LEVELS * 3 + 1]; |
| 62 | } PixletContext; | 63 | } PixletContext; |
| 63 | 64 | ||
| @@ -462,11 +463,27 @@ static void reconstruction(AVCodecContext *avctx, int16_t *dest, · 398 unmodified lines | |||
| 462 | } | 463 | } |
| 463 | } | 464 | } |
| 464 | 465 | ||
| 465 | static void postprocess_luma(AVFrame *frame, int w, int h, int depth) | 466 | static void build_luma_lut(AVCodecContext *avctx, int depth) |
| 466 | { | 467 | { |
| 468 | PixletContext *ctx = avctx->priv_data; | ||
| 469 | int max = (1 << depth) - 1; | ||
| 470 | |||
| 471 | if (ctx->depth == depth) | ||
| 472 | return; | ||
| 473 | ctx->depth = depth; | ||
| 474 | |||
| 475 | for (int i = 0; i < FF_ARRAY_ELEMS(ctx->lut); i++) | ||
| 476 | ctx->lut[i] = ((int64_t)i * i * 65535LL) / max / max; | ||
| 477 | } | ||
| 478 | |||
| 479 | static void postprocess_luma(AVCodecContext *avctx, AVFrame *frame, | ||
| 480 | int w, int h, int depth) | ||
| 481 | { | ||
| 482 | PixletContext *ctx = avctx->priv_data; | ||
| 467 | uint16_t *dsty = (uint16_t *)frame->data[0]; | 483 | uint16_t *dsty = (uint16_t *)frame->data[0]; |
| 468 | int16_t *srcy = (int16_t *)frame->data[0]; | 484 | int16_t *srcy = (int16_t *)frame->data[0]; |
| 469 | ptrdiff_t stridey = frame->linesize[0] / 2; | 485 | ptrdiff_t stridey = frame->linesize[0] / 2; |
| 486 | uint16_t *lut = ctx->lut; | ||
| 470 | int i, j; | 487 | int i, j; |
| 471 | 488 | ||
| 472 | for (j = 0; j < h; j++) { | 489 | for (j = 0; j < h; j++) { |
| @@ -476,8 +493,7 @@ static void postprocess_luma(AVFrame *frame, int w, int h, int depth) · 3 unmodified lines | |||
| 476 | else if (srcy[i] > ((1 << depth) - 1)) | 493 | else if (srcy[i] > ((1 << depth) - 1)) |
| 477 | dsty[i] = 65535; | 494 | dsty[i] = 65535; |
| 478 | else | 495 | else |
| 479 | dsty[i] = ((int64_t) srcy[i] * srcy[i] * 65535) / | 496 | dsty[i] = lut[srcy[i]]; |
| 480 | ((1 << depth) - 1) / ((1 << depth) - 1); | ||
| 481 | } | 497 | } |
| 482 | dsty += stridey; | 498 | dsty += stridey; |
| 483 | srcy += stridey; | 499 | srcy += stridey; |
| @@ -591,7 +607,7 @@ static int pixlet_decode_frame(AVCodecContext *avctx, void *data, · 107 unmodified lines | |||
| 591 | int i, w, h, width, height, ret, version; | 607 | int i, w, h, width, height, ret, version; |
| 592 | AVFrame *p = data; | 608 | AVFrame *p = data; |
| 593 | ThreadFrame frame = { .f = data }; | 609 | ThreadFrame frame = { .f = data }; |
| 594 | uint32_t pktsize; | 610 | uint32_t pktsize, depth; |
| 595 | 611 | ||
| 596 | bytestream2_init(&ctx->gb, avpkt->data, avpkt->size); | 612 | bytestream2_init(&ctx->gb, avpkt->data, avpkt->size); |
| 597 | 613 | ||
| @@ -623,12 +639,14 @@ static int pixlet_decode_frame(AVCodecContext *avctx, void *data, · 25 unmodified lines | |||
| 623 | ctx->levels = bytestream2_get_be32(&ctx->gb); | 639 | ctx->levels = bytestream2_get_be32(&ctx->gb); |
| 624 | if (ctx->levels != NB_LEVELS) | 640 | if (ctx->levels != NB_LEVELS) |
| 625 | return AVERROR_INVALIDDATA; | 641 | return AVERROR_INVALIDDATA; |
| 626 | ctx->depth = bytestream2_get_be32(&ctx->gb); | 642 | depth = bytestream2_get_be32(&ctx->gb); |
| 627 | if (ctx->depth < 8 || ctx->depth > 15) { | 643 | if (depth < 8 || depth > 15) { |
| 628 | avpriv_request_sample(avctx, "Depth %d", ctx->depth); | 644 | avpriv_request_sample(avctx, "Depth %d", depth); |
| 629 | return AVERROR_INVALIDDATA; | 645 | return AVERROR_INVALIDDATA; |
| 630 | } | 646 | } |
| 631 | 647 | ||
| 648 | build_luma_lut(avctx, depth); | ||
| 649 | |||
| 632 | ret = ff_set_dimensions(avctx, w, h); | 650 | ret = ff_set_dimensions(avctx, w, h); |
| 633 | if (ret < 0) | 651 | if (ret < 0) |
| 634 | return ret; | 652 | return ret; |
| @@ -667,7 +685,7 @@ static int pixlet_decode_frame(AVCodecContext *avctx, void *data, · 32 unmodified lines | |||
| 667 | break; | 685 | break; |
| 668 | } | 686 | } |
| 669 | 687 | ||
| 670 | postprocess_luma(frame.f, ctx->w, ctx->h, ctx->depth); | 688 | postprocess_luma(avctx, frame.f, ctx->w, ctx->h, ctx->depth); |
| 671 | postprocess_chroma(frame.f, ctx->w >> 1, ctx->h >> 1, ctx->depth); | 689 | postprocess_chroma(frame.f, ctx->w >> 1, ctx->h >> 1, ctx->depth); |
| 672 | 690 | ||
| 673 | *got_frame = 1; | 691 | *got_frame = 1; |