SP_RESULT load_calc(const char *load_file_name, const char *file_name, EPAnalysis& ep, bool playback) { RawData data; Capture c; char fn_buffer [128]=""; data.loadWav(stringFile(load_file_name,".wav",fn_buffer)); ep.Initial(&data); ep.reCalcAllData(); ep.saveMatlab(stringFile(file_name,".dat",fn_buffer)); if(playback)c.play(&data); ep.smooth(); ep.saveMatlab(stringFile(file_name,"_smooth.dat",fn_buffer)); ep.cut(); ep.saveMatlab(stringFile(file_name,"_cut.dat",fn_buffer)); //ep.smooth(); //ep.cut(); //ep.saveMatlab(stringFile(file_name,"_cut_2.m",fn_buffer)); if(playback)c.play(&data); return SP_SUCCESS; }
void capture(const char *save_file_name, RawData &data, bool playback) { DAEPAnalysis ep; AutoCapture c(&ep); Tip("Press any key to capture:"); getch(); puts(""); Tip("Preparing..."); sleep(1); char fn_buffer [128]=""; Tip("Start talking"); if(c.capture(&data)) { data.saveWav(stringFile(save_file_name,".wav",fn_buffer)); //if(playback)c.play(&data); ep.smooth(); ep.cut(); if(playback) c.play(&data); data.saveWav(stringFile(save_file_name,"_cut.wav",fn_buffer)); } else{ ErrorLog("Capture error"); } }
int test_main(int argc, char *argv[]) { if (argc == 1) { // no argument, lets run like we are in "check" const char * srcdir = getenv("srcdir"); BOOST_ASSERT(srcdir != NULL); g_testfile = std::string(srcdir); g_testfile += "/ljpegtest1.jpg"; } else { g_testfile = argv[1]; } RawData *decompData; File::Ptr s(new File(g_testfile.c_str())); RawContainer *container = new JfifContainer(s, 0); LJpegDecompressor decompressor(s.get(), container); decompData = decompressor.decompress(); boost::crc_optimal<16, 0x1021, 0xFFFF, 0, false, false> crc_ccitt2; const uint8_t * data = static_cast<uint8_t *>(decompData->data()); size_t data_len = decompData->size(); crc_ccitt2 = std::for_each( data, data + data_len, crc_ccitt2 ); BOOST_CHECK(crc_ccitt2() == 0x20cc); delete decompData; delete container; return 0; }
bool AnimationLoader::isLoadable(const std::string& filename) { bfs::path animPath(filename); std::string animationFilename = animPath.string(); try { RawData* data = m_vfs->open(animationFilename); if (data) { if (data->getDataLength() != 0) { // TODO - this could be expanded to do more checks TiXmlDocument doc; doc.Parse(data->readString(data->getDataLength()).c_str()); if (doc.Error()) { return false; } } // done with data delete resource delete data; data = 0; } } catch (NotFound&) { return false; } return true; }
TEST(CryptingTest, EncryptString) { RawData expression(StringToRawData("1234567890")); AesEncryptor encryptor(keyNormal, ivNormal); RawData encrypted; ASSERT_NO_THROW(encryptor.Encrypt(expression, encrypted)); EXPECT_EQ(encrypted.size(), expression.size()); EXPECT_NE(encrypted, expression); }
void createNoise(const char * file_name){ RawData data; int size =SAMPLES_IN_EACH_FRAME * FRAME_PER_SECOND * 60; data.setFrameNum(size); for(int i = 0;i<size;i++){ int d = rand()%500+10000; data.setData(i,d); } data.saveWav(file_name); }
void CommandManager::onResponse(CCHttpClient* client, CCHttpResponse* response) { const string commandName = m_currentCommand->getName(); if (response->isSucceed()) { m_currentCommand->setCommandState(CommandStateResonsedProcessed); if (m_currentCommand->getMessageHandler()) { int responseCode = response->getResponseCode(); RawData* responseData = response->getResponseData(); int responseDataSize = responseData->size(); const char* data = &((*responseData)[0]); CCLOG("command %s response code %d length %d", commandName.c_str(), responseCode, responseDataSize); ResponseMessage message; bool decoded = message.ParseFromArray(data, responseDataSize); CCAssert(decoded, FORMAT("command %s decode fail data length=%d", commandName.c_str(), responseDataSize)); m_currentCommand->getMessageHandler()->setMessage(&message); m_currentCommand->getMessageHandler()->execute(); } } else { CCLOG("command %s fail errorcode=%d error message=%s", commandName.c_str(), response->getResponseCode(), response->getErrorBuffer()); int resendCount = m_currentCommand->getResendCount(); if (resendCount < MAX_RESEND_COUNT) { client->send(response->getHttpRequest()); m_currentCommand->setResendCount(resendCount + 1); CCLOG("resend command %s for the %d time(s)", commandName.c_str(), resendCount); } else { CCMessageBox(FORMAT("Command fail %s", commandName.c_str()), "Error"); } } }
RawData KontrolerWejsciowy::porcjaDanych() { RawData wynik; while(!mojaKolejka->empty()) { wynik += mojaKolejka->front(); mojaKolejka->pop(); if(wynik.get_data_size() >= suggestedRawDataMaxSize) { break; } } return wynik; }
TEST(CryptingTest, EncryptStream) { std::stringstream strmIn; RawData expression; FillStream(strmIn, expression); std::stringstream strmOut; AesEncryptor encryptor(keyNormal, ivNormal); uint64_t encryptedSize = 0; ASSERT_NO_THROW(encryptedSize = encryptor.Encrypt(strmIn, strmOut, expression.size())); ASSERT_EQ(encryptedSize, expression.size()); EXPECT_EQ(encryptedSize, expression.size()); RawData encrypted(static_cast<unsigned int>(encryptedSize)); strmOut.read(reinterpret_cast<char*>(&encrypted[0]), encryptedSize); EXPECT_NE(encrypted, expression); }
TEST(CryptingTest, DecryptStream) { std::stringstream strmIn; RawData expression; FillStream(strmIn, expression); std::stringstream strmEncrypted; AesEncryptor encryptor(keyNormal, ivNormal); encryptor.Encrypt(strmIn, strmEncrypted, expression.size()); // This test case must be passed above std::stringstream strmDecrypted; AesDecryptor decryptor(keyNormal, ivNormal); uint64_t decryptedSize = 0; ASSERT_NO_THROW(decryptedSize = decryptor.Decrypt(strmEncrypted, strmDecrypted, expression.size())); ASSERT_EQ(decryptedSize, expression.size()); RawData decrypted(static_cast<unsigned int>(decryptedSize)); strmDecrypted.read(reinterpret_cast<char*>(&decrypted[0]), decryptedSize); EXPECT_EQ(decrypted, expression); }
SP_RESULT load_wav_file(const char *file_name, RawData &data) { DAEPAnalysis da_ep; Capture c; char fn_buffer[128] = ""; data.loadWav(stringFile(file_name, ".wav", fn_buffer)); da_ep.Initial(&data); da_ep.reCalcAllData(); // da_ep.smooth(); // da_ep.cut(); return SP_SUCCESS; }
void FillStream(std::iostream& strm, RawData& expression) { static const std::string s_smallExpression("0123456789abcdefghijklmnopqrstuvwxyz"); static const int iterationsCount = 10; for (int i = 0; i < iterationsCount; ++i) { strm << s_smallExpression; } size_t expressionSize = iterationsCount * s_smallExpression.size(); expression.resize(expressionSize); strm.read(reinterpret_cast<char*>(&expression[0]), expressionSize); strm.seekg(0); }
RawData *RawDataDump(float *ADC_import, int *ADCchan_import, int ntdc, int *TDC_channel_import, float *TDC_value_import, float *QDC_import) { RawData *raw = new RawData(); raw->Init(raw); for(int i=0;i<ADCsize;i++) { raw->SetADCValue(i,ADC_import[i]); raw->SetADCChannel(i,ADCchan_import[i]); raw->SetADCCalibratedValue(i,ADCOffsets[i] + ADCGains[i] * ADC_import[i]); } //for(int i=0;i<ADCsize;i++)raw->SetADCCalibratedValue(i,ADCOffsets[i] + ADCGains[i] * ADC_import[i]); for(int n=0;n<ntdc;n++) { raw->SetTDCChannel(n,TDC_channel_import[n]); raw->SetTDCValue(n,TDC_value_import[n]); } for(int i=0;i<QDCsize;i++)raw->SetQDCValue(i,QDC_import[i]); return raw; }
void Net::process() { sockaddr sa; sa.sa_family = AF_UNSPEC; NetAddress srcAddress; RawData tmpBuffer; tmpBuffer.alloc(MaxPacketDataSize); for(;;) { socklen_t addrLen = sizeof(sa); S32 bytesRead = -1; if(udpSocket != InvalidSocket) bytesRead = recvfrom(udpSocket, (char *) tmpBuffer.data, MaxPacketDataSize, 0, &sa, &addrLen); if(bytesRead == -1) break; if(sa.sa_family == AF_INET) IPSocketToNetAddress((sockaddr_in *) &sa, &srcAddress); else continue; if(bytesRead <= 0) continue; if(srcAddress.type == NetAddress::IPAddress && srcAddress.netNum[0] == 127 && srcAddress.netNum[1] == 0 && srcAddress.netNum[2] == 0 && srcAddress.netNum[3] == 1 && srcAddress.port == netPort) continue; tmpBuffer.size = bytesRead; Net::smPacketReceive.trigger(srcAddress, tmpBuffer); } // process the polled sockets. This blob of code performs functions // similar to WinsockProc in winNet.cc if (gPolledSockets.size() == 0) return; S32 optval; socklen_t optlen = sizeof(S32); S32 bytesRead; Net::Error err; bool removeSock = false; Socket *currentSock = NULL; sockaddr_in ipAddr; NetSocket incoming = InvalidSocket; char out_h_addr[1024]; int out_h_length = 0; RawData readBuff; for (S32 i = 0; i < gPolledSockets.size(); /* no increment, this is done at end of loop body */) { removeSock = false; currentSock = gPolledSockets[i]; switch (currentSock->state) { case ::InvalidState: Con::errorf("Error, InvalidState socket in polled sockets list"); break; case ::ConnectionPending: // see if it is now connected #ifdef TORQUE_OS_XENON // WSASetLastError has no return value, however part of the SO_ERROR behavior // is to clear the last error, so this needs to be done here. if( ( optval = _getLastErrorAndClear() ) == -1 ) #else if (getsockopt(currentSock->fd, SOL_SOCKET, SO_ERROR, (char*)&optval, &optlen) == -1) #endif { Con::errorf("Error getting socket options: %s", strerror(errno)); Net::smConnectionNotify.trigger(currentSock->fd, Net::ConnectFailed); removeSock = true; } else { if (optval == EINPROGRESS) // still connecting... break; if (optval == 0) { // poll for writable status to be sure we're connected. bool ready = netSocketWaitForWritable(currentSock->fd,0); if(!ready) break; currentSock->state = ::Connected; Net::smConnectionNotify.trigger(currentSock->fd, Net::Connected); } else { // some kind of error Con::errorf("Error connecting: %s", strerror(errno)); Net::smConnectionNotify.trigger(currentSock->fd, Net::ConnectFailed); removeSock = true; } } break; case ::Connected: // try to get some data bytesRead = 0; readBuff.alloc(MaxPacketDataSize); err = Net::recv(currentSock->fd, (U8*)readBuff.data, MaxPacketDataSize, &bytesRead); if(err == Net::NoError) { if (bytesRead > 0) { // got some data, post it readBuff.size = bytesRead; Net::smConnectionReceive.trigger(currentSock->fd, readBuff); } else { // ack! this shouldn't happen if (bytesRead < 0) Con::errorf("Unexpected error on socket: %s", strerror(errno)); // zero bytes read means EOF Net::smConnectionNotify.trigger(currentSock->fd, Net::Disconnected); removeSock = true; } } else if (err != Net::NoError && err != Net::WouldBlock) { Con::errorf("Error reading from socket: %s", strerror(errno)); Net::smConnectionNotify.trigger(currentSock->fd, Net::Disconnected); removeSock = true; } break; case ::NameLookupRequired: // is the lookup complete? if (!gNetAsync.checkLookup( currentSock->fd, out_h_addr, &out_h_length, sizeof(out_h_addr))) break; U32 newState; if (out_h_length == -1) { Con::errorf("DNS lookup failed: %s", currentSock->remoteAddr); newState = Net::DNSFailed; removeSock = true; } else { // try to connect dMemcpy(&(ipAddr.sin_addr.s_addr), out_h_addr, out_h_length); ipAddr.sin_port = currentSock->remotePort; ipAddr.sin_family = AF_INET; if(::connect(currentSock->fd, (struct sockaddr *)&ipAddr, sizeof(ipAddr)) == -1) { int errorCode; #if defined(TORQUE_USE_WINSOCK) errorCode = WSAGetLastError(); if( errorCode == WSAEINPROGRESS || errorCode == WSAEWOULDBLOCK ) #else errorCode = errno; if (errno == EINPROGRESS) #endif { newState = Net::DNSResolved; currentSock->state = ::ConnectionPending; } else { const char* errorString; #if defined(TORQUE_USE_WINSOCK) errorString = strerror_wsa( errorCode ); #else errorString = strerror( errorCode ); #endif Con::errorf("Error connecting to %s: %s (%i)", currentSock->remoteAddr, errorString, errorCode); newState = Net::ConnectFailed; removeSock = true; } } else { newState = Net::Connected; currentSock->state = Net::Connected; } } Net::smConnectionNotify.trigger(currentSock->fd, newState); break; case ::Listening: NetAddress incomingAddy; incoming = Net::accept(currentSock->fd, &incomingAddy); if(incoming != InvalidSocket) { setBlocking(incoming, false); addPolledSocket(incoming, Connected); Net::smConnectionAccept.trigger(currentSock->fd, incoming, incomingAddy); } break; } // only increment index if we're not removing the connection, since // the removal will shift the indices down by one if (removeSock) closeConnectTo(currentSock->fd); else i++; } }
int main(int argc, char* argv[]) { options opts; uint i = 0; uint j = 0; uint newFeatureIndex = 0; uint lastFeatureIndex = 0; double mrmr = 0; double acum = 0; vector<double> relevances; vector<double> redundances; vector<int> selectedFeatures; Timer tm; opts = parseOptions(argc, argv); RawData rawData = RawData(opts.file); tm.start(); ProbTable prob = ProbTable(rawData); MutualInfo mutualInfo = MutualInfo(rawData, prob); //Get relevances between all features and class. for (i = 0; i < rawData.getFeaturesSize(); ++i) { relevances.push_back(mutualInfo.get(opts.classIndex, i)); redundances.push_back(0); } // Max relevance feature is added because no redundancy is possible. newFeatureIndex = getMaxRelevance(relevances, opts.classIndex); selectedFeatures.push_back(newFeatureIndex); lastFeatureIndex = newFeatureIndex; cout << newFeatureIndex << ","; //MRMR while (selectedFeatures.size() < rawData.getFeaturesSize() - 1 //-1 because class is discarded and selectedFeatures.size() < opts.selectedFeatures) { acum = -std::numeric_limits<double>::infinity(); for (j = 0; j < rawData.getFeaturesSize(); ++j) { //If feature not in selected selectedFeatures if (find(selectedFeatures.begin(), selectedFeatures.end(), j) == selectedFeatures.end() && j != opts.classIndex) { redundances[j] += mutualInfo.get(lastFeatureIndex, j); mrmr = relevances[j] - (redundances[j] / selectedFeatures.size()); if (mrmr > acum) { acum = mrmr; newFeatureIndex = j; } } } //Last feature doesn't prints comma. if ( (selectedFeatures.size() == (opts.selectedFeatures - 1)) or (selectedFeatures.size() == (rawData.getFeaturesSize() -2)) ){ cout << newFeatureIndex; }else{ cout << newFeatureIndex << ","; } selectedFeatures.push_back(newFeatureIndex); lastFeatureIndex = newFeatureIndex; } rawData.destroy(); prob.destroy(); printf("\n"); return (0); }
// Calculates centroides of peaks from raw data void CentroidData::calcCentroids( RawData &pRawData ) // Profile data object // Calculates centroide data from profile data { int i,hw,j; double cm,toti,min_dh; vector<double> masses,intens; pRawData.get(masses,intens); fCentroidPeaks.clear(); //////////////////////////////////////////// if( CENTROID_DATA_MODUS ) { // if data alread centroided in mzXML file for (i=0;i<(int)masses.size();i++) { double inte = intens[i]; double mz = masses[i]; if( inte >= pRawData.LOW_INTENSITY_MS_SIGNAL_THRESHOLD ){ CentroidPeak peak(mz,inte, fScanRetentionTime); /* if( CentroidData::MonoIsoDebugging ){ if( ( CentroidData::DebugMonoIsoMassMin <= mz) && ( CentroidData::DebugMonoIsoMassMax >= mz) ){ peak.show_info(); } } */ fCentroidPeaks.push_back(peak); } } } else { //////////////////////////////////////////// // centroid raw data min_dh = pRawData.LOW_INTENSITY_MS_SIGNAL_THRESHOLD; // min height hw = fWindowWidth/2; for (i=2;i<(int)masses.size()-2;i++) { // Peak must be concave in the interval [i-2 .. i+2] if (intens[i]>min_dh && intens[i]>intens[i-1]+min_dh && intens[i]>=intens[i+1] && intens[i-1]>intens[i-2]+min_dh && intens[i+1]>=intens[i+2]) { // centroid mass: cm = 0.0; // total intensity: toti = 0.0; // double Tinte = intens[i]; double Tmz = masses[i]; /* if( MonoIsoDebugging ){ if( ( DebugMonoIsoMassMin <= Tmz) && ( DebugMonoIsoMassMax >= Tmz) ){ cout<<endl<<"*Centroid: "<<Tmz<<": "<<Tinte<<endl; } } */ for (j= -hw;j<=hw;j++) { double inte = intens[i-j]; double mz = masses[i-j]; /* if( MonoIsoDebugging ){ if( ( DebugMonoIsoMassMin <= Tmz) && ( DebugMonoIsoMassMax >= Tmz) ){ cout<<"** add: "<<mz<<": "<<inte<<endl; } } */ cm += inte*mz; toti += (double) intens[i-j]; } cm = cm/toti; // Centre of gravity = centroid // take the intensity at the apex of the profile peak: CentroidPeak peak(cm,intens[i],fScanRetentionTime); // Lukas: take summed intensity over all peaks: // CentroidPeak peak( cm, toti); if( MonoIsoDebugging ){ if( ( DebugMonoIsoMassMin <= Tmz) && ( DebugMonoIsoMassMax >= Tmz) ){ cout<<"*final: "; peak.show_info(); } } fCentroidPeaks.push_back(peak); } } } }
void DataStore::Insert(const RawData& data) { Insert(data.GetSessionId(), data.GetWebsiteId(), data.GetAction()); }
// Open a gammut surface dialog, use info passed in data if data is valid McoStatus AllWins::openGammutSurface1(void) { GamutSurfaceWin *gamutsurf; int32 maxwinnum = 0; McoStatus state = MCO_SUCCESS; int i; Str255 patchFName; RawData *raw; StandardFileReply sinReply; SFTypeList filelist; Str255 inname; FILE *fs; if (!QD3D_Present) return MCO_NO_QD3D; if (xyztorgb == NULL) return MCO_FAILURE; // raw is deleted by the window raw = new RawData(); filelist[0] = 'TEXT'; StandardGetFile(nil, 1, filelist, &sinReply); if(sinReply.sfGood == 0) return MCO_CANCEL; copy_str(patchFName,sinReply.sfFile.name); memcpy(inname, sinReply.sfFile.name, *(sinReply.sfFile.name)+1); PathNameFromDirID(sinReply.sfFile.parID, sinReply.sfFile.vRefNum, inname); ptocstr(inname); fs = fopen( (char*)inname, "r" ); if(!fs) return MCO_FILE_OPEN_ERROR; raw->loadData(fs); fclose(fs); //for (i=0; i<tempdoc->_condata.smooth; i++) raw->smooth_patch(); maxwinnum = 0; for (i=0; i<numWins; i++) if (wins[i]->isMyWindowType(GammutSurfaceTherm1)) { if (wins[i]->WinNum >= maxwinnum) maxwinnum = wins[i]->WinNum+1; } memcpy(inname, sinReply.sfFile.name, *(sinReply.sfFile.name)+1); // the flag after raw indicates that the window should delete raw gamutsurf = new GamutSurfaceWin(0L,raw,1,GammutSurfaceTherm1,maxwinnum,inname); if (gamutsurf == 0L) return MCO_MEM_ALLOC_ERROR; if (gamutsurf->error == MCO_MEM_ALLOC_ERROR) { McoErrorAlert(gamutsurf->error); delete gamutsurf; return MCO_SUCCESS; } if (gamutsurf->error != MCO_SUCCESS) { state = gamutsurf->error; delete gamutsurf; return state; } return AddWin(gamutsurf,0L); }
void OrganizedData::process(RawData* raw, int nBlock, double pTest, int nSupport) { int nData = raw->nData, nDim = raw->nDim - 1; this->nSupport = nSupport; this->nBlock = nBlock; this->nDim = nDim; train = field<mat>(nBlock,2); test = field<mat>(nBlock,2); support = field<mat>(1,2); mat xm(nSupport,nDim), ym(nSupport,1); vec mark(nData); mark.fill(0); printf("Randomly selecting %d supporting point ...\n", nSupport); for (int i = 0; i < nSupport; i++) { int pos = IRAND(0, nData - 1); while (mark[pos] > 0) pos = IRAND(0, nData - 1); mark[pos] = 1; for (int j = 0; j < nDim; j++) xm(i, j) = raw->X(pos,j); ym(i,0) = raw->X(pos,nDim); } support(0,0) = xm; xm.clear(); support(0,1) = ym; ym.clear(); cout << "Partitioning the remaining data into " << nBlock << " cluster using K-Mean ..." << endl; vvd _remain; for (int i = 0; i < nData; i++) if (!mark(i)) { rowvec R = raw->X.row(i); _remain.push_back(r2v(R)); } mat remaining = v2m(_remain); mark.clear(); RawData* remain = new RawData(remaining); KMean* partitioner = new KMean(remain); Partition* clusters = partitioner->cluster(nBlock); cout << "Packaging training/testing data points into their respective cluster" << endl; for (int i = 0; i < nBlock; i++) { cout << "Processing block " << i + 1 << endl; int bSize = (int) clusters->member[i].size(), tSize = (int) floor(bSize * pTest), pos = 0, counter = 0; mark = vec(bSize); mark.fill(0); if (bSize > tSize) // if we can afford to draw tSize test points from this block without depleting it ... { mat xt(tSize,nDim), yt(tSize,1); for (int j = 0; j < tSize; j++) { pos = IRAND(0, bSize - 1); while (mark[pos] > 0) pos = IRAND(0, bSize - 1); mark[pos] = 1; pos = clusters->member[i][pos]; for (int t = 0; t < nDim; t++) xt(j, t) = remain->X(pos,t); yt(j,0) = remain->X(pos,nDim); } bSize -= tSize; nTest += tSize; test(i,0) = xt; xt.clear(); test(i,1) = yt; yt.clear(); } nTrain += bSize; mat xb(bSize,nDim), yb(bSize,1); //cout << remain->X.n_rows << endl; for (int j = 0; j < (int)mark.n_elem; j++) if (mark[j] < 1) { for (int t = 0; t < nDim; t++) { xb(counter,t) = remain->X(clusters->member[i][j],t); } yb(counter++,0) = remain->X(clusters->member[i][j],nDim); } train(i,0) = xb; xb.clear(); train(i,1) = yb; yb.clear(); mark.clear(); printf("Done ! nData[%d] = %d, nTrain[%d] = %d, nTest[%d] = %d .\n", i, (int) clusters->member[i].size(), i, train(i,0).n_rows, i, (int) test(i,0).n_rows); } }
AnimationPtr AnimationLoader::load(const std::string& filename) { bfs::path animPath(filename); std::string animationFilename = animPath.string(); TiXmlDocument doc; AnimationPtr animation; try { RawData* data = m_vfs->open(animationFilename); if (data) { if (data->getDataLength() != 0) { doc.Parse(data->readString(data->getDataLength()).c_str()); if (doc.Error()) { return animation; } // done with data delete resource delete data; data = 0; } } } catch (NotFound& e) { FL_ERR(_log, e.what()); // TODO - should we abort here // or rethrow the exception // or just keep going return animation; } // if we get here then everything loaded properly // so we can just parse out the contents TiXmlElement* root = doc.RootElement(); if (root) { animation.reset(new Animation()); int animDelay = 0; root->QueryValueAttribute("delay", &animDelay); int animXoffset = 0; int animYoffset = 0; int action = -1; root->QueryValueAttribute("x_offset", &animXoffset); root->QueryValueAttribute("y_offset", &animYoffset); root->QueryValueAttribute("action", &action); for (TiXmlElement* frameElement = root->FirstChildElement("frame"); frameElement; frameElement = frameElement->NextSiblingElement("frame")) { if (animation) { animation->setActionFrame(action); const std::string* sourceId = frameElement->Attribute(std::string("source")); if (sourceId) { bfs::path framePath(filename); if (HasParentPath(framePath)) { framePath = GetParentPath(framePath) / *sourceId; } else { framePath = bfs::path(*sourceId); } ImagePtr imagePtr; if(!m_imageManager->exists(framePath.string())) { imagePtr = m_imageManager->create(framePath.string()); } else { imagePtr = m_imageManager->getPtr(framePath.string()); } if (imagePtr) { int frameXoffset = 0; int frameYoffset = 0; int success = root->QueryValueAttribute("x_offset", &frameXoffset); if (success == TIXML_SUCCESS) { imagePtr->setXShift(frameXoffset); } else { imagePtr->setXShift(animXoffset); } success = root->QueryValueAttribute("y_offset", &frameYoffset); if (success == TIXML_SUCCESS) { imagePtr->setYShift(frameYoffset); } else { imagePtr->setYShift(animYoffset); } int frameDelay = 0; success = root->QueryValueAttribute("delay", &frameDelay); if (success == TIXML_SUCCESS) { animation->addFrame(imagePtr, frameDelay); } else { animation->addFrame(imagePtr, animDelay); } } } } } } return animation; }