Changeset 13041 for OpenSceneGraph/trunk/src/osgDB/InputStream.cpp
- Timestamp:
- 03/21/12 18:36:20 (15 months ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/src/osgDB/InputStream.cpp (modified) (26 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgDB/InputStream.cpp
r13011 r13041 29 29 if ( !options ) return; 30 30 _options = options; 31 31 32 32 std::string schema; 33 33 if ( options->getPluginStringData("ForceReadingImage")=="true" ) … … 44 44 } 45 45 } 46 46 47 47 if ( schema.empty() ) 48 48 { … … 224 224 { 225 225 osg::ref_ptr<osg::Array> array = NULL; 226 226 227 227 unsigned int id = 0; 228 228 *this >> PROPERTY("ArrayID") >> id; 229 229 230 230 ArrayMap::iterator itr = _arrayMap.find( id ); 231 231 if ( itr!=_arrayMap.end() ) … … 233 233 return itr->second.get(); 234 234 } 235 235 236 236 DEF_MAPPEE(ArrayType, type); 237 237 *this >> type; … … 388 388 throwException( "InputStream::readArray(): Unsupported array type." ); 389 389 } 390 390 391 391 if ( getException() ) return NULL; 392 392 _arrayMap[id] = array; … … 398 398 { 399 399 osg::ref_ptr<osg::PrimitiveSet> primitive = NULL; 400 400 401 401 DEF_MAPPEE(PrimitiveType, type); 402 402 DEF_MAPPEE(PrimitiveType, mode); 403 403 *this >> type >> mode; 404 404 405 405 switch ( type.get() ) 406 406 { … … 472 472 throwException( "InputStream::readPrimitiveSet(): Unsupported array type." ); 473 473 } 474 474 475 475 if ( getException() ) return NULL; 476 476 return primitive.release(); 477 477 } 478 478 479 osg::Image* InputStream::readImage(bool readFromExternal) 479 osg::Image* InputStream::readImage(bool readFromExternal) 480 480 { 481 481 … … 499 499 500 500 osg::ref_ptr<osg::Image> image = NULL; 501 501 502 502 switch ( decision ) 503 503 { … … 506 506 { 507 507 image = new osg::Image; 508 508 509 509 // _origin, _s & _t & _r, _internalTextureFormat 510 510 int origin, s, t, r, internalFormat; 511 511 *this >> origin >> s >> t >> r >> internalFormat; 512 512 513 513 // _pixelFormat, _dataType, _packing, _allocationMode 514 514 int pixelFormat, dataType, packing, mode; 515 515 *this >> pixelFormat >> dataType >> packing >> mode; 516 516 517 517 // _data 518 518 unsigned int size = 0; *this >> size; … … 523 523 throwException( "InputStream::readImage() Out of memory." ); 524 524 if ( getException() ) return NULL; 525 525 526 526 readCharArray( data, size ); 527 527 image->setOrigin( (osg::Image::Origin)origin ); … … 555 555 } 556 556 readCharArray( data, size ); 557 557 558 558 std::string ext = osgDB::getFileExtension( name ); 559 559 osgDB::ReaderWriter* reader = … … 563 563 std::stringstream inputStream; 564 564 inputStream.write( data, size ); 565 565 566 566 osgDB::ReaderWriter::ReadResult rr = reader->readImage( inputStream ); 567 567 if ( rr.validImage() ) … … 588 588 break; 589 589 } 590 590 591 591 if ( readFromExternal ) 592 592 { … … 611 611 *this >> className >> BEGIN_BRACKET >> PROPERTY("UniqueID") >> id; 612 612 if ( getException() ) return NULL; 613 613 614 614 IdentifierMap::iterator itr = _identifierMap.find( id ); 615 615 if ( itr!=_identifierMap.end() ) … … 636 636 } 637 637 _fields.push_back( className ); 638 638 639 639 osg::ref_ptr<osg::Object> obj = existingObj ? existingObj : wrapper->getProto()->cloneType(); 640 640 _identifierMap[id] = obj; … … 652 652 } 653 653 _fields.push_back( assocWrapper->getName() ); 654 654 655 655 assocWrapper->read( *this, *obj ); 656 656 if ( getException() ) return NULL; 657 657 658 658 _fields.pop_back(); 659 659 } … … 670 670 { 671 671 if ( line[0]=='#' ) continue; // Comment 672 672 673 673 StringList keyAndValue; 674 674 split( line, keyAndValue, '=' ); 675 675 if ( keyAndValue.size()<2 ) continue; 676 676 677 677 setWrapperSchema( osgDB::trimEnclosingSpaces(keyAndValue[0]), 678 678 osgDB::trimEnclosingSpaces(keyAndValue[1]) ); … … 684 684 _fields.clear(); 685 685 _fields.push_back( "Start" ); 686 686 687 687 ReadType type = READ_UNKNOWN; 688 688 _in = inIterator; … … 692 692 693 693 _in->setInputStream(this); 694 694 695 695 // Check OSG header information 696 696 unsigned int version = 0; … … 700 700 *this >> typeValue >> version; 701 701 type = static_cast<ReadType>(typeValue); 702 702 703 703 unsigned int attributes; *this >> attributes; 704 704 if ( attributes&0x2 ) _useSchemaData = true; … … 710 710 else if ( typeString=="Image" ) type = READ_IMAGE; 711 711 else if ( typeString=="Object" ) type = READ_OBJECT; 712 712 713 713 std::string osgName, osgVersion; 714 714 *this >> PROPERTY("#Version") >> version; 715 715 *this >> PROPERTY("#Generator") >> osgName >> osgVersion; 716 716 } 717 717 718 718 // Record file version for back-compatibility checking of wrappers 719 719 _fileVersion = version; … … 726 726 if ( !isBinary() ) return; 727 727 _fields.clear(); 728 728 729 729 std::string compressorName; *this >> compressorName; 730 730 if ( compressorName!="0" ) … … 732 732 std::string data; 733 733 _fields.push_back( "Decompression" ); 734 734 735 735 BaseCompressor* compressor = Registry::instance()->getObjectWrapperManager()->findCompressor(compressorName); 736 736 if ( !compressor ) … … 739 739 << compressorName << std::endl; 740 740 } 741 741 742 742 if ( !compressor->decompress(*(_in->getStream()), data) ) 743 743 throwException( "InputStream: Failed to decompress stream." ); … … 748 748 _fields.pop_back(); 749 749 } 750 750 751 751 if ( _useSchemaData ) 752 752 { … … 770 770 return; 771 771 } 772 772 773 773 StringList schema, methods, keyAndValue; 774 774 std::vector<int> types;
