title: Any way to encode a PNG faster than UIImagePNGRepresentation?
body: <p>I'm generating a bunch of tiles for <code>CATiledLayer</code>. It takes about 11 seconds to generate 120 tiles at 256 x 256 with 4 levels of detail on an iPhone 4S. The image itself fits within 2048 x 2048.</p>
  
  <p>My bottleneck is <code>UIImagePNGRepresentation</code>. It takes about 0.10-0.15 seconds to generate every 256 x 256 image.</p>
  
  <p>I've tried generating multiple tiles on different background queue's, but this only cuts it down to about 9-10 seconds.</p>
  
  <p>I've also tried using the ImageIO framework with code like this:</p>
  
  <pre><code>- (void)writeCGImage:(CGImageRef)image toURL:(NSURL*)url andOptions:(CFDictionaryRef) options
  {
      CGImageDestinationRef myImageDest = CGImageDestinationCreateWithURL((__bridge CFURLRef)url, (__bridge CFStringRef)@"public.png", 1, nil);
      CGImageDestinationAddImage(myImageDest, image, options);
      CGImageDestinationFinalize(myImageDest);
      CFRelease(myImageDest);
  }
  </code></pre>
  
  <p>While this produces smaller PNG files (win!), it takes about 13 seconds, 2 seconds more than before.</p>
  
  <p>Is there any way to encode a PNG image from <code>CGImage</code> faster? Perhaps a library that makes use of <code>NEON</code> ARM extension (iPhone 3GS+) like <a href="http://libjpeg-turbo.virtualgl.org/">libjpeg-turbo</a> does?</p>
  
  <p>Is there perhaps a better format than PNG for saving tiles that doesn't take up a lot of space?</p>
  
  <p>The only viable option I've been able to come up with is to increase the tile size to 512 x 512. This cuts the encoding time by half. Not sure what that will do to my scroll view though. The app is for iPad 2+, and only supports iOS 6 (using iPhone 4S as a baseline).</p>