whitespace only, no functional change mixed tabs/spaces --> tabs.
[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 /* avi_set_compress_options gets its own file... now don't WE feel important? */
44
45 AviError AVI_set_compress_option (AviMovie *movie, int option_type, int stream, AviOption option, void *opt_data) {
46         int i;
47
48         (void)stream; /* unused */
49         
50         if (movie->header->TotalFrames != 0)  /* Can't change params after we have already started writing frames */
51                 return AVI_ERROR_OPTION;
52
53         switch (option_type) {
54         case AVI_OPTION_TYPE_MAIN:
55                 switch (option) {
56                         case AVI_OPTION_WIDTH:
57                                 movie->header->Width = *((int *) opt_data);
58                                 movie->header->SuggestedBufferSize = movie->header->Width*movie->header->Height*3;                              
59
60                                 for (i=0; i < movie->header->Streams; i++) {
61                                         if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) {
62                                                 ((AviBitmapInfoHeader *) movie->streams[i].sf)->Width = *((int *) opt_data);
63                                                 movie->streams[i].sh.SuggestedBufferSize = movie->header->SuggestedBufferSize;
64                                                 movie->streams[i].sh.right = *((int *) opt_data);
65                                                 ((AviBitmapInfoHeader *) movie->streams[i].sf)->SizeImage = movie->header->SuggestedBufferSize;
66                                                 fseek (movie->fp, movie->offset_table[1+i*2+1], SEEK_SET);
67                                                 awrite (movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH);
68                                         }
69                                 }
70
71                                 break;
72                                 
73                         case AVI_OPTION_HEIGHT:
74                                 movie->header->Height = *((int *) opt_data);
75                                 movie->header->SuggestedBufferSize = movie->header->Width*movie->header->Height*3;
76                                 
77                                 for (i=0; i < movie->header->Streams; i++) {
78                                         if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) {
79                                                 ((AviBitmapInfoHeader *) movie->streams[i].sf)->Height = *((int *) opt_data);
80                                                 movie->streams[i].sh.SuggestedBufferSize = movie->header->SuggestedBufferSize;
81                                                 movie->streams[i].sh.bottom = *((int *) opt_data);
82                                                 ((AviBitmapInfoHeader *) movie->streams[i].sf)->SizeImage = movie->header->SuggestedBufferSize;
83                                                 fseek (movie->fp, movie->offset_table[1+i*2+1], SEEK_SET);
84                                                 awrite (movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH);
85                                         }
86                                 }
87
88                                 break;
89                                 
90                         case AVI_OPTION_QUALITY:
91                                 for (i=0; i < movie->header->Streams; i++) {
92                                         if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) {
93                                                 movie->streams[i].sh.Quality = (*((int *) opt_data))*100;
94                                                 fseek (movie->fp, movie->offset_table[1+i*2+1], SEEK_SET);
95                                                 awrite (movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH);                                             
96                                         }
97                                 }
98                                 break;
99                                 
100                         case AVI_OPTION_FRAMERATE:
101                                 if (1000000/(*((double *) opt_data)))
102                                         movie->header->MicroSecPerFrame = 1000000/(*((double *) opt_data));                                     
103
104                                 for (i=0; i < movie->header->Streams; i++) {
105                                         if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) {
106                                                 movie->streams[i].sh.Scale = movie->header->MicroSecPerFrame;
107                                                 fseek (movie->fp, movie->offset_table[1+i*2+1], SEEK_SET);
108                                                 awrite (movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH);
109                                         }
110                                 }
111                                 
112                 }
113
114         fseek (movie->fp, movie->offset_table[0], SEEK_SET);
115         awrite (movie, movie->header, 1, sizeof(AviMainHeader), movie->fp, AVI_MAINH);
116
117         break;
118   case AVI_OPTION_TYPE_STRH:
119         break;
120   case AVI_OPTION_TYPE_STRF:
121         break;
122   default:
123         return AVI_ERROR_OPTION;
124         break;
125   }
126
127   return AVI_ERROR_NONE;
128 }
129