Implement a complete down sizing algorithm to avoid memory warnings

Code copy from the Apple Sample code "Large Image Downsizing" https://developer.apple.com/Library/ios/samplecode/LargeImageDownsizing/Introduction/Intro.html#//apple_ref/doc/uid/DTS40011173-Intro-DontLinkElementID_2
Modify image data back when the image is too large and it has been scaled down