Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

filebase.C

Go to the documentation of this file.
00001 #include "asset.h"
00002 #include "assets.h"
00003 #include "byteorder.h"
00004 #include "colormodels.h"
00005 #include "file.h"
00006 #include "filebase.h"
00007 #include "overlayframe.h"
00008 #include "sizes.h"
00009 
00010 #include <stdlib.h>
00011 
00012 FileBase::FileBase(Asset *asset, File *file)
00013 {
00014         this->file = file;
00015         this->asset = asset;
00016         internal_byte_order = get_byte_order();
00017         init_ima4();
00018         reset_parameters();
00019         overlayer = new OverlayFrame;
00020 }
00021 
00022 FileBase::~FileBase()
00023 {
00024         if(audio_buffer_in) delete [] audio_buffer_in;
00025         if(audio_buffer_out) delete [] audio_buffer_out;
00026         if(video_buffer_in) delete [] video_buffer_in;
00027         if(video_buffer_out) delete [] video_buffer_out;
00028         if(row_pointers_in) delete [] row_pointers_in;
00029         if(row_pointers_out) delete [] row_pointers_out;
00030         if(float_buffer) delete [] float_buffer;
00031         delete overlayer;
00032         delete_ima4();
00033 }
00034 
00035 int FileBase::close_file()
00036 {
00037         if(audio_buffer_in) delete [] audio_buffer_in;
00038         if(audio_buffer_out) delete [] audio_buffer_out;
00039         if(video_buffer_in) delete [] video_buffer_in;
00040         if(video_buffer_out) delete [] video_buffer_out;
00041         if(row_pointers_in) delete [] row_pointers_in;
00042         if(row_pointers_out) delete [] row_pointers_out;
00043         if(float_buffer) delete [] float_buffer;
00044         close_file_derived();
00045         reset_parameters();
00046         delete_ima4();
00047 }
00048 
00049 int FileBase::set_dither()
00050 {
00051         dither = 1;
00052         return 0;
00053 }
00054 
00055 int FileBase::reset_parameters()
00056 {
00057         dither = 0;
00058         audio_buffer_in = 0;
00059         video_buffer_in = 0;
00060         audio_buffer_out = 0;
00061         video_buffer_out = 0;
00062         float_buffer = 0;
00063         row_pointers_in = 0;
00064         row_pointers_out = 0;
00065         prev_buffer_position = -1;
00066         prev_frame_position = -1;
00067         prev_len = 0;
00068         prev_bytes = 0;
00069         prev_track = -1;
00070         prev_layer = -1;
00071         ulawtofloat_table = 0;
00072         floattoulaw_table = 0;
00073         rd = wr = 0;
00074 
00075         delete_ulaw_tables();
00076         reset_parameters_derived();
00077 }
00078 
00079 int FileBase::get_mode(char *mode, int rd, int wr)
00080 {
00081         if(rd && !wr) sprintf(mode, "rb");
00082         else
00083         if(!rd && wr) sprintf(mode, "wb");
00084         else
00085         if(rd && wr)
00086         {
00087                 int exists = 0;
00088                 FILE *stream;
00089 
00090                 if(stream = fopen(asset->path, "rb")) 
00091                 {
00092                         exists = 1; 
00093                         fclose(stream); 
00094                 }
00095 
00096                 if(exists) sprintf(mode, "rb+");
00097                 else
00098                 sprintf(mode, "wb+");
00099         }
00100 }
00101 
00102 
00103 
00104 
00105 
00106 
00107 
00108 
00109 
00110 
00111 // ======================================= audio codecs
00112 
00113 int FileBase::get_video_buffer(unsigned char **buffer, int depth)
00114 {
00115 // get a raw video buffer for writing or compression by a library
00116         if(!*buffer)
00117         {
00118 // Video compression is entirely done in the library.
00119                 int64_t bytes = asset->width * asset->height * depth;
00120                 *buffer = new unsigned char[bytes];
00121         }
00122         return 0;
00123 }
00124 
00125 int FileBase::get_row_pointers(unsigned char *buffer, unsigned char ***pointers, int depth)
00126 {
00127 // This might be fooled if a new VFrame is created at the same address with a different height.
00128         if(*pointers && (*pointers)[0] != &buffer[0])
00129         {
00130                 delete [] *pointers;
00131                 *pointers = 0;
00132         }
00133 
00134         if(!*pointers)
00135         {
00136                 *pointers = new unsigned char*[asset->height];
00137                 for(int i = 0; i < asset->height; i++)
00138                 {
00139                         (*pointers)[i] = &buffer[i * asset->width * depth / 8];
00140                 }
00141         }
00142 }
00143 
00144 int FileBase::match4(char *in, char *out)
00145 {
00146         if(in[0] == out[0] &&
00147                 in[1] == out[1] &&
00148                 in[2] == out[2] &&
00149                 in[3] == out[3])
00150                 return 1;
00151         else
00152                 return 0;
00153 }
00154 
00155 int FileBase::search_render_strategies(ArrayList<int>* render_strategies, int render_strategy)
00156 {
00157         int i;
00158         for(i = 0; i < render_strategies->total; i++)
00159                 if(render_strategies->values[i] == render_strategy) return 1;
00160 
00161         return 0;
00162 }

Generated on Sun Jan 8 13:38:54 2006 for Cinelerra-svn by  doxygen 1.4.4