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;
59 img_size = url_seek(h, 0, SEEK_END);
60 url_get_filename(h, fname, sizeof(fname));
62 if (infer_size(&info->width, &info->height, img_size) < 0) {
65 info->pix_fmt = PIX_FMT_YUV420P;
67 ret = alloc_cb(opaque, info);
71 size = info->width * info->height;
73 p = strrchr(fname, '.');
74 if (!p || p[1] != 'Y')
77 get_buffer(f, info->pict.data[0], size);
80 if (url_fopen(pb, fname, URL_RDONLY) < 0)
83 get_buffer(pb, info->pict.data[1], size / 4);
87 if (url_fopen(pb, fname, URL_RDONLY) < 0)
90 get_buffer(pb, info->pict.data[2], size / 4);
95 static int yuv_write(ByteIOContext *pb2, AVImageInfo *info)
97 ByteIOContext pb1, *pb;
99 int i, j, width, height;
102 static const char *ext = "YUV";
106 url_get_filename(h, fname, sizeof(fname));
108 p = strrchr(fname, '.');
109 if (!p || p[1] != 'Y')
113 height = info->height;
124 if (url_fopen(pb, fname, URL_WRONLY) < 0)
130 ptr = info->pict.data[i];
131 for(j=0;j<height;j++) {
132 put_buffer(pb, ptr, width);
133 ptr += info->pict.linesize[i];
135 put_flush_packet(pb);
143 static int yuv_probe(AVProbeData *pd)
145 if (match_ext(pd->filename, "Y"))
146 return AVPROBE_SCORE_MAX;
151 AVImageFormat yuv_image_format = {
156 (1 << PIX_FMT_YUV420P),