Revision 968570d6 libavcodec/vp8.c

View differences:

libavcodec/vp8.c
29 29
#include "rectangle.h"
30 30

  
31 31
typedef struct {
32
    uint8_t filter_level;
33
    uint8_t inner_limit;
34
} VP8FilterStrength;
35

  
36
typedef struct {
32 37
    uint8_t segment;
33 38
    uint8_t skip;
34 39
    // todo: make it possible to check for at least (i4x4 or split_mv)
......
79 84

  
80 85
    VP8Macroblock *macroblocks;
81 86
    VP8Macroblock *macroblocks_base;
87
    VP8FilterStrength *filter_strength;
82 88
    int mb_stride;
83 89

  
84 90
    uint8_t *intra4x4_pred_mode;
......
231 237
    s->b4_stride = 4*s->mb_stride;
232 238

  
233 239
    s->macroblocks_base        = av_mallocz(s->mb_stride*(s->mb_height+1)*sizeof(*s->macroblocks));
240
    s->filter_strength         = av_mallocz(s->mb_stride*sizeof(*s->filter_strength));
234 241
    s->intra4x4_pred_mode_base = av_mallocz(s->b4_stride*(4*s->mb_height+1));
235 242
    s->top_nnz                 = av_mallocz(s->mb_width*sizeof(*s->top_nnz));
236 243
    s->top_border              = av_mallocz((s->mb_width+1)*sizeof(*s->top_border));
237 244

  
238
    if (!s->macroblocks_base || !s->intra4x4_pred_mode_base || !s->top_nnz || !s->top_border)
245
    if (!s->macroblocks_base || !s->filter_strength || !s->intra4x4_pred_mode_base || !s->top_nnz || !s->top_border)
239 246
        return AVERROR(ENOMEM);
240 247

  
241 248
    s->macroblocks        = s->macroblocks_base        + 1 + s->mb_stride;
......
1212 1219
    }
1213 1220
}
1214 1221

  
1215
static void filter_level_for_mb(VP8Context *s, VP8Macroblock *mb, int *level, int *inner, int *hev_thresh)
1222
static void filter_level_for_mb(VP8Context *s, VP8Macroblock *mb, VP8FilterStrength *f )
1216 1223
{
1217 1224
    int interior_limit, filter_level;
1218 1225

  
......
1247 1254
    }
1248 1255
    interior_limit = FFMAX(interior_limit, 1);
1249 1256

  
1250
    *level = filter_level;
1251
    *inner = interior_limit;
1252

  
1253
    if (hev_thresh) {
1254
        *hev_thresh = filter_level >= 15;
1255

  
1256
        if (s->keyframe) {
1257
            if (filter_level >= 40)
1258
                *hev_thresh = 2;
1259
        } else {
1260
            if (filter_level >= 40)
1261
                *hev_thresh = 3;
1262
            else if (filter_level >= 20)
1263
                *hev_thresh = 2;
1264
        }
1265
    }
1257
    f->filter_level = filter_level;
1258
    f->inner_limit = interior_limit;
1266 1259
}
1267 1260

  
1268
static void filter_mb(VP8Context *s, uint8_t *dst[3], VP8Macroblock *mb, int mb_x, int mb_y)
1261
static void filter_mb(VP8Context *s, uint8_t *dst[3], VP8Macroblock *mb, VP8FilterStrength *f, int mb_x, int mb_y)
1269 1262
{
1270
    int filter_level, inner_limit, hev_thresh, mbedge_lim, bedge_lim;
1263
    int mbedge_lim, bedge_lim, hev_thresh;
1264
    int filter_level = f->filter_level;
1265
    int inner_limit = f->inner_limit;
1271 1266

  
1272
    filter_level_for_mb(s, mb, &filter_level, &inner_limit, &hev_thresh);
1273 1267
    if (!filter_level)
1274 1268
        return;
1275 1269

  
1276 1270
    mbedge_lim = 2*(filter_level+2) + inner_limit;
1277 1271
     bedge_lim = 2* filter_level    + inner_limit;
1272
    hev_thresh = filter_level >= 15;
1273

  
1274
    if (s->keyframe) {
1275
        if (filter_level >= 40)
1276
            hev_thresh = 2;
1277
    } else {
1278
        if (filter_level >= 40)
1279
            hev_thresh = 3;
1280
        else if (filter_level >= 20)
1281
            hev_thresh = 2;
1282
    }
1278 1283

  
1279 1284
    if (mb_x) {
1280 1285
        s->vp8dsp.vp8_h_loop_filter16y(dst[0],     s->linesize,
......
1319 1324
    }
1320 1325
}
1321 1326

  
1322
static void filter_mb_simple(VP8Context *s, uint8_t *dst, VP8Macroblock *mb, int mb_x, int mb_y)
1327
static void filter_mb_simple(VP8Context *s, uint8_t *dst, VP8Macroblock *mb, VP8FilterStrength *f, int mb_x, int mb_y)
1323 1328
{
1324
    int filter_level, inner_limit, mbedge_lim, bedge_lim;
1329
    int mbedge_lim, bedge_lim;
1330
    int filter_level = f->filter_level;
1331
    int inner_limit = f->inner_limit;
1325 1332

  
1326
    filter_level_for_mb(s, mb, &filter_level, &inner_limit, NULL);
1327 1333
    if (!filter_level)
1328 1334
        return;
1329 1335

  
......
1349 1355

  
1350 1356
static void filter_mb_row(VP8Context *s, int mb_y)
1351 1357
{
1358
    VP8FilterStrength *f = s->filter_strength;
1352 1359
    VP8Macroblock *mb = s->macroblocks + mb_y*s->mb_stride;
1353 1360
    uint8_t *dst[3] = {
1354 1361
        s->framep[VP56_FRAME_CURRENT]->data[0] + 16*mb_y*s->linesize,
......
1359 1366

  
1360 1367
    for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
1361 1368
        backup_mb_border(s->top_border[mb_x+1], dst[0], dst[1], dst[2], s->linesize, s->uvlinesize, 0);
1362
        filter_mb(s, dst, mb++, mb_x, mb_y);
1369
        filter_mb(s, dst, mb++, f++, mb_x, mb_y);
1363 1370
        dst[0] += 16;
1364 1371
        dst[1] += 8;
1365 1372
        dst[2] += 8;
......
1368 1375

  
1369 1376
static void filter_mb_row_simple(VP8Context *s, int mb_y)
1370 1377
{
1371
    uint8_t *dst = s->framep[VP56_FRAME_CURRENT]->data[0] + 16*mb_y*s->linesize;
1378
    VP8FilterStrength *f = s->filter_strength;
1372 1379
    VP8Macroblock *mb = s->macroblocks + mb_y*s->mb_stride;
1380
    uint8_t *dst = s->framep[VP56_FRAME_CURRENT]->data[0] + 16*mb_y*s->linesize;
1373 1381
    int mb_x;
1374 1382

  
1375 1383
    for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
1376 1384
        backup_mb_border(s->top_border[mb_x+1], dst, NULL, NULL, s->linesize, 0, 1);
1377
        filter_mb_simple(s, dst, mb++, mb_x, mb_y);
1385
        filter_mb_simple(s, dst, mb++, f++, mb_x, mb_y);
1378 1386
        dst += 16;
1379 1387
    }
1380 1388
}
......
1497 1505
                }
1498 1506
            }
1499 1507

  
1508
            if (s->deblock_filter)
1509
                filter_level_for_mb(s, mb, &s->filter_strength[mb_x]);
1510

  
1500 1511
            dst[0] += 16;
1501 1512
            dst[1] += 8;
1502 1513
            dst[2] += 8;

Also available in: Unified diff