#include <OSGGIFImageFileType.h>
Inheritance diagram for osg::GIFImageFileType:

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 | ~GIFImageFileType (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) |
Static Public Member Functions | |
Get Method | |
| *static GIFImageFileType & | the (void) |
Protected Member Functions | |
Default Constructor | |
| * | GIFImageFileType (const Char8 *mimeType, const Char8 *suffixArray[], UInt16 suffixByteCount) |
Copy Constructor | |
| * | GIFImageFileType (const GIFImageFileType &obj) |
Private Types | |
| typedef ImageFileType | Inherited |
Static Private Attributes | |
| static GIFImageFileType | _the |
Definition at line 55 of file OSGGIFImageFileType.h.
|
|
Definition at line 111 of file OSGGIFImageFileType.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 537 of file OSGGIFImageFileType.cpp.
|
|
||||||||||||||||
|
Constructor used for the singleton object Definition at line 515 of file OSGGIFImageFileType.cpp. 00517 : 00518 ImageFileType(mimeType,suffixArray, suffixByteCount) 00519 { 00520 return; 00521 }
|
|
|
Dummy Copy Constructor Definition at line 527 of file OSGGIFImageFileType.cpp. 00527 : 00528 ImageFileType(obj) 00529 { 00530 return; 00531 }
|
|
||||||||||||
|
Tries to fill the image object with the data read from the given fileName. Returns true on success. Implements osg::ImageFileType. Definition at line 199 of file OSGGIFImageFileType.cpp. References FDEBUG, FWARNING, osg::Image::OSG_INVALID_PF, osg::Image::OSG_L_PF, osg::Image::OSG_LA_PF, osg::Image::OSG_RGB_PF, and osg::Image::OSG_RGBA_PF. 00201 { 00202 bool retCode = false; 00203 00204 #ifdef OSG_WITH_GIF 00205 Image::PixelFormat pixelFormat = osg::Image::OSG_INVALID_PF; 00206 GIFStream *gifStream = GIFRead(const_cast <char *> (fileName)); 00207 GIFData *gifData = 0; 00208 bool isColor; 00209 int i, j, destI, lineSize, lineEnd; 00210 unsigned red, green, blue; 00211 int transparentIndex; 00212 int width = 0, height = 0, channel = 0, xOff = 0, yOff = 0; 00213 unsigned char *srcData = 0, *destData = 0; 00214 int colorIndex; 00215 unsigned frameCount = 0, currentFrame = 0; 00216 unsigned char *colorMap = 0; 00217 00218 // int imageSize = 0; 00219 int colorMapSize; 00220 Time frameDelay; 00221 00222 if(gifStream) 00223 { 00224 frameCount = 0; 00225 for(gifData = gifStream->data; gifData; gifData = gifData->next) 00226 { 00227 if(gifData->type == gif_image) 00228 frameCount++; 00229 } 00230 } 00231 00232 FDEBUG(("GIF Frames: %d\n", frameCount)); 00233 00234 if(gifStream) 00235 { 00236 for(gifData = gifStream->data; gifData; gifData = gifData->next) 00237 { 00238 switch(gifData->type) 00239 { 00240 case gif_image: 00241 if(frameCount) 00242 { 00243 FDEBUG(("Try to copy GIF Anim Frame %d/%d\n", 00244 (currentFrame + 1), frameCount)); 00245 } 00246 00247 // get the att. 00248 transparentIndex = gifData->info.transparent; 00249 frameDelay = float(gifData->info.delayTime) / 100.0f; 00250 width = gifData->width; 00251 height = gifData->height; 00252 xOff = gifData->x; 00253 yOff = gifData->y; 00254 00255 // check if the movie is color or greyscale 00256 isColor = false; 00257 if(gifData->data.image.cmapSize > 0) 00258 { 00259 colorMapSize = gifData->data.image.cmapSize; 00260 colorMap = (unsigned char *) gifData->data.image.cmapData; 00261 00262 // cout << "INFO: Use gifData colorMap" << endl; 00263 } 00264 else if(gifStream->cmapSize > 0) 00265 { 00266 colorMapSize = gifStream->cmapSize; 00267 colorMap = (unsigned char *) gifStream->cmapData; 00268 00269 // cout << "INFO: Use gifStream colorMap" << endl; 00270 } 00271 else 00272 { 00273 FWARNING(("Bad color map in GIFImageFileType::read()\n")); 00274 colorMapSize = 0; 00275 } 00276 00277 for(i = 0; i < colorMapSize; i++) 00278 { 00279 if(i != transparentIndex) 00280 { 00281 red = colorMap[i * 3 + 0]; 00282 green = colorMap[i * 3 + 1]; 00283 blue = colorMap[i * 3 + 2]; 00284 if(red != green || red != blue) 00285 { 00286 isColor = true; 00287 break; 00288 } 00289 } 00290 } 00291 00292 // calculate the movie channel 00293 channel = (isColor ? 3 : 1) + (transparentIndex >= 0 ? 1 : 0); 00294 00295 if(currentFrame) 00296 { 00297 // is not the first frame 00298 if((channel == image->getBpp()) && 00299 (width == image->getWidth()) && 00300 (height == image->getHeight())) 00301 { 00302 destData = image->getData(0, currentFrame); 00303 } 00304 else 00305 { 00306 FWARNING(("GIF Anim with misc. image dimensions\n")); 00307 00308 fprintf(stderr, "%d %d %d %d %d %d\n", 00309 channel, 00310 image->getBpp(), 00311 gifData->x, 00312 gifData->y, 00313 gifData->width, 00314 gifData->height); 00315 00316 destData = image->getData(0, currentFrame); 00317 00318 memcpy(destData, 00319 image->getData(0, 0), 00320 image->getWidth () * 00321 image->getHeight() * 00322 channel); 00323 //currentFrame++; 00324 // continue; 00325 } 00326 } 00327 else 00328 { 00329 switch(channel) 00330 { 00331 case 1: 00332 pixelFormat = Image::OSG_L_PF; 00333 break; 00334 case 2: 00335 pixelFormat = Image::OSG_LA_PF; 00336 break; 00337 case 3: 00338 pixelFormat = Image::OSG_RGB_PF; 00339 break; 00340 case 4: 00341 pixelFormat = Image::OSG_RGBA_PF; 00342 break; 00343 }; 00344 image->set(pixelFormat, width, height, 1, 1, frameCount, 00345 frameDelay); 00346 destData = image->getData(); 00347 } 00348 00349 // copy the image data) 00350 lineSize = image->getWidth() * channel; 00351 lineEnd = width * channel + xOff * channel; 00352 srcData = gifData->data.image.data; 00353 destData = destData + ((image->getHeight() - yOff - 1) * lineSize); 00354 00355 switch(channel) 00356 { 00357 case 1: // Greyscale without Alpha 00358 destI = 0; 00359 for(i = width * height; i--;) 00360 { 00361 destData[destI++] = colorMap[*srcData++ *3]; 00362 if(destI >= lineSize) 00363 { 00364 destI = 0; 00365 destData -= lineSize; 00366 } 00367 } 00368 break; 00369 00370 case 2: // Greyscale with Alpha 00371 destI = 0; 00372 for(i = width * height; i--;) 00373 { 00374 colorIndex = *srcData++; 00375 if(colorIndex == transparentIndex) 00376 { 00377 destData[destI++] = 0; 00378 destData[destI++] = 0; 00379 } 00380 else 00381 { 00382 destData[destI++] = colorMap[colorIndex * 3]; 00383 destData[destI++] = 255; 00384 } 00385 00386 if(destI >= lineSize) 00387 { 00388 destI = 0; 00389 destData -= lineSize; 00390 } 00391 } 00392 break; 00393 00394 case 3: // RGB without Alpha 00395 destI = 0; 00396 for(i = width * height; i--;) 00397 { 00398 colorIndex = *srcData++; 00399 for(j = 0; j < 3; j++) 00400 { 00401 destData[destI++] = colorMap[colorIndex * 3 + j]; 00402 } 00403 00404 if(destI >= lineSize) 00405 { 00406 destI = 0; 00407 destData -= lineSize; 00408 } 00409 } 00410 break; 00411 00412 case 4: // RGB with Alpha 00413 destI = xOff * 4; 00414 00415 for(i = width * height; i--;) 00416 { 00417 colorIndex = *srcData++; 00418 if(colorIndex == transparentIndex) 00419 { 00420 /* 00421 for(j = 0; j < 3; j++) 00422 destData[destI++] = 0; // RGB 00423 destData[destI++] = 0; // ALPHA 00424 */ 00425 destI += 4; 00426 } 00427 else 00428 { 00429 for(j = 0; j < 3; j++) 00430 { 00431 destData[destI++] = 00432 colorMap[colorIndex * 3 + j]; // RGB 00433 } 00434 00435 destData[destI++] = 255; // ALPHA 00436 } 00437 00438 if(destI >= lineEnd) 00439 { 00440 destI = xOff * 4; 00441 destData -= lineSize; 00442 } 00443 } 00444 break; 00445 } 00446 00447 retCode = true; 00448 00449 currentFrame++; 00450 00451 break; 00452 case gif_comment: 00453 break; 00454 case gif_text: 00455 break; 00456 } 00457 } 00458 00459 GIFFree(gifStream); 00460 } 00461 else 00462 retCode = false; 00463 #endif 00464 return retCode; 00465 }
|
|
||||||||||||
|
Tries to write the image object to the given fileName. Returns true on success. Implements osg::ImageFileType. Definition at line 472 of file OSGGIFImageFileType.cpp. References osg::endLog(), osg::ImageFileType::getMimeType(), and SWARNING. 00474 { 00475 #ifdef OSG_WITH_GIF 00476 SWARNING << getMimeType() << " write is not implemented " << endLog; 00477 00478 #else 00479 SWARNING << 00480 getMimeType() << 00481 " write is not compiled into the current binary " << 00482 endLog; 00483 #endif 00484 return false; 00485 }
|
|
||||||||||||
|
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 487 of file OSGGIFImageFileType.cpp. 00488 { 00489 implemented = true; 00490 00491 if(fileName == NULL) 00492 return false; 00493 00494 FILE *file = fopen(fileName, "rb"); 00495 if(file == NULL) 00496 return false; 00497 00498 std::string magic; 00499 magic.resize(4); 00500 fread((void *) &magic[0], 4, 1, file); 00501 fclose(file); 00502 00503 if(magic == "GIF8") 00504 { 00505 return true; 00506 } 00507 00508 return false; 00509 }
|
|
|
Class method to get the singleton Object Definition at line 189 of file OSGGIFImageFileType.cpp. References _the. 00190 { 00191 return _the; 00192 }
|
|
|
|
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 }
|
|
||||||||||||||||
|
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 }
|
|
||||||||||||||||
|
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::JPGImageFileType, osg::MTDImageFileType, and osg::PNGImageFileType. Definition at line 193 of file OSGImageFileType.cpp. References FWARNING, and osg::ImageFileType::getMimeType(). Referenced by osg::ImageFileType::restore(). 00196 { 00197 FWARNING(("ImageXFileType::restoreData() not impl. for mimeType %s\n", 00198 getMimeType())); 00199 00200 return 0; 00201 }
|
|
||||||||||||||||
|
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::JPGImageFileType, osg::MTDImageFileType, and osg::PNGImageFileType. Definition at line 208 of file OSGImageFileType.cpp. References FWARNING, and osg::ImageFileType::getMimeType(). Referenced by osg::ImageFileType::store(). 00211 { 00212 FWARNING(("ImageXFileType::storeData() not impl. for mimeType %s\n", 00213 getMimeType())); 00214 00215 return 0; 00216 }
|
|
|
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