void getGeneration(LifeList *cells, History hist, int gen) { assert(gen < hist.ngenerations); resizeIfNeeded(cells, hist.ncells[gen]); cells->ncells= copyList(hist.cellList[gen], hist.ncells[gen], cells->cellList, 0); }
void getpatRLE(char *s, LifeList *cells) { int i, x = 0, y = 0, reps = 0, n = 0; int patlen = strspn(s, "0123456789bo.ABCDE$"); for (i=0; i < patlen; i++) { if ('0' <= s[i] && s[i] <= '9') { reps = 10 * reps + (int)(s[i] - '0'); } else { if (reps == 0) reps = 1; if (s[i] == '$') { x = 0; y += reps; } else { int value = 0; if (s[i] == 'o' || s[i] == 'A') value = 1; else if (s[i] == 'C' || s[i] == 'E') value = (int) 'z'; if (value == 0) { x += reps; } else { while (reps-- > 0) { resizeIfNeeded(cells, n+1); cells->cellList[n].position = pack(x++, y); cells->cellList[n++].value = value; } } } reps = 0; } } cells->ncells=n; resizeIfNeeded(cells, n+1); }
status_t CameraMetadata::append(const camera_metadata_t* other) { if (mLocked) { ALOGE("%s: CameraMetadata is locked", __FUNCTION__); return INVALID_OPERATION; } size_t extraEntries = get_camera_metadata_entry_count(other); size_t extraData = get_camera_metadata_data_count(other); resizeIfNeeded(extraEntries, extraData); return append_camera_metadata(mBuffer, other); }
void ofxThreadedImage::threadedFunction(){ #ifdef TARGET_OSX pthread_setname_np("ofxThreadedImage"); #endif if( lock() ){ switch (whatToDo) { case SAVE: ofSaveImage(getPixelsRef(), fileName, quality); break; case LOAD:{ alpha = 0.0f; //float t1 = ofGetElapsedTimef(); loadImageBlocking(fileName); //ofLog() << "time to load: " << ofGetElapsedTimef() - t1; }break; case LOAD_HTTP: alpha = 0; ofxSimpleHttp http; http.setTimeOut(timeOut); ofxSimpleHttpResponse response = http.fetchURLtoDiskBlocking(url, IMG_DOWNLOAD_FOLDER_NAME); if (response.ok){ setUseTexture(false); bool loaded = loadImage(response.absolutePath); if (loaded){ resizeIfNeeded(); imageLoaded = true; }else{ ofLog(OF_LOG_ERROR, "loadHttpImageBlocking() failed to load from disk (%d) > %s\n", response.status, url.c_str() ); } }else{ ofLog(OF_LOG_ERROR, "loadHttpImageBlocking() failed to download (%d) > %s\n", response.status, url.c_str() ); } break; } unlock(); } else { ofLogError("ofxThreadedImage::threadedFunction Can't %s %s, thread is already running", whatToDo == SAVE ? "Save" : "Load", fileName.c_str() ); } stopThread(); #if defined(TARGET_OSX) || defined(TARGET_LINUX) /*I'm not 100% sure of linux*/ pthread_detach( pthread_self() ); //this is a workaround for this issue https://github.com/openframeworks/openFrameworks/issues/2506 #endif }
int emptyNeighbors(LifeList *cells) { int nnbhd; resizeIfNeeded(cells, cells->ncells*9); nnbhd= sumAllNeighbors(cells->cellList, cells->ncells, cells->neighborhoods); nnbhd= subtractLists(cells->cellList, cells->ncells, cells->neighborhoods, nnbhd); return nnbhd; }
void mergeLifeListsMin(LifeList *cells1, LifeList *cells2, int transl) { /* note: destroys neighborhood values */ copyList(cells2->cellList, cells2->ncells, cells2->neighborhoods, transl); resizeIfNeeded(cells1, cells1->ncells+cells2->ncells); cells1->ncells=combineListsMin(cells1->cellList, cells1->ncells, cells2->neighborhoods, cells2->ncells, cells1->neighborhoods); copyList(cells1->neighborhoods, cells1->ncells, cells1->cellList, 0); }
void ofxThreadedImage::loadImageBlocking(string fileName){ imageLoaded = false; whatToDo = LOAD; problemLoading = false; setUseTexture(false); alpha = 0.0; bool loaded = loadImage(fileName); if (!loaded){ ofLogError() << "ofxThreadedImage:: img couldnt load!" << endl; problemLoading = true; }else{ resizeIfNeeded(); imageLoaded = true; } pendingTexture = true; }
void setupPerturbors(LifeList *perturbs, Cell *placed, int nplaced, LifeList *justPerturbs, LifeList *reaction) { int i; justPerturbs->ncells=0; if (nplaced==0) { resizeIfNeeded(justPerturbs, 1); } else { for (i=0; i<nplaced; i++) { mergeLifeLists(justPerturbs, perturbs+placed[i].value, placed[i].position); } mergeLifeLists(reaction, justPerturbs, 0); } }
status_t CameraMetadata::updateImpl(uint32_t tag, const void *data, size_t data_count) { status_t res; if (mLocked) { ALOGE("%s: CameraMetadata is locked", __FUNCTION__); return INVALID_OPERATION; } int type = get_camera_metadata_tag_type(tag); if (type == -1) { ALOGE("%s: Tag %d not found", __FUNCTION__, tag); return BAD_VALUE; } size_t data_size = calculate_camera_metadata_entry_data_size(type, data_count); res = resizeIfNeeded(1, data_size); if (res == OK) { camera_metadata_entry_t entry; res = find_camera_metadata_entry(mBuffer, tag, &entry); if (res == NAME_NOT_FOUND) { res = add_camera_metadata_entry(mBuffer, tag, data, data_count); } else if (res == OK) { res = update_camera_metadata_entry(mBuffer, entry.index, data, data_count, NULL); } } if (res != OK) { ALOGE("%s: Unable to update metadata entry %s.%s (%x): %s (%d)", __FUNCTION__, get_camera_metadata_section_name(tag), get_camera_metadata_tag_name(tag), tag, strerror(-res), res); } IF_ALOGV() { ALOGE_IF(validate_camera_metadata_structure(mBuffer, /*size*/NULL) != OK, "%s: Failed to validate metadata structure after update %p", __FUNCTION__, mBuffer); } return res; }
int getClusterDesc(LifeList *cells, LifeList *working1, LifeList *working2, int ngens, LifeList *clusters, ClusterDesc *clusterInfo) { int i, nClusters; /* Warning: the calling procedure has to allocate space for the cluster information and an initialized array of LifeLists */ nClusters = independentUpTo(cells, working1, working2, ngens); /* First, partition the list into clusters, maintaining the original ordering of cells within clusters */ for (i=0; i<nClusters; i++) clusters[i].ncells=0; for (i=0; i<cells->ncells; i++) { LifeList *thiscluster = &(clusters[cells->cellList[i].value]); resizeIfNeeded(thiscluster, (thiscluster->ncells)++); thiscluster->cellList[thiscluster->ncells-1]=cells->cellList[i]; thiscluster->cellList[thiscluster->ncells-1].value=1; } /* Now collect information about each cluster */ for (i=0; i<nClusters; i++) { int period; clusterInfo[i].osc = simpleOscillation(&(clusters[i]), working1, ngens); period=clusterInfo[i].osc.period; if (period>=1) { cumulativeImage(&(clusters[i]), working1, period); clusterInfo[i].bb = makeBoundingBox(working1->cellList, working1->ncells); } else { clusterInfo[i].bb = makeBoundingBox(clusters[i].cellList, clusters[i].ncells); } } return nClusters; }
void IncrementalPlot::appendData(double *x, double *y, int size) { resizeIfNeeded(x[0], y[0]); if ( d_data == NULL ) d_data = new CurveData; if ( d_curve == NULL ) { d_curve = new QwtPlotCurve("Test Curve"); d_curve->setStyle(QwtPlotCurve::NoCurve); d_curve->setPaintAttribute(QwtPlotCurve::PaintFiltered); const QColor &c = Qt::white; d_curve->setSymbol(QwtSymbol(QwtSymbol::XCross, QBrush(c), QPen(c), QSize(5, 5)) ); d_curve->attach(this); } d_data->append(x, y, size); d_curve->setRawData(d_data->x(), d_data->y(), d_data->count()); #ifdef __GNUC__ #warning better use QwtData #endif const bool cacheMode = canvas()->testPaintAttribute(QwtPlotCanvas::PaintCached); #if QT_VERSION >= 0x040000 && defined(Q_WS_X11) // Even if not recommended by TrollTech, Qt::WA_PaintOutsidePaintEvent // works on X11. This has an tremendous effect on the performance.. canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true); #endif canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false); d_curve->draw(d_curve->dataSize() - size, d_curve->dataSize() - 1); canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, cacheMode); #if QT_VERSION >= 0x040000 && defined(Q_WS_X11) canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, false); #endif }
OscillatorDesc oscillation(LifeList *cells, LifeList *working, int testUpTo) { OscillatorDesc osc; int i; Transformation normT; Transformation oscT; normT= normalize(cells); resizeIfNeeded(working, cells->ncells); working->ncells= copyList(cells->cellList, cells->ncells, working->cellList, 0); setValues(working->cellList, working->ncells, 1); for (i=1; i<=testUpTo; i++) { generate(working); if (cells->ncells==working->ncells) { oscT= normalize(working); if ( !compare(working->cellList, cells->cellList, cells->ncells)) break; transformBack(working->cellList, oscT, working->ncells); } } osc.testedUpTo = testUpTo; if (i > testUpTo) osc.period= -1; else osc.period= i; osc.T= oscT; transformBack(cells->cellList, normT, cells->ncells); return osc; }
void resymmetrise(LifeList *cells) { if (!FLIP_X && !FLIP_Y) return; int i, n = cells->ncells; resizeIfNeeded(cells, 2 * n); for (i = 0; i < n; i++) { int pos = cells->cellList[i].position; if (FLIP_X) pos = flip_x(pos); if (FLIP_Y) pos = flip_y(pos); cells->cellList[i+n].position = pos; cells->cellList[i+n].value = cells->cellList[i].value; } cells->ncells = 2 * n; makeRowMajor(cells); }
bool Engine::renderFrame(bool allocateIfNeeded) { if (!mEgl.isReadyToRender(allocateIfNeeded)) return false; if (!initUI()) { LOGW("Could not initialize UI - assets may be missing!"); ANativeActivity_finish(mApp->activity); return false; } resizeIfNeeded(); // set up viewport glViewport((GLint)0, (GLint)0, (GLsizei)(mEgl.getWidth()), (GLsizei)(mEgl.getHeight())); // clear buffers as necessary glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // do some game rendering here // ... // start rendering bitfont text overlaid here. NVBFTextRenderPrep(); m_ui->Render(); // done rendering overlaid text. NVBFTextRenderDone(); if (mForceRender > 0) mForceRender--; mEgl.swap(); return true; }
void readCellsColor(LifeList *cells, char *patname, int color) { int n,pos,x,y,col; FILE *patfile; int curx, cury, lastx; int spacex, spacey; char *last_dot = strrchr(patname, '.'); if (last_dot && !strcmp(last_dot, ".rle")) { readCellsColorRLE(cells, patname, color); return; } curx=0; cury=0; spacex=0; spacey=0; if (!(patfile=fopen(patname, "r"))) { cells->ncells= 0; return; } n=cells->ncells; while (fgets(s, 8191, patfile)) { int patlen; patlen=strspn(s, ".*abcdefghijklmnopqrstuvwyxz!"); if (patlen>1 && s[patlen-1]=='!') { curx=spacex; cury=spacey; lastx=0; for (x=0; x<patlen; x++) { if (s[x]=='*' || (s[x]>='a' && s[x]<='z')) { pos=pack(curx+x-lastx, cury); resizeIfNeeded(cells, n+1); cells->cellList[n].position=pos; cells->cellList[n++].value= (s[x]=='*') ? color : (int)s[x]; } else if (s[x]=='!') { lastx=x+1; cury++; } } spacex+=SPACE; if (spacex>=MAXCOL) { spacex=0; spacey+=SPACE; } } else if (s[0]=='#') { if (sscanf(s+2, "%d%d", &x, &y)==2) { curx=x; cury=y; } } else if (strspn(s,".*abcdefghijklmnopqrstuvwxyz")>0) { for (x=0; s[x]!='\0'; x++) { if (s[x]=='*' || (s[x]>='a' && s[x]<='z')) { pos=pack(curx+x, cury); resizeIfNeeded(cells, n+1); cells->cellList[n].position=pos; cells->cellList[n++].value= (s[x]=='*') ? color : (int)s[x]; } } cury++; } else { col= -1; if (sscanf(s, "%d%d%d",&x, &y, &col)>=2) {; pos=pack(x,y); resizeIfNeeded(cells, n+1); cells->cellList[n].position=pos; if (col == -1) cells->cellList[n++].value= color; else cells->cellList[n++].value= spreadColor[col]; } } } cells->ncells=n; resizeIfNeeded(cells, n+1); makeRowMajor(cells); fclose(patfile); }
bool Engine::renderFrame(bool allocateIfNeeded) { if (!mEgl.isReadyToRender(allocateIfNeeded)) return false; if (!initUI()) { LOGW("Could not initialize UI - assets may be missing!"); ANativeActivity_finish(mApp->activity); return false; } // We've gotten this far, so EGL is ready for us. Have we loaded our assets? // Note that we cannot use APP_STATUS_GLES_LOADED to imply that EGL is // ready to render. We can have a valid context with all GLES resources loaded // into it but no surface and thus the context not bound. These are semi- // independent states. if (!mGlobeApp) { if (!allocateIfNeeded) return false; mGlobeApp = new GlobeApp; } if (!mGlobeApp->isInitialized()) { if (!allocateIfNeeded) return false; // If we are initializing and we have a new, known size, set that // before the init resizeIfNeeded(); if (!mGlobeApp->init()) return false; } resizeIfNeeded(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); mGlobeApp->render((float)mTimeVal); if (m_clockText) { NVBFTextRenderPrep(); NVBFTextRender(m_clockText); NVBFTextRenderDone(); int mins = mTimeVal / 60; float secs = (float)mTimeVal - mins*60; char str[32]; sprintf(str, "%03d:%05.2f", mins, secs); NVBFTextSetString(m_clockText, str); } // Render UI if needed if (m_uiModeTextures[mCurrentMode]) { int w = mEgl.getWidth(); int h = mEgl.getHeight(); mUIHalfSize = 300; mUICenterX = w/2; mUICenterY = h/2; NvDrawRect::setScreenResolution(w, h); static const float s_white[4] = {1.0f, 1.0f, 1.0f, 0.7f}; glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); mDrawRect->draw(m_uiModeTextures[mCurrentMode], mUICenterX - mUIHalfSize, mUICenterY - mUIHalfSize, mUICenterX + mUIHalfSize, mUICenterY + mUIHalfSize, s_white); glDisable(GL_BLEND); } if (mForceRender > 0) mForceRender--; mEgl.swap(); // A debug printout every 256 frames so we can see when we're // actively rendering and swapping if (!(mSwapCount++ & 0x00ff)) { DEBUG("Swap count is %d", mSwapCount); } return true; }