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

QTencoder.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 #include "QTencoder.h"
00022 
00036 QTencoder::QTencoder(char* path, unsigned int w, unsigned int h, float frate, int quality):width(w),height(h),frame_rate(frate)
00037 {
00038         //open the a file for the quicktime movie
00039         outfile = quicktime_open(path,0,1); //read access only!
00040         if (outfile == NULL)
00041                 throw "error opening file to write quicktime to";
00042 
00043         //Set video parameters - Using Interlaced Even Motion JPEG A compression
00044         quicktime_set_video(outfile, 1, width, height, frame_rate, "mjpa");
00045         //Set the JPEG quality factor 1=low 75=normal 90=high 100=best
00046         quicktime_set_jpeg(outfile, quality, 0);
00047 
00048         //Check compression scheme is supported
00049         if(!quicktime_supported_video(outfile, 0)){
00050                 throw "QT Compression scheme not supported" ;
00051         }
00052         //Check colour model is supported - using RGB888
00053         if(!quicktime_writes_cmodel(outfile, 9, 0)){
00054                 throw "QT Color Model not supported" ;
00055         }
00056         //Set colourmodel to RGB888 format
00057         quicktime_set_cmodel(outfile, 9);
00058 
00059         // allocate memory for rgb rows
00060         buff = new (unsigned char*)[height];
00061         for (unsigned int i = 0; i < height ; i++)
00062                 buff[i] = new (unsigned char)[width*3];
00063 }
00064 
00068 QTencoder::~QTencoder()
00069 {
00070         // free the memory for each of the rows
00071         for (unsigned int i = 0; i < height; i++)
00072                 delete [] buff[i];
00073         delete [] buff;
00074 }
00075 
00081 void QTencoder::close()
00082 {
00083         quicktime_close(outfile);
00084 }
00085 
00090 bool QTencoder::operator << (ImageRGB& img)
00091 {
00092         bool ret_val = 1;
00093         PixelRGB* rgb_ptr = img.data;
00094         unsigned char *buff_ptr = buff[0];
00095         for(unsigned int y_cnt=0 ; y_cnt< img.get_height() ; y_cnt++){
00096             buff_ptr = buff[y_cnt];
00097             for(unsigned int x_cnt=0 ; x_cnt< img.get_width() ; x_cnt++, rgb_ptr++){
00098                 (*buff_ptr++) = (unsigned char)((*rgb_ptr)[0]);
00099                 (*buff_ptr++) = (unsigned char)((*rgb_ptr)[1]);
00100                 (*buff_ptr++) = (unsigned char)((*rgb_ptr)[2]);
00101             }   
00102         }
00103         //Encode the frame and write to file
00104         if(quicktime_encode_video(outfile, buff, 0))
00105                 ret_val = 0 ;
00106         return ret_val;
00107 }
00108 
00113 bool QTencoder::operator << (ImageGrey& img)
00114 {
00115         bool ret_val = 1;
00116         int* b_ptr = img.brightness;
00117         unsigned char *buff_ptr = buff[0];
00118         for(unsigned int y_cnt=0 ; y_cnt< img.get_height() ; y_cnt++){
00119             buff_ptr = buff[y_cnt];
00120             for(unsigned int x_cnt=0 ; x_cnt< img.get_width() ; x_cnt++, b_ptr++){
00121                 (*buff_ptr++) = (unsigned char)((*b_ptr));
00122                 (*buff_ptr++) = (unsigned char)((*b_ptr));
00123                 (*buff_ptr++) = (unsigned char)((*b_ptr));
00124             }  
00125         }
00126         //Encode the frame and write to file
00127         if(quicktime_encode_video(outfile, buff, 0))
00128                 ret_val = 0 ;
00129         return ret_val;
00130 }
00131 
00132 void QTencoder::set_framerate(float fr)
00137 {
00138             quicktime_set_framerate(outfile, fr) ;
00139 }
00140 
00141 

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