vp9_mbpitch.c 3.41 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 20 21 22 23 24 25
static void setup_block(BLOCKD *b,
                        int mv_stride,
                        uint8_t **base,
                        uint8_t **base2,
                        int Stride,
                        int offset,
                        BLOCKSET bs) {
John Koleszar's avatar
John Koleszar committed
26 27 28 29 30 31 32 33 34 35
  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
36 37
}

Paul Wilkins's avatar
Paul Wilkins committed
38
static void setup_macroblock(MACROBLOCKD *xd, BLOCKSET bs) {
John Koleszar's avatar
John Koleszar committed
39
  int block;
John Koleszar's avatar
John Koleszar committed
40

41
  uint8_t **y, **u, **v;
42
  uint8_t **y2 = NULL, **u2 = NULL, **v2 = NULL;
Paul Wilkins's avatar
Paul Wilkins committed
43 44
  BLOCKD *blockd = xd->block;
  int stride;
John Koleszar's avatar
John Koleszar committed
45

John Koleszar's avatar
John Koleszar committed
46
  if (bs == DEST) {
Paul Wilkins's avatar
Paul Wilkins committed
47 48 49
    y = &xd->dst.y_buffer;
    u = &xd->dst.u_buffer;
    v = &xd->dst.v_buffer;
John Koleszar's avatar
John Koleszar committed
50
  } else {
Paul Wilkins's avatar
Paul Wilkins committed
51 52 53
    y = &xd->pre.y_buffer;
    u = &xd->pre.u_buffer;
    v = &xd->pre.v_buffer;
John Koleszar's avatar
John Koleszar committed
54

Paul Wilkins's avatar
Paul Wilkins committed
55 56 57
    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
58
  }
John Koleszar's avatar
John Koleszar committed
59

Paul Wilkins's avatar
Paul Wilkins committed
60
  stride = xd->dst.y_stride;
John Koleszar's avatar
John Koleszar committed
61
  for (block = 0; block < 16; block++) { /* y blocks */
Paul Wilkins's avatar
Paul Wilkins committed
62 63
    setup_block(&blockd[block], stride, y, y2, stride,
                (block >> 2) * 4 * stride + (block & 3) * 4, bs);
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.uv_stride;
John Koleszar's avatar
John Koleszar committed
67
  for (block = 16; block < 20; block++) { /* U and V blocks */
Paul Wilkins's avatar
Paul Wilkins committed
68 69
    setup_block(&blockd[block], stride, u, u2, stride,
      ((block - 16) >> 1) * 4 * stride + (block & 1) * 4, bs);
John Koleszar's avatar
John Koleszar committed
70

Paul Wilkins's avatar
Paul Wilkins committed
71 72
    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
73
  }
74 75 76 77 78 79 80 81 82 83 84

  // TODO(jkoleszar): this will move once we're actually scaling.
  xd->scale_factor[0].x_num = 1;
  xd->scale_factor[0].x_den = 1;
  xd->scale_factor[0].y_num = 1;
  xd->scale_factor[0].y_den = 1;
  xd->scale_factor[0].x_offset_q4 = 0;
  xd->scale_factor[0].y_offset_q4 = 0;
  xd->scale_factor[1]= xd->scale_factor[0];
  xd->scale_factor_uv[0] = xd->scale_factor[0];
  xd->scale_factor_uv[1] = xd->scale_factor[1];
John Koleszar's avatar
John Koleszar committed
85 86
}

87
void vp9_setup_block_dptrs(MACROBLOCKD *xd) {
John Koleszar's avatar
John Koleszar committed
88
  int r, c;
Paul Wilkins's avatar
Paul Wilkins committed
89
  BLOCKD *blockd = xd->block;
John Koleszar's avatar
John Koleszar committed
90 91 92

  for (r = 0; r < 4; r++) {
    for (c = 0; c < 4; c++) {
Paul Wilkins's avatar
Paul Wilkins committed
93 94
      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
95
    }
John Koleszar's avatar
John Koleszar committed
96
  }
John Koleszar's avatar
John Koleszar committed
97

John Koleszar's avatar
John Koleszar committed
98 99
  for (r = 0; r < 2; r++) {
    for (c = 0; c < 2; c++) {
Paul Wilkins's avatar
Paul Wilkins committed
100 101 102
      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
103 104

    }
John Koleszar's avatar
John Koleszar committed
105
  }
John Koleszar's avatar
John Koleszar committed
106

John Koleszar's avatar
John Koleszar committed
107 108
  for (r = 0; r < 2; r++) {
    for (c = 0; c < 2; c++) {
Paul Wilkins's avatar
Paul Wilkins committed
109 110 111
      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
112 113

    }
John Koleszar's avatar
John Koleszar committed
114
  }
John Koleszar's avatar
John Koleszar committed
115

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

122
void vp9_build_block_doffsets(MACROBLOCKD *xd) {
John Koleszar's avatar
John Koleszar committed
123
  /* handle the destination pitch features */
Paul Wilkins's avatar
Paul Wilkins committed
124 125
  setup_macroblock(xd, DEST);
  setup_macroblock(xd, PRED);
John Koleszar's avatar
John Koleszar committed
126
}