#include <OSGJPGImageFileType.h>

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 | ~JPGImageFileType (void) |
Get Method | |
| void | setQuality (UInt32 cl) |
| UInt32 | getQuality (void) |
Read/Write | |
| virtual bool | validateHeader (const Char8 *fileName, bool &implemented) |
| virtual bool | read (ImagePtr &image, std::istream &is, const std::string &mimetype) |
| virtual bool | write (const ImagePtr &image, std::ostream &os, const std::string &mimetype) |
| virtual std::string | determineMimetypeFromStream (std::istream &is) |
Buffer | |
| virtual UInt64 | restoreData (ImagePtr &image, const UChar8 *buffer, Int32 memSize=-1) |
| virtual UInt64 | storeData (const ImagePtr &image, UChar8 *buffer, Int32 memSize=-1) |
Set | |
| void | setOptions (const Char8 *options) |
Get Methods | |
| const Char8 * | getMimeType (void) const |
| const std::list< IDString > & | getSuffixList (void) const |
| virtual UInt32 | getFlags (void) const |
| const Char8 * | getOptions (void) |
Read/Write | |
| virtual bool | read (ImagePtr &image, const Char8 *fileName) |
| virtual bool | write (const ImagePtr &image, const Char8 *fileName) |
dump | |
| void | dump (void) |
Static Public Member Functions | |
Get Method | |
| static JPGImageFileType & | the (void) |
Protected Member Functions | |
Default Constructor | |
| JPGImageFileType (const Char8 *mimeType, const Char8 *suffixArray[], UInt16 suffixByteCount, UInt32 flags) | |
Protected Attributes | |
MTD Header | |
| std::string | _options |
Private Member Functions | |
Copy Constructor | |
| JPGImageFileType (const JPGImageFileType &obj) | |
Copy Operator | |
| const JPGImageFileType & | operator= (const JPGImageFileType &obj) |
Private Attributes | |
| UInt32 | _quality |
Static Private Attributes | |
| static JPGImageFileType | _the |
To be able to load JPEG images you need the IJG JPEG library, version 6 or later (check the Prerequisites page on www.opensg.org). The lib comes with all Linux distributions.
You have to --enable-jpg in the configure line to enable the singleton object.
Definition at line 56 of file OSGJPGImageFileType.h.
anonymous enum [inherited] |
Definition at line 66 of file OSGImageFileType.h.
00067 { 00068 OSG_READ_SUPPORTED = 1, 00069 OSG_WRITE_SUPPORTED = 2 00070 };
| JPGImageFileType::~JPGImageFileType | ( | void | ) | [virtual] |
| JPGImageFileType::JPGImageFileType | ( | const Char8 * | mimeType, | |
| const Char8 * | suffixArray[], | |||
| UInt16 | suffixByteCount, | |||
| UInt32 | flags | |||
| ) | [protected] |
Constructor used for the singleton object
Definition at line 746 of file OSGJPGImageFileType.cpp.
00749 : 00750 ImageFileType(mimeType, suffixArray, suffixByteCount, flags), 00751 _quality(90) 00752 {}
| osg::JPGImageFileType::JPGImageFileType | ( | const JPGImageFileType & | obj | ) | [private] |
| void JPGImageFileType::setQuality | ( | UInt32 | cl | ) |
Definition at line 358 of file OSGJPGImageFileType.cpp.
References _quality.
00359 { 00360 if(cl > 100) 00361 cl = 100; 00362 00363 _quality = cl; 00364 }
| UInt32 JPGImageFileType::getQuality | ( | void | ) |
Definition at line 366 of file OSGJPGImageFileType.cpp.
References _quality.
00367 { 00368 return _quality; 00369 }
| bool JPGImageFileType::validateHeader | ( | const Char8 * | fileName, | |
| bool & | implemented | |||
| ) | [virtual] |
Reimplemented from osg::ImageFileType.
Definition at line 554 of file OSGJPGImageFileType.cpp.
00555 { 00556 implemented = true; 00557 00558 if(fileName == NULL) 00559 return false; 00560 00561 FILE *file = fopen(fileName, "rb"); 00562 if(file == NULL) 00563 return false; 00564 00565 UInt16 magic = 0; 00566 fread((void *) &magic, sizeof(magic), 1, file); 00567 fclose(file); 00568 00569 #if BYTE_ORDER == LITTLE_ENDIAN 00570 if(magic == 0xd8ff) // the magic header is big endian need to swap it. 00571 #else 00572 if(magic == 0xffd8) 00573 #endif 00574 { 00575 return true; 00576 } 00577 00578 return false; 00579 }
| bool JPGImageFileType::read | ( | ImagePtr & | image, | |
| std::istream & | is, | |||
| const std::string & | mimetype | |||
| ) | [virtual] |
Tries to fill the image object with the data read from the given input stream. Returns true on success.
Reimplemented from osg::ImageFileType.
Definition at line 376 of file OSGJPGImageFileType.cpp.
References osg::ImageFileType::getMimeType(), osg::Image::OSG_INVALID_PF, osg::Image::OSG_L_PF, osg::Image::OSG_RESUNIT_INCH, osg::Image::OSG_RGB_PF, and SWARNING.
00378 { 00379 #ifdef OSG_WITH_JPG 00380 00381 struct osg_jpeg_error_mgr jerr; 00382 struct jpeg_decompress_struct cinfo; 00383 00384 cinfo.err = jpeg_std_error(&jerr.pub); 00385 if (setjmp(jerr.setjmp_buffer)) 00386 return false; 00387 cinfo.err->error_exit = osg_jpeg_error_exit; 00388 cinfo.err->output_message = osg_jpeg_output_message; 00389 00390 jpeg_create_decompress(&cinfo); 00391 00392 SourceManager *sourceManager = 00393 new ((*cinfo.mem->alloc_small)((j_common_ptr)&cinfo, JPOOL_IMAGE, sizeof(SourceManager))) 00394 SourceManager(&cinfo, is); 00395 cinfo.src = (jpeg_source_mgr*)sourceManager; 00396 00397 jpeg_read_header(&cinfo, TRUE); 00398 jpeg_start_decompress(&cinfo); 00399 00400 Image::PixelFormat pixelFormat; 00401 switch (cinfo.output_components) 00402 { 00403 case 1: 00404 pixelFormat = Image::OSG_L_PF; 00405 break; 00406 case 3: 00407 pixelFormat = Image::OSG_RGB_PF; 00408 break; 00409 default: 00410 pixelFormat = Image::OSG_INVALID_PF; 00411 break; 00412 }; 00413 00414 bool retCode; 00415 if (image->set(pixelFormat, cinfo.output_width, cinfo.output_height) == true) 00416 { 00417 Real32 res_x = Real32(cinfo.X_density); 00418 Real32 res_y = Real32(cinfo.Y_density); 00419 UInt16 res_unit = UInt16(cinfo.density_unit); 00420 if(res_unit == 2) // centimeter 00421 { 00422 // convert dpcm to dpi. 00423 res_x *= 2.54f; 00424 res_y *= 2.54f; 00425 res_unit = Image::OSG_RESUNIT_INCH; 00426 } 00427 image->setResX(res_x); 00428 image->setResY(res_y); 00429 image->setResUnit(res_unit); 00430 00431 unsigned char *destData = image->getData() + image->getSize(); 00432 int row_stride = cinfo.output_width * cinfo.output_components; 00433 while (cinfo.output_scanline < cinfo.output_height) 00434 { 00435 destData -= row_stride; 00436 jpeg_read_scanlines(&cinfo, &destData, 1); 00437 } 00438 retCode = true; 00439 } 00440 else 00441 retCode = false; 00442 00443 jpeg_finish_decompress(&cinfo); 00444 jpeg_destroy_decompress(&cinfo); 00445 00446 return retCode; 00447 00448 #else 00449 00450 SWARNING << 00451 getMimeType() << 00452 " read is not compiled into the current binary " << 00453 std::endl; 00454 return false; 00455 00456 #endif 00457 }
| bool JPGImageFileType::write | ( | const ImagePtr & | image, | |
| std::ostream & | os, | |||
| const std::string & | mimetype | |||
| ) | [virtual] |
Tries to write the image object to the given output stream. Returns true on success.
Reimplemented from osg::ImageFileType.
Definition at line 464 of file OSGJPGImageFileType.cpp.
References _quality, osg::ImageFileType::getMimeType(), and SWARNING.
00466 { 00467 #ifdef OSG_WITH_JPG 00468 00469 if ((image->getBpp() != 1 && 00470 image->getBpp() != 3) || image->getDepth() != 1) 00471 { 00472 SWARNING << 00473 getMimeType() << 00474 " JPEG write only works for 2D 1 or 3 bpp images " << 00475 std::endl; 00476 return false; 00477 } 00478 00479 struct osg_jpeg_error_mgr jerr; 00480 struct jpeg_compress_struct cinfo; 00481 00482 cinfo.err = jpeg_std_error(&jerr.pub); 00483 if (setjmp(jerr.setjmp_buffer)) 00484 return false; 00485 cinfo.err->error_exit = osg_jpeg_error_exit; 00486 cinfo.err->output_message = osg_jpeg_output_message; 00487 00488 jpeg_create_compress(&cinfo); 00489 00490 DestinationManager *destinationManager = 00491 new ((*cinfo.mem->alloc_small)((j_common_ptr)&cinfo, JPOOL_IMAGE, sizeof(DestinationManager))) 00492 DestinationManager(&cinfo, os); 00493 cinfo.dest = (jpeg_destination_mgr*)destinationManager; 00494 00495 cinfo.image_width = image->getWidth(); 00496 cinfo.image_height = image->getHeight(); 00497 cinfo.input_components = image->getBpp(); 00498 cinfo.in_color_space = (image->getBpp() == 1) ? JCS_GRAYSCALE : JCS_RGB; 00499 00500 jpeg_set_defaults(&cinfo); 00501 jpeg_set_quality(&cinfo, _quality, TRUE); 00502 00503 cinfo.density_unit = 1; // dpi 00504 cinfo.X_density = UInt16(image->getResX() < 0.0f ? 00505 image->getResX() - 0.5f : 00506 image->getResX() + 0.5f); 00507 cinfo.Y_density = UInt16(image->getResY() < 0.0f ? 00508 image->getResY() - 0.5f : 00509 image->getResY() + 0.5f); 00510 00511 jpeg_start_compress(&cinfo, TRUE); 00512 00513 unsigned char *srcData = image->getData() + image->getSize(); 00514 int row_stride = cinfo.image_width * cinfo.input_components; 00515 while (cinfo.next_scanline < cinfo.image_height) 00516 { 00517 srcData -= row_stride; 00518 jpeg_write_scanlines(&cinfo, &srcData, 1); 00519 } 00520 00521 jpeg_finish_compress(&cinfo); 00522 jpeg_destroy_compress(&cinfo); 00523 00524 return true; 00525 00526 #else 00527 00528 SWARNING << 00529 getMimeType() << 00530 " write is not compiled into the current binary " << 00531 std::endl; 00532 return false; 00533 00534 #endif 00535 }
| std::string JPGImageFileType::determineMimetypeFromStream | ( | std::istream & | is | ) | [virtual] |
Tries to determine the mime type of the data provided by an input stream by searching for magic bytes. Returns the mime type or an empty string when the function could not determine the mime type.
Reimplemented from osg::ImageFileType.
Definition at line 543 of file OSGJPGImageFileType.cpp.
References osg::ImageFileType::getMimeType().
00544 { 00545 char filecode[2]; 00546 is.read(filecode, 2); 00547 is.seekg(-2, std::ios::cur); 00548 return strncmp(filecode, "\xff\xd8", 2) == 0 ? 00549 std::string(getMimeType()) : std::string(); 00550 }
| UInt64 JPGImageFileType::restoreData | ( | ImagePtr & | image, | |
| const UChar8 * | buffer, | |||
| Int32 | memSize = -1 | |||
| ) | [virtual] |
Reimplemented from osg::ImageFileType.
Definition at line 583 of file OSGJPGImageFileType.cpp.
References osg::ImageFileType::getMimeType(), osg::Image::OSG_INVALID_PF, osg::Image::OSG_L_PF, osg::Image::OSG_LA_PF, osg::Image::OSG_RGB_PF, osg::Image::OSG_RGBA_PF, and SWARNING.
00586 { 00587 #ifdef OSG_WITH_JPG 00588 UInt64 retCode = 0; 00589 struct local_error_mgr 00590 { 00591 struct jpeg_error_mgr pub; 00592 jmp_buf setjmp_buffer; 00593 }; 00594 00595 unsigned char *destData; 00596 Image::PixelFormat pixelFormat = osg::Image::OSG_INVALID_PF; 00597 00598 unsigned long imageSize; 00599 typedef struct local_error_mgr *local_error_ptr; 00600 struct local_error_mgr jerr; 00601 struct jpeg_decompress_struct cinfo; 00602 JSAMPARRAY imagebuffer; 00603 00604 int row_stride; 00605 00606 cinfo.err = jpeg_std_error(&jerr.pub); 00607 if(setjmp(jerr.setjmp_buffer)) 00608 { 00609 jpeg_destroy_decompress(&cinfo); 00610 return 0; 00611 } 00612 00613 jpeg_create_decompress(&cinfo); 00614 jpeg_memory_src(&cinfo, buffer, memSize); 00615 jpeg_read_header(&cinfo, TRUE); 00616 jpeg_start_decompress(&cinfo); 00617 00618 switch(cinfo.output_components) 00619 { 00620 case 1: 00621 pixelFormat = Image::OSG_L_PF; 00622 break; 00623 case 2: 00624 pixelFormat = Image::OSG_LA_PF; 00625 break; 00626 case 3: 00627 pixelFormat = Image::OSG_RGB_PF; 00628 break; 00629 case 4: 00630 pixelFormat = Image::OSG_RGBA_PF; 00631 break; 00632 }; 00633 00634 if(image->set(pixelFormat, cinfo.output_width, cinfo.output_height)) 00635 { 00636 imageSize = image->getSize(); 00637 destData = image->getData() + imageSize; 00638 row_stride = cinfo.output_width * cinfo.output_components; 00639 imagebuffer = (*cinfo.mem->alloc_sarray) ((j_common_ptr) & cinfo, JPOOL_IMAGE, row_stride, 1); 00640 while(cinfo.output_scanline < cinfo.output_height) 00641 { 00642 destData -= row_stride; 00643 jpeg_read_scanlines(&cinfo, imagebuffer, 1); 00644 memcpy(destData, *imagebuffer, row_stride); 00645 } 00646 00647 retCode = imageSize; 00648 } 00649 else 00650 retCode = 0; 00651 00652 jpeg_finish_decompress(&cinfo); 00653 jpeg_destroy_decompress(&cinfo); 00654 00655 return retCode; 00656 00657 #else 00658 SWARNING << 00659 getMimeType() << 00660 " read is not compiled into the current binary " << 00661 std::endl; 00662 return 0; 00663 #endif 00664 }
| UInt64 JPGImageFileType::storeData | ( | const ImagePtr & | image, | |
| UChar8 * | buffer, | |||
| Int32 | memSize = -1 | |||
| ) | [virtual] |
Tries to restore the image data from the given memblock. Returns the amount of data read.
Reimplemented from osg::ImageFileType.
Definition at line 671 of file OSGJPGImageFileType.cpp.
References _quality, osg::ImageFileType::getMimeType(), and SWARNING.
00674 { 00675 #ifdef OSG_WITH_JPG 00676 if((image->getBpp() != 1 && image->getBpp() != 3) 00677 || image->getDepth() != 1) 00678 { 00679 SWARNING << 00680 getMimeType() << 00681 " JPEG storeData only works for 2D 1 or 3 bpp images " << 00682 std::endl; 00683 return 0; 00684 } 00685 00686 struct local_error_mgr 00687 { 00688 struct jpeg_error_mgr pub; 00689 jmp_buf setjmp_buffer; 00690 }; 00691 00692 typedef struct local_error_mgr *local_error_ptr; 00693 00694 struct local_error_mgr jerr; 00695 struct jpeg_compress_struct cinfo; 00696 JSAMPARRAY imagebuffer; 00697 UChar8 *data; 00698 00699 cinfo.err = jpeg_std_error(&jerr.pub); 00700 if(setjmp(jerr.setjmp_buffer)) 00701 { 00702 jpeg_destroy_compress(&cinfo); 00703 return 0; 00704 } 00705 00706 jpeg_create_compress(&cinfo); 00707 jpeg_memory_dest(&cinfo, buffer, memSize); 00708 00709 cinfo.image_width = image->getWidth(); 00710 cinfo.image_height = image->getHeight(); 00711 cinfo.input_components = image->getBpp(); 00712 cinfo.in_color_space = (image->getBpp() == 1) ? JCS_GRAYSCALE : JCS_RGB; 00713 00714 jpeg_set_defaults(&cinfo); 00715 jpeg_set_quality(&cinfo, _quality, TRUE); 00716 jpeg_start_compress(&cinfo, TRUE); 00717 00718 imagebuffer = &data; 00719 while(cinfo.next_scanline < cinfo.image_height) 00720 { 00721 data = image->getData() + 00722 (image->getHeight() - 1 - cinfo.next_scanline) * 00723 image->getWidth() * 00724 image->getBpp(); 00725 jpeg_write_scanlines(&cinfo, imagebuffer, 1); 00726 } 00727 00728 jpeg_finish_compress(&cinfo); 00729 jpeg_destroy_compress(&cinfo); 00730 00731 return jpeg_mem.dataSize; 00732 00733 #else 00734 SWARNING << 00735 getMimeType() << 00736 " write is not compiled into the current binary " << 00737 std::endl; 00738 return 0; 00739 #endif 00740 }
| JPGImageFileType & JPGImageFileType::the | ( | void | ) | [static] |
Class method to get the singleton Object
Definition at line 349 of file OSGJPGImageFileType.cpp.
References _the.
00350 { 00351 return _the; 00352 }
| const JPGImageFileType& osg::JPGImageFileType::operator= | ( | const JPGImageFileType & | obj | ) | [private] |
| void ImageFileType::setOptions | ( | const Char8 * | options | ) | [inherited] |
Definition at line 243 of file OSGImageFileType.cpp.
References osg::ImageFileType::_options.
Referenced by osg::ImageFileHandler::setOptions().
00244 { 00245 _options = options; 00246 }
| const Char8 * ImageFileType::getMimeType | ( | void | ) | const [inherited] |
Get method for the mime type
Definition at line 107 of file OSGImageFileType.cpp.
References osg::ImageFileType::_mimeType, and osg::IDString::str().
Referenced by osg::ImageFileHandler::addImageFileType(), osg::TIFImageFileType::determineMimetypeFromStream(), osg::SGIImageFileType::determineMimetypeFromStream(), osg::PSDImageFileType::determineMimetypeFromStream(), osg::PNMImageFileType::determineMimetypeFromStream(), osg::PNGImageFileType::determineMimetypeFromStream(), osg::MNGImageFileType::determineMimetypeFromStream(), determineMimetypeFromStream(), osg::JP2ImageFileType::determineMimetypeFromStream(), osg::GIFImageFileType::determineMimetypeFromStream(), osg::DDSImageFileType::determineMimetypeFromStream(), osg::BMPImageFileType::determineMimetypeFromStream(), osg::ImageFileType::dump(), osg::TIFImageFileType::read(), osg::PNGImageFileType::read(), read(), osg::JP2ImageFileType::read(), osg::ImageFileType::read(), osg::ImageFileHandler::read(), osg::EXRImageFileType::read(), osg::PNGImageFileType::restoreData(), restoreData(), osg::ImageFileType::restoreData(), osg::ImageFileHandler::store(), osg::PNGImageFileType::storeData(), storeData(), osg::ImageFileType::storeData(), osg::TIFImageFileType::write(), osg::PNGImageFileType::write(), write(), osg::ImageFileType::write(), osg::ImageFileHandler::write(), and osg::EXRImageFileType::write().
| const std::list< IDString > & ImageFileType::getSuffixList | ( | void | ) | const [inherited] |
Get method for the suffix list container
Definition at line 134 of file OSGImageFileType.cpp.
References osg::ImageFileType::_suffixList.
Referenced by osg::ImageFileHandler::addImageFileType().
00135 { 00136 return _suffixList; 00137 }
| UInt32 ImageFileType::getFlags | ( | void | ) | const [virtual, inherited] |
Get method for the flags indicating read/write support. Most image types only support reading.
Definition at line 117 of file OSGImageFileType.cpp.
References osg::ImageFileType::_flags.
Referenced by osg::ImageFileHandler::getSuffixList().
00118 { 00119 return _flags; 00120 }
| const Char8 * ImageFileType::getOptions | ( | void | ) | [inherited] |
Get method for the mime type
Definition at line 124 of file OSGImageFileType.cpp.
References osg::ImageFileType::_options.
Referenced by osg::ImageFileHandler::getOptions().
00125 { 00126 return _options.c_str(); 00127 }
Reimplemented in osg::DATImageFileType, and osg::HDRImageFileType.
Definition at line 141 of file OSGImageFileType.cpp.
Referenced by osg::ImageFileHandler::read().
00142 { 00143 std::ifstream is(fileName, std::ios::binary); 00144 if (is.good() == false) 00145 return false; 00146 return read(image, is, std::string()); 00147 }
Reimplemented in osg::DATImageFileType, and osg::HDRImageFileType.
Definition at line 151 of file OSGImageFileType.cpp.
Referenced by osg::ImageFileHandler::write().
00152 { 00153 std::ofstream os(fileName, std::ios::binary); 00154 if (os.good() == false) 00155 return false; 00156 return write(image, os, std::string()); 00157 }
| UInt64 ImageFileType::restore | ( | ImagePtr & | image, | |
| const UChar8 * | buffer, | |||
| Int32 | memSize = -1 | |||
| ) | [static, inherited] |
Tries to restore the Imagedata from the given memblock. The buffer must include a ImageFileType::Head data block.
Definition at line 283 of file OSGImageFileType.cpp.
References osg::ImageFileType::Head::dataType, osg::ImageFileType::Head::depth, osg::ImageFileHandler::determineMimetypeFromSuffix(), FDEBUG, osg::ImageFileType::Head::frameCount, osg::ImageFileType::Head::frameDelay, FWARNING, osg::ImageFileType::Head::height, osg::ImageFileType::Head::mipmapCount, osg::ImageFileType::Head::netToHost(), osg::NullFC, osg::Image::OSG_UINT8_IMAGEDATA, osg::ImageFileType::Head::pixelFormat, osg::ImageFileType::Head::sideCount, osg::ImageFileType::Head::suffix, osg::ImageFileHandler::the(), and osg::ImageFileType::Head::width.
Referenced by osg::ClusterViewBuffer::recv(), osg::ImageFileHandler::restore(), and osg::SimpleSceneManager::useOpenSGLogo().
00285 { 00286 unsigned long imageSize, headSize = sizeof(Head); 00287 unsigned long size = 0, attachmentSize; 00288 Head head; 00289 const UChar8 *data = buffer ? (buffer + headSize) : 0; 00290 ImageFileType *type; 00291 std::string mimeType; 00292 Image::Type dataType; 00293 00294 if ((image != osg::NullFC) && buffer && (memSize >= headSize)) { 00295 00296 // Copy header. Otherwise netToHost would change the original 00297 // data structur. 00298 memcpy(&head,buffer,sizeof(Head)); 00299 head.netToHost(); 00300 mimeType = ImageFileHandler::the().determineMimetypeFromSuffix(head.suffix); 00301 00302 if((type = ImageFileHandler::the().getFileType(mimeType.c_str(), 0))) 00303 { 00304 if (head.dataType) 00305 dataType = Image::Type(head.dataType); 00306 else 00307 dataType = Image::OSG_UINT8_IMAGEDATA; 00308 00309 image->set(Image::PixelFormat(head.pixelFormat), head.width, 00310 head.height, head.depth, head.mipmapCount, 00311 head.frameCount, float(head.frameDelay) / 1000.0, 0, 00312 dataType,true,head.sideCount ); 00313 imageSize = static_cast<unsigned long>( 00314 type->restoreData(image, data, memSize - headSize)); 00315 attachmentSize = 0; // head->attachmentSize; 00316 00317 /* 00318 if ((attachmentSize = head->attachmentSize)) 00319 { 00320 attData = (char*)(buffer + headSize + imageSize); 00321 attKey = attData; 00322 attValue = 0; 00323 for (i = 0; i < (attachmentSize-1); i++) { 00324 if (attData[i] == 0) 00325 if (attKey) { 00326 attValue = &(attData[i+1]); 00327 image->setAttachmentField (attKey,attValue); 00328 attKey = attValue = 0; 00329 } 00330 else 00331 attKey = &(attData[i+1]); 00332 } 00333 if (attKey || attValue) { 00334 FFATAL (("Attachment restore error\n")); 00335 } 00336 } 00337 */ 00338 00339 size = headSize + imageSize + attachmentSize; 00340 00341 FDEBUG (( "Restore image data: %lu (%lu/%lu/%lu)\n", 00342 size, headSize, imageSize, attachmentSize )); 00343 00344 } 00345 else 00346 { 00347 imageSize = 0; 00348 FWARNING(("Can not restore image data, invalid mimeType: %s\n", 00349 mimeType.empty() == false ? mimeType.c_str() : "Unknown")); 00350 } 00351 00352 00353 } 00354 00355 return size; 00356 }
| UInt64 ImageFileType::store | ( | const ImagePtr & | image, | |
| const char * | mimeType, | |||
| UChar8 * | buffer, | |||
| Int32 | memSize = -1 | |||
| ) | [static, inherited] |
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 364 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().
00366 { 00367 ImageFileType *type = ImageFileHandler::the().getFileType(mimeType); 00368 00369 return type ? type->store(image, buffer, memSize) : 0; 00370 }
| UInt64 ImageFileType::store | ( | const ImagePtr & | image, | |
| UChar8 * | buffer, | |||
| Int32 | memSize = -1 | |||
| ) | [inherited] |
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 378 of file OSGImageFileType.cpp.
References osg::ImageFileType::_suffixList, osg::ImageFileType::Head::attachmentSize, osg::ImageFileType::Head::dataType, osg::ImageFileType::Head::depth, FDEBUG, FFATAL, osg::ImageFileType::Head::frameCount, osg::ImageFileType::Head::frameDelay, osg::ImageFileType::Head::height, osg::ImageFileType::Head::hostToNet(), osg::ImageFileType::Head::mipmapCount, osg::ImageFileType::Head::pixelFormat, osg::ImageFileType::Head::sideCount, osg::ImageFileType::storeData(), osg::ImageFileType::Head::suffix, and osg::ImageFileType::Head::width.
00380 { 00381 Head *head; 00382 unsigned long dataSize = 0, headSize = sizeof(Head); 00383 unsigned long attachmentSize; 00384 UChar8 *dest; 00385 const UChar8 *src = image->getData(); 00386 std::map<std::string, std::string>::const_iterator aI; 00387 std::string value; 00388 00389 attachmentSize = 0; 00390 00391 // get attachment size 00392 /* 00393 ImageGenericAttPtr att=ImageGenericAttPtr::dcast( 00394 const_cast<Image*>(image.getCPtr())->findAttachment( 00395 ImageGenericAtt::getClassType().getGroupId())); 00396 if(att != NullFC) 00397 { 00398 for(i = 0; i < (att->getType().getNumFieldDescs()-1); ++i) 00399 { 00400 FieldDescription *fieldDesc=att->getType().getFieldDescription(i); 00401 Field *field=att->getField(i); 00402 if (fieldDesc && field) 00403 { 00404 field->getValueByStr(value); 00405 attachmentSize += strlen( fieldDesc->getName().str() ) + 1; 00406 attachmentSize += value.length() + 1; 00407 00408 std::cout << fieldDesc->getName().str() << std::endl; 00409 std::cout << value << std::endl; 00410 } 00411 else 00412 { 00413 FFATAL (("Invalid Attachment in ImageFileType::store()\n")); 00414 } 00415 } 00416 } 00417 */ 00418 00419 if (buffer) 00420 { 00421 head = (Head *)buffer; 00422 00423 head->pixelFormat = image->getPixelFormat(); 00424 head->width = image->getWidth(); 00425 head->height = image->getHeight(); 00426 head->depth = image->getDepth(); 00427 head->mipmapCount = image->getMipMapCount(); 00428 head->frameCount = image->getFrameCount(); 00429 head->frameDelay = short(image->getFrameDelay() * 1000.0); 00430 head->sideCount = image->getSideCount(); 00431 head->dataType = image->getDataType(); 00432 head->attachmentSize = static_cast<unsigned short>(attachmentSize); 00433 head->hostToNet(); 00434 00435 strcpy(head->suffix, _suffixList.front().str()); 00436 00437 dest = (UChar8 *) (buffer + headSize); 00438 00439 if (src) 00440 dataSize = static_cast<unsigned long>( 00441 storeData(image, dest, memSize - headSize)); 00442 00443 dest = (UChar8 *) (buffer + headSize + dataSize); 00444 00445 /* 00446 if(att != NullFC) 00447 { 00448 for(i = 0; i < (att->getType().getNumFieldDescs()-1); ++i) 00449 { 00450 FieldDescription *fieldDesc=att->getType().getFieldDescription(i); 00451 Field *field=att->getField(i); 00452 if (field && fieldDesc) 00453 { 00454 field->getValueByStr(value); 00455 00456 l = strlen( fieldDesc->getName().str() ); 00457 for (i = 0; i < l; i++) 00458 *dest++ = fieldDesc->getName().str()[i]; 00459 *dest++ = 0; 00460 l = value.length(); 00461 for (i = 0; i < l; i++) 00462 *dest++ = value[i]; 00463 *dest++ = 0; 00464 } 00465 else 00466 { 00467 FFATAL (("Invalid Attachment in ImageFileType::store()\n")); 00468 } 00469 } 00470 } 00471 */ 00472 00473 FDEBUG (( "Store image data: %lu (%lu/%lu/%lu)\n", 00474 headSize + dataSize + attachmentSize, headSize, dataSize, 00475 attachmentSize )); 00476 } 00477 else { 00478 FFATAL (("Invalid buffer in ImageFileType::store()\n")); 00479 } 00480 00481 return (headSize + dataSize + attachmentSize); 00482 00483 }
Returns the max buffer size needed to store the Image (Head + mimeType specific data block)
Definition at line 490 of file OSGImageFileType.cpp.
References FINFO.
Referenced by osg::ClusterViewBuffer::send(), and osg::ImageFileHandler::store().
00491 { 00492 std::string value; 00493 unsigned long size, attachmentSize; 00494 unsigned long imageSize = image->getSize(), headSize = sizeof(Head); 00495 00496 std::map<std::string, std::string>::const_iterator aI; 00497 00498 attachmentSize = 0; 00499 00500 // get attachment size 00501 /* 00502 ImageGenericAttPtr att=ImageGenericAttPtr::dcast( 00503 const_cast<Image*>(image.getCPtr())->findAttachment( 00504 ImageGenericAtt::getClassType().getGroupId())); 00505 if(att != NullFC) 00506 { 00507 for(i = 0; i < (att->getType().getNumFieldDescs()-1); ++i) 00508 { 00509 FieldDescription *fieldDesc=att->getType().getFieldDescription(i); 00510 Field *field=att->getField(i); 00511 if (field && fieldDesc) 00512 { 00513 field->getValueByStr(value); 00514 attachmentSize += strlen( fieldDesc->getName().str() ) + 1; 00515 attachmentSize += value.length() + 1; 00516 } 00517 else 00518 { 00519 FFATAL (("Invalid Attachment in ImageFileType::maxBufferSize()\n")); 00520 } 00521 } 00522 } 00523 */ 00524 00525 size = headSize + imageSize + attachmentSize; 00526 00527 FINFO (( "ImageFileType::maxBufferSize(): %lu (%lu/%lu/%lu)\n", 00528 size, headSize, imageSize, attachmentSize )); 00529 00530 return size; 00531 }
| void ImageFileType::dump | ( | void | ) | [inherited] |
The dump method just writes some object debugging info to the LOG stream
Definition at line 537 of file OSGImageFileType.cpp.
References osg::ImageFileType::_suffixList, osg::ImageFileType::getMimeType(), osg::LOG_DEBUG, and SLOG.
00538 { 00539 std::list<IDString>::iterator sI; 00540 00541 SLOG << getMimeType(); 00542 00543 if(_suffixList.empty()) 00544 { 00545 SLOG << ": Suffix: "; 00546 for(sI = _suffixList.begin(); sI != _suffixList.end(); sI++) 00547 { 00548 Log().stream(OSG::LOG_DEBUG) << sI->str() << " "; 00549 } 00550 } 00551 00552 std::cerr << std::endl; 00553 }
UInt32 osg::JPGImageFileType::_quality [private] |
Definition at line 140 of file OSGJPGImageFileType.h.
Referenced by getQuality(), setQuality(), storeData(), and write().
JPGImageFileType JPGImageFileType::_the [static, private] |
std::string osg::ImageFileType::_options [protected, inherited] |
Definition at line 182 of file OSGImageFileType.h.
Referenced by osg::ImageFileType::getOptions(), osg::ImageFileType::setOptions(), and osg::TIFImageFileType::write().
1.5.5