#include <OSGHDRImageFileType.h>

Safe Store/Restore | |
| UInt64 | store (const ImagePtr &image, UChar8 *buffer, Int32 memSize=-1) |
| virtual UInt64 | maxBufferSize (const ImagePtr &image) |
| static UInt64 | restore (ImagePtr &image, const UChar8 *buffer, Int32 memSize=-1) |
| static UInt64 | store (const ImagePtr &image, const char *mimeType, UChar8 *buffer, Int32 memSize=-1) |
Public Types | |
Flags | |
| enum | { OSG_READ_SUPPORTED = 1, OSG_WRITE_SUPPORTED = 2 } |
Public Member Functions | |
Destructor | |
| virtual | ~HDRImageFileType (void) |
Read/Write | |
| virtual bool | read (ImagePtr &image, const Char8 *fileName) |
| virtual bool | write (const ImagePtr &image, const Char8 *fileName) |
| 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) |
Set | |
| void | setOptions (const Char8 *options) |
Get Methods | |
| const Char8 * | getMimeType (void) const |
| const std::list< IDString > & | getSuffixList (void) const |
| virtual UInt32 | getFlags (void) const |
| const Char8 * | getOptions (void) |
Read/Write | |
| virtual bool | validateHeader (const Char8 *fileName, bool &implemented) |
| virtual std::string | determineMimetypeFromStream (std::istream &is) |
dump | |
| void | dump (void) |
Static Public Member Functions | |
Get Methods | |
| static HDRImageFileType & | the (void) |
Protected Member Functions | |
Default Constructor | |
| HDRImageFileType (const Char8 *mimeType, const Char8 *suffixArray[], UInt16 suffixByteCount, UInt32 flags) | |
Buffer | |
| virtual UInt64 | restoreData (ImagePtr &image, const UChar8 *buffer, Int32 memSize=-1) |
| virtual UInt64 | storeData (const ImagePtr &image, UChar8 *buffer, Int32 memSize=-1) |
Protected Attributes | |
MTD Header | |
| std::string | _options |
Private Types | |
| typedef unsigned char | RGBE [4] |
| typedef ImageFileType | Inherited |
Private Member Functions | |
| HDRImageFileType (const HDRImageFileType &obj) | |
| bool | checkHDR (FILE *file, int &width, int &height) |
| bool | checkHDR (std::istream &is, int &width, int &height) |
| bool | radiance2fp (FILE *file, Real32 *data, int width, int height) |
| bool | radiance2fp (std::istream &is, Real32 *data, int width, int height) |
| bool | freadcolrs (FILE *file, RGBE *scan, int width) |
| bool | freadcolrs (std::istream &is, RGBE *scan, int width) |
| bool | oldreadcolrs (FILE *file, RGBE *scan, int width) |
| void | RGBE2Float (RGBE rgbe, Real32 *fcol) |
| void | RGBE2Half (RGBE rgbe, Real16 *fcol) |
| int | fwritecolrs (FILE *file, Real32 *scan, RGBE *rgbe_scan, int width, int height) |
| int | fwritecolrs (FILE *file, Real16 *scan, RGBE *rgbe_scan, int width, int height) |
| int | fwritecolrs (std::ostream &os, Real32 *scan, RGBE *rgbe_scan, int width, int height) |
| int | fwritecolrs (std::ostream &os, Real16 *scan, RGBE *rgbe_scan, int width, int height) |
| int | fwriteRGBE (FILE *file, RGBE *rgbe_scan, int width, int height) |
| int | fwriteRGBE (std::ostream &os, RGBE *rgbe_scan, int width, int height) |
| void | half2RGBE (Real16 *fcol, RGBE rgbe) |
| void | float2RGBE (Real32 *fcol, RGBE rgbe) |
Static Private Attributes | |
| static HDRImageFileType | _the |
All the type specific code is included in the class. Does not depend on external libs.
Definition at line 56 of file OSGHDRImageFileType.h.
typedef unsigned char osg::HDRImageFileType::RGBE[4] [private] |
Definition at line 119 of file OSGHDRImageFileType.h.
typedef ImageFileType osg::HDRImageFileType::Inherited [private] |
Definition at line 147 of file OSGHDRImageFileType.h.
anonymous enum [inherited] |
Definition at line 66 of file OSGImageFileType.h.
00067 { 00068 OSG_READ_SUPPORTED = 1, 00069 OSG_WRITE_SUPPORTED = 2 00070 };
| HDRImageFileType::~HDRImageFileType | ( | void | ) | [virtual] |
| HDRImageFileType::HDRImageFileType | ( | const Char8 * | mimeType, | |
| const Char8 * | suffixArray[], | |||
| UInt16 | suffixByteCount, | |||
| UInt32 | flags | |||
| ) | [protected] |
Constructor used for the singleton object
Definition at line 353 of file OSGHDRImageFileType.cpp.
00357 : ImageFileType ( mimeType, suffixArray, suffixByteCount, flags ) 00358 { 00359 // FLOG(( "HDRImageFileType: %s %d\n", mimeType, flags )); 00360 }
| osg::HDRImageFileType::HDRImageFileType | ( | const HDRImageFileType & | obj | ) | [private] |
| HDRImageFileType & HDRImageFileType::the | ( | void | ) | [static] |
Class method to get the singleton Object
Definition at line 114 of file OSGHDRImageFileType.cpp.
References _the.
00115 { 00116 return _the; 00117 }
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 211 of file OSGHDRImageFileType.cpp.
References checkHDR(), osg::PathHandler::findFile(), osg::ImageFileHandler::getPathHandler(), osg::Image::OSG_FLOAT32_IMAGEDATA, osg::Image::OSG_RGB_PF, radiance2fp(), and osg::ImageFileHandler::the().
00213 { 00214 FILE *file = fopen(fileName, "rb"); 00215 00216 if(file == NULL && ImageFileHandler::the().getPathHandler()) 00217 { 00218 // Try to find the file in the search path 00219 PathHandler *ph = ImageFileHandler::the().getPathHandler(); 00220 file = fopen(ph->findFile(fileName).c_str(), "rb"); 00221 } 00222 00223 if(file == NULL) 00224 return false; 00225 00226 int width, height; 00227 if(!checkHDR(file, width, height)) 00228 { 00229 fclose(file); 00230 return false; 00231 } 00232 00233 image->set (Image::OSG_RGB_PF, width, height, 1, 1, 1, 0.0, 0, Image::OSG_FLOAT32_IMAGEDATA); 00234 image->clear(); 00235 00236 Real32 *data = ((Real32 *)(image->getData())); 00237 00238 bool ok = radiance2fp(file, data, width, height); 00239 fclose(file); 00240 return ok; 00241 }
Tries to write the image object to the given fileName. Returns true on success.
Reimplemented from osg::ImageFileType.
Definition at line 248 of file OSGHDRImageFileType.cpp.
References FWARNING, fwritecolrs(), osg::Image::OSG_FLOAT16_IMAGEDATA, and osg::Image::OSG_FLOAT32_IMAGEDATA.
00250 { 00251 if( ( image->getDataType() != Image::OSG_FLOAT32_IMAGEDATA) && 00252 ( image->getDataType() != Image::OSG_FLOAT16_IMAGEDATA)) 00253 { 00254 FWARNING(("HDRImageFileType::write: Image has non float data type!\n")); 00255 return false; 00256 } 00257 00258 FILE *file = fopen(fileName, "wb"); 00259 00260 if(file == NULL) 00261 return false; 00262 00263 int width = image->getWidth(); 00264 int height = image->getHeight(); 00265 00266 fprintf(file, "#?RADIANCE"); 00267 fputc(10, file); 00268 fprintf(file, "# %s", "Written with OpenSG"); 00269 fputc(10, file); 00270 fprintf(file, "FORMAT=32-bit_rle_rgbe"); 00271 fputc(10, file); 00272 fprintf(file, "EXPOSURE=%25.13f", 1.0); 00273 fputc(10, file); 00274 fputc(10, file); 00275 fprintf(file, "-Y %d +X %d", height, width); 00276 fputc(10, file); 00277 00278 RGBE *rgbe_scan = new RGBE[width]; 00279 00280 if( image->getDataType() == Image::OSG_FLOAT32_IMAGEDATA) 00281 { 00282 Real32 *data = ((Real32 *)(image->getData())); 00283 00284 //upside down !!! 00285 for(int y=height-1;y>=0;y--) 00286 { 00287 if (fwritecolrs(file, &data[y * width * 3], rgbe_scan, width, height) < 0) 00288 { 00289 fclose(file); 00290 delete [] rgbe_scan; 00291 return false; 00292 } 00293 } 00294 } 00295 else // 16 bit floating point data 00296 { 00297 Real16 *data = ((Real16 *)(image->getData())); 00298 00299 //upside down !!! 00300 for(int y=height-1;y>=0;y--) 00301 { 00302 if (fwritecolrs(file, &data[y * width * 3], rgbe_scan, width, height) < 0) 00303 { 00304 fclose(file); 00305 delete [] rgbe_scan; 00306 return false; 00307 } 00308 } 00309 } 00310 fclose(file); 00311 delete [] rgbe_scan; 00312 return true; 00313 }
| bool HDRImageFileType::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 128 of file OSGHDRImageFileType.cpp.
References checkHDR(), FWARNING, osg::Image::OSG_FLOAT32_IMAGEDATA, osg::Image::OSG_RGB_PF, and radiance2fp().
00129 { 00130 int width, height; 00131 00132 if (!checkHDR(is, width, height)) 00133 { 00134 FWARNING(("No valid RADIANCE picture format\n")); 00135 return false; 00136 } 00137 00138 image->set (Image::OSG_RGB_PF, width, height, 1, 1, 1, 0.0, 0, Image::OSG_FLOAT32_IMAGEDATA); 00139 image->clear(); 00140 00141 Real32 *data = ((Real32 *)(image->getData())); 00142 00143 return radiance2fp(is, data, width, height); 00144 }
| bool HDRImageFileType::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 151 of file OSGHDRImageFileType.cpp.
References FWARNING, fwritecolrs(), osg::Image::OSG_FLOAT16_IMAGEDATA, and osg::Image::OSG_FLOAT32_IMAGEDATA.
00152 { 00153 if( ( image->getDataType() != Image::OSG_FLOAT32_IMAGEDATA) && 00154 ( image->getDataType() != Image::OSG_FLOAT16_IMAGEDATA)) 00155 { 00156 FWARNING(("HDRImageFileType::write: Image has non float data type!\n")); 00157 return false; 00158 } 00159 00160 if (!os.good()) 00161 return false; 00162 00163 int width = image->getWidth(); 00164 int height = image->getHeight(); 00165 00166 os << "#?RADIANCE" << std::endl; 00167 os << "# Written with OpenSG" << std::endl; 00168 os << "FORMAT=32-bit_rle_rgbe" << std::endl; 00169 os << "EXPOSURE=" << 1.0f << std::endl << std::endl; 00170 os << "-Y " << height << " +X " << width << std::endl; 00171 00172 RGBE *rgbe_scan = new RGBE[width]; 00173 00174 if( image->getDataType() == Image::OSG_FLOAT32_IMAGEDATA) 00175 { 00176 Real32 *data = ((Real32 *)(image->getData())); 00177 00178 //upside down !!! 00179 for(int y=height-1;y>=0;y--) 00180 { 00181 if (fwritecolrs(os, &data[y * width * 3], rgbe_scan, width, height) < 0) 00182 { 00183 delete [] rgbe_scan; 00184 return false; 00185 } 00186 } 00187 } 00188 else // OSG_FLOAT16_IMAGEDATA 00189 { 00190 Real16 *data = ((Real16 *)(image->getData())); 00191 //upside down !!! 00192 for(int y=height-1;y>=0;y--) 00193 { 00194 if (fwritecolrs(os, &data[y * width * 3], rgbe_scan, width, height) < 0) 00195 { 00196 delete [] rgbe_scan; 00197 return false; 00198 } 00199 } 00200 } 00201 00202 delete [] rgbe_scan; 00203 return true; 00204 }
| UInt64 HDRImageFileType::restoreData | ( | ImagePtr & | image, | |
| const UChar8 * | buffer, | |||
| Int32 | memSize = -1 | |||
| ) | [protected, virtual] |
Tries to restore the image data from the given memblock. Returns the amount of data read.
Reimplemented from osg::ImageFileType.
Definition at line 321 of file OSGHDRImageFileType.cpp.
| UInt64 HDRImageFileType::storeData | ( | const ImagePtr & | image, | |
| UChar8 * | buffer, | |||
| Int32 | memSize = -1 | |||
| ) | [protected, virtual] |
Tries to store the image data to the given memblock. Returns the amount of data written.
Reimplemented from osg::ImageFileType.
Definition at line 335 of file OSGHDRImageFileType.cpp.
00338 { 00339 UInt32 dataSize = image->getSize(); 00340 const UChar8 *src = image->getData(); 00341 00342 if ( dataSize && src && buffer ) 00343 memcpy( buffer, src, dataSize); 00344 00345 return dataSize; 00346 }
| bool HDRImageFileType::checkHDR | ( | FILE * | file, | |
| int & | width, | |||
| int & | height | |||
| ) | [private] |
Definition at line 372 of file OSGHDRImageFileType.cpp.
Referenced by read().
00373 { 00374 char cs[256], st1[80], st2[80]; 00375 bool resok = false; 00376 bool HDRok = false; 00377 while(!feof(file) && !resok) 00378 { 00379 fgets(cs, 255, file); 00380 if(strstr(cs, "32-bit_rle_rgbe")) 00381 HDRok = true; 00382 if(strcmp(cs, "\n") == 0) 00383 { 00384 // empty line found, next is resolution info, format: -Y N +X N 00385 // directly followed by data 00386 fgets(cs, 255, file); 00387 sscanf(cs, "%s %d %s %d", (char*)&st1, &height, (char*)&st2, &width); 00388 resok = true; 00389 } 00390 } 00391 return HDRok; 00392 }
| bool HDRImageFileType::checkHDR | ( | std::istream & | is, | |
| int & | width, | |||
| int & | height | |||
| ) | [private] |
Definition at line 395 of file OSGHDRImageFileType.cpp.
00396 { 00397 char cs[256], st1[80], st2[80]; 00398 bool resok = false; 00399 bool HDRok = false; 00400 int i = 0; 00401 00402 while (!is.eof() && !resok) 00403 { 00404 is.getline(cs, 255); 00405 00406 if (strstr(cs, "32-bit_rle_rgbe")) 00407 HDRok = true; 00408 00409 if (HDRok && (cs[0] == '\r' || cs[0] == '\n' || cs[0] == '\0')) 00410 { 00411 // empty line found, next is resolution info, format: -Y N +X N 00412 // directly followed by data 00413 is.getline(cs, 255); 00414 00415 i = sscanf(cs, "%s %d %s %d", st1, &height, st2, &width); 00416 if (i == 4) 00417 resok = true; 00418 } 00419 } 00420 00421 return HDRok; 00422 }
| bool HDRImageFileType::radiance2fp | ( | FILE * | file, | |
| Real32 * | data, | |||
| int | width, | |||
| int | height | |||
| ) | [private] |
Definition at line 425 of file OSGHDRImageFileType.cpp.
References freadcolrs(), and RGBE2Float().
Referenced by read().
00426 { 00427 int x,y,yx; 00428 RGBE *sline = new RGBE[width]; 00429 00430 for(y=height-1;y>=0;y--) 00431 { 00432 yx = y*width; 00433 if (!freadcolrs(file, sline, width)) 00434 return false; 00435 Real32 *fcol = &data[yx * 3]; 00436 for (x=0;x<width;x++) 00437 { 00438 RGBE2Float(sline[x], fcol); 00439 fcol += 3; 00440 } 00441 } 00442 delete[] sline; 00443 return true; 00444 }
| bool HDRImageFileType::radiance2fp | ( | std::istream & | is, | |
| Real32 * | data, | |||
| int | width, | |||
| int | height | |||
| ) | [private] |
Definition at line 447 of file OSGHDRImageFileType.cpp.
References freadcolrs(), and RGBE2Float().
00448 { 00449 int x,y,yx; 00450 RGBE *sline = new RGBE[width]; 00451 00452 if (!sline) 00453 return false; 00454 00455 for(y=height-1;y>=0;y--) 00456 { 00457 yx = y*width; 00458 if (!freadcolrs(is, sline, width)) 00459 return false; 00460 Real32 *fcol = &data[yx * 3]; 00461 for (x=0;x<width;x++) 00462 { 00463 RGBE2Float(sline[x], fcol); 00464 fcol += 3; 00465 } 00466 } 00467 delete[] sline; 00468 00469 return true; 00470 }
| bool HDRImageFileType::freadcolrs | ( | FILE * | file, | |
| RGBE * | scan, | |||
| int | width | |||
| ) | [private] |
Definition at line 473 of file OSGHDRImageFileType.cpp.
References BLU, GRN, MAXELEN, MINELEN, and oldreadcolrs().
Referenced by radiance2fp().
00474 { 00475 int i,j,code,val,size; 00476 00477 if((width < MINELEN) | (width > MAXELEN)) 00478 return oldreadcolrs(file, scan, width); 00479 00480 if((i = getc(file)) == EOF) 00481 return false; 00482 00483 if(i != 2) 00484 { 00485 ungetc(i, file); 00486 return oldreadcolrs(file, scan, width); 00487 } 00488 00489 scan[0][GRN] = (unsigned char)getc(file); 00490 scan[0][BLU] = (unsigned char)getc(file); 00491 00492 if((i = getc(file)) == EOF) 00493 return false; 00494 00495 size = ((int)scan[0][BLU]) << 8; 00496 if ( (size | i) != width ) 00497 return false; 00498 00499 for(i=0;i<4;i++) 00500 { 00501 for (j=0;j<width;) 00502 { 00503 if ((code = getc(file)) == EOF) 00504 return false; 00505 if (code > 128) 00506 { 00507 code &= 127; 00508 val = getc(file); 00509 while (code--) 00510 scan[j++][i] = (unsigned char)val; 00511 } 00512 else 00513 { 00514 while (code--) 00515 scan[j++][i] = (unsigned char)getc(file); 00516 } 00517 } 00518 } 00519 return feof(file) ? false : true; 00520 }
| bool HDRImageFileType::freadcolrs | ( | std::istream & | is, | |
| RGBE * | scan, | |||
| int | width | |||
| ) | [private] |
Definition at line 523 of file OSGHDRImageFileType.cpp.
References BLU, FWARNING, GRN, MAXELEN, and MINELEN.
00524 { 00525 int i,j,code,val,size; 00526 unsigned char byte; 00527 00528 if ((width < MINELEN) | (width > MAXELEN)) 00529 { 00530 FWARNING(("Sorry, format probably too old\n")); 00531 return false; 00532 } 00533 00534 byte = (unsigned char)is.get(); 00535 if (is.eof()) 00536 return false; 00537 00538 byte = (unsigned char)is.get(); 00539 scan[0][GRN] = byte; 00540 00541 byte = (unsigned char)is.get(); 00542 scan[0][BLU] = byte; 00543 00544 size = ((int)scan[0][BLU]) << 8; 00545 i = is.get(); 00546 00547 if ( (size | i) != width ) 00548 return false; 00549 00550 for(i=0;i<4;i++) 00551 { 00552 for (j=0;j<width;) 00553 { 00554 if (is.eof()) 00555 return false; 00556 00557 code = is.get(); 00558 00559 if (code > 128) 00560 { 00561 code &= 127; 00562 val = is.get(); 00563 00564 while (code--) 00565 scan[j++][i] = (unsigned char)val; 00566 } 00567 else 00568 { 00569 while (code--) 00570 scan[j++][i] = is.get(); 00571 } 00572 } 00573 } 00574 00575 return is.eof() ? false : true; 00576 }
| bool HDRImageFileType::oldreadcolrs | ( | FILE * | file, | |
| RGBE * | scan, | |||
| int | width | |||
| ) | [private] |
Definition at line 579 of file OSGHDRImageFileType.cpp.
References BLU, copy_rgbe, EXP, GRN, and RED.
Referenced by freadcolrs().
00580 { 00581 int i, rshift = 0, len = width; 00582 while (len > 0) 00583 { 00584 scan[0][RED] = (unsigned char)getc(file); 00585 scan[0][GRN] = (unsigned char)getc(file); 00586 scan[0][BLU] = (unsigned char)getc(file); 00587 scan[0][EXP] = (unsigned char)getc(file); 00588 if(feof(file) || ferror(file)) 00589 return false; 00590 if(scan[0][RED] == 1 && scan[0][GRN] == 1 && scan[0][BLU] == 1) 00591 { 00592 for (i=scan[0][EXP]<<rshift;i>0;i--) 00593 { 00594 copy_rgbe(scan[-1], scan[0]); 00595 scan++; 00596 len--; 00597 } 00598 rshift += 8; 00599 } 00600 else 00601 { 00602 scan++; 00603 len--; 00604 rshift = 0; 00605 } 00606 } 00607 return true; 00608 }
Definition at line 611 of file OSGHDRImageFileType.cpp.
References BLU, COLXS, EXP, GRN, and RED.
Referenced by radiance2fp().
00612 { 00613 if (rgbe[EXP] == 0) 00614 { 00615 *(fcol + RED) = *(fcol + GRN) = *(fcol + BLU) = 0; 00616 } 00617 else 00618 { 00619 Real32 f = ldexp(1., rgbe[EXP]-(COLXS+8)); 00620 *(fcol + RED) = (rgbe[RED]+.5)*f; 00621 *(fcol + GRN) = (rgbe[GRN]+.5)*f; 00622 *(fcol + BLU) = (rgbe[BLU]+.5)*f; 00623 } 00624 }
Definition at line 627 of file OSGHDRImageFileType.cpp.
References BLU, COLXS, EXP, GRN, and RED.
00628 { 00629 if (rgbe[EXP] == 0) 00630 { 00631 *(fcol + RED) = *(fcol + GRN) = *(fcol + BLU) = 0; 00632 } 00633 else 00634 { 00635 Real32 f = ldexp(1., rgbe[EXP]-(COLXS+8)); 00636 *(fcol + RED) = Real16( ( rgbe[RED]+.5) * f); 00637 *(fcol + GRN) = Real16( ( rgbe[GRN]+.5) * f); 00638 *(fcol + BLU) = Real16( ( rgbe[BLU]+.5) * f); 00639 } 00640 }
| int HDRImageFileType::fwritecolrs | ( | FILE * | file, | |
| Real32 * | scan, | |||
| RGBE * | rgbe_scan, | |||
| int | width, | |||
| int | height | |||
| ) | [private] |
Definition at line 642 of file OSGHDRImageFileType.cpp.
References float2RGBE(), and fwriteRGBE().
Referenced by write().
00644 { 00645 // convert scanline 00646 for (unsigned int i=0; i < width; ++i) 00647 { 00648 float2RGBE(scan, rgbe_scan[i]); 00649 scan += 3; 00650 } 00651 // write the RGBE Data to a file 00652 return fwriteRGBE(file, rgbe_scan, width, height); 00653 }
| int HDRImageFileType::fwritecolrs | ( | FILE * | file, | |
| Real16 * | scan, | |||
| RGBE * | rgbe_scan, | |||
| int | width, | |||
| int | height | |||
| ) | [private] |
Definition at line 655 of file OSGHDRImageFileType.cpp.
References fwriteRGBE(), and half2RGBE().
00657 { 00658 // convert scanline 00659 for (unsigned int i=0; i < width; ++i) 00660 { 00661 half2RGBE(scan, rgbe_scan[i]); 00662 scan += 3; 00663 } 00664 // write the RGBE Data to a file 00665 return fwriteRGBE(file, rgbe_scan, width, height); 00666 }
| int HDRImageFileType::fwritecolrs | ( | std::ostream & | os, | |
| Real32 * | scan, | |||
| RGBE * | rgbe_scan, | |||
| int | width, | |||
| int | height | |||
| ) | [private] |
Definition at line 725 of file OSGHDRImageFileType.cpp.
References float2RGBE(), and fwriteRGBE().
00727 { 00728 // convert scanline 00729 for (unsigned int i=0;i<width;i++) 00730 { 00731 float2RGBE(scan, rgbe_scan[i]); 00732 scan += 3; 00733 } 00734 00735 return fwriteRGBE(os, rgbe_scan, width, height); 00736 }
| int HDRImageFileType::fwritecolrs | ( | std::ostream & | os, | |
| Real16 * | scan, | |||
| RGBE * | rgbe_scan, | |||
| int | width, | |||
| int | height | |||
| ) | [private] |
Definition at line 738 of file OSGHDRImageFileType.cpp.
References fwriteRGBE(), and half2RGBE().
00740 { 00741 // convert scanline 00742 for (unsigned int i=0;i<width;i++) 00743 { 00744 half2RGBE(scan, rgbe_scan[i]); 00745 scan += 3; 00746 } 00747 00748 return fwriteRGBE(os, rgbe_scan, width, height); 00749 }
| int HDRImageFileType::fwriteRGBE | ( | FILE * | file, | |
| RGBE * | rgbe_scan, | |||
| int | width, | |||
| int | height | |||
| ) | [private] |
Definition at line 668 of file OSGHDRImageFileType.cpp.
References MAXELEN, MINELEN, and MINRUN.
Referenced by fwritecolrs().
00669 { 00670 int i, j, beg, c2, cnt=0; 00671 if ((width < MINELEN) | (width > MAXELEN)) // OOBs, write out flat 00672 return (fwrite((char *)rgbe_scan, sizeof(RGBE), width, file) - width); 00673 00674 // put magic header 00675 putc(2, file); 00676 putc(2, file); 00677 putc((unsigned char)(width>>8), file); 00678 putc((unsigned char)(width&255), file); 00679 00680 // put components seperately 00681 for (i=0;i<4;i++) 00682 { 00683 for (j=0;j<width;j+=cnt) 00684 { // find next run 00685 for (beg=j;beg<width;beg+=cnt) 00686 { 00687 for(cnt=1;(cnt<127) && ((beg+cnt)<width) && (rgbe_scan[beg+cnt][i] == rgbe_scan[beg][i]); cnt++); 00688 if (cnt>=MINRUN) 00689 break; // long enough 00690 } 00691 if (((beg-j)>1) && ((beg-j) < MINRUN)) 00692 { 00693 c2 = j+1; 00694 while (rgbe_scan[c2++][i] == rgbe_scan[j][i]) 00695 if (c2 == beg) 00696 { // short run 00697 putc((unsigned char)(128+beg-j), file); 00698 putc((unsigned char)(rgbe_scan[j][i]), file); 00699 j = beg; 00700 break; 00701 } 00702 } 00703 while (j < beg) 00704 { // write out non-run 00705 if ((c2 = beg-j) > 128) 00706 c2 = 128; 00707 putc((unsigned char)(c2), file); 00708 while (c2--) 00709 putc(rgbe_scan[j++][i], file); 00710 } 00711 if (cnt >= MINRUN) 00712 { // write out run 00713 putc((unsigned char)(128+cnt), file); 00714 putc(rgbe_scan[beg][i], file); 00715 } 00716 else 00717 { 00718 cnt = 0; 00719 } 00720 } 00721 } 00722 return(ferror(file) ? -1 : 0); 00723 }
| int HDRImageFileType::fwriteRGBE | ( | std::ostream & | os, | |
| RGBE * | rgbe_scan, | |||
| int | width, | |||
| int | height | |||
| ) | [private] |
Definition at line 752 of file OSGHDRImageFileType.cpp.
References MAXELEN, MINELEN, and MINRUN.
00754 { 00755 int i, j, beg, c2, cnt=0; 00756 00757 if ((width < MINELEN) | (width > MAXELEN)) 00758 { 00759 // OOBs, write out flat 00760 os.write((char *)rgbe_scan, width); 00761 return 0; 00762 } 00763 00764 // put magic header 00765 os << (unsigned char)2; 00766 os << (unsigned char)2; 00767 os << (unsigned char)(width>>8); 00768 os << (unsigned char)(width&255); 00769 00770 // put components seperately 00771 for (i=0;i<4;i++) 00772 { 00773 for (j=0;j<width;j+=cnt) 00774 { 00775 // find next run 00776 for (beg=j;beg<width;beg+=cnt) 00777 { 00778 for(cnt=1; (cnt<127)&&((beg+cnt)<width)&&(rgbe_scan[beg+cnt][i]==rgbe_scan[beg][i]); cnt++) 00779 ; 00780 if (cnt>=MINRUN) 00781 break; 00782 // long enough 00783 } 00784 if (((beg-j)>1) && ((beg-j) < MINRUN)) 00785 { 00786 c2 = j+1; 00787 while (rgbe_scan[c2++][i] == rgbe_scan[j][i]) 00788 { 00789 if (c2 == beg) 00790 { 00791 // short run 00792 os << (unsigned char)(128+beg-j); 00793 os << (unsigned char)(rgbe_scan[j][i]); 00794 j = beg; 00795 break; 00796 } 00797 } 00798 } 00799 while (j < beg) 00800 { 00801 // write out non-run 00802 if ((c2 = beg-j) > 128) 00803 c2 = 128; 00804 os << (unsigned char)(c2); 00805 00806 while (c2--) 00807 os << rgbe_scan[j++][i]; 00808 } 00809 if (cnt >= MINRUN) 00810 { 00811 // write out run 00812 os << (unsigned char)(128+cnt); 00813 os << rgbe_scan[beg][i]; 00814 } 00815 else 00816 { 00817 cnt = 0; 00818 } 00819 } 00820 } 00821 return (os.fail() ? -1 : 0); 00822 }
Definition at line 847 of file OSGHDRImageFileType.cpp.
References BLU, COLXS, EXP, GRN, and RED.
Referenced by fwritecolrs().
00848 { 00849 Real32 d = (*(fcol + RED) > *(fcol + GRN)) ? *(fcol + RED) : *(fcol + GRN); 00850 00851 if(*(fcol + BLU) > d) 00852 d = *(fcol + BLU); 00853 if(d <= 1e-32f) 00854 { 00855 rgbe[RED] = rgbe[GRN] = rgbe[BLU] = rgbe[EXP] = 0; 00856 } 00857 else 00858 { 00859 int e; 00860 d = frexp(d, &e) * 256.f / d; 00861 rgbe[RED] = (unsigned char)(*(fcol + RED) * d); 00862 rgbe[GRN] = (unsigned char)(*(fcol + GRN) * d); 00863 rgbe[BLU] = (unsigned char)(*(fcol + BLU) * d); 00864 rgbe[EXP] = (unsigned char)(e + COLXS); 00865 } 00866 }
Definition at line 825 of file OSGHDRImageFileType.cpp.
References BLU, COLXS, EXP, GRN, and RED.
Referenced by fwritecolrs().
00826 { 00827 Real32 d = (*(fcol + RED) > *(fcol + GRN)) ? *(fcol + RED) : *(fcol + GRN); 00828 00829 if(*(fcol + BLU) > d) 00830 d = *(fcol + BLU); 00831 if(d <= 1e-32f) 00832 { 00833 rgbe[RED] = rgbe[GRN] = rgbe[BLU] = rgbe[EXP] = 0; 00834 } 00835 else 00836 { 00837 int e; 00838 d = frexp(d, &e) * 256.f / d; 00839 rgbe[RED] = (unsigned char)(*(fcol + RED) * d); 00840 rgbe[GRN] = (unsigned char)(*(fcol + GRN) * d); 00841 rgbe[BLU] = (unsigned char)(*(fcol + BLU) * d); 00842 rgbe[EXP] = (unsigned char)(e + COLXS); 00843 } 00844 }
| void ImageFileType::setOptions | ( | const Char8 * | options | ) | [inherited] |
Definition at line 243 of file OSGImageFileType.cpp.
References osg::ImageFileType::_options.
Referenced by osg::ImageFileHandler::setOptions().
00244 { 00245 _options = options; 00246 }
| const Char8 * ImageFileType::getMimeType | ( | void | ) | const [inherited] |
Get method for the mime type
Definition at line 107 of file OSGImageFileType.cpp.
References osg::ImageFileType::_mimeType, and osg::IDString::str().
Referenced by osg::ImageFileHandler::addImageFileType(), osg::TIFImageFileType::determineMimetypeFromStream(), osg::SGIImageFileType::determineMimetypeFromStream(), osg::PSDImageFileType::determineMimetypeFromStream(), osg::PNMImageFileType::determineMimetypeFromStream(), osg::PNGImageFileType::determineMimetypeFromStream(), osg::MNGImageFileType::determineMimetypeFromStream(), osg::JPGImageFileType::determineMimetypeFromStream(), osg::JP2ImageFileType::determineMimetypeFromStream(), osg::GIFImageFileType::determineMimetypeFromStream(), osg::DDSImageFileType::determineMimetypeFromStream(), osg::BMPImageFileType::determineMimetypeFromStream(), osg::ImageFileType::dump(), osg::TIFImageFileType::read(), osg::PNGImageFileType::read(), osg::JPGImageFileType::read(), osg::JP2ImageFileType::read(), osg::ImageFileType::read(), osg::ImageFileHandler::read(), osg::EXRImageFileType::read(), osg::PNGImageFileType::restoreData(), osg::JPGImageFileType::restoreData(), osg::ImageFileType::restoreData(), osg::ImageFileHandler::store(), osg::PNGImageFileType::storeData(), osg::JPGImageFileType::storeData(), osg::ImageFileType::storeData(), osg::TIFImageFileType::write(), osg::PNGImageFileType::write(), osg::JPGImageFileType::write(), osg::ImageFileType::write(), osg::ImageFileHandler::write(), and osg::EXRImageFileType::write().
| const std::list< IDString > & ImageFileType::getSuffixList | ( | void | ) | const [inherited] |
Get method for the suffix list container
Definition at line 134 of file OSGImageFileType.cpp.
References osg::ImageFileType::_suffixList.
Referenced by osg::ImageFileHandler::addImageFileType().
00135 { 00136 return _suffixList; 00137 }
| UInt32 ImageFileType::getFlags | ( | void | ) | const [virtual, inherited] |
Get method for the flags indicating read/write support. Most image types only support reading.
Definition at line 117 of file OSGImageFileType.cpp.
References osg::ImageFileType::_flags.
Referenced by osg::ImageFileHandler::getSuffixList().
00118 { 00119 return _flags; 00120 }
| const Char8 * ImageFileType::getOptions | ( | void | ) | [inherited] |
Get method for the mime type
Definition at line 124 of file OSGImageFileType.cpp.
References osg::ImageFileType::_options.
Referenced by osg::ImageFileHandler::getOptions().
00125 { 00126 return _options.c_str(); 00127 }
| bool ImageFileType::validateHeader | ( | const Char8 * | fileName, | |
| bool & | implemented | |||
| ) | [virtual, inherited] |
Reimplemented in osg::GIFImageFileType, osg::JPGImageFileType, osg::PNGImageFileType, osg::SGIImageFileType, and osg::TIFImageFileType.
Definition at line 161 of file OSGImageFileType.cpp.
Referenced by osg::ImageFileHandler::getFileType().
| std::string ImageFileType::determineMimetypeFromStream | ( | std::istream & | is | ) | [virtual, inherited] |
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 in osg::BMPImageFileType, osg::DDSImageFileType, osg::GIFImageFileType, osg::JP2ImageFileType, osg::JPGImageFileType, osg::MNGImageFileType, osg::PNGImageFileType, osg::PNMImageFileType, osg::PSDImageFileType, osg::SGIImageFileType, and osg::TIFImageFileType.
Definition at line 199 of file OSGImageFileType.cpp.
| UInt64 ImageFileType::restore | ( | ImagePtr & | image, | |
| const UChar8 * | buffer, | |||
| Int32 | memSize = -1 | |||
| ) | [static, inherited] |
Tries to restore the Imagedata from the given memblock. The buffer must include a ImageFileType::Head data block.
Definition at line 283 of file OSGImageFileType.cpp.
References osg::ImageFileType::Head::dataType, osg::ImageFileType::Head::depth, osg::ImageFileHandler::determineMimetypeFromSuffix(), FDEBUG, osg::ImageFileType::Head::frameCount, osg::ImageFileType::Head::frameDelay, FWARNING, osg::ImageFileType::Head::height, osg::ImageFileType::Head::mipmapCount, osg::ImageFileType::Head::netToHost(), osg::NullFC, osg::Image::OSG_UINT8_IMAGEDATA, osg::ImageFileType::Head::pixelFormat, osg::ImageFileType::Head::sideCount, osg::ImageFileType::Head::suffix, osg::ImageFileHandler::the(), and osg::ImageFileType::Head::width.
Referenced by osg::ClusterViewBuffer::recv(), osg::ImageFileHandler::restore(), and osg::SimpleSceneManager::useOpenSGLogo().
00285 { 00286 unsigned long imageSize, headSize = sizeof(Head); 00287 unsigned long size = 0, attachmentSize; 00288 Head head; 00289 const UChar8 *data = buffer ? (buffer + headSize) : 0; 00290 ImageFileType *type; 00291 std::string mimeType; 00292 Image::Type dataType; 00293 00294 if ((image != osg::NullFC) && buffer && (memSize >= headSize)) { 00295 00296 // Copy header. Otherwise netToHost would change the original 00297 // data structur. 00298 memcpy(&head,buffer,sizeof(Head)); 00299 head.netToHost(); 00300 mimeType = ImageFileHandler::the().determineMimetypeFromSuffix(head.suffix); 00301 00302 if((type = ImageFileHandler::the().getFileType(mimeType.c_str(), 0))) 00303 { 00304 if (head.dataType) 00305 dataType = Image::Type(head.dataType); 00306 else 00307 dataType = Image::OSG_UINT8_IMAGEDATA; 00308 00309 image->set(Image::PixelFormat(head.pixelFormat), head.width, 00310 head.height, head.depth, head.mipmapCount, 00311 head.frameCount, float(head.frameDelay) / 1000.0, 0, 00312 dataType,true,head.sideCount ); 00313 imageSize = static_cast<unsigned long>( 00314 type->restoreData(image, data, memSize - headSize)); 00315 attachmentSize = 0; // head->attachmentSize; 00316 00317 /* 00318 if ((attachmentSize = head->attachmentSize)) 00319 { 00320 attData = (char*)(buffer + headSize + imageSize); 00321 attKey = attData; 00322 attValue = 0; 00323 for (i = 0; i < (attachmentSize-1); i++) { 00324 if (attData[i] == 0) 00325 if (attKey) { 00326 attValue = &(attData[i+1]); 00327 image->setAttachmentField (attKey,attValue); 00328 attKey = attValue = 0; 00329 } 00330 else 00331 attKey = &(attData[i+1]); 00332 } 00333 if (attKey || attValue) { 00334 FFATAL (("Attachment restore error\n")); 00335 } 00336 } 00337 */ 00338 00339 size = headSize + imageSize + attachmentSize; 00340 00341 FDEBUG (( "Restore image data: %lu (%lu/%lu/%lu)\n", 00342 size, headSize, imageSize, attachmentSize )); 00343 00344 } 00345 else 00346 { 00347 imageSize = 0; 00348 FWARNING(("Can not restore image data, invalid mimeType: %s\n", 00349 mimeType.empty() == false ? mimeType.c_str() : "Unknown")); 00350 } 00351 00352 00353 } 00354 00355 return size; 00356 }
| UInt64 ImageFileType::store | ( | const ImagePtr & | image, | |
| const char * | mimeType, | |||
| UChar8 * | buffer, | |||
| Int32 | memSize = -1 | |||
| ) | [static, inherited] |
Tries to store the raster data to the given mem block. Will include a ImageFileType::Head description and the data encoded as 'mimeType'
Definition at line 364 of file OSGImageFileType.cpp.
References osg::ImageFileHandler::getFileType(), osg::ImageFileType::store(), and osg::ImageFileHandler::the().
Referenced by osg::ClusterViewBuffer::send(), osg::ImageFileType::store(), and osg::ImageFileHandler::store().
00366 { 00367 ImageFileType *type = ImageFileHandler::the().getFileType(mimeType); 00368 00369 return type ? type->store(image, buffer, memSize) : 0; 00370 }
| UInt64 ImageFileType::store | ( | const ImagePtr & | image, | |
| UChar8 * | buffer, | |||
| Int32 | memSize = -1 | |||
| ) | [inherited] |
Tries to store the raster data to the given mem block. Will include a ImageFileType::Head description for the derived concreate mimeType.
Definition at line 378 of file OSGImageFileType.cpp.
References osg::ImageFileType::_suffixList, osg::ImageFileType::Head::attachmentSize, osg::ImageFileType::Head::dataType, osg::ImageFileType::Head::depth, FDEBUG, FFATAL, osg::ImageFileType::Head::frameCount, osg::ImageFileType::Head::frameDelay, osg::ImageFileType::Head::height, osg::ImageFileType::Head::hostToNet(), osg::ImageFileType::Head::mipmapCount, osg::ImageFileType::Head::pixelFormat, osg::ImageFileType::Head::sideCount, osg::ImageFileType::storeData(), osg::ImageFileType::Head::suffix, and osg::ImageFileType::Head::width.
00380 { 00381 Head *head; 00382 unsigned long dataSize = 0, headSize = sizeof(Head); 00383 unsigned long attachmentSize; 00384 UChar8 *dest; 00385 const UChar8 *src = image->getData(); 00386 std::map<std::string, std::string>::const_iterator aI; 00387 std::string value; 00388 00389 attachmentSize = 0; 00390 00391 // get attachment size 00392 /* 00393 ImageGenericAttPtr att=ImageGenericAttPtr::dcast( 00394 const_cast<Image*>(image.getCPtr())->findAttachment( 00395 ImageGenericAtt::getClassType().getGroupId())); 00396 if(att != NullFC) 00397 { 00398 for(i = 0; i < (att->getType().getNumFieldDescs()-1); ++i) 00399 { 00400 FieldDescription *fieldDesc=att->getType().getFieldDescription(i); 00401 Field *field=att->getField(i); 00402 if (fieldDesc && field) 00403 { 00404 field->getValueByStr(value); 00405 attachmentSize += strlen( fieldDesc->getName().str() ) + 1; 00406 attachmentSize += value.length() + 1; 00407 00408 std::cout << fieldDesc->getName().str() << std::endl; 00409 std::cout << value << std::endl; 00410 } 00411 else 00412 { 00413 FFATAL (("Invalid Attachment in ImageFileType::store()\n")); 00414 } 00415 } 00416 } 00417 */ 00418 00419 if (buffer) 00420 { 00421 head = (Head *)buffer; 00422 00423 head->pixelFormat = image->getPixelFormat(); 00424 head->width = image->getWidth(); 00425 head->height = image->getHeight(); 00426 head->depth = image->getDepth(); 00427 head->mipmapCount = image->getMipMapCount(); 00428 head->frameCount = image->getFrameCount(); 00429 head->frameDelay = short(image->getFrameDelay() * 1000.0); 00430 head->sideCount = image->getSideCount(); 00431 head->dataType = image->getDataType(); 00432 head->attachmentSize = static_cast<unsigned short>(attachmentSize); 00433 head->hostToNet(); 00434 00435 strcpy(head->suffix, _suffixList.front().str()); 00436 00437 dest = (UChar8 *) (buffer + headSize); 00438 00439 if (src) 00440 dataSize = static_cast<unsigned long>( 00441 storeData(image, dest, memSize - headSize)); 00442 00443 dest = (UChar8 *) (buffer + headSize + dataSize); 00444 00445 /* 00446 if(att != NullFC) 00447 { 00448 for(i = 0; i < (att->getType().getNumFieldDescs()-1); ++i) 00449 { 00450 FieldDescription *fieldDesc=att->getType().getFieldDescription(i); 00451 Field *field=att->getField(i); 00452 if (field && fieldDesc) 00453 { 00454 field->getValueByStr(value); 00455 00456 l = strlen( fieldDesc->getName().str() ); 00457 for (i = 0; i < l; i++) 00458 *dest++ = fieldDesc->getName().str()[i]; 00459 *dest++ = 0; 00460 l = value.length(); 00461 for (i = 0; i < l; i++) 00462 *dest++ = value[i]; 00463 *dest++ = 0; 00464 } 00465 else 00466 { 00467 FFATAL (("Invalid Attachment in ImageFileType::store()\n")); 00468 } 00469 } 00470 } 00471 */ 00472 00473 FDEBUG (( "Store image data: %lu (%lu/%lu/%lu)\n", 00474 headSize + dataSize + attachmentSize, headSize, dataSize, 00475 attachmentSize )); 00476 } 00477 else { 00478 FFATAL (("Invalid buffer in ImageFileType::store()\n")); 00479 } 00480 00481 return (headSize + dataSize + attachmentSize); 00482 00483 }
Returns the max buffer size needed to store the Image (Head + mimeType specific data block)
Definition at line 490 of file OSGImageFileType.cpp.
References FINFO.
Referenced by osg::ClusterViewBuffer::send(), and osg::ImageFileHandler::store().
00491 { 00492 std::string value; 00493 unsigned long size, attachmentSize; 00494 unsigned long imageSize = image->getSize(), headSize = sizeof(Head); 00495 00496 std::map<std::string, std::string>::const_iterator aI; 00497 00498 attachmentSize = 0; 00499 00500 // get attachment size 00501 /* 00502 ImageGenericAttPtr att=ImageGenericAttPtr::dcast( 00503 const_cast<Image*>(image.getCPtr())->findAttachment( 00504 ImageGenericAtt::getClassType().getGroupId())); 00505 if(att != NullFC) 00506 { 00507 for(i = 0; i < (att->getType().getNumFieldDescs()-1); ++i) 00508 { 00509 FieldDescription *fieldDesc=att->getType().getFieldDescription(i); 00510 Field *field=att->getField(i); 00511 if (field && fieldDesc) 00512 { 00513 field->getValueByStr(value); 00514 attachmentSize += strlen( fieldDesc->getName().str() ) + 1; 00515 attachmentSize += value.length() + 1; 00516 } 00517 else 00518 { 00519 FFATAL (("Invalid Attachment in ImageFileType::maxBufferSize()\n")); 00520 } 00521 } 00522 } 00523 */ 00524 00525 size = headSize + imageSize + attachmentSize; 00526 00527 FINFO (( "ImageFileType::maxBufferSize(): %lu (%lu/%lu/%lu)\n", 00528 size, headSize, imageSize, attachmentSize )); 00529 00530 return size; 00531 }
| void ImageFileType::dump | ( | void | ) | [inherited] |
The dump method just writes some object debugging info to the LOG stream
Definition at line 537 of file OSGImageFileType.cpp.
References osg::ImageFileType::_suffixList, osg::ImageFileType::getMimeType(), osg::LOG_DEBUG, and SLOG.
00538 { 00539 std::list<IDString>::iterator sI; 00540 00541 SLOG << getMimeType(); 00542 00543 if(_suffixList.empty()) 00544 { 00545 SLOG << ": Suffix: "; 00546 for(sI = _suffixList.begin(); sI != _suffixList.end(); sI++) 00547 { 00548 Log().stream(OSG::LOG_DEBUG) << sI->str() << " "; 00549 } 00550 } 00551 00552 std::cerr << std::endl; 00553 }
HDRImageFileType HDRImageFileType::_the [static, private] |
std::string osg::ImageFileType::_options [protected, inherited] |
Definition at line 182 of file OSGImageFileType.h.
Referenced by osg::ImageFileType::getOptions(), osg::ImageFileType::setOptions(), and osg::TIFImageFileType::write().
1.5.5