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