void* PresizedArena::malloc(size_t size) { #ifndef ASSUME_ASSERTIONS_ARE_TRUE runtime_assert(static_cast<size_t>(m_end - m_bump) >= size, "Pre-sized arena is too small."); #endif auto result = static_cast<void*>(m_bump); m_bump += size; return result; }
void write_ini(const value& aValue, interfaces::ostream& aStream) { runtime_assert(solaire_write_ini(&aValue, &aStream), "solaire::serial::write_ini : Failed to write ini"); }
value read_ini(interfaces::istream& aStream) { value tmp; runtime_assert(solaire_read_ini(&tmp, &aStream), "solaire::serial::read_ini : Failed to read ini"); return tmp; }
VLA<uint8_t> Extractor::parse(std::istream &input) { /* start code prefix 24/32 bits (reverse order) */ static const uint8_t scp24[] = {1, 0, 0}; static const uint8_t scp32[] = {1, 0, 0, 0}; std::istream_iterator<uint8_t> begin(input), end; VLA<uint8_t> output; output.reserve(4 * 1024); /* search for byte stream NAL Unit start code prefix */ while( !isMatchingAt(output.rbegin(), output.rend(), scp24) && !isMatchingAt(output.rbegin(), output.rend(), scp32)) { /* expected syntax element: leading_zero_8bits */ output.pushBack(*begin); if(0 != output.back() && 1 != output.back()) { /* undo unexpected only */ input.unget(); runtime_assert(false); } ++begin; } /* until next NAL Unit start code prefix is encountered (or end of file), * treat all bytes as NAL Unit payload */ while(begin != end) { /* NAL Unit payload including syntax element: trailing_zero_8bits */ output.pushBack(*begin); const auto scp24Matched = isMatchingAt(output.rbegin(), output.rend(), scp24); /* do not search for scp32 if scp24 present */ const auto scp32Matched = scp24Matched ? false : isMatchingAt(output.rbegin(), output.rend(), scp32); if(scp24Matched || scp32Matched) { const auto scpSize = scp24Matched ? sizeof(scp24) : sizeof(scp32); /* revert consumed start code prefix */ const std::streampos absPos = input.tellg(); const std::streamoff offset = absPos - static_cast<std::streampos>(scpSize); runtime_assert(absPos > static_cast<std::streampos>(sizeof(scpSize))); input.seekg(offset, std::ios_base::beg); /* truncate next NAL Unit scp from current tail */ output.resize(output.size() - scpSize); break; } ++begin; } return output; }
inline T pop_front() { T tmp = container<T>::front(); runtime_assert(_pop_front(), "P12218319::deque::pop_front : Failed to pop item"); return tmp; }
inline void push_front(const T& aValue) { T tmp = aValue; runtime_assert(_push_front(std::move(tmp)), "P12218319::deque::push_front : Failed to push item"); }
inline void push_front(T&& aValue) { runtime_assert(_push_front(std::move(aValue)), "P12218319::deque::push_front : Failed to push item"); }
/*----------------------------------------------------------------------------*/ IntraAdjSamples IntraRefSamplesSubstitution::exec( State &, Plane plane, PelCoord coord, int bitDepth, IntraAdjSamples &&adj) { if(adj.areAllUnAvailable()) { auto setToMean = [&](const PelCoord &, IntraAdjSamples::AdjSample &sample) { sample = 1 << (bitDepth - 1); }; adj.forEach(setToMean); } else { const auto sideEnd = adj.getSideEnd(); // 1 if(!adj[{-1_pel, sideEnd - 1_pel}]) { auto findAvailable = [=]() { for(auto y = sideEnd - 1_pel; y >= -1_pel; --y) { if(adj[{-1_pel, y}]) { return adj[{-1_pel, y}]; } } for(auto x = 0_pel; x < sideEnd; ++x) { if(adj[{x, -1_pel}]) { return adj[{x, -1_pel}]; } } runtime_assert(false); return IntraAdjSamples::AdjSample(); }; adj[{-1_pel, sideEnd - 1_pel}] = findAvailable(); } // 2 for(auto y = sideEnd - 2_pel; y >= -1_pel; --y) { if(!adj[{-1_pel, y}]) { adj[{-1_pel, y}] = adj[{-1_pel, y + 1_pel}]; } } // 3 for(auto x = 0_pel; x < sideEnd; ++x) { if(!adj[{x, -1_pel}]) { adj[{x, -1_pel}] = adj[{x - 1_pel, -1_pel}]; } } } const auto toStr = [coord, &adj](std::ostream &oss) { oss << coord << '\n'; adj.writeTo( oss, [](std::ostream &os, IntraAdjSamples::AdjSample i) {pelFmt(os, *i);}); }; const LogId logId[] = { LogId::IntraAdjSubstitutedSamplesY, LogId::IntraAdjSubstitutedSamplesCb, LogId::IntraAdjSubstitutedSamplesCr }; log(logId[int(plane)], toStr); runtime_assert(adj.areAllAvailable()); return adj; }