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