History

avcodec/pixlet: postprocess luma using precalculated lut

Realtime decoding speed raises from 1.08 to 1.84 for 1504x846, 25391 kb/s, 24 fps video.

Paul B Mahol committed 6 years ago

Commit bc866291 parent d182d8f1 file · +26 −8Browse files

Unified · Split

libavcodec/pixlet.c+26−8
@@ -58,6 +58,7 @@ typedef struct PixletContext { · 57 unmodified lines
5858 int16_t *filter[2];
5959 int16_t *prediction;
6060 int64_t scaling[4][2][NB_LEVELS];
61+ uint16_t lut[65536];
6162 SubBand band[4][NB_LEVELS * 3 + 1];
6263 } PixletContext;
6364
@@ -462,11 +463,27 @@ static void reconstruction(AVCodecContext *avctx, int16_t *dest, · 398 unmodified lines
462463 }
463464 }
464465
465−static void postprocess_luma(AVFrame *frame, int w, int h, int depth)
466+static void build_luma_lut(AVCodecContext *avctx, int depth)
466467 {
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;
467483 uint16_t *dsty = (uint16_t *)frame->data[0];
468484 int16_t *srcy = (int16_t *)frame->data[0];
469485 ptrdiff_t stridey = frame->linesize[0] / 2;
486+ uint16_t *lut = ctx->lut;
470487 int i, j;
471488
472489 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
476493 else if (srcy[i] > ((1 << depth) - 1))
477494 dsty[i] = 65535;
478495 else
479− dsty[i] = ((int64_t) srcy[i] * srcy[i] * 65535) /
480− ((1 << depth) - 1) / ((1 << depth) - 1);
496+ dsty[i] = lut[srcy[i]];
481497 }
482498 dsty += stridey;
483499 srcy += stridey;
@@ -591,7 +607,7 @@ static int pixlet_decode_frame(AVCodecContext *avctx, void *data, · 107 unmodified lines
591607 int i, w, h, width, height, ret, version;
592608 AVFrame *p = data;
593609 ThreadFrame frame = { .f = data };
594− uint32_t pktsize;
610+ uint32_t pktsize, depth;
595611
596612 bytestream2_init(&ctx->gb, avpkt->data, avpkt->size);
597613
@@ -623,12 +639,14 @@ static int pixlet_decode_frame(AVCodecContext *avctx, void *data, · 25 unmodified lines
623639 ctx->levels = bytestream2_get_be32(&ctx->gb);
624640 if (ctx->levels != NB_LEVELS)
625641 return AVERROR_INVALIDDATA;
626− ctx->depth = bytestream2_get_be32(&ctx->gb);
627− if (ctx->depth < 8 || ctx->depth > 15) {
628− avpriv_request_sample(avctx, "Depth %d", ctx->depth);
642+ depth = bytestream2_get_be32(&ctx->gb);
643+ if (depth < 8 || depth > 15) {
644+ avpriv_request_sample(avctx, "Depth %d", depth);
629645 return AVERROR_INVALIDDATA;
630646 }
631647
648+ build_luma_lut(avctx, depth);
649+
632650 ret = ff_set_dimensions(avctx, w, h);
633651 if (ret < 0)
634652 return ret;
@@ -667,7 +685,7 @@ static int pixlet_decode_frame(AVCodecContext *avctx, void *data, · 32 unmodified lines
667685 break;
668686 }
669687
670− postprocess_luma(frame.f, ctx->w, ctx->h, ctx->depth);
688+ postprocess_luma(avctx, frame.f, ctx->w, ctx->h, ctx->depth);
671689 postprocess_chroma(frame.f, ctx->w >> 1, ctx->h >> 1, ctx->depth);
672690
673691 *got_frame = 1;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t