Commit f6577bd9 authored by Christophe Gisquet's avatar Christophe Gisquet Committed by Michael Niedermayer

huffyuvdec: use unsafe bitstream reader

The reader reads in chunks of 11 bits at most, and at most 3 times. The unsafe
reader therefore may read 6 chunks instead of 1 in worst case, ie 8 bytes,
which is within the padding tolerance.

The reader ends up being ~10% faster. Cumulative effect of unsafe reading and
code block swapping on 3 sequences is for 1 thread, decoding time goes from
23.3s to 19.0s.
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 02bffc56
......@@ -30,6 +30,8 @@
* huffyuv decoder
*/
#define UNCHECKED_BITSTREAM_READER 1
#include "avcodec.h"
#include "get_bits.h"
#include "huffyuv.h"
......@@ -613,15 +615,21 @@ static av_cold int decode_init_thread_copy(AVCodecContext *avctx)
static void decode_422_bitstream(HYuvContext *s, int count)
{
int i;
int i, icount;
OPEN_READER(re, &s->gb);
count /= 2;
if (count >= (get_bits_left(&s->gb)) / (32 * 4)) {
for (i = 0; i < count && get_bits_left(&s->gb) > 0; i++) {
icount = get_bits_left(&s->gb) / (32 * 4);
if (count >= icount) {
for (i = 0; i < icount; i++) {
READ_2PIX(s->temp[0][2 * i ], s->temp[1][i], 1);
READ_2PIX(s->temp[0][2 * i + 1], s->temp[2][i], 2);
}
for (; i < count && get_bits_left(&s->gb) > 0; i++) {
READ_2PIX(s->temp[0][2 * i ], s->temp[1][i], 1);
if (get_bits_left(&s->gb) <= 0) break;
READ_2PIX(s->temp[0][2 * i + 1], s->temp[2][i], 2);
}
for (; i < count; i++)
s->temp[0][2 * i ] = s->temp[1][i] =
s->temp[0][2 * i + 1] = s->temp[2][i] = 128;
......@@ -716,7 +724,7 @@ static av_always_inline void decode_bgr_1(HYuvContext *s, int count,
int i;
OPEN_READER(re, &s->gb);
for (i = 0; i < count; i++) {
for (i = 0; i < count && get_bits_left(&s->gb) > 0; i++) {
unsigned int index;
int code, n;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment