⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readerwriterqt.cpp

📁 最新osg包
💻 CPP
📖 第 1 页 / 共 2 页
字号:
                  }                  if (devices_list.size() > 1)                  {                      // Audio                      OSG_SGDeviceList& audio_device_list = devices_list[1];                      // Print                      osg::notify(osg::ALWAYS) << std::endl;                      osg::notify(osg::ALWAYS) << "Audio Component/Input IDs follow: " << std::endl;                      osg::notify(osg::ALWAYS) << std::endl;                      for (unsigned int device_input = 0; device_input < audio_device_list.size(); ++device_input)                      {                          OSG_SGDevicePair device_pair = audio_device_list[device_input];                          osg::notify(osg::ALWAYS) << device_pair.first.c_str() << "    " << device_pair.second.c_str() << std::endl;                      }                  }              }              return ReadResult::FILE_NOT_HANDLED;          }          else          {              osg::notify(osg::DEBUG_INFO) << " available Video DigitizerComponents : " << num_video_components << std::endl;              if (num_video_components)              {                  // Note from Riccardo Corsi                   // Quicktime initialization is done here, when a media is found                  // and before any image or movie is loaded.                   // After the first call the function does nothing.                   // The cleaning up is left to the QuicktimeExitObserver (see below)                  initQuicktime();                  //                  QuicktimeLiveImageStream* p_qt_image_stream = new QuicktimeLiveImageStream(osgDB::getNameLessExtension(file));                  // add the media to the observer for proper clean up on exit                  _qtExitObserver.addMedia(p_qt_image_stream);                  return p_qt_image_stream;              }              else              {                  osg::notify(osg::DEBUG_INFO) << "No available Video DigitizerComponents : " <<  std::endl;                  return ReadResult::FILE_NOT_HANDLED;              }          }      }      // Not an encoded "live" psuedo file - so check a real file exists      std::string fileName = osgDB::findDataFile( file,  options);      if (fileName.empty()) return ReadResult::FILE_NOT_FOUND;      // Note from Riccardo Corsi       // Quicktime initialization is done here, when a media is found      // and before any image or movie is loaded.       // After the first call the function does nothing.       // The cleaning up is left to the QuicktimeExitObserver (see below)      initQuicktime();      // if the file is a movie file then load as an ImageStream.      if (acceptsMovieExtension(ext))      {         // note from Robert Osfield when integrating, we should probably have so         // error handling mechanism here.  Possibly move the load from         // the constructor to a seperate load method, and have a valid         // state on the ImageStream... will integrated as is right now         // to get things off the ground.         QuicktimeImageStream* moov = new QuicktimeImageStream(fileName);         // moov->play();         // add the media to the observer for proper clean up on exit         _qtExitObserver.addMedia(moov);         return moov;      }         QuicktimeImportExport importer;        std::ifstream is;        is.open (fileName.c_str(), std::ios::binary | std::ios::in );        is.seekg (0, std::ios::end);        long length = is.tellg();        is.seekg (0, std::ios::beg);        osg::ref_ptr<osg::Image> image = importer.readFromStream(is, fileName, length);        is.close();        if (!importer.success() || (image == NULL)) {            osg::notify(osg::WARN) << "Error reading file " << file << " : " << importer.getLastErrorString() << std::endl;            return ReadResult::ERROR_IN_READING_FILE;        }      _qtExitObserver.addMedia(image.get());      return image.release();   }       virtual ReadResult readImage (std::istream& is, const osgDB::ReaderWriter::Options* options=NULL) const     {        std::string filename = "";        long sizeHint(0);        // check options for a file-type-hint         if (options) {            std::istringstream iss(options->getOptionString());            std::string opt;            while (iss >> opt)             {                int index = opt.find( "=" );                if( opt.substr( 0, index ) == "filename" ||                    opt.substr( 0, index ) == "FILENAME" )                {                    filename = opt.substr( index+1 );                } else if( opt.substr( 0, index ) == "size" ||                    opt.substr( 0, index ) == "SIZE" )                {                    std::string sizestr = opt.substr( index+1 );                    sizeHint = atol(sizestr.c_str());                }            }        }                QuicktimeImportExport importer;        osg::ref_ptr<osg::Image> image = importer.readFromStream(is, filename, sizeHint);                if (!importer.success() || (image == NULL)) {            osg::notify(osg::WARN) << "Error reading from stream "  << importer.getLastErrorString() << std::endl;            return ReadResult::ERROR_IN_READING_FILE;        }        _qtExitObserver.addMedia(image.get());        return image.release();            }    virtual WriteResult writeImage(const osg::Image &img,const std::string& fileName, const osgDB::ReaderWriter::Options*) const    {        std::string ext = osgDB::getFileExtension(fileName);        if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED;        initQuicktime();        //Buidl map  of extension <-> osFileTypes        std::map<std::string, OSType> extmap;        extmap.insert(std::pair<std::string, OSType>("jpg",  kQTFileTypeJPEG));        extmap.insert(std::pair<std::string, OSType>("jpeg", kQTFileTypeJPEG));        extmap.insert(std::pair<std::string, OSType>("bmp",  kQTFileTypeBMP));        extmap.insert(std::pair<std::string, OSType>("tif",  kQTFileTypeTIFF));        extmap.insert(std::pair<std::string, OSType>("tiff", kQTFileTypeTIFF));        extmap.insert(std::pair<std::string, OSType>("png",  kQTFileTypePNG));        extmap.insert(std::pair<std::string, OSType>("gif",  kQTFileTypeGIF));        extmap.insert(std::pair<std::string, OSType>("psd",  kQTFileTypePhotoShop));        extmap.insert(std::pair<std::string, OSType>("sgi",  kQTFileTypeSGIImage));                std::map<std::string, OSType>::iterator cur = extmap.find(ext);        // can not handle this type of file, perhaps a movie?        if (cur == extmap.end())         return WriteResult::FILE_NOT_HANDLED;        std::ofstream os(fileName.c_str(), std::ios::binary | std::ios::trunc | std::ios::out);        if(os.good())         {            QuicktimeImportExport exporter;            exporter.writeToStream(os, const_cast<osg::Image*>(&img), fileName);                        if (exporter.success())                 return WriteResult::FILE_SAVED;        }         return WriteResult::ERROR_IN_WRITING_FILE;     }       virtual WriteResult writeImage (const osg::Image& img, std::ostream& os, const Options* options=NULL) const    {        std::string filename = "file.jpg"; // use jpeg if not otherwise specified                if (options) {            std::istringstream iss(options->getOptionString());            std::string opt;            while (iss >> opt)             {                int index = opt.find( "=" );                if( opt.substr( 0, index ) == "filename" ||                    opt.substr( 0, index ) == "FILENAME" )                {                    filename = opt.substr( index+1 );                }            }        }                QuicktimeImportExport exporter;        exporter.writeToStream(os, const_cast<osg::Image*>(&img), filename);                    if (exporter.success())             return WriteResult::FILE_SAVED;                return WriteResult::ERROR_IN_WRITING_FILE;             }    mutable QuicktimeExitObserver _qtExitObserver;};// now register with Registry to instantiate the above// reader/writer.REGISTER_OSGPLUGIN(quicktime, ReaderWriterQT)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -