CGImageRef MyCreateJPEGImageRef(){ CGImageRef image; CGDataProviderRef provider; CFStringRef name; CFURLRef url; // Get the URL to the bundle resource. url = CFURLCreateWithFileSystemPath( kCFAllocatorDefault, CFSTR("/Users/reza/.irssi/irss.jpg"), // file path name kCFURLPOSIXPathStyle, // interpret as POSIX path false ); // is it a directory? // Create the data provider object provider = CGDataProviderCreateWithURL (url); CFRelease (url); printtext(NULL, NULL, MSGLEVEL_CLIENTNOTICE,"debug1\n"); // Create the image object from that provider. image = CGImageCreateWithJPEGDataProvider (provider, NULL, true, kCGRenderingIntentDefault); if (image == NULL) printtext(NULL, NULL, MSGLEVEL_CLIENTNOTICE,"debug2\n"); CGDataProviderRelease (provider); return (image); }
void CAUGuiGraphic::loadImagePNG ( char* pngFileName ) { CFBundleRef bundleRef = CFBundleGetBundleWithIdentifier(CFSTR( AU_BUNDLE_IDENTIFIER )); CGDataProviderRef provider; if ( bundleRef ) { SInt16 tmp = CurResFile(); CFStringRef fileName = ::CFStringCreateWithCString( NULL, pngFileName, kCFStringEncodingASCII ); if ( fileName != NULL ) { CFURLRef url = ::CFBundleCopyResourceURL( bundleRef, fileName, NULL, NULL ); provider = CGDataProviderCreateWithURL( url ); Image = CGImageCreateWithPNGDataProvider( provider, NULL, false, kCGRenderingIntentDefault ); CGDataProviderRelease( provider ); CFRelease( url ); CFRelease( fileName ); } else { Image = NULL; } UseResFile(tmp); } }
static CGImageRef GetThePoofImage() { CGDataProviderRef provider; CFStringRef fileName = NULL; CGImageRef image = NULL; CFURLRef url = NULL; CFBundleRef appBundle = CFBundleGetMainBundle(); if ( appBundle == NULL ) goto Bail; fileName = CFStringCreateWithCString( NULL, "ToolbarPoof.png", kCFStringEncodingASCII ); // ToolbarPoof.png is in our Resources directory within the bundle if ( fileName == NULL ) goto Bail; url = CFBundleCopyResourceURL( appBundle, fileName, NULL, NULL ); if ( url == NULL ) goto Bail; provider = CGDataProviderCreateWithURL( url ); image = CGImageCreateWithPNGDataProvider( provider, NULL, false, kCGRenderingIntentDefault ); CGDataProviderRelease( provider ); Bail: if ( fileName != NULL ) CFRelease( fileName ); if ( url != NULL ) CFRelease( url ); return( image ); }
// add an HIImageViewRef to the parentView HIViewRef AddImage( HIViewRef parentView ) { OSStatus status = paramErr; HIViewRef cgImageView = NULL; CGImageRef cgImage = NULL; CGDataProviderRef cgImageProvider = NULL; HILayoutInfo layoutInfo; CFBundleRef theAppBundle = NULL; CFStringRef imageFileName = NULL; CFURLRef imageURL = NULL; HIRect parentFrame; theAppBundle = CFBundleGetMainBundle(); imageFileName = CFStringCreateWithCString( NULL /*allocator*/, "rainbowpark.jpg", kCFStringEncodingASCII ); imageURL = CFBundleCopyResourceURL( theAppBundle, imageFileName, NULL, NULL ); cgImageProvider = CGDataProviderCreateWithURL(imageURL); require( cgImageProvider != NULL, FAIL ); cgImage = CGImageCreateWithJPEGDataProvider( cgImageProvider, NULL, false, kCGRenderingIntentDefault ); require( cgImage != NULL, FAIL ); CGDataProviderRelease( cgImageProvider ); CFRelease( imageFileName ); HIImageViewCreate( cgImage, &cgImageView ); CGImageRelease( cgImage); require( cgImageView != NULL, FAIL ); layoutInfo.binding.left.kind = kHILayoutBindLeft; layoutInfo.binding.left.toView = NULL; layoutInfo.binding.left.offset = 0.0; layoutInfo.binding.top.kind = kHILayoutBindTop; layoutInfo.binding.top.toView = NULL; layoutInfo.binding.top.offset = 0.0; layoutInfo.binding.right.kind = kHILayoutBindRight; layoutInfo.binding.right.toView = NULL; layoutInfo.binding.right.offset = 0.0; layoutInfo.binding.bottom.kind = kHILayoutBindBottom; layoutInfo.binding.bottom.toView = NULL; layoutInfo.binding.bottom.offset = 0.0; verify_noerr( HIViewSetLayoutInfo(cgImageView, &layoutInfo) ); verify_noerr( HIImageViewSetScaleToFit(cgImageView, true) ); status = HIViewAddSubview(parentView, cgImageView); if( status != noErr ) { CFRelease( cgImageView ); cgImageView = NULL; } FAIL: return cgImageView; }
SFFontRef SFFontCreateWithFileName(CFStringRef name, CFStringRef extension, CGFloat size) { CFBundleRef mainBundle = CFBundleGetMainBundle(); CFURLRef url = CFBundleCopyResourceURL(mainBundle, name, (CFStringRef)extension, NULL); CGDataProviderRef dataProvider = CGDataProviderCreateWithURL(url); CGFontRef fnt = CGFontCreateWithDataProvider(dataProvider); SFFontRef sfFont = SFFontCreate(fnt, size); CGFontRelease(fnt); CGDataProviderRelease(dataProvider); CFRelease(url); return sfFont; }
OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options) { CGDataProviderRef dataProvider = CGDataProviderCreateWithURL(url); if (!dataProvider) return -1; CFDataRef data = CGDataProviderCopyData(dataProvider); CGDataProviderRelease(dataProvider); if (!data) return -1; int width, height, channels; unsigned char* rgbadata = SOIL_load_image_from_memory(CFDataGetBytePtr(data), CFDataGetLength(data), &width, &height, &channels, SOIL_LOAD_RGBA); CFStringRef format=CFStringCreateWithBytes(NULL, CFDataGetBytePtr(data) + 0x54, 4, kCFStringEncodingASCII, false); CFRelease(data); if (!rgbadata) return -1; CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB(); CGContextRef context = CGBitmapContextCreate(rgbadata, width, height, 8, width * 4, rgb, kCGImageAlphaPremultipliedLast); SOIL_free_image_data(rgbadata); CGColorSpaceRelease(rgb); if (!context) return -1; CGImageRef image = CGBitmapContextCreateImage(context); CGContextRelease(context); if (!image) return -1; /* Add basic metadata to title */ CFStringRef name = CFURLCopyLastPathComponent(url); CFTypeRef keys[1] = {kQLPreviewPropertyDisplayNameKey}; CFTypeRef values[1] = {CFStringCreateWithFormat(NULL, NULL, CFSTR("%@ (%dx%d %@)"), name, width, height, format)}; CFDictionaryRef properties = CFDictionaryCreate(NULL, (const void**)keys, (const void**)values, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); CFRelease(name); context = QLPreviewRequestCreateContext(preview, CGSizeMake(width, height), true, properties); CGContextDrawImage(context, CGRectMake(0, 0, width, height), image); QLPreviewRequestFlushContext(preview, context); CGContextRelease(context); CFRelease(format); CFRelease(properties); return noErr; }
Boolean GetMetadataForURL(void* thisInterface, CFMutableDictionaryRef attributes, CFStringRef contentTypeUTI, CFURLRef url) { CGDataProviderRef dataProvider = CGDataProviderCreateWithURL(url); if (!dataProvider) return FALSE; CFDataRef data = CGDataProviderCopyData(dataProvider); CGDataProviderRelease(dataProvider); if (!data) return FALSE; const UInt8 *buf = CFDataGetBytePtr(data); int *height= ((int*) buf) + 3; int *width = ((int*) buf) + 4; int *pflags= ((int*) buf) + 20; CFStringRef format=NULL; if ((*pflags)&DDPF_FOURCC) format = CFStringCreateWithBytes(kCFAllocatorDefault, buf + 0x54, 4, kCFStringEncodingASCII, false); else if ((*pflags)&DDPF_RGB) format = (*pflags)&DDPF_ALPHAPIXELS ? CFSTR("RGBA") : CFSTR("RGB"); if (format) { CFArrayRef codecs = CFArrayCreate(kCFAllocatorDefault, (const void **) &format, 1, &kCFTypeArrayCallBacks); CFDictionaryAddValue(attributes, kMDItemCodecs, codecs); CFRelease(format); CFRelease(codecs); } CFNumberRef cfheight = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, height); CFDictionaryAddValue(attributes, kMDItemPixelHeight, cfheight); CFRelease(cfheight); CFNumberRef cfwidth = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, width); CFDictionaryAddValue(attributes, kMDItemPixelWidth, cfwidth); CFRelease(cfwidth); CFRelease(data); return TRUE; }
void MusicBoxDialog(void) { OSStatus err; IBNibRef nibRef; if (!cartOpen) return; err = CreateNibReference(kMacS9XCFString, &nibRef); if (err == noErr) { CFURLRef iconURL; FSRef iconFSRef; IconRef actIcon; WindowRef tWindowRef; actIcon = nil; if (musicboxmode == kMBXSoundEmulation) iconURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("musicbox_ledoff"), CFSTR("icns"), nil); else iconURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("musicbox_ledon" ), CFSTR("icns"), nil); if (iconURL) { if (CFURLGetFSRef(iconURL, &iconFSRef)) err = RegisterIconRefFromFSRef('~9X~', 'micn', &iconFSRef, &actIcon); CFRelease(iconURL); } err = CreateWindowFromNib(nibRef, CFSTR("MusicBox"), &tWindowRef); if (err == noErr) { EventHandlerRef mboxRef, paneRef; EventHandlerUPP mboxUPP, paneUPP; EventLoopTimerRef timeRef; EventLoopTimerUPP timeUPP; EventTypeSpec mboxEvents[] = { { kEventClassCommand, kEventCommandProcess }, { kEventClassCommand, kEventCommandUpdateStatus } }, paneEvents[] = { { kEventClassControl, kEventControlDraw } }; CFStringRef sref; CGDataProviderRef prov; CGImageRef ipng; CFURLRef iurl; HIViewRef ctl, root, paneView, imageView, contentView; HIViewID cid; HIRect bounds; Rect windowRect, barRect; char drive[_MAX_DRIVE], dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT]; mboxPause = false; mbxFinished = false; showIndicator = false; so.stereo_switch = ~0; for (int i = 0; i < MAC_MAX_PLAYERS; i++) controlPad[i] = 0; switch (drawingMethod) { case kDrawingOpenGL: Settings.OpenGLEnable = true; break; case kDrawingDirect: case kDrawingBlitGL: Settings.OpenGLEnable = false; } // 107's enhanced SPC player root = HIViewGetRoot(tWindowRef); cid.id = 0; if (musicboxmode == kMBXSoundEmulation) { cid.signature = 'HEAD'; HIViewFindByID(root, cid, &ctl); EnableControl(ctl); StoredAPU = new SAPU; StoredAPURegisters = new SAPURegisters; StoredSoundData = new SSoundData; StoredIAPURAM = new uint8 [0x10000]; SPCPlayFreeze(); } else MusicBoxForceFreeze(); cid.signature = 'Kart'; HIViewFindByID(root, cid, &ctl); SetStaticTextTrunc(ctl, truncEnd, false); _splitpath(Memory.ROMFilename, drive, dir, fname, ext); sref = CFStringCreateWithCString(kCFAllocatorDefault, fname, MAC_PATH_ENCODING); if (sref) { SetStaticTextCFString(ctl, sref, false); CFRelease(sref); } ipng = nil; iurl = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("musicbox_indicator"), CFSTR("png"), nil); if (iurl) { prov = CGDataProviderCreateWithURL(iurl); if (prov) { ipng = CGImageCreateWithPNGDataProvider(prov, nil, false, kCGRenderingIntentDefault); CGDataProviderRelease(prov); } CFRelease(iurl); } imageView = nil; if (ipng) { HIViewFindByID(root, kHIViewWindowContentID, &contentView); err = HIImageViewCreate(ipng, &imageView); if (err == noErr) { bounds = CGRectMake(30, 64, CGImageGetWidth(ipng), CGImageGetHeight(ipng)); HIViewSetFrame(imageView, &bounds); HIImageViewSetOpaque(imageView, false); HIViewSetVisible(imageView, true); HIViewAddSubview(contentView, imageView); cid.signature = 'iMaG'; SetControlID(imageView, &cid); } CGImageRelease(ipng); } cid.signature = 'Pane'; HIViewFindByID(root, cid, &paneView); HIViewGetBounds(paneView, &bounds); mbxViewWidth = bounds.size.width; mbxViewHeight = bounds.size.height; mbxMarginY = (mbxViewHeight - mbxBarHeight) / 2.0; mbxMarginX = (mbxViewWidth - ((mbxBarWidth * 8.0 + mbxBarSpace * 7.0) * 2.0 + mbxLRSpace)) / 2.0; if (imageView) { HIViewSetZOrder(imageView, kHIViewZOrderBelow, paneView); HIViewAddSubview(imageView, paneView); } cid.signature = 'Tr_i'; HIViewFindByID(root, cid, &ctl); HIViewGetFrame(ctl, &bounds); GetWindowBounds(tWindowRef, kWindowTitleBarRgn, &barRect); mbxClosedHeight = (short) (bounds.origin.y + bounds.size.height + 7.0) + (barRect.bottom - barRect.top); GetWindowBounds(tWindowRef, kWindowStructureRgn, &windowRect); mbxOpenedHeight = windowRect.bottom - windowRect.top; windowRect.bottom = windowRect.top + mbxClosedHeight; SetWindowBounds(tWindowRef, kWindowStructureRgn, &windowRect); paneUPP = NewEventHandlerUPP(IndicatorEventHandler); err = InstallControlEventHandler(paneView, paneUPP, GetEventTypeCount(paneEvents), paneEvents, (void *) paneView, &paneRef); mboxUPP = NewEventHandlerUPP(MusicBoxEventHandler); err = InstallWindowEventHandler(tWindowRef, mboxUPP, GetEventTypeCount(mboxEvents), mboxEvents, (void *) tWindowRef, &mboxRef); timeUPP = NewEventLoopTimerUPP(MusicBoxTimerHandler); err = InstallEventLoopTimer(GetCurrentEventLoop(), kEventDurationNoWait, kEventDurationSecond * 2.0 / (double) Memory.ROMFramesPerSecond, timeUPP, (void *) paneView, &timeRef); MusicBoxInitIndicator(); stopNow = false; MacStartSound(); pthread_create(&mbxThread, nil, SoundTask, nil); MoveWindowPosition(tWindowRef, kWindowMusicBox, true); GetWindowBounds(tWindowRef, kWindowStructureRgn, &windowRect); if (windowRect.bottom - windowRect.top > mbxClosedHeight) { showIndicator = true; SetControl32BitValue(ctl, 1); // Tr_i } ShowWindow(tWindowRef); err = RunAppModalLoopForWindow(tWindowRef); HideWindow(tWindowRef); SaveWindowPosition(tWindowRef, kWindowMusicBox); stopNow = true; pthread_join(mbxThread, nil); MacStopSound(); err = RemoveEventLoopTimer(timeRef); DisposeEventLoopTimerUPP(timeUPP); err = RemoveEventHandler(mboxRef); DisposeEventHandlerUPP(mboxUPP); err = RemoveEventHandler(paneRef); DisposeEventHandlerUPP(paneUPP); ReleaseWindow(tWindowRef); so.stereo_switch = ~0; mbxFinished = true; if (musicboxmode == kMBXSoundEmulation) { SPCPlayDefrost(); delete StoredAPU; delete StoredAPURegisters; delete StoredSoundData; delete [] StoredIAPURAM; } else MusicBoxForceDefrost(); Settings.OpenGLEnable = false; } if (actIcon) err = UnregisterIconRef('~9X~', 'micn'); DisposeNibReference(nibRef); } }
void CreateIconImages (void) { CGDataProviderRef prov; CGImageRef image; CFURLRef url; image = NULL; memset(macIconImage, 0, sizeof(macIconImage)); #ifdef MAC_PANTHER_SUPPORT if (systemVersion < 0x1040) memset(macIconRef, 0, sizeof(macIconRef)); #endif url = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("icons"), CFSTR("png"), NULL); if (url) { prov = CGDataProviderCreateWithURL(url); if (prov) { image = CGImageCreateWithPNGDataProvider(prov, NULL, true, kCGRenderingIntentDefault); CGDataProviderRelease(prov); } CFRelease(url); } if (image) { int x, y, v = 0, n = 0; macPadIconIndex = n; for (y = 0; y < 8; y++) { for (x = 0; x < 12; x++) SetIconImage(image, CGRectMake(x * kIconSize, v, kIconSize, kIconSize), n++); v += kIconSize; } macLegendIconIndex = n; for (x = 0; x < 2; x++) SetIconImage(image, CGRectMake(x * kIconSize, v, kIconSize, kIconSize), n++); v += kIconSize; macMusicBoxIconIndex = n; for (x = 0; x < 3; x++) SetIconImage(image, CGRectMake(x * kIconSize, v, kIconSize, kIconSize), n++); v += kIconSize; macFunctionIconIndex = n; for (x = 0; x < 17; x++) SetIconImage(image, CGRectMake(x * kIconSize, v, kIconSize, kIconSize), n++); CGImageRelease(image); #ifdef MAC_PANTHER_SUPPORT if (systemVersion < 0x1040) { CGColorSpaceRef color; CGContextRef ctx; CGRect rct; static UInt32 data[2][kIconSize * kIconSize]; rct = CGRectMake(0, 0, kIconSize, kIconSize); color = CGColorSpaceCreateDeviceRGB(); if (color) { for (int i = 0; i < 2; i++) { ctx = CGBitmapContextCreate(data[i], kIconSize, kIconSize, 8, kIconSize * 4, color, kCGImageAlphaNoneSkipFirst); if (ctx) { PlotIconRefInContext(ctx, &rct, kAlignNone, kTransformNone, NULL, kPlotIconRefNormalFlags, macIconRef[macLegendIconIndex + i]); CGContextRelease(ctx); prov = CGDataProviderCreateWithData(NULL, data[i], kIconSize * kIconSize * 4, NULL); if (prov) { macIconImage[macLegendIconIndex + i] = CGImageCreate(kIconSize, kIconSize, 8, 32, kIconSize * 4, color, kCGImageAlphaNoneSkipFirst, prov, NULL, 1, kCGRenderingIntentDefault); CGDataProviderRelease(prov); } } } CGColorSpaceRelease(color); } } #endif } }
OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thumbnail, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options, CGSize maxSize) { CGFloat minCartDrawSize = 64; CGFloat size = fmin(maxSize.width, maxSize.height); CGContextRef qlContext = NULL; if (size < minCartDrawSize) { size = 32; qlContext = QLThumbnailRequestCreateContext(thumbnail, CGSizeMake(size,size), true, NULL); } else { qlContext = QLThumbnailRequestCreateContext(thumbnail, CGSizeMake(size,size), false, NULL); } if (qlContext) { NDSHeader header; NDSIcon icon; int pathlen = 2047; UInt8 path[pathlen+1]; if (CFURLGetFileSystemRepresentation(url, true, path, pathlen)) { if (size < minCartDrawSize) { // at smaller sizes we only draw the game icon at native size and let QL do the scaling parseNDSInfo(path, &header, &icon); CGImageRef image = CGImageCreateWithNDSIcon(&icon); if (image) { CGContextDrawImage(qlContext, CGRectMake(0, 0, size, size), image); CGImageRelease(image); } } else { CGContextClearRect(qlContext, CGRectMake(0,0,size,size)); // draw cartridge background CFURLRef bgURL = CFBundleCopyResourceURL(CFBundleGetBundleWithIdentifier( CFSTR("net.mironer.nds.quicklookgenerator")), CFSTR("background"), CFSTR("png"), NULL); if (bgURL) { CGDataProviderRef bgPNG = CGDataProviderCreateWithURL(bgURL); if (bgPNG) { CGImageRef bg = CGImageCreateWithPNGDataProvider(bgPNG, NULL, true, kCGRenderingIntentDefault); if (bg) { CGContextDrawImage(qlContext, CGRectMake(0, 0, size, size), bg); CGImageRelease(bg); } CGDataProviderRelease(bgPNG); } CFRelease(bgURL); } // draw game icon parseNDSInfo(path, &header, &icon); CGImageRef image = CGImageCreateWithNDSIcon(&icon); if (image) { CGContextDrawImage(qlContext, CGRectMake(size / 5, size / 5, size * 3 / 5, size * 3 / 5), image); CGImageRelease(image); } // draw cartridge overlay CFURLRef ovrURL = CFBundleCopyResourceURL( CFBundleGetBundleWithIdentifier( CFSTR("net.mironer.nds.quicklookgenerator")), CFSTR("overlay"), CFSTR("png"), NULL); if (ovrURL) { CGDataProviderRef ovrPNG = CGDataProviderCreateWithURL(ovrURL); if (ovrPNG) { CGImageRef ovr = CGImageCreateWithPNGDataProvider(ovrPNG, NULL, true, kCGRenderingIntentDefault); if (ovr) { CGContextDrawImage(qlContext, CGRectMake(0, 0, size, size), ovr); CGImageRelease(ovr); } CGDataProviderRelease(ovrPNG); } CFRelease(ovrURL); } // draw serial number CFStringRef serial = CFStringCreateWithSerialNumber(&header); CFAttributedStringRef aString = CFAttributedStringCreate(kCFAllocatorDefault, serial, NULL); CFMutableAttributedStringRef attrStr = CFAttributedStringCreateMutableCopy(kCFAllocatorDefault, 128, aString); CFIndex len = CFAttributedStringGetLength(attrStr); CTFontRef font = CTFontCreateWithName(CFSTR("Lucida Sans"), size / 16, NULL); CFAttributedStringSetAttribute(attrStr, CFRangeMake(0, len), kCTFontAttributeName, font); CTTextAlignment rightAlign = kCTRightTextAlignment; CTParagraphStyleSetting styleSettings[] = { {kCTParagraphStyleSpecifierAlignment, sizeof(rightAlign), &rightAlign} }; CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(styleSettings, 1); CFAttributedStringSetAttribute(attrStr, CFRangeMake(0, len), kCTParagraphStyleAttributeName, paragraphStyle); CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(attrStr); CFRelease(attrStr); CFRelease(aString); CFRelease(serial); CFRelease(font); CGMutablePathRef path = CGPathCreateMutable(); CGPathAddRect(path, NULL, CGRectMake(-size * 1.55 / 8, -size * 6.1 / 8, size, size)); CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, 0), path, NULL); CTFrameDraw(frame, qlContext); CFRelease(frame); CFRelease(framesetter); CFRelease(paragraphStyle); CFRelease(path); } } QLThumbnailRequestFlushContext(thumbnail, qlContext); CFRelease(qlContext); } return noErr; }
CGDataProviderRef CGDataProviderCreateFromURL_wrap(u_char* bytes, uint32 len) { return CGDataProviderCreateWithURL(CFURLCreateWithBytes( kCFAllocatorDefault, bytes, len, kCFStringEncodingMacRoman, NULL)); }