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

Update to fully support all devices and latest GPUImage... #57

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Classes/DLCImagePickerController.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
- (void)imagePickerControllerDidCancel:(DLCImagePickerController *)picker;
@end

@interface DLCImagePickerController : UIViewController <UINavigationControllerDelegate,UIImagePickerControllerDelegate>
@interface DLCImagePickerController : UIViewController <UINavigationControllerDelegate,UIImagePickerControllerDelegate,UIPopoverControllerDelegate>

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *filterViewBottomConstraint;
@property (nonatomic, weak) IBOutlet GPUImageView *imageView;
@property (nonatomic, weak) id <DLCImagePickerDelegate> delegate;
@property (nonatomic, weak) IBOutlet UIButton *photoCaptureButton;
Expand Down
84 changes: 42 additions & 42 deletions Classes/DLCImagePickerController.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ @implementation DLCImagePickerController {
BOOL hasBlur;
int selectedFilter;
dispatch_once_t showLibraryOnceToken;
UIPopoverController *popover;
}

@synthesize delegate,
Expand Down Expand Up @@ -70,13 +71,12 @@ -(id) init {
-(void)viewDidLoad {

[super viewDidLoad];
self.wantsFullScreenLayout = YES;
self.extendedLayoutIncludesOpaqueBars = YES;

//set background color
self.view.backgroundColor = [UIColor colorWithPatternImage:
[UIImage imageNamed:@"micro_carbon"]];
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"micro_carbon"]];

self.photoBar.backgroundColor = [UIColor colorWithPatternImage:
[UIImage imageNamed:@"photo_bar"]];
self.photoBar.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"photo_bar"]];

self.topBar.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"photo_bar"]];
//button states
Expand All @@ -88,7 +88,7 @@ -(void)viewDidLoad {
self.focusView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"focus-crosshair"]];
[self.view addSubview:self.focusView];
self.focusView.alpha = 0;

[self.imageView setFillMode:kGPUImageFillModeStretch];

self.blurOverlayView = [[DLCBlurOverlayView alloc] initWithFrame:CGRectMake(0, 0,
self.imageView.frame.size.width,
Expand Down Expand Up @@ -268,7 +268,7 @@ -(void) prepareLiveFilter {
[filter addTarget:self.imageView];
}

[filter prepareForImageCapture];
[filter useNextFrameForImageCapture];

}

Expand Down Expand Up @@ -332,7 +332,15 @@ -(IBAction)switchToLibrary:(id)sender {
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePickerController.delegate = self;
imagePickerController.allowsEditing = YES;
[self presentViewController:imagePickerController animated:YES completion:NULL];

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
[popover dismissPopoverAnimated:YES];
popover = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];
popover.delegate = self;
[popover presentPopoverFromRect:self.libraryToggleButton.bounds inView:self.libraryToggleButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
} else {
[self presentViewController:imagePickerController animated:YES completion:NULL];
}
}

-(IBAction)toggleFlash:(UIButton *)button{
Expand All @@ -353,7 +361,6 @@ -(IBAction) toggleBlur:(UIButton*)blurButton {
blurFilter = [[GPUImageGaussianSelectiveBlurFilter alloc] init];
[(GPUImageGaussianSelectiveBlurFilter*)blurFilter setExcludeCircleRadius:80.0/320.0];
[(GPUImageGaussianSelectiveBlurFilter*)blurFilter setExcludeCirclePoint:CGPointMake(0.5f, 0.5f)];
[(GPUImageGaussianSelectiveBlurFilter*)blurFilter setBlurRadiusInPixels:kStaticBlurSize];
[(GPUImageGaussianSelectiveBlurFilter*)blurFilter setAspectRatio:1.0f];
}
hasBlur = YES;
Expand Down Expand Up @@ -383,6 +390,13 @@ -(IBAction) switchCamera {
}
}

#pragma mark - UIPopoverControllerDelegate
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
if (!isStatic) {
[self retakePhoto:nil];
}
}

-(void) prepareForCapture {
[stillCamera.inputCamera lockForConfiguration:nil];
if(self.flashToggleButton.selected &&
Expand Down Expand Up @@ -410,7 +424,7 @@ -(void)captureImage {

[self prepareFilter];
[self.retakeButton setHidden:NO];
[self.photoCaptureButton setTitle:@"Done" forState:UIControlStateNormal];
[self.photoCaptureButton setTitle:@"Finish" forState:UIControlStateNormal];
[self.photoCaptureButton setImage:nil forState:UIControlStateNormal];
[self.photoCaptureButton setEnabled:YES];
if(![self.filtersToggleButton isSelected]){
Expand All @@ -437,13 +451,13 @@ -(void)captureImage {
finalFilter = captureResize;
}

[finalFilter prepareForImageCapture];
[finalFilter useNextFrameForImageCapture];

[stillCamera capturePhotoAsImageProcessedUpToFilter:finalFilter withCompletionHandler:completion];
} else {
// A workaround inside capturePhotoProcessedUpToFilter:withImageOnGPUHandler: would cause the above method to fail,
// so we just grap the current crop filter output as an aproximation (the size won't match trough)
UIImage *img = [cropFilter imageFromCurrentlyProcessedOutput];
UIImage *img = [cropFilter imageFromCurrentFramebuffer];
completion(img, nil);
}
}
Expand Down Expand Up @@ -471,7 +485,7 @@ -(IBAction) takePhoto:(id)sender{

[staticPicture processImage];

UIImage *currentFilteredVideoFrame = [processUpTo imageFromCurrentlyProcessedOutputWithOrientation:staticPictureOriginalOrientation];
UIImage *currentFilteredVideoFrame = [processUpTo imageFromCurrentFramebufferWithOrientation:staticPictureOriginalOrientation];

NSDictionary *info = [[NSDictionary alloc] initWithObjectsAndKeys:
UIImageJPEGRepresentation(currentFilteredVideoFrame, self.outputJPEGQuality), @"data", nil];
Expand Down Expand Up @@ -518,20 +532,17 @@ -(IBAction) handlePan:(UIGestureRecognizer *) sender {

if ([sender state] == UIGestureRecognizerStateBegan) {
[self showBlurOverlay:YES];
[gpu setBlurRadiusInPixels:0.0f];
if (isStatic) {
[staticPicture processImage];
}
}

if ([sender state] == UIGestureRecognizerStateBegan || [sender state] == UIGestureRecognizerStateChanged) {
[gpu setBlurRadiusInPixels:0.0f];
[self.blurOverlayView setCircleCenter:tapPoint];
[gpu setExcludeCirclePoint:CGPointMake(tapPoint.x/320.0f, tapPoint.y/320.0f)];
}

if([sender state] == UIGestureRecognizerStateEnded){
[gpu setBlurRadiusInPixels:kStaticBlurSize];
[self showBlurOverlay:NO];
if (isStatic) {
[staticPicture processImage];
Expand Down Expand Up @@ -585,14 +596,12 @@ -(IBAction) handlePinch:(UIPinchGestureRecognizer *) sender {

if ([sender state] == UIGestureRecognizerStateBegan) {
[self showBlurOverlay:YES];
[gpu setBlurRadiusInPixels:0.0f];
if (isStatic) {
[staticPicture processImage];
}
}

if ([sender state] == UIGestureRecognizerStateBegan || [sender state] == UIGestureRecognizerStateChanged) {
[gpu setBlurRadiusInPixels:0.0f];
[gpu setExcludeCirclePoint:CGPointMake(midpoint.x/320.0f, midpoint.y/320.0f)];
self.blurOverlayView.circleCenter = CGPointMake(midpoint.x, midpoint.y);
CGFloat radius = MAX(MIN(sender.scale*[gpu excludeCircleRadius], 0.6f), 0.15f);
Expand All @@ -602,7 +611,6 @@ -(IBAction) handlePinch:(UIPinchGestureRecognizer *) sender {
}

if ([sender state] == UIGestureRecognizerStateEnded) {
[gpu setBlurRadiusInPixels:kStaticBlurSize];
[self showBlurOverlay:NO];
if (isStatic) {
[staticPicture processImage];
Expand All @@ -614,23 +622,14 @@ -(IBAction) handlePinch:(UIPinchGestureRecognizer *) sender {
-(void) showFilters {
[self.filtersToggleButton setSelected:YES];
self.filtersToggleButton.enabled = NO;
CGRect imageRect = self.imageView.frame;
imageRect.origin.y -= 34;
CGRect sliderScrollFrame = self.filterScrollView.frame;
sliderScrollFrame.origin.y -= self.filterScrollView.frame.size.height;
CGRect sliderScrollFrameBackground = self.filtersBackgroundImageView.frame;
sliderScrollFrameBackground.origin.y -=
self.filtersBackgroundImageView.frame.size.height-3;

self.filterScrollView.hidden = NO;
self.filtersBackgroundImageView.hidden = NO;
[UIView animateWithDuration:0.10
delay:0.05
options: UIViewAnimationOptionCurveEaseOut
animations:^{
self.imageView.frame = imageRect;
self.filterScrollView.frame = sliderScrollFrame;
self.filtersBackgroundImageView.frame = sliderScrollFrameBackground;
_filterViewBottomConstraint.constant=42;
[self.view layoutIfNeeded];
}
completion:^(BOOL finished){
self.filtersToggleButton.enabled = YES;
Expand All @@ -639,21 +638,12 @@ -(void) showFilters {

-(void) hideFilters {
[self.filtersToggleButton setSelected:NO];
CGRect imageRect = self.imageView.frame;
imageRect.origin.y += 34;
CGRect sliderScrollFrame = self.filterScrollView.frame;
sliderScrollFrame.origin.y += self.filterScrollView.frame.size.height;

CGRect sliderScrollFrameBackground = self.filtersBackgroundImageView.frame;
sliderScrollFrameBackground.origin.y += self.filtersBackgroundImageView.frame.size.height-3;

[UIView animateWithDuration:0.10
delay:0.05
options: UIViewAnimationOptionCurveEaseOut
animations:^{
self.imageView.frame = imageRect;
self.filterScrollView.frame = sliderScrollFrame;
self.filtersBackgroundImageView.frame = sliderScrollFrameBackground;
_filterViewBottomConstraint.constant=-31;
[self.view layoutIfNeeded];
}
completion:^(BOOL finished){

Expand Down Expand Up @@ -732,7 +722,13 @@ - (void)imagePickerController:(UIImagePickerController *)picker didFinishPicking
staticPicture = [[GPUImagePicture alloc] initWithImage:outputImage smoothlyScaleOutput:YES];
staticPictureOriginalOrientation = outputImage.imageOrientation;
isStatic = YES;
[self dismissViewControllerAnimated:YES completion:nil];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
[popover dismissPopoverAnimated:YES];
}
else {
[self dismissViewControllerAnimated:YES completion:nil];
}

[self.cameraToggleButton setEnabled:NO];
[self.flashToggleButton setEnabled:NO];
[self prepareStaticFilter];
Expand Down Expand Up @@ -760,6 +756,10 @@ - (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}

- (BOOL)prefersStatusBarHidden {
return YES;
}

#endif

@end
6 changes: 3 additions & 3 deletions Classes/PhotoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ - (void)loadView
-(void) takePhoto:(id)sender{
DLCImagePickerController *picker = [[DLCImagePickerController alloc] init];
picker.delegate = self;
[self presentModalViewController:picker animated:YES];
[self presentViewController:picker animated:YES completion:nil];
}


-(void) imagePickerControllerDidCancel:(DLCImagePickerController *)picker{
[self dismissModalViewControllerAnimated:YES];
[self dismissViewControllerAnimated:YES completion:nil];
}

-(void) imagePickerController:(DLCImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:NO];
[self dismissModalViewControllerAnimated:YES];
[self dismissViewControllerAnimated:YES completion:nil];

if (info) {
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
Expand Down
33 changes: 22 additions & 11 deletions DLCImagePickerController.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
remoteGlobalIDString = BCF1A34414DDB1EC00852800;
remoteInfo = GPUImageTests;
};
6A5D9A5515E01BC2001FAD14 /* PBXContainerItemProxy */ = {
84F1BAF5192E4F54000E0685 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 6A5D9A4815E01B72001FAD14 /* GPUImage.xcodeproj */;
proxyType = 1;
Expand Down Expand Up @@ -464,7 +464,7 @@
buildRules = (
);
dependencies = (
6A5D9A5615E01BC2001FAD14 /* PBXTargetDependency */,
84F1BAF6192E4F54000E0685 /* PBXTargetDependency */,
);
name = DLCImagePickerController;
productName = DLCImagePickerController;
Expand All @@ -477,7 +477,7 @@
6A5D9A0715E0152D001FAD14 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0460;
LastUpgradeCheck = 0510;
ORGANIZATIONNAME = "Backspaces Inc";
};
buildConfigurationList = 6A5D9A0A15E0152D001FAD14 /* Build configuration list for PBXProject "DLCImagePickerController" */;
Expand Down Expand Up @@ -614,10 +614,10 @@
/* End PBXSourcesBuildPhase section */

/* Begin PBXTargetDependency section */
6A5D9A5615E01BC2001FAD14 /* PBXTargetDependency */ = {
84F1BAF6192E4F54000E0685 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
name = GPUImage;
targetProxy = 6A5D9A5515E01BC2001FAD14 /* PBXContainerItemProxy */;
targetProxy = 84F1BAF5192E4F54000E0685 /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */

Expand All @@ -637,9 +637,10 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand All @@ -654,11 +655,15 @@
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = "GPUImage/framework/**";
IPHONEOS_DEPLOYMENT_TARGET = 4.3;
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
};
name = Debug;
Expand All @@ -667,21 +672,25 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = "GPUImage/framework/**";
IPHONEOS_DEPLOYMENT_TARGET = 4.3;
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
Expand All @@ -694,8 +703,9 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "DLCImagePickerController/DLCImagePickerController-Prefix.pch";
INFOPLIST_FILE = "DLCImagePickerController/DLCImagePickerController-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = "1,2";
WRAPPER_EXTENSION = app;
};
name = Debug;
Expand All @@ -706,8 +716,9 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "DLCImagePickerController/DLCImagePickerController-Prefix.pch";
INFOPLIST_FILE = "DLCImagePickerController/DLCImagePickerController-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = "1,2";
WRAPPER_EXTENSION = app;
};
name = Release;
Expand Down
2 changes: 1 addition & 1 deletion GPUImage
Submodule GPUImage updated 149 files
Loading