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