My MySQL tool is on softpedia.com.

I just got the notice today. I wrote this bulk row insert tool for MySQL that is designed to run over the Internet. It’s for really large data sets being loaded into … ahem … inexpensive hosted MySQL databases. Check out the mysqlxfer softpedia page.

Roll-your-own iPhone framework.

After starting work on my latest iPhone app (#6 or so), I finally decided it was time to get more efficient with my existing library of code. I’ve been building various helper classes for manipulating bitmaps, etc, and I wanted to be able to share them between my apps in a more organized way.

As usual, there isn’t much on the web about this, but I eventually tracked down a couple of useful articles to get me started:

The first article shows you how to add your own custom project type template to XCode so you can easily create shared iPhone libraries. The second one shows you how to reference your new library from your application. With a little trial-and-error I now have a nice shared lib of iPhone classes. Pretty soon, who knows, maybe Apple will allow dynamic linking and we can move iPhone development into the 80s!

iPhone programming: fun with grayscale images.

So I was trying to do something that I thought was simple. I needed to convert an image from full color to grayscale in my iPhone application, and I easily found the CGColorSpaceCreateDeviceGray method which seemed to put me on the right track. But the complication came when I tried to use this color space with CGBitmapContextCreate. I got this error in the console:

<Error>: CGBitmapContextCreate: unsupported parameter combination:
8 integer bits/component; 16 bits/pixel; 1-component colorspace;
kCGImageAlphaPremultipliedLast; 1472 bytes/row.

So the combination of parameters was incorrect. But which one was at fault? Thankfully, I found a helpful post on the web that led me to this article:

CGBitmapContextCreate Supported Color Spaces

Very handy. Wish that this table were actually included in the documentation for the CGBitmapContextCreate method. Imagine how useful that would be! So, for your convenience, here is a function to create a grayscale copy of a UIImage:

UIImage *createGrayCopy(UIImage *source)
{
	int width = source.size.width;
	int height = source.size.height;

	CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();

	CGContextRef context = CGBitmapContextCreate (nil,
						 width,
						 height,
						 8,      // bits per component
						 0,
						 colorSpace,
						 kCGImageAlphaNone);

	CGColorSpaceRelease(colorSpace);

	if (context == NULL) {
		return nil;
	}

	CGContextDrawImage(context,
		CGRectMake(0, 0, width, height), source.CGImage);

	UIImage *grayImage = [UIImage imageWithCGImage:CGBitmapContextCreateImage(context)];
	CGContextRelease(context);

	return grayImage;
}