- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgPlugins/imageio/ReaderWriterImageIO_IOS.cpp
r12683 r13041 99 99 source_ref = CGImageSourceCreateWithData(the_cf_data, NULL); 100 100 */ 101 101 102 102 CGDataProviderSequentialCallbacks provider_callbacks = 103 103 { … … 108 108 MyProviderReleaseInfoCallback 109 109 }; 110 110 111 111 CGDataProviderRef data_provider = CGDataProviderCreateSequential(&fin, &provider_callbacks); 112 112 113 113 // If we had a way of hinting at what the data type is, we could 114 114 // pass this hint in the second parameter. 115 115 source_ref = CGImageSourceCreateWithDataProvider(data_provider, NULL); 116 116 117 117 CGDataProviderRelease(data_provider); 118 119 118 119 120 120 if(!source_ref) 121 121 { 122 122 return NULL; 123 123 } 124 124 125 125 image_ref = CGImageSourceCreateImageAtIndex(source_ref, 0, NULL); 126 126 127 127 /* Don't need the SourceRef any more (error or not) */ 128 128 CFRelease(source_ref); 129 129 130 130 return image_ref; 131 131 } … … 134 134 { 135 135 NSString* nstr = nil; 136 136 137 137 if (!text.empty()) 138 138 { … … 140 140 //nstr = [NSString stringWithUTF8String:text.c_str()];// encoding:nsse] 141 141 } 142 142 143 143 if (nstr == nil) 144 144 { 145 145 nstr = @""; 146 146 } 147 147 148 148 return nstr; 149 149 } … … 167 167 //std::string strName = osgDB::getStrippedName(file); 168 168 //std::string strFile = strPath + "/" + strName; 169 170 //NSString* path = [NSString stringWithCString:strName.c_str() encoding:NSUTF8StringEncoding]; 171 //NSString* ext = [NSString stringWithCString:strExt.c_str() encoding:NSUTF8StringEncoding]; 172 169 170 //NSString* path = [NSString stringWithCString:strName.c_str() encoding:NSUTF8StringEncoding]; 171 //NSString* ext = [NSString stringWithCString:strExt.c_str() encoding:NSUTF8StringEncoding]; 172 173 173 //CGImageRef textureImage = [UIImage imageNamed:path].CGImage; 174 174 //CGImageRef textureImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:path ofType:ext]].CGImage; … … 187 187 return NULL; 188 188 } 189 190 size_t texWidth = CGImageGetWidth(textureImage); 189 190 size_t texWidth = CGImageGetWidth(textureImage); 191 191 size_t texHeight = CGImageGetHeight(textureImage); 192 192 GLubyte *textureData = (GLubyte *)malloc(texWidth * texHeight * 4); … … 205 205 } 206 206 207 CGContextRef textureContext = CGBitmapContextCreate(textureData, 207 CGContextRef textureContext = CGBitmapContextCreate(textureData, 208 208 texWidth, texHeight, 209 209 8, texWidth * 4, … … 217 217 return NULL; 218 218 } 219 219 220 220 //copy into texturedata 221 221 CGContextDrawImage(textureContext, … … 223 223 textureImage); 224 224 CGContextRelease(textureContext); 225 225 226 226 //create the osg image 227 227 int s = texWidth; … … 234 234 textureData, 235 235 osg::Image::USE_MALLOC_FREE); 236 236 237 237 //flip vertical 238 238 image->flipVertical(); 239 240 // 239 240 // 241 241 // Reverse the premultiplied alpha for avoiding unexpected darker edges 242 242 // by Tatsuhiro Nishioka (based on SDL's workaround on the similar issue) 243 243 // http://bugzilla.libsdl.org/show_bug.cgi?id=868 244 // 244 // 245 245 int i, j; 246 246 GLubyte *pixels = (GLubyte *)image->data(); 247 247 for (i = image->t() * image->s(); i--; ) { 248 248 249 249 GLubyte alpha = pixels[3]; 250 250 if (alpha && (alpha < 255)) { … … 269 269 } 270 270 271 size_t texWidth = CGImageGetWidth(textureImage); 271 size_t texWidth = CGImageGetWidth(textureImage); 272 272 size_t texHeight = CGImageGetHeight(textureImage); 273 273 … … 278 278 return NULL; 279 279 } 280 280 281 281 CGColorSpaceRef csref = CGColorSpaceCreateDeviceRGB(); 282 282 if (!csref) { … … 287 287 } 288 288 289 CGContextRef textureContext = CGBitmapContextCreate(textureData, 289 CGContextRef textureContext = CGBitmapContextCreate(textureData, 290 290 texWidth, texHeight, 291 291 8, texWidth * 4, … … 299 299 return NULL; 300 300 } 301 301 302 302 //copy into texturedata 303 303 CGContextDrawImage(textureContext, 304 304 CGRectMake(0.0f, 0.0f, (float)texWidth, (float)texHeight), 305 305 textureImage); 306 CGContextFlush(textureContext); 306 CGContextFlush(textureContext); 307 307 CGContextRelease(textureContext); 308 309 308 309 310 310 //create the osg image 311 311 int s = texWidth; … … 318 318 textureData, 319 319 osg::Image::USE_MALLOC_FREE); 320 320 321 321 //flip vertical 322 322 image->flipVertical(); 323 324 // 323 324 // 325 325 // Reverse the premultiplied alpha for avoiding unexpected darker edges 326 326 // by Tatsuhiro Nishioka (based on SDL's workaround on the similar issue) 327 327 // http://bugzilla.libsdl.org/show_bug.cgi?id=868 328 // 329 330 328 // 329 330 331 331 int i, j; 332 332 GLubyte *pixels = (GLubyte *)image->data(); 333 333 for (i = image->t() * image->s(); i--; ) { 334 334 335 335 GLubyte alpha = pixels[3]; 336 336 if (alpha && (alpha < 255)) { … … 352 352 ReaderWriterImageIO() 353 353 { 354 355 supportsExtension("jpg", "jpg image file"); 354 355 supportsExtension("jpg", "jpg image file"); 356 356 supportsExtension("jpeg", "jpeg image file"); 357 357 supportsExtension("jpe", "jpe image file"); 358 358 supportsExtension("jp2", "jp2 image file"); 359 supportsExtension("tiff", "tiff image file"); 360 supportsExtension("tif", "tif image file"); 359 supportsExtension("tiff", "tiff image file"); 360 supportsExtension("tif", "tif image file"); 361 361 supportsExtension("gif", "gif image file"); 362 362 supportsExtension("png", "png image file"); … … 371 371 supportsExtension("targa", "targa image file"); 372 372 supportsExtension("psd", "psd image file"); 373 373 374 374 supportsExtension("pdf", "pdf image file"); 375 375 supportsExtension("eps", "eps image file"); … … 378 378 supportsExtension("epsi", "epsi image file"); 379 379 supportsExtension("ps", "postscript image file"); 380 380 381 381 supportsExtension("dng", "dng image file"); 382 382 supportsExtension("cr2", "cr2 image file"); … … 400 400 supportsExtension("cur", "cur image file"); 401 401 supportsExtension("xbm", "xbm image file"); 402 402 403 403 supportsExtension("raw", "raw image file"); 404 404 } 405 405 406 406 virtual const char* className() const { return "Mac OS X ImageIO based Image Reader/Writer"; } 407 408 407 408 409 409 virtual bool acceptsExtension(const std::string& extension) const 410 410 { … … 419 419 // http://developer.apple.com/documentation/Carbon/Conceptual/understanding_utis/utilist/chapter_4_section_1.html 420 420 return 421 osgDB::equalCaseInsensitive(extension,"jpg") || 421 osgDB::equalCaseInsensitive(extension,"jpg") || 422 422 osgDB::equalCaseInsensitive(extension,"jpeg") || 423 423 osgDB::equalCaseInsensitive(extension,"jpe") || 424 424 osgDB::equalCaseInsensitive(extension,"jp2") || 425 osgDB::equalCaseInsensitive(extension,"tiff") || 426 osgDB::equalCaseInsensitive(extension,"tif") || 425 osgDB::equalCaseInsensitive(extension,"tiff") || 426 osgDB::equalCaseInsensitive(extension,"tif") || 427 427 osgDB::equalCaseInsensitive(extension,"gif") || 428 428 osgDB::equalCaseInsensitive(extension,"png") || … … 437 437 osgDB::equalCaseInsensitive(extension,"targa") || 438 438 osgDB::equalCaseInsensitive(extension,"psd") || 439 439 440 440 osgDB::equalCaseInsensitive(extension,"pdf") || 441 441 osgDB::equalCaseInsensitive(extension,"eps") || … … 444 444 osgDB::equalCaseInsensitive(extension,"epsi") || 445 445 osgDB::equalCaseInsensitive(extension,"ps") || 446 446 447 447 osgDB::equalCaseInsensitive(extension,"dng") || 448 448 osgDB::equalCaseInsensitive(extension,"cr2") || … … 466 466 osgDB::equalCaseInsensitive(extension,"cur") || 467 467 osgDB::equalCaseInsensitive(extension,"xbm") || 468 468 469 469 osgDB::equalCaseInsensitive(extension,"raw"); 470 470 } 471 472 473 471 472 473 474 474 ReadResult readImageStream(std::istream& fin) const 475 475 { … … 477 477 CGImageRef cg_image_ref = CreateCGImageFromDataStream(fin); 478 478 if (NULL == cg_image_ref) return ReadResult::FILE_NOT_FOUND; 479 479 480 480 // Create an osg::Image from the CGImageRef. 481 481 osg::Image* osg_image = CreateOSGImageFromCGImage(cg_image_ref); 482 482 483 483 CFRelease(cg_image_ref); 484 484 return osg_image; 485 485 } 486 486 487 487 virtual ReadResult readImage(std::istream& fin, const osgDB::ReaderWriter::Options* the_options = NULL) const 488 488 { … … 490 490 return read_result; 491 491 } 492 492 493 493 ReadResult readImageFile(const std::string& file_name) const 494 494 { 495 495 //osg::notify(osg::INFO) << "imageio readImageFile: " << file_name << std::endl; 496 496 497 497 // Create an osg::Image from the CGImageRef. 498 498 osg::Image* osg_image = ReadCoreGraphicsImageFromFile(file_name); … … 512 512 ReadResult read_result = readImageFile(full_file_name); 513 513 #else 514 // Only here to help test istream backend. The file version is better because 514 // Only here to help test istream backend. The file version is better because 515 515 // the filenname.extension could potentially be used by ImageIO to hint what the format type is. 516 516 std::ifstream istream(full_file_name.c_str(), std::ios::in | std::ios::binary); … … 531 531 WriteResult ret_val = WriteResult::ERROR_IN_WRITING_FILE; 532 532 533 return WriteResult::FILE_SAVED; 533 return WriteResult::FILE_SAVED; 534 534 } 535 535 … … 543 543 { 544 544 WriteResult ret_val = WriteResult::ERROR_IN_WRITING_FILE; 545 545 546 546 return WriteResult::FILE_SAVED; 547 547 } … … 558 558 return writeImageFile(osg_image, full_file_name, the_options); 559 559 #else 560 // Only here to help test ostream backend. The file version is better because 560 // Only here to help test ostream backend. The file version is better because 561 561 // the filenname.extension could potentially be used by ImageIO to hint what the format type is. 562 562 std::ofstream fout(file_name.c_str(), std::ios::out | std::ios::binary); 563 563 if(!fout) return WriteResult::ERROR_IN_WRITING_FILE; 564 564 return writeImage(osg_image, fout, the_options); 565 #endif 565 #endif 566 566 } 567 567
