GPUImage
GPUImage copied to clipboard
Adds the ability to capture opaque CGImages from GPUImageFilters
GPUImage is a fantastic library, thanks for all the hard work!
I frequently use GPUImage to create images for use in a UITableView
or UICollectionView
(creating thumbnails, adding a drop shadow, etc...).
One way to achieve smooth scrolling with a UITableView
is to ensure that every image in the table is fully opaque, with no alpha channel. A quick google for "UITableView performance" yields plenty of pages that describe why opaque images are important.
I often find myself writing code that does the following:
Source UIImage
|
+-> GPUImageFilter
|
+-> Output UIImage
|
+-> CoreGraphics removeAlpha()
|
+-> Opaque UIImage
using a UIImage
extension like this:
extension UIImage {
func removeAlpha() -> UIImage {
UIGraphicsBeginImageContextWithOptions(size, true, scale)
self.drawInRect(CGRectMake(0, 0, size.width, size.height))
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
}
Which is just crazy, because I'm needlessly using the CPU to create a copy of an image that I just created on the GPU. It would be nice if I could just ask GPUImage to make the UIImage
opaque when it's initially created.
This pull request adds a boolean flag shouldCaptureOpaqueImage
to GPUImageOutput
and GPUImageFrameBuffer
to enable this behavior.
Thanks again for creating GPUImage!