#import <KillMeNow/KillMeNow.h>

Discussion in 'Mac Programming' started by zeppenwolf, Dec 13, 2009.

  1. zeppenwolf macrumors regular


    Nov 17, 2009
    I am trying to compile the function pasted below. I copied it from "Quartz 2D Primer" or somesuch, as it does exactly what I think I need.

    ( And when I say, "copied", I mean I had to type to whole thing myself, as the text was not 'selectable' in the PDF. Heh. Thx, Apple )

    So I'd like to just compile this one file. It contains references to "CGDataProvider" etc, which are undefined without appropriate includes.

    Ok, fine. I loate the file which defines "CGDataProvider", and attempt to include it:

    #import <CGDataProvider.h>

    But that doesn't work. Fine. So I try:

    #import <CoreGraphics/CGDataProvider.h>

    But that doesn't work. Fine. So I try:

    #import <CoreGraphics/CoreGraphics.h>

    But that doesn't work.

    *Excuse me*, but what the heck is going on with this new goofy magic with "import" and the whole slash thing? I know exactly which file contains the definition, but I can't include it... Where is this goofiness documented?? Aaaargh/Thx. :)

    // iWidth			width of bitmap
    // iHeight			height of bitmap
    // iBytesPerRow		number of bytes per row, given by GetPixRowBytes()
    // contextR			a Core Graphics context to draw the image to
    void	Draw32BitARGBToContext( void* iBitsP, size_t iWidth, size_t iHeight, size_t iBytesPerRow, CGContextRef contextR ) {
    	CGRect			rectangle;
    	CGDataProvider	provider;
    	CGColorSpaceRef	colorSpace;
    	size_t			size;
    	CGImageRef		image;
    	size		= iBytesPerRow * height;
    	// Create a data provider with a pointer to the memory bits
    	provider	= CGDataProviderCreateWithData( NULL, iBitsP, size, NULL );
    	// Colorspace can be device, calibrated, or ICC profile based
    	colorSpace	= CGColorSpaceCreateDeviceRGB();
    	// Create the image
    	image		= CGImageCreate( iWidth, iHeight,
    					8,		// bitsPerComponent
    					32,		// bitsPerPixel
    					iBytesPerRow, colorSpace, kCGImageAlphaFirst, provider, NULL, 0, kVGRenderingIntentDefault );
    	//	Once the image is created we can release our reference to the provider and the colorspace.
    	// They will be retained by the image.
    	CGDataProviderRelease( provider );
    	CGColorSpaceRelease( colorSpace );
    	// Determine the location where the image will be drawn in userspace.
    	rectangle	= CGRectMake( 0, 0, iWidth, iHeight );
    	//	Draw the image to the Core Graphics context
    	CGContextDrawImage( context, rectangle, image );
    	CGImageRelease( image );
  2. Cromulent macrumors 603


    Oct 2, 2006
    The Land of Hope and Glory
    A slash just denotes a different folder. It is just a relative path basically.

    #import is just the same as #include except that it makes sure to only include files once.
  3. Guiyon macrumors 6502a

    Mar 19, 2008
    North Shore, MA
    Have you added/tried adding the ApplicationServices framework to the project?
  4. lloyddean macrumors 6502a

    May 10, 2009
    Des Moines, WA
    Change 'CGDataProvider' to 'CGDataProviderRef' and you'll be much less unhappy!
  5. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset

    Which OS version are you using? What PDF reader? I just downloaded "Quartz Primer.pdf" containing Draw32BitARGBToContext source from here:


    The source text was selectable and copy-pasteable on 10.5 Leopard and 10.6 Snow Leopard using Preview.app as the PDF reader.
  6. zeppenwolf thread starter macrumors regular


    Nov 17, 2009
    Ok guys, thanks for the help. Apparently, "ApplicationServices" is an "umbrella" framework, and I am not allowed to directly include files from frameworks inside it... I have to say, I'm not surprised I didn't figure that one out.

    chown33, I'm on OS 10.2.8 Heh. Yes, things may have advanced by now, but I assure you the text is not selectable on the pdf which comes with that era's Dev CD's. But hey-- at least I'm catching up!! :)
  7. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    For future reference, you might at least mention that you're using an extremely old OS version. It does have a direct bearing on what you will be able to do.

    You should also specify what tool you're using. Acrobat Reader can select text on 10.2.8; Preview.app cannot. Acrobat Reader 5.0 should be a standard part of the OS install.


    Booting up my ancient PowerPC machine under 10.2.8, I see Acrobat Reader 5.0 located in the /Applications folder. I drag Quartz Primer.pdf onto it and it runs. I see a Text Select tool in Acrobat Reader's toolbar. I choose it and select text, then copy and paste. It all works fine.

    Edit: I just rebooted the PPC to 10.3.5, and Preview.app can select, copy, and paste text in PDFs. You should consider upgrading to something a little less obsolete than 10.2.8.
  8. zeppenwolf thread starter macrumors regular


    Nov 17, 2009
    Someday, hopefully someday soon, I will have a newer machine.

    Not a 'new' machine, but a 'newer' machine.

    Meanwhile, the machine I am on cannot be upgraded past 10.2.8, not by motherboard upgrade, not by anthying. It is absolutely impossible, according to Apple. And purchasing a 'new' machine is absolutely impossible, according to my finances.

    I apologize if I have wasted anyone's time or led anyone down the wrong path; I will remember to mention my OS / tool versions in the future. I didn't think it was an issue in this thread. Thanks again for the help.
  9. Detrius macrumors 68000

    Sep 10, 2008
    Asheville, NC
    To install OS X on older unsupported machines:

    So, from my research, this would mean you're running either a Beige PowerMac G3 or a non-Pismo PowerBook G3. Wow. Ancient. Incredibly ancient. But yes, XPostFacto can get these running newer versions of OS X.

Share This Page