2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
11 #include "tools_common.h"
18 #if defined(_WIN32) || defined(__OS2__)
23 #define _setmode setmode
24 #define _fileno fileno
25 #define _O_BINARY O_BINARY
29 #define LOG_ERROR(label) do {\
30 const char *l = label;\
34 fprintf(stderr, "%s: ", l);\
35 vfprintf(stderr, fmt, ap);\
36 fprintf(stderr, "\n");\
41 FILE *set_binary_mode(FILE *stream) {
43 #if defined(_WIN32) || defined(__OS2__)
44 _setmode(_fileno(stream), _O_BINARY);
49 void die(const char *fmt, ...) {
54 void fatal(const char *fmt, ...) {
59 void warn(const char *fmt, ...) {
63 uint16_t mem_get_le16(const void *data) {
65 const uint8_t *mem = (const uint8_t*)data;
72 uint32_t mem_get_le32(const void *data) {
74 const uint8_t *mem = (const uint8_t*)data;
83 int read_yuv_frame(struct VpxInputContext *input_ctx, vpx_image_t *yuv_frame) {
84 FILE *f = input_ctx->file;
85 struct FileTypeDetectionBuffer *detect = &input_ctx->detect;
89 for (plane = 0; plane < 3; ++plane) {
91 const int w = (plane ? (1 + yuv_frame->d_w) / 2 : yuv_frame->d_w);
92 const int h = (plane ? (1 + yuv_frame->d_h) / 2 : yuv_frame->d_h);
95 /* Determine the correct plane based on the image format. The for-loop
96 * always counts in Y,U,V order, but this may not match the order of
101 ptr = yuv_frame->planes[
102 yuv_frame->fmt == VPX_IMG_FMT_YV12 ? VPX_PLANE_V : VPX_PLANE_U];
105 ptr = yuv_frame->planes[
106 yuv_frame->fmt == VPX_IMG_FMT_YV12 ? VPX_PLANE_U : VPX_PLANE_V];
109 ptr = yuv_frame->planes[plane];
112 for (r = 0; r < h; ++r) {
114 size_t buf_position = 0;
115 const size_t left = detect->buf_read - detect->position;
117 const size_t more = (left < needed) ? left : needed;
118 memcpy(ptr, detect->buf + detect->position, more);
121 detect->position += more;
124 shortread |= (fread(ptr + buf_position, 1, needed, f) < needed);
127 ptr += yuv_frame->stride[plane];