boost::uint32_t Crop::readBufferImpl(PointBuffer& dstData) { // The client has asked us for dstData.getCapacity() points. // We will read from our previous stage until we get that amount (or // until the previous stage runs out of points). boost::uint32_t numPointsNeeded = dstData.getCapacity(); assert(dstData.getNumPoints() == 0); while (numPointsNeeded > 0) { if (getPrevIterator().atEnd()) break; // set up buffer to be filled by prev stage PointBuffer srcData(dstData.getSchema(), numPointsNeeded); // read from prev stage const boost::uint32_t numSrcPointsRead = getPrevIterator().read(srcData); assert(numSrcPointsRead == srcData.getNumPoints()); assert(numSrcPointsRead <= numPointsNeeded); // we got no data, and there is no more to get -- exit the loop if (numSrcPointsRead == 0) break; // copy points from src (prev stage) into dst (our stage), // based on the CropFilter's rules (i.e. its bounds) const boost::uint32_t numPointsProcessed = m_cropFilter.processBuffer(dstData, srcData); numPointsNeeded -= numPointsProcessed; } const boost::uint32_t numPointsAchieved = dstData.getNumPoints(); return numPointsAchieved; }
boost::uint32_t DecimationFilterSequentialIterator::readBufferImpl(PointBuffer& dstData) { // The client has asked us for dstData.getCapacity() points. // We will read from our previous stage until we get that amount (or // until the previous stage runs out of points). boost::uint32_t numPointsNeeded = dstData.getCapacity(); assert(dstData.getNumPoints() == 0); // set up buffer to be filled by prev stage PointBuffer srcData(dstData.getSchemaLayout(), numPointsNeeded); while (numPointsNeeded > 0) { // read from prev stage const boost::uint64_t srcStartIndex = getPrevIterator().getIndex(); const boost::uint32_t numSrcPointsRead = getPrevIterator().read(srcData); assert(numSrcPointsRead <= srcData.getNumPoints()); //assert(numSrcPointsRead <= numPointsNeeded); // we got no data, and there is no more to get -- exit the loop if (numSrcPointsRead == 0) break; // copy points from src (prev stage) into dst (our stage), // based on the CropFilter's rules (i.e. its bounds) const boost::uint32_t numPointsAdded = m_filter.processBuffer(dstData, srcData, srcStartIndex); numPointsNeeded -= numPointsAdded; //printf(".");fflush(stdout); } const boost::uint32_t numPointsAchieved = dstData.getNumPoints(); return numPointsAchieved; }
QString txEmissionsBase::saveSourceData() const { QDir reportDir; const QString fullPath = reportDir.relativeFilePath(m_fullReportsPath) + QDir::separator() + "SourceData_" + m_calculationOptions->defStandardName( m_calculationOptions->val_standard() ) + "_" + m_currTime + ".dat"; QFile srcData(fullPath); if ( !srcData.open(QFile::WriteOnly) ) { throw txError("Can not open file " + fullPath + "!"); } QTextStream fout(&srcData); fout << right << qSetFieldWidth(COLUMNWIDTH); for ( ptrdiff_t i=0; i<SRCDATACAPTIONS_EMISSIONS.size(); i++ ) { fout << SRCDATACAPTIONS_EMISSIONS[i]; } fout << qSetFieldWidth(0) << "\n" << fixed << qSetFieldWidth(COLUMNWIDTH) << qSetRealNumberPrecision(PRECISION+1); for ( ptrdiff_t i=0; i<m_numberOfPoints; i++ ) { fout << qSetFieldWidth(COLUMNWIDTH); fout << i + 1; fout << ma_n[i] << ma_Me_brutto[i] << ma_Ne_brutto[i] << ma_N_fan[i] << ma_w[i] << ma_t0[i] << ma_B0[i] << ma_Ra[i] << ma_dPn[i] << ma_Gair[i] << ma_Gfuel[i] << ma_CNOx[i] << ma_gNOx[i] << ma_CCO[i] << ma_CCH[i] << ma_CCO2in[i] << ma_CCO2out[i] << ma_CO2[i] << ma_Ka1m[i] << ma_KaPerc[i] << ma_FSN[i] << ma_Pr[i] << ma_ts[i] << ma_tauf[i] << ma_qmdw[i] << ma_qmdew[i] << ma_rd[i]; fout << qSetFieldWidth(0) << "\n"; } srcData.close(); return "libtoxic: Source data file \"" + fullPath + "\" created.\n"; }
QString txReducedPower::saveSourceData() const { QDir reportDir; const QString fullPath = reportDir.relativeFilePath(m_fullReportsPath) + QDir::separator() + "SourceData_R85_" + m_currTime + ".dat"; QFile srcData(fullPath); if ( !srcData.open(QFile::WriteOnly) ) { throw txError("Can not open file " + fullPath + "!"); } QTextStream fout(&srcData); fout << right << qSetFieldWidth(COLUMNWIDTH); for ( ptrdiff_t i=0; i<SRCDATACAPTIONS_REDPOWER.size(); i++ ) { fout << SRCDATACAPTIONS_REDPOWER[i]; } fout << qSetFieldWidth(0) << "\n" << fixed << qSetFieldWidth(COLUMNWIDTH) << qSetRealNumberPrecision(PRECISION+1); for ( ptrdiff_t i=0; i<m_numberOfPoints; i++ ) { fout << qSetFieldWidth(COLUMNWIDTH); fout << i + 1; fout << ma_n[i] << ma_Me_brutto[i] << ma_t0[i] << ma_B0[i] << ma_Ra[i] << ma_S[i] << ma_pk[i] << ma_Gfuel[i] << ma_N_k[i] << ma_N_fan[i] << ma_t_cool[i] << ma_t_oil[i] << ma_tk[i] << ma_tks[i] << ma_t_fuel[i] << ma_pks[i] << ma_Gair[i]; fout << qSetFieldWidth(0) << "\n"; } srcData.close(); return "libtoxic: Source data file \"" + fullPath + "\" created.\n"; }
bool OpenNI2CameraImpl::copyInfrared( OpenNI2Camera::FrameView& frame ) { frame.infraredUpdated = false; VideoFrameRef src; Status rc = m_infraredStream.readFrame( &src ); if( rc == STATUS_OK ) { Array2DReadView< uint16_t > srcData( src.getData(), { src.getWidth(), src.getHeight() }, { sizeof( uint16_t ), src.getStrideInBytes() } ); frame.infraredTimestampNS = usToNS( static_cast< int64_t >( src.getTimestamp() ) ); frame.infraredFrameNumber = src.getFrameIndex(); frame.infraredUpdated = copy( srcData, frame.infrared ); return frame.infraredUpdated; } return false; }
DFAFile::DFAFile(const std::string &filename, const Palette &palette) : pixels() { VFS::IStreamPtr stream = VFS::Manager::get().open(filename.c_str()); Debug::check(stream != nullptr, "DFAFile", "Could not open \"" + filename + "\"."); stream->seekg(0, std::ios::end); const auto fileSize = stream->tellg(); stream->seekg(0, std::ios::beg); std::vector<uint8_t> srcData(fileSize); stream->read(reinterpret_cast<char*>(srcData.data()), srcData.size()); // Read DFA header data. const uint16_t imageCount = Bytes::getLE16(srcData.data()); const uint16_t unknown1 = Bytes::getLE16(srcData.data() + 2); const uint16_t unknown2 = Bytes::getLE16(srcData.data() + 4); const uint16_t width = Bytes::getLE16(srcData.data() + 6); const uint16_t height = Bytes::getLE16(srcData.data() + 8); const uint16_t compressedLength = Bytes::getLE16(srcData.data() + 10); // First frame. // Frame data with palette indices. std::vector<std::vector<uint8_t>> frames; // Uncompress the initial frame. frames.push_back(std::vector<uint8_t>(width * height)); Compression::decodeRLE(srcData.data() + 12, width * height, frames.at(0)); // Make copies of the original frame for each update chunk. for (int i = 1; i < imageCount; ++i) { frames.push_back(frames.at(0)); } // Offset to the beginning of the chunk data; advances as the chunk data is read. uint32_t offset = 12 + compressedLength; // Start reading chunks for each update group. Skip the first frame because // that's the full image. for (uint32_t frameIndex = 1; frameIndex < imageCount; ++frameIndex) { // Select the frame buffer at the current frame index. std::vector<uint8_t> &frame = frames.at(frameIndex); // Pointer to the beginning of the chunk data. Each update chunk // changes a group of pixels in a copy of the original image. const uint8_t *chunkData = srcData.data() + offset; const uint16_t chunkSize = Bytes::getLE16(chunkData); const uint16_t chunkCount = Bytes::getLE16(chunkData + 2); // Move the offset past the chunk header. offset += 4; for (uint32_t chunkIndex = 0; chunkIndex < chunkCount; ++chunkIndex) { const uint8_t *updateData = srcData.data() + offset; const uint16_t updateOffset = Bytes::getLE16(updateData); const uint16_t updateCount = Bytes::getLE16(updateData + 2); // Move the offset past the update header. offset += 4; for (uint32_t i = 0; i < updateCount; ++i) { frame.at(updateOffset + i) = *(srcData.begin() + offset); offset++; } } } this->width = width; this->height = height; // Finally, create 32-bit images using each frame's palette indices. for (const auto &frame : frames) { this->pixels.push_back(std::unique_ptr<uint32_t>( new uint32_t[this->width * this->height])); uint32_t *dstPixels = this->pixels.at(this->pixels.size() - 1).get(); std::transform(frame.begin(), frame.begin() + frame.size(), dstPixels, [&palette](uint8_t col) -> uint32_t { return palette[col].toARGB(); }); } }