Round using rint instead of always rounding up. Cast width, height to local size_t variables to avoid issues with creating a new CGBitmapContext with the given width/height. Rename bufferSize ivar to cachedBufferSize.