GPUImage icon indicating copy to clipboard operation
GPUImage copied to clipboard

GPUImageView over 2048x2048 doesn't show GPUImagePicture

Open rkreutz opened this issue 11 years ago • 5 comments

Hi Brad,

First of all I would like to thank you so much for this awesome framework.

So, I'm having this problem and I can't figure out what's going on, I would really appreciate if you could help me out.

I'm loading an image from the camera roll and resizing it so it's size is smaller than GPUImageContext.maximumTextureSizeForThisDevice() and creating a thumbnail so I can preview the filters, which are being filterOperation.filter.forceProcessingAtSizeRespectingAspectRatio(SizeOfThumbnail). After that I go to another view and create a GPUImageView with the size of the original image (lesser than GPUImageContext.maximumTextureSizeForThisDevice()) and then I add it to a scroll view. The problem is that the image doesn't appear after I do a processImage, but if I resize the image to be lesser than 2048 the image appears. Below it's the code.

   if GLint(image.size.width) > GPUImageContext.maximumTextureSizeForThisDevice() ||
       GLint(image.size.height) > GPUImageContext.maximumTextureSizeForThisDevice() {
        let biggestSize = (image.size.width > image.size.height) ? image.size.width : image.size.height

        let newSize = CGSizeMake(image.size.width * CGFloat(GPUImageContext.maximumTextureSizeForThisDevice()) / biggestSize, image.size.height * CGFloat(GPUImageContext.maximumTextureSizeForThisDevice()) / biggestSize)
        UIGraphicsBeginImageContextWithOptions(newSize, false, 0.0)
        image.drawInRect(CGRectMake(0, 0, newSize.width, newSize.height))
        self.originalImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
    }
    else {
        self.originalImage = image
    }

    self.sizeOfImage = CGSize(width: self.originalImage!.size.width, height: originalImage!.size.height)

    let newSize = CGSizeMake(1024.0 , image.size.height * 1024.0/image.size.width)
    UIGraphicsBeginImageContextWithOptions(newSize, false, 0.0)
    image.drawInRect(CGRectMake(0, 0, newSize.width, newSize.height))
    self.thumbnail = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()

    self.media = GPUImagePicture(image: self.thumbnail)

    for filterOperation in filterOperations {
        self.media?.addTarget(filterOperation.filter as! GPUImageInput)
        filterOperation.filter.forceProcessingAtSizeRespectingAspectRatio(newSize)
    }

The other view

    self.media = GPUImagePicture(image: self.originalImage)

    self.imageView = GPUImageView(frame: CGRectMake(0, 0, self.sizeOfImage.width, self.sizeOfImage.height))

    media?.addTarget(choosenFilter.filter as! GPUImageInput)
    choosenFilter.filter.addTarget(self.imageView)

    self.scrollView.addSubview(self.imageView)
    self.view.sendSubviewToBack(self.scrollView)

    self.imageView.backgroundColor = UIColor.clearColor()
    self.imageView.setBackgroundColorRed(0.0, green: 0.0, blue: 0.0, alpha: 0.0)

    self.setMainScrollViewZoom()
    self.scrollView.contentSize = CGSizeMake(self.sizeOfImage.width, self.sizeOfImage.height)
    (self.media as? GPUImagePicture)?.processImage()

As I've said before, if I change GPUImageContext.maximumTextureSizeForThisDevice() for 2048, everything work's perfectly.

Thanks

rkreutz avatar Aug 03 '15 12:08 rkreutz

Having the same issue here, if I initiate GPUImageView with a size higher than 2048x2048, I get no image. I think it might be related to screen scale being 2 which gives 4048x4048 which is the maximum texture size.

You might want to look into forceProcessingAtSize; as discussed here, https://github.com/BradLarson/GPUImage/issues/1387. You may be able to get rid of the bound checks that way

EfeAcikgoz avatar Aug 09 '15 10:08 EfeAcikgoz

If I do a forceProcessingAtSize it doesn't change anything, I still got nothing.

I've been testing on my iPhone 4, and it has the same problem BUT instead of 2048 it passes to 1024, so I believe it really does have something to with the screen scale, as on different devices the limitation is always maximum texture divided by 2.

Thanks for the response by the way

rkreutz avatar Aug 10 '15 01:08 rkreutz

For iPhone 6 plus the maximum size at which GPUImageView keeps working is 4096 divided by 3 = 1365 points in any dimension, which is significant limitation IMO. Looking forward to this issue being fixed!

nalexn avatar Aug 21 '15 10:08 nalexn

I had to use UIImageView instead of gpuimageview and render an image and set it to imageView every time a filter/effect is changed. This is definitely not the best solution but its better than 1650px resolution for iPhone 6 plus

EfeAcikgoz avatar Aug 21 '15 10:08 EfeAcikgoz

Here is a workaround I found:

NSInteger maxSize = [GPUImageContext maximumTextureSizeForThisDevice] / [UIScreen mainScreen].scale;
if (self.bounds.size.width > maxSize || self.bounds.size.height > maxSize) {
    // For hack it, set lower frame, and apply transform scale
    CGFloat scale = MIN(maxSize / self.bounds.size.width, maxSize / self.bounds.size.height);

    CGFloat xInset = (self.bounds.size.width - scale * self.bounds.size.width) / 2.0;
    CGFloat yInset = (self.bounds.size.height - scale * self.bounds.size.height)  / 2.0;
    CGRect frame = UIEdgeInsetsInsetRect(self.bounds, UIEdgeInsetsMake(yInset, xInset, yInset, xInset));

    self.overlayGPUImageView.frame = frame;
    self.overlayGPUImageView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1/scale, 1/scale);
} else {
    self.overlayGPUImageView.transform = CGAffineTransformIdentity;
}

AlexandrGraschenkov avatar Jul 11 '16 09:07 AlexandrGraschenkov