00001
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00039 outfile = quicktime_open(path,0,1);
00040 if (outfile == NULL)
00041 throw "error opening file to write quicktime to";
00042
00043
00044 quicktime_set_video(outfile, 1, width, height, frame_rate, "mjpa");
00045
00046 quicktime_set_jpeg(outfile, quality, 0);
00047
00048
00049 if(!quicktime_supported_video(outfile, 0)){
00050 throw "QT Compression scheme not supported" ;
00051 }
00052
00053 if(!quicktime_writes_cmodel(outfile, 9, 0)){
00054 throw "QT Color Model not supported" ;
00055 }
00056
00057 quicktime_set_cmodel(outfile, 9);
00058
00059
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
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
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
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