/// \brief Reallocates internal block to hold at least \p newSize bytes. /// /// Additional memory may be allocated, but for efficiency it is a very /// good idea to call reserve before doing byte-by-byte edit operations. /// The block size as returned by size() is not altered. reserve will not /// reduce allocated memory. If you think you are wasting space, call /// deallocate and start over. To avoid wasting space, use the block for /// only one purpose, and try to get that purpose to use similar amounts /// of memory on each iteration. /// void memblock::reserve (size_type newSize, bool bExact) { if ((newSize += minimumFreeCapacity()) <= m_Capacity) return; void* oldBlock (is_linked() ? NULL : data()); if (!bExact) newSize = Align (newSize, c_PageSize); pointer newBlock = (pointer) realloc (oldBlock, newSize); if (!newBlock) __THROW_BAD_ALLOC(newSize); if (!oldBlock && cdata()) copy_n (cdata(), min (size() + 1, newSize), newBlock); link (newBlock, size()); m_Capacity = newSize; }
static void writeDat( std::ofstream & os, const std::vector<char> & data ) { std::vector<char> cdata( data.size() ); uLongf len = data.size(); compress2( (Bytef*)cdata.data(), &len, (const Bytef*)data.data(), data.size(), 9 ); cdata.resize( len ); writeChunk( os, "IDAT", cdata ); }
void PVUnionArray::compress() { if (getArray()->getArraySizeType() == Array::fixed) return; svector vec(reuse()); // TODO: check for first NULL before realloc size_t length = vec.size(); size_t newLength = 0; for(size_t i=0; i<length; i++) { if(vec[i].get()!=NULL) { newLength++; continue; } // find first non 0 size_t notNull = 0; for(size_t j=i+1;j<length;j++) { if(vec[j].get()!=NULL) { notNull = j; break; } } if(notNull!=0) { vec[i] = vec[notNull]; vec[notNull].reset(); newLength++; continue; } break; } vec.resize(newLength); const_svector cdata(freeze(vec)); swap(cdata); }
/// \brief Reallocates internal block to hold at least \p newSize bytes. /// /// Additional memory may be allocated, but for efficiency it is a very /// good idea to call reserve before doing byte-by-byte edit operations. /// The block size as returned by size() is not altered. reserve will not /// reduce allocated memory. If you think you are wasting space, call /// deallocate and start over. To avoid wasting space, use the block for /// only one purpose, and try to get that purpose to use similar amounts /// of memory on each iteration. /// void memblock::reserve (size_type newSize, bool bExact) { if ((newSize += minimumFreeCapacity()) <= m_Capacity) return; pointer oldBlock (is_linked() ? NULL : data()); const size_t alignedSize (Align (newSize, 64)); if (!bExact) newSize = alignedSize; pointer newBlock = (pointer) realloc (oldBlock, newSize); if (!newBlock) USTL_THROW(bad_alloc (newSize)); if (!oldBlock & (cdata() != NULL)) copy_n (cdata(), min (size() + 1, newSize), newBlock); link (newBlock, size()); m_Capacity = newSize; }
JNIEXPORT jbyteArray JNICALL Java_com_rzheng_fdlib_FaceDetector_boxesProcess(JNIEnv* env, jclass, jlong thiz, jbyteArray jpegdata, jobjectArray bbxposArr, jobjectArray bbxtxtArr, jbooleanArray bbxprocArr, jintArray bbxproctypeArr) { jbyte* imgjData = env->GetByteArrayElements(jpegdata, 0); uchar* buf = (uchar*) imgjData; size_t len = env->GetArrayLength(jpegdata); std::vector<uchar> cdata(buf, buf+len); cv::Mat img = cv::imdecode(cdata, CV_LOAD_IMAGE_COLOR); int bbxnum = env->GetArrayLength(bbxposArr); // LOGD("boxes number: %d", bbxnum); jboolean* bbxproc = env->GetBooleanArrayElements(bbxprocArr, 0); jint* bbxproctype = env->GetIntArrayElements(bbxproctypeArr, 0); cv::Scalar color; for (int i=0; i < bbxnum; i++) { jintArray bbxposJ = (jintArray) env->GetObjectArrayElement(bbxposArr, i); jint *bbxpos = env->GetIntArrayElements(bbxposJ, 0); jstring bbxtxtJ = (jstring) env->GetObjectArrayElement(bbxtxtArr, i); const char* bbxtxt = env->GetStringUTFChars(bbxtxtJ, NULL); // LOGD("box position: (%d, %d) - (%d, %d), text: %s, do blur: %s, blur type: %d", bbxpos[0], bbxpos[1], bbxpos[2], bbxpos[3], bbxtxt, bbxproc[i]?"yes":"no", bbxproctype[i]); if (bbxproctype[i] == 2) { color = cv::Scalar(0,0,255); } else { color = cv::Scalar(0,255,0); } cv::Rect roi = cv::Rect(cv::Point(bbxpos[0], bbxpos[1]), cv::Point(bbxpos[2], bbxpos[3])); if (bbxproc[i]) { if (!bbxproctype[i]) { // blur face, default cv::medianBlur(img(roi), img(roi), 77); } else { // blur body } } cv::rectangle(img, roi, color, 2); cv::putText(img, bbxtxt, cv::Point(bbxpos[0], bbxpos[1]-10), cv::FONT_HERSHEY_DUPLEX, 0.8, color, 2); env->ReleaseIntArrayElements(bbxposJ, bbxpos, JNI_ABORT); env->ReleaseStringUTFChars(bbxtxtJ, bbxtxt); } env->ReleaseBooleanArrayElements(bbxprocArr, bbxproc, JNI_ABORT); env->ReleaseIntArrayElements(bbxproctypeArr, bbxproctype, JNI_ABORT); std::vector<int> params; params.push_back(CV_IMWRITE_JPEG_QUALITY); params.push_back(100); std::vector<uchar> cdataEnc; cv::imencode(".jpg", img, cdataEnc, params); jbyteArray jpegBoxsProcessed = env->NewByteArray(cdataEnc.size()); env->SetByteArrayRegion(jpegBoxsProcessed, 0, cdataEnc.size(), (jbyte*)&cdataEnc[0]); env->ReleaseByteArrayElements(jpegdata, imgjData, JNI_ABORT); return jpegBoxsProcessed; }
/** Segment a image using the Uchyama algorithm @param inputImage Input image data @param alpha Learning rate @param numcluster Number of clusters @param numwin Win threshold @param numiter Number of interactions @return Labeled image with clusters */ cv::Mat caib::clis(const cv::Mat &inputImage, const double &alpha, const int &numcluster, const int &numwin, const int &numiter) { std::vector<int> wincount = std::vector<int>(numcluster, 0); std::vector<std::vector<double> > cdata (1, std::vector<double>(inputImage.channels(),0)); cv::Mat labels = cv::Mat(inputImage.size(), cv::DataType<int>::type); std::vector<cv::Mat> imgChannels; cv::split(inputImage, imgChannels); for (int c = 0; c < imgChannels.size(); c++) { imgChannels[c].convertTo(imgChannels[c], cv::DataType<double>::type); } int nwin = (numwin < 0) ? sqrt(numcluster) * 400 : numwin; int niter = (numiter < 0) ? ( (2 * numcluster) - 3 ) * nwin * (numcluster + 7) : numiter; for (int i=0; i<niter; i++) { int rx = rand()%inputImage.cols; int ry = rand()%inputImage.rows; int winner = chooseWinner( imgChannels, cv::Point(rx,ry), cdata ); for (int c=0; c<inputImage.channels(); c++) { int offstep = rx + (ry * inputImage.cols); cdata[winner][c] += alpha * ( imgChannels[c].ptr<double>()[offstep] - cdata[winner][c] ); } wincount[winner]++; if (wincount[winner] == nwin && cdata.size() < numcluster) { cdata.push_back(cdata[winner]); wincount[winner] = 0; } } for (int x=0; x<inputImage.cols; x++) { for (int y=0; y<inputImage.rows; y++) { double mindist = DBL_MAX; for (int i=0; i<cdata.size(); i++) { double dist = 0; int offstep = x + (y * inputImage.cols); for (int c=0; c<inputImage.channels(); c++) dist += std::pow( ( imgChannels[c].ptr<double>()[offstep] - cdata[i][c] ), 2); if( dist < mindist ) { mindist = dist; labels.at<int>(cv::Point(x,y)) = i; } } } } return labels; }
/// Frees internal data. void memblock::deallocate (void) throw() { if (m_Capacity) { assert (cdata() && "Internal error: space allocated, but the pointer is NULL"); assert (data() && "Internal error: read-only block is marked as allocated space"); free (data()); } unlink(); }
PVStructurePtr StandardPVField::enumerated(StringArray const &choices) { StructureConstPtr field = standardField->enumerated(); PVStructurePtr pvStructure = pvDataCreate->createPVStructure(field); PVStringArray::svector cdata(choices.size()); std::copy(choices.begin(), choices.end(), cdata.begin()); pvStructure->getSubFieldT<PVStringArray>("choices")->replace(freeze(cdata)); return pvStructure; }
static void writeFDat( std::ofstream & os, const std::vector<char> & data, int i ) { std::vector<char> cdata( data.size()+4 ); uint32_t ui = ntohl( i ); memcpy( cdata.data(), &ui, sizeof(ui) ); uLongf len = data.size(); compress2( (Bytef*)(cdata.data()+4), &len, (const Bytef*)data.data(), data.size(), 9 ); cdata.resize( len+4 ); writeChunk( os, "fdAT", cdata ); }
void content(const char**p) { while (*p[0] != '\0') { if (*p[0] != '<') { ++(*p); } else if (!cdata(p) && !tag(p)) { break; } } }
/// \brief Reallocates internal block to hold at least \p newSize bytes. /// /// Additional memory may be allocated, but for efficiency it is a very /// good idea to call reserve before doing byte-by-byte edit operations. /// The block size as returned by size() is not altered. reserve will not /// reduce allocated memory. If you think you are wasting space, call /// deallocate and start over. To avoid wasting space, use the block for /// only one purpose, and try to get that purpose to use similar amounts /// of memory on each iteration. /// void memblock::reserve (size_type newSize, bool bExact) { if ((newSize += minimumFreeCapacity()) <= m_Capacity) return; void* oldBlock (is_linked() ? NULL : data()); if (!bExact) newSize = Align (newSize, c_PageSize); pointer newBlock = (pointer) realloc (oldBlock, newSize); if (!newBlock) #if PLATFORM_ANDROID printf("bad_alloc\n"); #else throw bad_alloc (newSize); #endif if (!oldBlock && cdata()) copy_n (cdata(), min (size() + 1, newSize), newBlock); link (newBlock, size()); m_Capacity = newSize; }
/// Called when more buffer space (\p n bytes) is needed. ofstream::size_type ofstream::overflow (size_type n) { if (eof() || (n > remaining() && n < capacity() - pos())) return (ostringstream::overflow (n)); size_type bw = m_File.write (cdata(), pos()); clear (m_File.rdstate()); erase (begin(), bw); if (remaining() < n) ostringstream::overflow (n); return (remaining()); }
void post( const XMLByte* const data, const Count_t count, XERCES_CPP_NAMESPACE::XMLFormatter* const formatter ) { if( cdata( data, count ) ) return; if( ends( data, count, forward_slash_ ) ) { --level_; inline_ = false; } else if( ! inline_ && ends( data, count, close_angle_ ) ) newline( formatter ); }
void CPlayerLevels::ListAsync( const std::string& mode, int page, int perPage, bool includeData, bool includeThumbs, const CustomData& customFilter ) { std::string modeSafe = mode.empty() ? "popular" : (mode == "newest" || mode == "popular" ? mode : "popular"); char dataSafe = includeData ? 'y': 'n'; char thumSafe = includeThumbs ? 'y': 'n'; char IdString[50]; sprintf_s(IdString,49,"%d",gPlaytomic->GameId()); std::string url = kPlayerLevelListUrl1 + gPlaytomic->GetGameGuid() +kPlayerLevelListUrl2 + IdString + kPlayerLevelListUrl3 + modeSafe; sprintf_s(IdString,49,"%d", page); url += kPlayerLevelListUrl4 + page; sprintf_s(IdString,49,"%d", perPage); url += kPlayerLevelListUrl5; url += IdString; url += kPlayerLevelListUrl6; url += dataSafe; url += kPlayerLevelListUrl7; url += thumSafe; sprintf_s(IdString,49,"%d", customFilter.size()); url += kPlayerLevelListUrl10; url += IdString; CPostPtr postData(new CPost); if(!customFilter.empty()) { int fieldNumber = 0; CustomData::const_iterator it = customFilter.begin(); for(; it != customFilter.end(); it++) { char buff[10]; sprintf_s(buff,9,"%d", fieldNumber); std::string ckey("ckey"); std::string cdata("cdata"); ckey += buff; cdata += buff; postData->AddText(ckey.c_str(), it->first.c_str()); postData->AddText(cdata.c_str(), it->second.c_str()); } } gConnectionInterface->PerformAsyncRequest(url.c_str(), fastdelegate::MakeDelegate(this, &CPlayerLevels::ListAsyncComplete), postData); }
SLevelListPtr CPlayerLevels::SaveLevel( CLevel& level ) { char IdString[50]; sprintf_s(IdString,49,"%d",gPlaytomic->GameId()); std::string url = kPlayerLevelSaveUrl1 + gPlaytomic->GetGameGuid() +kPlayerLevelSaveUrl2 + IdString + kPlayerLevelSaveUrl3 + gPlaytomic->GetSourceUrl(); CPost postData; postData.AddText("data", level.GetData().c_str()); postData.AddText("playerid", level.GetPlayerId().c_str()); postData.AddText("playername", level.GetPlayerName().c_str()); postData.AddText("playersource", level.GetPlayerSource().c_str()); postData.AddText("name",level.GetName().c_str()); postData.AddText("nothumb", "y"); sprintf_s(IdString, 49, "%d", level.GetCustomData().size()); postData.AddText("customfields", IdString); const CustomData& customData = level.GetCustomData(); CustomData::const_iterator it = customData.begin(); int fieldNumber = 0; for (; it != customData.end(); it++) { char buff[10]; sprintf_s(buff,9,"%d", fieldNumber); std::string ckey("ckey"); std::string cdata("cdata"); ckey += buff; cdata += buff; postData.AddText(ckey.c_str(), it->first.c_str()); postData.AddText(cdata.c_str(), it->second.c_str()); } CPlaytomicResponsePtr response = gConnectionInterface->PerformSyncRequest(url.c_str(), &postData); SLevelListPtr returnList(new SLevelList); returnList->sErrorCode = response->ResponseError(); returnList->sSucceded = response->ResponseSucceded(); if(!response->ResponseSucceded()) { return returnList; } FData id; id = response->ResponseData().get("LevelId", id); std::list<CLevel> levelList; AddLevel(response->ResponseData(), id.asString(), returnList->sLevelList); return returnList; }
static CFArrayRef copyCertChainFromSignature(xar_signature_t sig) { unsigned count = xar_signature_get_x509certificate_count(sig); CFRef<CFMutableArrayRef> certs = makeCFMutableArray(0); for (unsigned ix = 0; ix < count; ix++) { const uint8_t *data; uint32_t length; if (xar_signature_get_x509certificate_data(sig, ix, &data, &length) == 0) { CFTempData cdata(data, length); CFRef<SecCertificateRef> cert = SecCertificateCreateWithData(NULL, cdata); CFArrayAppendValue(certs, cert.get()); } } return certs.yield(); }
std::pair<std::unique_ptr<char[]>, size_t> compress(const void* data, size_t dataSize, int level) { if (dataSize == 0) return std::make_pair(std::unique_ptr<char[]>(), 0); int csizeBound = LZ4_compressBound(dataSize); std::unique_ptr<char[]> cdata(new char[csizeBound]); int csize = (level == 0) ? LZ4_compress_default(static_cast<const char*>(data), cdata.get(), dataSize, csizeBound) : LZ4_compress_HC(static_cast<const char*>(data), cdata.get(), dataSize, csizeBound, level); assert(csize >= 0 && csize <= csizeBound); return std::make_pair(std::move(cdata), csize); }
void FormatterToXercesDOM::charactersRaw( const XMLCh* const chars, const unsigned int length) { try { processAccumulatedText(); cdata(chars, length); } catch(const XERCES_CPP_NAMESPACE_QUALIFIER DOMException& theException) { throw XercesDOMException(theException); } }
void sax_parser<_Handler,_Config>::special_tag() { assert(cur_char() == '!'); // This can be either <![CDATA, <!--, or <!DOCTYPE. size_t len = remains(); if (len < 2) throw sax::malformed_xml_error("special tag too short."); switch (next_char()) { case '-': { // Possibly comment. if (next_char() != '-') throw sax::malformed_xml_error("comment expected."); len -= 2; if (len < 3) throw sax::malformed_xml_error("malformed comment."); next(); comment(); } break; case '[': { // Possibly a CDATA. expects_next("CDATA[", 6); if (has_char()) cdata(); } break; case 'D': { // check if this is a DOCTYPE. expects_next("OCTYPE", 6); blank(); if (has_char()) doctype(); } break; default: throw sax::malformed_xml_error("failed to parse special tag."); } }
int main (int argc, char *argv[]) { document ("<atag></atag>"); string ("<atag/>"); document ("<test>lala<b>bold</b>blablabla<a><c/></a></test>"); tag ("b", 0); tag ("c", "a", 0); string ("<test>lala<b>bold</b>blablabla<a><c/></a></test>"); document (buf); cdata ("\" <online&dangerous> \"", "status", 0); attrib ("c", "d", "a", "b", 0); tag ("test", 0); string (buf); return 0; }
void CLeaderboard::ListAsync( const std::string& tableName, bool highest, const std::string& mode, int page, int perPage,const CustomData& customFilter ) { char IdString[50]; sprintf_s(IdString,49,"%d",gPlaytomic->GameId()); std::string url = kLeaderboardUrl1 + gPlaytomic->GetGameGuid() + kLeaderboardUrlList + IdString + kLeaderboardUrl3; CPostPtr postData(new CPost); postData->AddText("url", gPlaytomic->GetSourceUrl().c_str()); postData->AddText("table", tableName.c_str()); postData->AddText("highest", highest ? "y": "n"); postData->AddText("mode", mode.c_str()); char buff[300]; sprintf_s(buff,299,"%d", page); postData->AddText("page", buff); sprintf_s(buff, 299,"%d", perPage); postData->AddText("perpage", buff); sprintf_s(buff, 299,"%d", customFilter.size()); postData->AddText("numfilters", buff); if(customFilter.size() > 0) { int fieldNumber = 0; CustomData::const_iterator it = customFilter.begin(); for(;it != customFilter.end(); it++) { sprintf_s(buff,299,"%d", fieldNumber); std::string ckey("ckey"); ckey += buff; std::string cdata("cdata"); cdata += buff; std::string value = it->second; fieldNumber++; postData->AddText(ckey.c_str(), it->first.c_str() ); postData->AddText(cdata.c_str(), it->second.c_str()); } } gConnectionInterface->PerformAsyncRequest(url.c_str(), fastdelegate::MakeDelegate(this, &CLeaderboard::ListComple),postData); }
int main(int argc,char*argv[]) { if(argc<2){ LOG("usage: "<<argv[0]<<" data.csv"); return -1; } if(argc==3) print_only_best=true; Concrete::CData cdata(argv[1]); cdata.init(); Concrete::CData bt_cdata=cdata;//.bootstrap(resize_data,0.05); Tree::FunctionDB* fdb=Tree::std_functions_db(); fdb->add_variables(bt_cdata.x_count()); //for(double i=-10.0;i<10.0;i+=0.5) // fdb->add_constant(i); Tree::Generator*gnrt=new Tree::Generator(fdb,max_depth); Tree::Crossover*crossover=new Tree::Crossover; Tree::Mutator mtr(gnrt,crossover); GpGenerator *dg=new GpGenerator(gnrt); //bin_dna_generator *dg=new GpGeneratorHist(fdb,max_depth); selector *sel_r=new rnd_selector; GpMutator *gp_mtn=new GpMutator(gnrt,crossover,fdb); GpCrossover*c=new GpCrossover(fdb,crossover); //std_ga* sg=new hist_gp(sel_r,gp_mtn,c,dg,10); std_ga* sg=new std_ga(sel_r,gp_mtn,c,dg); GpFitness*ftn=new GpFitness(percent_to_learn,&bt_cdata,fdb); sg->set_params(make_params(mtn_raiting,0.4,psize)); sg->setFitness(ftn); sg->init(); solution sln=sg->getSolution(max_steps,target_value,true,print_only_best); LOG("results: "<<sln.first); ftn->check_solution(sln.second,&cdata); }
// test tread-safty void crypt_func(sm::sm4::SM4* sm4,const unsigned char* data,size_t data_bytes,size_t loop,bool* satus) { sm::sm4::sm4_crypt_data edata(data_bytes); sm::sm4::sm4_crypt_data cdata(data_bytes); for (size_t i=0;i<loop;++i){ /* if(i%(loop/10)==0 && i!=0) std::cout<<"running, loop "<<i<<" of "<< loop<<std::endl; */ sm4->crypt(sm::sm4::kSM4Encrypt,data,data_bytes,edata); sm4->crypt(sm::sm4::kSM4Decrypt,edata.ptr(),edata.bytes(),cdata); if (::memcmp(data,cdata.ptr(),data_bytes)!=0){ std::cout<<"test failed, loop="<<i<< std::endl; *satus=false; return; } } }
size_t PVUnionArray::append(size_t number) { checkLength(value.size()+number); svector data(reuse()); data.resize(data.size()+number); UnionConstPtr punion = unionArray->getUnion(); PVDataCreatePtr pvDataCreate = getPVDataCreate(); for(svector::reverse_iterator it = data.rbegin(); number; ++it, --number) *it = pvDataCreate->createPVUnion(punion); size_t newLength = data.size(); const_svector cdata(freeze(data)); swap(cdata); return newLength; }
CPlaytomicResponsePtr CLeaderboard::Save( const std::string& tableName, const CScore& score, bool highest, bool allowDuplicates ) { char IdString[50]; sprintf_s(IdString,49,"%d",gPlaytomic->GameId()); std::string url = kLeaderboardUrl1 + gPlaytomic->GetGameGuid() + kLeaderboardUrl2 + IdString + kLeaderboardUrl3; CPost postData; postData.AddText("url", gPlaytomic->GetSourceUrl().c_str()); postData.AddText("table", tableName.c_str()); postData.AddText("highest", highest ? "y": "n"); postData.AddText("name", score.GetName().c_str()); char buff[300]; sprintf_s(buff,299,"%d", score.GetPoints()); postData.AddText("points", buff); sprintf_s(buff,299,"%s%d",gPlaytomic->GetSourceUrl().c_str(), score.GetPoints()); postData.AddText("auth", MD5(buff).hexdigest().c_str()); CustomData customData = score.GetCustomData(); sprintf_s(buff,299,"%d", customData.size()); postData.AddText("customfields", buff); int fieldNumber = 0; CustomData::iterator it = customData.begin(); for(;it != customData.end(); it++) { sprintf_s(buff,299,"%d", fieldNumber); std::string ckey("ckey"); ckey += buff; std::string cdata("cdata"); cdata += buff; std::string value = it->second; fieldNumber++; postData.AddText(ckey.c_str(), it->first.c_str() ); postData.AddText(cdata.c_str(), it->second.c_str()); } return gConnectionInterface->PerformSyncRequest(url.c_str(), &postData); }
JNIEXPORT jbyteArray JNICALL Java_com_rzheng_fdlib_FaceDetector_droidJPEGCalibrate(JNIEnv* env, jclass, jlong thiz, jbyteArray jpegdata, jint front1orback0, jint orientCase) { jbyte* picjData = env->GetByteArrayElements(jpegdata, 0); uchar* buf = (uchar*) picjData; size_t len = env->GetArrayLength(jpegdata); std::vector<uchar> cdata(buf, buf+len); cv::Mat m = cv::imdecode(cdata, CV_LOAD_IMAGE_COLOR); // do calibration: rotate + flip ((FaceDetector*)thiz)->fromDroidCamToCV(m, front1orback0, orientCase); LOGD("picture size after calibrated: %d X %d", m.rows, m.cols); std::vector<int> params; params.push_back(CV_IMWRITE_JPEG_QUALITY); params.push_back(100); std::vector<uchar> cdataEnc; cv::imencode(".jpg", m, cdataEnc, params); jbyteArray jpegCalibrated = env->NewByteArray(cdataEnc.size()); env->SetByteArrayRegion(jpegCalibrated, 0, cdataEnc.size(), (jbyte*)&cdataEnc[0]); env->ReleaseByteArrayElements(jpegdata, picjData, JNI_ABORT); return jpegCalibrated; }
bool PVUnionArray::remove(size_t offset,size_t number) { if (number==0) return true; else if (offset+number>getLength()) return false; else if (getArray()->getArraySizeType() == Array::fixed) return false; svector vec(reuse()); size_t length = vec.size(); for(size_t i = offset; i+number < length; i++) { vec[i].swap(vec[i + number]); } vec.resize(length - number); const_svector cdata(freeze(vec)); swap(cdata); return true; }
void CPlayerLevels::SaveLevelAsync( CLevel& level ) { char IdString[50]; sprintf_s(IdString,49,"%d",gPlaytomic->GameId()); std::string url = kPlayerLevelSaveUrl1 + gPlaytomic->GetGameGuid() +kPlayerLevelSaveUrl2 + IdString + kPlayerLevelSaveUrl3 + gPlaytomic->GetSourceUrl(); CPostPtr postData(new CPost); postData->AddText("data", level.GetData().c_str()); postData->AddText("playerid", level.GetPlayerId().c_str()); postData->AddText("playername", level.GetPlayerName().c_str()); postData->AddText("playersource", level.GetPlayerSource().c_str()); postData->AddText("name",level.GetName().c_str()); postData->AddText("nothumb", "y"); sprintf_s(IdString, 49, "%d", level.GetCustomData().size()); postData->AddText("customfields", IdString); const CustomData& customData = level.GetCustomData(); CustomData::const_iterator it = customData.begin(); int fieldNumber = 0; for (; it != customData.end(); it++) { char buff[10]; sprintf_s(buff,9,"%d", fieldNumber); std::string ckey("ckey"); std::string cdata("cdata"); ckey += buff; cdata += buff; postData->AddText(ckey.c_str(), it->first.c_str()); postData->AddText(cdata.c_str(), it->second.c_str()); } gConnectionInterface->PerformAsyncRequest(url.c_str(), fastdelegate::MakeDelegate(this, &CPlayerLevels::SaveLevelComplete), postData); }
JNIEXPORT jbyteArray JNICALL Java_com_rzheng_fdlib_FaceDetector_detectAndBlurJPEG(JNIEnv* env, jclass, jlong thiz, jbyteArray jpegdata) { jbyte* imgjData = env->GetByteArrayElements(jpegdata, 0); uchar* buf = (uchar*) imgjData; size_t len = env->GetArrayLength(jpegdata); std::vector<uchar> cdata(buf, buf+len); cv::Mat img = cv::imdecode(cdata, CV_LOAD_IMAGE_COLOR); cv::Mat imgDet = img; std::vector<cv::Rect> bbsFiltered = ((FaceDetector*)thiz)->detectMat(imgDet, true); for(std::vector<cv::Rect>::iterator r = bbsFiltered.begin(); r != bbsFiltered.end(); r++) { cv::medianBlur(img(*r), img(*r), 77); } std::vector<int> params; params.push_back(CV_IMWRITE_JPEG_QUALITY); params.push_back(100); std::vector<uchar> cdataEnc; cv::imencode(".jpg", img, cdataEnc, params); jbyteArray jpegProcessed = env->NewByteArray(cdataEnc.size()); env->SetByteArrayRegion(jpegProcessed, 0, cdataEnc.size(), (jbyte*)&cdataEnc[0]); env->ReleaseByteArrayElements(jpegdata, imgjData, JNI_ABORT); return jpegProcessed; }
/// Copies data from \p p, \p n. void memblock::assign (const void* p, size_type n) { assert ((p != (const void*) cdata() || size() == n) && "Self-assignment can not resize"); resize (n); copy (p, n); }