2 * Filter layer - format negotiation
3 * copyright (c) 2007 Bobby Bingham
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
24 AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b)
29 ret = av_mallocz(sizeof(AVFilterFormats));
31 /* merge list of formats */
32 ret->formats = av_malloc(sizeof(int) * FFMIN(a->format_count,
34 for(i = 0; i < a->format_count; i ++)
35 for(j = 0; j < b->format_count; j ++)
36 if(a->formats[i] == b->formats[j])
37 ret->formats[k++] = a->formats[i];
39 /* check that there was at least one common format */
40 if(!(ret->format_count = k)) {
41 av_free(ret->formats);
46 /* merge and update all the references */
47 ret->refs = av_malloc(sizeof(AVFilterFormats**)*(a->refcount+b->refcount));
48 for(i = 0; i < a->refcount; i ++) {
49 ret->refs[ret->refcount] = a->refs[i];
50 *ret->refs[ret->refcount++] = ret;
52 for(i = 0; i < b->refcount; i ++) {
53 ret->refs[ret->refcount] = b->refs[i];
54 *ret->refs[ret->refcount++] = ret;
68 AVFilterFormats *avfilter_make_format_list(int len, ...)
74 ret = av_mallocz(sizeof(AVFilterFormats));
75 ret->formats = av_malloc(sizeof(int) * len);
76 ret->format_count = len;
79 for(i = 0; i < len; i ++)
80 ret->formats[i] = va_arg(vl, int);
86 AVFilterFormats *avfilter_all_colorspaces(void)
88 return avfilter_make_format_list(31,
89 PIX_FMT_YUV444P, PIX_FMT_YUV422P, PIX_FMT_YUV420P,
90 PIX_FMT_YUV411P, PIX_FMT_YUV410P,
91 PIX_FMT_YUYV422, PIX_FMT_UYVY422, PIX_FMT_UYYVYY411,
92 PIX_FMT_YUVJ444P, PIX_FMT_YUVJ422P, PIX_FMT_YUVJ420P,
93 PIX_FMT_YUV440P, PIX_FMT_YUVJ440P,
94 PIX_FMT_RGB32, PIX_FMT_BGR32,
95 PIX_FMT_RGB32_1, PIX_FMT_BGR32_1,
96 PIX_FMT_RGB24, PIX_FMT_BGR24,
97 PIX_FMT_RGB565, PIX_FMT_BGR565,
98 PIX_FMT_RGB555, PIX_FMT_BGR555,
99 PIX_FMT_RGB8, PIX_FMT_BGR8,
100 PIX_FMT_RGB4_BYTE,PIX_FMT_BGR4_BYTE,
101 PIX_FMT_GRAY16BE, PIX_FMT_GRAY16LE,
102 PIX_FMT_GRAY8, PIX_FMT_PAL8);
105 void avfilter_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
108 f->refs = av_realloc(f->refs, sizeof(AVFilterFormats**) * ++f->refcount);
109 f->refs[f->refcount-1] = ref;
112 static int find_ref_index(AVFilterFormats **ref)
115 for(i = 0; i < (*ref)->refcount; i ++)
116 if((*ref)->refs[i] == ref)
121 void avfilter_formats_unref(AVFilterFormats **ref)
125 if((idx = find_ref_index(ref)) >= 0)
126 memmove((*ref)->refs + idx, (*ref)->refs + idx+1,
127 sizeof(AVFilterFormats**) * ((*ref)->refcount-idx-1));
129 if(!--(*ref)->refcount) {
130 av_free((*ref)->formats);
131 av_free((*ref)->refs);