]> rtime.felk.cvut.cz Git - frescor/ffmpeg.git/blob - libavfilter/formats.c
10l. parameter was unused and redundant.
[frescor/ffmpeg.git] / libavfilter / formats.c
1 /*
2  * Filter layer - format negotiation
3  * copyright (c) 2007 Bobby Bingham
4  *
5  * This file is part of FFmpeg.
6  *
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.
11  *
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.
16  *
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
20  */
21
22 #include "avfilter.h"
23
24 AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b)
25 {
26     AVFilterFormats *ret;
27     unsigned i, j, k = 0;
28
29     ret = av_mallocz(sizeof(AVFilterFormats));
30
31     /* merge list of formats */
32     ret->formats = av_malloc(sizeof(int) * FFMIN(a->format_count,
33                                                  b->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];
38
39     /* check that there was at least one common format */
40     if(!(ret->format_count = k)) {
41         av_free(ret->formats);
42         av_free(ret);
43         return NULL;
44     }
45
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;
51     }
52     for(i = 0; i < b->refcount; i ++) {
53         ret->refs[ret->refcount] = b->refs[i];
54         *ret->refs[ret->refcount++] = ret;
55     }
56
57     av_free(a->refs);
58     av_free(a->formats);
59     av_free(a);
60
61     av_free(b->refs);
62     av_free(b->formats);
63     av_free(b);
64
65     return ret;
66 }
67
68 AVFilterFormats *avfilter_make_format_list(int len, ...)
69 {
70     AVFilterFormats *ret;
71     int i;
72     va_list vl;
73
74     ret = av_mallocz(sizeof(AVFilterFormats));
75     ret->formats = av_malloc(sizeof(int) * len);
76     ret->format_count = len;
77
78     va_start(vl, len);
79     for(i = 0; i < len; i ++)
80         ret->formats[i] = va_arg(vl, int);
81     va_end(vl);
82
83     return ret;
84 }
85
86 AVFilterFormats *avfilter_all_colorspaces(void)
87 {
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);
103 }
104
105 void avfilter_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
106 {
107     *ref = f;
108     f->refs = av_realloc(f->refs, sizeof(AVFilterFormats**) * ++f->refcount);
109     f->refs[f->refcount-1] = ref;
110 }
111
112 static int find_ref_index(AVFilterFormats **ref)
113 {
114     int i;
115     for(i = 0; i < (*ref)->refcount; i ++)
116         if((*ref)->refs[i] == ref)
117             return i;
118     return -1;
119 }
120
121 void avfilter_formats_unref(AVFilterFormats **ref)
122 {
123     int idx;
124
125     if((idx = find_ref_index(ref)) >= 0)
126         memmove((*ref)->refs + idx, (*ref)->refs + idx+1,
127             sizeof(AVFilterFormats**) * ((*ref)->refcount-idx-1));
128
129     if(!--(*ref)->refcount) {
130         av_free((*ref)->formats);
131         av_free((*ref)->refs);
132         av_free(*ref);
133     }
134     *ref = NULL;
135 }
136