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