osg::TIFImageFileType Class Reference
[Image]

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

#include <OSGTIFImageFileType.h>

Inheritance diagram for osg::TIFImageFileType:

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 Types

Flags


enum  { OSG_READ_SUPPORTED = 1, OSG_WRITE_SUPPORTED = 2 }

Public Member Functions

Destructor


virtual ~TIFImageFileType (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)
Set


void setOptions (const Char8 *options)
Get Methods


const Char8getMimeType (void) const
const std::list< IDString > & getSuffixList (void) const
virtual UInt32 getFlags (void) const
const Char8getOptions (void)
Read/Write


virtual bool read (ImagePtr &image, const Char8 *fileName)
virtual bool write (const ImagePtr &image, const Char8 *fileName)
Raw Store/Restore


virtual UInt64 restoreData (ImagePtr &image, const UChar8 *buffer, Int32 memSize=-1)
virtual UInt64 storeData (const ImagePtr &image, UChar8 *buffer, Int32 memSize=-1)
dump


void dump (void)

Static Public Member Functions

Get Method


static TIFImageFileTypethe (void)

Protected Member Functions

Default Constructor


 TIFImageFileType (const Char8 *mimeType, const Char8 *suffixArray[], UInt16 suffixByteCount, UInt32 flags)

Protected Attributes

MTD Header


std::string _options

Private Member Functions

Copy Constructor


 TIFImageFileType (const TIFImageFileType &obj)
Copy Operator


const TIFImageFileTypeoperator= (const TIFImageFileType &obj)

Static Private Attributes

static TIFImageFileType _the


Detailed Description

Image File Type to read/write and store/restore Image objects as TIF (tif/tiff suffix) data.

To be able to load TIFF images you need the IJG TIFF library, (check the Prerequisites page on www.opensg.org). The lib comes with all Linux distributions.

You have to --enable-tif in the configure line to enable the singleton object.

Definition at line 56 of file OSGTIFImageFileType.h.


Member Enumeration Documentation

anonymous enum [inherited]

Enumerator:
OSG_READ_SUPPORTED 
OSG_WRITE_SUPPORTED 

Definition at line 66 of file OSGImageFileType.h.

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


Constructor & Destructor Documentation

TIFImageFileType::~TIFImageFileType ( void   )  [virtual]

Destructor

Definition at line 566 of file OSGTIFImageFileType.cpp.

00566 {}

TIFImageFileType::TIFImageFileType ( const Char8 mimeType,
const Char8 suffixArray[],
UInt16  suffixByteCount,
UInt32  flags 
) [protected]

Constructor used for the singleton object

Definition at line 550 of file OSGTIFImageFileType.cpp.

00553                                                  :
00554     ImageFileType(mimeType, suffixArray, suffixByteCount, flags)
00555 {
00556 #ifdef OSG_WITH_TIF
00557     TIFFSetWarningHandler(&warningHandler);
00558     TIFFSetErrorHandler(&errorHandler);
00559 #endif
00560 }

osg::TIFImageFileType::TIFImageFileType ( const TIFImageFileType obj  )  [private]


Member Function Documentation

TIFImageFileType & TIFImageFileType::the ( void   )  [static]

Class method to get the singleton Object

Definition at line 253 of file OSGTIFImageFileType.cpp.

References _the.

00254 {
00255     return _the;
00256 }

bool TIFImageFileType::validateHeader ( const Char8 fileName,
bool &  implemented 
) [virtual]

Reimplemented from osg::ImageFileType.

Definition at line 522 of file OSGTIFImageFileType.cpp.

00523 {
00524     implemented = true;
00525 
00526     if(fileName == NULL)
00527         return false;
00528 
00529     FILE *file = fopen(fileName, "rb");
00530     if(file == NULL)
00531         return false;
00532 
00533     std::string magic;
00534     magic.resize(2);
00535     fread((void *) &magic[0], 2, 1, file);
00536     fclose(file);
00537 
00538     if(magic == "MM" || magic == "II")
00539     {
00540         return true;
00541     }
00542 
00543     return false;
00544 }

bool TIFImageFileType::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 268 of file OSGTIFImageFileType.cpp.

References osg::ImageFileType::getMimeType(), osg::Image::OSG_INVALID_PF, osg::Image::OSG_L_PF, osg::Image::OSG_LA_PF, osg::Image::OSG_RESUNIT_INCH, osg::Image::OSG_RGB_PF, osg::Image::OSG_RGBA_PF, and SWARNING.

00270 {
00271     bool    valid = false;
00272 
00273 #ifdef OSG_WITH_TIF
00274     TIFF    *in = TIFFClientOpen("dummy", "rm", (thandle_t)&is,
00275                                  isReadProc, isWriteProc, isSeekProc, closeProc,
00276                                  isSizeProc, mapFileProc, unmapFileProc);
00277     UChar8  *data = 0, *line = 0, *dest;
00278     UInt32  w, h, u, v;
00279     Real32  res_x, res_y;
00280     UInt16  res_unit;
00281     UInt16  bpp;
00282     Char8   errorMessage[1024];
00283     UInt16  *sampleinfo;
00284     UInt16  extrasamples;
00285     UInt16  si;
00286     UInt16  red, green, blue, alpha;
00287 
00288     if(in)
00289     {
00290         TIFFGetField(in, TIFFTAG_IMAGEWIDTH, &w);
00291         TIFFGetField(in, TIFFTAG_IMAGELENGTH, &h);
00292 
00293         TIFFGetField(in, TIFFTAG_XRESOLUTION, &res_x);
00294         TIFFGetField(in, TIFFTAG_YRESOLUTION, &res_y);
00295         TIFFGetField(in, TIFFTAG_RESOLUTIONUNIT, &res_unit);
00296 
00297         TIFFGetFieldDefaulted(in, TIFFTAG_SAMPLESPERPIXEL, &bpp);
00298 
00299         if(bpp == 4)
00300         {   // accept unspecified extra samples as associated alpha
00301             TIFFGetFieldDefaulted(in, TIFFTAG_EXTRASAMPLES, &extrasamples,
00302                                   &sampleinfo);
00303 
00304             if(sampleinfo && sampleinfo[0] == EXTRASAMPLE_UNSPECIFIED)
00305             {
00306                 si = EXTRASAMPLE_ASSOCALPHA;
00307                 TIFFSetField(in, TIFFTAG_EXTRASAMPLES, 1, &si);
00308             }
00309         }
00310 
00311         data = new UChar8[w * h * 4];
00312         if(TIFFRGBAImageOK(in, errorMessage) &&
00313            TIFFReadRGBAImage(in, w, h, (uint32 *) data, 1))
00314             valid = true;
00315         else
00316         {
00317             SWARNING << "Tiff reader failed: " << errorMessage << std::endl;
00318             valid = false;
00319         }
00320 
00321         if(valid)
00322         {
00323             Image::PixelFormat  type = osg::Image::OSG_INVALID_PF;
00324             switch(bpp)
00325             {
00326             case 1:
00327                 type = Image::OSG_L_PF;
00328                 break;
00329             case 2:
00330                 type = Image::OSG_LA_PF;
00331                 break;
00332             case 3:
00333                 type = Image::OSG_RGB_PF;
00334                 break;
00335             case 4:
00336                 type = Image::OSG_RGBA_PF;
00337                 break;
00338             }
00339 
00340             image->set(type, w, h);
00341             if(res_unit == RESUNIT_CENTIMETER)
00342             {
00343                 // convert it to dpi.
00344                 res_x *= 2.54f;
00345                 res_y *= 2.54f;
00346                 res_unit = Image::OSG_RESUNIT_INCH;
00347             }
00348             image->setResX(res_x);
00349             image->setResY(res_y);
00350             image->setResUnit(res_unit);
00351             dest = image->getData();
00352 
00353 #if defined(__linux) || defined(_WIN32)
00354             red = 0;
00355             green = 1;
00356             blue = 2;
00357             alpha = 3;
00358 
00359 #else
00360             red = 3;
00361             green = 2;
00362             blue = 1;
00363             alpha = 0;
00364 #endif
00365             for(v = 0; v < h; v++)
00366             {
00367                 line = data + ((v) * (w * 4));
00368                 for(u = 0; u < w; u++)
00369                 {
00370                     switch(bpp)
00371                     {
00372                     case 4:
00373                         *dest++ = line[red];
00374                         *dest++ = line[green];
00375                         *dest++ = line[blue];
00376                         *dest++ = line[alpha];
00377                         break;
00378                     case 3:
00379                         *dest++ = line[red];
00380                         *dest++ = line[green];
00381                         *dest++ = line[blue];
00382                         break;
00383                     case 2:
00384                         *dest++ = line[red];
00385                         *dest++ = line[green];
00386                         break;
00387                     case 1:
00388                         *dest++ = line[red];
00389                         break;
00390                     }
00391 
00392                     line += 4;
00393                 }
00394             }
00395 
00396             TIFFClose(in);
00397             delete[] data;
00398             data = 0;
00399         }
00400     }
00401 
00402 #else
00403     SWARNING <<
00404         getMimeType() <<
00405         " read is not compiled into the current binary " <<
00406         std::endl;
00407 #endif
00408     return valid;
00409 }

bool TIFImageFileType::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 416 of file OSGTIFImageFileType.cpp.

References osg::ImageFileType::_options, FWARNING, osg::ImageFileType::getMimeType(), and SWARNING.

00418 {
00419     bool                retCode = false;
00420 
00421 #ifdef OSG_WITH_TIF
00422     
00423     if(image->getDimension() < 1 || image->getDimension() > 2)
00424     {
00425         FWARNING(("TIFImageFileType::write: invalid dimension %d!\n",
00426             image->getDimension()));
00427         return false;
00428     }
00429 
00430     TIFF         *out = TIFFClientOpen("dummy", "wm", (thandle_t)&os,
00431                                        osReadProc, osWriteProc, osSeekProc, closeProc,
00432                                        osSizeProc, mapFileProc, unmapFileProc);
00433     int           lineSize = image->getWidth() * image->getBpp();
00434     int           photometric = 0, samplesPerPixel = 0;
00435     const UChar8 *data;
00436     int           row;
00437 
00438     // TODO: implement all cases correct
00439     switch(image->getBpp())
00440     {
00441     case 1:
00442         samplesPerPixel = 1;
00443         photometric = PHOTOMETRIC_MINISBLACK;
00444         break;
00445     case 2:
00446         samplesPerPixel = 2;
00447         photometric = PHOTOMETRIC_MINISBLACK;
00448         break;
00449     case 3:
00450         samplesPerPixel = 3;
00451         photometric = PHOTOMETRIC_RGB;
00452         break;
00453     case 4:
00454         samplesPerPixel = 4;
00455         photometric = PHOTOMETRIC_RGB;
00456         break;
00457     }
00458 
00459     if(out)
00460     {
00461         TIFFSetField(out, TIFFTAG_IMAGEWIDTH, image->getWidth());
00462         TIFFSetField(out, TIFFTAG_IMAGELENGTH, image->getHeight());
00463         TIFFSetField(out, TIFFTAG_XRESOLUTION, image->getResX());
00464         TIFFSetField(out, TIFFTAG_YRESOLUTION, image->getResY());
00465         TIFFSetField(out, TIFFTAG_RESOLUTIONUNIT, image->getResUnit());
00466         TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
00467         TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, samplesPerPixel);
00468         TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 8);
00469         TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
00470         TIFFSetField(out, TIFFTAG_PHOTOMETRIC, photometric);
00471 
00472         if(_options.find("compressionType=LZW") != std::string::npos)
00473             TIFFSetField(out, TIFFTAG_COMPRESSION, COMPRESSION_LZW);
00474         else
00475             TIFFSetField(out, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
00476 
00477         TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(out, 0));
00478 
00479         for(row = 0; row < image->getHeight(); row++)
00480         {
00481             data = image->getData() + ((image->getHeight() - row - 1) * lineSize);
00482             if(TIFFWriteScanline(out, 
00483                                  (tdata_t) const_cast<UChar8 *>(data), 
00484                                  row, 
00485                                  0) < 0)
00486                 break;
00487         }
00488 
00489         TIFFClose(out);
00490         retCode = true;
00491     }
00492 
00493 #else
00494     SWARNING <<
00495         getMimeType() <<
00496         " write is not compiled into the current binary " <<
00497         std::endl;
00498 #endif
00499     return retCode;
00500 }

std::string TIFImageFileType::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 508 of file OSGTIFImageFileType.cpp.

References osg::ImageFileType::getMimeType().

00509 {
00510     char filecode[4];
00511     is.read(filecode, 4);
00512     is.seekg(-4, std::ios::cur);
00513     if (strncmp(filecode, "MM\x00\x2a", 4) == 0)
00514         return std::string(getMimeType());
00515     if (strncmp(filecode, "II\x2a\x00", 4) == 0)
00516         return std::string(getMimeType());
00517     return std::string();
00518 }

const TIFImageFileType& osg::TIFImageFileType::operator= ( const TIFImageFileType 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]

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 }

bool ImageFileType::read ( ImagePtr image,
const Char8 fileName 
) [virtual, inherited]

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 }

bool ImageFileType::write ( const ImagePtr image,
const Char8 fileName 
) [virtual, inherited]

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 }

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

UInt64 ImageFileType::restoreData ( ImagePtr image,
const UChar8 buffer,
Int32  memSize = -1 
) [virtual, inherited]

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

Reimplemented in osg::DATImageFileType, osg::EXRImageFileType, osg::HDRImageFileType, osg::JPGImageFileType, osg::MTDImageFileType, and osg::PNGImageFileType.

Definition at line 253 of file OSGImageFileType.cpp.

References FWARNING, and osg::ImageFileType::getMimeType().

00256 {
00257   FWARNING(("ImageXFileType::restoreData() not impl. for mimeType %s\n",
00258             getMimeType()));
00259 
00260   return 0;
00261 }

UInt64 ImageFileType::storeData ( const ImagePtr image,
UChar8 buffer,
Int32  memSize = -1 
) [virtual, inherited]

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

Reimplemented in osg::DATImageFileType, osg::EXRImageFileType, osg::HDRImageFileType, osg::JPGImageFileType, osg::MTDImageFileType, and osg::PNGImageFileType.

Definition at line 268 of file OSGImageFileType.cpp.

References FWARNING, and osg::ImageFileType::getMimeType().

Referenced by osg::ImageFileType::store().

00271 {
00272   FWARNING(("ImageXFileType::storeData() not impl. for mimeType %s\n",
00273             getMimeType()));
00274   
00275   return 0;
00276 }

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 }


Member Data Documentation

Definition at line 120 of file OSGTIFImageFileType.h.

Referenced by the().

std::string osg::ImageFileType::_options [protected, inherited]


The documentation for this class was generated from the following files:

Generated on Mon Mar 17 12:05:57 2008 for OpenSG by  doxygen 1.5.5