3 * Copyright (c) 2003 Fabrice Bellard.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 static int sizes[][2] = {
33 static int infer_size(int *width_ptr, int *height_ptr, int size)
37 for(i=0;i<sizeof(sizes)/sizeof(sizes[0]);i++) {
38 if ((sizes[i][0] * sizes[i][1]) == size) {
39 *width_ptr = sizes[i][0];
40 *height_ptr = sizes[i][1];
47 static int yuv_read(ByteIOContext *f,
48 int (*alloc_cb)(void *opaque, AVImageInfo *info), void *opaque)
50 ByteIOContext pb1, *pb = &pb1;
55 AVImageInfo info1, *info = &info1;
57 img_size = url_fsize(f);
61 url_get_filename(h, fname, sizeof(fname));
63 if (infer_size(&info->width, &info->height, img_size) < 0) {
66 info->pix_fmt = PIX_FMT_YUV420P;
68 ret = alloc_cb(opaque, info);
72 size = info->width * info->height;
74 p = strrchr(fname, '.');
75 if (!p || p[1] != 'Y')
78 get_buffer(f, info->pict.data[0], size);
81 if (url_fopen(pb, fname, URL_RDONLY) < 0)
84 get_buffer(pb, info->pict.data[1], size / 4);
88 if (url_fopen(pb, fname, URL_RDONLY) < 0)
91 get_buffer(pb, info->pict.data[2], size / 4);
96 static int yuv_write(ByteIOContext *pb2, AVImageInfo *info)
98 ByteIOContext pb1, *pb;
100 int i, j, width, height;
103 static const char *ext = "YUV";
107 url_get_filename(h, fname, sizeof(fname));
109 p = strrchr(fname, '.');
110 if (!p || p[1] != 'Y')
114 height = info->height;
125 if (url_fopen(pb, fname, URL_WRONLY) < 0)
131 ptr = info->pict.data[i];
132 for(j=0;j<height;j++) {
133 put_buffer(pb, ptr, width);
134 ptr += info->pict.linesize[i];
136 put_flush_packet(pb);
144 static int yuv_probe(AVProbeData *pd)
146 if (match_ext(pd->filename, "Y"))
147 return AVPROBE_SCORE_MAX;
152 AVImageFormat yuv_image_format = {
157 (1 << PIX_FMT_YUV420P),