const char *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";
}
}
int read_yuv_frame(struct AvxInputContext *input_ctx, aom_image_t *yuv_frame) {
FILE *f = input_ctx->file; struct FileTypeDetectionBuffer *detect = &input_ctx->detect;
int plane = 0;
int shortread = 0; const int bytespp = (yuv_frame->fmt & AOM_IMG_FMT_HIGHBITDEPTH) ? 2 : 1;
for (plane = 0; plane < 3; ++plane) {
uint8_t *ptr;
int w = aom_img_plane_width(yuv_frame, plane); const int 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 *alwayscountsinY,U,Vorder,butthismaynotmatchtheorderof *thedataondisk.
*/ switch (plane) { case1:
ptr =
yuv_frame->planes[yuv_frame->fmt == AOM_IMG_FMT_YV12 ? AOM_PLANE_V
: AOM_PLANE_U]; break; case2:
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); const char *short_name;
uint32_t fourcc;
};
aom_codec_iface_t *get_aom_decoder_by_short_name(const char *name) {
for (int i = 0; i < get_aom_decoder_count(); ++i) { conststruct CodecInfo *info = &aom_decoders[i];
if (strcmp(info->short_name, name) == 0) return info->interface();
} return NULL;
}
aom_codec_iface_t *get_aom_decoder_by_fourcc(uint32_t fourcc) {
for (int i = 0; i < get_aom_decoder_count(); ++i) { conststruct CodecInfo *info = &aom_decoders[i];
if (info->fourcc == fourcc) return info->interface();
} return NULL;
}
const char *get_short_name_by_aom_decoder(aom_codec_iface_t *iface) {
for (int i = 0; i < get_aom_decoder_count(); ++i) { conststruct CodecInfo *info = &aom_decoders[i];
if (info->interface() == iface) { return info->short_name;
}
} return NULL;
}
uint32_t get_fourcc_by_aom_decoder(aom_codec_iface_t *iface) {
for (int i = 0; i < get_aom_decoder_count(); ++i) { conststruct CodecInfo *info = &aom_decoders[i];
if (info->interface() == iface) { return info->fourcc;
}
} return0;
}
#endif// CONFIG_AV1_DECODER
void aom_img_write(const aom_image_t *img, FILE *file) {
int plane; const int bytespp = (img->fmt & AOM_IMG_FMT_HIGHBITDEPTH) ? 2 : 1;
for (plane = 0; plane < 3; ++plane) { constunsigned char *buf = img->planes[plane]; const int stride = img->stride[plane];
int w = aom_img_plane_width(img, plane); const int 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;
}
}
}
bool aom_img_read(aom_image_t *img, FILE *file) {
int plane; const int bytespp = (img->fmt & AOM_IMG_FMT_HIGHBITDEPTH) ? 2 : 1;
for (plane = 0; plane < 3; ++plane) { unsigned char *buf = img->planes[plane]; const int stride = img->stride[plane];
int w = aom_img_plane_width(img, plane); const int 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) return false;
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 constunsigned char *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 constunsigned char *ubuf = img->planes[1]; constunsigned char *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;
} else if (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, unsigned char *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.