iOS-Image-Filters icon indicating copy to clipboard operation
iOS-Image-Filters copied to clipboard

When used on large images, the result is cropped to a small portion of the image

Open peterpaulis opened this issue 8 years ago • 5 comments

No sure where the problem is, but when a large image is used 3000x2000 than the result is just a cropped portion of the original

In my implementation it was happening too, so i wanted to give yours a try, but the the same problem there

peterpaulis avatar Mar 24 '16 12:03 peterpaulis

this is only the case when using blur

peterpaulis avatar Mar 24 '16 12:03 peterpaulis

I'll look into this @peterpaulis, thank you for reporting the issue. Please report back if you find a solution to :smile:

jameswomack avatar Mar 24 '16 19:03 jameswomack

the problem is also with CIBloom as well

peterpaulis avatar Mar 25 '16 15:03 peterpaulis

found the problem, looks like some images report incorrect size and than the crop gets wrong

using the alternative to find the size bellow (and than cropping with it!) fixed the issue, but more research on this would be welcome

- (NGImage *)filter:(NSString *)filterName params:(NSDictionary *)theParams {
  NGImage *uiImage;

    NSLog(@"%f %f", self.image.size.width, self.image.size.height);

    NSSize imageSize = self.image.size;
    {
        NSInteger width = 0;
        NSInteger height = 0;

        for (NSImageRep * imageRep in self.image.representations) {
            if ([imageRep pixelsWide] > width) width = [imageRep pixelsWide];
            if ([imageRep pixelsHigh] > height) height = [imageRep pixelsHigh];
        }

        imageSize.width = width;
        imageSize.height = height;

        NSLog(@"Width from NSBitmapImageRep: %f",(CGFloat)width);
        NSLog(@"Height from NSBitmapImageRep: %f",(CGFloat)height);
    }

  CIImage *image = self.image.ng_CIImage;

  BOOL shouldClamp = theParams.allKeys.count && theParams[@"inputRadius"];
  if (shouldClamp) {
    image = [image ng_imageByClampingToExtent];
  }

  CIFilter *filter = [CIFilter withName:filterName andCIImage:image];

  [theParams enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop __unused) {
    [filter setValue:obj forKey:key];
  }];

  CIImage* outputImage = filter.outputImage;

  CGRect extent = shouldClamp ? (CGRect){.size = imageSize} : outputImage.extent;
  self.image = uiImage = [outputImage UIImageFromExtent:extent];

    return uiImage;
}

peterpaulis avatar Mar 25 '16 15:03 peterpaulis

a good approach looks like getting the size from CIImage, but with concating multiple filters, this could be a problem as sometime the extent is infinite

- (NGImage *)filter:(NSString *)filterName params:(NSDictionary *)theParams {
  NGImage *uiImage;

    CIImage *image = self.image.ng_CIImage;
    NSSize imageSize = [image extent].size;

peterpaulis avatar Mar 25 '16 15:03 peterpaulis