#include <OSGMTDImageFileType.h>
Inheritance diagram for osg::MTDImageFileType:

Safe Store/Restore | |
| UInt64 | store (const ImagePtr &image, UChar8 *buffer, Int32 memSize=-1) |
| virtual UInt64 | maxBufferSize (const ImagePtr &image) |
| *static UInt64 | restore (ImagePtr &image, const UChar8 *buffer, Int32 memSize=-1) |
| static UInt64 | store (const ImagePtr &image, const char *mimeType, UChar8 *buffer, Int32 memSize=-1) |
Public Types | |
Flags | |
| enum | { OSG_READ_SUPPORTED = 1, OSG_WRITE_SUPPORTED = 2 } |
Public Member Functions | |
Destructor | |
| *virtual | ~MTDImageFileType (void) |
Read/Write | |
| *virtual bool | read (ImagePtr &image, const Char8 *fileName) |
| virtual bool | write (const ImagePtr &image, const Char8 *fileName) |
Buffer | |
| *virtual UInt64 | restoreData (ImagePtr &image, const UChar8 *buffer, Int32 memSize=-1) |
| virtual UInt64 | storeData (const ImagePtr &image, UChar8 *buffer, Int32 memSize=-1) |
Get Methods | |
| *const Char8 * | getMimeType (void) const |
| const std::list< IDString > & | getSuffixList (void) const |
| virtual UInt32 | getFlags (void) const |
Read/Write | |
| virtual bool | validateHeader (const Char8 *fileName, bool &implemented) |
dump | |
| *void | dump (void) |
Static Public Member Functions | |
Get Methods | |
| *static MTDImageFileType & | the (void) |
Protected Member Functions | |
Default Constructor | |
| * | MTDImageFileType (const Char8 *mimeType, const Char8 *suffixArray[], UInt16 suffixByteCount, UInt32 flags) |
Copy Constructor | |
| * | MTDImageFileType (const MTDImageFileType &obj) |
Private Types | |
| typedef ImageFileType | Inherited |
Static Private Attributes | |
| static MTDImageFileType | _the |
All the type specific code is included in the class. Does not depend on external libs.
Definition at line 56 of file OSGMTDImageFileType.h.
|
|
Definition at line 117 of file OSGMTDImageFileType.h. |
|
|
Definition at line 65 of file OSGImageFileType.h. 00066 { 00067 OSG_READ_SUPPORTED = 1, 00068 OSG_WRITE_SUPPORTED = 2 00069 };
|
|
|
Destructor Definition at line 236 of file OSGMTDImageFileType.cpp.
|
|
||||||||||||||||||||
|
Constructor used for the singleton object Definition at line 213 of file OSGMTDImageFileType.cpp. 00217 : ImageFileType ( mimeType, suffixArray, suffixByteCount, flags ) 00218 { 00219 return; 00220 }
|
|
|
Dummy Copy Constructor Definition at line 226 of file OSGMTDImageFileType.cpp. 00227 : ImageFileType(obj) 00228 { 00229 return; 00230 }
|
|
|
Class method to get the singleton Object Definition at line 98 of file OSGMTDImageFileType.cpp. References _the. 00099 { 00100 return _the; 00101 }
|
|
||||||||||||
|
Tries to fill the image object with the data read from the given fileName. Returns true on success. Implements osg::ImageFileType. Definition at line 112 of file OSGMTDImageFileType.cpp. References osg::Image::OSG_UINT8_IMAGEDATA. 00114 { 00115 bool retCode = false; 00116 std::ifstream in(fileName, std::ios::in | std::ios::binary); 00117 Head head; 00118 void *headData = (void*)(&head); 00119 unsigned dataSize, headSize = sizeof(Head); 00120 00121 if ( in && 00122 in.read(static_cast<char *>(headData), 00123 headSize) && head.netToHost() && 00124 image->set ( Image::PixelFormat(head.pixelFormat), 00125 head.width, head.height, head.depth, head.mipmapCount, 00126 head.frameCount, float(head.frameDelay) / 1000.0, 0, 00127 ( head.dataType ? Image::Type(head.dataType) : 00128 Image::OSG_UINT8_IMAGEDATA ), 00129 true, head.sideCount) && 00130 (dataSize = image->getSize()) && 00131 in.read((char *)(image->getData()), dataSize )) 00132 retCode = true; 00133 else 00134 retCode = false; 00135 00136 return retCode; 00137 }
|
|
||||||||||||
|
Tries to write the image object to the given fileName. Returns true on success. Implements osg::ImageFileType. Definition at line 144 of file OSGMTDImageFileType.cpp. 00146 { 00147 bool retCode = false; 00148 00149 std::ofstream out(fileName, std::ios::out | std::ios::binary); 00150 00151 Head head; 00152 const void *headData = (void*)(&head); 00153 unsigned dataSize = image->getSize(), headSize = sizeof(Head); 00154 00155 head.pixelFormat = image->getPixelFormat(); 00156 head.width = image->getWidth(); 00157 head.height = image->getHeight(); 00158 head.depth = image->getDepth(); 00159 head.mipmapCount = image->getMipMapCount(); 00160 head.frameCount = image->getFrameCount(); 00161 head.frameDelay = short(image->getFrameDelay() * 1000.0); 00162 head.sideCount = image->getSideCount(); 00163 head.dataType = image->getDataType(); 00164 head.hostToNet(); 00165 00166 if ( out && out.write(static_cast<const char *>(headData), headSize) && 00167 dataSize && out.write((char *)(image->getData()), dataSize) ) 00168 retCode = true; 00169 else 00170 retCode = false; 00171 00172 return retCode; 00173 }
|
|
||||||||||||||||
|
Tries to restore the image data from the given memblock. Returns the amount of data read. Reimplemented from osg::ImageFileType. Definition at line 181 of file OSGMTDImageFileType.cpp.
|
|
||||||||||||||||
|
Tries to store the image data to the given memblock. Returns the amount of data written. Reimplemented from osg::ImageFileType. Definition at line 195 of file OSGMTDImageFileType.cpp. 00198 { 00199 unsigned dataSize = image->getSize(); 00200 const UChar8 *src = image->getData(); 00201 00202 if ( dataSize && src && buffer ) 00203 memcpy( buffer, src, dataSize); 00204 00205 return dataSize; 00206 }
|
|
|
|
Get method for the suffix list container Definition at line 125 of file OSGImageFileType.cpp. References osg::ImageFileType::_suffixList. Referenced by osg::ImageFileHandler::addImageFileType(). 00126 { 00127 return _suffixList; 00128 }
|
|
|
Get method for the flags indicating read/write support. Most image types only support reading. Definition at line 116 of file OSGImageFileType.cpp. References osg::ImageFileType::_flags. Referenced by osg::ImageFileHandler::getSuffixList(). 00117 { 00118 return _flags; 00119 }
|
|
||||||||||||
|
Reimplemented in osg::GIFImageFileType, osg::JPGImageFileType, osg::PNGImageFileType, osg::SGIImageFileType, and osg::TIFImageFileType. Definition at line 132 of file OSGImageFileType.cpp. Referenced by osg::ImageFileHandler::getFileType().
|
|
||||||||||||||||
|
Tries to restore the Imagedata from the given memblock. The buffer must include a ImageFileType::Head data block. Definition at line 223 of file OSGImageFileType.cpp. References FDEBUG, FWARNING, osg::ImageFileHandler::getFileType(), osg::NullFC, osg::Image::OSG_UINT8_IMAGEDATA, osg::ImageFileType::restoreData(), and osg::ImageFileHandler::the(). Referenced by osg::ClusterViewBuffer::recv(), osg::ImageFileHandler::restore(), and osg::SimpleSceneManager::useOpenSGLogo(). 00225 { 00226 unsigned long imageSize, headSize = sizeof(Head); 00227 unsigned long size = 0, attachmentSize; 00228 Head head; 00229 const UChar8 *data = buffer ? (buffer + headSize) : 0; 00230 ImageFileType *type; 00231 const char *mimeType; 00232 Image::Type dataType; 00233 00234 if ((image != osg::NullFC) && buffer && (memSize >= headSize)) { 00235 00236 // Copy header. Otherwise netToHost would change the original 00237 // data structur. 00238 memcpy(&head,buffer,sizeof(Head)); 00239 head.netToHost(); 00240 mimeType = head.mimeType; 00241 00242 if((type = ImageFileHandler::the().getFileType(mimeType, 0))) 00243 { 00244 if (head.dataType) 00245 dataType = Image::Type(head.dataType); 00246 else 00247 dataType = Image::OSG_UINT8_IMAGEDATA; 00248 00249 image->set(Image::PixelFormat(head.pixelFormat), head.width, 00250 head.height, head.depth, head.mipmapCount, 00251 head.frameCount, float(head.frameDelay) / 1000.0, 0, 00252 dataType,true,head.sideCount ); 00253 imageSize = static_cast<unsigned long>( 00254 type->restoreData(image, data, memSize - headSize)); 00255 attachmentSize = 0; // head->attachmentSize; 00256 00257 /* 00258 if ((attachmentSize = head->attachmentSize)) 00259 { 00260 attData = (char*)(buffer + headSize + imageSize); 00261 attKey = attData; 00262 attValue = 0; 00263 for (i = 0; i < (attachmentSize-1); i++) { 00264 if (attData[i] == 0) 00265 if (attKey) { 00266 attValue = &(attData[i+1]); 00267 image->setAttachmentField (attKey,attValue); 00268 attKey = attValue = 0; 00269 } 00270 else 00271 attKey = &(attData[i+1]); 00272 } 00273 if (attKey || attValue) { 00274 FFATAL (("Attachment restore error\n")); 00275 } 00276 } 00277 */ 00278 00279 size = headSize + imageSize + attachmentSize; 00280 00281 FDEBUG (( "Restore image data: %lu (%lu/%lu/%lu)\n", 00282 size, headSize, imageSize, attachmentSize )); 00283 00284 } 00285 else 00286 { 00287 imageSize = 0; 00288 FWARNING(("Can not restore image data, invalid mimeType: %s\n", 00289 mimeType ? mimeType : "Unknown")); 00290 } 00291 00292 00293 } 00294 00295 return size; 00296 }
|
|
||||||||||||||||||||
|
Tries to store the raster data to the given mem block. Will include a ImageFileType::Head description and the data encoded as 'mimeType' Definition at line 304 of file OSGImageFileType.cpp. References osg::ImageFileHandler::getFileType(), osg::ImageFileType::store(), and osg::ImageFileHandler::the(). Referenced by osg::ClusterViewBuffer::send(), osg::ImageFileType::store(), and osg::ImageFileHandler::store(). 00306 { 00307 ImageFileType *type = ImageFileHandler::the().getFileType(mimeType); 00308 00309 return type ? type->store(image, buffer, memSize) : 0; 00310 }
|
|
||||||||||||||||
|
Tries to store the raster data to the given mem block. Will include a ImageFileType::Head description for the derived concreate mimeType. Definition at line 318 of file OSGImageFileType.cpp. References osg::ImageFileType::Head::attachmentSize, osg::ImageFileType::Head::dataType, osg::ImageFileType::Head::depth, FDEBUG, FFATAL, osg::ImageFileType::Head::frameCount, osg::ImageFileType::Head::frameDelay, osg::ImageFileType::getMimeType(), osg::ImageFileType::Head::height, osg::ImageFileType::Head::hostToNet(), osg::ImageFileType::Head::mimeType, osg::ImageFileType::Head::mipmapCount, osg::ImageFileType::Head::pixelFormat, osg::ImageFileType::Head::sideCount, osg::ImageFileType::storeData(), and osg::ImageFileType::Head::width. 00320 { 00321 Head *head; 00322 unsigned long dataSize = 0, headSize = sizeof(Head); 00323 unsigned long attachmentSize; 00324 UChar8 *dest; 00325 const UChar8 *src = image->getData(); 00326 std::map<std::string, std::string>::const_iterator aI; 00327 std::string value; 00328 00329 attachmentSize = 0; 00330 00331 // get attachment size 00332 /* 00333 ImageGenericAttPtr att=ImageGenericAttPtr::dcast( 00334 const_cast<Image*>(image.getCPtr())->findAttachment( 00335 ImageGenericAtt::getClassType().getGroupId())); 00336 if(att != NullFC) 00337 { 00338 for(i = 0; i < (att->getType().getNumFieldDescs()-1); ++i) 00339 { 00340 FieldDescription *fieldDesc=att->getType().getFieldDescription(i); 00341 Field *field=att->getField(i); 00342 if (fieldDesc && field) 00343 { 00344 field->getValueByStr(value); 00345 attachmentSize += strlen( fieldDesc->getName().str() ) + 1; 00346 attachmentSize += value.length() + 1; 00347 00348 std::cout << fieldDesc->getName().str() << std::endl; 00349 std::cout << value << std::endl; 00350 } 00351 else 00352 { 00353 FFATAL (("Invalid Attachment in ImageFileType::store()\n")); 00354 } 00355 } 00356 } 00357 */ 00358 00359 if (buffer) 00360 { 00361 head = (Head *)buffer; 00362 00363 head->pixelFormat = image->getPixelFormat(); 00364 head->width = image->getWidth(); 00365 head->height = image->getHeight(); 00366 head->depth = image->getDepth(); 00367 head->mipmapCount = image->getMipMapCount(); 00368 head->frameCount = image->getFrameCount(); 00369 head->frameDelay = short(image->getFrameDelay() * 1000.0); 00370 head->sideCount = image->getSideCount(); 00371 head->dataType = image->getDataType(); 00372 head->attachmentSize = static_cast<unsigned short>(attachmentSize); 00373 head->hostToNet(); 00374 00375 strcpy(head->mimeType, getMimeType()); 00376 00377 dest = (UChar8 *) (buffer + headSize); 00378 00379 if (src) 00380 dataSize = static_cast<unsigned long>( 00381 storeData(image, dest, memSize - headSize)); 00382 00383 dest = (UChar8 *) (buffer + headSize + dataSize); 00384 00385 /* 00386 if(att != NullFC) 00387 { 00388 for(i = 0; i < (att->getType().getNumFieldDescs()-1); ++i) 00389 { 00390 FieldDescription *fieldDesc=att->getType().getFieldDescription(i); 00391 Field *field=att->getField(i); 00392 if (field && fieldDesc) 00393 { 00394 field->getValueByStr(value); 00395 00396 l = strlen( fieldDesc->getName().str() ); 00397 for (i = 0; i < l; i++) 00398 *dest++ = fieldDesc->getName().str()[i]; 00399 *dest++ = 0; 00400 l = value.length(); 00401 for (i = 0; i < l; i++) 00402 *dest++ = value[i]; 00403 *dest++ = 0; 00404 } 00405 else 00406 { 00407 FFATAL (("Invalid Attachment in ImageFileType::store()\n")); 00408 } 00409 } 00410 } 00411 */ 00412 00413 FDEBUG (( "Store image data: %lu (%lu/%lu/%lu)\n", 00414 headSize + dataSize + attachmentSize, headSize, dataSize, 00415 attachmentSize )); 00416 } 00417 else { 00418 FFATAL (("Invalid buffer in ImageFileType::store()\n")); 00419 } 00420 00421 return (headSize + dataSize + attachmentSize); 00422 00423 }
|
|
|
Returns the max buffer size needed to store the Image (Head + mimeType specific data block) Definition at line 430 of file OSGImageFileType.cpp. References FINFO. Referenced by osg::ClusterViewBuffer::send(), and osg::ImageFileHandler::store(). 00431 { 00432 std::string value; 00433 unsigned long size, attachmentSize; 00434 unsigned long imageSize = image->getSize(), headSize = sizeof(Head); 00435 00436 std::map<std::string, std::string>::const_iterator aI; 00437 00438 attachmentSize = 0; 00439 00440 // get attachment size 00441 /* 00442 ImageGenericAttPtr att=ImageGenericAttPtr::dcast( 00443 const_cast<Image*>(image.getCPtr())->findAttachment( 00444 ImageGenericAtt::getClassType().getGroupId())); 00445 if(att != NullFC) 00446 { 00447 for(i = 0; i < (att->getType().getNumFieldDescs()-1); ++i) 00448 { 00449 FieldDescription *fieldDesc=att->getType().getFieldDescription(i); 00450 Field *field=att->getField(i); 00451 if (field && fieldDesc) 00452 { 00453 field->getValueByStr(value); 00454 attachmentSize += strlen( fieldDesc->getName().str() ) + 1; 00455 attachmentSize += value.length() + 1; 00456 } 00457 else 00458 { 00459 FFATAL (("Invalid Attachment in ImageFileType::maxBufferSize()\n")); 00460 } 00461 } 00462 } 00463 */ 00464 00465 size = headSize + imageSize + attachmentSize; 00466 00467 FINFO (( "ImageFileType::maxBufferSize(): %lu (%lu/%lu/%lu)\n", 00468 size, headSize, imageSize, attachmentSize )); 00469 00470 return size; 00471 }
|
|
|
The dump method just writes some object debugging info to the LOG stream Definition at line 477 of file OSGImageFileType.cpp. References osg::ImageFileType::_suffixList, osg::ImageFileType::getMimeType(), osg::LOG_DEBUG, and SLOG. 00478 { 00479 std::list<IDString>::iterator sI; 00480 00481 SLOG << getMimeType(); 00482 00483 if(_suffixList.empty()) 00484 { 00485 SLOG << ": Suffix: "; 00486 for(sI = _suffixList.begin(); sI != _suffixList.end(); sI++) 00487 { 00488 Log().stream(OSG::LOG_DEBUG) << sI->str() << " "; 00489 } 00490 } 00491 00492 std::cerr << std::endl; 00493 }
|
|
|
Referenced by the(). |
1.4.3