00001
00002
00003
00004
00005
00006 #include <string.h>
00007 #include <stdlib.h>
00008 #include <inttypes.h>
00009 #include <stdio.h>
00010 #include <sys/stat.h>
00011 #include <fcntl.h>
00012 #include <unistd.h>
00013
00014
00015 int
00016 main(int argc, char **argv)
00017 {
00018 int fd[2];
00019 int print_pixels = 0;
00020 int dump_blocks = 0;
00021
00022 int width;
00023 int height;
00024 int to_skip = 0;
00025
00026 if (argc < 6) {
00027 fprintf(stderr, "%s [YUV file 1] [YUV file 2] width height pixelcmp|blockdump (# to skip)\n", argv[0]);
00028 return 1;
00029 }
00030
00031 width = atoi(argv[3]);
00032 height = atoi(argv[4]);
00033 if (argc > 6)
00034 to_skip = atoi(argv[6]);
00035
00036 uint8_t *Y[2], *C[2][2];
00037 int i, v, c, p;
00038 int lsiz = width * height;
00039 int csiz = width * height / 4;
00040 int x, y;
00041 int cwidth = width / 2;
00042 int fr = to_skip;
00043 int mb;
00044 char *mberrors;
00045 int mb_x, mb_y;
00046 uint8_t *a;
00047 uint8_t *b;
00048 int die = 0;
00049
00050 print_pixels = strstr(argv[5], "pixelcmp") ? 1 : 0;
00051 dump_blocks = strstr(argv[5], "blockdump") ? 1 : 0;
00052
00053 for(i = 0; i < 2; i++) {
00054 Y[i] = malloc(lsiz);
00055 C[0][i] = malloc(csiz);
00056 C[1][i] = malloc(csiz);
00057
00058 fd[i] = open(argv[1 + i], O_RDONLY);
00059 if(fd[i] == -1) {
00060 perror("open");
00061 exit(1);
00062 }
00063 fcntl(fd[i], F_NOCACHE, 1);
00064
00065 if (to_skip)
00066 lseek(fd[i], to_skip * (lsiz + 2*csiz), SEEK_SET);
00067 }
00068
00069 mb_x = width / 16;
00070 mb_y = height / 16;
00071
00072 mberrors = malloc(mb_x * mb_y);
00073
00074 while(!die) {
00075 memset(mberrors, 0, mb_x * mb_y);
00076
00077 printf("Loading frame %d\n", ++fr);
00078
00079 for(i = 0; i < 2; i++) {
00080 v = read(fd[i], Y[i], lsiz);
00081 if(v != lsiz) {
00082 fprintf(stderr, "Unable to read Y from file %d, exiting\n", i + 1);
00083 return 1;
00084 }
00085 }
00086
00087
00088 for(c = 0; c < lsiz; c++) {
00089 if(Y[0][c] != Y[1][c]) {
00090 x = c % width;
00091 y = c / width;
00092
00093 mb = x / 16 + (y / 16) * mb_x;
00094
00095 if(print_pixels)
00096 printf("Luma diff 0x%02x != 0x%02x at pixel (%4d,%-4d) mb(%d,%d) #%d\n",
00097 Y[0][c],
00098 Y[1][c],
00099 x, y,
00100 x / 16,
00101 y / 16,
00102 mb);
00103
00104 mberrors[mb] |= 1;
00105 }
00106 }
00107
00108
00109
00110 for(p = 0; p < 2; p++) {
00111
00112 for(i = 0; i < 2; i++) {
00113 v = read(fd[i], C[p][i], csiz);
00114 if(v != csiz) {
00115 fprintf(stderr, "Unable to read %c from file %d, exiting\n",
00116 "UV"[p], i + 1);
00117 return 1;
00118 }
00119 }
00120
00121 for(c = 0; c < csiz; c++) {
00122 if(C[p][0][c] != C[p][1][c]) {
00123 x = c % cwidth;
00124 y = c / cwidth;
00125
00126 mb = x / 8 + (y / 8) * mb_x;
00127
00128 mberrors[mb] |= 2 << p;
00129
00130 if(print_pixels)
00131
00132 printf("c%c diff 0x%02x != 0x%02x at pixel (%4d,%-4d) "
00133 "mb(%3d,%-3d) #%d\n",
00134 p ? 'r' : 'b',
00135 C[p][0][c],
00136 C[p][1][c],
00137
00138 x, y,
00139 x / 8,
00140 y / 8,
00141 x / 8 + y / 8 * cwidth / 8);
00142 }
00143 }
00144 }
00145
00146 for(i = 0; i < mb_x * mb_y; i++) {
00147 x = i % mb_x;
00148 y = i / mb_x;
00149
00150 if(mberrors[i]) {
00151 die = 1;
00152
00153 printf("MB (%3d,%-3d) %4d %d %c%c%c damaged\n",
00154 x, y, i, mberrors[i],
00155 mberrors[i] & 1 ? 'Y' : ' ',
00156 mberrors[i] & 2 ? 'U' : ' ',
00157 mberrors[i] & 4 ? 'V' : ' ');
00158
00159 if(dump_blocks) {
00160 a = Y[0] + x * 16 + y * 16 * width;
00161 b = Y[1] + x * 16 + y * 16 * width;
00162
00163 for(y = 0; y < 16; y++) {
00164 printf("%c ", "TB"[y&1]);
00165 for(x = 0; x < 16; x++)
00166 printf("%02x%c", a[x + y * width],
00167 a[x + y * width] != b[x + y * width] ? '<' : ' ');
00168
00169 printf("| ");
00170 for(x = 0; x < 16; x++)
00171 printf("%02x%c", b[x + y * width],
00172 a[x + y * width] != b[x + y * width] ? '<' : ' ');
00173
00174 printf("\n");
00175 }
00176 }
00177 }
00178 }
00179 }
00180
00181 return 0;
00182 }