vp9_seg_common.c 3.17 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
/*
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

John Koleszar's avatar
John Koleszar committed
11
12
#include <assert.h>
#include "vp9/common/vp9_blockd.h"
13
#include "vp9/common/vp9_seg_common.h"
14

Dmitry Kovalev's avatar
Dmitry Kovalev committed
15
16
static const int seg_feature_data_signed[SEG_LVL_MAX] = { 1, 1, 0, 0 };
static const int seg_feature_data_max[SEG_LVL_MAX] = { MAXQ, 63, 15, 15 };
17
18
19
20
21
22

// These functions provide access to new segment level features.
// Eventually these function may be "optimized out" but for the moment,
// the coding mechanism is still subject to change so these provide a
// convenient single point of change.

Dmitry Kovalev's avatar
Dmitry Kovalev committed
23
int vp9_segfeature_active(const MACROBLOCKD *xd, int segment_id,
24
                          SEG_LVL_FEATURES feature_id) {
Dmitry Kovalev's avatar
Dmitry Kovalev committed
25
26
  return xd->segmentation_enabled &&
         (xd->segment_feature_mask[segment_id] & (1 << feature_id));
27
28
}

29
void vp9_clearall_segfeatures(MACROBLOCKD *xd) {
John Koleszar's avatar
John Koleszar committed
30
31
  vpx_memset(xd->segment_feature_data, 0, sizeof(xd->segment_feature_data));
  vpx_memset(xd->segment_feature_mask, 0, sizeof(xd->segment_feature_mask));
32
33
}

Dmitry Kovalev's avatar
Dmitry Kovalev committed
34
void vp9_enable_segfeature(MACROBLOCKD *xd, int segment_id,
35
                           SEG_LVL_FEATURES feature_id) {
Dmitry Kovalev's avatar
Dmitry Kovalev committed
36
  xd->segment_feature_mask[segment_id] |= 1 << feature_id;
37
38
}

Dmitry Kovalev's avatar
Dmitry Kovalev committed
39
void vp9_disable_segfeature(MACROBLOCKD *xd, int segment_id,
40
                            SEG_LVL_FEATURES feature_id) {
John Koleszar's avatar
John Koleszar committed
41
  xd->segment_feature_mask[segment_id] &= ~(1 << feature_id);
42
43
}

John Koleszar's avatar
John Koleszar committed
44
45
int vp9_seg_feature_data_max(SEG_LVL_FEATURES feature_id) {
  return seg_feature_data_max[feature_id];
46
47
}

48
int vp9_is_segfeature_signed(SEG_LVL_FEATURES feature_id) {
Dmitry Kovalev's avatar
Dmitry Kovalev committed
49
  return seg_feature_data_signed[feature_id];
50
51
}

Dmitry Kovalev's avatar
Dmitry Kovalev committed
52
void vp9_clear_segdata(MACROBLOCKD *xd, int segment_id,
53
                       SEG_LVL_FEATURES feature_id) {
John Koleszar's avatar
John Koleszar committed
54
  xd->segment_feature_data[segment_id][feature_id] = 0;
55
56
}

Dmitry Kovalev's avatar
Dmitry Kovalev committed
57
58
void vp9_set_segdata(MACROBLOCKD *xd, int segment_id,
                     SEG_LVL_FEATURES feature_id, int seg_data) {
John Koleszar's avatar
John Koleszar committed
59
60
  assert(seg_data <= seg_feature_data_max[feature_id]);
  if (seg_data < 0) {
Dmitry Kovalev's avatar
Dmitry Kovalev committed
61
    assert(seg_feature_data_signed[feature_id]);
John Koleszar's avatar
John Koleszar committed
62
63
64
    assert(-seg_data <= seg_feature_data_max[feature_id]);
  }

John Koleszar's avatar
John Koleszar committed
65
  xd->segment_feature_data[segment_id][feature_id] = seg_data;
66
67
}

Dmitry Kovalev's avatar
Dmitry Kovalev committed
68
int vp9_get_segdata(const MACROBLOCKD *xd, int segment_id,
69
                    SEG_LVL_FEATURES feature_id) {
John Koleszar's avatar
John Koleszar committed
70
  return xd->segment_feature_data[segment_id][feature_id];
71
}
72
73

void vp9_clear_segref(MACROBLOCKD *xd, int segment_id) {
John Koleszar's avatar
John Koleszar committed
74
  xd->segment_feature_data[segment_id][SEG_LVL_REF_FRAME] = 0;
75
76
}

Dmitry Kovalev's avatar
Dmitry Kovalev committed
77
void vp9_set_segref(MACROBLOCKD *xd, int segment_id,
78
                    MV_REFERENCE_FRAME ref_frame) {
Dmitry Kovalev's avatar
Dmitry Kovalev committed
79
  xd->segment_feature_data[segment_id][SEG_LVL_REF_FRAME] |= 1 << ref_frame;
80
81
}

Dmitry Kovalev's avatar
Dmitry Kovalev committed
82
int vp9_check_segref(const MACROBLOCKD *xd, int segment_id,
83
                     MV_REFERENCE_FRAME ref_frame) {
John Koleszar's avatar
John Koleszar committed
84
  return (xd->segment_feature_data[segment_id][SEG_LVL_REF_FRAME] &
Dmitry Kovalev's avatar
Dmitry Kovalev committed
85
         (1 << ref_frame)) ? 1 : 0;
86
87
88
}

// TBD? Functions to read and write segment data with range / validity checking