bool ImageIcon::show(const Glib::ustring &fileName) { if (!Glib::file_test(fileName, Glib::FILE_TEST_EXISTS)) return false; gchar *fName = (gchar *)fileName.c_str(); //g_message("fname:%s\n", fName); if (Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)) { struct stat info; if (stat(fName, &info)) { Glib::ustring err = "cannot get file info"; showBrokenImage(err); return false; } long fileLen = info.st_size; if (fileLen > 0x150000L) { Glib::ustring err = "File too large"; showBrokenImage(err); return false; } } Glib::ustring svg = ".svg"; Glib::ustring svgz = ".svgz"; if (hasSuffix(fileName, svg) || hasSuffix(fileName, svgz) ) { if (!showSvgFile(fileName)) { showBrokenImage(bitmapError); return false; } return true; } else if (isValidImageIconFile(fileName)) { if (!showBitmap(fileName)) { showBrokenImage(bitmapError); return false; } return true; } else { showBrokenImage("unsupported file type"); return false; } }
/* * Open a file for reading. 'path' is the file to open, and 'mode' should * be either "r" or "rb". * * If the file at 'path' does not exist, we append the ".gz" suffix (if 'path' * doesn't already have it) and try again. So if you pass "foo" as 'path', * this will open either "foo" or "foo.gz". */ cfp *cfopen_read(const char *path, const char *mode) { cfp *fp; #ifdef HAVE_LIBZ if (hasSuffix(path, ".gz")) fp = cfopen(path, mode, 1); else #endif { fp = cfopen(path, mode, 0); #ifdef HAVE_LIBZ if (fp == NULL) { int fnamelen = strlen(path) + 4; char *fname = malloc(fnamelen); if (fname == NULL) die_horribly(NULL, modulename, "Out of memory\n"); snprintf(fname, fnamelen, "%s%s", path, ".gz"); fp = cfopen(fname, mode, 1); free(fname); } #endif } return fp; }
/* * Open a file for reading. 'path' is the file to open, and 'mode' should * be either "r" or "rb". * * If the file at 'path' does not exist, we append the ".gz" suffix (if 'path' * doesn't already have it) and try again. So if you pass "foo" as 'path', * this will open either "foo" or "foo.gz". */ cfp * cfopen_read(const char *path, const char *mode) { cfp *fp; #ifdef HAVE_LIBZ if (hasSuffix(path, ".gz")) fp = cfopen(path, mode, 1); else #endif { fp = cfopen(path, mode, 0); #ifdef HAVE_LIBZ if (fp == NULL) { char *fname; fname = psprintf("%s.gz", path); fp = cfopen(fname, mode, 1); free(fname); } #endif } return fp; }
bool LibraryModule::CompileUnit::isNeededForExporter (ProjectExporter& exporter) const { if ((hasSuffix (file, "_OSX") && ! exporter.isOSX()) || (hasSuffix (file, "_iOS") && ! exporter.isiOS()) || (hasSuffix (file, "_Windows") && ! exporter.isWindows()) || (hasSuffix (file, "_Linux") && ! exporter.isLinux()) || (hasSuffix (file, "_Android") && ! exporter.isAndroid())) return false; auto targetType = Project::getTargetTypeFromFilePath (file, false); if (targetType != ProjectType::Target::unspecified && ! exporter.shouldBuildTargetType (targetType)) return false; return exporter.usesMMFiles() ? isCompiledForObjC : isCompiledForNonObjC; }
vector<string> Gallery::getFileList(){ if (isReady() && _fileList.size()==0){ DIR *dir; struct dirent *ent; if ( (dir = opendir ( (GalleryManager::Instance()->getGalleriesPath() +"/"+ getName() ).c_str() )) != NULL) { /* print all the files and directories within directory */ while ((ent = readdir (dir)) != NULL) { string str(ent->d_name); if (hasSuffix(str,".jpg") || hasSuffix(str,".png")) _fileList.push_back(str); } closedir (dir); } else { //TODO cant open dir } } return _fileList; }
/// \fixme This function is almost an exact duplicate of SVGPreview::set() in ui/dialog/filedialogimpl-gtkmm.cpp. bool ImageIcon::show(const Glib::ustring &fileName) { if (!Glib::file_test(fileName, Glib::FILE_TEST_EXISTS)) { showBrokenImage("File does not exist"); return false; } if (Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)) { gchar *fName = const_cast<gchar *>(fileName.c_str()); // this const-cast seems not necessary, was it put there because of older sys/stat.h version? struct stat info; if (stat(fName, &info)) // stat returns 0 upon success { showBrokenImage("Cannot get file info"); return false; } if (info.st_size > 0x150000L) { showBrokenImage("File too large"); return false; } } Glib::ustring svg = ".svg"; Glib::ustring svgz = ".svgz"; if (hasSuffix(fileName, svg) || hasSuffix(fileName, svgz)) { if (!showSvgFile(fileName)) { showBrokenImage(bitmapError); return false; } return true; } else if (isValidImageIconFile(fileName)) { if (!showBitmap(fileName)) { showBrokenImage(bitmapError); return false; } return true; } else { showBrokenImage("unsupported file type"); return false; } }
bool isValidImageFile(const Glib::ustring &fileName) { std::vector<Gdk::PixbufFormat>formats = Gdk::Pixbuf::get_formats(); for (unsigned int i=0; i<formats.size(); i++) { Gdk::PixbufFormat format = formats[i]; std::vector<Glib::ustring>extensions = format.get_extensions(); for (unsigned int j=0; j<extensions.size(); j++) { Glib::ustring ext = extensions[j]; if (hasSuffix(fileName, ext)) return true; } } return false; }
bool checkJointNames(const JointTrajectoryConstPtr& trajectory) { bool rtn = false; // The maximum number of joints in the motoman controller is fixed if ((int)trajectory->joint_names.size() <= motoman::parameters::Parameters::JOINT_SUFFIXES_SIZE) { rtn = true; } else { rtn = false; ROS_WARN("Size of joint names: %zd, exceeds motoman size: %d", trajectory->joint_names.size(), motoman::parameters::Parameters::JOINT_SUFFIXES_SIZE); } if (rtn) { for(unsigned int i = 0; i<trajectory->joint_names.size(); i++) { string suffix(motoman::parameters::Parameters::JOINT_SUFFIXES[i]); if ( hasSuffix(trajectory->joint_names[i], suffix ) ) { rtn = true; } else { rtn = false; break; } } } return rtn; }
bool LibraryModule::CompileUnit::isNeededForExporter (ProjectExporter& exporter) const { Project& project = exporter.getProject(); if ((hasSuffix (file, "_OSX") && ! exporter.isOSX()) || (hasSuffix (file, "_iOS") && ! exporter.isiOS()) || (hasSuffix (file, "_Windows") && ! exporter.isWindows()) || (hasSuffix (file, "_Linux") && ! exporter.isLinux()) || (hasSuffix (file, "_Android") && ! exporter.isAndroid()) || (hasSuffix (file, "_AU") && ! (project.shouldBuildAU() .getValue() && exporter.supportsAU())) || (hasSuffix (file, "_AUv3") && ! (project.shouldBuildAUv3().getValue() && exporter.supportsAUv3())) || (hasSuffix (file, "_AAX") && ! (project.shouldBuildAAX() .getValue() && exporter.supportsAAX())) || (hasSuffix (file, "_RTAS") && ! (project.shouldBuildRTAS().getValue() && exporter.supportsRTAS())) || (hasSuffix (file, "_VST2") && ! (project.shouldBuildVST() .getValue() && exporter.supportsVST())) || (hasSuffix (file, "_VST3") && ! (project.shouldBuildVST3().getValue() && exporter.supportsVST3())) || (hasSuffix (file, "_Standalone") && ! (project.shouldBuildStandalone().getValue() && exporter.supportsStandalone()))) return false; return exporter.usesMMFiles() ? isCompiledForObjC : isCompiledForNonObjC; }
/** * Main application entry point. * * Accepted argumemnts: * - cpu Perform depth processing with the CPU. * - gl Perform depth processing with OpenGL. * - cl Perform depth processing with OpenCL. * - <number> Serial number of the device to open. * - -noviewer Disable viewer window. * - -streamer Enable UDP Streaming of captured images. * - -recorder Enable recording of captured images. * - -replay Enable replay of captured images. */ int main(int argc, char *argv[]) /// [main] { std::string program_path(argv[0]); std::cerr << "Version: " << LIBFREENECT2_VERSION << std::endl; std::cerr << "Environment variables: LOGFILE=<protonect.log>" << std::endl; std::cerr << "Usage: " << program_path << " [-gpu=<id>] [gl | cl | clkde | cuda | cudakde | cpu] [<device serial>]" << std::endl; std::cerr << " [-noviewer] [-norgb | -nodepth] [-help] [-version]" << std::endl; std::cerr << " [-recorder] [-streamer] [-replay]" << std::endl; std::cerr << " [-frames <number of frames to process>]" << std::endl; std::cerr << "To pause and unpause: pkill -USR1 ProtonectSR" << std::endl; size_t executable_name_idx = program_path.rfind("ProtonectSR"); const std::string prog(argv[0]); std::string binpath = "/"; if(executable_name_idx != std::string::npos) { binpath = program_path.substr(0, executable_name_idx); } #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) // avoid flooing the very slow Windows console with debug messages libfreenect2::setGlobalLogger(libfreenect2::createConsoleLogger(libfreenect2::Logger::Info)); #else // create a console logger with debug level (default is console logger with info level) /// [logging] libfreenect2::setGlobalLogger(libfreenect2::createConsoleLogger(libfreenect2::Logger::Debug)); /// [logging] #endif /// [file logging] MyFileLogger *filelogger = new MyFileLogger(getenv("LOGFILE")); if (filelogger->good()) libfreenect2::setGlobalLogger(filelogger); else delete filelogger; /// [file logging] /// [context] libfreenect2::Freenect2 freenect2; // TODO: enable on merge //libfreenect2::Freenect2Replay freenect2replay; libfreenect2::Freenect2Device *dev = 0; libfreenect2::PacketPipeline *pipeline = 0; /// [context] std::string serial = ""; bool viewer_enabled = true; bool streamer_enabled = false; bool recorder_enabled = false; bool replay_enabled = false; bool enable_rgb = true; bool enable_depth = true; int deviceId = -1; size_t framemax = -1; for(int argI = 1; argI < argc; ++argI) { const std::string arg(argv[argI]); if(arg == "-help" || arg == "--help" || arg == "-h" || arg == "-v" || arg == "--version" || arg == "-version") { // Just let the initial lines display at the beginning of main return 0; } else if(arg.find("-gpu=") == 0) { if (pipeline) { std::cerr << "-gpu must be specified before pipeline argument" << std::endl; return -1; } deviceId = atoi(argv[argI] + 5); } else if(arg == "cpu") { if(!pipeline) /// [pipeline] pipeline = new libfreenect2::CpuPacketPipeline(); /// [pipeline] } else if(arg == "gl") { #ifdef LIBFREENECT2_WITH_OPENGL_SUPPORT if(!pipeline) pipeline = new libfreenect2::OpenGLPacketPipeline(); #else std::cout << "OpenGL pipeline is not supported!" << std::endl; #endif } else if(arg == "cl") { #ifdef LIBFREENECT2_WITH_OPENCL_SUPPORT if(!pipeline) pipeline = new libfreenect2::OpenCLPacketPipeline(deviceId); #else std::cout << "OpenCL pipeline is not supported!" << std::endl; #endif } else if(arg == "clkde") { #ifdef LIBFREENECT2_WITH_OPENCL_SUPPORT if(!pipeline) pipeline = new libfreenect2::OpenCLKdePacketPipeline(deviceId); #else std::cout << "OpenCL pipeline is not supported!" << std::endl; #endif } else if(arg == "cuda") { #ifdef LIBFREENECT2_WITH_CUDA_SUPPORT if(!pipeline) pipeline = new libfreenect2::CudaPacketPipeline(deviceId); #else std::cout << "CUDA pipeline is not supported!" << std::endl; #endif } else if(arg == "cudakde") { #ifdef LIBFREENECT2_WITH_CUDA_SUPPORT if(!pipeline) pipeline = new libfreenect2::CudaKdePacketPipeline(deviceId); #else std::cout << "CUDA pipeline is not supported!" << std::endl; #endif } else if(arg.find_first_not_of("0123456789") == std::string::npos) //check if parameter could be a serial number { serial = arg; } else if(arg == "-noviewer" || arg == "--noviewer") { viewer_enabled = false; } else if(arg == "-norgb" || arg == "--norgb") { enable_rgb = false; } else if(arg == "-nodepth" || arg == "--nodepth") { enable_depth = false; } else if(arg == "-frames") { ++argI; framemax = strtol(argv[argI], NULL, 0); if (framemax == 0) { std::cerr << "invalid frame count '" << argv[argI] << "'" << std::endl; return -1; } } else if(arg == "-streamer" || arg == "--streamer" || prog == "freenect2-stream") { streamer_enabled = true; } else if(arg == "-recorder" || arg == "--recorder" || prog == "freenect2-record") { recorder_enabled = true; } else if(arg == "-replay" || arg == "--replay" || prog == "freenect2-replay") { replay_enabled = true; } else { std::cout << "Unknown argument: " << arg << std::endl; } } if (!enable_rgb && !enable_depth) { std::cerr << "Disabling both streams is not allowed!" << std::endl; return -1; } /// [discovery] if(replay_enabled == false) { if(freenect2.enumerateDevices() == 0) { std::cout << "no device connected!" << std::endl; return -1; } if(serial == "") { serial = freenect2.getDefaultDeviceSerialNumber(); } } /// [discovery] if(replay_enabled == false) { if(pipeline) { /// [open] dev = freenect2.openDevice(serial, pipeline); /// [open] } else { dev = freenect2.openDevice(serial); } } else { DIR *d; struct dirent *dir; std::vector<std::string> frame_filenames; d = opendir("recordings/depth"); if(!d) { std::cerr << "Could not open directory " << dir << " for replay." << std::endl; exit(1); } while((dir = readdir(d)) != NULL) { std::string name = dir->d_name; if(hasSuffix(name, ".depth")) { frame_filenames.push_back(name); } else { std::cerr << "Skipping currently unsupported frame filename: " << name << std::endl; } } // TODO: enable on merge /* if(pipeline) { /// [open] dev = freenect2replay.openDevice(frame_filenames, pipeline); /// [open] } else { dev = freenect2replay.openDevice(frame_filenames); } */ } if(dev == 0) { std::cout << "failure opening device!" << std::endl; return -1; } devtopause = dev; signal(SIGINT,sigint_handler); #ifdef SIGUSR1 signal(SIGUSR1, sigusr1_handler); #endif protonect_shutdown = false; /// [listeners] int types = 0; if (enable_rgb) types |= libfreenect2::Frame::Color; if (enable_depth) types |= libfreenect2::Frame::Ir | libfreenect2::Frame::Depth; libfreenect2::SyncMultiFrameListener listener(types); libfreenect2::FrameMap frames; dev->setColorFrameListener(&listener); dev->setIrAndDepthFrameListener(&listener); /// [listeners] /// [start] if (enable_rgb && enable_depth) { if (!dev->start()) return -1; } else { if (!dev->startStreams(enable_rgb, enable_depth)) return -1; } std::cout << "device serial: " << dev->getSerialNumber() << std::endl; std::cout << "device firmware: " << dev->getFirmwareVersion() << std::endl; /// [start] /// [registration setup] libfreenect2::Registration* registration = new libfreenect2::Registration(dev->getIrCameraParams(), dev->getColorCameraParams()); libfreenect2::Frame undistorted(512, 424, 4), registered(512, 424, 4); /// [registration setup] size_t framecount = 0; #ifdef EXAMPLES_WITH_OPENGL_SUPPORT Viewer viewer; if (viewer_enabled) viewer.initialize(); #else viewer_enabled = false; #endif Streamer streamer; // have to declare it outside statements to be accessible everywhere Recorder recorder; if(streamer_enabled) { streamer.initialize(); } if(recorder_enabled) { recorder.initialize(); } /// [loop start] while(!protonect_shutdown && (framemax == (size_t)-1 || framecount < framemax)) { if (!listener.waitForNewFrame(frames, 10*1000)) // 10 sconds { std::cout << "timeout!" << std::endl; return -1; } libfreenect2::Frame *rgb = frames[libfreenect2::Frame::Color]; libfreenect2::Frame *ir = frames[libfreenect2::Frame::Ir]; libfreenect2::Frame *depth = frames[libfreenect2::Frame::Depth]; /// [loop start] if (enable_rgb && enable_depth) { /// [registration] registration->apply(rgb, depth, &undistorted, ®istered); /// [registration] } framecount++; if (streamer_enabled) { streamer.stream(depth); } if (recorder_enabled) { // TODO: add recording timestamp if max frame number reached // + avoid recording new ones recorder.record(depth, "depth"); recorder.record(®istered, "registered"); // recorder.record(rgb,"rgb"); recorder.registTimeStamp(); } if (!viewer_enabled) { if (framecount % 100 == 0) std::cout << "The viewer is turned off. Received " << framecount << " frames. Ctrl-C to stop." << std::endl; listener.release(frames); continue; } #ifdef EXAMPLES_WITH_OPENGL_SUPPORT if (enable_rgb) { viewer.addFrame("RGB", rgb); } if (enable_depth) { viewer.addFrame("ir", ir); viewer.addFrame("depth", depth); } if (enable_rgb && enable_depth) { viewer.addFrame("registered", ®istered); } protonect_shutdown = protonect_shutdown || viewer.render(); #endif /// [loop end] listener.release(frames); /** libfreenect2::this_thread::sleep_for(libfreenect2::chrono::milliseconds(100)); */ } /// [loop end] if (recorder_enabled) { recorder.saveTimeStamp(); } // TODO: restarting ir stream doesn't work! // TODO: bad things will happen, if frame listeners are freed before dev->stop() :( /// [stop] dev->stop(); dev->close(); /// [stop] delete registration; return 0; }
bool String::hasSuffix(const String &x) const { return hasSuffix(x.c_str()); }
int isPlaylist(char * utf8file) { if(isFile(utf8file,NULL)) { return hasSuffix(utf8file,PLAYLIST_FILE_SUFFIX); } return 0; }