Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

osg::JPGImageFileType Class Reference
[Image]

JPEG File Handler. Used to read/write JPEG files. See Image for a detailed description. More...

#include <OSGJPGImageFileType.h>

Inheritance diagram for osg::JPGImageFileType:

osg::ImageFileType List of all members.

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 Member Functions

Destructor
*virtual ~JPGImageFileType (void)
Get Method
*void setQuality (UInt32 cl)
UInt32 getQuality (void)
Read/Write
*virtual bool read (ImagePtr &image, const Char8 *fileName)
virtual bool write (const ImagePtr &image, const Char8 *fileName)
virtual bool validateHeader (const Char8 *fileName, bool &implemented)
Buffer
*virtual UInt64 restoreData (ImagePtr &image, const UChar8 *buffer, Int32 memSize=-1)
virtual UInt64 storeData (const ImagePtr &image, UChar8 *buffer, Int32 memSize=-1)

Static Public Member Functions

Get Method
*static JPGImageFileTypethe (void)

Protected Member Functions

Default Constructor
JPGImageFileType (const Char8 *mimeType, const Char8 *suffixArray[], UInt16 suffixByteCount, UInt32 flags)
Copy Constructor
JPGImageFileType (const JPGImageFileType &obj)

Private Types

typedef ImageFileType Inherited

Private Attributes

UInt32 _quality

Static Private Attributes

static JPGImageFileType _the

Detailed Description

Image File Type to read/write and store/restore Image objects as JPEG data.

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 55 of file OSGJPGImageFileType.h.


Member Typedef Documentation

typedef ImageFileType osg::JPGImageFileType::Inherited [private]
 

Definition at line 128 of file OSGJPGImageFileType.h.


Member Enumeration Documentation

anonymous enum [inherited]
 

Enumerator:
OSG_READ_SUPPORTED 
OSG_WRITE_SUPPORTED 

Definition at line 65 of file OSGImageFileType.h.

00066     {
00067         OSG_READ_SUPPORTED = 1,
00068         OSG_WRITE_SUPPORTED = 2
00069     };


Constructor & Destructor Documentation

JPGImageFileType::~JPGImageFileType void   )  [virtual]
 

Destructor

Definition at line 625 of file OSGJPGImageFileType.cpp.

00626 {
00627     return;
00628 }

JPGImageFileType::JPGImageFileType const Char8 mimeType,
const Char8 suffixArray[],
UInt16  suffixByteCount,
UInt32  flags
[protected]
 

Constructor used for the singleton object

Definition at line 600 of file OSGJPGImageFileType.cpp.

00603                                                   :
00604     ImageFileType(mimeType, suffixArray, suffixByteCount, flags),
00605     _quality(90)
00606 {
00607     return;
00608 }

JPGImageFileType::JPGImageFileType const JPGImageFileType obj  )  [protected]
 

Dummy Copy Constructor

Definition at line 614 of file OSGJPGImageFileType.cpp.

00614                                                               :
00615     ImageFileType(obj),
00616     _quality(obj._quality)
00617 {
00618     return;
00619 }


Member Function Documentation

void JPGImageFileType::setQuality UInt32  cl  ) 
 

Definition at line 216 of file OSGJPGImageFileType.cpp.

References _quality.

00217 {
00218     if(cl > 100)
00219         cl = 100;
00220     
00221     _quality = cl;
00222 }

UInt32 JPGImageFileType::getQuality void   ) 
 

Definition at line 224 of file OSGJPGImageFileType.cpp.

References _quality.

00225 {
00226     return _quality;
00227 }

bool JPGImageFileType::read ImagePtr image,
const Char8 fileName
[virtual]
 

Tries to fill the image object with the data read from the given fileName. Returns true on success.

Implements osg::ImageFileType.

Definition at line 234 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.

00236 {
00237 #ifdef OSG_WITH_JPG
00238     bool    retCode = false;
00239     struct local_error_mgr
00240     {
00241         struct jpeg_error_mgr   pub;
00242         jmp_buf                 setjmp_buffer;
00243     };
00244 
00245     unsigned char                   *destData;
00246     Image::PixelFormat              pixelFormat = osg::Image::OSG_INVALID_PF;
00247 
00248     unsigned long                    imageSize;
00249     typedef struct local_error_mgr  *local_error_ptr;
00250     struct local_error_mgr          jerr;
00251     struct jpeg_decompress_struct   cinfo;
00252     FILE                            *infile;
00253     JSAMPARRAY                      buffer;
00254 
00255     int                             row_stride;
00256 
00257     if((infile = fopen(fileName, "rb")))
00258     {
00259         cinfo.err = jpeg_std_error(&jerr.pub);
00260         if(setjmp(jerr.setjmp_buffer))
00261         {
00262             jpeg_destroy_decompress(&cinfo);
00263             fclose(infile);
00264             return retCode;
00265         }
00266 
00267         jpeg_create_decompress(&cinfo);
00268         jpeg_stdio_src(&cinfo, infile);
00269         jpeg_read_header(&cinfo, TRUE);
00270         jpeg_start_decompress(&cinfo);
00271 
00272         switch(cinfo.output_components)
00273         {
00274         case 1:
00275             pixelFormat = Image::OSG_L_PF;
00276             break;
00277         case 2:
00278             pixelFormat = Image::OSG_LA_PF;
00279             break;
00280         case 3:
00281             pixelFormat = Image::OSG_RGB_PF;
00282             break;
00283         case 4:
00284             pixelFormat = Image::OSG_RGBA_PF;
00285             break;
00286         };
00287 
00288         if(image->set(pixelFormat, cinfo.output_width, cinfo.output_height))
00289         {
00290             imageSize = image->getSize();
00291             destData = image->getData() + imageSize;
00292             row_stride = cinfo.output_width * cinfo.output_components;
00293             buffer = (*cinfo.mem->alloc_sarray) ((j_common_ptr) & cinfo, JPOOL_IMAGE, row_stride, 1);
00294             while(cinfo.output_scanline < cinfo.output_height)
00295             {
00296                 destData -= row_stride;
00297                 jpeg_read_scanlines(&cinfo, buffer, 1);
00298                 memcpy(destData, *buffer, row_stride);
00299             }
00300 
00301             retCode = true;
00302         }
00303         else
00304             retCode = false;
00305 
00306         jpeg_finish_decompress(&cinfo);
00307         jpeg_destroy_decompress(&cinfo);
00308         fclose(infile);
00309     }
00310 
00311     return retCode;
00312 
00313 #else
00314     SWARNING <<
00315         getMimeType() <<
00316         " read is not compiled into the current binary " <<
00317         std::endl;
00318     return false;
00319 #endif
00320 }

bool JPGImageFileType::write const ImagePtr image,
const Char8 fileName
[virtual]
 

Tries to write the image object to the given fileName. Returns true on success.

Implements osg::ImageFileType.

Definition at line 327 of file OSGJPGImageFileType.cpp.

References _quality, osg::ImageFileType::getMimeType(), and SWARNING.

00329 {
00330 #ifdef OSG_WITH_JPG
00331     if((image->getBpp() != 1 && 
00332         image->getBpp() != 3) || image->getDepth() != 1)
00333     {
00334         SWARNING <<
00335             getMimeType() <<
00336             " JPEG write only works for 2D 1 or 3 bpp images " <<
00337             std::endl;
00338         return false;
00339     }
00340 
00341     bool    retCode = false;
00342 
00343     struct local_error_mgr
00344     {
00345         struct jpeg_error_mgr   pub;
00346         jmp_buf                 setjmp_buffer;
00347     };
00348 
00349     typedef struct local_error_mgr  *local_error_ptr;
00350 
00351     struct local_error_mgr          jerr;
00352     struct jpeg_compress_struct     cinfo;
00353     FILE                            *outfile;
00354     JSAMPARRAY                      buffer;
00355     UChar8                          *data;
00356 
00357     if((outfile = fopen(fileName, "wb")) == NULL)
00358     {
00359         fprintf(stderr, "can't open %s\n", fileName);
00360         return retCode;
00361     }
00362 
00363     cinfo.err = jpeg_std_error(&jerr.pub);
00364     if(setjmp(jerr.setjmp_buffer))
00365     {
00366         jpeg_destroy_compress(&cinfo);
00367         fclose(outfile);
00368         return 0;
00369     }
00370 
00371     jpeg_create_compress(&cinfo);
00372     jpeg_stdio_dest(&cinfo, outfile);
00373 
00374     cinfo.image_width = image->getWidth();
00375     cinfo.image_height = image->getHeight();
00376     cinfo.input_components = image->getBpp();
00377     cinfo.in_color_space = (image->getBpp() == 1) ? JCS_GRAYSCALE : JCS_RGB;
00378 
00379     jpeg_set_defaults(&cinfo);
00380     jpeg_set_quality(&cinfo, _quality, TRUE);
00381     jpeg_start_compress(&cinfo, TRUE);
00382 
00383     buffer = &data;
00384     while(cinfo.next_scanline < cinfo.image_height)
00385     {
00386         data = image->getData() +
00387             (image->getHeight() - 1 - cinfo.next_scanline) *
00388             image->getWidth() *
00389             image->getBpp();
00390         jpeg_write_scanlines(&cinfo, buffer, 1);
00391     }
00392 
00393     jpeg_finish_compress(&cinfo);
00394     jpeg_destroy_compress(&cinfo);
00395     fclose(outfile);
00396 
00397     return true;
00398 
00399 #else
00400     SWARNING <<
00401         getMimeType() <<
00402         " write is not compiled into the current binary " <<
00403         std::endl;
00404     return false;
00405 #endif
00406 }

bool JPGImageFileType::validateHeader const Char8 fileName,
bool &  implemented
[virtual]
 

Tries to fill the image object with the data read from the given fileName. Returns true on success.

Reimplemented from osg::ImageFileType.

Definition at line 408 of file OSGJPGImageFileType.cpp.

00409 {
00410     implemented = true;
00411 
00412     if(fileName == NULL)
00413         return false;
00414 
00415     FILE *file = fopen(fileName, "rb");
00416     if(file == NULL)
00417         return false;
00418 
00419     UInt16 magic = 0;
00420     fread((void *) &magic, sizeof(magic), 1, file);
00421     fclose(file);
00422 
00423 #if BYTE_ORDER == LITTLE_ENDIAN
00424     if(magic == 0xd8ff) // the magic header is big endian need to swap it.
00425 #else
00426     if(magic == 0xffd8)
00427 #endif
00428     {
00429         return true;
00430     }
00431 
00432     return false;
00433 }

UInt64 JPGImageFileType::restoreData ImagePtr image,
const UChar8 buffer,
Int32  memSize = -1
[virtual]
 

Abstract restore method. Should be overwriten by a concrete derived class. Tries to restore the image data from the given memblock.

Reimplemented from osg::ImageFileType.

Definition at line 437 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.

00440 {
00441 #ifdef OSG_WITH_JPG
00442     UInt64    retCode = 0;
00443     struct local_error_mgr
00444     {
00445         struct jpeg_error_mgr   pub;
00446         jmp_buf                 setjmp_buffer;
00447     };
00448 
00449     unsigned char                   *destData;
00450     Image::PixelFormat              pixelFormat = osg::Image::OSG_INVALID_PF;
00451 
00452     unsigned long                    imageSize;
00453     typedef struct local_error_mgr  *local_error_ptr;
00454     struct local_error_mgr          jerr;
00455     struct jpeg_decompress_struct   cinfo;
00456     JSAMPARRAY                      imagebuffer;
00457 
00458     int                             row_stride;
00459 
00460     cinfo.err = jpeg_std_error(&jerr.pub);
00461     if(setjmp(jerr.setjmp_buffer))
00462     {
00463         jpeg_destroy_decompress(&cinfo);
00464         return 0;
00465     }
00466 
00467     jpeg_create_decompress(&cinfo);
00468     jpeg_memory_src(&cinfo, buffer, memSize);
00469     jpeg_read_header(&cinfo, TRUE);
00470     jpeg_start_decompress(&cinfo);
00471 
00472     switch(cinfo.output_components)
00473     {
00474     case 1:
00475         pixelFormat = Image::OSG_L_PF;
00476         break;
00477     case 2:
00478         pixelFormat = Image::OSG_LA_PF;
00479         break;
00480     case 3:
00481         pixelFormat = Image::OSG_RGB_PF;
00482         break;
00483     case 4:
00484         pixelFormat = Image::OSG_RGBA_PF;
00485         break;
00486     };
00487 
00488     if(image->set(pixelFormat, cinfo.output_width, cinfo.output_height))
00489     {
00490         imageSize = image->getSize();
00491         destData = image->getData() + imageSize;
00492         row_stride = cinfo.output_width * cinfo.output_components;
00493         imagebuffer = (*cinfo.mem->alloc_sarray) ((j_common_ptr) & cinfo, JPOOL_IMAGE, row_stride, 1);
00494         while(cinfo.output_scanline < cinfo.output_height)
00495         {
00496             destData -= row_stride;
00497             jpeg_read_scanlines(&cinfo, imagebuffer, 1);
00498             memcpy(destData, *imagebuffer, row_stride);
00499         }
00500 
00501         retCode = imageSize;
00502     }
00503     else
00504         retCode = 0;
00505 
00506     jpeg_finish_decompress(&cinfo);
00507     jpeg_destroy_decompress(&cinfo);
00508 
00509     return retCode;
00510 
00511 #else
00512     SWARNING <<
00513         getMimeType() <<
00514         " read is not compiled into the current binary " <<
00515         std::endl;
00516     return 0;
00517 #endif
00518 }

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 525 of file OSGJPGImageFileType.cpp.

References _quality, osg::ImageFileType::getMimeType(), and SWARNING.

00528 {
00529 #ifdef OSG_WITH_JPG
00530     if((image->getBpp() != 1 && image->getBpp() != 3)
00531        || image->getDepth() != 1)
00532     {
00533         SWARNING <<
00534             getMimeType() <<
00535             " JPEG storeData only works for 2D 1 or 3 bpp images " <<
00536             std::endl;
00537         return 0;
00538     }
00539 
00540     struct local_error_mgr
00541     {
00542         struct jpeg_error_mgr   pub;
00543         jmp_buf                 setjmp_buffer;
00544     };
00545 
00546     typedef struct local_error_mgr  *local_error_ptr;
00547 
00548     struct local_error_mgr          jerr;
00549     struct jpeg_compress_struct     cinfo;
00550     JSAMPARRAY                      imagebuffer;
00551     UChar8                          *data;
00552 
00553     cinfo.err = jpeg_std_error(&jerr.pub);
00554     if(setjmp(jerr.setjmp_buffer))
00555     {
00556         jpeg_destroy_compress(&cinfo);
00557         return 0;
00558     }
00559 
00560     jpeg_create_compress(&cinfo);
00561     jpeg_memory_dest(&cinfo, buffer, memSize);
00562 
00563     cinfo.image_width = image->getWidth();
00564     cinfo.image_height = image->getHeight();
00565     cinfo.input_components = image->getBpp();
00566     cinfo.in_color_space = (image->getBpp() == 1) ? JCS_GRAYSCALE : JCS_RGB;
00567 
00568     jpeg_set_defaults(&cinfo);
00569     jpeg_set_quality(&cinfo, _quality, TRUE);
00570     jpeg_start_compress(&cinfo, TRUE);
00571 
00572     imagebuffer = &data;
00573     while(cinfo.next_scanline < cinfo.image_height)
00574     {
00575         data = image->getData() +
00576             (image->getHeight() - 1 - cinfo.next_scanline) *
00577             image->getWidth() *
00578             image->getBpp();
00579         jpeg_write_scanlines(&cinfo, imagebuffer, 1);
00580     }
00581 
00582     jpeg_finish_compress(&cinfo);
00583     jpeg_destroy_compress(&cinfo);
00584 
00585     return jpeg_mem.dataSize;
00586 
00587 #else
00588     SWARNING <<
00589         getMimeType() <<
00590         " write is not compiled into the current binary " <<
00591         std::endl;
00592     return 0;
00593 #endif
00594 }

JPGImageFileType & JPGImageFileType::the void   )  [static]
 

Class method to get the singleton Object

Definition at line 207 of file OSGJPGImageFileType.cpp.

References _the.

00208 {
00209   return _the;
00210 }

const Char8 * ImageFileType::getMimeType void   )  const [inherited]
 

Get method for the mime type

Definition at line 106 of file OSGImageFileType.cpp.

References osg::ImageFileType::_mimeType, and osg::IDString::str().

Referenced by osg::ImageFileType::dump(), osg::TIFImageFileType::read(), osg::PNGImageFileType::read(), osg::MNGImageFileType::read(), read(), osg::ImageFileHandler::read(), osg::PNGImageFileType::restoreData(), restoreData(), osg::ImageFileType::restoreData(), osg::ImageFileType::store(), osg::ImageFileHandler::store(), osg::PNGImageFileType::storeData(), storeData(), osg::ImageFileType::storeData(), osg::TIFImageFileType::write(), osg::TGAImageFileType::write(), osg::PNGImageFileType::write(), osg::MNGImageFileType::write(), write(), osg::ImageFileHandler::write(), osg::GIFImageFileType::write(), and osg::DDSImageFileType::write().

00107 {
00108     return _mimeType.str();
00109 }

const std::list< IDString > & ImageFileType::getSuffixList void   )  const [inherited]
 

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 }

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 116 of file OSGImageFileType.cpp.

References osg::ImageFileType::_flags.

Referenced by osg::ImageFileHandler::getSuffixList().

00117 {
00118     return _flags;
00119 }

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 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 }

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 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 }

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 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 }

UInt64 ImageFileType::maxBufferSize const ImagePtr image  )  [virtual, inherited]
 

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 }

void ImageFileType::dump void   )  [inherited]
 

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 }


Member Data Documentation

UInt32 osg::JPGImageFileType::_quality [private]
 

Definition at line 130 of file OSGJPGImageFileType.h.

Referenced by getQuality(), setQuality(), storeData(), and write().

JPGImageFileType JPGImageFileType::_the [static, private]
 

Referenced by the().


The documentation for this class was generated from the following files:
Generated on Thu Aug 25 04:14:22 2005 for OpenSG by  doxygen 1.4.3