int *lens; ///< codelengths
} TM2Huff;
+/**
+ *
+ * @returns the length of the longest code or an AVERROR code
+ */
static int tm2_read_tree(TM2Context *ctx, uint32_t prefix, int length, TM2Huff *huff)
{
- int ret;
+ int ret, ret2;
if (length > huff->max_bits) {
av_log(ctx->avctx, AV_LOG_ERROR, "Tree exceeded its given depth (%i)\n",
huff->max_bits);
huff->bits[huff->num] = prefix;
huff->lens[huff->num] = length;
huff->num++;
- return 0;
+ return length;
} else { /* non-terminal node */
- if ((ret = tm2_read_tree(ctx, prefix << 1, length + 1, huff)) < 0)
- return ret;
+ if ((ret2 = tm2_read_tree(ctx, prefix << 1, length + 1, huff)) < 0)
+ return ret2;
if ((ret = tm2_read_tree(ctx, (prefix << 1) | 1, length + 1, huff)) < 0)
return ret;
}
- return 0;
+ return FFMAX(ret, ret2);
}
static int tm2_build_huff_table(TM2Context *ctx, TM2Codes *code)
res = tm2_read_tree(ctx, 0, 0, &huff);
+ if (res >= 0 && res != huff.max_bits) {
+ av_log(ctx->avctx, AV_LOG_ERROR, "Got less bits than expected: %i of %i\n",
+ res, huff.max_bits);
+ res = AVERROR_INVALIDDATA;
+ }
if (huff.num != huff.max_num) {
av_log(ctx->avctx, AV_LOG_ERROR, "Got less codes than expected: %i of %i\n",
huff.num, huff.max_num);
}
}
-static inline void tm2_low_chroma(int *data, int stride, int *clast, int *CD, int *deltas, int bx)
+static inline void tm2_low_chroma(int *data, int stride, int *clast, unsigned *CD, int *deltas, int bx)
{
int t;
int l;
prev = clast[-3];
else
prev = 0;
- t = (CD[0] + CD[1]) >> 1;
- l = (prev - CD[0] - CD[1] + clast[1]) >> 1;
+ t = (int)(CD[0] + CD[1]) >> 1;
+ l = (int)(prev - CD[0] - CD[1] + clast[1]) >> 1;
CD[1] = CD[0] + CD[1] - t;
CD[0] = t;
clast[0] = l;
{
int i;
int ct;
- int left, right, diff;
+ unsigned left, right;
+ int diff;
int deltas[16];
TM2_INIT_POINTERS();
/* update chroma */
for (j = 0; j < 2; j++) {
for (i = 0; i < 2; i++) {
- U[i] = Uo[i] + GET_TOK(ctx, TM2_UPD);
- V[i] = Vo[i] + GET_TOK(ctx, TM2_UPD);
+ U[i] = Uo[i] + (unsigned)GET_TOK(ctx, TM2_UPD);
+ V[i] = Vo[i] + (unsigned)GET_TOK(ctx, TM2_UPD);
}
U += Ustride;
V += Vstride;
dst = p->data[0];
for (j = 0; j < h; j++) {
for (i = 0; i < w; i++) {
- int y = Y[i], u = U[i >> 1], v = V[i >> 1];
+ unsigned y = Y[i], u = U[i >> 1], v = V[i >> 1];
dst[3*i+0] = av_clip_uint8(y + v);
dst[3*i+1] = av_clip_uint8(y);
dst[3*i+2] = av_clip_uint8(y + u);