/* * 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.
*/
for (plane = 0; plane < 3; ++plane) {
uint8_t *ptr; int w = vpx_img_plane_width(yuv_frame, plane); constint h = vpx_img_plane_height(yuv_frame, plane); int r; // Assuming that for nv12 we read all chroma data at once if (yuv_frame->fmt == VPX_IMG_FMT_NV12 && plane > 1) break; // Fixing NV12 chroma width if it is odd if (yuv_frame->fmt == VPX_IMG_FMT_NV12 && plane == 1) w = (w + 1) & ~1; /* Determine the correct plane based on the image format. The for-loop * always counts in Y,U,V order, but this may not match the order of * the data on disk.
*/ switch (plane) { case 1:
ptr =
yuv_frame->planes[yuv_frame->fmt == VPX_IMG_FMT_YV12 ? VPX_PLANE_V
: VPX_PLANE_U]; break; case 2:
ptr =
yuv_frame->planes[yuv_frame->fmt == VPX_IMG_FMT_YV12 ? VPX_PLANE_U
: VPX_PLANE_V]; break; default: ptr = yuv_frame->planes[plane];
}
for (r = 0; r < h; ++r) {
size_t needed = w * bytespp;
size_t buf_position = 0; const size_t left = detect->buf_read - detect->position; if (left > 0) { const size_t more = (left < needed) ? left : needed;
memcpy(ptr, detect->buf + detect->position, more);
buf_position = more;
needed -= more;
detect->position += more;
} if (needed > 0) {
shortread |= (fread(ptr + buf_position, 1, needed, f) < needed);
}
for (plane = 0; plane < 3; ++plane) { constunsignedchar *buf = img->planes[plane]; constint stride = img->stride[plane]; int w = vpx_img_plane_width(img, plane); constint h = vpx_img_plane_height(img, plane); int y;
// Assuming that for nv12 we write all chroma data at once if (img->fmt == VPX_IMG_FMT_NV12 && plane > 1) break; // Fixing NV12 chroma width if it is odd if (img->fmt == VPX_IMG_FMT_NV12 && plane == 1) w = (w + 1) & ~1;
for (y = 0; y < h; ++y) {
fwrite(buf, bytespp, w, file);
buf += stride;
}
}
}
int vpx_img_read(vpx_image_t *img, FILE *file) { int plane; constint bytespp = (img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? 2 : 1;
for (plane = 0; plane < 3; ++plane) { unsignedchar *buf = img->planes[plane]; constint stride = img->stride[plane]; int w = vpx_img_plane_width(img, plane); constint h = vpx_img_plane_height(img, plane); int y;
// Assuming that for nv12 we read all chroma data at once if (img->fmt == VPX_IMG_FMT_NV12 && plane > 1) break; // Fixing NV12 chroma width if it is odd if (img->fmt == VPX_IMG_FMT_NV12 && plane == 1) w = (w + 1) & ~1;
for (y = 0; y < h; ++y) { if (fread(buf, bytespp, w, file) != (size_t)w) return 0;
buf += stride;
}
}
int file_is_y4m(constchar detect[4]) { if (memcmp(detect, "YUV4", 4) == 0) { return 1;
} return 0;
}
int fourcc_is_ivf(constchar detect[4]) { if (memcmp(detect, "DKIF", 4) == 0) { return 1;
} return 0;
}
void open_input_file(struct VpxInputContext *input) { /* Parse certain options from the input file, if possible */
input->file = strcmp(input->filename, "-") ? fopen(input->filename, "rb")
: set_binary_mode(stdin);
if (!input->file) fatal("Failed to open input file");
if (!fseeko(input->file, 0, SEEK_END)) { /* Input file is seekable. Figure out how long it is, so we can get * progress info.
*/
input->length = ftello(input->file);
rewind(input->file);
}
/* For RAW input sources, these bytes will applied on the first frame * in read_frame().
*/
input->detect.buf_read = fread(input->detect.buf, 1, 4, input->file);
input->detect.position = 0;
match &= (img1->fmt == img2->fmt);
match &= (img1->d_w == img2->d_w);
match &= (img1->d_h == img2->d_h); #if CONFIG_VP9_HIGHBITDEPTH if (img1->fmt & VPX_IMG_FMT_HIGHBITDEPTH) {
l_w *= 2;
c_w *= 2;
} #endif
for (i = 0; i < img1->d_h; ++i)
match &= (memcmp(img1->planes[VPX_PLANE_Y] + i * img1->stride[VPX_PLANE_Y],
img2->planes[VPX_PLANE_Y] + i * img2->stride[VPX_PLANE_Y],
l_w) == 0);
for (i = 0; i < c_h; ++i)
match &= (memcmp(img1->planes[VPX_PLANE_U] + i * img1->stride[VPX_PLANE_U],
img2->planes[VPX_PLANE_U] + i * img2->stride[VPX_PLANE_U],
c_w) == 0);
for (i = 0; i < c_h; ++i)
match &= (memcmp(img1->planes[VPX_PLANE_V] + i * img1->stride[VPX_PLANE_V],
img2->planes[VPX_PLANE_V] + i * img2->stride[VPX_PLANE_V],
c_w) == 0);
return match;
}
#define mmin(a, b) ((a) < (b) ? (a) : (b))
#if CONFIG_VP9_HIGHBITDEPTH void find_mismatch_high(const vpx_image_t *const img1, const vpx_image_t *const img2, int yloc[4], int uloc[4], int vloc[4]) {
uint16_t *plane1, *plane2;
uint32_t stride1, stride2; const uint32_t bsize = 64; const uint32_t bsizey = bsize >> img1->y_chroma_shift; const uint32_t bsizex = bsize >> img1->x_chroma_shift; const uint32_t c_w =
(img1->d_w + img1->x_chroma_shift) >> img1->x_chroma_shift; const uint32_t c_h =
(img1->d_h + img1->y_chroma_shift) >> img1->y_chroma_shift; int match = 1;
uint32_t i, j;
yloc[0] = yloc[1] = yloc[2] = yloc[3] = -1;
plane1 = (uint16_t *)img1->planes[VPX_PLANE_Y];
plane2 = (uint16_t *)img2->planes[VPX_PLANE_Y];
stride1 = img1->stride[VPX_PLANE_Y] / 2;
stride2 = img2->stride[VPX_PLANE_Y] / 2; for (i = 0, match = 1; match && i < img1->d_h; i += bsize) { for (j = 0; match && j < img1->d_w; j += bsize) { int k, l; constint si = mmin(i + bsize, img1->d_h) - i; constint sj = mmin(j + bsize, img1->d_w) - j; for (k = 0; match && k < si; ++k) { for (l = 0; match && l < sj; ++l) { if (*(plane1 + (i + k) * stride1 + j + l) !=
*(plane2 + (i + k) * stride2 + j + l)) {
yloc[0] = i + k;
yloc[1] = j + l;
yloc[2] = *(plane1 + (i + k) * stride1 + j + l);
yloc[3] = *(plane2 + (i + k) * stride2 + j + l);
match = 0; break;
}
}
}
}
}
uloc[0] = uloc[1] = uloc[2] = uloc[3] = -1;
plane1 = (uint16_t *)img1->planes[VPX_PLANE_U];
plane2 = (uint16_t *)img2->planes[VPX_PLANE_U];
stride1 = img1->stride[VPX_PLANE_U] / 2;
stride2 = img2->stride[VPX_PLANE_U] / 2; for (i = 0, match = 1; match && i < c_h; i += bsizey) { for (j = 0; match && j < c_w; j += bsizex) { int k, l; constint si = mmin(i + bsizey, c_h - i); constint sj = mmin(j + bsizex, c_w - j); for (k = 0; match && k < si; ++k) { for (l = 0; match && l < sj; ++l) { if (*(plane1 + (i + k) * stride1 + j + l) !=
*(plane2 + (i + k) * stride2 + j + l)) {
uloc[0] = i + k;
uloc[1] = j + l;
uloc[2] = *(plane1 + (i + k) * stride1 + j + l);
uloc[3] = *(plane2 + (i + k) * stride2 + j + l);
match = 0; break;
}
}
}
}
}
vloc[0] = vloc[1] = vloc[2] = vloc[3] = -1;
plane1 = (uint16_t *)img1->planes[VPX_PLANE_V];
plane2 = (uint16_t *)img2->planes[VPX_PLANE_V];
stride1 = img1->stride[VPX_PLANE_V] / 2;
stride2 = img2->stride[VPX_PLANE_V] / 2; for (i = 0, match = 1; match && i < c_h; i += bsizey) { for (j = 0; match && j < c_w; j += bsizex) { int k, l; constint si = mmin(i + bsizey, c_h - i); constint sj = mmin(j + bsizex, c_w - j); for (k = 0; match && k < si; ++k) { for (l = 0; match && l < sj; ++l) { if (*(plane1 + (i + k) * stride1 + j + l) !=
*(plane2 + (i + k) * stride2 + j + l)) {
vloc[0] = i + k;
vloc[1] = j + l;
vloc[2] = *(plane1 + (i + k) * stride1 + j + l);
vloc[3] = *(plane2 + (i + k) * stride2 + j + l);
match = 0; break;
}
}
}
}
}
} #endif// CONFIG_VP9_HIGHBITDEPTH
void find_mismatch(const vpx_image_t *const img1, const vpx_image_t *const img2, int yloc[4], int uloc[4], int vloc[4]) { const uint32_t bsize = 64; const uint32_t bsizey = bsize >> img1->y_chroma_shift; const uint32_t bsizex = bsize >> img1->x_chroma_shift; const uint32_t c_w =
(img1->d_w + img1->x_chroma_shift) >> img1->x_chroma_shift; const uint32_t c_h =
(img1->d_h + img1->y_chroma_shift) >> img1->y_chroma_shift; int match = 1;
uint32_t i, j;
yloc[0] = yloc[1] = yloc[2] = yloc[3] = -1; for (i = 0, match = 1; match && i < img1->d_h; i += bsize) { for (j = 0; match && j < img1->d_w; j += bsize) { int k, l; constint si = mmin(i + bsize, img1->d_h) - i; constint sj = mmin(j + bsize, img1->d_w) - j; for (k = 0; match && k < si; ++k) { for (l = 0; match && l < sj; ++l) { if (*(img1->planes[VPX_PLANE_Y] +
(i + k) * img1->stride[VPX_PLANE_Y] + j + l) !=
*(img2->planes[VPX_PLANE_Y] +
(i + k) * img2->stride[VPX_PLANE_Y] + j + l)) {
yloc[0] = i + k;
yloc[1] = j + l;
yloc[2] = *(img1->planes[VPX_PLANE_Y] +
(i + k) * img1->stride[VPX_PLANE_Y] + j + l);
yloc[3] = *(img2->planes[VPX_PLANE_Y] +
(i + k) * img2->stride[VPX_PLANE_Y] + j + l);
match = 0; break;
}
}
}
}
}
uloc[0] = uloc[1] = uloc[2] = uloc[3] = -1; for (i = 0, match = 1; match && i < c_h; i += bsizey) { for (j = 0; match && j < c_w; j += bsizex) { int k, l; constint si = mmin(i + bsizey, c_h - i); constint sj = mmin(j + bsizex, c_w - j); for (k = 0; match && k < si; ++k) { for (l = 0; match && l < sj; ++l) { if (*(img1->planes[VPX_PLANE_U] +
(i + k) * img1->stride[VPX_PLANE_U] + j + l) !=
*(img2->planes[VPX_PLANE_U] +
(i + k) * img2->stride[VPX_PLANE_U] + j + l)) {
uloc[0] = i + k;
uloc[1] = j + l;
uloc[2] = *(img1->planes[VPX_PLANE_U] +
(i + k) * img1->stride[VPX_PLANE_U] + j + l);
uloc[3] = *(img2->planes[VPX_PLANE_U] +
(i + k) * img2->stride[VPX_PLANE_U] + j + l);
match = 0; break;
}
}
}
}
}
vloc[0] = vloc[1] = vloc[2] = vloc[3] = -1; for (i = 0, match = 1; match && i < c_h; i += bsizey) { for (j = 0; match && j < c_w; j += bsizex) { int k, l; constint si = mmin(i + bsizey, c_h - i); constint sj = mmin(j + bsizex, c_w - j); for (k = 0; match && k < si; ++k) { for (l = 0; match && l < sj; ++l) { if (*(img1->planes[VPX_PLANE_V] +
(i + k) * img1->stride[VPX_PLANE_V] + j + l) !=
*(img2->planes[VPX_PLANE_V] +
(i + k) * img2->stride[VPX_PLANE_V] + j + l)) {
vloc[0] = i + k;
vloc[1] = j + l;
vloc[2] = *(img1->planes[VPX_PLANE_V] +
(i + k) * img1->stride[VPX_PLANE_V] + j + l);
vloc[3] = *(img2->planes[VPX_PLANE_V] +
(i + k) * img2->stride[VPX_PLANE_V] + j + l);
match = 0; break;
}
}
}
}
}
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.