00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00024
00025 #include <QVDirReader>
00026
00027 #include <QUrl>
00028
00029 #ifdef QVIPP
00030 #include <qvipp.h>
00031 #endif // QVIPP
00032
00033 bool QVDirReader:: open(const QString & url_string,
00034 unsigned int & suggested_cols, unsigned int & suggested_rows,
00035 unsigned int & suggested_fps, QVVideoReader::OpenOptions & suggested_options,
00036 QVVideoReader::TSourceMode & source_mode)
00037 {
00038
00039
00040 source_mode = QVVideoReader::RGBMode;
00041
00042 ended = false;
00043
00044
00045 QString dir_string = url_string;
00046 dir_string.remove("dir://");
00047 QStringList filters;
00048 QFileInfo info(dir_string);
00049 if(info.isDir()) {
00050 dir = QDir(dir_string);
00051 filters << "*.jpg" << "*.png" << "*.bmp" << "*.pgm" << "*.gif" << "*.jpeg" << "*.pbm" << "*.ppm"
00052 << "*.tiff" << "*.xbm" << "*.xpm";
00053 } else {
00054 QString path = info.path(), files = info.fileName();
00055 QFileInfo info(path);
00056 if(not info.isDir())
00057 return false;
00058 dir = QDir(path);
00059 filters << files;
00060 }
00061 dir.setNameFilters(filters);
00062 dir.setSorting(QDir::Name);
00063 filenames = dir.entryList();
00064
00065 if(filenames.isEmpty())
00066 return false;
00067
00068
00069 noLoop = (suggested_options & QVVideoReader::NoLoop);
00070 realTime = (suggested_options & QVVideoReader::RealTime);
00071
00072 if(realTime)
00073 suggested_fps = 25;
00074
00075
00076
00077
00078 suggested_cols = suggested_rows = 0;
00079
00080 if(filenames.size() > 0) {
00081 index = 0;
00082 return true;
00083 } else
00084 return false;
00085 }
00086
00087 bool QVDirReader::close()
00088 {
00089 return true;
00090 }
00091
00092 bool QVDirReader::grab(QVImage<uChar,1> &imgR, QVImage<uChar,1> &imgG, QVImage<uChar,1> &imgB)
00093 {
00094 if(ended)
00095 return false;
00096
00097 QString fullpathtofile = dir.absolutePath() + "/" + filenames.at(index);
00098
00099
00100
00101 QVImage<uchar,3> ColorImage(fullpathtofile);
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 imgR = QVImage<uChar>(ColorImage.getCols(),ColorImage.getRows());
00116 imgG = QVImage<uChar>(ColorImage.getCols(),ColorImage.getRows());
00117 imgB = QVImage<uChar>(ColorImage.getCols(),ColorImage.getRows());
00118 Copy(ColorImage,0,imgR);
00119 Copy(ColorImage,1,imgG);
00120 Copy(ColorImage,2,imgB);
00121
00122 index = index + 1;
00123 if(index == filenames.size()) {
00124 if(noLoop) {
00125 ended = true;
00126 return false;
00127 } else
00128 index = 0;
00129 }
00130 return true;
00131 }
00132
00133 int QVDirReader::getLength()
00134 {
00135 return static_cast<double>(filenames.size());
00136 }
00137
00138 int QVDirReader::getPos()
00139 {
00140 return static_cast<double>(index);
00141 }
00142
00143 bool QVDirReader::seek(int pos)
00144 {
00145 index = pos;
00146 return true;
00147 }