#include <OSGPNMImageFileType.h>
Inheritance diagram for osg::PNMImageFileType:

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 | ~PNMImageFileType (void) |
Read/Write | |
| *virtual bool | read (ImagePtr &image, const Char8 *fileName) |
| virtual bool | write (const ImagePtr &image, const Char8 *fileName) |
Static Public Member Functions | |
Get Methods | |
| *static PNMImageFileType & | the (void) |
Protected Member Functions | |
Default Constructor | |
| * | PNMImageFileType (const Char8 *mimeType, const Char8 *suffixArray[], UInt16 suffixByteCount, UInt32 flags) |
Copy Constructor | |
| * | PNMImageFileType (const PNMImageFileType &obj) |
Private Types | |
| typedef ImageFileType | Inherited |
Static Private Attributes | |
| static PNMImageFileType | _the |
All the type specific code is included in the class. Does not depend on external libs.
Definition at line 55 of file OSGPNMImageFileType.h.
|
|
Definition at line 107 of file OSGPNMImageFileType.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 347 of file OSGPNMImageFileType.cpp.
|
|
||||||||||||||||||||
|
Constructor used for the singleton object Definition at line 324 of file OSGPNMImageFileType.cpp. 00327 : 00328 ImageFileType(mimeType,suffixArray, suffixByteCount, flags) 00329 { 00330 return; 00331 }
|
|
|
Dummy Copy Constructor Definition at line 337 of file OSGPNMImageFileType.cpp. 00337 : 00338 ImageFileType(obj) 00339 { 00340 return; 00341 }
|
|
|
Class method to get the singleton Object Definition at line 104 of file OSGPNMImageFileType.cpp. References _the. 00105 { 00106 return _the; 00107 }
|
|
||||||||||||
|
Tries to fill the image object with the data read from the given fileName. Returns true on success. Implements osg::ImageFileType. Definition at line 118 of file OSGPNMImageFileType.cpp. References FWARNING, INT_MAX, osg::Image::OSG_L_PF, osg::Image::OSG_LA_PF, osg::Image::OSG_RGB_PF, osg::Image::OSG_RGBA_PF, SINFO, and SWARNING. 00119 { 00120 bool isBinary = true; 00121 Int16 type = 0, width, height, lineSize, maxValue=0, value, x, y; 00122 UInt32 i, n; 00123 UChar8 *imageData = 0; 00124 UInt8 id, commentKey = '#'; 00125 std::ifstream in(fileName, std::ios::in | std::ios::binary); 00126 00127 if(in.rdbuf()->is_open()) 00128 { 00129 in >> id >> type; 00130 in.ignore(INT_MAX, '\n'); 00131 while(in.peek() == commentKey) 00132 in.ignore(INT_MAX, '\n'); 00133 in >> width >> height; 00134 isBinary = ((type > 3) && (type < 7)) ? true : false; 00135 } 00136 else 00137 { 00138 FWARNING(("Error opening PNM file %s!\n", fileName)); 00139 return false; 00140 } 00141 00142 switch(type) 00143 { 00144 case 1: 00145 case 4: 00146 maxValue = 1; 00147 image->set(Image::OSG_L_PF, width, height); 00148 break; 00149 case 2: 00150 case 5: 00151 maxValue = 0; 00152 image->set(Image::OSG_L_PF, width, height); 00153 break; 00154 case 3: 00155 case 6: 00156 maxValue = 0; 00157 image->set(Image::OSG_RGB_PF, width, height); 00158 break; 00159 case 7: // LA extention 00160 FWARNING (("Read PNM type %d: LA-ascii extention\n",type )); 00161 maxValue = 0; 00162 image->set(Image::OSG_LA_PF, width, height); 00163 break; 00164 case 8: // RGBA extention 00165 FWARNING (("Read PNM type %d: RGBA-ascii extention\n",type )); 00166 maxValue = 0; 00167 image->set(Image::OSG_RGBA_PF, width, height); 00168 break; 00169 default: 00170 SWARNING << 00171 "unknown image format type " << 00172 type << 00173 " in " << 00174 fileName << 00175 std::endl; 00176 break; 00177 } 00178 00179 if(!maxValue) 00180 { 00181 in >> maxValue; 00182 if(maxValue != 255) 00183 { 00184 SWARNING << 00185 "unknown max value " << 00186 maxValue << 00187 " in " << 00188 fileName << 00189 ", can't read the image" << 00190 std::endl; 00191 maxValue = 0; 00192 } 00193 } 00194 00195 // eat the endline 00196 in.ignore(INT_MAX, '\n'); 00197 00198 if(maxValue && (imageData = image->getData())) 00199 { 00200 SINFO << 00201 "Read pnm file of type " << 00202 type << 00203 ", " << 00204 width << 00205 "x" << 00206 height << 00207 std::endl; 00208 00209 lineSize = width * image->getBpp(); 00210 if(isBinary) 00211 { // image is binary 00212 for(y = height - 1; y >= 0; y--) 00213 { 00214 in.read((Char8 *) &(imageData[y * lineSize]), lineSize); 00215 } 00216 } 00217 else 00218 { // image is ascii 00219 for(y = height - 1; y >= 0; y--) 00220 { 00221 for(x = 0; x < lineSize; x++) 00222 { 00223 in >> value; 00224 imageData[y * lineSize + x] = UChar8(value); 00225 } 00226 } 00227 } 00228 00229 if(maxValue == 1) 00230 { 00231 n = image->getSize(); 00232 for(i = 0; i < n; i++) 00233 imageData[0] *= 255; 00234 } 00235 } 00236 00237 return true; 00238 }
|
|
||||||||||||
|
Tries to write the image object to the given fileName. Returns true on success. Implements osg::ImageFileType. Definition at line 245 of file OSGPNMImageFileType.cpp. References p. 00246 { 00247 Int16 p, y, x, lineSize; 00248 std::ofstream out(fileName, std::ios::out | std::ios::binary); 00249 UInt16 bpp = image->getBpp(); 00250 UInt8 *data = 0; 00251 00252 if(out.rdbuf()->is_open()) 00253 { 00254 switch(bpp) 00255 { 00256 case 1: 00257 case 2: 00258 out << "P5" << std::endl; 00259 break; 00260 case 3: 00261 case 4: 00262 out << "P6" << std::endl; 00263 break; 00264 } 00265 00266 out << "# PNMImageFileType write" << std::endl; 00267 out << image->getWidth() << " " << image->getHeight() << std::endl; 00268 out << "255" << std::endl; 00269 00270 if(bpp & 1) 00271 { 00272 // with alpha 00273 lineSize = image->getBpp() * image->getWidth(); 00274 for(y = image->getHeight() - 1; y >= 0; y--) 00275 { 00276 out.write((char *) (image->getData() + (lineSize * y)), 00277 lineSize); 00278 } 00279 } 00280 else 00281 { 00282 // skip alpha 00283 lineSize = image->getBpp() * image->getWidth(); 00284 for(y = image->getHeight() - 1; y >= 0; y--) 00285 { 00286 data = (UInt8 *) (image->getData() + (lineSize * y)); 00287 for(x = 0; x < image->getWidth(); x++) 00288 { 00289 for(p = bpp - 1; p--;) 00290 out << *data++; 00291 data++; 00292 } 00293 } 00294 } 00295 00296 out.close(); 00297 } 00298 00299 return data ? true : false; 00300 }
|
|
|
|
Get method for the suffix list container Definition at line 125 of file OSGImageFileType.cpp. References osg::ImageFileType::_suffixList. Referenced by osg::ImageFileHandler::addImageFileType(). 00126 { 00127 return _suffixList; 00128 }
|
|
|
Get method for the flags indicating read/write support. Most image types only support reading. Definition at line 116 of file OSGImageFileType.cpp. References osg::ImageFileType::_flags. Referenced by osg::ImageFileHandler::getSuffixList(). 00117 { 00118 return _flags; 00119 }
|
|
||||||||||||
|
Reimplemented in osg::GIFImageFileType, osg::JPGImageFileType, osg::PNGImageFileType, osg::SGIImageFileType, and osg::TIFImageFileType. Definition at line 132 of file OSGImageFileType.cpp. Referenced by osg::ImageFileHandler::getFileType().
|
|
||||||||||||||||
|
Tries to restore the Imagedata from the given memblock. The buffer must include a ImageFileType::Head data block. Definition at line 223 of file OSGImageFileType.cpp. References FDEBUG, FWARNING, osg::ImageFileHandler::getFileType(), osg::NullFC, osg::Image::OSG_UINT8_IMAGEDATA, osg::ImageFileType::restoreData(), and osg::ImageFileHandler::the(). Referenced by osg::ClusterViewBuffer::recv(), osg::ImageFileHandler::restore(), and osg::SimpleSceneManager::useOpenSGLogo(). 00225 { 00226 unsigned long imageSize, headSize = sizeof(Head); 00227 unsigned long size = 0, attachmentSize; 00228 Head head; 00229 const UChar8 *data = buffer ? (buffer + headSize) : 0; 00230 ImageFileType *type; 00231 const char *mimeType; 00232 Image::Type dataType; 00233 00234 if ((image != osg::NullFC) && buffer && (memSize >= headSize)) { 00235 00236 // Copy header. Otherwise netToHost would change the original 00237 // data structur. 00238 memcpy(&head,buffer,sizeof(Head)); 00239 head.netToHost(); 00240 mimeType = head.mimeType; 00241 00242 if((type = ImageFileHandler::the().getFileType(mimeType, 0))) 00243 { 00244 if (head.dataType) 00245 dataType = Image::Type(head.dataType); 00246 else 00247 dataType = Image::OSG_UINT8_IMAGEDATA; 00248 00249 image->set(Image::PixelFormat(head.pixelFormat), head.width, 00250 head.height, head.depth, head.mipmapCount, 00251 head.frameCount, float(head.frameDelay) / 1000.0, 0, 00252 dataType,true,head.sideCount ); 00253 imageSize = static_cast<unsigned long>( 00254 type->restoreData(image, data, memSize - headSize)); 00255 attachmentSize = 0; // head->attachmentSize; 00256 00257 /* 00258 if ((attachmentSize = head->attachmentSize)) 00259 { 00260 attData = (char*)(buffer + headSize + imageSize); 00261 attKey = attData; 00262 attValue = 0; 00263 for (i = 0; i < (attachmentSize-1); i++) { 00264 if (attData[i] == 0) 00265 if (attKey) { 00266 attValue = &(attData[i+1]); 00267 image->setAttachmentField (attKey,attValue); 00268 attKey = attValue = 0; 00269 } 00270 else 00271 attKey = &(attData[i+1]); 00272 } 00273 if (attKey || attValue) { 00274 FFATAL (("Attachment restore error\n")); 00275 } 00276 } 00277 */ 00278 00279 size = headSize + imageSize + attachmentSize; 00280 00281 FDEBUG (( "Restore image data: %lu (%lu/%lu/%lu)\n", 00282 size, headSize, imageSize, attachmentSize )); 00283 00284 } 00285 else 00286 { 00287 imageSize = 0; 00288 FWARNING(("Can not restore image data, invalid mimeType: %s\n", 00289 mimeType ? mimeType : "Unknown")); 00290 } 00291 00292 00293 } 00294 00295 return size; 00296 }
|
|
||||||||||||||||||||
|
Tries to store the raster data to the given mem block. Will include a ImageFileType::Head description and the data encoded as 'mimeType' Definition at line 304 of file OSGImageFileType.cpp. References osg::ImageFileHandler::getFileType(), osg::ImageFileType::store(), and osg::ImageFileHandler::the(). Referenced by osg::ClusterViewBuffer::send(), osg::ImageFileType::store(), and osg::ImageFileHandler::store(). 00306 { 00307 ImageFileType *type = ImageFileHandler::the().getFileType(mimeType); 00308 00309 return type ? type->store(image, buffer, memSize) : 0; 00310 }
|
|
||||||||||||||||
|
Tries to store the raster data to the given mem block. Will include a ImageFileType::Head description for the derived concreate mimeType. Definition at line 318 of file OSGImageFileType.cpp. References osg::ImageFileType::Head::attachmentSize, osg::ImageFileType::Head::dataType, osg::ImageFileType::Head::depth, FDEBUG, FFATAL, osg::ImageFileType::Head::frameCount, osg::ImageFileType::Head::frameDelay, osg::ImageFileType::getMimeType(), osg::ImageFileType::Head::height, osg::ImageFileType::Head::hostToNet(), osg::ImageFileType::Head::mimeType, osg::ImageFileType::Head::mipmapCount, osg::ImageFileType::Head::pixelFormat, osg::ImageFileType::Head::sideCount, osg::ImageFileType::storeData(), and osg::ImageFileType::Head::width. 00320 { 00321 Head *head; 00322 unsigned long dataSize = 0, headSize = sizeof(Head); 00323 unsigned long attachmentSize; 00324 UChar8 *dest; 00325 const UChar8 *src = image->getData(); 00326 std::map<std::string, std::string>::const_iterator aI; 00327 std::string value; 00328 00329 attachmentSize = 0; 00330 00331 // get attachment size 00332 /* 00333 ImageGenericAttPtr att=ImageGenericAttPtr::dcast( 00334 const_cast<Image*>(image.getCPtr())->findAttachment( 00335 ImageGenericAtt::getClassType().getGroupId())); 00336 if(att != NullFC) 00337 { 00338 for(i = 0; i < (att->getType().getNumFieldDescs()-1); ++i) 00339 { 00340 FieldDescription *fieldDesc=att->getType().getFieldDescription(i); 00341 Field *field=att->getField(i); 00342 if (fieldDesc && field) 00343 { 00344 field->getValueByStr(value); 00345 attachmentSize += strlen( fieldDesc->getName().str() ) + 1; 00346 attachmentSize += value.length() + 1; 00347 00348 std::cout << fieldDesc->getName().str() << std::endl; 00349 std::cout << value << std::endl; 00350 } 00351 else 00352 { 00353 FFATAL (("Invalid Attachment in ImageFileType::store()\n")); 00354 } 00355 } 00356 } 00357 */ 00358 00359 if (buffer) 00360 { 00361 head = (Head *)buffer; 00362 00363 head->pixelFormat = image->getPixelFormat(); 00364 head->width = image->getWidth(); 00365 head->height = image->getHeight(); 00366 head->depth = image->getDepth(); 00367 head->mipmapCount = image->getMipMapCount(); 00368 head->frameCount = image->getFrameCount(); 00369 head->frameDelay = short(image->getFrameDelay() * 1000.0); 00370 head->sideCount = image->getSideCount(); 00371 head->dataType = image->getDataType(); 00372 head->attachmentSize = static_cast<unsigned short>(attachmentSize); 00373 head->hostToNet(); 00374 00375 strcpy(head->mimeType, getMimeType()); 00376 00377 dest = (UChar8 *) (buffer + headSize); 00378 00379 if (src) 00380 dataSize = static_cast<unsigned long>( 00381 storeData(image, dest, memSize - headSize)); 00382 00383 dest = (UChar8 *) (buffer + headSize + dataSize); 00384 00385 /* 00386 if(att != NullFC) 00387 { 00388 for(i = 0; i < (att->getType().getNumFieldDescs()-1); ++i) 00389 { 00390 FieldDescription *fieldDesc=att->getType().getFieldDescription(i); 00391 Field *field=att->getField(i); 00392 if (field && fieldDesc) 00393 { 00394 field->getValueByStr(value); 00395 00396 l = strlen( fieldDesc->getName().str() ); 00397 for (i = 0; i < l; i++) 00398 *dest++ = fieldDesc->getName().str()[i]; 00399 *dest++ = 0; 00400 l = value.length(); 00401 for (i = 0; i < l; i++) 00402 *dest++ = value[i]; 00403 *dest++ = 0; 00404 } 00405 else 00406 { 00407 FFATAL (("Invalid Attachment in ImageFileType::store()\n")); 00408 } 00409 } 00410 } 00411 */ 00412 00413 FDEBUG (( "Store image data: %lu (%lu/%lu/%lu)\n", 00414 headSize + dataSize + attachmentSize, headSize, dataSize, 00415 attachmentSize )); 00416 } 00417 else { 00418 FFATAL (("Invalid buffer in ImageFileType::store()\n")); 00419 } 00420 00421 return (headSize + dataSize + attachmentSize); 00422 00423 }
|
|
|
Returns the max buffer size needed to store the Image (Head + mimeType specific data block) Definition at line 430 of file OSGImageFileType.cpp. References FINFO. Referenced by osg::ClusterViewBuffer::send(), and osg::ImageFileHandler::store(). 00431 { 00432 std::string value; 00433 unsigned long size, attachmentSize; 00434 unsigned long imageSize = image->getSize(), headSize = sizeof(Head); 00435 00436 std::map<std::string, std::string>::const_iterator aI; 00437 00438 attachmentSize = 0; 00439 00440 // get attachment size 00441 /* 00442 ImageGenericAttPtr att=ImageGenericAttPtr::dcast( 00443 const_cast<Image*>(image.getCPtr())->findAttachment( 00444 ImageGenericAtt::getClassType().getGroupId())); 00445 if(att != NullFC) 00446 { 00447 for(i = 0; i < (att->getType().getNumFieldDescs()-1); ++i) 00448 { 00449 FieldDescription *fieldDesc=att->getType().getFieldDescription(i); 00450 Field *field=att->getField(i); 00451 if (field && fieldDesc) 00452 { 00453 field->getValueByStr(value); 00454 attachmentSize += strlen( fieldDesc->getName().str() ) + 1; 00455 attachmentSize += value.length() + 1; 00456 } 00457 else 00458 { 00459 FFATAL (("Invalid Attachment in ImageFileType::maxBufferSize()\n")); 00460 } 00461 } 00462 } 00463 */ 00464 00465 size = headSize + imageSize + attachmentSize; 00466 00467 FINFO (( "ImageFileType::maxBufferSize(): %lu (%lu/%lu/%lu)\n", 00468 size, headSize, imageSize, attachmentSize )); 00469 00470 return size; 00471 }
|
|
||||||||||||||||
|
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