00001
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00035 if (!quicktime_check_sig(path))
00036 throw "incompatible quicktime file";
00037
00038
00039 file = quicktime_open(path,1,0);
00040 if (file == NULL)
00041 throw "error opening quicktime file";
00042
00043
00044 if (quicktime_video_tracks(file) != 1)
00045 throw "QT file does not only have one video track";
00046
00047
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
00056
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
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
00070 type = Image::COLOUR;
00071 }
00072
00073
00074 QTSource::~QTSource()
00078 {
00079 quicktime_close(file);
00080
00081
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
00097 quicktime_decode_video(file,buff,0);
00098
00099
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 }