Fix some MSVC 2010 warnings (including one apparent bug in intern/elbeem/intern/solve...
[blender.git] / source / blender / avi / intern / options.c
1 /*
2  * $Id$
3  *
4  * This is external code. Sets some compression related options
5  * (width, height quality, framerate).
6  *
7  * ***** BEGIN GPL LICENSE BLOCK *****
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL LICENSE BLOCK *****
31  *
32  */
33
34 /** \file blender/avi/intern/options.c
35  *  \ingroup avi
36  */
37
38
39 #include "AVI_avi.h"
40 #include "avi_intern.h"
41 #include "endian.h"
42
43 #include "BLI_winstuff.h"
44
45 /* avi_set_compress_options gets its own file... now don't WE feel important? */
46
47 AviError AVI_set_compress_option (AviMovie *movie, int option_type, int stream, AviOption option, void *opt_data) {
48         int i;
49         int useconds;
50
51         (void)stream; /* unused */
52         
53         if (movie->header->TotalFrames != 0)  /* Can't change params after we have already started writing frames */
54                 return AVI_ERROR_OPTION;
55
56         switch (option_type) {
57         case AVI_OPTION_TYPE_MAIN:
58                 switch (option) {
59                 case AVI_OPTION_WIDTH:
60                         movie->header->Width = *((int *) opt_data);
61                         movie->header->SuggestedBufferSize = movie->header->Width*movie->header->Height*3;
62
63                         for (i=0; i < movie->header->Streams; i++) {
64                                 if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) {
65                                         ((AviBitmapInfoHeader *) movie->streams[i].sf)->Width = *((int *) opt_data);
66                                         movie->streams[i].sh.SuggestedBufferSize = movie->header->SuggestedBufferSize;
67                                         movie->streams[i].sh.right = *((int *) opt_data);
68                                         ((AviBitmapInfoHeader *) movie->streams[i].sf)->SizeImage = movie->header->SuggestedBufferSize;
69                                         fseek (movie->fp, movie->offset_table[1+i*2+1], SEEK_SET);
70                                         awrite (movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH);
71                                 }
72                         }
73
74                         break;
75
76                 case AVI_OPTION_HEIGHT:
77                         movie->header->Height = *((int *) opt_data);
78                         movie->header->SuggestedBufferSize = movie->header->Width*movie->header->Height*3;
79
80                         for (i=0; i < movie->header->Streams; i++) {
81                                 if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) {
82                                         ((AviBitmapInfoHeader *) movie->streams[i].sf)->Height = *((int *) opt_data);
83                                         movie->streams[i].sh.SuggestedBufferSize = movie->header->SuggestedBufferSize;
84                                         movie->streams[i].sh.bottom = *((int *) opt_data);
85                                         ((AviBitmapInfoHeader *) movie->streams[i].sf)->SizeImage = movie->header->SuggestedBufferSize;
86                                         fseek (movie->fp, movie->offset_table[1+i*2+1], SEEK_SET);
87                                         awrite (movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH);
88                                 }
89                         }
90
91                         break;
92
93                 case AVI_OPTION_QUALITY:
94                         for (i=0; i < movie->header->Streams; i++) {
95                                 if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) {
96                                         movie->streams[i].sh.Quality = (*((int *) opt_data))*100;
97                                         fseek (movie->fp, movie->offset_table[1+i*2+1], SEEK_SET);
98                                         awrite (movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH);
99                                 }
100                         }
101                         break;
102
103                 case AVI_OPTION_FRAMERATE:
104                         useconds = (int)(1000000/(*((double *) opt_data)));
105                         if (useconds)
106                                 movie->header->MicroSecPerFrame = useconds;
107
108                         for (i=0; i < movie->header->Streams; i++) {
109                                 if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) {
110                                         movie->streams[i].sh.Scale = movie->header->MicroSecPerFrame;
111                                         fseek (movie->fp, movie->offset_table[1+i*2+1], SEEK_SET);
112                                         awrite (movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH);
113                                 }
114                         }
115
116                 }
117
118                 fseek (movie->fp, movie->offset_table[0], SEEK_SET);
119                 awrite (movie, movie->header, 1, sizeof(AviMainHeader), movie->fp, AVI_MAINH);
120
121                 break;
122         case AVI_OPTION_TYPE_STRH:
123                 break;
124         case AVI_OPTION_TYPE_STRF:
125                 break;
126         default:
127                 return AVI_ERROR_OPTION;
128                 break;
129         }
130
131         return AVI_ERROR_NONE;
132 }
133