doxygen: add newline after \file
[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
21  * \ingroup avi
22  *
23  * This is external code. Sets some compression related options
24  * (width, height quality, framerate).
25  */
26
27 #include "AVI_avi.h"
28 #include "avi_intern.h"
29 #include "avi_endian.h"
30
31 #ifdef WIN32
32 #  include "BLI_winstuff.h"
33 #endif
34
35 /* avi_set_compress_options gets its own file... now don't WE feel important? */
36
37 AviError AVI_set_compress_option(AviMovie *movie, int option_type, int stream, AviOption option, void *opt_data)
38 {
39         int i;
40         int useconds;
41
42         (void)stream; /* unused */
43
44         if (movie->header->TotalFrames != 0)  /* Can't change params after we have already started writing frames */
45                 return AVI_ERROR_OPTION;
46
47         switch (option_type) {
48                 case AVI_OPTION_TYPE_MAIN:
49                         switch (option) {
50                                 case AVI_OPTION_WIDTH:
51                                         movie->header->Width = *((int *) opt_data);
52                                         movie->header->SuggestedBufferSize = movie->header->Width * movie->header->Height * 3;
53
54                                         for (i = 0; i < movie->header->Streams; i++) {
55                                                 if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) {
56                                                         ((AviBitmapInfoHeader *) movie->streams[i].sf)->Width = *((int *) opt_data);
57                                                         movie->streams[i].sh.SuggestedBufferSize = movie->header->SuggestedBufferSize;
58                                                         movie->streams[i].sh.right = *((int *) opt_data);
59                                                         ((AviBitmapInfoHeader *) movie->streams[i].sf)->SizeImage = movie->header->SuggestedBufferSize;
60                                                         fseek(movie->fp, movie->offset_table[1 + i * 2 + 1], SEEK_SET);
61                                                         awrite(movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH);
62                                                 }
63                                         }
64
65                                         break;
66
67                                 case AVI_OPTION_HEIGHT:
68                                         movie->header->Height = *((int *) opt_data);
69                                         movie->header->SuggestedBufferSize = movie->header->Width * movie->header->Height * 3;
70
71                                         for (i = 0; i < movie->header->Streams; i++) {
72                                                 if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) {
73                                                         ((AviBitmapInfoHeader *) movie->streams[i].sf)->Height = *((int *) opt_data);
74                                                         movie->streams[i].sh.SuggestedBufferSize = movie->header->SuggestedBufferSize;
75                                                         movie->streams[i].sh.bottom = *((int *) opt_data);
76                                                         ((AviBitmapInfoHeader *) movie->streams[i].sf)->SizeImage = movie->header->SuggestedBufferSize;
77                                                         fseek(movie->fp, movie->offset_table[1 + i * 2 + 1], SEEK_SET);
78                                                         awrite(movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH);
79                                                 }
80                                         }
81
82                                         break;
83
84                                 case AVI_OPTION_QUALITY:
85                                         for (i = 0; i < movie->header->Streams; i++) {
86                                                 if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) {
87                                                         movie->streams[i].sh.Quality = (*((int *) opt_data)) * 100;
88                                                         fseek(movie->fp, movie->offset_table[1 + i * 2 + 1], SEEK_SET);
89                                                         awrite(movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH);
90                                                 }
91                                         }
92                                         break;
93
94                                 case AVI_OPTION_FRAMERATE:
95                                         useconds = (int)(1000000 / (*((double *) opt_data)));
96                                         if (useconds)
97                                                 movie->header->MicroSecPerFrame = useconds;
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                                         break;
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         }
120
121         return AVI_ERROR_NONE;
122 }