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