/* * Copyright (c) 2016, Alliance for Open Media. All rights reserved. * * This source code is subject to the terms of the BSD 2 Clause License and * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License * was not distributed with this source code in the LICENSE file, you can * obtain it at www.aomedia.org/license/software. If the Alliance for Open * Media Patent License 1.0 was not distributed with this source code in the * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/
constchar *image_format_to_string(aom_img_fmt_t fmt) { switch (fmt) { case AOM_IMG_FMT_I420: return"I420"; case AOM_IMG_FMT_I422: return"I422"; case AOM_IMG_FMT_I444: return"I444"; case AOM_IMG_FMT_YV12: return"YV12"; case AOM_IMG_FMT_NV12: return"NV12"; case AOM_IMG_FMT_YV1216: return"YV1216"; case AOM_IMG_FMT_I42016: return"I42016"; case AOM_IMG_FMT_I42216: return"I42216"; case AOM_IMG_FMT_I44416: return"I44416"; default: return"Other";
}
}
for (plane = 0; plane < 3; ++plane) {
uint8_t *ptr; int w = aom_img_plane_width(yuv_frame, plane); constint h = aom_img_plane_height(yuv_frame, plane); int r; // Assuming that for nv12 we read all chroma data at once if (yuv_frame->fmt == AOM_IMG_FMT_NV12 && plane > 1) break; if (yuv_frame->fmt == AOM_IMG_FMT_NV12 && plane == 1) w *= 2; /* 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 == AOM_IMG_FMT_YV12 ? AOM_PLANE_V
: AOM_PLANE_U]; break; case 2:
ptr =
yuv_frame->planes[yuv_frame->fmt == AOM_IMG_FMT_YV12 ? AOM_PLANE_U
: AOM_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);
}
ptr += yuv_frame->stride[plane];
}
}
return shortread;
}
struct CodecInfo { // Pointer to a function of zero arguments that returns an aom_codec_iface_t.
aom_codec_iface_t *(*interface)(void); constchar *short_name;
uint32_t fourcc;
};
for (plane = 0; plane < 3; ++plane) { constunsignedchar *buf = img->planes[plane]; constint stride = img->stride[plane]; int w = aom_img_plane_width(img, plane); constint h = aom_img_plane_height(img, plane); int y;
// Assuming that for nv12 we write all chroma data at once if (img->fmt == AOM_IMG_FMT_NV12 && plane > 1) break; if (img->fmt == AOM_IMG_FMT_NV12 && plane == 1) w *= 2;
for (y = 0; y < h; ++y) {
fwrite(buf, bytespp, w, file);
buf += stride;
}
}
}
for (plane = 0; plane < 3; ++plane) { unsignedchar *buf = img->planes[plane]; constint stride = img->stride[plane]; int w = aom_img_plane_width(img, plane); constint h = aom_img_plane_height(img, plane); int y;
// Assuming that for nv12 we read all chroma data at once if (img->fmt == AOM_IMG_FMT_NV12 && plane > 1) break; if (img->fmt == AOM_IMG_FMT_NV12 && plane == 1) w *= 2;
for (y = 0; y < h; ++y) { if (fread(buf, bytespp, w, file) != (size_t)w) returnfalse;
buf += stride;
}
}
// Related to I420, NV12 format has one luma "luminance" plane Y and one plane // with U and V values interleaved. void aom_img_write_nv12(const aom_image_t *img, FILE *file) { // Y plane constunsignedchar *buf = img->planes[0]; int stride = img->stride[0]; int w = aom_img_plane_width(img, 0) *
((img->fmt & AOM_IMG_FMT_HIGHBITDEPTH) ? 2 : 1); int h = aom_img_plane_height(img, 0); int x, y;
for (y = 0; y < h; ++y) {
fwrite(buf, 1, w, file);
buf += stride;
}
// Interleaved U and V plane constunsignedchar *ubuf = img->planes[1]; constunsignedchar *vbuf = img->planes[2]; const size_t size = (img->fmt & AOM_IMG_FMT_HIGHBITDEPTH) ? 2 : 1;
stride = img->stride[1];
w = aom_img_plane_width(img, 1);
h = aom_img_plane_height(img, 1);
for (y = 0; y < h; ++y) { for (x = 0; x < w; ++x) {
fwrite(ubuf, size, 1, file);
fwrite(vbuf, size, 1, file);
ubuf += size;
vbuf += size;
}
ubuf += (stride - w * size);
vbuf += (stride - w * size);
}
}
size_t input_to_detect_buf(struct AvxInputContext *input_ctx, size_t n) { if (n + input_ctx->detect.position > DETECT_BUF_SZ) {
die("Failed to store in the detect buffer, maximum size exceeded.");
} const size_t buffered_bytes =
input_ctx->detect.buf_read - input_ctx->detect.position;
size_t read_n; if (buffered_bytes == 0) {
read_n = fread(input_ctx->detect.buf + input_ctx->detect.buf_read, 1, n,
input_ctx->file);
input_ctx->detect.buf_read += read_n;
} elseif (n <= buffered_bytes) { // In this case, don't need to do anything as the data is already in // the detect buffer
read_n = n;
} else {
read_n = fread(input_ctx->detect.buf + input_ctx->detect.buf_read, 1,
n - buffered_bytes, input_ctx->file);
input_ctx->detect.buf_read += read_n;
read_n += buffered_bytes;
} return read_n;
}
// Read from detect buffer to a buffer. If not enough, read from input and also // buffer them first.
size_t buffer_input(struct AvxInputContext *input_ctx, size_t n, unsignedchar *buf, bool buffered) { if (!buffered) { return read_from_input(input_ctx, n, buf);
} const size_t buf_n = input_to_detect_buf(input_ctx, n); if (buf_n < n) { return buf_n;
} return read_from_input(input_ctx, n, buf);
}
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.