2.5
[blender-staging.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 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.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  *
25  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
26  * All rights reserved.
27  *
28  * The Original Code is: all of this file.
29  *
30  * Contributor(s): none yet.
31  *
32  * ***** END GPL LICENSE BLOCK *****
33  *  */
34
35 #include "AVI_avi.h"
36 #include "avi_intern.h"
37 #include "endian.h"
38
39 #ifdef HAVE_CONFIG_H
40 #include <config.h>
41 #endif
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         if (movie->header->TotalFrames != 0)  /* Can't change params after we have already started writing frames */
49                 return AVI_ERROR_OPTION;
50
51         switch (option_type) {
52         case AVI_OPTION_TYPE_MAIN:
53                 switch (option) {
54                         case AVI_OPTION_WIDTH:
55                                 movie->header->Width = *((int *) opt_data);
56                                 movie->header->SuggestedBufferSize = movie->header->Width*movie->header->Height*3;                              
57
58                                 for (i=0; i < movie->header->Streams; i++) {
59                                         if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) {
60                                                 ((AviBitmapInfoHeader *) movie->streams[i].sf)->Width = *((int *) opt_data);
61                                                 movie->streams[i].sh.SuggestedBufferSize = movie->header->SuggestedBufferSize;
62                                                 movie->streams[i].sh.right = *((int *) opt_data);
63                                                 ((AviBitmapInfoHeader *) movie->streams[i].sf)->SizeImage = movie->header->SuggestedBufferSize;
64                                                 fseek (movie->fp, movie->offset_table[1+i*2+1], SEEK_SET);
65                                                 awrite (movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH);
66                                         }
67                                 }
68
69                                 break;
70                                 
71                         case AVI_OPTION_HEIGHT:
72                                 movie->header->Height = *((int *) opt_data);
73                                 movie->header->SuggestedBufferSize = movie->header->Width*movie->header->Height*3;
74                                 
75                                 for (i=0; i < movie->header->Streams; i++) {
76                                         if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) {
77                                                 ((AviBitmapInfoHeader *) movie->streams[i].sf)->Height = *((int *) opt_data);
78                                                 movie->streams[i].sh.SuggestedBufferSize = movie->header->SuggestedBufferSize;
79                                                 movie->streams[i].sh.bottom = *((int *) opt_data);
80                                                 ((AviBitmapInfoHeader *) movie->streams[i].sf)->SizeImage = movie->header->SuggestedBufferSize;
81                                                 fseek (movie->fp, movie->offset_table[1+i*2+1], SEEK_SET);
82                                                 awrite (movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH);
83                                         }
84                                 }
85
86                                 break;
87                                 
88                         case AVI_OPTION_QUALITY:
89                                 for (i=0; i < movie->header->Streams; i++) {
90                                         if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) {
91                                                 movie->streams[i].sh.Quality = (*((int *) opt_data))*100;
92                                                 fseek (movie->fp, movie->offset_table[1+i*2+1], SEEK_SET);
93                                                 awrite (movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH);                                             
94                                         }
95                                 }
96                                 break;
97                                 
98                         case AVI_OPTION_FRAMERATE:
99                                 if (1000000/(*((double *) opt_data)))
100                                         movie->header->MicroSecPerFrame = 1000000/(*((double *) opt_data));                                     
101
102                                 for (i=0; i < movie->header->Streams; i++) {
103                                         if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) {
104                                                 movie->streams[i].sh.Scale = movie->header->MicroSecPerFrame;
105                                                 fseek (movie->fp, movie->offset_table[1+i*2+1], SEEK_SET);
106                                                 awrite (movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH);
107                                         }
108                                 }
109                                 
110                 }
111
112     fseek (movie->fp, movie->offset_table[0], SEEK_SET);
113     awrite (movie, movie->header, 1, sizeof(AviMainHeader), movie->fp, AVI_MAINH);
114
115     break;
116   case AVI_OPTION_TYPE_STRH:
117     break;
118   case AVI_OPTION_TYPE_STRF:
119     break;
120   default:
121     return AVI_ERROR_OPTION;
122     break;
123   }
124
125   return AVI_ERROR_NONE;
126 }
127