Coverage Report

Created: 2025-06-22 08:04

/src/aom/av1/common/debugmodes.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3
 *
4
 * This source code is subject to the terms of the BSD 2 Clause License and
5
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6
 * was not distributed with this source code in the LICENSE file, you can
7
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8
 * Media Patent License 1.0 was not distributed with this source code in the
9
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10
 */
11
12
#include "av1/common/debugmodes.h"
13
14
#include <stdio.h>
15
16
#include "av1/common/av1_common_int.h"
17
#include "av1/common/blockd.h"
18
#include "av1/common/enums.h"
19
20
#if 0
21
static void log_frame_info(AV1_COMMON *cm, const char *str, FILE *f) {
22
  fprintf(f, "%s", str);
23
  fprintf(f, "(Frame %u, Show:%d, Q:%d): \n", cm->current_frame.frame_number,
24
          cm->show_frame, cm->quant_params.base_qindex);
25
}
26
27
/* This function dereferences a pointer to the mbmi structure
28
 * and uses the passed in member offset to print out the value of an integer
29
 * for each mbmi member value in the mi structure.
30
 */
31
static void print_mi_data(AV1_COMMON *cm, FILE *file, const char *descriptor,
32
                          size_t member_offset) {
33
  const CommonModeInfoParams *const mi_params = &cm->mi_params;
34
  MB_MODE_INFO **mi = mi_params->mi_grid_base;
35
  int rows = mi_params->mi_rows;
36
  int cols = mi_params->mi_cols;
37
  char prefix = descriptor[0];
38
39
  log_frame_info(cm, descriptor, file);
40
  for (int mi_row = 0; mi_row < rows; mi_row++) {
41
    fprintf(file, "%c ", prefix);
42
    for (int mi_col = 0; mi_col < cols; mi_col++) {
43
      fprintf(file, "%2d ", *((char *)((char *)(mi[0]) + member_offset)));
44
      mi++;
45
    }
46
    fprintf(file, "\n");
47
    mi += mi_params->mi_stride - cols;
48
  }
49
  fprintf(file, "\n");
50
}
51
52
void av1_print_modes_and_motion_vectors(AV1_COMMON *cm, const char *file) {
53
  CommonModeInfoParams *mi_params = &cm->mi_params;
54
  FILE *mvs = fopen(file, "a");
55
  MB_MODE_INFO **mi = mi_params->mi_grid_base;
56
  const int rows = mi_params->mi_rows;
57
  const int cols = mi_params->mi_cols;
58
59
  print_mi_data(cm, mvs, "Partitions:", offsetof(MB_MODE_INFO, bsize));
60
  print_mi_data(cm, mvs, "Modes:", offsetof(MB_MODE_INFO, mode));
61
  print_mi_data(cm, mvs, "Ref frame:", offsetof(MB_MODE_INFO, ref_frame[0]));
62
  print_mi_data(cm, mvs, "Transform:", offsetof(MB_MODE_INFO, tx_size));
63
  print_mi_data(cm, mvs, "UV Modes:", offsetof(MB_MODE_INFO, uv_mode));
64
65
  // output skip infomation.
66
  log_frame_info(cm, "Skips:", mvs);
67
  for (int mi_row = 0; mi_row < rows; mi_row++) {
68
    fprintf(mvs, "S ");
69
    for (int mi_col = 0; mi_col < cols; mi_col++) {
70
      fprintf(mvs, "%2d ", mi[0]->skip_txfm);
71
      mi++;
72
    }
73
    fprintf(mvs, "\n");
74
    mi += mi_params->mi_stride - cols;
75
  }
76
  fprintf(mvs, "\n");
77
78
  // output motion vectors.
79
  log_frame_info(cm, "Vectors ", mvs);
80
  mi = mi_params->mi_grid_base;
81
  for (int mi_row = 0; mi_row < rows; mi_row++) {
82
    fprintf(mvs, "V ");
83
    for (int mi_col = 0; mi_col < cols; mi_col++) {
84
      fprintf(mvs, "%4d:%4d ", mi[0]->mv[0].as_mv.row, mi[0]->mv[0].as_mv.col);
85
      mi++;
86
    }
87
    fprintf(mvs, "\n");
88
    mi += mi_params->mi_stride - cols;
89
  }
90
  fprintf(mvs, "\n");
91
92
  fclose(mvs);
93
}
94
#endif  // 0
95
96
void av1_print_uncompressed_frame_header(const uint8_t *data, int size,
97
0
                                         const char *filename) {
98
0
  FILE *hdrFile = fopen(filename, "w");
99
0
  fwrite(data, size, sizeof(uint8_t), hdrFile);
100
101
  // Reset order hints(7bit + a previous bit) to 0, so that all camera frame
102
  // headers are identical in large scale coding.
103
0
  uint8_t zero = 0;
104
0
  fseek(hdrFile, 1, SEEK_SET);
105
  // Reset second byte.
106
0
  fwrite(&zero, 1, sizeof(uint8_t), hdrFile);
107
0
  fclose(hdrFile);
108
0
}
109
110
0
void av1_print_frame_contexts(const FRAME_CONTEXT *fc, const char *filename) {
111
0
  FILE *fcFile = fopen(filename, "w");
112
0
  const uint16_t *fcp = (uint16_t *)fc;
113
0
  const unsigned int n_contexts = sizeof(FRAME_CONTEXT) / sizeof(uint16_t);
114
0
  unsigned int i;
115
116
0
  for (i = 0; i < n_contexts; ++i) fprintf(fcFile, "%d ", *fcp++);
117
0
  fclose(fcFile);
118
0
}