3 * Copyright (c) 2003 Fabrice Bellard.
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 static int sizes[][2] = {
35 static int infer_size(int *width_ptr, int *height_ptr, int size)
39 for(i=0;i<sizeof(sizes)/sizeof(sizes[0]);i++) {
40 if ((sizes[i][0] * sizes[i][1]) == size) {
41 *width_ptr = sizes[i][0];
42 *height_ptr = sizes[i][1];
49 static int yuv_read(ByteIOContext *f,
50 int (*alloc_cb)(void *opaque, AVImageInfo *info), void *opaque)
52 ByteIOContext pb1, *pb = &pb1;
57 AVImageInfo info1, *info = &info1;
59 img_size = url_fsize(f);
63 url_get_filename(h, fname, sizeof(fname));
65 if (infer_size(&info->width, &info->height, img_size) < 0) {
68 info->pix_fmt = PIX_FMT_YUV420P;
70 ret = alloc_cb(opaque, info);
74 size = info->width * info->height;
76 p = strrchr(fname, '.');
77 if (!p || p[1] != 'Y')
80 get_buffer(f, info->pict.data[0], size);
83 if (url_fopen(pb, fname, URL_RDONLY) < 0)
86 get_buffer(pb, info->pict.data[1], size / 4);
90 if (url_fopen(pb, fname, URL_RDONLY) < 0)
93 get_buffer(pb, info->pict.data[2], size / 4);
98 static int yuv_write(ByteIOContext *pb2, AVImageInfo *info)
100 ByteIOContext pb1, *pb;
101 char fname[1024], *p;
102 int i, j, width, height;
105 static const char *ext = "YUV";
109 url_get_filename(h, fname, sizeof(fname));
111 p = strrchr(fname, '.');
112 if (!p || p[1] != 'Y')
116 height = info->height;
127 if (url_fopen(pb, fname, URL_WRONLY) < 0)
133 ptr = info->pict.data[i];
134 for(j=0;j<height;j++) {
135 put_buffer(pb, ptr, width);
136 ptr += info->pict.linesize[i];
138 put_flush_packet(pb);
146 static int yuv_probe(AVProbeData *pd)
148 if (match_ext(pd->filename, "Y"))
149 return AVPROBE_SCORE_MAX;
154 AVImageFormat yuv_image_format = {
159 (1 << PIX_FMT_YUV420P),