doxygen: add newline after \file
[blender.git] / source / blender / avi / intern / avi_codecs.c
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19
20 /** \file
21  * \ingroup avi
22  *
23  * This is external code. Identify and convert different avi-files.
24  */
25
26
27 #include "AVI_avi.h"
28 #include "avi_intern.h"
29
30 #include "avi_rgb.h"
31 #include "avi_mjpeg.h"
32 #include "avi_rgb32.h"
33
34 void *avi_format_convert(AviMovie *movie, int stream, void *buffer, AviFormat from, AviFormat to, size_t *size)
35 {
36         if (from == to)
37                 return buffer;
38
39         if (from != AVI_FORMAT_RGB24 &&
40             to != AVI_FORMAT_RGB24)
41         {
42                 return avi_format_convert(movie, stream,
43                                           avi_format_convert(movie, stream, buffer, from, AVI_FORMAT_RGB24, size),
44                                           AVI_FORMAT_RGB24, to, size);
45         }
46
47         switch (to) {
48                 case AVI_FORMAT_RGB24:
49                         switch (from) {
50                                 case AVI_FORMAT_AVI_RGB:
51                                         buffer = avi_converter_from_avi_rgb(movie, stream, buffer, size);
52                                         break;
53                                 case AVI_FORMAT_MJPEG:
54                                         buffer = avi_converter_from_mjpeg(movie, stream, buffer, size);
55                                         break;
56                                 case AVI_FORMAT_RGB32:
57                                         buffer = avi_converter_from_rgb32(movie, stream, buffer, size);
58                                         break;
59                                 default:
60                                         break;
61                         }
62                         break;
63                 case AVI_FORMAT_AVI_RGB:
64                         buffer = avi_converter_to_avi_rgb(movie, stream, buffer, size);
65                         break;
66                 case AVI_FORMAT_MJPEG:
67                         buffer = avi_converter_to_mjpeg(movie, stream, buffer, size);
68                         break;
69                 case AVI_FORMAT_RGB32:
70                         buffer = avi_converter_to_rgb32(movie, stream, buffer, size);
71                         break;
72                 default:
73                         break;
74         }
75
76         return buffer;
77 }
78
79 int avi_get_data_id(AviFormat format, int stream)
80 {
81         char fcc[5];
82
83         if (avi_get_format_type(format) == FCC("vids"))
84                 sprintf(fcc, "%2.2ddc", stream);
85         else if (avi_get_format_type(format) == FCC("auds"))
86                 sprintf(fcc, "%2.2ddc", stream);
87         else
88                 return 0;
89
90         return FCC(fcc);
91 }
92
93 int avi_get_format_type(AviFormat format)
94 {
95         switch (format) {
96                 case AVI_FORMAT_RGB24:
97                 case AVI_FORMAT_RGB32:
98                 case AVI_FORMAT_AVI_RGB:
99                 case AVI_FORMAT_MJPEG:
100                         return FCC("vids");
101                 default:
102                         return 0;
103         }
104 }
105
106 int avi_get_format_fcc(AviFormat format)
107 {
108         switch (format) {
109                 case AVI_FORMAT_RGB24:
110                 case AVI_FORMAT_RGB32:
111                 case AVI_FORMAT_AVI_RGB:
112                         return FCC("DIB ");
113                 case AVI_FORMAT_MJPEG:
114                         return FCC("MJPG");
115                 default:
116                         return 0;
117         }
118 }
119
120 int avi_get_format_compression(AviFormat format)
121 {
122         switch (format) {
123                 case AVI_FORMAT_RGB24:
124                 case AVI_FORMAT_RGB32:
125                 case AVI_FORMAT_AVI_RGB:
126                         return 0;
127                 case AVI_FORMAT_MJPEG:
128                         return FCC("MJPG");
129                 default:
130                         return 0;
131         }
132 }