AVPixelFormat FindBestPixelFormat(const std::vector<AVPixelFormat> &Dsts, AVPixelFormat Src) { // some trivial special cases to make sure there's as little conversion as possible if (Dsts.empty()) return FFMS_PIX_FMT(NONE); if (Dsts.size() == 1) return Dsts[0]; // is the input in the output? auto i = std::find(Dsts.begin(), Dsts.end(), Src); if (i != Dsts.end()) return Src; // If it's an evil paletted format pretend it's normal RGB when calculating loss if (Src == FFMS_PIX_FMT(PAL8)) Src = FFMS_PIX_FMT(RGB32); i = Dsts.begin(); LossAttributes Loss = CalculateLoss(*i++, Src); for (; i != Dsts.end(); ++i) { LossAttributes CLoss = CalculateLoss(*i, Src); if (Loss.CSLoss >= 3 && CLoss.CSLoss < Loss.CSLoss) { // favor the same color format output Loss = CLoss; } else if (Loss.DepthDifference >= 0 && CLoss.DepthDifference >= 0) { // focus on chroma undersamling and conversion loss if the target depth has been achieved if ((CLoss.ChromaUndersampling < Loss.ChromaUndersampling) || (CLoss.ChromaUndersampling == Loss.ChromaUndersampling && CLoss.CSLoss < Loss.CSLoss) || (CLoss.ChromaUndersampling == Loss.ChromaUndersampling && CLoss.CSLoss == Loss.CSLoss && CLoss.DepthDifference < Loss.DepthDifference) || (CLoss.ChromaUndersampling == Loss.ChromaUndersampling && CLoss.CSLoss == Loss.CSLoss && CLoss.DepthDifference == Loss.DepthDifference && CLoss.ChromaOversampling < Loss.ChromaOversampling)) Loss = CLoss; } else { // put priority on reaching the same depth as the input if ((CLoss.DepthDifference > Loss.DepthDifference) || (CLoss.DepthDifference == Loss.DepthDifference && CLoss.ChromaUndersampling < Loss.ChromaUndersampling) || (CLoss.DepthDifference == Loss.DepthDifference && CLoss.ChromaUndersampling == Loss.ChromaUndersampling && CLoss.CSLoss < Loss.CSLoss) || (CLoss.DepthDifference == Loss.DepthDifference && CLoss.ChromaUndersampling == Loss.ChromaUndersampling && CLoss.CSLoss == Loss.CSLoss && CLoss.ChromaOversampling < Loss.ChromaOversampling)) Loss = CLoss; } } return Loss.Format; }
PixelFormat FindBestPixelFormat(const std::vector<PixelFormat> &Dsts, PixelFormat Src) { // some trivial special cases to make sure there's as little conversion as possible if (Dsts.empty()) return PIX_FMT_NONE; if (Dsts.size() == 1) return Dsts[0]; // is the input in the output? std::vector<PixelFormat>::const_iterator i = std::find(Dsts.begin(), Dsts.end(), Src); if (i != Dsts.end()) return Src; i = Dsts.begin(); LossAttributes Loss = CalculateLoss(*i++, Src); for (; i != Dsts.end(); ++i) { LossAttributes CLoss = CalculateLoss(*i, Src); if (Loss.CSLoss == 3 && CLoss.CSLoss < 3) { // Preserve chroma information at any cost Loss = CLoss; } else if (Loss.DepthDifference >= 0 && CLoss.DepthDifference >= 0) { // focus on chroma undersamling and conversion loss if the target depth has been achieved if ((CLoss.ChromaUndersampling < Loss.ChromaUndersampling) || (CLoss.ChromaUndersampling == Loss.ChromaUndersampling && CLoss.CSLoss < Loss.CSLoss) || (CLoss.ChromaUndersampling == Loss.ChromaUndersampling && CLoss.CSLoss == Loss.CSLoss && CLoss.DepthDifference < Loss.DepthDifference) || (CLoss.ChromaUndersampling == Loss.ChromaUndersampling && CLoss.CSLoss == Loss.CSLoss && CLoss.DepthDifference == Loss.DepthDifference && CLoss.ChromaOversampling < Loss.ChromaOversampling)) Loss = CLoss; } else { // put priority on reaching the same depth as the input if ((CLoss.DepthDifference > Loss.DepthDifference) || (CLoss.DepthDifference == Loss.DepthDifference && CLoss.ChromaUndersampling < Loss.ChromaUndersampling) || (CLoss.DepthDifference == Loss.DepthDifference && CLoss.ChromaUndersampling == Loss.ChromaUndersampling && CLoss.CSLoss < Loss.CSLoss) || (CLoss.DepthDifference == Loss.DepthDifference && CLoss.ChromaUndersampling == Loss.ChromaUndersampling && CLoss.CSLoss == Loss.CSLoss && CLoss.ChromaOversampling < Loss.ChromaOversampling)) Loss = CLoss; } } return Loss.Format; }
Ptr<SpectrumValue> FriisSpectrumPropagationLossModel::DoCalcRxPowerSpectralDensity (Ptr<const SpectrumValue> txPsd, Ptr<const MobilityModel> a, Ptr<const MobilityModel> b) const { Ptr<SpectrumValue> rxPsd = Copy<SpectrumValue> (txPsd); Values::iterator vit = rxPsd->ValuesBegin (); Bands::const_iterator fit = rxPsd->ConstBandsBegin (); NS_ASSERT (a); NS_ASSERT (b); double d = a->GetDistanceFrom (b); while (vit != rxPsd->ValuesEnd ()) { NS_ASSERT (fit != rxPsd->ConstBandsEnd ()); *vit /= CalculateLoss (fit->fc, d); // Prx = Ptx / loss ++vit; ++fit; } return rxPsd; }