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

MPEGSource.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 "MPEGSource.h"
00026 
00027 //char *Y, *U, *V ; // commented out by cjn 14-09-01
00028                     // already declared in class MPEGSource
00029 
00030 MPEGSource::MPEGSource(char* path)
00036 {
00037         // check the files signature is valid
00038         if (!mpeg3_check_sig(path))
00039                 throw "incompatible mpeg file";
00040         
00041         // open the MPEG file
00042         file = mpeg3_open(path);
00043         if (file == NULL)
00044                 throw "error opening mpeg file";
00045 
00046         // check that it is a video MPEG file
00047         if (!mpeg3_has_video(file))
00048                 throw "non-video MPEG file";
00049                         
00050         
00051         width  = mpeg3_video_width(file, 0);
00052         height = mpeg3_video_height(file, 0);
00053         frames = mpeg3_video_frames(file, 0);
00054         framerate = mpeg3_frame_rate(file, 0);
00055 
00056         // allocate memory for rgb rows
00057         buff = new (unsigned char*)[height];
00058         for (unsigned int i = 0; i < height - 1; i++)
00059                 buff[i] = new (unsigned char)[width*3];
00060         
00061         // last row need space for mmx scratch area
00062         buff[height - 1] = new (unsigned char)[width*3 + 4];
00063 
00064         // Allocate memory for YUV data
00065         Y = new char[width*height] ;
00066         U = new char[width*height/4] ;
00067         V = new char[width*height/4] ;
00068         
00069         // default palette type for this ImageSource is colour 
00070         type = Image::COLOUR;
00071 }
00072 
00073 
00074 MPEGSource::~MPEGSource()
00078 {
00079         mpeg3_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         // free the rest of the memory
00086         delete [] buff;
00087 }
00088 
00089 
00090 ImageSource& MPEGSource::operator >> (ImageRGB& img) 
00096 {
00097         // read the frame to a temporary buffer
00098         mpeg3_read_frame(file, buff, 
00099                          0, 0,
00100                          width, height,
00101                          width, height,
00102                          MPEG3_RGB888, 0);
00103 
00104         // convert the frame to rgb96
00105         conv_rgb24_rgb96(width, height, buff, img.data[0]);
00106 
00107         return *this;
00108 }
00109 
00110 
00111 ImageSource& MPEGSource::operator >> (ImageGrey& img)
00118 {
00119         // No longer needed
00120         // char *Y, *U, *V;     // temp pointers for yuv frame information
00121 
00122         // set the pointers to point to y, u, and v buffers
00123         // Originally used the faster:
00124         // mpeg3_read_yuvframe_ptr(file, &Y, &U, &V, 0);
00125         // But this doesn't seem to work
00126 
00127  
00128         mpeg3_read_yuvframe(file,
00129                             Y,U,V,
00130                             0, 0,
00131                             width, height,
00132                             0);
00133 
00134         // convert the Y (luminance) information to 32bit greyscale
00135         // Originally 
00136         conv_420p_grey(width, height, Y, img.brightness);
00137 
00138 
00139         return *this;
00140 }
00141 
00142 
00143 ImageSource& MPEGSource::operator >> (Image& img) 
00152 {
00153         (type == Image::COLOUR) ? *this >> (ImageRGB&)img
00154                                 : *this >> (ImageGrey&)img;
00155                 
00156         return *this;
00157 }
00158 
00159 int  MPEGSource::get_no_frames()
00160 {
00161 return (int) frames;
00162 }
00163 
00164 void MPEGSource::get_size(unsigned int& w, unsigned int& h)
00171 {
00172         w = width; 
00173         h = height;
00174 }
00175 
00176 int MPEGSource::set_frame(long frame_no)
00182 {
00183     return mpeg3_set_frame(file, frame_no, 0) ;
00184 }
00185 
00186 void MPEGSource::get_framerate(float& fr_rate)
00192 {
00193     fr_rate = framerate;
00194 }
00195 
00196 bool MPEGSource::eof() const
00201 {
00202     return (bool)(mpeg3_end_of_video(file, 0));
00203 }
00204 

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