void CadScene::updateObjectDrawCache( Object& object ) { Geometry& geom = m_geometry[object.geometryIndex]; std::vector<ListItem> listSolid; std::vector<ListItem> listWire; listSolid.reserve(geom.parts.size()); listWire.reserve(geom.parts.size()); for (size_t i = 0; i < geom.parts.size(); i++) { if (!object.parts[i].active) continue; ListItem item; item.state.materialIndex = object.parts[i].materialIndex; item.range = geom.parts[i].indexSolid; item.state.matrixIndex = object.parts[i].matrixIndex; listSolid.push_back(item); item.range = geom.parts[i].indexWire; item.state.matrixIndex = object.parts[i].matrixIndex; listWire.push_back(item); } std::sort( listSolid.begin(), listSolid.end(), ListItem_compare ); std::sort( listWire.begin(), listWire.end(), ListItem_compare ); fillCache(object.cacheSolid, listSolid); fillCache(object.cacheWire, listWire); }
std::streamsize CurlStreamFile::read(void *dst, std::streamsize bytes){ if(eof() || _error) return 0; fillCache(bytes + tell()); if(_error) return 0; return std::fread(dst, 1, bytes, _cache); }
String XWindowsClipboard::get(EFormat format) const { assert(m_open); fillCache(); return m_data[format]; }
bool XWindowsClipboard::has(EFormat format) const { assert(m_open); fillCache(); return m_added[format]; }
std::string Demangler::demangle(const std::string &mangledName) { std::string retval; if (!nameMap_.getOptional(mangledName).assignTo(retval)) { std::vector<std::string> mangledNames(1, mangledName); fillCache(mangledNames); retval = nameMap_[mangledName]; // an exception here means fillCache failed } return retval; }
Bool FileRStream::read(int size, void* d) { Int32 remaining; BYTE *p; if (strm_status != STRM_OK) // exit on stream error return FALSE; if (size) // if were reading anything... { remaining = size; p = (BYTE*)d; if (buffHead == -1) // if the buffer is empty and { // this block we want to read is if (size < (STRM_BUFFER_SIZE/2)) // less than half the buffer if (!fillCache(getPosition())) // then fill the buffer return (FALSE); } if (buffHead != -1) // if there is a buffer fulfill { // as much of the request as size = a_min(buffTail-buffPos+1, remaining); // possible from the buffer memcpy(p, buffer+(buffPos-buffHead), size); remaining-= size; buffPos += size; p += size; } // if not all fulfilled from the if (remaining) // buffer go to disk if (ReadFile(hFile, p, remaining, &lastBytes, NULL)) { if ((Int32)lastBytes != remaining) { strm_status = STRM_EOS; return FALSE; } } else { return setStatus(); } if (buffPos > buffTail) buffHead = -1; } return TRUE; }
bool CurlStreamFile::seek(std::streampos pos){ if(pos<0){ std::ostringstream os; os<<"CurlStreamFile: can't seek to negative absolute position"<<pos; throw SnailException(os.str()); } fillCache(pos); if(_error) return false; if(_cached<pos){ return false; } if(std::fseek(_cache, pos, SEEK_SET)==-1){ std::cout<<"warning : fseek failed"<<std::endl; return false; } return true; }
int main(void) { eLibrary_CLT_registerClient(); for (;;) { eLibrary_CLT_createRequest(str, &request); cache_hit = readCache(request, &response); if (false == cache_hit) { eLibrary_CLT_getResponse(); } fillCache(response); writeOutput(); freeResponse(); } eLibrary_CLT_destroyClient(); }
Token * CachingTokenFilter::next( Token* t ) { if( ! bCacheInitialized ) { fillCache(); bCacheInitialized = true; itCache = cache.begin(); } // if the cache is exhausted, return null if( itCache == cache.end() ) return NULL; t->set( (*itCache)->termBuffer(), (*itCache)->startOffset(), (*itCache)->endOffset(), (*itCache)->type() ); t->setPositionIncrement( (*itCache)->getPositionIncrement() ); t->setPayload( (*itCache)->getPayload() ); itCache++; return t; }
void getMaxRectangle(u8* data, u8 val, int w, int h, vect2D* pos, vect2D* size) { int x; vect2D originb=vect2(0,0),cornerb=vect2(-1,-1); pile_struct p; initPile(&p); int* c=initCache(h); for(x=w-1;x>=0;x--) { int y, width=0; fillCache(c,data,val,w,h,x); for(y=0;y<=h;y++) { if(c[y]>width) { pushPile(vect2(y,width),&p); width=c[y]; }else if(c[y]<width) { int y0, w0; while(1) { vect2D v=popPile(&p); y0=v.x;w0=v.y; if(width*(y-y0)>area(originb,cornerb)) { originb=vect2(x,y0); cornerb=vect2(x+width-1,y-1); } width=w0; if(c[y]>=width)break; } width=c[y]; if(width)pushPile(vect2(y0,w0),&p); } } } if(c)free(c); *pos=originb; *size=vect2(cornerb.x-originb.x+1,cornerb.y-originb.y+1); }
uint8_t ADMVideoDropOut::getFrameNumberNoAlloc(uint32_t frame, uint32_t *len, uint8_t *data, uint32_t *flags) { UNUSED_ARG(flags); uint32_t uvlen; uint32_t dlen,dflags; uint8_t *_next; uint8_t *_previous; uint8_t *_current; // printf("\n DropOut : %lu\n",frame); uvlen= _info.width*_info.height; *len=uvlen+(uvlen>>1); if(frame> _info.nb_frames-1) return 0; if(!frame || (frame==_info.nb_frames-1)) { if(!_in->getFrameNumberNoAlloc(frame, &dlen,_buffer[0],&dflags)) { return 0; } _bufnum[0]=frame; memcpy(data,_buffer[0],*len); return 1; } assert(frame<_info.nb_frames); // read uncompressed frame switch(fillCache(frame)) { case 0: return 0; case 1: memcpy(data,_buffer[index_c],*len);return 1;break; case 2: break; default: assert(0); break; } _previous=_buffer[index_p]; _current=_buffer[index_c]; _next=_buffer[index_n]; // for u & v , no action -> copy it as is memcpy(data+uvlen,_current+uvlen,uvlen>>1); uint8_t *inprev,*innext,*incur,*zout; inprev=_previous+1+_info.width; innext=_next+1+_info.width; incur =_current+1+_info.width; zout=data+_info.width+1; int32_t c0,c1,c2,c3; //,_nextPix,_currPix,_prevPix,cc; for(uint32_t y= _info.height-2;y>2;y--) { c0=0; c1=0; c2=0; c3=0; inprev=_previous +1+y*_info.width; innext=_next +1+y*_info.width;; incur =_current +1+y*_info.width;; // look if the field is more different temporarily than spacially for(uint32_t x= _info.width-1;x>1;x--) { c0+=(abs(((*inprev))-( *incur ))^2); c1+=(abs(((*inprev))-( *innext ))^2)<<1; c0+=(abs(((*incur ))-( *innext ))^2); c2+=(abs((( *(incur-_info.width*2) ))-( *(incur ) ))^2) ; c3+=(abs((( *(incur-_info.width*2) ))-( *(incur+_info.width*2) ))^2)<<1; c2+=(abs((( *(incur ) ))-( *(incur+_info.width*2) ))^2) ; incur++; innext++; inprev++; } // If yes, replace the line by an average of next/previous image inprev=_previous +y*_info.width; innext=_next +y*_info.width;; incur =_current +y*_info.width;; zout=data +y*_info.width; if (c1<c0 &&c3<c2) { for(uint32_t x= _info.width;x>0;x--) { *zout= ((*(inprev))+(*(innext)))>>1 ; zout++; innext++; inprev++; } } else memcpy(zout,incur,_info.width); }