Skip to content

Commit 0e3c56d

Browse files
committed
Add filters
2 parents 61cd700 + 6a6438b commit 0e3c56d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+590
-62
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ DerivedData
1919

2020
#CocoaPods
2121
Pods
22+
Podfile.lock

DBCamera.podspec

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
Pod::Spec.new do |s|
22
s.name = 'DBCamera'
3-
s.version = '2.2.2'
3+
s.version = '2.3'
44
s.license = 'MIT'
55
s.summary = 'DBCamera is a simple custom camera with AVFoundation'
66
s.homepage = 'https://github.com/danielebogo/DBCamera'
77
s.author = { 'Daniele Bogo' => '[email protected]' }
8-
s.source = { :git => 'https://github.com/danielebogo/DBCamera.git', :tag => '2.2.2' }
8+
s.source = { :git => 'https://github.com/danielebogo/DBCamera.git', :tag => '2.3' }
99
s.platform = :ios, '6.0'
1010
s.requires_arc = true
1111

12-
s.source_files = 'DBCamera/Categories/*.{h,m}', 'DBCamera/Controllers/*.{h,m}', 'DBCamera/Headers/*.{h,m}', 'DBCamera/Managers/*.{h,m}', 'DBCamera/Objects/*.{h,m}', 'DBCamera/Views/*.{h,m}'
13-
s.resource = ['DBCamera/Resources/*.{xib,xcassets}', 'DBCamera/Localizations/**']
14-
s.framework = 'AVFoundation', 'CoreMedia'
12+
s.source_files = 'DBCamera/Categories/*.{h,m}', 'DBCamera/Controllers/*.{h,m}', 'DBCamera/Headers/*.{h,m}', 'DBCamera/Managers/*.{h,m}', 'DBCamera/Objects/*.{h,m}', 'DBCamera/Views/*.{h,m}', 'DBCamera/Filters/*.{h,m}'
13+
s.resource = ['DBCamera/Resources/*.{xib,xcassets}', 'DBCamera/Localizations/**', 'DBCamera/Filters/*.{acv}']
14+
s.framework = 'AVFoundation', 'CoreMedia', 'QuartzCore'
15+
s.dependency 'GPUImage', '~> 0.1'
1516
end

DBCamera/Controllers/DBCameraBaseCropViewController.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ - (BOOL) handleGestureState:(UIGestureRecognizerState)state
260260
}
261261

262262

263-
- (void)checkBoundsWithTransform:(CGAffineTransform)transform
263+
- (void) checkBoundsWithTransform:(CGAffineTransform)transform
264264
{
265265
CGRect r1 = [self boundingBoxForRect:self.cropRect rotatedByRadians:[self imageRotation]];
266266
Rectangle r2 = [self applyTransform:transform toRect:self.initialImageFrame];

DBCamera/Controllers/DBCameraLibraryViewController.m

+2-9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#import "UIImage+Crop.h"
1616
#import "UIImage+TintColor.h"
1717
#import "DBCameraMacros.h"
18+
#import "DBCameraLoadingView.h"
1819

1920
#ifndef DBCameraLocalizedStrings
2021
#define DBCameraLocalizedStrings(key) \
@@ -229,16 +230,8 @@ - (void) close
229230
- (UIView *) loading
230231
{
231232
if( !_loading ) {
232-
_loading = [[UIView alloc] initWithFrame:(CGRect){ 0, 0, 100, 100 }];
233-
[_loading.layer setCornerRadius:10];
234-
[_loading setBackgroundColor:RGBColor(0x000000, .7)];
233+
_loading = [[DBCameraLoadingView alloc] initWithFrame:(CGRect){ 0, 0, 100, 100 }];
235234
[_loading setCenter:self.view.center];
236-
[_loading setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin];
237-
238-
UIActivityIndicatorView *activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
239-
[activity setCenter:(CGPoint){ CGRectGetMidX(_loading.bounds), CGRectGetMidY(_loading.bounds) }];
240-
[_loading addSubview:activity];
241-
[activity startAnimating];
242235
}
243236

244237
return _loading;

DBCamera/Controllers/DBCameraSegueViewController.h

+12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#import "DBCameraDelegate.h"
1111
#import "UIViewController+UIViewController_FullScreen.h"
1212

13+
@class DBCameraFiltersView;
14+
1315
/**
1416
* DBCameraSegueViewController
1517
*/
@@ -29,6 +31,16 @@
2931
*/
3032
@property (nonatomic, assign) BOOL cropMode;
3133

34+
/**
35+
* Filter collectionView
36+
*/
37+
@property (nonatomic, strong) DBCameraFiltersView *filtersView;
38+
39+
/**
40+
* Filter to be applied to the image
41+
*/
42+
@property (nonatomic, readonly) NSIndexPath *selectedFilterIndex;
43+
3244
/**
3345
* The init method with the captured image and thumb
3446
*

DBCamera/Controllers/DBCameraSegueViewController.m

+95-10
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,35 @@
99
#import "DBCameraSegueViewController.h"
1010
#import "DBCameraBaseCropViewController+Private.h"
1111
#import "DBCameraCropView.h"
12+
#import "DBCameraFiltersView.h"
13+
#import "DBCameraFilterCell.h"
14+
#import "DBCameraLoadingView.h"
1215
#import "UIImage+TintColor.h"
1316

17+
#import <GPUImage/GPUImage.h>
18+
19+
#define kFilterCellIdentifier @"filterCell"
20+
1421
#ifndef DBCameraLocalizedStrings
1522
#define DBCameraLocalizedStrings(key) \
1623
NSLocalizedStringFromTable(key, @"DBCamera", nil)
1724
#endif
1825

1926
#define buttonMargin 20.0f
2027

21-
@interface DBCameraSegueViewController () <UIActionSheetDelegate> {
28+
static const CGSize kFilterCellSize = { 75, 90 };
29+
30+
@interface DBCameraSegueViewController () <UIActionSheetDelegate, UICollectionViewDelegate, UICollectionViewDataSource> {
2231
DBCameraCropView *_cropView;
23-
NSArray *_cropArray;
32+
33+
NSArray *_cropArray, *_filtersList;
34+
NSDictionary *_filterMapping;
2435
CGRect _pFrame, _lFrame;
2536
}
2637

2738
@property (nonatomic, strong) UIView *navigationBar, *bottomBar;
2839
@property (nonatomic, strong) UIButton *useButton, *retakeButton, *cropButton;
40+
@property (nonatomic, strong) DBCameraLoadingView *loadingView;
2941
@end
3042

3143
@implementation DBCameraSegueViewController
@@ -41,6 +53,13 @@ - (id) initWithImage:(UIImage *)image thumb:(UIImage *)thumb
4153
if (self) {
4254
// Custom initialization
4355
_cropArray = @[ @320, @213, @240, @192, @180 ];
56+
_filtersList = @[ @"normal", @"1977", @"amaro", @"grey", @"hudson", @"mayfair", @"nashville", @"valencia" ];
57+
_filterMapping = @{ @0:[[GPUImageFilter alloc] init], @1:[[GPUImageToneCurveFilter alloc] initWithACV:@"1977"],
58+
@2:[[GPUImageToneCurveFilter alloc] initWithACV:@"amaro"], @3:[[GPUImageGrayscaleFilter alloc] init],
59+
@4:[[GPUImageToneCurveFilter alloc] initWithACV:@"Hudson"], @5:[[GPUImageToneCurveFilter alloc] initWithACV:@"mayfair"],
60+
@6:[[GPUImageToneCurveFilter alloc] initWithACV:@"Nashville"], @7:[[GPUImageToneCurveFilter alloc] initWithACV:@"Valencia"] };
61+
62+
_selectedFilterIndex = 0;
4463

4564
[self setSourceImage:image];
4665
[self setPreviewImage:thumb];
@@ -59,16 +78,18 @@ - (void)viewDidLoad
5978

6079
[self.view setUserInteractionEnabled:YES];
6180
[self.view setBackgroundColor:[UIColor blackColor]];
62-
[self.view addSubview:self.navigationBar];
63-
[self.view addSubview:self.bottomBar];
64-
[self.view setClipsToBounds:YES];
6581

6682
CGFloat cropX = ( CGRectGetWidth( self.frameView.frame) - 320 ) * .5;
6783
_pFrame = (CGRect){ cropX, ( CGRectGetHeight( self.frameView.frame) - 360 ) * .5, 320, 320 };
6884
_lFrame = (CGRect){ cropX, ( CGRectGetHeight( self.frameView.frame) - 240) * .5, 320, 240 };
6985

7086
[self setCropRect:self.previewImage.size.width > self.previewImage.size.height ? _lFrame : _pFrame];
7187

88+
[self.view addSubview:self.filtersView];
89+
[self.view addSubview:self.navigationBar];
90+
[self.view addSubview:self.bottomBar];
91+
[self.view setClipsToBounds:YES];
92+
7293
if( self.cameraSegueConfigureBlock )
7394
self.cameraSegueConfigureBlock(self);
7495
}
@@ -109,9 +130,10 @@ - (void) openActionsheet:(UIButton *)button
109130

110131
- (void) createInterface
111132
{
112-
CGFloat viewHeight = CGRectGetHeight([[UIScreen mainScreen] bounds]) - 64;
133+
CGFloat viewHeight = CGRectGetHeight([[UIScreen mainScreen] bounds]) - 64 - 50;
113134
_cropView = [[DBCameraCropView alloc] initWithFrame:(CGRect){ 0, 64, 320, viewHeight }];
114135
[_cropView setHidden:YES];
136+
115137
[self setFrameView:_cropView];
116138
}
117139

@@ -127,8 +149,10 @@ - (void) saveImage
127149
if ( [_delegate respondsToSelector:@selector(camera:didFinishWithImage:withMetadata:)] ) {
128150
if ( _cropMode )
129151
[self cropImage];
130-
else
131-
[_delegate camera:self didFinishWithImage:self.sourceImage withMetadata:self.capturedImageMetadata];
152+
else{
153+
UIImage *transform = [_filterMapping[@(_selectedFilterIndex.row)] imageByFilteringImage:self.sourceImage];
154+
[_delegate camera:self didFinishWithImage:transform withMetadata:self.capturedImageMetadata];
155+
}
132156
}
133157
}
134158

@@ -145,6 +169,7 @@ - (void) cropImage
145169
dispatch_async(dispatch_get_main_queue(), ^{
146170
UIImage *transform = [UIImage imageWithCGImage:resultRef scale:1.0 orientation:UIImageOrientationUp];
147171
CGImageRelease(resultRef);
172+
transform = [_filterMapping[@(_selectedFilterIndex.row)] imageByFilteringImage:transform];
148173
[_delegate camera:self didFinishWithImage:transform withMetadata:self.capturedImageMetadata];
149174
});
150175
});
@@ -155,6 +180,29 @@ - (void) setCropMode:(BOOL)cropMode
155180
_cropMode = cropMode;
156181
[self.frameView setHidden:!_cropMode];
157182
[self.bottomBar setHidden:!_cropMode];
183+
[self.filtersView setHidden:_cropMode];
184+
}
185+
186+
- (DBCameraFiltersView *) filtersView
187+
{
188+
if ( !_filtersView ) {
189+
_filtersView = [[DBCameraFiltersView alloc] initWithFrame:(CGRect){ 0, CGRectGetHeight(self.view.frame)-kFilterCellSize.height, CGRectGetWidth(self.view.frame), kFilterCellSize.height} collectionViewLayout:[DBCameraFiltersView filterLayout]];
190+
[_filtersView setDelegate:self];
191+
[_filtersView setDataSource:self];
192+
[_filtersView registerClass:[DBCameraFilterCell class] forCellWithReuseIdentifier:kFilterCellIdentifier];
193+
}
194+
195+
return _filtersView;
196+
}
197+
198+
- (DBCameraLoadingView *) loadingView
199+
{
200+
if ( !_loadingView ) {
201+
_loadingView = [[DBCameraLoadingView alloc] initWithFrame:(CGRect){ 0, 0, 100, 100 }];
202+
[_loadingView setCenter:self.view.center];
203+
}
204+
205+
return _loadingView;
158206
}
159207

160208
- (UIView *) navigationBar
@@ -194,7 +242,7 @@ - (UIButton *) useButton
194242
{
195243
if ( !_useButton ) {
196244
_useButton = [self baseButton];
197-
[_useButton setTitle:DBCameraLocalizedStrings(@"button.use") forState:UIControlStateNormal];
245+
[_useButton setTitle:[DBCameraLocalizedStrings(@"button.use") uppercaseString] forState:UIControlStateNormal];
198246
[_useButton.titleLabel sizeToFit];
199247
[_useButton sizeToFit];
200248
[_useButton setFrame:(CGRect){ CGRectGetWidth(self.view.frame) - (CGRectGetWidth(_useButton.frame) + buttonMargin), 0, CGRectGetWidth(_useButton.frame) + buttonMargin, 60 }];
@@ -208,7 +256,7 @@ - (UIButton *) retakeButton
208256
{
209257
if ( !_retakeButton ) {
210258
_retakeButton = [self baseButton];
211-
[_retakeButton setTitle:DBCameraLocalizedStrings(@"button.retake") forState:UIControlStateNormal];
259+
[_retakeButton setTitle:[DBCameraLocalizedStrings(@"button.retake") uppercaseString] forState:UIControlStateNormal];
212260
[_retakeButton.titleLabel sizeToFit];
213261
[_retakeButton sizeToFit];
214262
[_retakeButton setFrame:(CGRect){ 0, 0, CGRectGetWidth(_retakeButton.frame) + buttonMargin, 60 }];
@@ -237,6 +285,7 @@ - (UIButton *) baseButton
237285
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
238286
[button setBackgroundColor:[UIColor clearColor]];
239287
[button setTitleColor:self.tintColor forState:UIControlStateNormal];
288+
button.titleLabel.font = [UIFont systemFontOfSize:12];
240289

241290
return button;
242291
}
@@ -246,6 +295,42 @@ - (BOOL) prefersStatusBarHidden
246295
return YES;
247296
}
248297

298+
#pragma mark - UICollectionViewDataSource
299+
300+
- (NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
301+
{
302+
return _filtersList.count;
303+
}
304+
305+
- (UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
306+
{
307+
DBCameraFilterCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kFilterCellIdentifier forIndexPath:indexPath];
308+
[cell.imageView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@Filter", _filtersList[indexPath.row]]]];
309+
[cell.label setText:[_filtersList[indexPath.row] uppercaseString]];
310+
[cell.imageView.layer setBorderWidth:(self.selectedFilterIndex.row == indexPath.row) ? 1.0 : 0.0];
311+
312+
return cell;
313+
}
314+
315+
- (CGSize) collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
316+
{
317+
return kFilterCellSize;
318+
}
319+
320+
#pragma mark - UICollectionViewDelegate
321+
322+
- (void) collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
323+
{
324+
[self.view addSubview:self.loadingView];
325+
326+
_selectedFilterIndex = indexPath;
327+
[self.filtersView reloadData];
328+
329+
UIImage *filteredImage = [_filterMapping[@(indexPath.row)] imageByFilteringImage:self.sourceImage];
330+
[self.loadingView removeFromSuperview];
331+
[self.imageView setImage:filteredImage];
332+
}
333+
249334
#pragma mark - UIActionSheetDelegate
250335

251336
- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex

DBCamera/Controllers/DBCameraViewController.m

+2-4
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,8 @@ - (BOOL) prefersStatusBarHidden
167167

168168
- (void) dismissCamera
169169
{
170-
if ( _delegate && [_delegate respondsToSelector:@selector(dismissCamera)] )
171-
[_delegate dismissCamera];
172-
else
173-
[self dismissViewControllerAnimated:YES completion:nil];
170+
if ( _delegate && [_delegate respondsToSelector:@selector(dismissCamera:)] )
171+
[_delegate dismissCamera:self];
174172
}
175173

176174
- (DBCameraView *) cameraView

DBCamera/Filters/1977.acv

190 Bytes
Binary file not shown.

DBCamera/Filters/Hudson.acv

186 Bytes
Binary file not shown.

DBCamera/Filters/Nashville.acv

198 Bytes
Binary file not shown.

DBCamera/Filters/Valencia.acv

186 Bytes
Binary file not shown.

DBCamera/Filters/amaro.acv

186 Bytes
Binary file not shown.

DBCamera/Filters/mayfair.acv

186 Bytes
Binary file not shown.

DBCamera/Headers/DBCameraDelegate.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
/**
106106
* Tells the delegate when the camera must be dismissed
107107
*/
108-
- (void) dismissCamera;
108+
- (void) dismissCamera:(id)cameraViewController;
109109
@end
110110

111111
/**

DBCamera/Objects/DBCameraFilterCell.h

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// FilterCell.h
3+
// DBCamera
4+
//
5+
// Created by Marco De Nadai on 21/06/14.
6+
// Copyright (c) 2014 PSSD - Daniele Bogo. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
@interface DBCameraFilterCell : UICollectionViewCell
12+
/**
13+
* The name label of the filter
14+
*/
15+
@property (nonatomic, strong) UILabel *label;
16+
17+
/**
18+
* The image view contains the example
19+
*/
20+
@property (nonatomic, strong) UIImageView *imageView;
21+
@end

DBCamera/Objects/DBCameraFilterCell.m

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//
2+
// FilterCell.m
3+
// DBCamera
4+
//
5+
// Created by Marco De Nadai on 21/06/14.
6+
// Copyright (c) 2014 PSSD - Daniele Bogo. All rights reserved.
7+
//
8+
9+
#import "DBCameraFilterCell.h"
10+
#import "DBCameraMacros.h"
11+
#import <QuartzCore/QuartzCore.h>
12+
13+
static const NSUInteger kLabelHeight = 18;
14+
static const NSUInteger kCellPadding = 10;
15+
static const NSUInteger kBorderWidth = 1;
16+
17+
@implementation DBCameraFilterCell
18+
19+
- (id)initWithFrame:(CGRect)frame
20+
{
21+
self = [super initWithFrame:frame];
22+
if (self) {
23+
// Initialization code
24+
[self setBackgroundColor:RGBColor(0x101010, 1)];
25+
26+
UIView *backgroundCellView = [[UIView alloc] initWithFrame:(CGRect){ 0, kBorderWidth, CGRectGetWidth(self.frame)-kBorderWidth, CGRectGetHeight(self.frame)-kBorderWidth*2 }];
27+
[backgroundCellView setBackgroundColor:[UIColor blackColor]];
28+
29+
_label = [[UILabel alloc] initWithFrame:CGRectMake(0, self.frame.size.height-kLabelHeight, self.frame.size.width, kLabelHeight-kCellPadding)];
30+
[_label setFont:[UIFont systemFontOfSize:9]];
31+
[_label setTextAlignment:NSTextAlignmentCenter];
32+
[_label setTextColor:[UIColor whiteColor]];
33+
[_label setBackgroundColor:[UIColor clearColor]];
34+
[backgroundCellView addSubview:_label];
35+
36+
_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(kCellPadding, kCellPadding, CGRectGetWidth(self.frame)-kCellPadding*2, CGRectGetHeight(self.frame)-kLabelHeight-kCellPadding*2)];
37+
[_imageView.layer setCornerRadius:4.0];
38+
[_imageView.layer setBorderWidth:0.0];
39+
[_imageView.layer setBorderColor:[RGBColor(0xffffff, .3) CGColor]];
40+
[_imageView.layer setMasksToBounds:YES];
41+
42+
[backgroundCellView addSubview:_imageView];
43+
44+
[self addSubview:backgroundCellView];
45+
}
46+
return self;
47+
}
48+
49+
- (void)setHighlighted:(BOOL)highlighted{
50+
51+
}
52+
53+
@end
Loading

0 commit comments

Comments
 (0)