-
Notifications
You must be signed in to change notification settings - Fork 310
Expand file tree
/
Copy pathDLCImagePickerController.m
More file actions
765 lines (630 loc) · 25.5 KB
/
DLCImagePickerController.m
File metadata and controls
765 lines (630 loc) · 25.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
//
// DLCImagePickerController.m
// DLCImagePickerController
//
// Created by Dmitri Cherniak on 8/14/12.
// Copyright (c) 2012 Dmitri Cherniak. All rights reserved.
//
#import "DLCImagePickerController.h"
#import "DLCGrayscaleContrastFilter.h"
#define kStaticBlurSize 2.0f
@implementation DLCImagePickerController {
GPUImageStillCamera *stillCamera;
GPUImageOutput<GPUImageInput> *filter;
GPUImageOutput<GPUImageInput> *blurFilter;
GPUImageCropFilter *cropFilter;
GPUImagePicture *staticPicture;
UIImageOrientation staticPictureOriginalOrientation;
BOOL isStatic;
BOOL hasBlur;
int selectedFilter;
dispatch_once_t showLibraryOnceToken;
UIPopoverController *popover;
}
@synthesize delegate,
imageView,
cameraToggleButton,
photoCaptureButton,
blurToggleButton,
flashToggleButton,
cancelButton,
retakeButton,
filtersToggleButton,
libraryToggleButton,
filterScrollView,
filtersBackgroundImageView,
photoBar,
topBar,
blurOverlayView,
outputJPEGQuality,
requestedImageSize;
-(void) sharedInit {
outputJPEGQuality = 1.0;
requestedImageSize = CGSizeZero;
}
-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
[self sharedInit];
}
return self;
}
-(id) initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
[self sharedInit];
}
return self;
}
-(id) init {
return [self initWithNibName:@"DLCImagePicker" bundle:nil];
}
-(void)viewDidLoad {
[super viewDidLoad];
self.extendedLayoutIncludesOpaqueBars = YES;
//set background color
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"micro_carbon"]];
self.photoBar.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"photo_bar"]];
self.topBar.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"photo_bar"]];
//button states
[self.blurToggleButton setSelected:NO];
[self.filtersToggleButton setSelected:NO];
staticPictureOriginalOrientation = UIImageOrientationUp;
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,
self.imageView.frame.size.height)];
self.blurOverlayView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.blurOverlayView.alpha = 0;
[self.imageView addSubview:self.blurOverlayView];
hasBlur = NO;
[self loadFilters];
//we need a crop filter for the live video
cropFilter = [[GPUImageCropFilter alloc] initWithCropRegion:CGRectMake(0.0f, 0.0f, 1.0f, 0.75f)];
filter = [[GPUImageFilter alloc] init];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
[self setUpCamera];
});
}
-(void) viewWillAppear:(BOOL)animated {
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
[super viewWillAppear:animated];
}
-(void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
if (![UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
dispatch_once(&showLibraryOnceToken, ^{
[self switchToLibrary:nil];
});
}
}
-(void) loadFilters {
for(int i = 0; i < 10; i++) {
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg", i + 1]] forState:UIControlStateNormal];
button.frame = CGRectMake(10+i*(60+10), 5.0f, 60.0f, 60.0f);
button.layer.cornerRadius = 7.0f;
//use bezier path instead of maskToBounds on button.layer
UIBezierPath *bi = [UIBezierPath bezierPathWithRoundedRect:button.bounds
byRoundingCorners:UIRectCornerAllCorners
cornerRadii:CGSizeMake(7.0,7.0)];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = button.bounds;
maskLayer.path = bi.CGPath;
button.layer.mask = maskLayer;
button.layer.borderWidth = 1;
button.layer.borderColor = [[UIColor blackColor] CGColor];
[button addTarget:self
action:@selector(filterClicked:)
forControlEvents:UIControlEventTouchUpInside];
button.tag = i;
[button setTitle:@"*" forState:UIControlStateSelected];
if(i == 0){
[button setSelected:YES];
}
[self.filterScrollView addSubview:button];
}
[self.filterScrollView setContentSize:CGSizeMake(10 + 10*(60+10), 75.0)];
}
-(void) setUpCamera {
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
// Has camera
stillCamera = [[GPUImageStillCamera alloc] initWithSessionPreset:AVCaptureSessionPresetPhoto cameraPosition:AVCaptureDevicePositionBack];
stillCamera.outputImageOrientation = UIInterfaceOrientationPortrait;
runOnMainQueueWithoutDeadlocking(^{
[stillCamera startCameraCapture];
if([stillCamera.inputCamera hasTorch]){
[self.flashToggleButton setEnabled:YES];
}else{
[self.flashToggleButton setEnabled:NO];
}
[self prepareFilter];
});
} else {
runOnMainQueueWithoutDeadlocking(^{
// No camera awailable, hide camera related buttons and show the image picker
self.cameraToggleButton.hidden = YES;
self.photoCaptureButton.hidden = YES;
self.flashToggleButton.hidden = YES;
// Show the library picker
// [self switchToLibrary:nil];
// [self performSelector:@selector(switchToLibrary:) withObject:nil afterDelay:0.5];
[self prepareFilter];
});
}
}
-(void) filterClicked:(UIButton *) sender {
for(UIView *view in self.filterScrollView.subviews){
if([view isKindOfClass:[UIButton class]]){
[(UIButton *)view setSelected:NO];
}
}
[sender setSelected:YES];
[self removeAllTargets];
selectedFilter = sender.tag;
[self setFilter:sender.tag];
[self prepareFilter];
}
-(void) setFilter:(int) index {
switch (index) {
case 1:{
filter = [[GPUImageContrastFilter alloc] init];
[(GPUImageContrastFilter *) filter setContrast:1.75];
} break;
case 2: {
filter = [[GPUImageToneCurveFilter alloc] initWithACV:@"crossprocess"];
} break;
case 3: {
filter = [[GPUImageToneCurveFilter alloc] initWithACV:@"02"];
} break;
case 4: {
filter = [[DLCGrayscaleContrastFilter alloc] init];
} break;
case 5: {
filter = [[GPUImageToneCurveFilter alloc] initWithACV:@"17"];
} break;
case 6: {
filter = [[GPUImageToneCurveFilter alloc] initWithACV:@"aqua"];
} break;
case 7: {
filter = [[GPUImageToneCurveFilter alloc] initWithACV:@"yellow-red"];
} break;
case 8: {
filter = [[GPUImageToneCurveFilter alloc] initWithACV:@"06"];
} break;
case 9: {
filter = [[GPUImageToneCurveFilter alloc] initWithACV:@"purple-green"];
} break;
default:
filter = [[GPUImageFilter alloc] init];
break;
}
}
-(void) prepareFilter {
if (![UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
isStatic = YES;
}
if (!isStatic) {
[self prepareLiveFilter];
} else {
[self prepareStaticFilter];
}
}
-(void) prepareLiveFilter {
[stillCamera addTarget:cropFilter];
[cropFilter addTarget:filter];
//blur is terminal filter
if (hasBlur) {
[filter addTarget:blurFilter];
[blurFilter addTarget:self.imageView];
//regular filter is terminal
} else {
[filter addTarget:self.imageView];
}
[filter useNextFrameForImageCapture];
}
-(void) prepareStaticFilter {
[staticPicture addTarget:filter];
// blur is terminal filter
if (hasBlur) {
[filter addTarget:blurFilter];
[blurFilter addTarget:self.imageView];
//regular filter is terminal
} else {
[filter addTarget:self.imageView];
}
GPUImageRotationMode imageViewRotationMode = kGPUImageNoRotation;
switch (staticPictureOriginalOrientation) {
case UIImageOrientationLeft:
imageViewRotationMode = kGPUImageRotateLeft;
break;
case UIImageOrientationRight:
imageViewRotationMode = kGPUImageRotateRight;
break;
case UIImageOrientationDown:
imageViewRotationMode = kGPUImageRotate180;
break;
default:
imageViewRotationMode = kGPUImageNoRotation;
break;
}
// seems like atIndex is ignored by GPUImageView...
[self.imageView setInputRotation:imageViewRotationMode atIndex:0];
[staticPicture processImage];
}
-(void) removeAllTargets {
[stillCamera removeAllTargets];
[staticPicture removeAllTargets];
[cropFilter removeAllTargets];
//regular filter
[filter removeAllTargets];
//blur
[blurFilter removeAllTargets];
}
-(IBAction)switchToLibrary:(id)sender {
if (!isStatic) {
// shut down camera
[stillCamera stopCameraCapture];
[self removeAllTargets];
}
UIImagePickerController* imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePickerController.delegate = self;
imagePickerController.allowsEditing = YES;
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{
[button setSelected:!button.selected];
}
-(IBAction) toggleBlur:(UIButton*)blurButton {
[self.blurToggleButton setEnabled:NO];
[self removeAllTargets];
if (hasBlur) {
hasBlur = NO;
[self showBlurOverlay:NO];
[self.blurToggleButton setSelected:NO];
} else {
if (!blurFilter) {
blurFilter = [[GPUImageGaussianSelectiveBlurFilter alloc] init];
[(GPUImageGaussianSelectiveBlurFilter*)blurFilter setExcludeCircleRadius:80.0/320.0];
[(GPUImageGaussianSelectiveBlurFilter*)blurFilter setExcludeCirclePoint:CGPointMake(0.5f, 0.5f)];
[(GPUImageGaussianSelectiveBlurFilter*)blurFilter setAspectRatio:1.0f];
}
hasBlur = YES;
CGPoint excludePoint = [(GPUImageGaussianSelectiveBlurFilter*)blurFilter excludeCirclePoint];
CGSize frameSize = self.blurOverlayView.frame.size;
self.blurOverlayView.circleCenter = CGPointMake(excludePoint.x * frameSize.width, excludePoint.y * frameSize.height);
[self.blurToggleButton setSelected:YES];
[self flashBlurOverlay];
}
[self prepareFilter];
[self.blurToggleButton setEnabled:YES];
}
-(IBAction) switchCamera {
[self.cameraToggleButton setEnabled:NO];
[stillCamera rotateCamera];
[self.cameraToggleButton setEnabled:YES];
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera] && stillCamera) {
if ([stillCamera.inputCamera hasFlash] && [stillCamera.inputCamera hasTorch]) {
[self.flashToggleButton setEnabled:YES];
} else {
[self.flashToggleButton setEnabled:NO];
}
}
}
#pragma mark - UIPopoverControllerDelegate
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
if (!isStatic) {
[self retakePhoto:nil];
}
}
-(void) prepareForCapture {
[stillCamera.inputCamera lockForConfiguration:nil];
if(self.flashToggleButton.selected &&
[stillCamera.inputCamera hasTorch]){
[stillCamera.inputCamera setTorchMode:AVCaptureTorchModeOn];
[self performSelector:@selector(captureImage)
withObject:nil
afterDelay:0.25];
}else{
[self captureImage];
}
}
-(void)captureImage {
void (^completion)(UIImage *, NSError *) = ^(UIImage *img, NSError *error) {
[stillCamera.inputCamera unlockForConfiguration];
[stillCamera stopCameraCapture];
[self removeAllTargets];
staticPicture = [[GPUImagePicture alloc] initWithImage:img smoothlyScaleOutput:NO];
staticPictureOriginalOrientation = img.imageOrientation;
[self prepareFilter];
[self.retakeButton setHidden:NO];
[self.photoCaptureButton setTitle:@"Finish" forState:UIControlStateNormal];
[self.photoCaptureButton setImage:nil forState:UIControlStateNormal];
[self.photoCaptureButton setEnabled:YES];
if(![self.filtersToggleButton isSelected]){
[self showFilters];
}
};
AVCaptureDevicePosition currentCameraPosition = stillCamera.inputCamera.position;
Class contextClass = NSClassFromString(@"GPUImageContext") ?: NSClassFromString(@"GPUImageOpenGLESContext");
if ((currentCameraPosition != AVCaptureDevicePositionFront) || (![contextClass supportsFastTextureUpload])) {
// Image full-resolution capture is currently possible just on the final (destination filter), so
// create a new paralel chain, that crops and resizes our image
[self removeAllTargets];
GPUImageCropFilter *captureCrop = [[GPUImageCropFilter alloc] initWithCropRegion:cropFilter.cropRegion];
[stillCamera addTarget:captureCrop];
GPUImageFilter *finalFilter = captureCrop;
if (!CGSizeEqualToSize(requestedImageSize, CGSizeZero)) {
GPUImageFilter *captureResize = [[GPUImageFilter alloc] init];
[captureResize forceProcessingAtSize:requestedImageSize];
[captureCrop addTarget:captureResize];
finalFilter = captureResize;
}
[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 imageFromCurrentFramebuffer];
completion(img, nil);
}
}
-(IBAction) takePhoto:(id)sender{
[self.photoCaptureButton setEnabled:NO];
if (!isStatic) {
isStatic = YES;
[self.libraryToggleButton setHidden:YES];
[self.cameraToggleButton setEnabled:NO];
[self.flashToggleButton setEnabled:NO];
[self prepareForCapture];
} else {
GPUImageOutput<GPUImageInput> *processUpTo;
if (hasBlur) {
processUpTo = blurFilter;
} else {
processUpTo = filter;
}
[staticPicture processImage];
UIImage *currentFilteredVideoFrame = [processUpTo imageFromCurrentFramebufferWithOrientation:staticPictureOriginalOrientation];
NSDictionary *info = [[NSDictionary alloc] initWithObjectsAndKeys:
UIImageJPEGRepresentation(currentFilteredVideoFrame, self.outputJPEGQuality), @"data", nil];
[self.delegate imagePickerController:self didFinishPickingMediaWithInfo:info];
}
}
-(IBAction) retakePhoto:(UIButton *)button {
[self.retakeButton setHidden:YES];
[self.libraryToggleButton setHidden:NO];
staticPicture = nil;
staticPictureOriginalOrientation = UIImageOrientationUp;
isStatic = NO;
[self removeAllTargets];
[stillCamera startCameraCapture];
[self.cameraToggleButton setEnabled:YES];
if([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]
&& stillCamera
&& [stillCamera.inputCamera hasTorch]) {
[self.flashToggleButton setEnabled:YES];
}
[self.photoCaptureButton setImage:[UIImage imageNamed:@"camera-icon"] forState:UIControlStateNormal];
[self.photoCaptureButton setTitle:nil forState:UIControlStateNormal];
if ([self.filtersToggleButton isSelected]) {
[self hideFilters];
}
[self setFilter:selectedFilter];
[self prepareFilter];
}
-(IBAction) cancel:(id)sender {
[self.delegate imagePickerControllerDidCancel:self];
}
-(IBAction) handlePan:(UIGestureRecognizer *) sender {
if (hasBlur) {
CGPoint tapPoint = [sender locationInView:imageView];
GPUImageGaussianSelectiveBlurFilter* gpu =
(GPUImageGaussianSelectiveBlurFilter*)blurFilter;
if ([sender state] == UIGestureRecognizerStateBegan) {
[self showBlurOverlay:YES];
if (isStatic) {
[staticPicture processImage];
}
}
if ([sender state] == UIGestureRecognizerStateBegan || [sender state] == UIGestureRecognizerStateChanged) {
[self.blurOverlayView setCircleCenter:tapPoint];
[gpu setExcludeCirclePoint:CGPointMake(tapPoint.x/320.0f, tapPoint.y/320.0f)];
}
if([sender state] == UIGestureRecognizerStateEnded){
[self showBlurOverlay:NO];
if (isStatic) {
[staticPicture processImage];
}
}
}
}
- (IBAction) handleTapToFocus:(UITapGestureRecognizer *)tgr{
if (!isStatic && tgr.state == UIGestureRecognizerStateRecognized) {
CGPoint location = [tgr locationInView:self.imageView];
AVCaptureDevice *device = stillCamera.inputCamera;
CGPoint pointOfInterest = CGPointMake(.5f, .5f);
CGSize frameSize = [[self imageView] frame].size;
if ([stillCamera cameraPosition] == AVCaptureDevicePositionFront) {
location.x = frameSize.width - location.x;
}
pointOfInterest = CGPointMake(location.y / frameSize.height, 1.f - (location.x / frameSize.width));
if ([device isFocusPointOfInterestSupported] && [device isFocusModeSupported:AVCaptureFocusModeAutoFocus]) {
NSError *error;
if ([device lockForConfiguration:&error]) {
[device setFocusPointOfInterest:pointOfInterest];
[device setFocusMode:AVCaptureFocusModeAutoFocus];
if([device isExposurePointOfInterestSupported] && [device isExposureModeSupported:AVCaptureExposureModeContinuousAutoExposure]) {
[device setExposurePointOfInterest:pointOfInterest];
[device setExposureMode:AVCaptureExposureModeContinuousAutoExposure];
}
self.focusView.center = [tgr locationInView:self.view];
self.focusView.alpha = 1;
[UIView animateWithDuration:0.5 delay:0.5 options:0 animations:^{
self.focusView.alpha = 0;
} completion:nil];
[device unlockForConfiguration];
} else {
NSLog(@"ERROR = %@", error);
}
}
}
}
-(IBAction) handlePinch:(UIPinchGestureRecognizer *) sender {
if (hasBlur) {
CGPoint midpoint = [sender locationInView:imageView];
GPUImageGaussianSelectiveBlurFilter* gpu =
(GPUImageGaussianSelectiveBlurFilter*)blurFilter;
if ([sender state] == UIGestureRecognizerStateBegan) {
[self showBlurOverlay:YES];
if (isStatic) {
[staticPicture processImage];
}
}
if ([sender state] == UIGestureRecognizerStateBegan || [sender state] == UIGestureRecognizerStateChanged) {
[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);
self.blurOverlayView.radius = radius*320.f;
[gpu setExcludeCircleRadius:radius];
sender.scale = 1.0f;
}
if ([sender state] == UIGestureRecognizerStateEnded) {
[self showBlurOverlay:NO];
if (isStatic) {
[staticPicture processImage];
}
}
}
}
-(void) showFilters {
[self.filtersToggleButton setSelected:YES];
self.filtersToggleButton.enabled = NO;
self.filterScrollView.hidden = NO;
self.filtersBackgroundImageView.hidden = NO;
[UIView animateWithDuration:0.10
delay:0.05
options: UIViewAnimationOptionCurveEaseOut
animations:^{
_filterViewBottomConstraint.constant=42;
[self.view layoutIfNeeded];
}
completion:^(BOOL finished){
self.filtersToggleButton.enabled = YES;
}];
}
-(void) hideFilters {
[self.filtersToggleButton setSelected:NO];
[UIView animateWithDuration:0.10
delay:0.05
options: UIViewAnimationOptionCurveEaseOut
animations:^{
_filterViewBottomConstraint.constant=-31;
[self.view layoutIfNeeded];
}
completion:^(BOOL finished){
self.filtersToggleButton.enabled = YES;
self.filterScrollView.hidden = YES;
self.filtersBackgroundImageView.hidden = YES;
}];
}
-(IBAction) toggleFilters:(UIButton *)sender {
sender.enabled = NO;
if (sender.selected){
[self hideFilters];
} else {
[self showFilters];
}
}
-(void) showBlurOverlay:(BOOL)show{
if(show){
[UIView animateWithDuration:0.2 delay:0 options:0 animations:^{
self.blurOverlayView.alpha = 0.6;
} completion:^(BOOL finished) {
}];
}else{
[UIView animateWithDuration:0.35 delay:0.2 options:0 animations:^{
self.blurOverlayView.alpha = 0;
} completion:^(BOOL finished) {
}];
}
}
-(void) flashBlurOverlay {
[UIView animateWithDuration:0.2 delay:0 options:0 animations:^{
self.blurOverlayView.alpha = 0.6;
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.35 delay:0.2 options:0 animations:^{
self.blurOverlayView.alpha = 0;
} completion:^(BOOL finished) {
}];
}];
}
-(void) dealloc {
[self removeAllTargets];
stillCamera = nil;
cropFilter = nil;
filter = nil;
blurFilter = nil;
staticPicture = nil;
self.blurOverlayView = nil;
self.focusView = nil;
}
- (void)viewWillDisappear:(BOOL)animated {
[stillCamera stopCameraCapture];
[super viewWillDisappear:animated];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:NO];
}
#pragma mark - UIImagePickerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage* outputImage = [info objectForKey:UIImagePickerControllerEditedImage];
if (outputImage == nil) {
outputImage = [info objectForKey:UIImagePickerControllerOriginalImage];
}
if (outputImage) {
staticPicture = [[GPUImagePicture alloc] initWithImage:outputImage smoothlyScaleOutput:YES];
staticPictureOriginalOrientation = outputImage.imageOrientation;
isStatic = YES;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
[popover dismissPopoverAnimated:YES];
}
else {
[self dismissViewControllerAnimated:YES completion:nil];
}
[self.cameraToggleButton setEnabled:NO];
[self.flashToggleButton setEnabled:NO];
[self prepareStaticFilter];
[self.photoCaptureButton setHidden:NO];
[self.photoCaptureButton setTitle:@"Done" forState:UIControlStateNormal];
[self.photoCaptureButton setImage:nil forState:UIControlStateNormal];
[self.photoCaptureButton setEnabled:YES];
if(![self.filtersToggleButton isSelected]){
[self showFilters];
}
}
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissViewControllerAnimated:YES completion:nil];
if (!isStatic) {
[self retakePhoto:nil];
}
}
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 60000
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
- (BOOL)prefersStatusBarHidden {
return YES;
}
#endif
@end