forked from sumanthk2006/Camera-Filters
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageFilter.m
1699 lines (1513 loc) · 79.2 KB
/
ImageFilter.m
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
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// ImageFilter.m
// Camera-Filters
//
// Created by A1Brains Infotech on 11/07/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "ImageFilter.h"
@interface ImageFilter ()
@end
@implementation ImageFilter
@synthesize imageView = _imageView;
@synthesize glImageView;
@synthesize tileController;
@synthesize filterSettingsSlider = _filterSettingsSlider;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
-(void)imageFilter:(UIImage*)image{
_imageView = image;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
glImageView = [[GPUImageView alloc]initWithFrame:self.view.frame];
[self.view addSubview:glImageView];
[self addButtonsToView];
// [self setUpMenu];
[self setupDisplayFiltering:GPUIMAGE_SEPIA];
// UITapGestureRecognizer *doubleTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
// doubleTapRecognizer.numberOfTapsRequired = 2;
// doubleTapRecognizer.delegate = self;
// [glImageView addGestureRecognizer:doubleTapRecognizer];
//
// UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
// tapRecognizer.delegate = self;
// [glImageView addGestureRecognizer:tapRecognizer];
}
-(void)setUpMenu{
UIImage *storyMenuItemImage = [UIImage imageNamed:@"bg-menuitem.png"];
UIImage *storyMenuItemImagePressed = [UIImage imageNamed:@"bg-menuitem-highlighted.png"];
UIImage *starImage = [UIImage imageNamed:@"icon-star.png"];
AwesomeMenuItem *starMenuItem1 = [[AwesomeMenuItem alloc] initWithImage:storyMenuItemImage
highlightedImage:storyMenuItemImagePressed
ContentImage:starImage
highlightedContentImage:nil];
AwesomeMenuItem *starMenuItem2 = [[AwesomeMenuItem alloc] initWithImage:storyMenuItemImage
highlightedImage:storyMenuItemImagePressed
ContentImage:starImage
highlightedContentImage:nil];
AwesomeMenuItem *starMenuItem3 = [[AwesomeMenuItem alloc] initWithImage:storyMenuItemImage
highlightedImage:storyMenuItemImagePressed
ContentImage:starImage
highlightedContentImage:nil];
AwesomeMenuItem *starMenuItem4 = [[AwesomeMenuItem alloc] initWithImage:storyMenuItemImage
highlightedImage:storyMenuItemImagePressed
ContentImage:starImage
highlightedContentImage:nil];
AwesomeMenuItem *starMenuItem5 = [[AwesomeMenuItem alloc] initWithImage:storyMenuItemImage
highlightedImage:storyMenuItemImagePressed
ContentImage:starImage
highlightedContentImage:nil];
AwesomeMenuItem *starMenuItem6 = [[AwesomeMenuItem alloc] initWithImage:storyMenuItemImage
highlightedImage:storyMenuItemImagePressed
ContentImage:starImage
highlightedContentImage:nil];
AwesomeMenuItem *starMenuItem7 = [[AwesomeMenuItem alloc] initWithImage:storyMenuItemImage
highlightedImage:storyMenuItemImagePressed
ContentImage:starImage
highlightedContentImage:nil];
AwesomeMenuItem *starMenuItem8 = [[AwesomeMenuItem alloc] initWithImage:storyMenuItemImage
highlightedImage:storyMenuItemImagePressed
ContentImage:starImage
highlightedContentImage:nil];
AwesomeMenuItem *starMenuItem9 = [[AwesomeMenuItem alloc] initWithImage:storyMenuItemImage
highlightedImage:storyMenuItemImagePressed
ContentImage:starImage
highlightedContentImage:nil];
NSArray *menus = [NSArray arrayWithObjects:starMenuItem1, starMenuItem2, starMenuItem3, starMenuItem4, starMenuItem5, starMenuItem6, starMenuItem7,starMenuItem8,starMenuItem9, nil];
AwesomeMenu *menu = [[AwesomeMenu alloc] initWithFrame:self.glImageView.frame menus:menus];
menu.delegate = self;
[self.glImageView addSubview:menu];
}
- (void)AwesomeMenu:(AwesomeMenu *)menu didSelectIndex:(NSInteger)idx{
NSLog(@"Select the index : %d",idx);
filter = nil;
[sourcePicture removeTarget:filter];
sourcePicture = nil;
switch (idx) {
case 0:
[self setupDisplayFiltering:GPUIMAGE_SKETCH];
break;
case 1:
[self setupDisplayFiltering:GPUIMAGE_POLARPIXELLATE];
break;
case 2:
[self setupDisplayFiltering:GPUIMAGE_SMOOTHTOON];
break;
case 3:
[self setupDisplayFiltering:GPUIMAGE_BULGE];
break;
case 4:
[self setupDisplayFiltering:GPUIMAGE_SWIRL];
break;
case 5:
[self setupDisplayFiltering:GPUIMAGE_STRETCH];
break;
case 6:
[self setupDisplayFiltering:GPUIMAGE_EROSION];
break;
case 7:
[self setupDisplayFiltering:GPUIMAGE_GAUSSIAN_SELECTIVE];
break;
case 8:
[self setupDisplayFiltering:GPUIMAGE_NOBLECORNERDETECTION];
break;
default:
break;
}
}
- (void)setupDisplayFiltering:(GPUImageShowcaseFilterType)value;
{
@autoreleasepool {
sourcePicture = [[GPUImagePicture alloc] initWithImage:[self scaleAndRotateImage:_imageView] smoothlyScaleOutput:YES];
selectFilterValue = value;
glImageView = (GPUImageView *)glImageView;
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] init];
BOOL needsSecondImage = NO;
switch (value)
{
case GPUIMAGE_SEPIA:
{
self.title = @"Sepia Tone";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setValue:1.0];
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:1.0];
filter = [[GPUImageSepiaFilter alloc] init];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_PIXELLATE:
{
self.title = @"Pixellate";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setValue:0.05];
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:0.3];
filter = [[GPUImagePixellateFilter alloc] init];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_POLARPIXELLATE:
{
self.title = @"Polar Pixellate";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setValue:0.05];
[self.filterSettingsSlider setMinimumValue:-0.1];
[self.filterSettingsSlider setMaximumValue:0.1];
filter = [[GPUImagePolarPixellateFilter alloc] init];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_CROSSHATCH:
{
self.title = @"Crosshatch";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setValue:0.03];
[self.filterSettingsSlider setMinimumValue:0.01];
[self.filterSettingsSlider setMaximumValue:0.06];
filter = [[GPUImageCrosshatchFilter alloc] init];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_COLORINVERT:
{
self.title = @"Color Invert";
self.filterSettingsSlider.hidden = YES;
filter = [[GPUImageColorInvertFilter alloc] init];
}; break;
case GPUIMAGE_GRAYSCALE:
{
self.title = @"Grayscale";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:0.0];
filter = [[GPUImageGrayscaleFilter alloc] init];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_MONOCHROME:
{
self.title = @"Monochrome";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setValue:1.0];
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:1.0];
filter = [[GPUImageMonochromeFilter alloc] init];
[(GPUImageMonochromeFilter *)filter setColor:(GPUVector4){0.0f, 0.0f, 1.0f, 1.f}];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_SATURATION:
{
self.title = @"Saturation";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setValue:1.0];
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:2.0];
filter = [[GPUImageSaturationFilter alloc] init];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_CONTRAST:
{
self.title = @"Contrast";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:4.0];
[self.filterSettingsSlider setValue:1.0];
filter = [[GPUImageContrastFilter alloc] init];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_BRIGHTNESS:
{
self.title = @"Brightness";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:-1.0];
[self.filterSettingsSlider setMaximumValue:1.0];
[self.filterSettingsSlider setValue:0.0];
filter = [[GPUImageBrightnessFilter alloc] init];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_RGB:
{
self.title = @"RGB";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:2.0];
[self.filterSettingsSlider setValue:1.0];
filter = [[GPUImageRGBFilter alloc] init];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_EXPOSURE:
{
self.title = @"Exposure";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:-4.0];
[self.filterSettingsSlider setMaximumValue:4.0];
[self.filterSettingsSlider setValue:0.0];
filter = [[GPUImageExposureFilter alloc] init];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_SHARPEN:
{
self.title = @"Sharpen";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:-1.0];
[self.filterSettingsSlider setMaximumValue:4.0];
[self.filterSettingsSlider setValue:0.0];
filter = [[GPUImageSharpenFilter alloc] init];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_UNSHARPMASK:
{
self.title = @"Unsharp Mask";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:5.0];
[self.filterSettingsSlider setValue:1.0];
filter = [[GPUImageUnsharpMaskFilter alloc] init];
// [(GPUImageUnsharpMaskFilter *)filter setIntensity:3.0];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_GAMMA:
{
self.title = @"Gamma";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:3.0];
[self.filterSettingsSlider setValue:1.0];
filter = [[GPUImageGammaFilter alloc] init];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_TONECURVE:
{
self.title = @"Tone curve";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:1.0];
[self.filterSettingsSlider setValue:0.5];
filter = [[GPUImageToneCurveFilter alloc] init];
[(GPUImageToneCurveFilter *)filter setBlueControlPoints:[NSArray arrayWithObjects:[NSValue valueWithCGPoint:CGPointMake(0.0, 0.0)], [NSValue valueWithCGPoint:CGPointMake(0.5, 0.5)], [NSValue valueWithCGPoint:CGPointMake(1.0, 0.75)], nil]];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_HAZE:
{
self.title = @"Haze / UV";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:-0.2];
[self.filterSettingsSlider setMaximumValue:0.2];
[self.filterSettingsSlider setValue:0.2];
filter = [[GPUImageHazeFilter alloc] init];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_HISTOGRAM:
{
self.title = @"Histogram";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:4.0];
[self.filterSettingsSlider setMaximumValue:32.0];
[self.filterSettingsSlider setValue:16.0];
filter = [[GPUImageHistogramFilter alloc] initWithHistogramType:kGPUImageHistogramRGB];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_THRESHOLD:
{
self.title = @"Luminance Threshold";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:1.0];
[self.filterSettingsSlider setValue:0.5];
filter = [[GPUImageLuminanceThresholdFilter alloc] init];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_ADAPTIVETHRESHOLD:
{
self.title = @"Adaptive Threshold";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:1.0];
[self.filterSettingsSlider setMaximumValue:20.0];
[self.filterSettingsSlider setValue:1.0];
filter = [[GPUImageAdaptiveThresholdFilter alloc] init];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_CROP:
{
self.title = @"Crop";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.2];
[self.filterSettingsSlider setMaximumValue:1.0];
[self.filterSettingsSlider setValue:0.5];
filter = [[GPUImageCropFilter alloc] initWithCropRegion:CGRectMake(0.0, 0.0, 1.0, 0.25)];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_MASK:
{
self.title = @"Mask";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:0.0];
needsSecondImage = YES;
filter = [[GPUImageMaskFilter alloc] init];
[(GPUImageFilter*)filter setBackgroundColorRed:0.0 green:1.0 blue:0.0 alpha:1.0];
}; break;
case GPUIMAGE_TRANSFORM:
{
self.title = @"Transform (2-D)";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:6.28];
[self.filterSettingsSlider setValue:2.0];
filter = [[GPUImageTransformFilter alloc] init];
[(GPUImageTransformFilter *)filter setAffineTransform:CGAffineTransformMakeRotation(2.0)];
// [(GPUImageTransformFilter *)filter setIgnoreAspectRatio:YES];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_TRANSFORM3D:
{
self.title = @"Transform (3-D)";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:6.28];
[self.filterSettingsSlider setValue:0.75];
filter = [[GPUImageTransformFilter alloc] init];
CATransform3D perspectiveTransform = CATransform3DIdentity;
perspectiveTransform.m34 = 0.4;
perspectiveTransform.m33 = 0.4;
perspectiveTransform = CATransform3DScale(perspectiveTransform, 0.75, 0.75, 0.75);
perspectiveTransform = CATransform3DRotate(perspectiveTransform, 0.75, 0.0, 1.0, 0.0);
[(GPUImageTransformFilter *)filter setTransform3D:perspectiveTransform];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_SOBELEDGEDETECTION:
{
self.title = @"Sobel Edge Detection";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:0.0];
filter = [[GPUImageSobelEdgeDetectionFilter alloc] init];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_XYGRADIENT:
{
self.title = @"XY Derivative";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:0.0];
filter = [[GPUImageXYDerivativeFilter alloc] init];
}; break;
case GPUIMAGE_HARRISCORNERDETECTION:
{
self.title = @"Harris Corner Detection";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.01];
[self.filterSettingsSlider setMaximumValue:0.70];
[self.filterSettingsSlider setValue:0.20];
filter = [[GPUImageHarrisCornerDetectionFilter alloc] init];
[(GPUImageHarrisCornerDetectionFilter *)filter setThreshold:0.20];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_NOBLECORNERDETECTION:
{
self.title = @"Noble Corner Detection";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.01];
[self.filterSettingsSlider setMaximumValue:0.70];
[self.filterSettingsSlider setValue:0.20];
filter = [[GPUImageNobleCornerDetectionFilter alloc] init];
[(GPUImageNobleCornerDetectionFilter *)filter setThreshold:0.20];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_SHITOMASIFEATUREDETECTION:
{
self.title = @"Shi-Tomasi Feature Detection";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.01];
[self.filterSettingsSlider setMaximumValue:0.70];
[self.filterSettingsSlider setValue:0.20];
filter = [[GPUImageShiTomasiFeatureDetectionFilter alloc] init];
[(GPUImageShiTomasiFeatureDetectionFilter *)filter setThreshold:0.20];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_PREWITTEDGEDETECTION:
{
self.title = @"Prewitt Edge Detection";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:0.0];
filter = [[GPUImagePrewittEdgeDetectionFilter alloc] init];
}; break;
case GPUIMAGE_CANNYEDGEDETECTION:
{
self.title = @"Canny Edge Detection";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:1.0];
[self.filterSettingsSlider setValue:1.0];
// [self.filterSettingsSlider setMinimumValue:0.0];
// [self.filterSettingsSlider setMaximumValue:0.5];
// [self.filterSettingsSlider setValue:0.1];
filter = [[GPUImageCannyEdgeDetectionFilter alloc] init];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_BUFFER:
{
self.title = @"Image Buffer";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:0.0];
filter = [[GPUImageBuffer alloc] init];
}; break;
case GPUIMAGE_SKETCH:
{
self.title = @"Sketch";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:0.0];
filter = [[GPUImageSketchFilter alloc] init];
}; break;
case GPUIMAGE_TOON:
{
self.title = @"Toon";
self.filterSettingsSlider.hidden = YES;
filter = [[GPUImageToonFilter alloc] init];
}; break;
case GPUIMAGE_SMOOTHTOON:
{
self.title = @"Smooth Toon";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:1.0];
[self.filterSettingsSlider setValue:0.5];
filter = [[GPUImageSmoothToonFilter alloc] init];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_TILTSHIFT:
{
self.title = @"Tilt Shift";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.2];
[self.filterSettingsSlider setMaximumValue:0.8];
[self.filterSettingsSlider setValue:0.5];
filter = [[GPUImageTiltShiftFilter alloc] init];
[(GPUImageTiltShiftFilter *)filter setTopFocusLevel:0.4];
[(GPUImageTiltShiftFilter *)filter setBottomFocusLevel:0.6];
[(GPUImageTiltShiftFilter *)filter setFocusFallOffRate:0.2];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_CGA:
{
self.title = @"CGA Colorspace";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:0.0];
filter = [[GPUImageCGAColorspaceFilter alloc] init];
}; break;
case GPUIMAGE_CONVOLUTION:
{
self.title = @"3x3 Convolution";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:0.0];
filter = [[GPUImage3x3ConvolutionFilter alloc] init];
// [(GPUImage3x3ConvolutionFilter *)filter setConvolutionKernel:(GPUMatrix3x3){
// {-2.0f, -1.0f, 0.0f},
// {-1.0f, 1.0f, 1.0f},
// { 0.0f, 1.0f, 2.0f}
// }];
[(GPUImage3x3ConvolutionFilter *)filter setConvolutionKernel:(GPUMatrix3x3){
{-1.0f, 0.0f, 1.0f},
{-2.0f, 0.0f, 2.0f},
{-1.0f, 0.0f, 1.0f}
}];
// [(GPUImage3x3ConvolutionFilter *)filter setConvolutionKernel:(GPUMatrix3x3){
// {1.0f, 1.0f, 1.0f},
// {1.0f, -8.0f, 1.0f},
// {1.0f, 1.0f, 1.0f}
// }];
// [(GPUImage3x3ConvolutionFilter *)filter setConvolutionKernel:(GPUMatrix3x3){
// { 0.11f, 0.11f, 0.11f},
// { 0.11f, 0.11f, 0.11f},
// { 0.11f, 0.11f, 0.11f}
// }];
}; break;
case GPUIMAGE_EMBOSS:
{
self.title = @"Emboss";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:5.0];
[self.filterSettingsSlider setValue:1.0];
filter = [[GPUImageEmbossFilter alloc] init];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_POSTERIZE:
{
self.title = @"Posterize";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:1.0];
[self.filterSettingsSlider setMaximumValue:20.0];
[self.filterSettingsSlider setValue:10.0];
filter = [[GPUImagePosterizeFilter alloc] init];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_SWIRL:
{
self.title = @"Swirl";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:2.0];
[self.filterSettingsSlider setValue:1.0];
filter = [[GPUImageSwirlFilter alloc] init];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_BULGE:
{
self.title = @"Bulge";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:-1.0];
[self.filterSettingsSlider setMaximumValue:1.0];
[self.filterSettingsSlider setValue:0.5];
filter = [[GPUImageBulgeDistortionFilter alloc] init];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_SPHEREREFRACTION:
{
self.title = @"Sphere Refraction";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:1.0];
[self.filterSettingsSlider setValue:0.5];
filter = [[GPUImageSphereRefractionFilter alloc] init];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_PINCH:
{
self.title = @"Pinch";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:-2.0];
[self.filterSettingsSlider setMaximumValue:2.0];
[self.filterSettingsSlider setValue:0.5];
filter = [[GPUImagePinchDistortionFilter alloc] init];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_STRETCH:
{
self.title = @"Stretch";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:0.0];
filter = [[GPUImageStretchDistortionFilter alloc] init];
}; break;
case GPUIMAGE_DILATION:
{
self.title = @"Dilation";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:0.0];
filter = [[GPUImageRGBDilationFilter alloc] initWithRadius:4];
}; break;
case GPUIMAGE_EROSION:
{
self.title = @"Erosion";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:0.0];
filter = [[GPUImageRGBErosionFilter alloc] initWithRadius:4];
}; break;
case GPUIMAGE_OPENING:
{
self.title = @"Opening";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:0.0];
filter = [[GPUImageRGBOpeningFilter alloc] initWithRadius:4];
}; break;
case GPUIMAGE_CLOSING:
{
self.title = @"Closing";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:0.0];
filter = [[GPUImageRGBClosingFilter alloc] initWithRadius:4];
}; break;
case GPUIMAGE_PERLINNOISE:
{
self.title = @"Perlin Noise";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:1.0];
[self.filterSettingsSlider setMaximumValue:30.0];
[self.filterSettingsSlider setValue:8.0];
filter = [[GPUImagePerlinNoiseFilter alloc] init];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_VORONI:
{
self.title = @"Voroni";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:0.0];
GPUImageJFAVoroniFilter *jfa = [[GPUImageJFAVoroniFilter alloc] init];
[jfa setSizeInPixels:CGSizeMake(1024.0, 1024.0)];
sourcePicture = [[GPUImagePicture alloc] initWithImage:[UIImage imageNamed:@"voroni_points2.png"]];
[sourcePicture addTarget:jfa];
filter = [[GPUImageVoroniConsumerFilter alloc] init];
[jfa setSizeInPixels:CGSizeMake(1024.0, 1024.0)];
[(GPUImageVoroniConsumerFilter *)filter setSizeInPixels:CGSizeMake(1024.0, 1024.0)];
[sourcePicture addTarget:filter];
[jfa addTarget:filter];
[sourcePicture processImage];
}; break;
case GPUIMAGE_MOSAIC:
{
self.title = @"Mosaic";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.002];
[self.filterSettingsSlider setMaximumValue:0.05];
[self.filterSettingsSlider setValue:0.025];
filter = [[GPUImageMosaicFilter alloc] init];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
[(GPUImageMosaicFilter *)filter setTileSet:@"squares.png"];
[(GPUImageMosaicFilter *)filter setColorOn:NO];
//[(GPUImageMosaicFilter *)filter setTileSet:@"dotletterstiles.png"];
//[(GPUImageMosaicFilter *)filter setTileSet:@"curvies.png"];
[filter setInputRotation:kGPUImageRotateRight atIndex:0];
}; break;
case GPUIMAGE_CHROMAKEY:
{
self.title = @"Chroma Key (Green)";
self.filterSettingsSlider.hidden = YES;
needsSecondImage = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:1.0];
[self.filterSettingsSlider setValue:0.4];
filter = [[GPUImageChromaKeyBlendFilter alloc] init];
[(GPUImageChromaKeyBlendFilter *)filter setColorToReplaceRed:0.0 green:1.0 blue:0.0];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_MULTIPLY:
{
self.title = @"Multiply Blend";
self.filterSettingsSlider.hidden = YES;
needsSecondImage = YES;
filter = [[GPUImageMultiplyBlendFilter alloc] init];
}; break;
case GPUIMAGE_OVERLAY:
{
self.title = @"Overlay Blend";
self.filterSettingsSlider.hidden = YES;
needsSecondImage = YES;
filter = [[GPUImageOverlayBlendFilter alloc] init];
}; break;
case GPUIMAGE_LIGHTEN:
{
self.title = @"Lighten Blend";
self.filterSettingsSlider.hidden = YES;
needsSecondImage = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:0.0];
filter = [[GPUImageLightenBlendFilter alloc] init];
}; break;
case GPUIMAGE_DARKEN:
{
self.title = @"Darken Blend";
self.filterSettingsSlider.hidden = YES;
needsSecondImage = YES;
filter = [[GPUImageDarkenBlendFilter alloc] init];
}; break;
case GPUIMAGE_DISSOLVE:
{
self.title = @"Dissolve Blend";
self.filterSettingsSlider.hidden = YES;
needsSecondImage = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:1.0];
[self.filterSettingsSlider setValue:0.5];
filter = [[GPUImageDissolveBlendFilter alloc] init];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_SCREENBLEND:
{
self.title = @"Screen Blend";
self.filterSettingsSlider.hidden = YES;
needsSecondImage = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:0.0];
filter = [[GPUImageScreenBlendFilter alloc] init];
}; break;
case GPUIMAGE_COLORBURN:
{
self.title = @"Color Burn Blend";
self.filterSettingsSlider.hidden = YES;
needsSecondImage = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:0.0];
filter = [[GPUImageColorBurnBlendFilter alloc] init];
}; break;
case GPUIMAGE_COLORDODGE:
{
self.title = @"Color Dodge Blend";
self.filterSettingsSlider.hidden = YES;
needsSecondImage = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:0.0];
filter = [[GPUImageColorDodgeBlendFilter alloc] init];
}; break;
case GPUIMAGE_EXCLUSIONBLEND:
{
self.title = @"Exclusion Blend";
self.filterSettingsSlider.hidden = YES;
needsSecondImage = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:0.0];
filter = [[GPUImageExclusionBlendFilter alloc] init];
}; break;
case GPUIMAGE_DIFFERENCEBLEND:
{
self.title = @"Difference Blend";
self.filterSettingsSlider.hidden = YES;
needsSecondImage = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:0.0];
filter = [[GPUImageDifferenceBlendFilter alloc] init];
}; break;
case GPUIMAGE_SUBTRACTBLEND:
{
self.title = @"Subtract Blend";
self.filterSettingsSlider.hidden = YES;
needsSecondImage = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:0.0];
filter = [[GPUImageSubtractBlendFilter alloc] init];
}; break;
case GPUIMAGE_HARDLIGHTBLEND:
{
self.title = @"Hard Light Blend";
self.filterSettingsSlider.hidden = YES;
needsSecondImage = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:0.0];
filter = [[GPUImageHardLightBlendFilter alloc] init];
}; break;
case GPUIMAGE_SOFTLIGHTBLEND:
{
self.title = @"Soft Light Blend";
self.filterSettingsSlider.hidden = YES;
needsSecondImage = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:0.0];
filter = [[GPUImageSoftLightBlendFilter alloc] init];
}; break;
case GPUIMAGE_CUSTOM:
{
self.title = @"Custom";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:0.0];
filter = [[GPUImageFilter alloc] initWithFragmentShaderFromFile:@"CustomFilter"];
}; break;
case GPUIMAGE_KUWAHARA:
{
self.title = @"Kuwahara";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:3.0];
[self.filterSettingsSlider setMaximumValue:8.0];
[self.filterSettingsSlider setValue:3.0];
filter = [[GPUImageKuwaharaFilter alloc] init];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_VIGNETTE:
{
self.title = @"Vignette";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.5];
[self.filterSettingsSlider setMaximumValue:0.9];
[self.filterSettingsSlider setValue:0.75];
filter = [[GPUImageVignetteFilter alloc] init];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_GAUSSIAN:
{
self.title = @"Gaussian Blur";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:10.0];
[self.filterSettingsSlider setValue:1.0];
filter = [[GPUImageGaussianBlurFilter alloc] init];
[pinch addTarget:self action:@selector(handlePinch:)];
[glImageView addGestureRecognizer:pinch];
}; break;
case GPUIMAGE_FASTBLUR:
{
self.title = @"Fast Blur";
self.filterSettingsSlider.hidden = YES;
[self.filterSettingsSlider setMinimumValue:1.0];