Skip to content
This repository has been archived by the owner on Jun 25, 2020. It is now read-only.

Commit

Permalink
Merge branch 'alyce_phase_2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Donnelly committed Aug 24, 2017
2 parents 1f252b9 + 53b3643 commit 3300aa8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 31 deletions.
5 changes: 3 additions & 2 deletions Source/PBJVision.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
#import "VideoFilterManager.h"
#import "GPUImageFilterGallery.h"

// vision types

Expand Down Expand Up @@ -126,7 +126,8 @@ static CGFloat const PBJVideoBitRate1280x750 = 5000000 * 8; // 40bmps

+ (PBJVision *)sharedInstance;

- (void)setCurrentFilterType:(VideoFilterType)filterType;
- (void)setCurrentFilterStyle:(ALYCEVideoStyle)filterStyle;
- (void)setCurrentFilterColor:(ALYCEColorFilter)filterColor;

@property (nonatomic, weak) id<PBJVisionDelegate> delegate;

Expand Down
78 changes: 49 additions & 29 deletions Source/PBJVision.m
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,21 @@ @interface PBJVision () <
size_t xOffset;
size_t yOffset;
} _pixelBufferInfo;

ALYCEVideoStyle _lastFilterStyle;
ALYCEColorFilter _lastFilterColor;
AirbrushFilterType _lastAirbrushFilterType;
}

@property (nonatomic) AVCaptureDevice *currentDevice;

@property (nonatomic, readonly) GPUImageView *filteredPreviewView;

@property (nonatomic, strong) GPUImageMovie *movieDataInput;
@property (nonatomic, strong) GPUImageFilterGroup *currentFilterGroup;
@property (nonatomic, strong) VideoFilterManager *filterManager;
@property (nonatomic, assign) VideoFilterType currentFilterType;
@property (nonatomic, strong) GPUImageOutput<GPUImageInput> *currentFilterGroup;

@property (nonatomic, assign) ALYCEVideoStyle currentFilterStyle;
@property (nonatomic, assign) ALYCEColorFilter currentFilterColor;


@property (nonatomic, retain) __attribute__((NSObject)) CMFormatDescriptionRef outputVideoFormatDescription;
Expand Down Expand Up @@ -722,7 +727,8 @@ - (id)init
self = [super init];
if (self) {


[self resetFilters];

sDeviceRgbColorSpace = CGColorSpaceCreateDeviceRGB();

_centerPercentage = 0.5f;
Expand Down Expand Up @@ -770,8 +776,6 @@ - (id)init
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_applicationWillEnterForeground:) name:@"UIApplicationWillEnterForegroundNotification" object:[UIApplication sharedApplication]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_applicationDidEnterBackground:) name:@"UIApplicationWillResignActiveNotification" object:[UIApplication sharedApplication]];

_filterManager = [VideoFilterManager sharedInstance];

_detectLowLight = NO;
_lastLightDetectTimestamp = kCMTimeInvalid;

Expand All @@ -797,6 +801,12 @@ - (void)dealloc
[self _destroyCamera];
}

- (void)resetFilters
{
_currentFilterStyle = _lastFilterStyle = ALYCEVideoStyleClassic;
_currentFilterColor = _lastFilterColor = ALYCEColorFilterNone;
}

- (void)setupPreviewViews
{
DLog(@"resetting preview views...");
Expand Down Expand Up @@ -1341,6 +1351,8 @@ - (void)_setupSession

- (void)startPreview
{
[self resetFilters];

[self _enqueueBlockOnCaptureVideoQueue:^{

_lastLightDetectTimestamp = kCMTimeInvalid;
Expand Down Expand Up @@ -1400,6 +1412,8 @@ - (void)stopPreview
{
[_movieDataInput removeTarget:_currentFilterGroup];
[_currentFilterGroup removeAllTargets];
[_currentFilterGroup setInputRotation:kGPUImageNoRotation atIndex:0];
_currentFilterGroup = nil;
}

if (mirrorFilter)
Expand Down Expand Up @@ -2789,32 +2803,38 @@ - (void)_renderSampleBuffer:(CMSampleBufferRef)sampleBuffer

if(_isFilterEnabled)
{
// Get filter based on scrollview offset
GPUImageFilterGroup *newFilterGroup = [_filterManager splitFilterGroupForType:self.currentFilterType airbrushFilterType:self.airbrushFilterType];

// Check if the filter needs to be changed
if (![[_movieDataInput targets] containsObject:newFilterGroup])
// Update current filter group if needed
if (_currentFilterStyle != _lastFilterStyle ||
_currentFilterColor != _lastFilterColor ||
_airbrushFilterType != _lastAirbrushFilterType ||
!_currentFilterGroup)
{
[_movieDataInput removeTarget:_currentFilterGroup];
[_currentFilterGroup removeAllTargets];

_currentFilterGroup = newFilterGroup;
[_movieDataInput addTarget:_currentFilterGroup];
[_currentFilterGroup addTarget:_filteredPreviewView];

}


// to handle mirroring with GPUImage, we just need to horizontal flip the
// initial filters in the chain (as long as they aren't split filters). This
// will flip image for left and right side of split, without flipping split direction
for ( int i = 0; i < _currentFilterGroup.initialFilters.count; i++ )
{
GPUImageFilter *filter = (GPUImageFilter *)_currentFilterGroup.initialFilters[i];
if ( ![filter isKindOfClass:[GPUImageSplitFilter class]] ) {
[filter setInputRotation:rotation atIndex:0];
runSynchronouslyOnVideoProcessingQueue(^{
[[GPUImageFilterGallery sharedInstance] setInputRotation:kGPUImageNoRotation atIndex:0];
[GPUImageFilterGallery sharedInstance].videoStyle = _currentFilterStyle;
[GPUImageFilterGallery sharedInstance].colorFilter = _currentFilterColor;
[GPUImageFilterGallery sharedInstance].airbrushFilterType = _airbrushFilterType;
});
GPUImageOutput<GPUImageInput> *newFilterGroup = [GPUImageFilterGallery sharedInstance];

// Check if the filter needs to be changed
if (![[_movieDataInput targets] containsObject:newFilterGroup])
{
[_movieDataInput removeTarget:_currentFilterGroup];
[_currentFilterGroup removeAllTargets];
_currentFilterGroup = newFilterGroup;
[_movieDataInput addTarget:_currentFilterGroup];
[_currentFilterGroup addTarget:_filteredPreviewView];
}

_lastFilterStyle = _currentFilterStyle;
_lastFilterColor = _currentFilterColor;
_lastAirbrushFilterType = _airbrushFilterType;

}
[_currentFilterGroup setInputRotation:rotation atIndex:0];
}
else
{
Expand Down

0 comments on commit 3300aa8

Please sign in to comment.