Exemplo n.º 1
0
void PuReader::readHeader()
{
  std::string line;
  bool search = true;
  while (search)
  {
    *sourceFile >> line;
    search = !((line == "Luma") || (line == "Cb") || (line == "Cr"));
    if (search)
      readNextLine(sourceFile);
  }
  pu->setImgComp(getImgComp(line));

  int value;
  for (int i = 0; i < 3; i++)
  {
    *sourceFile >> line >> line >> value;
    if (i == 0)
      pu->setModeIdx(value);
    else if (i == 1)
      pu->setPuIdx(value);
    else if (i == 2)
      pu->setPuSize(value);
  }
  readNextLine(sourceFile);
}
/* SRT format:
 *   Subtitle number
 *   Start time --> End time
 *   Text of subtitle (one or more lines)
 *   Blank lines
 *
 * .srt file example:
 * 1
 * 00:00:20,000 --> 00:00:24,400
 * Altocumulus clouds occr between six thousand
 *
 * 2
 * 00:00:24,600 --> 00:00:27,800
 * and twenty thousand feet above ground level.
 */
status_t TimedTextSRTSource::getNextSubtitleInfo(
          off64_t *offset, int64_t *startTimeUs, TextInfo *info) {
    AString data;
    status_t err;

    // To skip blank lines.
    do {
        if ((err = readNextLine(offset, &data)) != OK) {
            return err;
        }
        data.trim();
    } while (data.empty());

    // Just ignore the first non-blank line which is subtitle sequence number.
    if ((err = readNextLine(offset, &data)) != OK) {
        return err;
    }
    int hour1, hour2, min1, min2, sec1, sec2, msec1, msec2;
    // the start time format is: hours:minutes:seconds,milliseconds
    // 00:00:24,600 --> 00:00:27,800
    if (sscanf(data.c_str(), "%02d:%02d:%02d,%03d --> %02d:%02d:%02d,%03d",
               &hour1, &min1, &sec1, &msec1, &hour2, &min2, &sec2, &msec2) != 8) {
        return ERROR_MALFORMED;
    }

    *startTimeUs = ((hour1 * 3600 + min1 * 60 + sec1) * 1000 + msec1) * 1000ll;
    info->endTimeUs = ((hour2 * 3600 + min2 * 60 + sec2) * 1000 + msec2) * 1000ll;
    if (info->endTimeUs <= *startTimeUs) {
        return ERROR_MALFORMED;
    }

    info->offset = *offset;
    bool needMoreData = true;
    while (needMoreData) {
        if ((err = readNextLine(offset, &data)) != OK) {
            if (err == ERROR_END_OF_STREAM) {
                break;
            } else {
                return err;
            }
        }

        data.trim();
        if (data.empty()) {
            // it's an empty line used to separate two subtitles
            needMoreData = false;
        }
    }
    info->textLen = *offset - info->offset;
    return OK;
}
Exemplo n.º 3
0
// Parse delimited (from file)
int LineParser::getArgsDelim(int optionMask)
{
	Messenger::enter("LineParser::getArgsDelim[ifstream]");
	bool done = false;
	int result;

	// Returns : 0=ok, 1=error, -1=eof
	do
	{
		// Read line from file and parse it
		result = readNextLine(optionMask);
		if (result != 0)
		{
			Messenger::exit("LineParser::getArgsDelim[ifstream]");
			return result;
		}
		// Assume that we will finish after parsing the line we just read in
		done = true;
		// To check for blank lines, do the parsing and then check nargs()
		getAllArgsDelim(optionMask);
		if ((optionMask&Parser::SkipBlanks) && (nArgs() == 0)) done = false;
	} while (!done);

	Messenger::exit("LineParser::getArgsDelim[ifstream]");
	return 0;
}
Exemplo n.º 4
0
    /*!returns the next string in the file
    @return the next string*/
    inline std::string next() {

        //read until we find a non white space character
        while (file.good()) {

            //read through this line looking for non-white space chars
            for (unsigned i = 0; i < currentLine.length(); ++i) {

                //look for non-white space char
                if (currentLine[i] != ' ' && currentLine[i] != '\t') {

                    //remove the white space
                    currentLine = currentLine.substr(i, currentLine.length());

                    //read the next full string and return
                    return readString();
                }
            }

            //get the next line
            readNextLine();
        }

        return "";
    }
Exemplo n.º 5
0
void Parser::reset()
{
    inputStream.clear();
    inputStream.seekg(0);
    linePos = 0;
    readNextLine(); // ?????????????????????????????????????????
}
Exemplo n.º 6
0
bool Parser::nextValidLine()
{
    if (!readNextLine())
        return false;

    while (true) {
        if (currentLine.empty() || it == currentLine.end()) {
            if (!readNextLine())
                return false;
        } else {
            break;
        }
    }

    return true;
}
Exemplo n.º 7
0
void PicRecon::readSeqParams()
{
  SeqParams *seqParams = SeqParams::getInstance();
  std::regex spsStart("SPS");
  std::smatch match;
  std::string line;
  int value;

  bool search = true;
  while (search)
  {
    line = readNextLine(&sourceFile);
    if (std::regex_search(line, match, spsStart))
    {
      search = false;
      for (int lineIdx = 0; lineIdx < 6; lineIdx++)
      {
        sourceFile >> line;
        if (lineIdx == 0)
        {
          sourceFile >> line >> value;
          seqParams->setPicWidth(value);
        }
        else if (lineIdx == 1)
        {
          sourceFile >> line >> value;
          seqParams->setPicHeight(value);
        }
        else if (lineIdx == 2)
Exemplo n.º 8
0
void PuReader::readSamples()
{
  for (int y = 0; y < pu->getPuSize(); y++)
  {
    for (int x = 0; x < pu->getPuSize(); x++)
      *sourceFile >> samples[x][y];
    readNextLine(sourceFile);
  }
}
Exemplo n.º 9
0
    /*!Gets the next line in the scanner
    @return the next line*/
    inline std::string nextLine() {

        //store the current line
        std::string nextLine = currentLine;
        //get the next line'
        readNextLine();

        return nextLine;
    }
Exemplo n.º 10
0
    /*!Creates a new file scanner
    @_path the path of the file to open*/
    FileScanner(const std::string& _path) :
        path(_path) {

        //open the file
        file.open(path.c_str());

        //get the next line
        readNextLine();
    }
Exemplo n.º 11
0
// Get arguments according to specified format
bool LineParser::getArgsFormatted(ParseFormat& format, int optionMask, bool readLine)
{
	Messenger::enter("LineParser::getArgsFormatted");
	bool done = false;
	int result;

	arguments_.clear();

	// Get line from file?
	if (readLine)
	{
		// Returns : 0=ok, 1=error, -1=eof
		result = readNextLine(optionMask);
		
		if (result != 0)
		{
			Messenger::exit("LineParser::getArgsFormatted");
			return result;
		}
	}

	// Loop over chunks in format
	QString arg;
	bool failed = false;
	for (ParseChunk* chunk = format.chunks(); chunk != NULL; chunk = chunk->next)
	{
		switch (chunk->type())
		{
			case (ParseChunk::DelimitedChunk):
				if (getNextArg(optionMask, arg)) arguments_ << arg;
				else failed = true;
				break;
			case (ParseChunk::FormattedChunk):
				if (getNextN(optionMask, chunk->formatLength(), arg)) arguments_ << arg;
				else failed = true;
				break;
			case (ParseChunk::DiscardChunk):
				if (!getNextN(optionMask, chunk->formatLength(), arg)) failed = true;
				break;
			case (ParseChunk::PlainTextChunk):
				if (!getNextN(optionMask, chunk->cFormat().length(), arg)) failed = true;
				break;
			case (ParseChunk::GreedyDelimitedChunk):
				if (getRest(arg)) arguments_ << arg;
				else failed = true;
				break;
      default:
        break;
		}

		if (failed) break;
	}

	Messenger::exit("LineParser::getArgsFormatted");
	return 0;
}
Exemplo n.º 12
0
    /*!Copies this scanner from the other scanner
    #NOTE: this will not keep the position of the scanner
    @other the other scanner to copy from*/
    FileScanner(const FileScanner& other) {

        path = other.path;

        //open the file file
        file.open(path.c_str());

        //get the next line
        readNextLine();
    }
Exemplo n.º 13
0
    /*!Copies the file from the other scanner to this scanner
    #NOTE: this will not keep the position of the scanner
    @other the other scanner to copy from*/
    inline const FileScanner& operator=(const FileScanner& other) {

        path = other.path;

        //open the file file
        file.open(path.c_str());

        //get the next line
        readNextLine();

        return *this;
    }
Exemplo n.º 14
0
    /*!Reads the next string in the current line*/
    inline std::string readString() {

        //read until either the end of the the line
        //or a white space character
        for (unsigned i = 0; i < currentLine.length(); ++i) {

            if (currentLine[i] == ' ' || currentLine[i] == '\t') {

                //get this string
                std::string line = currentLine.substr(0, i);

                //find the next non white space character
                for (unsigned j = i; j < currentLine.length(); ++j) {

                    if (currentLine[j] != ' ' && currentLine[j] != '\t') {

                        currentLine =
                            currentLine.substr(j, currentLine.length());

                        return line;
                    }
                }

                readNextLine();
                
                return line;
            }
        }

        //store this line
        std::string line = currentLine;

        //read the next line
        readNextLine();

        return line;
    }
Exemplo n.º 15
0
// Skip lines from file
int LineParser::skipLines(int nlines)
{
	Messenger::enter("LineParser::skipLines");
	int result;
	for (int n=0; n<nlines; n++)
	{
		result = readNextLine(0);
		if (result != 0)
		{
			Messenger::exit("LineParser::skipLines");
			return result;
		}
	}
	Messenger::exit("LineParser::skipLines");
	return 0;
}
Exemplo n.º 16
0
void FileIO::open()
{
    if (mSource.isEmpty()){
        emit error("source is empty");
    }

    file = new QFile(mSource);

    if (!file->exists())
        emit error("file doesn't exist...");

    file->open(QIODevice::ReadOnly);

    file->readLine(); // Skip header


    currentSimTime = std::numeric_limits<double>::max();

    readNextLine(); // First datas
    currentSimTime = currentLine.value(TIME).toDouble();
}
Exemplo n.º 17
0
bool ObjParser::parse( std::istream& input )
{
    reset();

    // Read each line of the .obj file
    while ( readNextLine( input ) && !hasErrors() )
    {
        // Skip lines that are empty
        if ( isCurrentLineEmpty() )
        {
            continue;
        }

        // Split the input line into "words' that are separated by
        // spaces. The first word is the next obj file command, the others
        // that follow are arguments to that command
        std::vector<std::string> tokens;

        tokenizeCommandString( lineText(), tokens );
        assert( tokens.size() > 0 );

        // What kind of command is this?
        if ( tokens[0] == "v" )
        {
            processVertexPosition( tokens );
        }
        else if ( tokens[0] == "vt" )
        {
            processVertexTexCoord( tokens );
        }
        else if ( tokens[0] == "vn" )
        {
            processVertexNormal( tokens );
        }
        else if ( tokens[0] == "g" )
        {
            processGroup( tokens );
        }
        else if ( tokens[0] == "f" )
        {
            processFace( tokens );
        }
        else if ( tokens[0] == "usemtl" )
        {
            processMaterial( tokens );
        }
        else if ( tokens[0] == "mtllib" )
        {
            processMaterialLib( tokens );
        }
        else if ( tokens[0] == "s" )
        {
            // ignore smoothing groups
        }
        else
        {
            raiseError("Unknown .obj command encountered");
            continue;
        }
    }

    // Make sure the last group has at least one face in it
    if ( m_objdata->currentGroup.empty() == false )
    {
        if ( m_objdata->groups[ m_objdata->currentGroupIndex ].count == 0 )
        {
            raiseError("The last active group didn't have any faces");
        }
    }

    // Now we're done, make sure to return if the parsing was successful or
    // not
    return !hasErrors();
}
Exemplo n.º 18
0
Parser::Parser(istream& inputStream)
    : inputStream(inputStream),
      linePos(0)
{
    readNextLine(); // ???????????
}
Exemplo n.º 19
0
/* SRT format:
 *   Subtitle number
 *   Start time --> End time
 *   Text of subtitle (one or more lines)
 *   Blank lines
 *
 * .srt file example:
 * 1
 * 00:00:20,000 --> 00:00:24,400
 * Altocumulus clouds occr between six thousand
 *
 * 2
 * 00:00:24,600 --> 00:00:27,800
 * and twenty thousand feet above ground level.
 */
status_t TimedTextSRTSource::getNextSubtitleInfo(
          off64_t *offset, int64_t *startTimeUs, TextInfo *info) {
#ifdef MTK_SUBTITLE_SUPPORT
	MagicString data("", mFileEncodeType);
	MagicString* spString = new MagicString("-->", ENCODE_TYPE_NORMAL);
	int8_t typeSize = MagicString::sizeOfType(data.getType());
	status_t err;

	// To skip blank lines.
    do {
        if ((err = TimedTextUtil::readNextLine(mSource, offset, &data, mFileEncodeType)) != OK) {
			ALOGE("[SRT Parser] Reading Over Return Here! (EOS)");
			return err;
        }
        data.trim();
		MagicString::print("[Get Line]", data);
    } while (data.empty());

	MagicString::print("[Subtitle Index]", data);
	// Just ignore the first non-blank line which is subtitle sequence number.
    if ((err = TimedTextUtil::readNextLine(mSource,	offset, &data, mFileEncodeType)) != OK) {
        return err;
    }

	MagicString::print("[Time Line]",data);
	int64_t index = data.indexOf(spString);
	if(-1 == index || 0 == index){
		return ERROR_MALFORMED;
	}	

	sp<MagicString> time1 = data.subString(0, index - typeSize);
	time1->trim();
	MagicString::print("[StartTime]", time1);
	sp<MagicString> time2 = data.subString(index + spString->length() * typeSize);
	time2->trim();
	MagicString::print("[EndTime]", time2);

	// the start time format is: hours:minutes:seconds,milliseconds
	// 00:00:24,600 --> 00:00:27,800
	StructTime startTime = StructTime(time1); 
	StructTime endTime = StructTime(time2);

	*startTimeUs = startTime.calcTimeUs();
	info->endTimeUs = endTime.calcTimeUs();

	free(spString);

	ALOGE("[SRTParser] getStartTime=%lld, getEndTime=%lld", *startTimeUs, info->endTimeUs);
    if (info->endTimeUs <= *startTimeUs) {
        return ERROR_MALFORMED;
    }

    info->offset = *offset;
    bool needMoreData = true;
	int64_t lineBeginIndex = 0;
	int64_t lineLen = 0;
    while (needMoreData) {
		lineBeginIndex = *offset;
        if ((err = TimedTextUtil::readNextLine(mSource, offset, &data, mFileEncodeType)) != OK) {
            if (err == ERROR_END_OF_STREAM) {
                break;
            } else {
                return err;
            }
        }
		lineLen = data.length();
        data.trim();
		MagicString::print("[Get Subtitle]", data);
        if (data.empty()) {
            // it's an empty line used to separate two subtitles
            needMoreData = false;
		}else{		
			info->textLen = lineBeginIndex + lineLen - info->offset;
			//ALOGE("[SRT Parser] read a subtitle line begin=%lld, lineLen =%lld, end=%d", lineBeginIndex, lineLen, info->textLen);
        }
    }
	//ALOGE("[SRT Parser] subtitle from=%lld, len=%d", info->offset, info->textLen);
    return OK;
#else
    AString data;
    status_t err;

    // To skip blank lines.
    do {
        if ((err = readNextLine(offset, &data)) != OK) {
            return err;
        }
        data.trim();
    } while (data.empty());

    // Just ignore the first non-blank line which is subtitle sequence number.
    if ((err = readNextLine(offset, &data)) != OK) {
        return err;
    }
    int hour1, hour2, min1, min2, sec1, sec2, msec1, msec2;
    // the start time format is: hours:minutes:seconds,milliseconds
    // 00:00:24,600 --> 00:00:27,800
    if (sscanf(data.c_str(), "%02d:%02d:%02d,%03d --> %02d:%02d:%02d,%03d",
               &hour1, &min1, &sec1, &msec1, &hour2, &min2, &sec2, &msec2) != 8) {
        return ERROR_MALFORMED;
    }

    *startTimeUs = ((hour1 * 3600 + min1 * 60 + sec1) * 1000 + msec1) * 1000ll;
    info->endTimeUs = ((hour2 * 3600 + min2 * 60 + sec2) * 1000 + msec2) * 1000ll;
    if (info->endTimeUs <= *startTimeUs) {
        return ERROR_MALFORMED;
    }

    info->offset = *offset;
    bool needMoreData = true;
    while (needMoreData) {
        if ((err = readNextLine(offset, &data)) != OK) {
            if (err == ERROR_END_OF_STREAM) {
                break;
            } else {
                return err;
            }
        }

        data.trim();
        if (data.empty()) {
            // it's an empty line used to separate two subtitles
            needMoreData = false;
        }
    }
    info->textLen = *offset - info->offset;
    return OK;
#endif
}