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


12
#include "vp9/common/vp9_blockd.h"
John Koleszar's avatar
John Koleszar committed
13

John Koleszar's avatar
John Koleszar committed
14 15 16
typedef enum {
  PRED = 0,
  DEST = 1
John Koleszar's avatar
John Koleszar committed
17 18
} BLOCKSET;

19
static void setup_block
John Koleszar's avatar
John Koleszar committed
20
(
John Koleszar's avatar
John Koleszar committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
  BLOCKD *b,
  int mv_stride,
  unsigned char **base,
  unsigned char **base2,
  int Stride,
  int offset,
  BLOCKSET bs
) {

  if (bs == DEST) {
    b->dst_stride = Stride;
    b->dst = offset;
    b->base_dst = base;
  } else {
    b->pre_stride = Stride;
    b->pre = offset;
    b->base_pre = base;
    b->base_second_pre = base2;
  }
John Koleszar's avatar
John Koleszar committed
40 41 42

}

43

Paul Wilkins's avatar
Paul Wilkins committed
44
static void setup_macroblock(MACROBLOCKD *xd, BLOCKSET bs) {
John Koleszar's avatar
John Koleszar committed
45
  int block;
John Koleszar's avatar
John Koleszar committed
46

John Koleszar's avatar
John Koleszar committed
47 48
  unsigned char **y, **u, **v;
  unsigned char **y2, **u2, **v2;
Paul Wilkins's avatar
Paul Wilkins committed
49 50
  BLOCKD *blockd = xd->block;
  int stride;
John Koleszar's avatar
John Koleszar committed
51

John Koleszar's avatar
John Koleszar committed
52
  if (bs == DEST) {
Paul Wilkins's avatar
Paul Wilkins committed
53 54 55
    y = &xd->dst.y_buffer;
    u = &xd->dst.u_buffer;
    v = &xd->dst.v_buffer;
John Koleszar's avatar
John Koleszar committed
56
  } else {
Paul Wilkins's avatar
Paul Wilkins committed
57 58 59
    y = &xd->pre.y_buffer;
    u = &xd->pre.u_buffer;
    v = &xd->pre.v_buffer;
John Koleszar's avatar
John Koleszar committed
60

Paul Wilkins's avatar
Paul Wilkins committed
61 62 63
    y2 = &xd->second_pre.y_buffer;
    u2 = &xd->second_pre.u_buffer;
    v2 = &xd->second_pre.v_buffer;
John Koleszar's avatar
John Koleszar committed
64
  }
John Koleszar's avatar
John Koleszar committed
65

Paul Wilkins's avatar
Paul Wilkins committed
66
  stride = xd->dst.y_stride;
John Koleszar's avatar
John Koleszar committed
67
  for (block = 0; block < 16; block++) { /* y blocks */
Paul Wilkins's avatar
Paul Wilkins committed
68 69
    setup_block(&blockd[block], stride, y, y2, stride,
                (block >> 2) * 4 * stride + (block & 3) * 4, bs);
John Koleszar's avatar
John Koleszar committed
70
  }
John Koleszar's avatar
John Koleszar committed
71

Paul Wilkins's avatar
Paul Wilkins committed
72
  stride = xd->dst.uv_stride;
John Koleszar's avatar
John Koleszar committed
73
  for (block = 16; block < 20; block++) { /* U and V blocks */
Paul Wilkins's avatar
Paul Wilkins committed
74 75
    setup_block(&blockd[block], stride, u, u2, stride,
      ((block - 16) >> 1) * 4 * stride + (block & 1) * 4, bs);
John Koleszar's avatar
John Koleszar committed
76

Paul Wilkins's avatar
Paul Wilkins committed
77 78
    setup_block(&blockd[block + 4], stride, v, v2, stride,
      ((block - 16) >> 1) * 4 * stride + (block & 1) * 4, bs);
John Koleszar's avatar
John Koleszar committed
79
  }
John Koleszar's avatar
John Koleszar committed
80 81
}

82
void vp9_setup_block_dptrs(MACROBLOCKD *xd) {
John Koleszar's avatar
John Koleszar committed
83
  int r, c;
Paul Wilkins's avatar
Paul Wilkins committed
84
  BLOCKD *blockd = xd->block;
John Koleszar's avatar
John Koleszar committed
85 86 87

  for (r = 0; r < 4; r++) {
    for (c = 0; c < 4; c++) {
Paul Wilkins's avatar
Paul Wilkins committed
88 89
      blockd[r * 4 + c].diff = &xd->diff[r * 4 * 16 + c * 4];
      blockd[r * 4 + c].predictor = xd->predictor + r * 4 * 16 + c * 4;
John Koleszar's avatar
John Koleszar committed
90
    }
John Koleszar's avatar
John Koleszar committed
91
  }
John Koleszar's avatar
John Koleszar committed
92

John Koleszar's avatar
John Koleszar committed
93 94
  for (r = 0; r < 2; r++) {
    for (c = 0; c < 2; c++) {
Paul Wilkins's avatar
Paul Wilkins committed
95 96 97
      blockd[16 + r * 2 + c].diff = &xd->diff[256 + r * 4 * 8 + c * 4];
      blockd[16 + r * 2 + c].predictor =
        xd->predictor + 256 + r * 4 * 8 + c * 4;
John Koleszar's avatar
John Koleszar committed
98 99

    }
John Koleszar's avatar
John Koleszar committed
100
  }
John Koleszar's avatar
John Koleszar committed
101

John Koleszar's avatar
John Koleszar committed
102 103
  for (r = 0; r < 2; r++) {
    for (c = 0; c < 2; c++) {
Paul Wilkins's avatar
Paul Wilkins committed
104 105 106
      blockd[20 + r * 2 + c].diff = &xd->diff[320 + r * 4 * 8 + c * 4];
      blockd[20 + r * 2 + c].predictor =
        xd->predictor + 320 + r * 4 * 8 + c * 4;
John Koleszar's avatar
John Koleszar committed
107 108

    }
John Koleszar's avatar
John Koleszar committed
109
  }
John Koleszar's avatar
John Koleszar committed
110

Paul Wilkins's avatar
Paul Wilkins committed
111
  blockd[24].diff = &xd->diff[384];
John Koleszar's avatar
John Koleszar committed
112

John Koleszar's avatar
John Koleszar committed
113
  for (r = 0; r < 25; r++) {
Paul Wilkins's avatar
Paul Wilkins committed
114 115
    blockd[r].qcoeff  = xd->qcoeff  + r * 16;
    blockd[r].dqcoeff = xd->dqcoeff + r * 16;
John Koleszar's avatar
John Koleszar committed
116
  }
John Koleszar's avatar
John Koleszar committed
117 118
}

119
void vp9_build_block_doffsets(MACROBLOCKD *xd) {
John Koleszar's avatar
John Koleszar committed
120

John Koleszar's avatar
John Koleszar committed
121
  /* handle the destination pitch features */
Paul Wilkins's avatar
Paul Wilkins committed
122 123
  setup_macroblock(xd, DEST);
  setup_macroblock(xd, PRED);
John Koleszar's avatar
John Koleszar committed
124
}