yuvcmp.c
Go to the documentation of this file.
1 /*
2  * originally by Andreas Ă–man (andoma)
3  * some changes by Alexander Strange
4  */
5 
6 #include <string.h>
7 #include <stdlib.h>
8 #include <inttypes.h>
9 #include <stdio.h>
10 #include <sys/stat.h>
11 #include <fcntl.h>
12 #include <unistd.h>
13 
14 
15 int
16 main(int argc, char **argv)
17 {
18  int fd[2];
19  int print_pixels = 0;
20  int dump_blocks = 0;
21 
22  int width;
23  int height;
24  int to_skip = 0;
25 
26  if (argc < 6) {
27  fprintf(stderr, "%s [YUV file 1] [YUV file 2] width height pixelcmp|blockdump (# to skip)\n", argv[0]);
28  return 1;
29  }
30 
31  width = atoi(argv[3]);
32  height = atoi(argv[4]);
33  if (argc > 6)
34  to_skip = atoi(argv[6]);
35 
36  uint8_t *Y[2], *C[2][2];
37  int i, v, c, p;
38  int lsiz = width * height;
39  int csiz = width * height / 4;
40  int x, y;
41  int cwidth = width / 2;
42  int fr = to_skip;
43  int mb;
44  char *mberrors;
45  int mb_x, mb_y;
46  uint8_t *a;
47  uint8_t *b;
48  int die = 0;
49 
50  print_pixels = strstr(argv[5], "pixelcmp") ? 1 : 0;
51  dump_blocks = strstr(argv[5], "blockdump") ? 1 : 0;
52 
53  for(i = 0; i < 2; i++) {
54  Y[i] = malloc(lsiz);
55  C[0][i] = malloc(csiz);
56  C[1][i] = malloc(csiz);
57 
58  fd[i] = open(argv[1 + i], O_RDONLY);
59  if(fd[i] == -1) {
60  perror("open");
61  exit(1);
62  }
63  fcntl(fd[i], F_NOCACHE, 1);
64 
65  if (to_skip)
66  lseek(fd[i], to_skip * (lsiz + 2*csiz), SEEK_SET);
67  }
68 
69  mb_x = width / 16;
70  mb_y = height / 16;
71 
72  mberrors = malloc(mb_x * mb_y);
73 
74  while(!die) {
75  memset(mberrors, 0, mb_x * mb_y);
76 
77  printf("Loading frame %d\n", ++fr);
78 
79  for(i = 0; i < 2; i++) {
80  v = read(fd[i], Y[i], lsiz);
81  if(v != lsiz) {
82  fprintf(stderr, "Unable to read Y from file %d, exiting\n", i + 1);
83  return 1;
84  }
85  }
86 
87 
88  for(c = 0; c < lsiz; c++) {
89  if(Y[0][c] != Y[1][c]) {
90  x = c % width;
91  y = c / width;
92 
93  mb = x / 16 + (y / 16) * mb_x;
94 
95  if(print_pixels)
96  printf("Luma diff 0x%02x != 0x%02x at pixel (%4d,%-4d) mb(%d,%d) #%d\n",
97  Y[0][c],
98  Y[1][c],
99  x, y,
100  x / 16,
101  y / 16,
102  mb);
103 
104  mberrors[mb] |= 1;
105  }
106  }
107 
108  /* Chroma planes */
109 
110  for(p = 0; p < 2; p++) {
111 
112  for(i = 0; i < 2; i++) {
113  v = read(fd[i], C[p][i], csiz);
114  if(v != csiz) {
115  fprintf(stderr, "Unable to read %c from file %d, exiting\n",
116  "UV"[p], i + 1);
117  return 1;
118  }
119  }
120 
121  for(c = 0; c < csiz; c++) {
122  if(C[p][0][c] != C[p][1][c]) {
123  x = c % cwidth;
124  y = c / cwidth;
125 
126  mb = x / 8 + (y / 8) * mb_x;
127 
128  mberrors[mb] |= 2 << p;
129 
130  if(print_pixels)
131 
132  printf("c%c diff 0x%02x != 0x%02x at pixel (%4d,%-4d) "
133  "mb(%3d,%-3d) #%d\n",
134  p ? 'r' : 'b',
135  C[p][0][c],
136  C[p][1][c],
137 
138  x, y,
139  x / 8,
140  y / 8,
141  x / 8 + y / 8 * cwidth / 8);
142  }
143  }
144  }
145 
146  for(i = 0; i < mb_x * mb_y; i++) {
147  x = i % mb_x;
148  y = i / mb_x;
149 
150  if(mberrors[i]) {
151  die = 1;
152 
153  printf("MB (%3d,%-3d) %4d %d %c%c%c damaged\n",
154  x, y, i, mberrors[i],
155  mberrors[i] & 1 ? 'Y' : ' ',
156  mberrors[i] & 2 ? 'U' : ' ',
157  mberrors[i] & 4 ? 'V' : ' ');
158 
159  if(dump_blocks) {
160  a = Y[0] + x * 16 + y * 16 * width;
161  b = Y[1] + x * 16 + y * 16 * width;
162 
163  for(y = 0; y < 16; y++) {
164  printf("%c ", "TB"[y&1]);
165  for(x = 0; x < 16; x++)
166  printf("%02x%c", a[x + y * width],
167  a[x + y * width] != b[x + y * width] ? '<' : ' ');
168 
169  printf("| ");
170  for(x = 0; x < 16; x++)
171  printf("%02x%c", b[x + y * width],
172  a[x + y * width] != b[x + y * width] ? '<' : ' ');
173 
174  printf("\n");
175  }
176  }
177  }
178  }
179  }
180 
181  return 0;
182 }
float v
#define C
uint8_t
#define mb
#define Y
Definition: vf_boxblur.c:76
#define b
Definition: input.c:42
Discrete Time axis x
static int width
Definition: tests/utils.c:158
int main(int argc, char **argv)
Definition: yuvcmp.c:16
BYTE int const BYTE int int int height
Definition: avisynth_c.h:713
synthesis window for stochastic i
static double c[64]
function y
Definition: D.m:1
printf("static const uint8_t my_array[100] = {\n")