Blender  V2.93
avi_options.c
Go to the documentation of this file.
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 
27 #include "AVI_avi.h"
28 #include "BLI_fileops.h"
29 #include "avi_endian.h"
30 #include "avi_intern.h"
31 
32 #ifdef WIN32
33 # include "BLI_winstuff.h"
34 #endif
35 
36 /* avi_set_compress_options gets its own file... now don't WE feel important? */
37 
39  AviMovie *movie, int option_type, int stream, AviOption option, void *opt_data)
40 {
41  int i;
42  int useconds;
43 
44  (void)stream; /* unused */
45 
46  if (movie->header->TotalFrames != 0) {
47  /* Can't change params after we have already started writing frames. */
48  return AVI_ERROR_OPTION;
49  }
50 
51  switch (option_type) {
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);
62  movie->streams[i].sh.right = *((int *)opt_data);
63  ((AviBitmapInfoHeader *)movie->streams[i].sf)->SizeImage =
65  BLI_fseek(movie->fp, movie->offset_table[1 + i * 2 + 1], SEEK_SET);
66  awrite(movie,
67  movie->streams[i].sf,
68  1,
69  movie->streams[i].sf_size,
70  movie->fp,
71  AVI_BITMAPH);
72  }
73  }
74 
75  break;
76 
77  case AVI_OPTION_HEIGHT:
78  movie->header->Height = *((int *)opt_data);
79  movie->header->SuggestedBufferSize = movie->header->Width * movie->header->Height * 3;
80 
81  for (i = 0; i < movie->header->Streams; i++) {
82  if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) {
83  ((AviBitmapInfoHeader *)movie->streams[i].sf)->Height = *((int *)opt_data);
85  movie->streams[i].sh.bottom = *((int *)opt_data);
86  ((AviBitmapInfoHeader *)movie->streams[i].sf)->SizeImage =
88  BLI_fseek(movie->fp, movie->offset_table[1 + i * 2 + 1], SEEK_SET);
89  awrite(movie,
90  movie->streams[i].sf,
91  1,
92  movie->streams[i].sf_size,
93  movie->fp,
94  AVI_BITMAPH);
95  }
96  }
97 
98  break;
99 
100  case AVI_OPTION_QUALITY:
101  for (i = 0; i < movie->header->Streams; i++) {
102  if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) {
103  movie->streams[i].sh.Quality = (*((int *)opt_data)) * 100;
104  BLI_fseek(movie->fp, movie->offset_table[1 + i * 2 + 1], SEEK_SET);
105  awrite(movie,
106  movie->streams[i].sf,
107  1,
108  movie->streams[i].sf_size,
109  movie->fp,
110  AVI_BITMAPH);
111  }
112  }
113  break;
114 
116  useconds = (int)(1000000 / (*((double *)opt_data)));
117  if (useconds) {
118  movie->header->MicroSecPerFrame = useconds;
119  }
120 
121  for (i = 0; i < movie->header->Streams; i++) {
122  if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) {
123  movie->streams[i].sh.Scale = movie->header->MicroSecPerFrame;
124  BLI_fseek(movie->fp, movie->offset_table[1 + i * 2 + 1], SEEK_SET);
125  awrite(movie,
126  movie->streams[i].sf,
127  1,
128  movie->streams[i].sf_size,
129  movie->fp,
130  AVI_BITMAPH);
131  }
132  }
133  break;
134  }
135 
136  BLI_fseek(movie->fp, movie->offset_table[0], SEEK_SET);
137  awrite(movie, movie->header, 1, sizeof(AviMainHeader), movie->fp, AVI_MAINH);
138 
139  break;
141  break;
143  break;
144  default:
145  return AVI_ERROR_OPTION;
146  }
147 
148  return AVI_ERROR_NONE;
149 }
#define FCC(ch4)
Definition: AVI_avi.h:231
AviError
Definition: AVI_avi.h:201
@ AVI_ERROR_OPTION
Definition: AVI_avi.h:210
@ AVI_ERROR_NONE
Definition: AVI_avi.h:202
#define AVI_OPTION_TYPE_STRF
Definition: AVI_avi.h:266
AviOption
Definition: AVI_avi.h:214
@ AVI_OPTION_HEIGHT
Definition: AVI_avi.h:216
@ AVI_OPTION_FRAMERATE
Definition: AVI_avi.h:218
@ AVI_OPTION_WIDTH
Definition: AVI_avi.h:215
@ AVI_OPTION_QUALITY
Definition: AVI_avi.h:217
#define AVI_OPTION_TYPE_STRH
Definition: AVI_avi.h:262
#define AVI_OPTION_TYPE_MAIN
Definition: AVI_avi.h:258
File and directory operations.
int BLI_fseek(FILE *stream, int64_t offset, int whence)
Definition: storage.c:186
Compatibility-like things for windows.
int avi_get_format_type(AviFormat format)
Definition: avi_codecs.c:99
void awrite(AviMovie *movie, void *datain, int block, int size, FILE *fp, int type)
Definition: avi_endian.c:149
#define AVI_MAINH
Definition: avi_endian.h:31
#define AVI_BITMAPH
Definition: avi_endian.h:33
AviError AVI_set_compress_option(AviMovie *movie, int option_type, int stream, AviOption option, void *opt_data)
Definition: avi_options.c:38
int MicroSecPerFrame
Definition: AVI_avi.h:61
int SuggestedBufferSize
Definition: AVI_avi.h:81
int TotalFrames
Definition: AVI_avi.h:78
int64_t * offset_table
Definition: AVI_avi.h:194
FILE * fp
Definition: AVI_avi.h:179
AviMainHeader * header
Definition: AVI_avi.h:187
AviStreamRec * streams
Definition: AVI_avi.h:188
int SuggestedBufferSize
Definition: AVI_avi.h:108
AviFormat format
Definition: AVI_avi.h:175
AviStreamHeader sh
Definition: AVI_avi.h:172
void * sf
Definition: AVI_avi.h:173