void RawFiles::setEntry(const char *inbuf, long len) { FileDesc *datafile; long start; unsigned short size; VerseKey *key = &getVerseKey(); len = (len<0)?strlen(inbuf):len; findOffset(key->Testament(), key->TestamentIndex(), &start, &size); if (size) { SWBuf tmpbuf; entryBuf = path; entryBuf += '/'; readText(key->Testament(), start, size, tmpbuf); entryBuf += tmpbuf; } else { SWBuf tmpbuf; entryBuf = path; entryBuf += '/'; tmpbuf = getNextFilename(); doSetText(key->Testament(), key->TestamentIndex(), tmpbuf); entryBuf += tmpbuf; } datafile = FileMgr::getSystemFileMgr()->open(entryBuf, FileMgr::CREAT|FileMgr::WRONLY|FileMgr::TRUNC); if (datafile->getFd() > 0) { datafile->write(inbuf, len); } FileMgr::getSystemFileMgr()->close(datafile); }
void MainWindow::fileBrowse() { QString message = "Log file selection"; QString types = "All files (*)"; QString fileName = QFileDialog::getSaveFileName(this, message, ".", types); if(!fileName.isEmpty()) { if(!fileName.contains(".klg", Qt::CaseInsensitive)) { fileName.append(".klg"); } #ifdef unix logFolder = fileName.toStdString().substr(0, fileName.toStdString().rfind("/")); lastFilename = fileName.toStdString().substr(fileName.toStdString().rfind("/") + 1, fileName.toStdString().rfind(".klg")); #else logFolder = fileName.toStdString().substr(0, fileName.toStdString().rfind("\\")); lastFilename = fileName.toStdString().substr(fileName.toStdString().rfind("\\") + 1, fileName.toStdString().rfind(".klg")); #endif lastFilename = lastFilename.substr(0, lastFilename.size() - 4); logFile->setText(QString::fromStdString(getNextFilename())); } }
void MainWindow::recordToggle() { if(!recording) { if(logFile->text().length() == 0) { QMessageBox::information(this, "Information", "You have not selected an output log file"); } else { memoryRecord->setEnabled(false); compressed->setEnabled(false); logger->startWriting(logFile->text().toStdString()); startStop->setText("Stop"); recording = true; } } else { logger->stopWriting(this); memoryRecord->setEnabled(true); compressed->setEnabled(true); startStop->setText(tcp ? "Stream && Record" : "Record"); recording = false; logFile->setText(QString::fromStdString(getNextFilename())); } }
void ImageSequenceRecorder::OnFrame(const cricket::VideoFrame& yuvframe) { STrace << "On video frame: " << yuvframe.width() << 'x' << yuvframe.height() << std::endl; if (_width != yuvframe.width() || _height != yuvframe.height()) { _width = yuvframe.width(); _height = yuvframe.height(); _encoder.iparams.width = yuvframe.width(); _encoder.iparams.height = yuvframe.height(); _encoder.iparams.pixelFmt = "yuv420p"; _encoder.oparams.encoder = "mjpeg"; // "png" _encoder.oparams.pixelFmt = "yuvj420p"; _encoder.oparams.width = yuvframe.width(); _encoder.oparams.height = yuvframe.height(); _encoder.oparams.fps = 25; // avoid FFmpeg 0 fps bitrate tolerance error _encoder.oparams.enabled = true; _encoder.create(); _encoder.open(); // Cleanup the previous frame (if any) if (_avframe) av_free(_avframe); // Initialize the AVFrame _avframe = av_frame_alloc(); _avframe->width = yuvframe.width(); _avframe->height = yuvframe.height(); _avframe->format = AV_PIX_FMT_YUV420P; // Initialize avframe->linesize avpicture_fill((AVPicture*)_avframe, NULL, /*_avframe->format*/ AV_PIX_FMT_YUV420P, _avframe->width, _avframe->height); } // Set avframe->data pointers manually _avframe->data[0] = (uint8_t*)yuvframe.video_frame_buffer()->DataY(); _avframe->data[1] = (uint8_t*)yuvframe.video_frame_buffer()->DataU(); _avframe->data[2] = (uint8_t*)yuvframe.video_frame_buffer()->DataV(); // Feed the raw frame into the encoder AVPacket opacket; if (_encoder.encode(_avframe, opacket)) { // Write the output file std::string filename(getNextFilename()); LTrace("Write video frame: ", filename) fs::savefile(filename, (const char*)opacket.data, (std::streamsize)opacket.size); } }
int main () { // open the dir char *dirname = "."; DIR *dir ; dir = opendir ( dirname ); if ( ! dir ) { fprintf(stderr,"disk: opendir(%s) : %s", dirname,strerror( errno ) ); return -1; } // scan each file rewinddir ( dir ); char saved[1024]; loop: char *f = getNextFilename ( dir , "*" ); if ( ! f ) return 0; // get the date from it char *p = NULL; if ( ! p ) p = strstr (f,"2008" ) ; if ( ! p ) p = strstr (f,"2009" ) ; if ( ! p ) p = strstr (f,"2010" ) ; if ( ! p ) p = strstr (f,"2011" ) ; if ( ! p ) p = strstr (f,"2012" ) ; if ( ! p ) p = strstr (f,"2013" ) ; if ( ! p ) p = strstr (f,"2014" ) ; if ( ! p ) p = strstr (f,"2015" ) ; if ( ! p ) p = strstr (f,"2016" ) ; if ( ! p ) p = strstr (f,"2017" ) ; if ( ! p ) goto loop; // get the full date char buf[1024]; sprintf ( buf , "mkdir %.8s", p ); // don't repeat it if ( strcmp ( buf , saved ) != 0 ) { fprintf(stderr,"%s\n",buf); system ( buf ); strcpy ( saved , buf ); } // store in there sprintf( buf , "mv %s %.8s/",f,p); fprintf(stderr,"%s\n",buf); system(buf ); goto loop; }
void doBmpScreenShot(Visual *display) { static int last_bmp_num; /* store last free file index. */ nebu_Surface *pScreen; char *path = getNextFilename(".bmp", &last_bmp_num); if(!path) return; pScreen = nebu_Video_GrabScreen(display->w, display->h); nebu_Surface_SaveBMP(pScreen, path); nebu_Surface_Free(pScreen); free(path); }
//-------------------------------------------------------------- void testApp::setup(){ screenWidth = 1024; screenHeight = 768; kernelSize = screenWidth / 2; currentLut = 0; currentTrial = 0; bNoiseState = true; bFirstTrial = true; // static const float sigmas[] = {1.5, 1.25, 1.0, 0.75, 0.5, 0.25, 0.125, 0.0625}; // static const float thetas[] = {0, 45, 90, 135, 180, 225, 270, 315}; // static const float freqs[] = {0.0625, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 1.0}; static const float sigmas[] = {1.25, 0.125, 0.25, 1.5, 1.0, 0.5, 0.0625, 0.75}; static const float thetas[] = {0, 45, 225, 270, 135, 180, 315, 90}; static const float freqs[] = {0.375, 0.0625, 0.625, 0.5, 1.0, 0.125, 0.75, 0.25}; this->sigmas = vector<float>(sigmas, sigmas + sizeof(sigmas) / sizeof(sigmas[0]) ); this->thetas = vector<float>(thetas, thetas + sizeof(thetas) / sizeof(thetas[0]) ); this->freqs = vector<float>(freqs, freqs + sizeof(freqs) / sizeof(freqs[0]) ); for (int i = 0; i < this->sigmas.size(); i++) { for (int j = 0; j < this->thetas.size(); j++) { for (int k = 0; k < this->freqs.size(); k++) { int lut[] = {i, j, k}; vector<int> clut(lut, lut + sizeof(lut) / sizeof(lut[0])); this->lut.push_back(clut); } } } ////////////////////////////////////////////////////// // now create the file so that we can start adding frames to it: string filename = getNextFilename("eeg-record-trial-" + ofToString(currentTrial), "txt"); outfile.open( ofToDataPath(filename).c_str() ); oscReceiver.setup(RECEIVE_PORT); atom.allocate(max(screenWidth, screenHeight)); noiseShader.load(ofToDataPath("noise")); ofSetVerticalSync(true); ofSetWindowShape(screenWidth, screenHeight); ofResetElapsedTimeCounter(); }
void doPngScreenShot(Visual *display) { screenshot_info_t screenshot; static int last_png_num; /* store last free file index. */ char *path; path = getNextFilename(".png", &last_png_num); if(path != NULL) { if (captureScreenToPixmap(&screenshot, display) != 0) { fprintf(stderr, "Error capturing screenshot\n"); return; } if (writePixmapToPng(&screenshot, path) != 0) { fprintf(stderr, "Error writing screenshot %s\n", path); } else { fprintf(stderr, "Screenshot written to %s\n", path); } free(screenshot.pixmap); free(path); } }
void doBmpScreenShot(Visual *display) { screenshot_info_t screenshot; static int last_bmp_num; /* store last free file index. */ char *path; path = getNextFilename(".bmp", &last_bmp_num); if(path != NULL) { if (captureScreenToPixmap(&screenshot, display) != 0) { fprintf(stderr, "Error capturing screenshot\n"); return; } if (SystemWriteBMP(path, screenshot.width, screenshot.height, screenshot.pixmap) != 0) { fprintf(stderr, "Error writing screenshot %s\n", path); } else { fprintf(stderr, "Screenshot written to %s\n", path); } free(screenshot.pixmap); free(path); } }
//-------------------------------------------------------------- void testApp::update(){ /* sigma = 2.0 * kernelSize * sinf(ofGetElapsedTimef() / 12.0) / 5.0; theta = 180.0 * cosf(ofGetElapsedTimef() / 6.0); freq = sinf(ofGetElapsedTimef() / 2.0); */ if (!bFirstTrial && ofGetElapsedTimeMillis() >= MS_PER_STIMULI) { ofResetElapsedTimeCounter(); bNoiseState = !bNoiseState; if (bNoiseState) { currentLut++; if (currentLut == 512) { currentLut = 0; currentTrial++; if (currentTrial == 10) { cout << "[OK] Finished!" << endl; outfile.close(); OF_EXIT_APP(0); } outfile.close(); string filename = getNextFilename("eeg-record-trial-" + ofToString(currentTrial), "txt"); outfile.open( ofToDataPath(filename).c_str() ); } } } if (bNoiseState) { } else { sigma = kernelSize * sigmas[lut[currentLut][0]]; theta = thetas[lut[currentLut][1]]; freq = freqs[lut[currentLut][2]]; atom.update(sigma, theta, freq); } string delimiter = ","; #ifdef USE_OSC while (oscReceiver.hasWaitingMessages()) { ofxOscMessage m; if(oscReceiver.getNextMessage(&m)) { if (m.getAddress() == "/eeg") { #endif outfile << ofGetTimestampString() << delimiter << bNoiseState << delimiter << currentTrial << delimiter << currentLut << delimiter << sigma << delimiter << theta << delimiter << freq; #ifdef USE_OSC for (int ch = 0; ch < 22; ch++) { outfile << delimiter << m.getArgAsFloat(ch); } #endif outfile << delimiter; outfile << endl; #ifdef USE_OSC } } } #endif }
void MainWindow::dateFilename() { lastFilename.clear(); logFile->setText(QString::fromStdString(getNextFilename())); }
MainWindow::MainWindow(Logger * logger) : logger(logger), depthImage(640, 480, QImage::Format_RGB888), rgbImage(640, 480, QImage::Format_RGB888), recording(false), lastDrawn(-1) { this->setMaximumSize(1280, 600); this->setMinimumSize(1280, 600); QVBoxLayout * wrapperLayout = new QVBoxLayout; QHBoxLayout * mainLayout = new QHBoxLayout; QHBoxLayout * fileLayout = new QHBoxLayout; QHBoxLayout * buttonLayout = new QHBoxLayout; wrapperLayout->addLayout(mainLayout); depthLabel = new QLabel(this); depthLabel->setPixmap(QPixmap::fromImage(depthImage)); mainLayout->addWidget(depthLabel); imageLabel = new QLabel(this); imageLabel->setPixmap(QPixmap::fromImage(rgbImage)); mainLayout->addWidget(imageLabel); wrapperLayout->addLayout(fileLayout); QLabel * logLabel = new QLabel("Log file: ", this); logLabel->setMaximumWidth(logLabel->fontMetrics().boundingRect(logLabel->text()).width()); fileLayout->addWidget(logLabel); logFile = new QLabel(this); logFile->setTextInteractionFlags(Qt::TextSelectableByMouse); logFile->setStyleSheet("border: 1px solid grey"); fileLayout->addWidget(logFile); browseButton = new QPushButton("Browse", this); browseButton->setMaximumWidth(browseButton->fontMetrics().boundingRect(browseButton->text()).width() + 10); connect(browseButton, SIGNAL(clicked()), this, SLOT(fileBrowse())); fileLayout->addWidget(browseButton); dateNameButton = new QPushButton("Date filename", this); dateNameButton->setMaximumWidth(dateNameButton->fontMetrics().boundingRect(dateNameButton->text()).width() + 10); connect(dateNameButton, SIGNAL(clicked()), this, SLOT(dateFilename())); fileLayout->addWidget(dateNameButton); wrapperLayout->addLayout(buttonLayout); startStop = new QPushButton("Record", this); connect(startStop, SIGNAL(clicked()), this, SLOT(recordToggle())); buttonLayout->addWidget(startStop); QPushButton * quitButton = new QPushButton("Quit", this); connect(quitButton, SIGNAL(clicked()), this, SLOT(quit())); buttonLayout->addWidget(quitButton); setLayout(wrapperLayout); startStop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); quitButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); QFont currentFont = startStop->font(); currentFont.setPointSize(currentFont.pointSize() + 8); startStop->setFont(currentFont); quitButton->setFont(currentFont); painter = new QPainter(&depthImage); timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(timerCallback())); timer->start(15); #ifdef unix char * homeDir = getenv("HOME"); logFolder.append(homeDir); logFolder.append("/"); #else char * homeDrive = getenv("HOMEDRIVE"); char * homeDir = getenv("HOMEPATH"); logFolder.append(homeDrive); logFolder.append("\\"); logFolder.append(homeDir); logFolder.append("\\"); #endif logFolder.append("Kinect_Logs"); boost::filesystem::path p(logFolder.c_str()); boost::filesystem::create_directory(p); logFile->setText(QString::fromStdString(getNextFilename())); }
MainWindow::MainWindow(int width, int height, int fps, bool tcp) : logger(0), depthImage(width, height, QImage::Format_RGB888), rgbImage(width, height, QImage::Format_RGB888), recording(false), lastDrawn(-1), width(width), height(height), fps(fps), tcp(tcp), comms(tcp ? new Communicator : 0) { this->setMaximumSize(width * 2, height + 160); this->setMinimumSize(width * 2, height + 160); QVBoxLayout * wrapperLayout = new QVBoxLayout; QHBoxLayout * mainLayout = new QHBoxLayout; QHBoxLayout * fileLayout = new QHBoxLayout; QHBoxLayout * optionLayout = new QHBoxLayout; QHBoxLayout * buttonLayout = new QHBoxLayout; wrapperLayout->addLayout(mainLayout); depthLabel = new QLabel(this); depthLabel->setPixmap(QPixmap::fromImage(depthImage)); mainLayout->addWidget(depthLabel); imageLabel = new QLabel(this); imageLabel->setPixmap(QPixmap::fromImage(rgbImage)); mainLayout->addWidget(imageLabel); wrapperLayout->addLayout(fileLayout); wrapperLayout->addLayout(optionLayout); QLabel * logLabel = new QLabel("Log file: ", this); logLabel->setMaximumWidth(logLabel->fontMetrics().boundingRect(logLabel->text()).width()); fileLayout->addWidget(logLabel); logFile = new QLabel(this); logFile->setTextInteractionFlags(Qt::TextSelectableByMouse); logFile->setStyleSheet("border: 1px solid grey"); fileLayout->addWidget(logFile); #ifdef __APPLE__ int cushion = 25; #else int cushion = 10; #endif browseButton = new QPushButton("Browse", this); browseButton->setMaximumWidth(browseButton->fontMetrics().boundingRect(browseButton->text()).width() + cushion); connect(browseButton, SIGNAL(clicked()), this, SLOT(fileBrowse())); fileLayout->addWidget(browseButton); dateNameButton = new QPushButton("Date filename", this); dateNameButton->setMaximumWidth(dateNameButton->fontMetrics().boundingRect(dateNameButton->text()).width() + cushion); connect(dateNameButton, SIGNAL(clicked()), this, SLOT(dateFilename())); fileLayout->addWidget(dateNameButton); autoExposure = new QCheckBox("Auto Exposure"); autoExposure->setChecked(false); autoWhiteBalance = new QCheckBox("Auto White Balance"); autoWhiteBalance->setChecked(false); compressed = new QCheckBox("Compressed"); compressed->setChecked(true); memoryRecord = new QCheckBox("Record to RAM"); memoryRecord->setChecked(false); memoryStatus = new QLabel(""); connect(autoExposure, SIGNAL(stateChanged(int)), this, SLOT(setExposure())); connect(autoWhiteBalance, SIGNAL(stateChanged(int)), this, SLOT(setWhiteBalance())); connect(compressed, SIGNAL(released()), this, SLOT(setCompressed())); connect(memoryRecord, SIGNAL(stateChanged(int)), this, SLOT(setMemoryRecord())); optionLayout->addWidget(autoExposure); optionLayout->addWidget(autoWhiteBalance); optionLayout->addWidget(compressed); optionLayout->addWidget(memoryRecord); optionLayout->addWidget(memoryStatus); wrapperLayout->addLayout(buttonLayout); startStop = new QPushButton(tcp ? "Stream && Record" : "Record", this); connect(startStop, SIGNAL(clicked()), this, SLOT(recordToggle())); buttonLayout->addWidget(startStop); QPushButton * quitButton = new QPushButton("Quit", this); connect(quitButton, SIGNAL(clicked()), this, SLOT(quit())); buttonLayout->addWidget(quitButton); setLayout(wrapperLayout); startStop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); quitButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); QFont currentFont = startStop->font(); currentFont.setPointSize(currentFont.pointSize() + 8); startStop->setFont(currentFont); quitButton->setFont(currentFont); painter = new QPainter(&depthImage); painter->setPen(Qt::green); painter->setFont(QFont("Arial", 30)); painter->drawText(10, 50, "Attempting to start OpenNI2..."); depthLabel->setPixmap(QPixmap::fromImage(depthImage)); #ifndef OS_WINDOWS char * homeDir = getenv("HOME"); logFolder.append(homeDir); logFolder.append("/"); #else char * homeDrive = getenv("HOMEDRIVE"); char * homeDir = getenv("HOMEPATH"); logFolder.append(homeDrive); logFolder.append("\\"); logFolder.append(homeDir); logFolder.append("\\"); #endif logFolder.append("Kinect_Logs"); boost::filesystem::path p(logFolder.c_str()); boost::filesystem::create_directory(p); logFile->setText(QString::fromStdString(getNextFilename())); timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(timerCallback())); timer->start(15); }