int main(int argc, char **argv) { char filename[BUF_SIZE]; char *dirin, *rootname, *fname; l_int32 i, firstpage, npages, nfiles; l_float32 thresh, weight; JBDATA *data; JBCLASSER *classer; SARRAY *safiles; PIX *pix, *pixt; PIXA *pixa, *pixadb; static char mainName[] = "jbcorrelation"; if (argc != 5 && argc != 7) return ERROR_INT(" Syntax: jbcorrelation dirin thresh weight " "rootname [firstpage, npages]", mainName, 1); dirin = argv[1]; thresh = atof(argv[2]); weight = atof(argv[3]); rootname = argv[4]; if (argc == 5) { firstpage = 0; npages = 0; } else { firstpage = atoi(argv[5]); npages = atoi(argv[6]); } #if 0 /*--------------------------------------------------------------*/ jbCorrelation(dirin, thresh, weight, COMPONENTS, rootname, firstpage, npages, 1); /*--------------------------------------------------------------*/ #else /*--------------------------------------------------------------*/ safiles = getSortedPathnamesInDirectory(dirin, NULL, firstpage, npages); nfiles = sarrayGetCount(safiles); sarrayWriteStream(stderr, safiles); /* Classify components on requested pages */ startTimer(); classer = jbCorrelationInit(COMPONENTS, 0, 0, thresh, weight); jbAddPages(classer, safiles); fprintf(stderr, "Time to generate classes: %6.3f sec\n", stopTimer()); /* Save and write out the result */ data = jbDataSave(classer); jbDataWrite(rootname, data); fprintf(stderr, "Number of classes: %d\n", classer->nclass); /* Render the pages from the classifier data. * Use debugflag == FALSE to omit outlines of each component. */ pixa = jbDataRender(data, FALSE); /* Write the pages out */ npages = pixaGetCount(pixa); if (npages != nfiles) fprintf(stderr, "npages = %d, nfiles = %d, not equal!\n", npages, nfiles); for (i = 0; i < npages; i++) { pix = pixaGetPix(pixa, i, L_CLONE); snprintf(filename, BUF_SIZE, "%s.%05d", rootname, i); fprintf(stderr, "filename: %s\n", filename); pixWrite(filename, pix, IFF_PNG); pixDestroy(&pix); } #if DISPLAY_DIFFERENCE fname = sarrayGetString(safiles, 0, 0); pixt = pixRead(fname); pix = pixaGetPix(pixa, 0, L_CLONE); pixXor(pixt, pixt, pix); pixWrite("junk_output_diff", pixt, IFF_PNG); pixDestroy(&pix); pixDestroy(&pixt); #endif /* DISPLAY_DIFFERENCE */ #if DEBUG_TEST_DATA_IO { JBDATA *newdata; PIX *newpix; PIXA *newpixa; l_int32 same, iofail; /* Read the data back in and render the pages */ newdata = jbDataRead(rootname); newpixa = jbDataRender(newdata, FALSE); iofail = FALSE; for (i = 0; i < npages; i++) { pix = pixaGetPix(pixa, i, L_CLONE); newpix = pixaGetPix(newpixa, i, L_CLONE); pixEqual(pix, newpix, &same); if (!same) { iofail = TRUE; fprintf(stderr, "pix on page %d are unequal!\n", i); } pixDestroy(&pix); pixDestroy(&newpix); } if (iofail) fprintf(stderr, "read/write for jbdata fails\n"); else fprintf(stderr, "read/write for jbdata succeeds\n"); jbDataDestroy(&newdata); pixaDestroy(&newpixa); } #endif /* DEBUG_TEST_DATA_IO */ #if RENDER_DEBUG /* Use debugflag == TRUE to see outlines of each component. */ pixadb = jbDataRender(data, TRUE); /* Write the debug pages out */ npages = pixaGetCount(pixadb); for (i = 0; i < npages; i++) { pix = pixaGetPix(pixadb, i, L_CLONE); snprintf(filename, BUF_SIZE, "%s.db.%05d", rootname, i); fprintf(stderr, "filename: %s\n", filename); pixWrite(filename, pix, IFF_PNG); pixDestroy(&pix); } pixaDestroy(&pixadb); #endif /* RENDER_DEBUG */ #if DISPLAY_ALL_INSTANCES /* display all instances, organized by template */ pix = pixaaDisplayByPixa(classer->pixaa, X_SPACING, Y_SPACING, MAX_OUTPUT_WIDTH); pixWrite("output_instances", pix, IFF_PNG); pixDestroy(&pix); #endif /* DISPLAY_ALL_INSTANCES */ pixaDestroy(&pixa); sarrayDestroy(&safiles); jbClasserDestroy(&classer); jbDataDestroy(&data); /*--------------------------------------------------------------*/ #endif return 0; }
void stopLaserBeacon() { // Shutdown timer Timer* beaconTimer = getTimerByCode(BEACON_TIMER_CODE); stopTimer(beaconTimer); }
void PluginListComponent::timerCallback() { stopTimer(); scanFor (AudioPluginFormatManager::getInstance()->getFormat (typeToScan)); }
int main(int argc, char **argv) { l_int32 i; BOXA *boxa; NUMA *nas, *nab; PIX *pixs; PIXA *pixa, *pixas; /* ----------------- Custom with a few large pix -----------------*/ /* Set up pms */ nas = numaCreate(4); /* small */ numaAddNumber(nas, 5); numaAddNumber(nas, 4); numaAddNumber(nas, 3); numaAddNumber(nas, 2); setPixMemoryManager(pmsCustomAlloc, pmsCustomDealloc); pmsCreate(200000, 400000, nas, "/tmp/junk1.log"); /* Make the pix and do successive copies and removals of the copies */ pixas = GenerateSetOfMargePix(); startTimer(); for (i = 0; i < ntimes; i++) CopyStoreClean(pixas, nlevels, ncopies); fprintf(stderr, "Time (big pix; custom) = %7.3f sec\n", stopTimer()); /* Clean up */ numaDestroy(&nas); pixaDestroy(&pixas); pmsDestroy(); /* ----------------- Standard with a few large pix -----------------*/ setPixMemoryManager(malloc, free); /* Make the pix and do successive copies and removals of the copies */ startTimer(); pixas = GenerateSetOfMargePix(); for (i = 0; i < ntimes; i++) CopyStoreClean(pixas, nlevels, ncopies); fprintf(stderr, "Time (big pix; standard) = %7.3f sec\n", stopTimer()); pixaDestroy(&pixas); /* ----------------- Custom with many small pix -----------------*/ /* Set up pms */ nab = numaCreate(10); numaAddNumber(nab, 2000); numaAddNumber(nab, 2000); numaAddNumber(nab, 2000); numaAddNumber(nab, 500); numaAddNumber(nab, 100); numaAddNumber(nab, 100); numaAddNumber(nab, 100); setPixMemoryManager(pmsCustomAlloc, pmsCustomDealloc); if (logging) /* use logging == 0 for speed comparison */ pmsCreate(20, 40, nab, "/tmp/junk2.log"); else pmsCreate(20, 40, nab, NULL); pixs = pixRead("feyn.tif"); startTimer(); for (i = 0; i < 5; i++) { boxa = pixConnComp(pixs, &pixa, 8); boxaDestroy(&boxa); pixaDestroy(&pixa); } numaDestroy(&nab); pixDestroy(&pixs); pmsDestroy(); fprintf(stderr, "Time (custom) = %7.3f sec\n", stopTimer()); /* ----------------- Standard with many small pix -----------------*/ setPixMemoryManager(malloc, free); pixs = pixRead("feyn.tif"); startTimer(); for (i = 0; i < 5; i++) { boxa = pixConnComp(pixs, &pixa, 8); boxaDestroy(&boxa); pixaDestroy(&pixa); } pixDestroy(&pixs); fprintf(stderr, "Time (standard) = %7.3f sec\n", stopTimer()); return 0; }
Win32AudioCDStream::~Win32AudioCDStream() { stopTimer(); }
/* Launches n worker threads incrementing under the authority of given lock */ double parallel_work(int work, int n, int type) { int i; StopWatch_t watch; if (work % n != 0) { fprintf(stderr, "Error: work is not divisible by number of worker threads."); exit(1); } // Lock args volatile long counter = 0; // TAS args volatile int state; // MUTEX args pthread_mutex_t m; // Initialize alock volatile int anders[n*4]; volatile long tail; volatile long head; volatile alock_t alock; // Initialize CLH tail volatile node_t *p; thr_data_t data[n]; pthread_t workers[n]; volatile lock_t lock; // Or for clh volatile lock_t c_locks[n]; // Initialize using switch over type switch (type) { case TAS: state = 0; lock.tas = &state; for (i = 0; i < n; i++) { data[i].lock_f = &tas_lock; data[i].unlock_f = &tas_unlock; data[i].locks = &lock; } break; case BACK: state = 0; lock.tas = &state; for (i = 0; i < n; i++) { data[i].lock_f = &backoff_lock; data[i].unlock_f = &backoff_unlock; data[i].locks = &lock; } break; case MUTEX: pthread_mutex_init(&m, NULL); lock.m = &m; for (i = 0; i < n; i++) { data[i].lock_f = &mutex_lock; data[i].unlock_f = &mutex_unlock; data[i].locks = &lock; } break; case ALOCK: tail = 0; alock.tail = &tail; alock.head = &head; alock.max = n*4; alock.array = anders; for (i = 0; i < n; i++) { anders[i*4] = 0; data[i].lock_f = &anders_lock; data[i].unlock_f = &anders_unlock; data[i].locks = &lock; } anders[0] = 1; lock.a = alock; break; case CLH: p = new_clh_node(); p->locked = 0; for (i = 0; i < n; i++) { data[i].lock_f = &clh_lock; data[i].unlock_f = &clh_unlock; data[i].locks = c_locks+i; c_locks[i].clh.me = new_clh_node(); c_locks[i].clh.tail = &p; } } for (i=0; i<n; i++) { data[i].counter = &counter; data[i].my_count = work/n; } // Start timing startTimer(&watch); counter = 0; // spawn worker spawn_work(type, n, workers, data); // Kill worker for (i = 0; i < n; i++) { pthread_join(workers[i], NULL); } // Stop timing stopTimer(&watch); // print counter //printf("Counter = %i\n", counter); // print thread counters int sum = 0; for (i = 0; i < n; i++) { //printf("%i : %i \n", i, data[i].my_count); sum += data[i].my_count; } // print time //printf("%f\n",getElapsedTime(&watch)); if (work - counter - sum) { return 0; } return getElapsedTime(&watch); }
void UGenPlugin::timerCallback() { stopTimer(); processEnvs(); }
void Ipc::timerEvent(QTimerEvent *event) { QByteArray data; Message *msg; enum Cmd cmd; enum Result result; (void) event; if ((m_mode == ModeManager) && (m_cmdSent.msecsTo(QTime::currentTime()) > m_timeout)) // Проверка таймаута { stopTimer(); if (m_resultConnected.contains(ResultTimedOut)) emit timedOut(m_sentCmd); else { std::cout << "Command execution timed out" << std::endl; qApp->quit(); } return; } if (m_shared.lock()) { msg = (Message *)m_shared.constData(); if (msg->dataSize > 0) data.append((const char *)(msg + 1), msg->dataSize); } else return; switch (m_mode) { case ModeApplication: cmd = (enum Cmd)msg->code; if (msg->sender == ModeManager) { #ifdef DEBUG dbg << " i: IPC got command = " << cmd << " [" << data.toHex() << "]"; #endif if (m_cmdConnected.contains(cmd)) { stopTimer(); notify(cmd); } else switch (cmd) { case CmdStatus: if (m_state != StateNone) send(ResultOk, QByteArray(1, m_state), true); else send(ResultNotImplemented, true); break; case CmdStop: send(ResultOk, true); qApp->quit(); break; case CmdPid: send(ResultOk, QByteArray::number(QApplication::applicationPid()), true); break; default: send(ResultNotImplemented, true); } } break; case ModeManager: result = (enum Result)msg->code; if (msg->sender == ModeApplication) { #ifdef DEBUG dbg << " i: IPC got response = " << result << " [" << data.toHex() << "]"; #endif stopTimer(); if (m_resultConnected.contains(result)) notify(result, data); else { switch (result) { case ResultOk: switch (m_sentCmd) { case CmdPid: std::cout << data.data() << std::endl; break; case CmdStop: break; default: std::cout << "Command execution succeeded. Response dump: " << data.toHex().data() << std::endl; break; } break; case ResultNotImplemented: std::cout << "Command not implemented" << std::endl; break; case ResultFail: std::cout << "Error while executing command: " << data.data() << std::endl; break; default:; } qApp->quit(); } } break; } m_shared.unlock(); }
int main(int argc, char **argv) { l_float32 scalefact; L_BMF *bmf, *bmftop; L_KERNEL *kel, *kelx, *kely; PIX *pixs, *pixg, *pixt, *pixd; PIX *pix1, *pix2, *pix3, *pix4, *pix5, *pix6, *pix7, *pix8; PIXA *pixa; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; /* ----------------- Test on 8 bpp grayscale ---------------------*/ pixa = pixaCreate(5); bmf = bmfCreate("./fonts", 6); bmftop = bmfCreate("./fonts", 10); pixs = pixRead("lucasta-47.jpg"); pixg = pixScale(pixs, 0.4, 0.4); /* 8 bpp grayscale */ pix1 = pixConvertTo32(pixg); /* 32 bpp rgb */ AddTextAndSave(pixa, pix1, 1, bmf, textstr[0], L_ADD_BELOW, 0xff000000); pix2 = pixConvertGrayToSubpixelRGB(pixs, 0.4, 0.4, L_SUBPIXEL_ORDER_RGB); AddTextAndSave(pixa, pix2, 0, bmf, textstr[1], L_ADD_BELOW, 0x00ff0000); pix3 = pixConvertGrayToSubpixelRGB(pixs, 0.4, 0.4, L_SUBPIXEL_ORDER_BGR); AddTextAndSave(pixa, pix3, 0, bmf, textstr[2], L_ADD_BELOW, 0x0000ff00); pix4 = pixConvertGrayToSubpixelRGB(pixs, 0.4, 0.4, L_SUBPIXEL_ORDER_VRGB); AddTextAndSave(pixa, pix4, 0, bmf, textstr[3], L_ADD_BELOW, 0x00ff0000); pix5 = pixConvertGrayToSubpixelRGB(pixs, 0.4, 0.4, L_SUBPIXEL_ORDER_VBGR); AddTextAndSave(pixa, pix5, 0, bmf, textstr[4], L_ADD_BELOW, 0x0000ff00); pixt = pixaDisplay(pixa, 0, 0); pixd = pixAddSingleTextblock(pixt, bmftop, "Regression test for subpixel scaling: gray", 0xff00ff00, L_ADD_ABOVE, NULL); regTestWritePixAndCheck(rp, pixd, IFF_JFIF_JPEG); /* 0 */ pixDisplayWithTitle(pixd, 50, 50, NULL, rp->display); pixaDestroy(&pixa); pixDestroy(&pixs); pixDestroy(&pixg); pixDestroy(&pixt); pixDestroy(&pixd); pixDestroy(&pix1); pixDestroy(&pix2); pixDestroy(&pix3); pixDestroy(&pix4); pixDestroy(&pix5); /* ----------------- Test on 32 bpp rgb ---------------------*/ pixa = pixaCreate(5); pixs = pixRead("fish24.jpg"); pix1 = pixScale(pixs, 0.4, 0.4); AddTextAndSave(pixa, pix1, 1, bmf, textstr[0], L_ADD_BELOW, 0xff000000); pix2 = pixConvertToSubpixelRGB(pixs, 0.4, 0.4, L_SUBPIXEL_ORDER_RGB); AddTextAndSave(pixa, pix2, 0, bmf, textstr[1], L_ADD_BELOW, 0x00ff0000); pix3 = pixConvertToSubpixelRGB(pixs, 0.4, 0.35, L_SUBPIXEL_ORDER_BGR); AddTextAndSave(pixa, pix3, 0, bmf, textstr[2], L_ADD_BELOW, 0x0000ff00); pix4 = pixConvertToSubpixelRGB(pixs, 0.4, 0.45, L_SUBPIXEL_ORDER_VRGB); AddTextAndSave(pixa, pix4, 0, bmf, textstr[3], L_ADD_BELOW, 0x00ff0000); pix5 = pixConvertToSubpixelRGB(pixs, 0.4, 0.4, L_SUBPIXEL_ORDER_VBGR); AddTextAndSave(pixa, pix5, 0, bmf, textstr[4], L_ADD_BELOW, 0x0000ff00); pixt = pixaDisplay(pixa, 0, 0); pixd = pixAddSingleTextblock(pixt, bmftop, "Regression test for subpixel scaling: color", 0xff00ff00, L_ADD_ABOVE, NULL); regTestWritePixAndCheck(rp, pixd, IFF_JFIF_JPEG); /* 1 */ pixDisplayWithTitle(pixd, 50, 350, NULL, rp->display); pixaDestroy(&pixa); pixDestroy(&pixs); pixDestroy(&pixt); pixDestroy(&pixd); pixDestroy(&pix1); pixDestroy(&pix2); pixDestroy(&pix3); pixDestroy(&pix4); pixDestroy(&pix5); bmfDestroy(&bmf); bmfDestroy(&bmftop); /* --------------- Test on images that are initially 1 bpp ------------*/ /* For these, it is better to apply a lowpass filter before scaling */ /* Normal scaling of 8 bpp grayscale */ scalefact = 800. / 2320.; pixs = pixRead("patent.png"); /* sharp, 300 ppi, 1 bpp image */ pix1 = pixConvertTo8(pixs, FALSE); /* use 8 bpp input */ pix2 = pixScale(pix1, scalefact, scalefact); regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 2 */ /* Subpixel scaling; bad because there is very little aliasing. */ pix3 = pixConvertToSubpixelRGB(pix1, scalefact, scalefact, L_SUBPIXEL_ORDER_RGB); regTestWritePixAndCheck(rp, pix3, IFF_PNG); /* 3 */ /* Get same (bad) result doing subpixel rendering on RGB input */ pix4 = pixConvertTo32(pixs); pix5 = pixConvertToSubpixelRGB(pix4, scalefact, scalefact, L_SUBPIXEL_ORDER_RGB); regTestComparePix(rp, pix3, pix5); /* 4 */ regTestWritePixAndCheck(rp, pix5, IFF_PNG); /* 5 */ /* Now apply a small lowpass filter before scaling. */ makeGaussianKernelSep(2, 2, 1.0, 1.0, &kelx, &kely); startTimer(); pix6 = pixConvolveSep(pix1, kelx, kely, 8, 1); /* normalized */ fprintf(stderr, "Time sep: %7.3f\n", stopTimer()); regTestWritePixAndCheck(rp, pix6, IFF_PNG); /* 6 */ /* Get same lowpass result with non-separated convolution */ kel = makeGaussianKernel(2, 2, 1.0, 1.0); startTimer(); pix7 = pixConvolve(pix1, kel, 8, 1); /* normalized */ fprintf(stderr, "Time non-sep: %7.3f\n", stopTimer()); regTestComparePix(rp, pix6, pix7); /* 7 */ /* Now do the subpixel scaling on this slightly blurred image */ pix8 = pixConvertToSubpixelRGB(pix6, scalefact, scalefact, L_SUBPIXEL_ORDER_RGB); regTestWritePixAndCheck(rp, pix8, IFF_PNG); /* 8 */ kernelDestroy(&kelx); kernelDestroy(&kely); kernelDestroy(&kel); pixDestroy(&pixs); pixDestroy(&pix1); pixDestroy(&pix2); pixDestroy(&pix3); pixDestroy(&pix4); pixDestroy(&pix5); pixDestroy(&pix6); pixDestroy(&pix7); pixDestroy(&pix8); return regTestCleanup(rp); }
//============================================================================== String reopen (const BigInteger& inputChannels, const BigInteger& outputChannels, double newSampleRate, int bufferSizeSamples) { String error; JUCE_COREAUDIOLOG ("CoreAudio reopen"); callbacksAllowed = false; stopTimer(); stop (false); activeInputChans = inputChannels; activeInputChans.setRange (inChanNames.size(), activeInputChans.getHighestBit() + 1 - inChanNames.size(), false); activeOutputChans = outputChannels; activeOutputChans.setRange (outChanNames.size(), activeOutputChans.getHighestBit() + 1 - outChanNames.size(), false); numInputChans = activeInputChans.countNumberOfSetBits(); numOutputChans = activeOutputChans.countNumberOfSetBits(); // set sample rate AudioObjectPropertyAddress pa; pa.mSelector = kAudioDevicePropertyNominalSampleRate; pa.mScope = kAudioObjectPropertyScopeWildcard; pa.mElement = kAudioObjectPropertyElementMaster; Float64 sr = newSampleRate; if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (sr), &sr))) { error = "Couldn't change sample rate"; } else { // change buffer size UInt32 framesPerBuf = (UInt32) bufferSizeSamples; pa.mSelector = kAudioDevicePropertyBufferFrameSize; if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (framesPerBuf), &framesPerBuf))) { error = "Couldn't change buffer size"; } else { // Annoyingly, after changing the rate and buffer size, some devices fail to // correctly report their new settings until some random time in the future, so // after calling updateDetailsFromDevice, we need to manually bodge these values // to make sure we're using the correct numbers.. updateDetailsFromDevice(); sampleRate = newSampleRate; bufferSize = bufferSizeSamples; if (sampleRates.size() == 0) error = "Device has no available sample-rates"; else if (bufferSizes.size() == 0) error = "Device has no available buffer-sizes"; else if (inputDevice != 0) error = inputDevice->reopen (inputChannels, outputChannels, newSampleRate, bufferSizeSamples); } } callbacksAllowed = true; return error; }
int main(int argc, char **argv) { l_int32 i, j; l_float32 f; l_uint32 redval, greenval; PIX *pixs, *pixd, *pix0, *pix1, *pix2; static char mainName[] = "locminmax_reg"; if (argc != 1) return ERROR_INT("syntax: locminmax_reg", mainName, 1); pixs = pixCreate(500, 500, 8); for (i = 0; i < 500; i++) { for (j = 0; j < 500; j++) { f = 128.0 + 26.3 * sin(0.0438 * (l_float32)i); f += 33.4 * cos(0.0712 * (l_float32)i); f += 18.6 * sin(0.0561 * (l_float32)j); f += 23.6 * cos(0.0327 * (l_float32)j); pixSetPixel(pixs, j, i, (l_int32)f); } } pixDisplay(pixs, 0, 0); pixWrite("/tmp/junkpattern.png", pixs, IFF_PNG); startTimer(); /* pixSelectedLocalExtrema(pixs, 1, &pix1, &pix2); */ pixLocalExtrema(pixs, 0, 0, &pix1, &pix2); fprintf(stderr, "Time for extrema: %7.3f\n", stopTimer()); composeRGBPixel(255, 0, 0, &redval); composeRGBPixel(0, 255, 0, &greenval); pixd = pixConvertTo32(pixs); pixPaintThroughMask(pixd, pix2, 0, 0, greenval); pixPaintThroughMask(pixd, pix1, 0, 0, redval); pixDisplay(pixd, 510, 0); pixWrite("/tmp/junkpixd.png", pixd, IFF_PNG); pixDestroy(&pix1); pixDestroy(&pix2); pixDestroy(&pixs); pixDestroy(&pixd); pix0 = pixRead("karen8.jpg"); pixs = pixBlockconv(pix0, 10, 10); pixDisplay(pixs, 0, 400); pixWrite("/tmp/junkconv.png", pixs, IFF_PNG); startTimer(); /* pixSelectedLocalExtrema(pixs, 1, &pix1, &pix2); */ pixLocalExtrema(pixs, 50, 100, &pix1, &pix2); fprintf(stderr, "Time for extrema: %7.3f\n", stopTimer()); composeRGBPixel(255, 0, 0, &redval); composeRGBPixel(0, 255, 0, &greenval); pixd = pixConvertTo32(pixs); pixPaintThroughMask(pixd, pix2, 0, 0, greenval); pixPaintThroughMask(pixd, pix1, 0, 0, redval); pixDisplay(pixd, 350, 400); pixWrite("/tmp/junkpixd2.png", pixd, IFF_PNG); pixDestroy(&pix0); pixDestroy(&pix1); pixDestroy(&pix2); pixDestroy(&pixs); pixDestroy(&pixd); return 0; }
void updateDetailsFromDevice() { stopTimer(); if (deviceID == 0) return; const ScopedLock sl (callbackLock); AudioObjectPropertyAddress pa; pa.mScope = kAudioObjectPropertyScopeWildcard; pa.mElement = kAudioObjectPropertyElementMaster; UInt32 isAlive; UInt32 size = sizeof (isAlive); pa.mSelector = kAudioDevicePropertyDeviceIsAlive; if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &isAlive)) && isAlive == 0) return; Float64 sr; size = sizeof (sr); pa.mSelector = kAudioDevicePropertyNominalSampleRate; if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &sr))) sampleRate = sr; UInt32 framesPerBuf; size = sizeof (framesPerBuf); pa.mSelector = kAudioDevicePropertyBufferFrameSize; if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &framesPerBuf))) { bufferSize = (int) framesPerBuf; allocateTempBuffers(); } bufferSizes.clear(); pa.mSelector = kAudioDevicePropertyBufferFrameSizeRange; if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size))) { HeapBlock <AudioValueRange> ranges; ranges.calloc (size, 1); if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges))) { bufferSizes.add ((int) (ranges[0].mMinimum + 15) & ~15); for (int i = 32; i < 2048; i += 32) { for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;) { if (i >= ranges[j].mMinimum && i <= ranges[j].mMaximum) { bufferSizes.addIfNotAlreadyThere (i); break; } } } if (bufferSize > 0) bufferSizes.addIfNotAlreadyThere (bufferSize); } } if (bufferSizes.size() == 0 && bufferSize > 0) bufferSizes.add (bufferSize); sampleRates.clear(); const double possibleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 }; String rates; pa.mSelector = kAudioDevicePropertyAvailableNominalSampleRates; if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size))) { HeapBlock <AudioValueRange> ranges; ranges.calloc (size, 1); if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges))) { for (int i = 0; i < numElementsInArray (possibleRates); ++i) { bool ok = false; for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;) if (possibleRates[i] >= ranges[j].mMinimum - 2 && possibleRates[i] <= ranges[j].mMaximum + 2) ok = true; if (ok) { sampleRates.add (possibleRates[i]); rates << possibleRates[i] << ' '; } } } } if (sampleRates.size() == 0 && sampleRate > 0) { sampleRates.add (sampleRate); rates << sampleRate; } JUCE_COREAUDIOLOG ("sr: " + rates); inputLatency = 0; outputLatency = 0; UInt32 lat; size = sizeof (lat); pa.mSelector = kAudioDevicePropertyLatency; pa.mScope = kAudioDevicePropertyScopeInput; if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr) inputLatency = (int) lat; pa.mScope = kAudioDevicePropertyScopeOutput; size = sizeof (lat); if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr) outputLatency = (int) lat; JUCE_COREAUDIOLOG ("lat: " + String (inputLatency) + " " + String (outputLatency)); inChanNames.clear(); outChanNames.clear(); inputChannelInfo.calloc ((size_t) numInputChans + 2); numInputChannelInfos = 0; outputChannelInfo.calloc ((size_t) numOutputChans + 2); numOutputChannelInfos = 0; fillInChannelInfo (true); fillInChannelInfo (false); }
main(int argc, char **argv) { char *str; l_int32 i, j, same, ok; l_float32 sum, avediff, rmsdiff; L_KERNEL *kel1, *kel2, *kel3, *kel4, *kelx, *kely; BOX *box; PIX *pix, *pixs, *pixb, *pixg, *pixr, *pixd, *pixp, *pixt; PIX *pixt1, *pixt2, *pixt3; PIXA *pixa; SARRAY *sa; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; pixa = pixaCreate(0); /* Test creating from a string */ kel1 = kernelCreateFromString(5, 5, 2, 2, kdatastr); pixd = kernelDisplayInPix(kel1, 41, 2); pixWrite("/tmp/pixkern.png", pixd, IFF_PNG); regTestCheckFile(rp, "/tmp/pixkern.png"); /* 0 */ pixSaveTiled(pixd, pixa, 1, 1, 20, 8); pixDestroy(&pixd); kernelDestroy(&kel1); /* Test read/write for kernel. Note that both get * compared to the same golden file, which is * overwritten with a copy of /tmp/kern2.kel */ kel1 = kernelCreateFromString(5, 5, 2, 2, kdatastr); kernelWrite("/tmp/kern1.kel", kel1); regTestCheckFile(rp, "/tmp/kern1.kel"); /* 1 */ kel2 = kernelRead("/tmp/kern1.kel"); kernelWrite("/tmp/kern2.kel", kel2); regTestCheckFile(rp, "/tmp/kern2.kel"); /* 2 */ regTestCompareFiles(rp, 1, 2); /* 3 */ kernelDestroy(&kel1); kernelDestroy(&kel2); /* Test creating from a file */ sa = sarrayCreate(0); sarrayAddString(sa, (char *)"# small 3x3 kernel", L_COPY); sarrayAddString(sa, (char *)"3 5", L_COPY); sarrayAddString(sa, (char *)"1 2", L_COPY); sarrayAddString(sa, (char *)"20.5 50 80 50 20", L_COPY); sarrayAddString(sa, (char *)"82. 120 180 120 80", L_COPY); sarrayAddString(sa, (char *)"22.1 50 80 50 20", L_COPY); str = sarrayToString(sa, 1); l_binaryWrite("/tmp/kernfile.kel", "w", str, strlen(str)); kel2 = kernelCreateFromFile("/tmp/kernfile.kel"); pixd = kernelDisplayInPix(kel2, 41, 2); pixSaveTiled(pixd, pixa, 1, 1, 20, 0); pixWrite("/tmp/ker1.png", pixd, IFF_PNG); regTestCheckFile(rp, "/tmp/ker1.png"); /* 4 */ pixDestroy(&pixd); sarrayDestroy(&sa); lept_free(str); kernelDestroy(&kel2); /* Test creating from a pix */ pixt = pixCreate(5, 3, 8); pixSetPixel(pixt, 0, 0, 20); pixSetPixel(pixt, 1, 0, 50); pixSetPixel(pixt, 2, 0, 80); pixSetPixel(pixt, 3, 0, 50); pixSetPixel(pixt, 4, 0, 20); pixSetPixel(pixt, 0, 1, 80); pixSetPixel(pixt, 1, 1, 120); pixSetPixel(pixt, 2, 1, 180); pixSetPixel(pixt, 3, 1, 120); pixSetPixel(pixt, 4, 1, 80); pixSetPixel(pixt, 0, 0, 20); pixSetPixel(pixt, 1, 2, 50); pixSetPixel(pixt, 2, 2, 80); pixSetPixel(pixt, 3, 2, 50); pixSetPixel(pixt, 4, 2, 20); kel3 = kernelCreateFromPix(pixt, 1, 2); pixd = kernelDisplayInPix(kel3, 41, 2); pixSaveTiled(pixd, pixa, 1, 0, 20, 0); pixWrite("/tmp/ker2.png", pixd, IFF_PNG); regTestCheckFile(rp, "/tmp/ker2.png"); /* 5 */ pixDestroy(&pixd); pixDestroy(&pixt); kernelDestroy(&kel3); /* Test convolution with kel1 */ pixs = pixRead("test24.jpg"); pixg = pixScaleRGBToGrayFast(pixs, 3, COLOR_GREEN); pixSaveTiled(pixg, pixa, 1, 1, 20, 0); kel1 = kernelCreateFromString(5, 5, 2, 2, kdatastr); pixd = pixConvolve(pixg, kel1, 8, 1); pixSaveTiled(pixd, pixa, 1, 0, 20, 0); pixWrite("/tmp/ker3.png", pixd, IFF_PNG); regTestCheckFile(rp, "/tmp/ker3.png"); /* 6 */ pixDestroy(&pixs); pixDestroy(&pixg); pixDestroy(&pixd); kernelDestroy(&kel1); /* Test convolution with flat rectangular kel; also test * block convolution with tiling. */ pixs = pixRead("test24.jpg"); pixg = pixScaleRGBToGrayFast(pixs, 3, COLOR_GREEN); kel2 = makeFlatKernel(11, 11, 5, 5); pixd = pixConvolve(pixg, kel2, 8, 1); pixSaveTiled(pixd, pixa, 1, 1, 20, 0); pixWrite("/tmp/ker4.png", pixd, IFF_PNG); regTestCheckFile(rp, "/tmp/ker4.png"); /* 7 */ pixt = pixBlockconv(pixg, 5, 5); pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixWrite("/tmp/ker5.png", pixt, IFF_PNG); regTestCheckFile(rp, "/tmp/ker5.png"); /* 8 */ if (rp->display) pixCompareGray(pixd, pixt, L_COMPARE_ABS_DIFF, GPLOT_X11, NULL, NULL, NULL, NULL); pixt2 = pixBlockconvTiled(pixg, 5, 5, 3, 6); pixSaveTiled(pixt2, pixa, 1, 0, 20, 0); pixWrite("/tmp/ker5a.png", pixt2, IFF_PNG); regTestCheckFile(rp, "/tmp/ker5a.png"); /* 9 */ pixDestroy(&pixt2); ok = TRUE; for (i = 1; i <= 7; i++) { for (j = 1; j <= 7; j++) { if (i == 1 && j == 1) continue; pixt2 = pixBlockconvTiled(pixg, 5, 5, j, i); pixEqual(pixt2, pixd, &same); if (!same) { fprintf(stderr," Error for nx = %d, ny = %d\n", j, i); ok = FALSE; } pixDestroy(&pixt2); } } if (ok) fprintf(stderr, "OK: Tiled results identical to pixConvolve()\n"); else fprintf(stderr, "ERROR: Tiled results not identical to pixConvolve()\n"); pixDestroy(&pixs); pixDestroy(&pixg); pixDestroy(&pixd); pixDestroy(&pixt); kernelDestroy(&kel2); /* Do another flat rectangular test; this time with white at edge. * About 1% of the pixels near the image edge differ by 1 between * the pixConvolve() and pixBlockconv(). For what it's worth, * pixConvolve() gives the more accurate result; namely, 255 for * pixels at the edge. */ pix = pixRead("pageseg1.tif"); box = boxCreate(100, 100, 2260, 3160); pixb = pixClipRectangle(pix, box, NULL); pixs = pixScaleToGray4(pixb); kel3 = makeFlatKernel(7, 7, 3, 3); startTimer(); pixt = pixConvolve(pixs, kel3, 8, 1); fprintf(stderr, "Generic convolution time: %5.3f sec\n", stopTimer()); pixSaveTiled(pixt, pixa, 1, 1, 20, 0); pixWrite("/tmp/conv1.png", pixt, IFF_PNG); regTestCheckFile(rp, "/tmp/conv1.png"); /* 10 */ startTimer(); pixt2 = pixBlockconv(pixs, 3, 3); fprintf(stderr, "Flat block convolution time: %5.3f sec\n", stopTimer()); pixSaveTiled(pixt2, pixa, 1, 0, 20, 0); pixWrite("/tmp/conv2.png", pixt2, IFF_PNG); /* ditto */ regTestCheckFile(rp, "/tmp/conv2.png"); /* 11 */ pixCompareGray(pixt, pixt2, L_COMPARE_ABS_DIFF, GPLOT_PNG, NULL, &avediff, &rmsdiff, NULL); #ifndef _WIN32 sleep(1); /* give gnuplot time to write out the file */ #else Sleep(1000); #endif /* _WIN32 */ pixp = pixRead("/tmp/grayroot.png"); pixSaveTiled(pixp, pixa, 1, 0, 20, 0); pixWrite("/tmp/conv3.png", pixp, IFF_PNG); regTestCheckFile(rp, "/tmp/conv3.png"); /* 12 */ fprintf(stderr, "Ave diff = %6.4f, RMS diff = %6.4f\n", avediff, rmsdiff); if (avediff <= 0.01) fprintf(stderr, "OK: avediff = %6.4f <= 0.01\n", avediff); else fprintf(stderr, "Bad?: avediff = %6.4f > 0.01\n", avediff); pixDestroy(&pixt); pixDestroy(&pixt2); pixDestroy(&pixs); pixDestroy(&pixp); pixDestroy(&pix); pixDestroy(&pixb); boxDestroy(&box); kernelDestroy(&kel3); /* Do yet another set of flat rectangular tests, this time * on an RGB image */ pixs = pixRead("test24.jpg"); kel4 = makeFlatKernel(7, 7, 3, 3); startTimer(); pixt1 = pixConvolveRGB(pixs, kel4); fprintf(stderr, "Time 7x7 non-separable: %7.3f sec\n", stopTimer()); pixWrite("/tmp/conv4.jpg", pixt1, IFF_JFIF_JPEG); regTestCheckFile(rp, "/tmp/conv4.jpg"); /* 13 */ kelx = makeFlatKernel(1, 7, 0, 3); kely = makeFlatKernel(7, 1, 3, 0); startTimer(); pixt2 = pixConvolveRGBSep(pixs, kelx, kely); fprintf(stderr, "Time 7x1,1x7 separable: %7.3f sec\n", stopTimer()); pixWrite("/tmp/conv5.jpg", pixt2, IFF_JFIF_JPEG); regTestCheckFile(rp, "/tmp/conv5.jpg"); /* 14 */ startTimer(); pixt3 = pixBlockconv(pixs, 3, 3); fprintf(stderr, "Time 7x7 blockconv: %7.3f sec\n", stopTimer()); pixWrite("/tmp/conv6.jpg", pixt3, IFF_JFIF_JPEG); regTestCheckFile(rp, "/tmp/conv6.jpg"); /* 15 */ regTestComparePix(rp, pixt1, pixt2); /* 16 */ regTestCompareSimilarPix(rp, pixt2, pixt3, 15, 0.0005, 0); /* 17 */ pixDestroy(&pixs); pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixt3); kernelDestroy(&kel4); kernelDestroy(&kelx); kernelDestroy(&kely); /* Test generation and convolution with gaussian kernel */ pixs = pixRead("test8.jpg"); pixSaveTiled(pixs, pixa, 1, 1, 20, 0); kel1 = makeGaussianKernel(5, 5, 3.0, 5.0); kernelGetSum(kel1, &sum); fprintf(stderr, "Sum for gaussian kernel = %f\n", sum); kernelWrite("/tmp/gauss.kel", kel1); pixt = pixConvolve(pixs, kel1, 8, 1); pixt2 = pixConvolve(pixs, kel1, 16, 0); pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixSaveTiled(pixt2, pixa, 1, 0, 20, 0); pixWrite("/tmp/ker6.png", pixt, IFF_PNG); regTestCheckFile(rp, "/tmp/ker6.png"); /* 18 */ pixDestroy(&pixt); pixDestroy(&pixt2); pixt = kernelDisplayInPix(kel1, 25, 2); pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixDestroy(&pixt); kernelDestroy(&kel1); pixDestroy(&pixs); /* Test generation and convolution with separable gaussian kernel */ pixs = pixRead("test8.jpg"); pixSaveTiled(pixs, pixa, 1, 1, 20, 0); makeGaussianKernelSep(5, 5, 3.0, 5.0, &kelx, &kely); kernelGetSum(kelx, &sum); fprintf(stderr, "Sum for x gaussian kernel = %f\n", sum); kernelGetSum(kely, &sum); fprintf(stderr, "Sum for y gaussian kernel = %f\n", sum); kernelWrite("/tmp/gauss.kelx", kelx); kernelWrite("/tmp/gauss.kely", kely); pixt = pixConvolveSep(pixs, kelx, kely, 8, 1); pixt2 = pixConvolveSep(pixs, kelx, kely, 16, 0); pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixSaveTiled(pixt2, pixa, 1, 0, 20, 0); pixWrite("/tmp/ker7.png", pixt, IFF_PNG); regTestCheckFile(rp, "/tmp/ker7.png"); /* 19 */ pixDestroy(&pixt); pixDestroy(&pixt2); pixt = kernelDisplayInPix(kelx, 25, 2); pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixDestroy(&pixt); pixt = kernelDisplayInPix(kely, 25, 2); pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixDestroy(&pixt); kernelDestroy(&kelx); kernelDestroy(&kely); pixDestroy(&pixs); /* Test generation and convolution with diff of gaussians kernel */ /* pixt = pixRead("marge.jpg"); pixs = pixConvertRGBToLuminance(pixt); pixDestroy(&pixt); */ pixs = pixRead("test8.jpg"); pixSaveTiled(pixs, pixa, 1, 1, 20, 0); kel1 = makeDoGKernel(7, 7, 1.5, 2.7); kernelGetSum(kel1, &sum); fprintf(stderr, "Sum for DoG kernel = %f\n", sum); kernelWrite("/tmp/dog.kel", kel1); pixt = pixConvolve(pixs, kel1, 8, 0); /* pixInvert(pixt, pixt); */ pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixWrite("/tmp/ker8.png", pixt, IFF_PNG); regTestCheckFile(rp, "/tmp/ker8.png"); /* 20 */ pixDestroy(&pixt); pixt = kernelDisplayInPix(kel1, 20, 2); pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixDestroy(&pixt); kernelDestroy(&kel1); pixDestroy(&pixs); pixd = pixaDisplay(pixa, 0, 0); pixDisplayWithTitle(pixd, 100, 100, NULL, rp->display); pixWrite("/tmp/kernel.jpg", pixd, IFF_JFIF_JPEG); pixDestroy(&pixd); pixaDestroy(&pixa); regTestCleanup(rp); return 0; }
//O(t*(s+d)) void corrigeTexto(TipoTexto *Texto, TipoTexto *Dic, TipoTexto *Stopw, char *NomeArqSaida, bool Analise) { stopWatch cronometro; double tempogasto; char NomeArqAnalise[] = "Analise.txt"; FILE *ArqAnalise = fopen (NomeArqAnalise,"a"); if (Analise) startTimer(&cronometro); int t; int indiceMaisProxStopw, indiceMaisProxDic; int indiceMaisProx = 0; //id da string mais próxima da string do texto no dicionário ou stopwords int DEdic=0, DEstopw=0; //Distância de edição de uma palavra no dicionario e nas stopwords int distEd; //Armazena a distância de edição temporária para evitar recálculo int local = 0; //local onde a palavra foi encontrada STOPW ou DIC int statusMaiuscula=0; int qntcorrecoes=0; int qntEmpates=0; for (t=0; t<Texto->qntPalavras; t++) { //Percorre todas as palavras do texto if (ehConjPont(Texto->Palavra[t].palavra)) //Ignora as strings que tiverem caracter especial, pela definição de inserção na matriz os caracteres especiais estão junto em uma string continue; VerificaMaiuscula(Texto->Palavra[t].palavra, &statusMaiuscula); local = 0; DEdic=INT_MAX; DEstopw=INT_MAX; //Busca nas stopwords e no dicionário, caso encontre a palavra igual nas stowords, não busca no dicionário Texto->Palavra[t].palavra = strtolower(Texto->Palavra[t].palavra); DEstopw = BuscaStopwords(&Texto->Palavra[t], Stopw, &indiceMaisProxStopw); if (DEstopw != 0) { //Não encontrou na lista de stopwords, deve buscar no dicionário também DEdic = BuscaDicionario(&Texto->Palavra[t], Dic, &indiceMaisProxDic, &qntEmpates); } //Define onde foi encontrada a menor distância de edição e qual o Ãndice, onde TipoTexto->palavra[indice].palavra == palavra mais próxima if (DEstopw <= DEdic ) { local = STOPW; indiceMaisProx = indiceMaisProxStopw; distEd = DEstopw; } else { local = DIC; indiceMaisProx = indiceMaisProxDic; distEd = DEdic; } //Corrige a palavra no texto somente se a distância de edição mÃnima for <= 2 if (distEd <= 2) { if (local == STOPW) { Texto->Palavra[t].palavra = Stopw->Palavra[indiceMaisProx].palavra; } else { Texto->Palavra[t].palavra = Dic->Palavra[indiceMaisProx].palavra; Dic->Palavra[indiceMaisProx].freq++; //A palavra do dicionário foi encontrada +1 vez } if (distEd != 0) qntcorrecoes++; //A palavra não estava escrita certa } //Acerta padronização de letras maiúsculas VoltaMaiuscula(Texto->Palavra[t].palavra, statusMaiuscula); } //Para o cronômetro e armazena as informações if (Analise) stopTimer(&cronometro); if (Analise) tempogasto = getElapsedTime(&cronometro); if (Analise) EscreveResultadoAnaliseLaTeX(ArqAnalise, Texto, Dic, Stopw, tempogasto); fclose(ArqAnalise); EscreveResultadosEMetricas(Texto, Dic, NomeArqSaida, qntcorrecoes, qntEmpates); }
MLReporter::ReporterTimer::~ReporterTimer() { stopTimer(); }
int NDBT_TestCase::execute(NDBT_Context* ctx){ int res; ndbout << "- " << name << " started [" << ctx->suite->getDate() << "]" << endl; ctx->setCase(this); // Copy test case properties to ctx Properties::Iterator it(&props); for(const char * key = it.first(); key != 0; key = it.next()){ PropertiesType pt; const bool b = props.getTypeOf(key, &pt); assert(b == true); switch(pt){ case PropertiesType_Uint32:{ Uint32 val; props.get(key, &val); ctx->setProperty(key, val); break; } case PropertiesType_char:{ const char * val; props.get(key, &val); ctx->setProperty(key, val); break; } default: abort(); } } // start timer so that we get a time even if // test case consist only of initializer startTimer(ctx); if ((res = runInit(ctx)) == NDBT_OK){ // If initialiser is ok, run steps res = runSteps(ctx); if (res == NDBT_OK){ // If steps is ok, run verifier res = runVerifier(ctx); } } stopTimer(ctx); printTimer(ctx); // Always run finalizer to clean up db runFinal(ctx); if (res == NDBT_OK) { ndbout << "- " << name << " PASSED [" << ctx->suite->getDate() << "]" << endl; } else { ndbout << "- " << name << " FAILED [" << ctx->suite->getDate() << "]" << endl; } return res; }
void CPetControl::stopPetTimer(uint timerIndex) { if (_timers[timerIndex]._target) { stopTimer(_timers[timerIndex]._id); _timers[timerIndex]._target = nullptr; } }
/// Calculate potential energy and forces for the EAM potential. /// /// Three steps are required: /// /// -# Loop over all atoms and their neighbors, compute the two-body /// interaction and the electron density at each atom /// -# Loop over all atoms, compute the embedding energy and its /// derivative for each atom /// -# Loop over all atoms and their neighbors, compute the embedding /// energy contribution to the force and add to the two-body force /// int eamForce(SimFlat* s) { //OPT: loop invariant references Atoms* atoms = s->atoms; LinkCell* boxes = s->boxes; int nLocalBoxes = boxes->nLocalBoxes; int nTotalBoxes = boxes->nTotalBoxes; int* nAtoms = boxes->nAtoms; real3* atoms_r = atoms->r; real3* atoms_f = atoms->f; real_t* atoms_U = atoms->U; EamPotential* pot = (EamPotential*) s->pot; assert(pot); // set up halo exchange and internal storage on first call to forces. if (pot->forceExchange == NULL) { int maxTotalAtoms = MAXATOMS*s->boxes->nTotalBoxes; pot->dfEmbed = comdMalloc(maxTotalAtoms*sizeof(real_t)); pot->rhobar = comdMalloc(maxTotalAtoms*sizeof(real_t)); pot->forceExchange = initForceHaloExchange(s->domain, s->boxes); pot->forceExchangeData = comdMalloc(sizeof(ForceExchangeData)); pot->forceExchangeData->dfEmbed = pot->dfEmbed; pot->forceExchangeData->boxes = s->boxes; } real_t rCut2 = pot->cutoff*pot->cutoff; // zero forces / energy / rho /rhoprime real_t etot = 0.0; memset(atoms_f, 0, nTotalBoxes*MAXATOMS*sizeof(real3)); memset(atoms_U, 0, nTotalBoxes*MAXATOMS*sizeof(real_t)); memset(pot->dfEmbed, 0, nTotalBoxes*MAXATOMS*sizeof(real_t)); memset(pot->rhobar, 0, nTotalBoxes*MAXATOMS*sizeof(real_t)); int nbrBoxes[27]; // loop over local boxes for (int iBox=0; iBox<nLocalBoxes; iBox++) { int nIBox = nAtoms[iBox]; int nNbrBoxes = getNeighborBoxes(boxes, iBox, nbrBoxes); // loop over neighbor boxes of iBox (some may be halo boxes) for (int jTmp=0; jTmp<nNbrBoxes; jTmp++) { int jBox = nbrBoxes[jTmp]; if (jBox < iBox ) continue; int nJBox = nAtoms[jBox]; // loop over atoms in iBox for (int iOff=MAXATOMS*iBox,ii=0; ii<nIBox; ii++,iOff++) { // loop over atoms in jBox for (int jOff=MAXATOMS*jBox,ij=0; ij<nJBox; ij++,jOff++) { if ( (iBox==jBox) &&(ij <= ii) ) continue; double r2 = 0.0; real3 dr; //OPT: loop unrolling // for (int k=0; k<3; k++) // { // dr[k]=atoms_r[iOff][k]-atoms_r[jOff][k]; // r2+=dr[k]*dr[k]; // } double dr0 = atoms_r[iOff][0]-atoms_r[jOff][0]; r2+=dr0*dr0; double dr1 = atoms_r[iOff][1]-atoms_r[jOff][1]; r2+=dr1*dr1; double dr2 = atoms_r[iOff][2]-atoms_r[jOff][2]; r2+=dr2*dr2; //End of OPT: loop unrolling if(r2>rCut2) continue; double r = sqrt(r2); real_t phiTmp, dPhi, rhoTmp, dRho; interpolate(pot->phi, r, &phiTmp, &dPhi); interpolate(pot->rho, r, &rhoTmp, &dRho); //OPT: loop unrolling // for (int k=0; k<3; k++) // { // atoms_f[iOff][k] -= dPhi*dr[k]/r; // atoms_f[jOff][k] += dPhi*dr[k]/r; // } real_t cal = dPhi*dr0/r; atoms_f[iOff][0] -= cal; atoms_f[jOff][0] += cal; cal = dPhi*dr1/r; atoms_f[iOff][1] -= cal; atoms_f[jOff][1] += cal; cal = dPhi*dr2/r; atoms_f[iOff][2] -= cal; atoms_f[jOff][2] += cal; //End of OPT: loop unrolling // update energy terms // calculate energy contribution based on whether // the neighbor box is local or remote if (jBox < nLocalBoxes) etot += phiTmp; else etot += 0.5*phiTmp; atoms_U[iOff] += 0.5*phiTmp; atoms_U[jOff] += 0.5*phiTmp; // accumulate rhobar for each atom pot->rhobar[iOff] += rhoTmp; pot->rhobar[jOff] += rhoTmp; } // loop over atoms in jBox } // loop over atoms in iBox } // loop over neighbor boxes } // loop over local boxes // Compute Embedding Energy // loop over all local boxes for (int iBox=0; iBox<nLocalBoxes; iBox++) { int iOff; int nIBox = nAtoms[iBox]; // loop over atoms in iBox for (int iOff=MAXATOMS*iBox,ii=0; ii<nIBox; ii++,iOff++) { real_t fEmbed, dfEmbed; interpolate(pot->f, pot->rhobar[iOff], &fEmbed, &dfEmbed); pot->dfEmbed[iOff] = dfEmbed; // save derivative for halo exchange etot += fEmbed; atoms_U[iOff] += fEmbed; } } // exchange derivative of the embedding energy with repsect to rhobar startTimer(eamHaloTimer); haloExchange(pot->forceExchange, pot->forceExchangeData); stopTimer(eamHaloTimer); // third pass // loop over local boxes for (int iBox=0; iBox<nLocalBoxes; iBox++) { int nIBox = nAtoms[iBox]; int nNbrBoxes = getNeighborBoxes(boxes, iBox, nbrBoxes); // loop over neighbor boxes of iBox (some may be halo boxes) for (int jTmp=0; jTmp<nNbrBoxes; jTmp++) { int jBox = nbrBoxes[jTmp]; if(jBox < iBox) continue; int nJBox = nAtoms[jBox]; // loop over atoms in iBox for (int iOff=MAXATOMS*iBox,ii=0; ii<nIBox; ii++,iOff++) { // loop over atoms in jBox for (int jOff=MAXATOMS*jBox,ij=0; ij<nJBox; ij++,jOff++) { if ((iBox==jBox) && (ij <= ii)) continue; double r2 = 0.0; real3 dr; //OPT: loop unrolling // for (int k=0; k<3; k++) // { // dr[k]=atoms_r[iOff][k]-atoms_r[jOff][k]; // r2+=dr[k]*dr[k]; // } real_t dr0 = atoms_r[iOff][0]-atoms_r[jOff][0]; r2 += dr0*dr0; real_t dr1 = atoms_r[iOff][1]-atoms_r[jOff][1]; r2 += dr1*dr1; real_t dr2 = atoms_r[iOff][2]-atoms_r[jOff][2]; r2 += dr2*dr2; //End of OPT: loop unrolling if(r2>=rCut2) continue; real_t r = sqrt(r2); real_t rhoTmp, dRho; interpolate(pot->rho, r, &rhoTmp, &dRho); //OPT: loop unrolling // for (int k=0; k<3; k++) // { // atoms_f[iOff][k] -= (pot->dfEmbed[iOff]+pot->dfEmbed[jOff])*dRho*dr[k]/r; // atoms_f[jOff][k] += (pot->dfEmbed[iOff]+pot->dfEmbed[jOff])*dRho*dr[k]/r; // } real_t cal = (pot->dfEmbed[iOff]+pot->dfEmbed[jOff])*dRho*dr0/r; atoms_f[iOff][0] -= cal; atoms_f[jOff][0] += cal; cal = (pot->dfEmbed[iOff]+pot->dfEmbed[jOff])*dRho*dr1/r; atoms_f[iOff][1] -= cal; atoms_f[jOff][1] += cal; cal = (pot->dfEmbed[iOff]+pot->dfEmbed[jOff])*dRho*dr2/r; atoms_f[iOff][2] -= cal; atoms_f[jOff][2] += cal; //End of OPT: loop unrolling } // loop over atoms in jBox } // loop over atoms in iBox } // loop over neighbor boxes } // loop over local boxes s->ePotential = (real_t) etot; return 0; }
int main(int argc, char **argv) { char buffer[512]; char *tempfile1, *tempfile2; l_uint8 *data; l_int32 i, j, w, h, seq, ret, same; size_t nbytes; const char *title; BOX *box; BOXA *boxa1, *boxa2; L_BYTEA *ba; L_PDF_DATA *lpd; PIX *pix1, *pix2, *pix3, *pix4, *pix5, *pix6; PIX *pixs, *pixt, *pixg, *pixgc, *pixc; static char mainName[] = "pdfiotest"; if (argc != 1) return ERROR_INT("syntax: pdfiotest", mainName, 1); l_pdfSetDateAndVersion(0); lept_mkdir("lept/pdf"); #if 1 /* --------------- Single image tests ------------------- */ fprintf(stderr, "\n*** Writing single images as pdf files\n"); convertToPdf("weasel2.4c.png", L_FLATE_ENCODE, 0, "/tmp/lept/pdf/file01.pdf", 0, 0, 72, "weasel2.4c.png", NULL, 0); convertToPdf("test24.jpg", L_JPEG_ENCODE, 0, "/tmp/lept/pdf/file02.pdf", 0, 0, 72, "test24.jpg", NULL, 0); convertToPdf("feyn.tif", L_G4_ENCODE, 0, "/tmp/lept/pdf/file03.pdf", 0, 0, 300, "feyn.tif", NULL, 0); pixs = pixRead("feyn.tif"); pixConvertToPdf(pixs, L_G4_ENCODE, 0, "/tmp/lept/pdf/file04.pdf", 0, 0, 300, "feyn.tif", NULL, 0); pixDestroy(&pixs); pixs = pixRead("test24.jpg"); pixConvertToPdf(pixs, L_JPEG_ENCODE, 5, "/tmp/lept/pdf/file05.pdf", 0, 0, 72, "test24.jpg", NULL, 0); pixDestroy(&pixs); pixs = pixRead("feyn.tif"); pixt = pixScaleToGray2(pixs); pixWrite("/tmp/lept/pdf/feyn8.png", pixt, IFF_PNG); convertToPdf("/tmp/lept/pdf/feyn8.png", L_JPEG_ENCODE, 0, "/tmp/lept/pdf/file06.pdf", 0, 0, 150, "feyn8.png", NULL, 0); pixDestroy(&pixs); pixDestroy(&pixt); convertToPdf("weasel4.16g.png", L_FLATE_ENCODE, 0, "/tmp/lept/pdf/file07.pdf", 0, 0, 30, "weasel4.16g.png", NULL, 0); pixs = pixRead("test24.jpg"); pixg = pixConvertTo8(pixs, 0); box = boxCreate(100, 100, 100, 100); pixc = pixClipRectangle(pixs, box, NULL); pixgc = pixClipRectangle(pixg, box, NULL); pixWrite("/tmp/lept/pdf/pix32.jpg", pixc, IFF_JFIF_JPEG); pixWrite("/tmp/lept/pdf/pix8.jpg", pixgc, IFF_JFIF_JPEG); convertToPdf("/tmp/lept/pdf/pix32.jpg", L_FLATE_ENCODE, 0, "/tmp/lept/pdf/file08.pdf", 0, 0, 72, "pix32.jpg", NULL, 0); convertToPdf("/tmp/lept/pdf/pix8.jpg", L_FLATE_ENCODE, 0, "/tmp/lept/pdf/file09.pdf", 0, 0, 72, "pix8.jpg", NULL, 0); pixDestroy(&pixs); pixDestroy(&pixg); pixDestroy(&pixc); pixDestroy(&pixgc); boxDestroy(&box); #endif #if 1 /* --------------- Multiple image tests ------------------- */ fprintf(stderr, "\n*** Writing multiple images as single page pdf files\n"); pix1 = pixRead("feyn-fract.tif"); pix2 = pixRead("weasel8.240c.png"); /* l_pdfSetDateAndVersion(0); */ /* First, write the 1 bpp image through the mask onto the weasels */ for (i = 0; i < 5; i++) { for (j = 0; j < 10; j++) { seq = (i == 0 && j == 0) ? L_FIRST_IMAGE : L_NEXT_IMAGE; title = (i == 0 && j == 0) ? "feyn-fract.tif" : NULL; pixConvertToPdf(pix2, L_FLATE_ENCODE, 0, NULL, 100 * j, 100 * i, 70, title, &lpd, seq); } } pixConvertToPdf(pix1, L_G4_ENCODE, 0, "/tmp/lept/pdf/file10.pdf", 0, 0, 80, NULL, &lpd, L_LAST_IMAGE); /* Now, write the 1 bpp image over the weasels */ l_pdfSetG4ImageMask(0); for (i = 0; i < 5; i++) { for (j = 0; j < 10; j++) { seq = (i == 0 && j == 0) ? L_FIRST_IMAGE : L_NEXT_IMAGE; title = (i == 0 && j == 0) ? "feyn-fract.tif" : NULL; pixConvertToPdf(pix2, L_FLATE_ENCODE, 0, NULL, 100 * j, 100 * i, 70, title, &lpd, seq); } } pixConvertToPdf(pix1, L_G4_ENCODE, 0, "/tmp/lept/pdf/file11.pdf", 0, 0, 80, NULL, &lpd, L_LAST_IMAGE); l_pdfSetG4ImageMask(1); pixDestroy(&pix1); pixDestroy(&pix2); #endif #if 1 /* -------- pdf convert segmented with no image regions -------- */ fprintf(stderr, "\n*** Writing segmented images without image regions\n"); pix1 = pixRead("rabi.png"); pix2 = pixScaleToGray2(pix1); pixWrite("/tmp/lept/pdf/rabi8.jpg", pix2, IFF_JFIF_JPEG); pix3 = pixThresholdTo4bpp(pix2, 16, 1); pixWrite("/tmp/lept/pdf/rabi4.png", pix3, IFF_PNG); pixDestroy(&pix1); pixDestroy(&pix2); pixDestroy(&pix3); /* 1 bpp input */ convertToPdfSegmented("rabi.png", 300, L_G4_ENCODE, 128, NULL, 0, 0, NULL, "/tmp/lept/pdf/file12.pdf"); convertToPdfSegmented("rabi.png", 300, L_JPEG_ENCODE, 128, NULL, 0, 0, NULL, "/tmp/lept/pdf/file13.pdf"); convertToPdfSegmented("rabi.png", 300, L_FLATE_ENCODE, 128, NULL, 0, 0, NULL, "/tmp/lept/pdf/file14.pdf"); /* 8 bpp input, no cmap */ convertToPdfSegmented("/tmp/lept/pdf/rabi8.jpg", 150, L_G4_ENCODE, 128, NULL, 0, 0, NULL, "/tmp/lept/pdf/file15.pdf"); convertToPdfSegmented("/tmp/lept/pdf/rabi8.jpg", 150, L_JPEG_ENCODE, 128, NULL, 0, 0, NULL, "/tmp/lept/pdf/file16.pdf"); convertToPdfSegmented("/tmp/lept/pdf/rabi8.jpg", 150, L_FLATE_ENCODE, 128, NULL, 0, 0, NULL, "/tmp/lept/pdf/file17.pdf"); /* 4 bpp input, cmap */ convertToPdfSegmented("/tmp/lept/pdf/rabi4.png", 150, L_G4_ENCODE, 128, NULL, 0, 0, NULL, "/tmp/lept/pdf/file18.pdf"); convertToPdfSegmented("/tmp/lept/pdf/rabi4.png", 150, L_JPEG_ENCODE, 128, NULL, 0, 0, NULL, "/tmp/lept/pdf/file19.pdf"); convertToPdfSegmented("/tmp/lept/pdf/rabi4.png", 150, L_FLATE_ENCODE, 128, NULL, 0, 0, NULL, "/tmp/lept/pdf/file20.pdf"); #endif #if 1 /* ---------- pdf convert segmented with image regions ---------- */ fprintf(stderr, "\n*** Writing segmented images with image regions\n"); /* Get the image region(s) for rabi.png. There are two * small bogus regions at the top, but we'll keep them for * the demonstration. */ pix1 = pixRead("rabi.png"); pixSetResolution(pix1, 300, 300); pixGetDimensions(pix1, &w, &h, NULL); pix2 = pixGenerateHalftoneMask(pix1, NULL, NULL, NULL); pix3 = pixMorphSequence(pix2, "c20.1 + c1.20", 0); boxa1 = pixConnComp(pix3, NULL, 8); boxa2 = boxaTransform(boxa1, 0, 0, 0.5, 0.5); pixDestroy(&pix1); pixDestroy(&pix2); pixDestroy(&pix3); /* 1 bpp input */ convertToPdfSegmented("rabi.png", 300, L_G4_ENCODE, 128, boxa1, 0, 0.25, NULL, "/tmp/lept/pdf/file21.pdf"); convertToPdfSegmented("rabi.png", 300, L_JPEG_ENCODE, 128, boxa1, 0, 0.25, NULL, "/tmp/lept/pdf/file22.pdf"); convertToPdfSegmented("rabi.png", 300, L_FLATE_ENCODE, 128, boxa1, 0, 0.25, NULL, "/tmp/lept/pdf/file23.pdf"); /* 8 bpp input, no cmap */ convertToPdfSegmented("/tmp/lept/pdf/rabi8.jpg", 150, L_G4_ENCODE, 128, boxa2, 0, 0.5, NULL, "/tmp/lept/pdf/file24.pdf"); convertToPdfSegmented("/tmp/lept/pdf/rabi8.jpg", 150, L_JPEG_ENCODE, 128, boxa2, 0, 0.5, NULL, "/tmp/lept/pdf/file25.pdf"); convertToPdfSegmented("/tmp/lept/pdf/rabi8.jpg", 150, L_FLATE_ENCODE, 128, boxa2, 0, 0.5, NULL, "/tmp/lept/pdf/file26.pdf"); /* 4 bpp input, cmap */ convertToPdfSegmented("/tmp/lept/pdf/rabi4.png", 150, L_G4_ENCODE, 128, boxa2, 0, 0.5, NULL, "/tmp/lept/pdf/file27.pdf"); convertToPdfSegmented("/tmp/lept/pdf/rabi4.png", 150, L_JPEG_ENCODE, 128, boxa2, 0, 0.5, NULL, "/tmp/lept/pdf/file28.pdf"); convertToPdfSegmented("/tmp/lept/pdf/rabi4.png", 150, L_FLATE_ENCODE, 128, boxa2, 0, 0.5, NULL, "/tmp/lept/pdf/file29.pdf"); /* 4 bpp input, cmap, data output */ data = NULL; convertToPdfDataSegmented("/tmp/lept/pdf/rabi4.png", 150, L_G4_ENCODE, 128, boxa2, 0, 0.5, NULL, &data, &nbytes); l_binaryWrite("/tmp/lept/pdf/file30.pdf", "w", data, nbytes); lept_free(data); convertToPdfDataSegmented("/tmp/lept/pdf/rabi4.png", 150, L_JPEG_ENCODE, 128, boxa2, 0, 0.5, NULL, &data, &nbytes); l_binaryWrite("/tmp/lept/pdf/file31.pdf", "w", data, nbytes); lept_free(data); convertToPdfDataSegmented("/tmp/lept/pdf/rabi4.png", 150, L_FLATE_ENCODE, 128, boxa2, 0, 0.5, NULL, &data, &nbytes); l_binaryWrite("/tmp/lept/pdf/file32.pdf", "w", data, nbytes); lept_free(data); boxaDestroy(&boxa1); boxaDestroy(&boxa2); #endif #if 1 /* -------- pdf convert segmented from color image -------- */ fprintf(stderr, "\n*** Writing color segmented images\n"); pix1 = pixRead("candelabrum.011.jpg"); pix2 = pixScale(pix1, 3.0, 3.0); pixWrite("/tmp/lept/pdf/candelabrum3.jpg", pix2, IFF_JFIF_JPEG); GetImageMask(pix2, 200, &boxa1, "/tmp/lept/pdf/seg1.jpg"); convertToPdfSegmented("/tmp/lept/pdf/candelabrum3.jpg", 200, L_G4_ENCODE, 100, boxa1, 0, 0.25, NULL, "/tmp/lept/pdf/file33.pdf"); convertToPdfSegmented("/tmp/lept/pdf/candelabrum3.jpg", 200, L_JPEG_ENCODE, 100, boxa1, 0, 0.25, NULL, "/tmp/lept/pdf/file34.pdf"); convertToPdfSegmented("/tmp/lept/pdf/candelabrum3.jpg", 200, L_FLATE_ENCODE, 100, boxa1, 0, 0.25, NULL, "/tmp/lept/pdf/file35.pdf"); pixDestroy(&pix1); pixDestroy(&pix2); boxaDestroy(&boxa1); pix1 = pixRead("lion-page.00016.jpg"); pix2 = pixScale(pix1, 3.0, 3.0); pixWrite("/tmp/lept/pdf/lion16.jpg", pix2, IFF_JFIF_JPEG); pix3 = pixRead("lion-mask.00016.tif"); boxa1 = pixConnComp(pix3, NULL, 8); boxa2 = boxaTransform(boxa1, 0, 0, 3.0, 3.0); convertToPdfSegmented("/tmp/lept/pdf/lion16.jpg", 200, L_G4_ENCODE, 190, boxa2, 0, 0.5, NULL, "/tmp/lept/pdf/file36.pdf"); convertToPdfSegmented("/tmp/lept/pdf/lion16.jpg", 200, L_JPEG_ENCODE, 190, boxa2, 0, 0.5, NULL, "/tmp/lept/pdf/file37.pdf"); convertToPdfSegmented("/tmp/lept/pdf/lion16.jpg", 200, L_FLATE_ENCODE, 190, boxa2, 0, 0.5, NULL, "/tmp/lept/pdf/file38.pdf"); /* Quantize the non-image part and flate encode. * This is useful because it results in a smaller file than * when you flate-encode the un-quantized non-image regions. */ pix4 = pixScale(pix3, 3.0, 3.0); /* higher res mask, for combining */ pix5 = QuantizeNonImageRegion(pix2, pix4, 12); pixWrite("/tmp/lept/pdf/lion16-quant.png", pix5, IFF_PNG); convertToPdfSegmented("/tmp/lept/pdf/lion16-quant.png", 200, L_FLATE_ENCODE, 190, boxa2, 0, 0.5, NULL, "/tmp/lept/pdf/file39.pdf"); pixDestroy(&pix1); pixDestroy(&pix2); pixDestroy(&pix3); pixDestroy(&pix4); pixDestroy(&pix5); boxaDestroy(&boxa1); boxaDestroy(&boxa2); #endif #if 1 /* ------------------ Test multipage pdf generation ----------------- */ fprintf(stderr, "\n*** Writing multipage pdfs from single page pdfs\n"); /* Generate a multi-page pdf from all these files */ startTimer(); concatenatePdf("/tmp/lept/pdf", "file", "/tmp/lept/pdf/cat_lept.pdf"); fprintf(stderr, "All files have been concatenated: /tmp/lept/pdf/cat_lept.pdf\n" "Concatenation time: %7.3f\n", stopTimer()); #endif #if 1 /* ----------- Test corruption recovery by concatenation ------------ */ /* Put two good pdf files in a directory */ lept_rmdir("lept/good"); lept_mkdir("lept/good"); lept_cp("testfile1.pdf", "lept/good", NULL, NULL); lept_cp("testfile2.pdf", "lept/good", NULL, NULL); concatenatePdf("/tmp/lept/good", "file", "/tmp/lept/pdf/good.pdf"); /* Make a bad version with the pdf id removed, so that it is not * recognized as a pdf */ lept_rmdir("lept/bad"); lept_mkdir("lept/bad"); ba = l_byteaInitFromFile("testfile2.pdf"); data = l_byteaGetData(ba, &nbytes); l_binaryWrite("/tmp/lept/bad/testfile0.notpdf.pdf", "w", data + 10, nbytes - 10); /* Make a version with a corrupted trailer */ if (data) data[2297] = '2'; /* munge trailer object 6: change 458 --> 428 */ l_binaryWrite("/tmp/lept/bad/testfile2.bad.pdf", "w", data, nbytes); l_byteaDestroy(&ba); /* Copy testfile1.pdf to the /tmp/lept/bad directory. Then * run concat on the bad files. The "not pdf" file should be * ignored, and the corrupted pdf file should be properly parsed, * so the resulting concatenated pdf files should be identical. */ fprintf(stderr, "\nWe attempt to build from the bad directory\n"); lept_cp("testfile1.pdf", "lept/bad", NULL, NULL); concatenatePdf("/tmp/lept/bad", "file", "/tmp/lept/pdf/bad.pdf"); filesAreIdentical("/tmp/lept/pdf/good.pdf", "/tmp/lept/pdf/bad.pdf", &same); if (same) fprintf(stderr, "Fixed: files are the same\n" "Attempt succeeded\n"); else fprintf(stderr, "Busted: files are different\n"); #endif #if 0 fprintf(stderr, "\n*** pdftk writes multipage pdfs from images\n"); tempfile1 = genPathname("/tmp/lept/pdf", "file*.pdf"); tempfile2 = genPathname("/tmp/lept/pdf", "cat_pdftk.pdf"); snprintf(buffer, sizeof(buffer), "pdftk %s output %s", tempfile1, tempfile2); ret = system(buffer); /* pdftk */ lept_free(tempfile1); lept_free(tempfile2); #endif #if 1 /* -- Test simple interface for generating multi-page pdf from images -- */ fprintf(stderr, "\n*** Writing multipage pdfs from images\n"); /* Put four image files in a directory. They will be encoded thus: * file1.png: flate (8 bpp, only 10 colors) * file2.jpg: dct (8 bpp, 256 colors because of the jpeg encoding) * file3.tif: g4 (1 bpp) * file4.jpg: dct (32 bpp) */ lept_mkdir("lept/image"); pix1 = pixRead("feyn.tif"); pix2 = pixRead("rabi.png"); pix3 = pixScaleToGray3(pix1); pix4 = pixScaleToGray3(pix2); pix5 = pixScale(pix1, 0.33, 0.33); pix6 = pixRead("test24.jpg"); pixWrite("/tmp/lept/image/file1.png", pix3, IFF_PNG); /* 10 colors */ pixWrite("/tmp/lept/image/file2.jpg", pix4, IFF_JFIF_JPEG); /* 256 colors */ pixWrite("/tmp/lept/image/file3.tif", pix5, IFF_TIFF_G4); pixWrite("/tmp/lept/image/file4.jpg", pix6, IFF_JFIF_JPEG); startTimer(); convertFilesToPdf("/tmp/lept/image", "file", 100, 0.8, 0, 75, "4 file test", "/tmp/lept/pdf/fourimages.pdf"); fprintf(stderr, "4-page pdf generated: /tmp/lept/pdf/fourimages.pdf\n" "Time: %7.3f\n", stopTimer()); pixDestroy(&pix1); pixDestroy(&pix2); pixDestroy(&pix3); pixDestroy(&pix4); pixDestroy(&pix5); pixDestroy(&pix6); #endif return 0; }
/* morph composite with morph non-composite */ l_int32 DoComparisonDwa1(PIX *pixs, PIX *pixt1, PIX *pixt2, PIX *pixt3, PIX *pixt4, PIX *pixt5, PIX *pixt6, l_int32 isize) { l_int32 fact1, fact2, size; selectComposableSizes(isize, &fact1, &fact2); size = fact1 * fact2; fprintf(stderr, "..%d..", size); if (TIMING) startTimer(); pixDilateCompBrick(pixt1, pixs, size, 1); pixDilateCompBrick(pixt3, pixs, 1, size); pixDilateCompBrick(pixt5, pixs, size, size); if (TIMING) fprintf(stderr, "Time Dwa: %7.3f sec\n", stopTimer()); if (TIMING) startTimer(); pixDilateBrick(pixt2, pixs, size, 1); pixDilateBrick(pixt4, pixs, 1, size); pixDilateBrick(pixt6, pixs, size, size); if (TIMING) fprintf(stderr, "Time Rop: %7.3f sec\n", stopTimer()); PixCompareDwa(size, "dilate", pixt1, pixt2, pixt3, pixt4, pixt5, pixt6); if (TIMING) startTimer(); pixErodeCompBrick(pixt1, pixs, size, 1); pixErodeCompBrick(pixt3, pixs, 1, size); pixErodeCompBrick(pixt5, pixs, size, size); if (TIMING) fprintf(stderr, "Time Dwa: %7.3f sec\n", stopTimer()); if (TIMING) startTimer(); pixErodeBrick(pixt2, pixs, size, 1); pixErodeBrick(pixt4, pixs, 1, size); pixErodeBrick(pixt6, pixs, size, size); if (TIMING) fprintf(stderr, "Time Rop: %7.3f sec\n", stopTimer()); PixCompareDwa(size, "erode", pixt1, pixt2, pixt3, pixt4, pixt5, pixt6); if (TIMING) startTimer(); pixOpenCompBrick(pixt1, pixs, size, 1); pixOpenCompBrick(pixt3, pixs, 1, size); pixOpenCompBrick(pixt5, pixs, size, size); if (TIMING) fprintf(stderr, "Time Dwa: %7.3f sec\n", stopTimer()); if (TIMING) startTimer(); pixOpenBrick(pixt2, pixs, size, 1); pixOpenBrick(pixt4, pixs, 1, size); pixOpenBrick(pixt6, pixs, size, size); if (TIMING) fprintf(stderr, "Time Rop: %7.3f sec\n", stopTimer()); PixCompareDwa(size, "open", pixt1, pixt2, pixt3, pixt4, pixt5, pixt6); #if 1 pixWrite("/tmp/junko1.png", pixt1, IFF_PNG); pixWrite("/tmp/junko2.png", pixt2, IFF_PNG); pixXor(pixt1, pixt1, pixt2); pixWrite("/tmp/junkoxor.png", pixt1, IFF_PNG); #endif #if 0 pixDisplay(pixt1, 100, 100); pixDisplay(pixt2, 800, 100); pixWrite("/tmp/junkpixt1.png", pixt1, IFF_PNG); pixWrite("/tmp/junkpixt2.png", pixt2, IFF_PNG); #endif if (TIMING) startTimer(); pixCloseSafeCompBrick(pixt1, pixs, size, 1); pixCloseSafeCompBrick(pixt3, pixs, 1, size); pixCloseSafeCompBrick(pixt5, pixs, size, size); if (TIMING) fprintf(stderr, "Time Dwa: %7.3f sec\n", stopTimer()); if (TIMING) startTimer(); pixCloseSafeBrick(pixt2, pixs, size, 1); pixCloseSafeBrick(pixt4, pixs, 1, size); pixCloseSafeBrick(pixt6, pixs, size, size); if (TIMING) fprintf(stderr, "Time Rop: %7.3f sec\n", stopTimer()); PixCompareDwa(size, "close", pixt1, pixt2, pixt3, pixt4, pixt5, pixt6); #if 1 pixWrite("/tmp/junkc1.png", pixt1, IFF_PNG); pixWrite("/tmp/junkc2.png", pixt2, IFF_PNG); pixXor(pixt1, pixt1, pixt2); pixWrite("/tmp/junkcxor.png", pixt1, IFF_PNG); #endif return 0; }
double parallel_dispatcher #else long parallel_dispatcher #endif (int n_packets, int n_src, int q_depth, long mean, int seed, #ifdef TESTING int n_lazy, #endif int distr) { // This array holds packets so we can free them in the end. Shouldn't be too big... // also we're putting packet memory management outside the timing for all three. Packet_t **rcvd_packets = malloc (n_packets * n_src * sizeof(Packet_t *)); PacketSource_t *source = createPacketSource (mean, n_src, seed); StopWatch_t watch; startTimer(&watch); struct l_queue *queues = create_queues (n_src, q_depth); int n_workers_done = 0; int packet_ctr = 0; long total_fp_sum = 0; pthread_t *workers = calloc (n_src, sizeof(pthread_t)); struct thread_data *worker_data = calloc (n_src, sizeof(struct thread_data)); for (int i = 0; i < n_src; i++) { worker_data[i].q = queues + i; #ifdef TESTING if (i >= n_lazy) worker_data[i].do_work = true; #endif pthread_create (workers + i, NULL, worker_fn, (void *) (worker_data + i)); } Packet_t *(*pkt_fn)(PacketSource_t *, int) = distr ? &getUniformPacket : &getExponentialPacket; while (n_workers_done < n_src) { for (int i = 0; i < n_src; i++) { int n_enqs = get_n_enqueues(queues + i); if (n_enqs == n_packets + 1) continue; if (!check_free(queues + i)) continue; if (n_enqs == n_packets) { enq(queues + i, NULL); } else { Packet_t *pkt = pkt_fn (source, i); enq (queues + i, (void *) pkt); rcvd_packets[packet_ctr] = pkt; packet_ctr += 1; } if (get_n_enqueues(queues + i) == n_packets + 1) n_workers_done += 1; } #ifdef TESTING if (n_workers_done == n_src - n_lazy) break; #endif } for (int i = 0; i < n_src; i++) { long this_fp = 0; pthread_join (workers[i], (void **) &this_fp); total_fp_sum += this_fp; #ifdef TESTING printf("%d\n", get_n_enqueues(queues + i) - 1); #endif } free (worker_data); destroy_queues (n_src, queues); stopTimer(&watch); deletePacketSource (source); // Free all the packets... for (int i = 0; i < packet_ctr; i++) free (rcvd_packets[i]); free (rcvd_packets); #ifdef PERF return getElapsedTime(&watch); #else return total_fp_sum; #endif }
/* dwa composite with morph non-composite */ l_int32 DoComparisonDwa5(PIX *pixs, PIX *pixt1, PIX *pixt2, PIX *pixt3, PIX *pixt4, PIX *pixt5, PIX *pixt6, l_int32 isize) { l_int32 fact1, fact2, size; selectComposableSizes(isize, &fact1, &fact2); size = fact1 * fact2; fprintf(stderr, "..%d..", size); if (TIMING) startTimer(); pixDilateCompBrickDwa(pixt1, pixs, size, 1); pixDilateCompBrickDwa(pixt3, pixs, 1, size); pixDilateCompBrickDwa(pixt5, pixs, size, size); if (TIMING) fprintf(stderr, "Time Dwa: %7.3f sec\n", stopTimer()); if (TIMING) startTimer(); pixDilateBrick(pixt2, pixs, size, 1); pixDilateBrick(pixt4, pixs, 1, size); pixDilateBrick(pixt6, pixs, size, size); if (TIMING) fprintf(stderr, "Time Rop: %7.3f sec\n", stopTimer()); PixCompareDwa(size, "dilate", pixt1, pixt2, pixt3, pixt4, pixt5, pixt6); /* pixDisplay(pixt1, 100, 100); */ /* pixDisplay(pixt2, 800, 100); */ if (TIMING) startTimer(); pixErodeCompBrickDwa(pixt1, pixs, size, 1); pixErodeCompBrickDwa(pixt3, pixs, 1, size); pixErodeCompBrickDwa(pixt5, pixs, size, size); if (TIMING) fprintf(stderr, "Time Dwa: %7.3f sec\n", stopTimer()); if (TIMING) startTimer(); pixErodeBrick(pixt2, pixs, size, 1); pixErodeBrick(pixt4, pixs, 1, size); pixErodeBrick(pixt6, pixs, size, size); if (TIMING) fprintf(stderr, "Time Rop: %7.3f sec\n", stopTimer()); PixCompareDwa(size, "erode", pixt1, pixt2, pixt3, pixt4, pixt5, pixt6); if (TIMING) startTimer(); pixOpenCompBrickDwa(pixt1, pixs, size, 1); pixOpenCompBrickDwa(pixt3, pixs, 1, size); pixOpenCompBrickDwa(pixt5, pixs, size, size); if (TIMING) fprintf(stderr, "Time Dwa: %7.3f sec\n", stopTimer()); if (TIMING) startTimer(); pixOpenBrick(pixt2, pixs, size, 1); pixOpenBrick(pixt4, pixs, 1, size); pixOpenBrick(pixt6, pixs, size, size); if (TIMING) fprintf(stderr, "Time Rop: %7.3f sec\n", stopTimer()); PixCompareDwa(size, "open", pixt1, pixt2, pixt3, pixt4, pixt5, pixt6); if (TIMING) startTimer(); pixCloseCompBrickDwa(pixt1, pixs, size, 1); pixCloseCompBrickDwa(pixt3, pixs, 1, size); pixCloseCompBrickDwa(pixt5, pixs, size, size); if (TIMING) fprintf(stderr, "Time Dwa: %7.3f sec\n", stopTimer()); if (TIMING) startTimer(); pixCloseSafeBrick(pixt2, pixs, size, 1); pixCloseSafeBrick(pixt4, pixs, 1, size); pixCloseSafeBrick(pixt6, pixs, size, size); if (TIMING) fprintf(stderr, "Time Rop: %7.3f sec\n", stopTimer()); PixCompareDwa(size, "close", pixt1, pixt2, pixt3, pixt4, pixt5, pixt6); return 0; }
/** * The main thread of parallel radix join. It does partitioning in parallel with * other threads and during the join phase, picks up join tasks from the task * queue and calls appropriate JoinFunction to compute the join task. * * @param param * * @return */ void * prj_thread(void * param) { arg_t * args = (arg_t*) param; int32_t my_tid = args->my_tid; const int fanOut = 1 << (NUM_RADIX_BITS / NUM_PASSES); const int R = (NUM_RADIX_BITS / NUM_PASSES); const int D = (NUM_RADIX_BITS - (NUM_RADIX_BITS / NUM_PASSES)); const int thresh1 = MAX((1<<D), (1<<R)) * THRESHOLD1(args->nthreads); uint64_t results = 0; int i; int rv; part_t part; task_t * task; task_queue_t * part_queue; task_queue_t * join_queue; #ifdef SKEW_HANDLING task_queue_t * skew_queue; #endif int32_t * outputR = (int32_t *) calloc((fanOut+1), sizeof(int32_t)); int32_t * outputS = (int32_t *) calloc((fanOut+1), sizeof(int32_t)); MALLOC_CHECK((outputR && outputS)); part_queue = args->part_queue; join_queue = args->join_queue; #ifdef SKEW_HANDLING skew_queue = args->skew_queue; #endif args->histR[my_tid] = (int32_t *) calloc(fanOut, sizeof(int32_t)); args->histS[my_tid] = (int32_t *) calloc(fanOut, sizeof(int32_t)); /* in the first pass, partitioning is done together by all threads */ args->parts_processed = 0; #ifdef PERF_COUNTERS if(my_tid == 0){ PCM_initPerformanceMonitor(NULL, NULL); PCM_start(); } #endif /* wait at a barrier until each thread starts and then start the timer */ BARRIER_ARRIVE(args->barrier, rv); /* if monitoring synchronization stats */ SYNC_TIMERS_START(args, my_tid); #ifndef NO_TIMING if(my_tid == 0){ /* thread-0 checkpoints the time */ gettimeofday(&args->start, NULL); startTimer(&args->timer1); startTimer(&args->timer2); startTimer(&args->timer3); } #endif /********** 1st pass of multi-pass partitioning ************/ part.R = 0; part.D = NUM_RADIX_BITS / NUM_PASSES; part.thrargs = args; part.padding = PADDING_TUPLES; /* 1. partitioning for relation R */ part.rel = args->relR; part.tmp = args->tmpR; part.hist = args->histR; part.output = outputR; part.num_tuples = args->numR; part.total_tuples = args->totalR; part.relidx = 0; #ifdef USE_SWWC_OPTIMIZED_PART parallel_radix_partition_optimized(&part); #else parallel_radix_partition(&part); #endif /* 2. partitioning for relation S */ part.rel = args->relS; part.tmp = args->tmpS; part.hist = args->histS; part.output = outputS; part.num_tuples = args->numS; part.total_tuples = args->totalS; part.relidx = 1; #ifdef USE_SWWC_OPTIMIZED_PART parallel_radix_partition_optimized(&part); #else parallel_radix_partition(&part); #endif /* wait at a barrier until each thread copies out */ BARRIER_ARRIVE(args->barrier, rv); /********** end of 1st partitioning phase ******************/ /* 3. first thread creates partitioning tasks for 2nd pass */ if(my_tid == 0) { for(i = 0; i < fanOut; i++) { int32_t ntupR = outputR[i+1] - outputR[i] - PADDING_TUPLES; int32_t ntupS = outputS[i+1] - outputS[i] - PADDING_TUPLES; #ifdef SKEW_HANDLING if(ntupR > thresh1 || ntupS > thresh1){ DEBUGMSG(1, "Adding to skew_queue= R:%d, S:%d\n", ntupR, ntupS); task_t * t = task_queue_get_slot(skew_queue); t->relR.num_tuples = t->tmpR.num_tuples = ntupR; t->relR.tuples = args->tmpR + outputR[i]; t->tmpR.tuples = args->relR + outputR[i]; t->relS.num_tuples = t->tmpS.num_tuples = ntupS; t->relS.tuples = args->tmpS + outputS[i]; t->tmpS.tuples = args->relS + outputS[i]; task_queue_add(skew_queue, t); } else #endif if(ntupR > 0 && ntupS > 0) { task_t * t = task_queue_get_slot(part_queue); t->relR.num_tuples = t->tmpR.num_tuples = ntupR; t->relR.tuples = args->tmpR + outputR[i]; t->tmpR.tuples = args->relR + outputR[i]; t->relS.num_tuples = t->tmpS.num_tuples = ntupS; t->relS.tuples = args->tmpS + outputS[i]; t->tmpS.tuples = args->relS + outputS[i]; task_queue_add(part_queue, t); } } /* debug partitioning task queue */ DEBUGMSG(1, "Pass-2: # partitioning tasks = %d\n", part_queue->count); } SYNC_TIMER_STOP(&args->localtimer.sync3); /* wait at a barrier until first thread adds all partitioning tasks */ BARRIER_ARRIVE(args->barrier, rv); /* global barrier sync point-3 */ SYNC_GLOBAL_STOP(&args->globaltimer->sync3, my_tid); /************ 2nd pass of multi-pass partitioning ********************/ /* 4. now each thread further partitions and add to join task queue **/ #if NUM_PASSES==1 /* If the partitioning is single pass we directly add tasks from pass-1 */ task_queue_t * swap = join_queue; join_queue = part_queue; /* part_queue is used as a temporary queue for handling skewed parts */ part_queue = swap; #elif NUM_PASSES==2 while((task = task_queue_get_atomic(part_queue))){ serial_radix_partition(task, join_queue, R, D); } #else #warning Only 2-pass partitioning is implemented, set NUM_PASSES to 2! #endif #ifdef SKEW_HANDLING /* Partitioning pass-2 for skewed relations */ part.R = R; part.D = D; part.thrargs = args; part.padding = SMALL_PADDING_TUPLES; while(1) { if(my_tid == 0) { *args->skewtask = task_queue_get_atomic(skew_queue); } BARRIER_ARRIVE(args->barrier, rv); if( *args->skewtask == NULL) break; DEBUGMSG((my_tid==0), "Got skew task = R: %d, S: %d\n", (*args->skewtask)->relR.num_tuples, (*args->skewtask)->relS.num_tuples); int32_t numperthr = (*args->skewtask)->relR.num_tuples / args->nthreads; const int fanOut2 = (1 << D); free(outputR); free(outputS); outputR = (int32_t*) calloc(fanOut2 + 1, sizeof(int32_t)); outputS = (int32_t*) calloc(fanOut2 + 1, sizeof(int32_t)); free(args->histR[my_tid]); free(args->histS[my_tid]); args->histR[my_tid] = (int32_t*) calloc(fanOut2, sizeof(int32_t)); args->histS[my_tid] = (int32_t*) calloc(fanOut2, sizeof(int32_t)); /* wait until each thread allocates memory */ BARRIER_ARRIVE(args->barrier, rv); /* 1. partitioning for relation R */ part.rel = (*args->skewtask)->relR.tuples + my_tid * numperthr; part.tmp = (*args->skewtask)->tmpR.tuples; part.hist = args->histR; part.output = outputR; part.num_tuples = (my_tid == (args->nthreads-1)) ? ((*args->skewtask)->relR.num_tuples - my_tid * numperthr) : numperthr; part.total_tuples = (*args->skewtask)->relR.num_tuples; part.relidx = 2; /* meaning this is pass-2, no syncstats */ parallel_radix_partition(&part); numperthr = (*args->skewtask)->relS.num_tuples / args->nthreads; /* 2. partitioning for relation S */ part.rel = (*args->skewtask)->relS.tuples + my_tid * numperthr; part.tmp = (*args->skewtask)->tmpS.tuples; part.hist = args->histS; part.output = outputS; part.num_tuples = (my_tid == (args->nthreads-1)) ? ((*args->skewtask)->relS.num_tuples - my_tid * numperthr) : numperthr; part.total_tuples = (*args->skewtask)->relS.num_tuples; part.relidx = 2; /* meaning this is pass-2, no syncstats */ parallel_radix_partition(&part); /* wait at a barrier until each thread copies out */ BARRIER_ARRIVE(args->barrier, rv); /* first thread adds join tasks */ if(my_tid == 0) { const int THR1 = THRESHOLD1(args->nthreads); for(i = 0; i < fanOut2; i++) { int32_t ntupR = outputR[i+1] - outputR[i] - SMALL_PADDING_TUPLES; int32_t ntupS = outputS[i+1] - outputS[i] - SMALL_PADDING_TUPLES; if(ntupR > THR1 || ntupS > THR1){ DEBUGMSG(1, "Large join task = R: %d, S: %d\n", ntupR, ntupS); /* use part_queue temporarily */ for(int k=0; k < args->nthreads; k++) { int ns = (k == args->nthreads-1) ? (ntupS - k*(ntupS/args->nthreads)) : (ntupS/args->nthreads); task_t * t = task_queue_get_slot(part_queue); t->relR.num_tuples = t->tmpR.num_tuples = ntupR; t->relR.tuples = (*args->skewtask)->tmpR.tuples + outputR[i]; t->tmpR.tuples = (*args->skewtask)->relR.tuples + outputR[i]; t->relS.num_tuples = t->tmpS.num_tuples = ns; //ntupS; t->relS.tuples = (*args->skewtask)->tmpS.tuples + outputS[i] //; + k*(ntupS/args->nthreads); t->tmpS.tuples = (*args->skewtask)->relS.tuples + outputS[i] //; + k*(ntupS/args->nthreads); task_queue_add(part_queue, t); } } else if(ntupR > 0 && ntupS > 0) { task_t * t = task_queue_get_slot(join_queue); t->relR.num_tuples = t->tmpR.num_tuples = ntupR; t->relR.tuples = (*args->skewtask)->tmpR.tuples + outputR[i]; t->tmpR.tuples = (*args->skewtask)->relR.tuples + outputR[i]; t->relS.num_tuples = t->tmpS.num_tuples = ntupS; t->relS.tuples = (*args->skewtask)->tmpS.tuples + outputS[i]; t->tmpS.tuples = (*args->skewtask)->relS.tuples + outputS[i]; task_queue_add(join_queue, t); DEBUGMSG(1, "Join added = R: %d, S: %d\n", t->relR.num_tuples, t->relS.num_tuples); } } } } /* add large join tasks in part_queue to the front of the join queue */ if(my_tid == 0) { while((task = task_queue_get_atomic(part_queue))) task_queue_add(join_queue, task); } #endif free(outputR); free(outputS); SYNC_TIMER_STOP(&args->localtimer.sync4); /* wait at a barrier until all threads add all join tasks */ BARRIER_ARRIVE(args->barrier, rv); /* global barrier sync point-4 */ SYNC_GLOBAL_STOP(&args->globaltimer->sync4, my_tid); #ifndef NO_TIMING if(my_tid == 0) stopTimer(&args->timer3);/* partitioning finished */ #endif DEBUGMSG((my_tid == 0), "Number of join tasks = %d\n", join_queue->count); #ifdef PERF_COUNTERS if(my_tid == 0){ PCM_stop(); PCM_log("======= Partitioning phase profiling results ======\n"); PCM_printResults(); PCM_start(); } /* Just to make sure we get consistent performance numbers */ BARRIER_ARRIVE(args->barrier, rv); #endif while((task = task_queue_get_atomic(join_queue))){ /* do the actual join. join method differs for different algorithms, i.e. bucket chaining, histogram-based, histogram-based with simd & prefetching */ results += args->join_function(&task->relR, &task->relS, &task->tmpR); args->parts_processed ++; } args->result = results; /* this thread is finished */ SYNC_TIMER_STOP(&args->localtimer.finish_time); #ifndef NO_TIMING /* this is for just reliable timing of finish time */ BARRIER_ARRIVE(args->barrier, rv); if(my_tid == 0) { /* Actually with this setup we're not timing build */ stopTimer(&args->timer2);/* build finished */ stopTimer(&args->timer1);/* probe finished */ gettimeofday(&args->end, NULL); } #endif /* global finish time */ SYNC_GLOBAL_STOP(&args->globaltimer->finish_time, my_tid); #ifdef PERF_COUNTERS if(my_tid == 0) { PCM_stop(); PCM_log("=========== Build+Probe profiling results =========\n"); PCM_printResults(); PCM_log("===================================================\n"); PCM_cleanup(); } /* Just to make sure we get consistent performance numbers */ BARRIER_ARRIVE(args->barrier, rv); #endif return 0; }
int main_find_pattern(int argc, char **argv) { char *filein, *fileout, *patternfile; l_int32 w, h, i, n; BOX *box, *boxe; BOXA *boxa1, *boxa2; PIX *pixs, *pixp, *pixpe; PIX *pixd, *pixt1, *pixt2, *pixhmt; SEL *sel_2h, *sel; static char mainName[] = "findpattern1"; filein = "feyn.tif"; patternfile = "char.tif"; fileout = "result.findpattern1"; if ((pixs = pixRead(filein)) == NULL) printf("pixs not made\n"); if ((pixp = pixRead(patternfile)) == NULL) printf("pixp not made\n"); w = pixGetWidth(pixp); h = pixGetHeight(pixp); /* generate the hit-miss Sel with runs */ sel = pixGenerateSelWithRuns(pixp, NumHorLines, NumVertLines, 0, MinRunlength, 7, 7, 0, 0, &pixpe); /* display the Sel two ways */ selWriteStream(stderr, sel); pixt1 = pixDisplayHitMissSel(pixpe, sel, 9, HitColor, MissColor); pixDisplay(pixt1, 200, 200); pixWrite("junkpixt", pixt1, IFF_PNG); /* use the Sel to find all instances in the page */ startTimer(); pixhmt = pixHMT(NULL, pixs, sel); fprintf(stderr, "Time to find patterns = %7.3f\n", stopTimer()); /* small erosion to remove noise; typically not necessary if * there are enough elements in the Sel */ sel_2h = selCreateBrick(1, 2, 0, 0, SEL_HIT); pixt2 = pixErode(NULL, pixhmt, sel_2h); /* display the result visually by placing the Sel at each * location found */ pixd = pixDilate(NULL, pixt2, sel); pixWrite(fileout, pixd, IFF_TIFF_G4); /* display outut with an outline around each located pattern */ boxa1 = pixConnCompBB(pixt2, 8); n = boxaGetCount(boxa1); boxa2 = boxaCreate(n); for (i = 0; i < n; i++) { box = boxaGetBox(boxa1, i, L_COPY); boxe = boxCreate(box->x - w / 2, box->y - h / 2, w + 4, h + 4); boxaAddBox(boxa2, boxe, L_INSERT); pixRenderBox(pixs, boxe, 4, L_FLIP_PIXELS); boxDestroy(&box); } pixWrite("junkoutline", pixs, IFF_TIFF_G4); //boxaWriteStream(stderr, boxa2); //TODO ??? pixDestroy(&pixs); pixDestroy(&pixp); pixDestroy(&pixpe); pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixhmt); pixDestroy(&pixd); selDestroy(&sel); selDestroy(&sel_2h); boxaDestroy(&boxa1); boxaDestroy(&boxa2); printf("\n---\nEND\n"); getchar(); return 0; }
MainWindow::MainWindow(int startState, QString run_binary, QWidget * parent, Qt::WindowFlags f) : QMainWindow(parent, f){ // Loading libq4wine-core.so #ifdef RELEASE libq4wine.setFileName(_CORELIB_PATH_); #else libq4wine.setFileName("../q4wine-lib/libq4wine-core"); #endif if (!libq4wine.load()){ libq4wine.load(); } // Getting corelib class pointer CoreLibClassPointer = (CoreLibPrototype *) libq4wine.resolve("createCoreLib"); CoreLib.reset((corelib *)CoreLibClassPointer(true)); clearTmp(); db_prefix.fixPrefixPath(); if (CoreLib->getSetting("DesktopImport", "importAtStartup", false, 0)==1){ Progress progress(0, ""); progress.exec(); } // importIcons(QString("%1/.local/share/applications/wine/").arg(QDir::homePath())); //exportProcess.close(); // Base GUI setup setupUi(this); if (!this->createSocket()){ this->close(); return; } if (startState == 1) this->showMinimized(); setWindowTitle(tr("%1 :. Qt GUI for Wine v%2").arg(APP_NAME) .arg(APP_VERS)); std::auto_ptr<QVBoxLayout> vlayout (new QVBoxLayout); std::auto_ptr<PrefixConfigWidget> configWidget (new PrefixConfigWidget(tabPrefixSeup)); connect(configWidget.get(), SIGNAL(updateDatabaseConnections()), this, SLOT(updateDtabaseConnectedItems())); connect(configWidget.get(), SIGNAL(setTabIndex (int)), tbwGeneral, SLOT(setCurrentIndex (int))); connect(this, SIGNAL(updateDatabaseConnections()), configWidget.get(), SLOT(getPrefixes())); std::auto_ptr<LoggingWidget> logWidget (new LoggingWidget(tabLogging)); connect (this, SIGNAL(reloadLogData()), logWidget.get(), SLOT(getLogRecords())); logWidget->getLogRecords(); logLayout->addWidget(logWidget.release()); std::auto_ptr<IconListWidget> lstIcons (new IconListWidget(tabPrograms)); connect(this, SIGNAL(runProgramRequest(QString)), lstIcons.get(), SLOT(runProgramRequest(QString))); connect(lstIcons.get(), SIGNAL(iconItemClick(QString, QString, QString, QString, QString)), this, SLOT(updateIconDesc(QString, QString, QString, QString, QString))); connect(lstIcons.get(), SIGNAL(changeStatusText(QString)), this, SLOT(changeStatusText(QString))); connect(lstIcons.get(), SIGNAL(appRunned(bool)), this, SLOT(setMeVisible(bool))); std::auto_ptr<PrefixTreeWidget> twPrograms (new PrefixTreeWidget(tabPrograms)); connect(twPrograms.get(), SIGNAL(updateDatabaseConnections()), this, SLOT(updateDtabaseConnectedItems())); connect(this, SIGNAL(updateDatabaseConnections()), twPrograms.get(), SLOT(getPrefixes())); connect(twPrograms.get(), SIGNAL(showFolderContents(QString, QString)), lstIcons.get(), SLOT(showFolderContents(QString, QString))); connect(twPrograms.get(), SIGNAL(setSearchFocus()), this, SLOT(setSearchFocus())); connect(twPrograms.get(), SIGNAL(changeStatusText(QString)), this, SLOT(changeStatusText(QString))); connect(this, SIGNAL(setDefaultFocus(QString, QString)), twPrograms.get(), SLOT(setDefaultFocus(QString, QString))); connect(configWidget.get(), SIGNAL(prefixIndexChanged(QString)), twPrograms.get(), SLOT(setDefaultFocus(QString))); connect(twPrograms.get(), SIGNAL(prefixIndexChanged(QString)), configWidget.get(), SLOT(setPrefix(QString))); connect(twPrograms.get(), SIGNAL(setTabIndex (int)), tbwGeneral, SLOT(setCurrentIndex (int))); connect(twPrograms.get(), SIGNAL(pasteAction()), lstIcons.get(), SLOT(iconPaste_Click())); std::auto_ptr<WineProcessWidget> procWidget (new WineProcessWidget(tabProcess)); connect(this, SIGNAL(stopProcTimer()), procWidget.get(), SLOT(stopTimer())); connect(this, SIGNAL(startProcTimer()), procWidget.get(), SLOT(startTimer())); connect(procWidget.get(), SIGNAL(changeStatusText(QString)), this, SLOT(changeStatusText(QString))); tabProcessLayout->addWidget(procWidget.release()); std::auto_ptr<PrefixControlWidget> prefixWidget (new PrefixControlWidget(tabPrefix)); connect(prefixWidget.get(), SIGNAL(updateDatabaseConnections()), twPrograms.get(), SLOT(getPrefixes())); connect(prefixWidget.get(), SIGNAL(updateDatabaseConnections()), this, SLOT(updateDtabaseConnectedItems())); connect(configWidget.get(), SIGNAL(prefixIndexChanged(QString)), prefixWidget.get(), SLOT(setDefaultFocus(QString))); connect(prefixWidget.get(), SIGNAL(prefixIndexChanged(QString)), configWidget.get(), SLOT(setPrefix(QString))); connect(prefixWidget.get(), SIGNAL(setTabIndex (int)), tbwGeneral, SLOT(setCurrentIndex (int))); connect(twPrograms.get(), SIGNAL(updateDatabaseConnections()), prefixWidget.get(), SLOT(updateDtabaseItems())); std::auto_ptr<IconListToolbar> iconToolBar (new IconListToolbar(tabPrograms)); connect(iconToolBar.get(), SIGNAL(searchFilterChange(QString)), lstIcons.get(), SLOT(setFilterString(QString))); connect(iconToolBar.get(), SIGNAL(changeView(int)), lstIcons.get(), SLOT(changeView(int))); std::auto_ptr<PrefixTreeToolbar> prefixToolBar (new PrefixTreeToolbar(tabPrograms)); connect(prefixToolBar.get(), SIGNAL(expandTree()), twPrograms.get(), SLOT(expandTree())); connect(prefixToolBar.get(), SIGNAL(collapseTree()), twPrograms.get(), SLOT(collapseTree())); connect(prefixToolBar.get(), SIGNAL(updatePrefixTree()), this, SLOT(updateDtabaseConnectedItems())); connect(prefixToolBar.get(), SIGNAL(updatePrefixTree()), prefixWidget.get(), SLOT(updateDtabaseItems())); vlayout.reset(new QVBoxLayout); vlayout->addWidget(prefixToolBar.release()); vlayout->addWidget(twPrograms.release()); vlayout->setMargin(0); vlayout->setSpacing(0); std::auto_ptr<QWidget> wid (new QWidget(tabPrograms)); wid->setLayout(vlayout.release()); splitter.reset(new QSplitter(tabPrograms)); splitter->addWidget(wid.release()); vlayout.reset(new QVBoxLayout); vlayout->addWidget(iconToolBar.release()); vlayout->addWidget(lstIcons.release()); vlayout->setMargin(0); vlayout->setSpacing(0); //vlayout->setContentsMargins(0,0,0,0); wid.reset(new QWidget(tabPrograms)); wid->setLayout(vlayout.release()); splitter->addWidget(wid.release()); vlayout.reset(new QVBoxLayout); vlayout->addWidget(splitter.get()); vlayout->addWidget(gbInfo); vlayout->setContentsMargins(3,0,3,3); tabPrograms->setLayout(vlayout.release()); tabPrefixLayout->addWidget(prefixWidget.release()); setupLayout->addWidget(configWidget.release()); // Updating database connected items updateDtabaseConnectedItems(); // Getting settings from config file this->createTrayIcon(); this->getSettings(); connect(tbwGeneral, SIGNAL(currentChanged(int)), this, SLOT(tbwGeneral_CurrentTabChange(int))); //connect(cmdCreateFake, SIGNAL(clicked()), this, SLOT(cmdCreateFake_Click())); //connect(cmdUpdateFake, SIGNAL(clicked()), this, SLOT(cmdUpdateFake_Click())); //Main menu actions connection to slots connect(mainRun, SIGNAL(triggered()), this, SLOT(mainRun_Click())); connect(mainPrograms, SIGNAL(triggered()), this, SLOT(mainPrograms_Click())); connect(mainLogging, SIGNAL(triggered()), this, SLOT(mainLogging_Click())); connect(mainProcess, SIGNAL(triggered()), this, SLOT(mainProcess_Click())); connect(mainSetup, SIGNAL(triggered()), this, SLOT(mainSetup_Click())); connect(mainPrefix, SIGNAL(triggered()), this, SLOT(mainPrefix_Click())); connect(mainImageManage, SIGNAL(triggered()), this, SLOT(mainImageManager_Click())); connect(mainAbout, SIGNAL(triggered()), this, SLOT(mainAbout_Click())); connect(mainAboutQt, SIGNAL(triggered()), this, SLOT(mainAboutQt_Click())); connect(mainExportIcons, SIGNAL(triggered()), this, SLOT(mainExportIcons_Click())); connect(mainOptions, SIGNAL(triggered()), this, SLOT(mainOptions_Click())); connect(mainInstall, SIGNAL(triggered()), this, SLOT(mainInstall_Click())); connect(mainExit, SIGNAL(triggered()), this, SLOT(mainExit_Click())); connect(mainImportWineIcons, SIGNAL(triggered()), this, SLOT(mainImportWineIcons_Click())); connect(mainVersionManager, SIGNAL(triggered()), this, SLOT(mainVersionManager_Click())); CoreLib->runAutostart(); #ifndef WITH_ICOUTILS mainExportIcons->setEnabled(false); #endif if (!run_binary.isEmpty()) messageReceived(run_binary); if (!trayIcon->isVisible()) show(); return; }
clock_t Timer::stopTimer(const String & name) { // hack return stopTimer(theInstance().currentTest, name); }
QGroupBox* HW3b::controlPanel() { // init group box QGroupBox *groupBox = new QGroupBox("Homework 3a"); groupBox->setMinimumWidth(300); QGridLayout *layout = new QGridLayout; m_comboBox = new QComboBox(); m_comboBox->addItem("Texture"); m_comboBox->addItem("Wireframe"); m_comboBox->addItem("Tex+Wire"); m_comboBox->setCurrentIndex(TEX_WIRE); m_comboBox_mode = new QComboBox(); m_comboBox_mode->addItem("FLAT"); m_comboBox_mode->addItem("SPIKE"); m_comboBox_mode->addItem("DIAGONALWALL"); m_comboBox_mode->addItem("SIDEWALL"); m_comboBox_mode->addItem("HOLE"); m_comboBox_mode->addItem("MIDDLEBLOCK"); m_comboBox_mode->addItem("DIAGONALBLOCK"); m_comboBox_mode->addItem("CORNERBLOCK"); m_comboBox_mode->addItem("HILL"); m_comboBox_mode->addItem("HILLFOUR"); m_comboBox_mode->setCurrentIndex(HILLFOUR); m_PushbottonGo = new QPushButton("go"); m_PushbottonStop = new QPushButton("Stop"); layout->addWidget(m_PushbottonGo,0,0,1,2); layout->addWidget(m_PushbottonStop,1,0,1,2); layout->addWidget(m_comboBox,2,0,1,2); layout->addWidget(m_comboBox_mode,3,0,1,2); m_sliderGrid = new QSlider(Qt::Horizontal); m_sliderGrid->setRange(2, 64); m_sliderGrid->setValue(16); m_spinboxGrid = new QSpinBox; m_spinboxGrid->setRange(2,64); m_spinboxGrid->setValue(16); m_sliderSpeed = new QSlider(Qt::Horizontal); m_sliderSpeed->setRange(1, 20); m_sliderSpeed->setValue(6); m_spinboxSpeed = new QSpinBox; m_spinboxSpeed->setRange(1,20); m_spinboxSpeed->setValue(6); m_labelGrid = new QLabel("Grid"); m_labelSpeed = new QLabel("Speed"); layout->addWidget(m_labelGrid,4,0,1,1); layout->addWidget(m_sliderGrid,4,1,1,1); layout->addWidget(m_spinboxGrid,4,3,1,1); layout->addWidget(m_labelSpeed,5,0,1,1); layout->addWidget(m_sliderSpeed,5,1,1,1); layout->addWidget(m_spinboxSpeed,5,3,1,1); connect(m_comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(displayChange(int))); connect(m_comboBox_mode, SIGNAL(currentIndexChanged(int)), this, SLOT(selectMode(int))); connect(m_PushbottonGo, SIGNAL(clicked()), this, SLOT(begintimer())); connect(m_PushbottonStop, SIGNAL(clicked()), this, SLOT(stopTimer())); connect(m_sliderGrid, SIGNAL(valueChanged(int)), this, SLOT(setsize(int))); connect(m_spinboxGrid, SIGNAL(valueChanged(int)), this, SLOT(setsize(int))); connect(m_sliderSpeed, SIGNAL(valueChanged(int)), this, SLOT(setSpeed(int))); // connect(m_spinboxSpeed, SIGNAL(valueChanged(int)), this, SLOT(setSpeed(int))); groupBox->setLayout(layout); return(groupBox); }
GLCanvas::~GLCanvas() { delete glContext; stopTimer(); }
MediaPlayer::~MediaPlayer() { stopTimer(); stop(); }
void MainContentComponent::timerCallback() { // reset the command label's background to white _commandLabel.setColour(Label::backgroundColourId, Colours::white); stopTimer(); }