Blender V2.61 - r43446

options.c

Go to the documentation of this file.
00001 /*
00002  *
00003  * This is external code. Sets some compression related options
00004  * (width, height quality, framerate).
00005  *
00006  * ***** BEGIN GPL LICENSE BLOCK *****
00007  *
00008  * This program is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU General Public License
00010  * as published by the Free Software Foundation; either version 2
00011  * of the License, or (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software Foundation,
00020  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00021  *
00022  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00023  * All rights reserved.
00024  *
00025  * The Original Code is: all of this file.
00026  *
00027  * Contributor(s): none yet.
00028  *
00029  * ***** END GPL LICENSE BLOCK *****
00030  *
00031  */
00032 
00038 #include "AVI_avi.h"
00039 #include "avi_intern.h"
00040 #include "endian.h"
00041 
00042 #include "BLI_winstuff.h"
00043 
00044 /* avi_set_compress_options gets its own file... now don't WE feel important? */
00045 
00046 AviError AVI_set_compress_option (AviMovie *movie, int option_type, int stream, AviOption option, void *opt_data)
00047 {
00048     int i;
00049     int useconds;
00050 
00051     (void)stream; /* unused */
00052     
00053     if (movie->header->TotalFrames != 0)  /* Can't change params after we have already started writing frames */
00054         return AVI_ERROR_OPTION;
00055 
00056     switch (option_type) {
00057     case AVI_OPTION_TYPE_MAIN:
00058         switch (option) {
00059         case AVI_OPTION_WIDTH:
00060             movie->header->Width = *((int *) opt_data);
00061             movie->header->SuggestedBufferSize = movie->header->Width*movie->header->Height*3;
00062 
00063             for (i=0; i < movie->header->Streams; i++) {
00064                 if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) {
00065                     ((AviBitmapInfoHeader *) movie->streams[i].sf)->Width = *((int *) opt_data);
00066                     movie->streams[i].sh.SuggestedBufferSize = movie->header->SuggestedBufferSize;
00067                     movie->streams[i].sh.right = *((int *) opt_data);
00068                     ((AviBitmapInfoHeader *) movie->streams[i].sf)->SizeImage = movie->header->SuggestedBufferSize;
00069                     fseek (movie->fp, movie->offset_table[1+i*2+1], SEEK_SET);
00070                     awrite (movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH);
00071                 }
00072             }
00073 
00074             break;
00075 
00076         case AVI_OPTION_HEIGHT:
00077             movie->header->Height = *((int *) opt_data);
00078             movie->header->SuggestedBufferSize = movie->header->Width*movie->header->Height*3;
00079 
00080             for (i=0; i < movie->header->Streams; i++) {
00081                 if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) {
00082                     ((AviBitmapInfoHeader *) movie->streams[i].sf)->Height = *((int *) opt_data);
00083                     movie->streams[i].sh.SuggestedBufferSize = movie->header->SuggestedBufferSize;
00084                     movie->streams[i].sh.bottom = *((int *) opt_data);
00085                     ((AviBitmapInfoHeader *) movie->streams[i].sf)->SizeImage = movie->header->SuggestedBufferSize;
00086                     fseek (movie->fp, movie->offset_table[1+i*2+1], SEEK_SET);
00087                     awrite (movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH);
00088                 }
00089             }
00090 
00091             break;
00092 
00093         case AVI_OPTION_QUALITY:
00094             for (i=0; i < movie->header->Streams; i++) {
00095                 if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) {
00096                     movie->streams[i].sh.Quality = (*((int *) opt_data))*100;
00097                     fseek (movie->fp, movie->offset_table[1+i*2+1], SEEK_SET);
00098                     awrite (movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH);
00099                 }
00100             }
00101             break;
00102 
00103         case AVI_OPTION_FRAMERATE:
00104             useconds = (int)(1000000/(*((double *) opt_data)));
00105             if (useconds)
00106                 movie->header->MicroSecPerFrame = useconds;
00107 
00108             for (i=0; i < movie->header->Streams; i++) {
00109                 if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) {
00110                     movie->streams[i].sh.Scale = movie->header->MicroSecPerFrame;
00111                     fseek (movie->fp, movie->offset_table[1+i*2+1], SEEK_SET);
00112                     awrite (movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH);
00113                 }
00114             }
00115 
00116         }
00117 
00118         fseek (movie->fp, movie->offset_table[0], SEEK_SET);
00119         awrite (movie, movie->header, 1, sizeof(AviMainHeader), movie->fp, AVI_MAINH);
00120 
00121         break;
00122     case AVI_OPTION_TYPE_STRH:
00123         break;
00124     case AVI_OPTION_TYPE_STRF:
00125         break;
00126     default:
00127         return AVI_ERROR_OPTION;
00128         break;
00129     }
00130 
00131     return AVI_ERROR_NONE;
00132 }
00133