GPUImage icon indicating copy to clipboard operation
GPUImage copied to clipboard

Crop Filter aspect ratio breaks inside Filter Group

Open lauraskelton opened this issue 14 years ago • 6 comments

I'm trying to use the Crop Filter to make my photos square before applying other filters such as vignette and sepia.

If I use crop filter alone, or crop filter in a Filter Group with one other filter, it works perfectly.

When I combine 2 or more filters with the crop filter, the aspect ratio is screwed up. Instead of appearing square, the image appears squashed. It seems like the vertical and horizontal dimensions are swapped.

It seems like it's forgetting the original image orientation somehow when used in series with other filters.

Any idea of how to fix it? I love the library and really hope it will work for my project!

Thanks, Laura

Here's the working code without the aspect ratio problem:

- (void)viewDidLoad
{
    stillCamera = [[GPUImageStillCamera alloc] initWithSessionPreset:AVCaptureSessionPresetPhoto cameraPosition:AVCaptureDevicePositionBack];
    stillCamera.outputImageOrientation = UIInterfaceOrientationPortrait;

    filter = [[GPUImageFilterGroup alloc] init];

    GPUImageCropFilter *cropFilter = [[GPUImageCropFilter alloc] initWithCropRegion:CGRectMake(0.0, 0.125, 1.0, 0.75)];

    GPUImageVignetteFilter *vignetteFilter = [[GPUImageVignetteFilter alloc] init];
    [(GPUImageFilterGroup *)filter addFilter:vignetteFilter];

    [cropFilter addTarget:vignetteFilter];

    [(GPUImageFilterGroup *)filter setInitialFilters:[NSArray arrayWithObjects: cropFilter, nil]];
    [(GPUImageFilterGroup *)filter setTerminalFilter:vignetteFilter];


    [filter prepareForImageCapture];

    [stillCamera addTarget:filter];

    [filter addTarget:filterView];
}

Here's the broken code with the squashed aspect ratio when I add a third filter to the group:

- (void)viewDidLoad
{
    stillCamera = [[GPUImageStillCamera alloc] initWithSessionPreset:AVCaptureSessionPresetPhoto cameraPosition:AVCaptureDevicePositionBack];
    stillCamera.outputImageOrientation = UIInterfaceOrientationPortrait;

    filter = [[GPUImageFilterGroup alloc] init];

    GPUImageCropFilter *cropFilter = [[GPUImageCropFilter alloc] initWithCropRegion:CGRectMake(0.0, 0.125, 1.0, 0.75)];

    GPUImageVignetteFilter *vignetteFilter = [[GPUImageVignetteFilter alloc] init];
    [(GPUImageFilterGroup *)filter addFilter:vignetteFilter];

    [cropFilter addTarget:vignetteFilter];

    GPUImageSepiaFilter *sepiaFilter = [[GPUImageSepiaFilter alloc] init];
    [(GPUImageFilterGroup *)filter addFilter:sepiaFilter];

    [vignetteFilter addTarget:sepiaFilter];

    [(GPUImageFilterGroup *)filter setInitialFilters:[NSArray arrayWithObjects: cropFilter, vignetteFilter, nil]];
    [(GPUImageFilterGroup *)filter setTerminalFilter:sepiaFilter];


    [filter prepareForImageCapture];

    [stillCamera addTarget:filter];

    [filter addTarget:filterView];
}

lauraskelton avatar Jul 24 '12 04:07 lauraskelton

Is this with the latest code in the repository? I had just fixed an issue with the crop not resizing properly a few days ago. If this is with the latest code, there might still be a bug somewhere in there and I can check on that.

BradLarson avatar Jul 24 '12 14:07 BradLarson

I downloaded the code from the repository yesterday afternoon so it should be the latest. Thank you so much for looking into it!

lauraskelton avatar Jul 24 '12 14:07 lauraskelton

+1 Can confirm this is happening , everything is fine with < 3 filters in the group

rromanchuk avatar Aug 21 '12 13:08 rromanchuk

+1 Problem occurs here too, with more than 3 filters in a group.

jeroentrappers avatar Oct 09 '12 11:10 jeroentrappers

Its happening with my code too. I assume its got something to do with the orientation of the images. The crop filter's setInputRotation is faulty for some of the orientations. Can anyone please suggest something here?

girishvr avatar Feb 20 '13 14:02 girishvr

It seems crop is not working for any filter group subclass, i.e. including GPUImageAmatorkaFilter

plenilune avatar Sep 08 '14 01:09 plenilune