Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

QTSource.cpp

Go to the documentation of this file.
00001 /**************************************************************************
00008  *
00009  * Source code for Real Time Image Library (libRTImage)
00010  *
00011  * Leeds Vision Group give permission for this code to be copied, modified 
00012  * and distributed within the University of Leeds subject to the following 
00013  * conditions:-
00014  *
00015  * - The code is not to be used for commercial gain.
00016  * - The code and use thereof will be attributed to the author where
00017  *   appropriate (inluding demonstrations which rely on it's use).
00018  * - All modified, distributions of the source files will retain this header.
00019  *
00020  ****************************************************************************/
00021  
00022 #define ORIGINAL_VER
00023  
00024 #include "ccvt/conv.h"
00025 #include "QTSource.h"
00026 
00027 QTSource::QTSource(char* path)
00033 {
00034         // check the files signature is valid
00035         if (!quicktime_check_sig(path))
00036                 throw "incompatible quicktime file";
00037         
00038         // open the QT file
00039         file = quicktime_open(path,1,0); //read access only!
00040         if (file == NULL)
00041                 throw "error opening quicktime file";
00042 
00043         // check that it is a video QT file, with one track
00044         if (quicktime_video_tracks(file) != 1)
00045                 throw "QT file does not only have one video track";
00046 //        if (quicktime_audio_tracks(file) != 0)
00047 //                throw "QT file has audio tracks";
00048 
00049         width  = quicktime_video_width(file, 0);
00050         height = quicktime_video_height(file, 0);
00051         frames = quicktime_video_length(file, 0);
00052         c_frame_no = 0 ;
00053         qt_eof = false ; 
00054 
00055         //Check Depth: Only RGB allowed, RGBA not supported
00056         //Could be, but requires extra processing in this file
00057         if(quicktime_video_depth(file, 0) != 24)
00058                 throw "Depth not 24 ie not RGBRGBRGB encoded QT";
00059 
00060         comp_type = quicktime_video_compressor(file, 0);
00061         if (!quicktime_supported_video(file, 0))
00062                 throw "QT data cannot be decoded";
00063 
00064         // allocate memory for rgb rows
00065         buff = new (unsigned char*)[height];
00066         for (unsigned int i = 0; i < height ; i++)
00067                 buff[i] = new (unsigned char)[width*3];
00068 
00069         // default palette type for this ImageSource is colour 
00070         type = Image::COLOUR;
00071 }
00072 
00073 
00074 QTSource::~QTSource()
00078 {
00079         quicktime_close(file);
00080 
00081         // free the memory for each of the rows
00082         for (unsigned int i = 0; i < height; i++)
00083                 delete [] buff[i];
00084         
00085         delete [] buff;
00086 }
00087 
00088 
00089 ImageSource& QTSource::operator >> (ImageRGB& img) 
00095 {
00096         // read the frame to a temporary buffer
00097         quicktime_decode_video(file,buff,0);
00098 
00099         // convert the frame to rgb96
00100         conv_rgb24_rgb96(width, height, buff, img.data[0]);
00101 
00102         c_frame_no++ ;
00103         if(c_frame_no > frames) qt_eof = true ;
00104 
00105         return *this;
00106 }
00107 
00108 ImageSource& QTSource::operator >> (ImageGrey& img)
00115 {
00116  
00117         quicktime_decode_video(file,buff,0);
00118   
00119         unsigned int y_cnt;
00120         unsigned int x_cnt;
00121         PixelGrey *bri_ptr = img.brightness;
00122         unsigned char* rgb_ptr = buff[0];
00123 
00124         for(y_cnt=0 ; y_cnt< img.get_height() ; y_cnt++){
00125           rgb_ptr = buff[y_cnt];
00126           for(x_cnt=0 ; x_cnt< img.get_width() ; x_cnt++){
00127             *(bri_ptr++) = (PixelGrey)( (RED_COEF*(float)*rgb_ptr++) +
00128                              (GREEN_COEF*(float)*rgb_ptr++) +
00129                              (BLUE_COEF*(float)*rgb_ptr++ ) );
00130           }
00131         }
00132         return *this;
00133 }
00134 
00135 ImageSource& QTSource::operator >> (Image& img) 
00144 {
00145         (type == Image::COLOUR) ? *this >> (ImageRGB&)img 
00146                                 : *this >> (ImageGrey&)img;
00147         return *this;
00148 }
00149 
00150 
00151 void QTSource::get_size(unsigned int& w, unsigned int& h)
00158 {
00159         w = width; 
00160         h = height;
00161 }
00162 
00163 int QTSource::set_frame(long frame_no)
00169 {
00170     c_frame_no = frame_no ;
00171     return quicktime_set_video_position(file, frame_no, 0) ;
00172 }
00173 
00174 long QTSource::get_no_frames()
00178 {
00179     return quicktime_video_length(file,0) ;
00180 }
00181 
00182 void QTSource::get_framerate(float &fr)
00186 {
00187     fr = quicktime_frame_rate(file,0) ;
00188 }
00189 
00190 void QTSource::set_framerate(float fr)
00195 {
00196     quicktime_set_framerate(file, fr) ;
00197 }

Generated at Fri Aug 13 17:29:21 2004 for libRTImage by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001