Blender  V2.59
AVI_avi.h
Go to the documentation of this file.
00001 /*
00002  * $Id: AVI_avi.h 38302 2011-07-11 09:47:13Z blendix $ 
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00021  * All rights reserved.
00022  *
00023  * The Original Code is: all of this file.
00024  *
00025  * Contributor(s): none yet.
00026  *
00027  * ***** END GPL LICENSE BLOCK *****
00028  *
00029  */
00030 
00055 #ifndef __AVI_H__
00056 #define __AVI_H__
00057 
00058 #include "MEM_sys_types.h"
00059 #include <stdio.h> /* for FILE */
00060 
00061 typedef struct _AviChunk {
00062   int fcc;
00063   int size;
00064 } AviChunk;
00065 
00066 typedef struct _AviList {
00067   int fcc;
00068   int size;
00069   int ids;
00070 } AviList;
00071 
00072 typedef struct _AviMainHeader {
00073   int fcc;
00074   int size;  
00075   int MicroSecPerFrame;       /* MicroSecPerFrame - timing between frames */
00076   int MaxBytesPerSec;        /* MaxBytesPerSec - approx bps system must handle */
00077   int PaddingGranularity;
00078   int Flags;
00079 #define AVIF_HASINDEX           0x00000010        /* had idx1 chunk */
00080 #define AVIF_MUSTUSEINDEX       0x00000020        /* must use idx1 chunk to determine order */
00081 #define AVIF_ISINTERLEAVED      0x00000100        /* AVI file is interleaved */
00082 #define AVIF_TRUSTCKTYPE        0x00000800
00083 #define AVIF_WASCAPTUREFILE     0x00010000        /* specially allocated used for capturing real time video */
00084 #define AVIF_COPYRIGHTED        0x00020000        /* contains copyrighted data */
00085 
00086   int TotalFrames;
00087   int InitialFrames;    /* InitialFrames - initial frame before interleaving */
00088   int Streams;
00089   int SuggestedBufferSize;
00090   int Width;
00091   int Height;
00092   int Reserved[4];
00093 } AviMainHeader;
00094 
00095 typedef struct _AviStreamHeader {
00096   int fcc;
00097   int size;  
00098   int Type;
00099 #define AVIST_VIDEO FCC("vids")
00100 #define AVIST_AUDIO FCC("auds")
00101 #define AVIST_MIDI  FCC("mids")
00102 #define AVIST_TEXT  FCC("txts")
00103   
00104   int Handler;
00105   int Flags;
00106 #define AVISF_DISABLED 0x00000001
00107 #define AVISF_VIDEO_PALCHANGES 0x00010000
00108 
00109   short Priority;
00110   short Language;
00111   int InitialFrames;
00112   int Scale;
00113   int Rate;
00114   int Start;
00115   int Length;
00116   int SuggestedBufferSize;
00117   int Quality;
00118   int SampleSize;
00119   short left;
00120   short top;
00121   short right;
00122   short bottom;
00123 } AviStreamHeader;
00124 
00125 typedef struct _AviBitmapInfoHeader {
00126   int fcc;
00127   int size;  
00128   int Size;
00129   int Width;
00130   int Height;
00131   short Planes;
00132   short BitCount;
00133   int Compression;
00134   int SizeImage;
00135   int XPelsPerMeter;
00136   int YPelsPerMeter;
00137   int ClrUsed;
00138   int ClrImportant;
00139 } AviBitmapInfoHeader;
00140 
00141 typedef struct _AviMJPEGUnknown {
00142   int a;
00143   int b;
00144   int c;
00145   int d;
00146   int e;
00147   int f;
00148   int g;
00149 } AviMJPEGUnknown;
00150 
00151 typedef struct _AviIndexEntry {
00152   int ChunkId;
00153   int Flags;
00154 #define AVIIF_LIST       0x00000001
00155 #define AVIIF_KEYFRAME   0x00000010 
00156 #define AVIIF_NO_TIME    0x00000100
00157 #define AVIIF_COMPRESSOR 0x0FFF0000
00158   int Offset;
00159   int Size;
00160 } AviIndexEntry;
00161 
00162 typedef struct _AviIndex {
00163   int fcc;
00164   int size;
00165   AviIndexEntry *entrys;
00166 } AviIndex;
00167 
00168 typedef enum {
00169   AVI_FORMAT_RGB24,  /* The most basic of forms, 3 bytes per pixel, 1 per r, g, b */
00170   AVI_FORMAT_RGB32,  /* The second most basic of forms, 4 bytes per pixel, 1 per r, g, b, alpha */
00171   AVI_FORMAT_AVI_RGB, /* Same as above, but is in the weird AVI order (bottom to top, left to right) */
00172   AVI_FORMAT_MJPEG /* Motion-JPEG */
00173 } AviFormat;
00174 
00175 typedef struct _AviStreamRec {
00176   AviStreamHeader sh;
00177   void *sf;
00178   int sf_size;
00179   AviFormat format;
00180 } AviStreamRec;
00181 
00182 typedef struct _AviMovie {
00183         FILE *fp; 
00184         
00185         int type;
00186 #define AVI_MOVIE_READ  0
00187 #define AVI_MOVIE_WRITE 1
00188         
00189         int64_t size;
00190 
00191         AviMainHeader *header;
00192         AviStreamRec *streams;
00193         AviIndexEntry *entries;
00194         int index_entries;
00195         
00196         int64_t movi_offset;
00197         int64_t read_offset;
00198         int64_t *offset_table;
00199         
00200         /* Local data goes here */
00201         int interlace;
00202         int odd_fields;
00203 } AviMovie;
00204 
00205 typedef enum {
00206   AVI_ERROR_NONE=0,
00207   AVI_ERROR_COMPRESSION,
00208   AVI_ERROR_OPEN,
00209   AVI_ERROR_READING,
00210   AVI_ERROR_WRITING,
00211   AVI_ERROR_FORMAT,
00212   AVI_ERROR_ALLOC,
00213   AVI_ERROR_FOUND,
00214   AVI_ERROR_OPTION
00215 } AviError;
00216 
00217 /* belongs to the option-setting function. */
00218 typedef enum {
00219   AVI_OPTION_WIDTH=0,
00220   AVI_OPTION_HEIGHT, 
00221   AVI_OPTION_QUALITY,
00222   AVI_OPTION_FRAMERATE
00223 } AviOption;
00224 
00225 /* The offsets that will always stay the same in AVI files we
00226  * write... used to seek around to the places where we need to write
00227  * the sizes */
00228 
00229 #define AVI_RIFF_SOFF 4L
00230 #define AVI_HDRL_SOFF 16L
00231 
00235 #define FCC(ch4) (ch4[0] | ch4[1]<<8 | ch4[2]<<16 | ch4[3] << 24)
00236 
00240 int AVI_is_avi (const char *name);
00241 
00242 
00246 AviError AVI_open_compress (char *name, AviMovie *movie, int streams, ...);
00247 
00251 AviError AVI_close_compress (AviMovie *movie);
00252 
00257 AviError AVI_set_compress_option (AviMovie *movie,
00258                                                                   int option_type,
00259                                                                   int stream,
00260                                                                   AviOption option,
00261                                                                   void *opt_data);
00262 /* Hmmm... there should be some explanantion about what these mean */
00266 #define AVI_OPTION_TYPE_MAIN 0
00267 
00270 #define AVI_OPTION_TYPE_STRH 1
00271 
00274 #define AVI_OPTION_TYPE_STRF 2
00275 
00280 int AVI_get_stream (AviMovie *movie, int avist_type, int stream_num);
00281 
00285 AviError AVI_open_movie (const char *name, AviMovie *movie);
00286 
00290 void *AVI_read_frame (AviMovie *movie,
00291                                           AviFormat format,
00292                                           int frame,
00293                                           int stream);
00297 AviError AVI_close (AviMovie *movie);
00298 
00302 AviError AVI_write_frame (AviMovie *movie, int frame_num, ...);
00303 
00307 AviError AVI_print_error (AviError error);
00308 void AVI_set_debug (int mode);
00309 
00310 #endif /* __AVI_H__ */
00311