Rational operator*(Rational num1, Rational num2) { int c = num1.getB() * num2.getB(); int d = num1.getA() * num2.getA(); return Rational(d, c); }
Rational Rational::Inverse() { if(num == 0) return Rational(num, den); else return Rational(den, num); }
Rational opposite() const { return Rational(-numerator, denominator); }
bool Rational::operator>(int right) const { return *this > Rational(right, 1); }
bool QuadraticField::FindSqrt(std::vector<Rational> root_) { if(root_.size() != degree) return false; else if(degree==2) { // We look for a square root of the form a+b*R^(1/2) where a,b rational. // For the notes, we are finding the square root of X+Y*R^(1/2) // so that X = root_[0] and Y = root_[1]. Rational newroot(1,1), newrootB(1,1); // Extra variables that will be necessary later if(root_[1].IsZero()) { // The case of finding square root of X // Solve a^2 + R b^2 = X and 2ab = 0 // The case that a=0 // Look at b = (X/R)^(1/2) newroot = root_[0]*Root[0].Inverse(); if(newroot.FindSqrt()) { Result[0] = Rational(0,1); Result[1] = newroot.GetSqrt(); return true; } // The case that b=0 // Look at a = X^(1/2) newroot = root_[0]; if(newroot.FindSqrt()) { Result[0] = newroot.GetSqrt(); Result[1] = Rational(0,1); return true; } // Neither Case Works, so there is no square root return false; } else { // Looking at the hardest case of Y non-zero // Solve a^2 + R b^2 = X and 2ab = Y // Now know that a and b both are non-zero, // So it is safe to substitute b = Y/2a into the // first equation. // So we must solve a^2 + (R/4) Y^2/a^2 = X // equivalent to a^4 - X a^2 + (R/4) Y^2 = 0. // Need to find a in Q satisfying quartic polynomial. // Quadratic Formula tells us a^2 is in Q iff // (X^2 - R Y^2)^(1/2) is in Q. First check this. newroot = root_[0]*root_[0] - Root[0]*root_[1]*root_[1]; if(newroot.FindSqrt()) { // Know that a^2 is in the Q. Need to check square root // of either positive or negative root to see if any a // is in the field newroot = newroot.GetSqrt(); // Check the plus root newrootB = (root_[0]+newroot)*Rational(1,2); if(newrootB.FindSqrt()) { Result[0] = newrootB.GetSqrt(); Result[1] = root_[1]*Rational(1,2)*Result[0].Inverse(); return true; } //Check the minus root newrootB = (root_[0]-newroot)*Rational(1,2); if(newrootB.FindSqrt()) { Result[0] = newrootB.GetSqrt(); Result[1] = root_[1]*Rational(1,2)*Result[0].Inverse(); return true; } // Neither plus/minus root has a root in Q. So there is no rational root return false; } else return false; } } else { return false; } }
Rational &Rational::operator-=(int right) { return *this -= Rational(right); }
Rational &Rational::operator/=(int right) { return *this /= Rational(right); }
Rational Rational::operator-() const { return Rational(-numerator, denominator, no_normalise_tag()); }
void WaveAudioEssenceReader::setEditRate(const Rational& rate) { _editRate = rate; //WaveAudioEssenceDescriptor* waed = // dynamic_cast<WaveAudioEssenceDescriptor*>(_descriptor); //if (waed == 0) //{ // /// \todo report error // return; //} //waed->setSampleRate(rate); // A call to set the edit rate will also set the container duration. // Calculate frame and buffer sizes _baseSampleCount = 0; // reset so we can detect error if (rate == Rational(30000, 1001)) { if (_fmtChunk->nSamplesPerSec == 48000) { _baseSampleCount = 1600; _additionalSampleCounts = 5; _additionalSampleCount[0] = 2; _additionalSampleCount[1] = 1; _additionalSampleCount[2] = 2; _additionalSampleCount[3] = 1; _additionalSampleCount[4] = 2; } /// \todo warn if audio data isn't 48kHz } else { _baseSampleCount = (UInt32)( _fmtChunk->nSamplesPerSec * (UInt64) rate.getDenominator() / (UInt64) rate.getNumerator()); _additionalSampleCounts = 0; } _combinedDataLength = 0; if (_additionalSampleCounts > 0) { // Calculate the average buffer size for (UInt32 i = 0; i < _additionalSampleCounts; ++i) { _combinedDataLength += (_baseSampleCount + _additionalSampleCount[i]) * (_fmtChunk->wBitsPerSample / 8) * _fmtChunk->nChannels; } } else { _combinedDataLength = _baseSampleCount * (_fmtChunk->wBitsPerSample / 8) * _fmtChunk->nChannels; } if (_baseSampleCount == 0 || _combinedDataLength == 0) { // We've failed to determine the size of an edit unit error(ESS_ERROR_FailedToDetermineFrameSize); return; } // Update the duration for the essence descriptor if (_additionalSampleCounts > 0) { Length duration = ((_dataLength * _additionalSampleCounts) / _combinedDataLength); // we have to do the rounding manually as ceil() takes a double // and VC6 can't handle unsigned int64 to double... Length rem = (_dataLength * _additionalSampleCounts) % _combinedDataLength; if (rem != 0) duration++; // round up //waed->setContainerDuration(duration); _containerDuration = duration; } else { Length duration = _dataLength / _combinedDataLength; // we have to do the rounding manually as ceil() takes a double // and VC6 can't handle unsigned int64 to double... Length rem = _dataLength % _combinedDataLength; if (rem != 0) duration++; // round up //waed->setContainerDuration(duration); _containerDuration = duration; } }
Expr Expr::operator-() const { return Sum::rational_multiple(*this, Rational(-1)).simplify(); }
Rational Xmpdatum::toRational(long n) const { return p_->value_.get() == 0 ? Rational(-1, 1) : p_->value_->toRational(n); }
VideoFormat::VideoFormat(AVCodecContext * ctx) { _width=ctx->width; _height=ctx->height; _framerate=Rational(ctx->time_base.num,ctx->time_base.den); _type=FORMAT_VIDEO; }
Point(const Rational& x = Rational(), const Rational& y = Rational()) : x_(x), y_(y) { }
Rational operator^(Rational num1, int power) { int c = pow(num1.getB(), power); int d = pow(num1.getA(), power); return Rational(d, c); }
Rational & operator /=( int i ) { (*this) /= Rational(i); return * this ; }
void Broder86::computeNeighbours(const BipartiteMatching& s, boost::unordered_map<BipartiteMatching, Rational>& neighbors) const { // Variables const int n = g.getNumberOfNodes(); const int k = s.k; int u, v; BipartiteMatching s2; edgelist edges; neighbors.clear(); // Implementierung der Transitionen nach Vorlage JS89 // Gehe über jede Kante g.getEdges(edges); //std::cout << "compute neighbors for s=" << s << std::endl; // Für jede Wahl einer Kante e=(u,v) wird Transition konstruiert for (typename edgelist::iterator it = edges.begin(); it != edges.end(); ++it) { u = it->first; v = it->second; // create new state as copy of old one s2 = BipartiteMatching(s); // Transition 1 if (2 * k == n && s.mates[u] == v) { // remove edge (u,v) s2.mates[u] = n; s2.mates[v] = n; s2.k = k - 1; s2.unmatched[0] = u; s2.unmatched[1] = v; } else if (2 * k + 2 == n) { // Transition 2 if (s.mates[u] == n && s.mates[v] == n) { // add edge (u,v) s2.mates[u] = v; s2.mates[v] = u; s2.k = k + 1; s2.unmatched[0] = n; s2.unmatched[1] = n; } // Transition 3a else if (s.mates[u] != n && s.mates[v] == n) { // remove edge (u, mate[u]) // add edge (u,v) int w = s.mates[u]; s2.mates[w] = n; s2.mates[u] = v; s2.mates[v] = u; // w=mate[u] (>= n/2) becomes unmatched node in bipartition group 1 s2.unmatched[1] = w; } // Transition 3b else if (s.mates[u] == n && s.mates[v] != n) { // remove edge (v, mate[v]) // add edge (u,v) int w = s.mates[v]; s2.mates[w] = n; s2.mates[u] = v; s2.mates[v] = u; // w=mate[v] (< n/2) becomes unmatched node in bipartition group 0 s2.unmatched[0] = w; } else { // stay in s } } // sonst else { // Verbleibe im aktuellen Zustand } neighbors[s2] += Rational(1, edges.size()); //std::cout << std::endl; } }
Rational &Rational::operator+=(int right) { return *this += Rational(right); }
// load up the data for a level bool levLoadData(char const *name, Sha256 const *hash, char *pSaveName, GAME_TYPE saveType) { LEVEL_DATASET *psNewLevel, *psBaseData, *psChangeLevel; bool bCamChangeSaveGame; debug(LOG_WZ, "Loading level %s hash %s (%s, type %d)", name, hash == nullptr ? "builtin" : hash->toString().c_str(), pSaveName, (int)saveType); if (saveType == GTYPE_SAVE_START || saveType == GTYPE_SAVE_MIDMISSION) { if (!levReleaseAll()) { debug(LOG_ERROR, "Failed to unload old data"); return false; } } levelLoadType = saveType; // find the level dataset psNewLevel = levFindDataSet(name, hash); if (psNewLevel == nullptr) { debug(LOG_INFO, "Dataset %s not found - trying to load as WRF", name); return levLoadSingleWRF(name); } debug(LOG_WZ, "** Data set found is %s type %d", psNewLevel->pName, (int)psNewLevel->type); /* Keep a copy of the present level name */ sstrcpy(currentLevelName, name); bCamChangeSaveGame = false; if (pSaveName && saveType == GTYPE_SAVE_START) { if (psNewLevel->psChange != nullptr) { bCamChangeSaveGame = true; debug(LOG_WZ, "** CAMCHANGE FOUND"); } } // select the change dataset if there is one psChangeLevel = nullptr; if (((psNewLevel->psChange != nullptr) && (psCurrLevel != nullptr)) || bCamChangeSaveGame) { //store the level name debug(LOG_WZ, "Found CAMCHANGE dataset"); psChangeLevel = psNewLevel; psNewLevel = psNewLevel->psChange; } // ensure the correct dataset is loaded if (psNewLevel->type == LDS_CAMPAIGN) { debug(LOG_ERROR, "Cannot load a campaign dataset (%s)", psNewLevel->pName); return false; } else { if (psCurrLevel != nullptr) { if ((psCurrLevel->psBaseData != psNewLevel->psBaseData) || (psCurrLevel->type < LDS_NONE && psNewLevel->type >= LDS_NONE) || (psCurrLevel->type >= LDS_NONE && psNewLevel->type < LDS_NONE)) { // there is a dataset loaded but it isn't the correct one debug(LOG_WZ, "Incorrect base dataset loaded (%p != %p, %d - %d)", psCurrLevel->psBaseData, psNewLevel->psBaseData, (int)psCurrLevel->type, (int)psNewLevel->type); if (!levReleaseAll()) // this sets psCurrLevel to NULL { debug(LOG_ERROR, "Failed to release old data"); return false; } } else { debug(LOG_WZ, "Correct base dataset already loaded."); } } // setup the correct dataset to load if necessary if (psCurrLevel == nullptr) { if (psNewLevel->psBaseData != nullptr) { debug(LOG_WZ, "Setting base dataset to load: %s", psNewLevel->psBaseData->pName); } psBaseData = psNewLevel->psBaseData; } else { debug(LOG_WZ, "No base dataset to load"); psBaseData = nullptr; } } if (!rebuildSearchPath(psNewLevel->dataDir, true, psNewLevel->realFileName)) { debug(LOG_ERROR, "Failed to rebuild search path"); return false; } // reset the old mission data if necessary if (psCurrLevel != nullptr) { debug(LOG_WZ, "Reseting old mission data"); if (!levReleaseMissionData()) { debug(LOG_ERROR, "Failed to unload old mission data"); return false; } } // need to free the current map and droids etc for a save game if (psBaseData == nullptr && pSaveName != nullptr) { if (!saveGameReset()) { debug(LOG_ERROR, "Failed to saveGameReset()!"); return false; } } // initialise if necessary if (psNewLevel->type == LDS_COMPLETE || psBaseData != nullptr) { debug(LOG_WZ, "Calling stageOneInitialise!"); if (!stageOneInitialise()) { debug(LOG_ERROR, "Failed stageOneInitialise!"); return false; } } // load up a base dataset if necessary if (psBaseData != nullptr) { debug(LOG_WZ, "Loading base dataset %s", psBaseData->pName); for (int i = 0; i < LEVEL_MAXFILES; i++) { if (psBaseData->apDataFiles[i]) { // load the data debug(LOG_WZ, "Loading [directory: %s] %s ...", PHYSFS_getRealDir(psBaseData->apDataFiles[i]), psBaseData->apDataFiles[i]); if (!resLoad(psBaseData->apDataFiles[i], i)) { debug(LOG_ERROR, "Failed resLoad(%s)!", psBaseData->apDataFiles[i]); return false; } } } } if (psNewLevel->type == LDS_CAMCHANGE) { if (!campaignReset()) { debug(LOG_ERROR, "Failed campaignReset()!"); return false; } } if (psNewLevel->game == -1) //no .gam file to load - BETWEEN missions (for Editor games only) { ASSERT(psNewLevel->type == LDS_BETWEEN, "Only BETWEEN missions do not need a .gam file"); debug(LOG_WZ, "No .gam file for level: BETWEEN mission"); if (pSaveName != nullptr) { if (psBaseData != nullptr) { if (!stageTwoInitialise()) { debug(LOG_ERROR, "Failed stageTwoInitialise()!"); return false; } } //set the mission type before the saveGame data is loaded if (saveType == GTYPE_SAVE_MIDMISSION) { debug(LOG_WZ, "Init mission stuff"); if (!startMissionSave(psNewLevel->type)) { debug(LOG_ERROR, "Failed startMissionSave(%d)!", psNewLevel->type); return false; } debug(LOG_NEVER, "dataSetSaveFlag"); dataSetSaveFlag(); } debug(LOG_NEVER, "Loading savegame: %s", pSaveName); if (!loadGame(pSaveName, false, true, true)) { debug(LOG_ERROR, "Failed loadGame(%s)!", pSaveName); return false; } } if (pSaveName == nullptr || saveType == GTYPE_SAVE_START) { debug(LOG_NEVER, "Start mission - no .gam"); if (!startMission((LEVEL_TYPE)psNewLevel->type, nullptr)) { debug(LOG_ERROR, "Failed startMission(%d)!", psNewLevel->type); return false; } } } //we need to load up the save game data here for a camchange if (bCamChangeSaveGame) { if (pSaveName != nullptr) { if (psBaseData != nullptr) { if (!stageTwoInitialise()) { debug(LOG_ERROR, "Failed stageTwoInitialise() [camchange]!"); return false; } } debug(LOG_NEVER, "loading savegame: %s", pSaveName); if (!loadGame(pSaveName, false, true, true)) { debug(LOG_ERROR, "Failed loadGame(%s)!", pSaveName); return false; } campaignReset(); } } // load the new data debug(LOG_NEVER, "Loading mission dataset: %s", psNewLevel->pName); for (int i = 0; i < LEVEL_MAXFILES; i++) { if (psNewLevel->game == i) { // do some more initialising if necessary if (psNewLevel->type == LDS_COMPLETE || psNewLevel->type >= LDS_MULTI_TYPE_START || (psBaseData != nullptr && !bCamChangeSaveGame)) { if (!stageTwoInitialise()) { debug(LOG_ERROR, "Failed stageTwoInitialise() [newdata]!"); return false; } } // load a savegame if there is one - but not if already done so if (pSaveName != nullptr && !bCamChangeSaveGame) { //set the mission type before the saveGame data is loaded if (saveType == GTYPE_SAVE_MIDMISSION) { debug(LOG_WZ, "Init mission stuff"); if (!startMissionSave(psNewLevel->type)) { debug(LOG_ERROR, "Failed startMissionSave(%d)!", psNewLevel->type); return false; } debug(LOG_NEVER, "dataSetSaveFlag"); dataSetSaveFlag(); } debug(LOG_NEVER, "Loading save game %s", pSaveName); if (!loadGame(pSaveName, false, true, true)) { debug(LOG_ERROR, "Failed loadGame(%s)!", pSaveName); return false; } } if (pSaveName == nullptr || saveType == GTYPE_SAVE_START) { // load the game debug(LOG_WZ, "Loading scenario file %s", psNewLevel->apDataFiles[i]); switch (psNewLevel->type) { case LDS_COMPLETE: case LDS_CAMSTART: debug(LOG_WZ, "LDS_COMPLETE / LDS_CAMSTART"); if (!startMission(LDS_CAMSTART, psNewLevel->apDataFiles[i])) { debug(LOG_ERROR, "Failed startMission(%d, %s)!", LDS_CAMSTART, psNewLevel->apDataFiles[i]); return false; } break; case LDS_BETWEEN: debug(LOG_WZ, "LDS_BETWEEN"); if (!startMission(LDS_BETWEEN, psNewLevel->apDataFiles[i])) { debug(LOG_ERROR, "Failed startMission(%d, %s)!", LDS_BETWEEN, psNewLevel->apDataFiles[i]); return false; } break; case LDS_MKEEP: debug(LOG_WZ, "LDS_MKEEP"); if (!startMission(LDS_MKEEP, psNewLevel->apDataFiles[i])) { debug(LOG_ERROR, "Failed startMission(%d, %s)!", LDS_MKEEP, psNewLevel->apDataFiles[i]); return false; } break; case LDS_CAMCHANGE: debug(LOG_WZ, "LDS_CAMCHANGE"); if (!startMission(LDS_CAMCHANGE, psNewLevel->apDataFiles[i])) { debug(LOG_ERROR, "Failed startMission(%d, %s)!", LDS_CAMCHANGE, psNewLevel->apDataFiles[i]); return false; } break; case LDS_EXPAND: debug(LOG_WZ, "LDS_EXPAND"); if (!startMission(LDS_EXPAND, psNewLevel->apDataFiles[i])) { debug(LOG_ERROR, "Failed startMission(%d, %s)!", LDS_EXPAND, psNewLevel->apDataFiles[i]); return false; } break; case LDS_EXPAND_LIMBO: debug(LOG_WZ, "LDS_LIMBO"); if (!startMission(LDS_EXPAND_LIMBO, psNewLevel->apDataFiles[i])) { debug(LOG_ERROR, "Failed startMission(%d, %s)!", LDS_EXPAND_LIMBO, psNewLevel->apDataFiles[i]); return false; } break; case LDS_MCLEAR: debug(LOG_WZ, "LDS_MCLEAR"); if (!startMission(LDS_MCLEAR, psNewLevel->apDataFiles[i])) { debug(LOG_ERROR, "Failed startMission(%d, %s)!", LDS_MCLEAR, psNewLevel->apDataFiles[i]); return false; } break; case LDS_MKEEP_LIMBO: debug(LOG_WZ, "LDS_MKEEP_LIMBO"); if (!startMission(LDS_MKEEP_LIMBO, psNewLevel->apDataFiles[i])) { debug(LOG_ERROR, "Failed startMission(%d, %s)!", LDS_MKEEP_LIMBO, psNewLevel->apDataFiles[i]); return false; } break; default: ASSERT(psNewLevel->type >= LDS_MULTI_TYPE_START, "Unexpected mission type"); debug(LOG_WZ, "default (MULTIPLAYER)"); if (!startMission(LDS_CAMSTART, psNewLevel->apDataFiles[i])) { debug(LOG_ERROR, "Failed startMission(%d, %s) (default)!", LDS_CAMSTART, psNewLevel->apDataFiles[i]); return false; } break; } } } else if (psNewLevel->apDataFiles[i]) { // load the data debug(LOG_WZ, "Loading %s", psNewLevel->apDataFiles[i]); if (!resLoad(psNewLevel->apDataFiles[i], i + CURRENT_DATAID)) { debug(LOG_ERROR, "Failed resLoad(%s, %d) (default)!", psNewLevel->apDataFiles[i], i + CURRENT_DATAID); return false; } } } if (bMultiPlayer) { // This calls resLoadFile("SMSG", "multiplay.txt"). Must be before loadMissionExtras, which calls loadSaveMessage, which calls getViewData. loadMultiScripts(); } if (pSaveName != nullptr) { //load MidMission Extras if (!loadMissionExtras(pSaveName, psNewLevel->type)) { debug(LOG_ERROR, "Failed loadMissionExtras(%s, %d)!", pSaveName, psNewLevel->type); return false; } } if (pSaveName != nullptr && saveType == GTYPE_SAVE_MIDMISSION) { //load script stuff // load the event system state here for a save game debug(LOG_SAVE, "Loading script system state"); if (!loadScriptState(pSaveName)) { debug(LOG_ERROR, "Failed loadScriptState(%s)!", pSaveName); return false; } } if (!stageThreeInitialise()) { debug(LOG_ERROR, "Failed stageThreeInitialise()!"); return false; } dataClearSaveFlag(); //this enables us to to start cam2/cam3 without going via a save game and get the extra droids //in from the script-controlled Transporters if (!pSaveName && psNewLevel->type == LDS_CAMSTART) { eventFireCallbackTrigger((TRIGGER_TYPE)CALL_NO_REINFORCEMENTS_LEFT); } //restore the level name for comparisons on next mission load up if (psChangeLevel == nullptr) { psCurrLevel = psNewLevel; } else { psCurrLevel = psChangeLevel; } // Copy this info to be used by the crash handler for the dump file char buf[256]; ssprintf(buf, "Current Level/map is %s", psCurrLevel->pName); addDumpInfo(buf); triggerEvent(TRIGGER_GAME_LOADED); if (autogame_enabled()) { gameTimeSetMod(Rational(500)); if (hostlaunch != 2) // tests will specify the AI manually { jsAutogameSpecific("multiplay/skirmish/semperfi.js", selectedPlayer); } } return true; }
Rational &Rational::operator*=(int right) { return *this *= Rational(right); }
Rational toRational(long n =0) const { return value_.get() == 0 ? Rational(-1, 1) : value_->toRational(n); }
const Rational Rational::operator-() const { return Rational(-_num, _denom); }
Tsubtitle* TsubtitleParserSSA::parse(Tstream &fd, int flags, REFERENCE_TIME start, REFERENCE_TIME stop) { /* * Sub Station Alpha v4 (and v2?) scripts have 9 commas before subtitle * other Sub Station Alpha scripts have only 8 commas before subtitle * Reading the "ScriptType:" field is not reliable since many scripts appear * w/o it * * http://www.scriptclub.org is a good place to find more examples * http://www.eswat.demon.co.uk is where the SSA specs can be found */ wchar_t line0[this->LINE_LEN + 1]; wchar_t *line = line0; int playResXscript = 0, playResYscript = 0; while (fd.fgets(line, this->LINE_LEN)) { #if 0 DPRINTF(L"%s", line); #endif lineID++; if (line[0] == ';') { continue; } wchar_t *cr = strrchr(line, '\n'); if (cr) { *cr = '\0'; } cr = strrchr(line, '\r'); if (cr) { *cr = '\0'; } if (strnicmp(line, L"[Script Info]", 13) == 0) { inV4styles = 0; inEvents = 0; inInfo = 1; } else if (inInfo && strnicmp(line, L"PlayResX:", 8) == 0) { nmTextSubtitles::strToInt(line + 9, &playResXscript); } else if (inInfo && strnicmp(line, L"PlayResY:", 8) == 0) { nmTextSubtitles::strToInt(line + 9, &playResYscript); } else if (inInfo && strnicmp(line, L"Timer:", 6) == 0) { wchar_t *end; double t = strtod(line + 7, &end); if (*end == '\0' && t != 0) { timer = Rational(t / 100.0, _I32_MAX); } } else if (inInfo && strnicmp(line, L"WrapStyle:", 9) == 0) { nmTextSubtitles::strToInt(line + 10, &wrapStyle); } else if (inInfo && strnicmp(line, L"ScaledBorderAndShadow:", 21) == 0) { nmTextSubtitles::strToInt(line + 22, &scaleBorderAndShadow); } else if (strnicmp(line, L"[V4 Styles]", 11) == 0) { version = nmTextSubtitles::SSA; inV4styles = 2; inEvents = 0; inInfo = 0; } else if (strnicmp(line, L"[V4+ Styles]", 11) == 0) { version = nmTextSubtitles::ASS; inV4styles = 2; inEvents = 0; inInfo = 0; } else if (strnicmp(line, L"[V4++ Styles]", 11) == 0) { version = nmTextSubtitles::ASS2; inV4styles = 2; inEvents = 0; inInfo = 0; } else if (strnicmp(line, L"[Events]", 8) == 0) { inV4styles = 0; inEvents = 2; inInfo = 0; } else if (inV4styles == 2 && strnicmp(line, L"Format:", 7) == 0) { strlwr(line); strrmchar(line, L' '); typedef std::vector<Tstrpart > Tparts; Tparts fields; const wchar_t *l = line + 7; strtok(l, L",", fields); styleFormat.clear(); for (Tparts::const_iterator f = fields.begin(); f != fields.end(); f++) { if (strnicmp(f->first, L"name", 4) == 0) { styleFormat.push_back(&TSSAstyle::name); } else if (strnicmp(f->first, L"layer", 5) == 0) { styleFormat.push_back(&TSSAstyle::layer); } else if (strnicmp(f->first, L"fontname", 8) == 0) { styleFormat.push_back(&TSSAstyle::fontname); } else if (strnicmp(f->first, L"fontsize", 8) == 0) { styleFormat.push_back(&TSSAstyle::fontsize); } else if (strnicmp(f->first, L"primaryColour", 13) == 0) { styleFormat.push_back(&TSSAstyle::primaryColour); } else if (strnicmp(f->first, L"SecondaryColour", 15) == 0) { styleFormat.push_back(&TSSAstyle::secondaryColour); } else if (strnicmp(f->first, L"TertiaryColour", 14) == 0) { styleFormat.push_back(&TSSAstyle::tertiaryColour); } else if (strnicmp(f->first, L"OutlineColour", 13) == 0) { styleFormat.push_back(&TSSAstyle::outlineColour); } else if (strnicmp(f->first, L"BackColour", 10) == 0) { styleFormat.push_back(&TSSAstyle::backgroundColour); } else if (strnicmp(f->first, L"bold", 4) == 0) { styleFormat.push_back(&TSSAstyle::bold); } else if (strnicmp(f->first, L"italic", 6) == 0) { styleFormat.push_back(&TSSAstyle::italic); } else if (strnicmp(f->first, L"Underline", 9) == 0) { styleFormat.push_back(&TSSAstyle::underline); } else if (strnicmp(f->first, L"Strikeout", 9) == 0) { styleFormat.push_back(&TSSAstyle::strikeout); } else if (strnicmp(f->first, L"ScaleX", 6) == 0) { styleFormat.push_back(&TSSAstyle::fontScaleX); } else if (strnicmp(f->first, L"ScaleY", 6) == 0) { styleFormat.push_back(&TSSAstyle::fontScaleY); } else if (strnicmp(f->first, L"Spacing", 7) == 0) { styleFormat.push_back(&TSSAstyle::spacing); } else if (strnicmp(f->first, L"Angle", 5) == 0) { styleFormat.push_back(&TSSAstyle::angleZ); } else if (strnicmp(f->first, L"outline", 7) == 0) { styleFormat.push_back(&TSSAstyle::outlineWidth); } else if (strnicmp(f->first, L"shadow", 6) == 0) { styleFormat.push_back(&TSSAstyle::shadowDepth); } else if (strnicmp(f->first, L"alignment", 9) == 0) { styleFormat.push_back(&TSSAstyle::alignment); } else if (strnicmp(f->first, L"encoding", 8) == 0) { styleFormat.push_back(&TSSAstyle::encoding); } else if (strnicmp(f->first, L"marginl", 7) == 0) { styleFormat.push_back(&TSSAstyle::marginLeft); } else if (strnicmp(f->first, L"marginr", 7) == 0) { styleFormat.push_back(&TSSAstyle::marginRight); } else if (strnicmp(f->first, L"marginv", 7) == 0) { styleFormat.push_back(&TSSAstyle::marginV); } else if (strnicmp(f->first, L"borderstyle", 11) == 0) { styleFormat.push_back(&TSSAstyle::borderStyle); } else { styleFormat.push_back(NULL); } } inV4styles = 1; } else if (inV4styles && strnicmp(line, L"Style:", 6) == 0) { if (inV4styles == 2) { styleFormat.clear(); if (version == nmTextSubtitles::ASS2) { styleFormat.push_back(&TSSAstyle::name); styleFormat.push_back(&TSSAstyle::fontname); styleFormat.push_back(&TSSAstyle::fontsize); styleFormat.push_back(&TSSAstyle::primaryColour); styleFormat.push_back(&TSSAstyle::secondaryColour); styleFormat.push_back(&TSSAstyle::tertiaryColour); styleFormat.push_back(&TSSAstyle::backgroundColour); styleFormat.push_back(&TSSAstyle::bold); styleFormat.push_back(&TSSAstyle::italic); if (version >= nmTextSubtitles::ASS) { styleFormat.push_back(&TSSAstyle::underline); } if (version >= nmTextSubtitles::ASS) { styleFormat.push_back(&TSSAstyle::strikeout); } if (version >= nmTextSubtitles::ASS) { styleFormat.push_back(&TSSAstyle::fontScaleX); } if (version >= nmTextSubtitles::ASS) { styleFormat.push_back(&TSSAstyle::fontScaleY); } if (version >= nmTextSubtitles::ASS) { styleFormat.push_back(&TSSAstyle::spacing); } if (version >= nmTextSubtitles::ASS) { styleFormat.push_back(&TSSAstyle::angleZ); } styleFormat.push_back(&TSSAstyle::borderStyle); styleFormat.push_back(&TSSAstyle::outlineWidth); styleFormat.push_back(&TSSAstyle::shadowDepth); styleFormat.push_back(&TSSAstyle::alignment); styleFormat.push_back(&TSSAstyle::marginLeft); styleFormat.push_back(&TSSAstyle::marginRight); styleFormat.push_back(&TSSAstyle::marginTop); if (version >= nmTextSubtitles::ASS2) { styleFormat.push_back(&TSSAstyle::marginBottom); } styleFormat.push_back(&TSSAstyle::encoding); if (version <= nmTextSubtitles::SSA) { styleFormat.push_back(&TSSAstyle::alpha); } styleFormat.push_back(&TSSAstyle::relativeTo); } inV4styles = 1; } strings fields; strtok(line + 7, L",", fields); // Fix for missing or incomplete movie dimensions in the script if (playResXscript == 0 && playResYscript == 0) { // Assume 384x288 like VSFilter playResX = 384; playResY = 288; } else { // At least one of the two is set if (playResXscript == 0 || playResYscript == 0) { // Assume 4/3 aspect ratio like VSFilter, but only if one of them is missing if (playResXscript == 0) { playResX = playResYscript * 4 / 3; } else { playResX = playResXscript; } if (playResYscript == 0) { playResY = playResXscript * 3 / 4; } else { playResY = playResYscript; } } else { // Both are set, use them playResX = playResXscript; playResY = playResYscript; } } TSSAstyle style(playResX, playResY, version, wrapStyle, scaleBorderAndShadow); for (size_t i = 0; i < fields.size() && i < styleFormat.size(); i++) if (styleFormat[i]) { style.*(styleFormat[i]) = fields[i]; } styles.add(style); } else if (inEvents == 2 && strnicmp(line, L"Format:", 7) == 0) { strlwr(line); strrmchar(line, L' '); typedef std::vector<Tstrpart > Tparts; Tparts fields; const wchar_t *l = line + 7; strtok(l, L",", fields); eventFormat.clear(); // On embedded streams, read order is added as first column if (isEmbedded) { eventFormat.push_back(&Tevent::readorder); } for (Tparts::const_iterator f = fields.begin(); f != fields.end(); f++) { if (strnicmp(f->first, L"marked", 6) == 0) { eventFormat.push_back(&Tevent::marked); } else if (strnicmp(f->first, L"layer", 5) == 0) { eventFormat.push_back(&Tevent::layer); } else if (strnicmp(f->first, L"start", 5) == 0) { // On embedded subtitles time is removed if (!isEmbedded) { eventFormat.push_back(&Tevent::start); } } else if (strnicmp(f->first, L"end", 3) == 0) { // On embedded subtitles time is removed if (!isEmbedded) { eventFormat.push_back(&Tevent::end); } } else if (strnicmp(f->first, L"style", 5) == 0) { eventFormat.push_back(&Tevent::style); } else if (strnicmp(f->first, L"name", 4) == 0) { eventFormat.push_back(&Tevent::name); } else if (strnicmp(f->first, L"marginL", 7) == 0) { eventFormat.push_back(&Tevent::marginL); } else if (strnicmp(f->first, L"marginR", 7) == 0) { eventFormat.push_back(&Tevent::marginR); } else if (strnicmp(f->first, L"marginV", 7) == 0) { eventFormat.push_back(&Tevent::marginV); } else if (strnicmp(f->first, L"marginR", 7) == 0) { eventFormat.push_back(&Tevent::marginR); } else if (strnicmp(f->first, L"effect", 6) == 0) { eventFormat.push_back(&Tevent::effect); } else if (strnicmp(f->first, L"text", 4) == 0) { eventFormat.push_back(&Tevent::text); } else { eventFormat.push_back(NULL); } } inEvents = 1; } else if ((flags & this->SSA_NODIALOGUE) || (inEvents == 1 && strnicmp(line, L"Dialogue:", 8) == 0)) { if (eventFormat.empty()) { if (!(flags & this->SSA_NODIALOGUE)) { if (version <= nmTextSubtitles::SSA) { eventFormat.push_back(&Tevent::marked); } if (version >= nmTextSubtitles::ASS) { eventFormat.push_back(&Tevent::layer); } eventFormat.push_back(&Tevent::start); eventFormat.push_back(&Tevent::end); } else { eventFormat.push_back(&Tevent::readorder); eventFormat.push_back(&Tevent::layer); } eventFormat.push_back(&Tevent::style); eventFormat.push_back(&Tevent::actor); eventFormat.push_back(&Tevent::marginL); eventFormat.push_back(&Tevent::marginR); eventFormat.push_back(&Tevent::marginT); if (version >= nmTextSubtitles::ASS2) { eventFormat.push_back(&Tevent::marginB); } eventFormat.push_back(&Tevent::effect); eventFormat.push_back(&Tevent::text); } strings fields; strtok(line + (flags & this->SSA_NODIALOGUE ? 0 : 9), L"," , fields, true, eventFormat.size()); Tevent event; event.dummy = ""; // avoid being optimized. for (size_t i = 0; i < fields.size() && i < eventFormat.size(); i++) { if (eventFormat[i]) { event.*(eventFormat[i]) = fields[i]; } } if (event.text) { #if 0 DPRINTF(L"%s", event.text.c_str()); #endif int hour1 = 0, min1 = 0, sec1 = 0, hunsec1 = 0; int hour2 = 0, min2 = 0, sec2 = 0, hunsec2 = 0; if (!(flags & this->PARSETIME) || (swscanf(event.start.c_str(), L"%d:%d:%d.%d", &hour1, &min1, &sec1, &hunsec1) == 4 && swscanf(event.end.c_str() , L"%d:%d:%d.%d", &hour2, &min2, &sec2, &hunsec2) == 4)) { const TSubtitleProps *props = styles.getProps(event.style); TsubtitleText current(this->format, props ? *props : defprops, styles); current.defProps.lineID = lineID; // margins nmTextSubtitles::strToIntMargin(event.marginL, ¤t.defProps.marginL); nmTextSubtitles::strToIntMargin(event.marginR, ¤t.defProps.marginR); nmTextSubtitles::strToIntMargin(event.marginV, ¤t.defProps.marginV); // layer nmTextSubtitles::strToInt(event.layer, ¤t.defProps.layer); // timestamps if (flags & this->PARSETIME) { current.start = timer.den * this->hmsToTime(hour1, min1, sec1, hunsec1) / timer.num; current.stop = timer.den * this->hmsToTime(hour2, min2, sec2, hunsec2) / timer.num; } else if (start != REFTIME_INVALID && stop != REFTIME_INVALID) { current.start = start; current.stop = stop; } current.defProps.tStart = current.defProps.karaokeStart = current.start; current.defProps.tStop = current.stop; // scroll event.effect = event.effect.ConvertToLowerCase(); if (event.effect.find(L"scroll up;") != ffstring::npos) { current.defProps.scroll.directionV = -1; } if (event.effect.find(L"scroll down;") != ffstring::npos) { current.defProps.scroll.directionV = 1; } if (current.defProps.scroll.directionV) { int y1, y2, delay, fadeawayheight = 0; if (swscanf(event.effect.c_str() + event.effect.find(L";"), L";%d;%d;%d;%d", &y1, &y2, &delay, &fadeawayheight) >= 3) { if (y1 > y2) { std::swap(y1, y2); } current.defProps.scroll.y1 = y1; current.defProps.scroll.y2 = y2; current.defProps.scroll.delay = std::max(delay, 1); current.defProps.scroll.fadeaway = fadeawayheight; } } if (event.effect.find(L"banner;") != ffstring::npos) { current.defProps.scroll.directionV = 0; current.defProps.scroll.directionH = -1; int delay, lefttoright = 0, fadeawaywidth = 0; if (swscanf(event.effect.c_str() + event.effect.find(L";"), L";%d;%d;%d", &delay, &lefttoright, &fadeawaywidth) >= 1) { current.defProps.scroll.delay = std::max(delay, 1); current.defProps.scroll.directionH = lefttoright ? 1 : -1; current.defProps.scroll.fadeaway = fadeawaywidth; } } // replace \h with non-breaking space (U+00A0). event.text = stringreplace(event.text, L"\\h", L"\xa0", rfReplaceAll); const wchar_t *line2 = event.text.c_str(); do { const wchar_t *tmp, *tmp1; int lineBreakReason = 0; do { tmp = strstr(line2, L"\\n"); tmp1 = strstr(line2, L"\\N"); if (tmp == NULL && tmp1 == NULL) { break; } if (tmp && tmp1) { tmp = std::min(tmp, tmp1); } if (tmp == NULL) { tmp = tmp1; } current.addSSA(line2, tmp - line2, lineBreakReason); lineBreakReason = tmp[1] == 'n' ? 1 : 2; line2 = tmp + 2; } while (1); current.addSSA(line2, lineBreakReason); } while (flags & this->SSA_NODIALOGUE && fd.fgets((wchar_t*)(line2 = line), this->LINE_LEN)); textformat.setProps(current.defProps); return store(current); } } } } return NULL; }
bool Rational::operator<=(int right) const { return *this <= Rational(right, 1); }
Rational & operator +=( int i ) { (*this) += Rational(i); return * this ; }
void QuadraticField::ZeroResult() { for(int i =0; i<degree; i++) Result[i] = Rational(0,1); }
Rational & operator -=( int i ) { (*this) -= Rational(i); return * this ; }
Rational StateGraph::getWeight(int i) const { return Rational(1); }
Rational & operator *=( int i ) { (*this) *= Rational(i); return * this ; }
Rational inverse() const { return Rational(denominator, numerator); }
Rational operator-(Rational num1, Rational num2) { int c = LCM(num1.getB(), num2.getB()); int d = (c / num1.getB())*num1.getA() - (c / num2.getB())*num2.getA(); return Rational(d, c); }