summaryrefslogtreecommitdiff
path: root/vp9/common/vp9_debugmodes.c
blob: 827e4bf8490a3394f0886892776dd7865d392d52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
 *  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.
 */

#include <stdio.h>
#include "vp9/common/vp9_onyxc_int.h"
#include "vp9/common/vp9_blockd.h"
#include "vp9/common/vp9_tile_common.h"
typedef struct {
  char *debug_array;
  int w;
  int h;
} DEBUG_MODE_STRUCT;

static void draw_rect(int r, int c, int w, int h, DEBUG_MODE_STRUCT *da) {
  int i;
  da->debug_array[r / 2 * da->w + c] = '+';
  for (i = r / 2 + 1; i < r / 2 + h / 2; i++) {
    da->debug_array[i * da->w + c] = '|';
  }
  for (i = c + 1; i < c + w; i++) {
    da->debug_array[r / 2 * da->w + i] = '-';
  }
}
static void debug_partitioning(VP9_COMMON * cm, MODE_INFO *m, int mi_row,
                               int mi_col, BLOCK_SIZE_TYPE bsize,
                               DEBUG_MODE_STRUCT *da) {
  const int mis = cm->mode_info_stride;
  int bwl, bhl;
  int bw, bh;
  int bsl = mi_width_log2(bsize), bs = (1 << bsl) / 2;
  int n;
  PARTITION_TYPE partition;
  BLOCK_SIZE_TYPE subsize;

  if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols)
    return;

  bwl = mi_width_log2(m->mbmi.sb_type);
  bhl = mi_height_log2(m->mbmi.sb_type);
  bw = 1 << bwl;
  bh = 1 << bhl;

  // parse the partition type
  if ((bwl == bsl) && (bhl == bsl))
    partition = PARTITION_NONE;
  else if ((bwl == bsl) && (bhl < bsl))
    partition = PARTITION_HORZ;
  else if ((bwl < bsl) && (bhl == bsl))
    partition = PARTITION_VERT;
  else if ((bwl < bsl) && (bhl < bsl))
    partition = PARTITION_SPLIT;
  else
    assert(0);

#if CONFIG_AB4X4
  if (bsize == BLOCK_SIZE_SB8X8 && m->mbmi.sb_type < BLOCK_SIZE_SB8X8)
  partition = PARTITION_SPLIT;
  if (bsize < BLOCK_SIZE_SB8X8)
  return;
#endif

#if CONFIG_AB4X4
  if (bsize >= BLOCK_SIZE_SB8X8) {
#else
  if (bsize > BLOCK_SIZE_SB8X8) {
#endif
  }

  subsize = get_subsize(bsize, partition);
  switch (partition) {
    case PARTITION_NONE:
      draw_rect(mi_row * 8, mi_col * 8, bw * 8, bh * 8, da);
      break;
    case PARTITION_HORZ:
      draw_rect(mi_row * 8, mi_col * 8, bw * 8, bh * 8, da);
      if ((mi_row + bh) < cm->mi_rows)
        draw_rect(8 * bs + mi_row * 8, mi_col * 8, bw * 8, bh * 8, da);
      break;
    case PARTITION_VERT:
      draw_rect(mi_row * 8, mi_col * 8, bw * 8, bh * 8, da);
      if ((mi_col + bw) < cm->mi_cols)
        draw_rect(mi_row * 8, 8 * bs + mi_col * 8, bw * 8, bh * 8, da);
      break;
    case PARTITION_SPLIT:
      for (n = 0; n < 4; n++) {
        int j = n >> 1, i = n & 0x01;
        debug_partitioning(cm, m + j * bs * mis + i * bs, mi_row + j * bs,
                           mi_col + i * bs, subsize, da);
      }
      break;
    default:
      assert(0);
  }
}
static void debug_partitionings(VP9_COMMON *c, DEBUG_MODE_STRUCT *da) {
  const int mis = c->mode_info_stride;
  MODE_INFO *m, *m_ptr = c->mi;
  int mi_row, mi_col;

  m_ptr += c->cur_tile_mi_col_start + c->cur_tile_mi_row_start * mis;

  for (mi_row = c->cur_tile_mi_row_start; mi_row < c->cur_tile_mi_row_end;
      mi_row += 8, m_ptr += 8 * mis) {
    m = m_ptr;
    for (mi_col = c->cur_tile_mi_col_start; mi_col < c->cur_tile_mi_col_end;
        mi_col += 8, m += 8) {
      debug_partitioning(c, m, mi_row, mi_col, BLOCK_SIZE_SB64X64, da);
    }
  }
}
void vp9_debug_tile_partitionings(VP9_COMMON *pc) {
  int tile_row, tile_col;
  DEBUG_MODE_STRUCT da;

  da.w = pc->width;
  da.h = pc->height / 2;
  da.debug_array = vpx_malloc(da.h * da.w);
  vpx_memset(da.debug_array, ' ', da.h * da.w);
  for (tile_row = 0; tile_row < pc->tile_rows; tile_row++) {
    vp9_get_tile_row_offsets(pc, tile_row);
    for (tile_col = 0; tile_col < pc->tile_columns; tile_col++) {
      vp9_get_tile_col_offsets(pc, tile_col);

      debug_partitionings(pc, &da);
    }
  }
  {
    FILE *f = fopen("partitionings.txt", "a");
    int i, j;
    fprintf(f, "\n\n\nFrame: %d \n", pc->current_video_frame);
    for (i = 0; i < da.h; i++) {
      for (j = 0; j < da.w; j++) {
        fprintf(f, "%c", da.debug_array[i * da.w + j]);
      }
      fprintf(f, "\n");
    }
    fclose(f);
  }
  vpx_free(da.debug_array);
}