Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
peterpaulis opened this issue Mar 24, 2016 · 5 comments

Comments

@peterpaulis
Copy link

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
Copy link
Author

this is only the case when using blur

@jameswomack
Copy link
Owner

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

@peterpaulis
Copy link
Author

the problem is also with CIBloom as well

@peterpaulis
Copy link
Author

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
Copy link
Author

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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants