Search code examples
iphonecameraquartz-2d

Is there a better / faster way to process camera images than Quartz 2D?


I'm currently working on an iphone app that lets the user take a picture with the camera and then process it using Quartz 2D.

With Quartz 2D I transform the context to make the picture appear with the right orientation (scale and translate because it's mirrored) and then I stack a bunch of layers whith blending modes to process the picture.

The initial (and the final result) picture is 3mp or 5mp depending on device and it takes a great amount of memory once drawn. Reminder : it's not a jpeg in memory, it's bitmap data.

My layers are the same size as the initial picture so every time i draw a new layer on top of my picture i need the current picture state in memory (A) + the layer to blend memory space (B) + the space in memory to write the result (C).

When i get the result i ditch "A" and "B", takes "C" to the next stage of processing where it become the new "A"...

I need 4 pass like this to obtain the finale picture.

Giving the resolution of these pictures my memory usage can climb high. I can see a peek at 14Mo-15Mo and most of the time i only get level 1 warnings but level 2s sometimes wave at me and kill my app.

  • Am i doing this the right way regarding general process ?
  • Is there a way to speed up the processing ?
  • Why oh why memory warnings spawn randomly ?
  • Why the second picture process is longer than the first as you can see in this pic:

instruments screenshot


Solution

  • Because the duration looks to be about twice as long; I'd say it was doing twice as much processing. Does the third photo taken take three times as long?

    If so, that would seem to indicate it's processing all previous photos / layers taken. Which - of course - is a bug in your code somewhere.