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_smoothing'
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-smule committed Sep 6, 2017
2 parents 3300aa8 + 5adf49a commit 400f6f2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 52 deletions.
9 changes: 2 additions & 7 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 "GPUImageFilterGallery.h"
#import "GPUImageALYCEFilter.h"

// vision types

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

+ (PBJVision *)sharedInstance;

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

@property (nonatomic, strong) GPUImageALYCEFilter *alyceFilter;
@property (nonatomic, weak) id<PBJVisionDelegate> delegate;

// session
Expand Down Expand Up @@ -226,9 +224,6 @@ static CGFloat const PBJVideoBitRate1280x750 = 5000000 * 8; // 40bmps
// this determines whether we display video with PBJ or GPUImage
@property (nonatomic) BOOL isFilterEnabled;

// this determines whether we should include airbrush in the video effects chain
@property (nonatomic) AirbrushFilterType airbrushFilterType;

// this determines whether or not we do low light detection for video
@property (nonatomic, getter=isDetectingLowLight) BOOL detectLowLight;

Expand Down
63 changes: 18 additions & 45 deletions Source/PBJVision.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#import "GPUImageSplitFilter.h"
#include "BufferCopy.h"

#include "GPUImageALYCEFilter.h"

#import <ImageIO/ImageIO.h>
#import <OpenGLES/EAGL.h>

Expand Down Expand Up @@ -216,18 +218,13 @@ @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) GPUImageOutput<GPUImageInput> *currentFilterGroup;

@property (nonatomic, assign) ALYCEVideoStyle currentFilterStyle;
@property (nonatomic, assign) ALYCEColorFilter currentFilterColor;
Expand Down Expand Up @@ -733,7 +730,7 @@ - (id)init

_centerPercentage = 0.5f;

_airbrushFilterType = AirbrushFilterTypeNone;
_alyceFilter = [[GPUImageALYCEFilter alloc] init];

// set default capture preset
_captureSessionPreset = AVCaptureSessionPresetMedium;
Expand Down Expand Up @@ -803,8 +800,8 @@ - (void)dealloc

- (void)resetFilters
{
_currentFilterStyle = _lastFilterStyle = ALYCEVideoStyleClassic;
_currentFilterColor = _lastFilterColor = ALYCEColorFilterNone;
self.alyceFilter.colorFilter = ALYCEColorFilterNone;
self.alyceFilter.videoStyle = ALYCEVideoStyleClassic;
}

- (void)setupPreviewViews
Expand Down Expand Up @@ -1408,12 +1405,10 @@ - (void)stopPreview

DLog(@"Stop Preview");

if (_currentFilterGroup)
if (_alyceFilter)
{
[_movieDataInput removeTarget:_currentFilterGroup];
[_currentFilterGroup removeAllTargets];
[_currentFilterGroup setInputRotation:kGPUImageNoRotation atIndex:0];
_currentFilterGroup = nil;
[_movieDataInput removeTarget:_alyceFilter];
[_alyceFilter removeAllTargets];
}

if (mirrorFilter)
Expand Down Expand Up @@ -2686,10 +2681,10 @@ - (void)mediaWriterDidFinishRecording:(PBJMediaWriter *)mediaWriter
- (void)clearPreviewView
{

if (self.currentFilterGroup)
if (self.alyceFilter)
{
[self.currentFilterGroup removeAllTargets];
[self.currentFilterGroup addTarget:_filteredPreviewView];
[self.alyceFilter removeAllTargets];
[self.alyceFilter addTarget:_filteredPreviewView];
}
}

Expand Down Expand Up @@ -2803,38 +2798,16 @@ - (void)_renderSampleBuffer:(CMSampleBufferRef)sampleBuffer

if(_isFilterEnabled)
{
// Update current filter group if needed
if (_currentFilterStyle != _lastFilterStyle ||
_currentFilterColor != _lastFilterColor ||
_airbrushFilterType != _lastAirbrushFilterType ||
!_currentFilterGroup)
[self.alyceFilter setInputRotation:rotation atIndex:0];

// Check if the filter needs to be changed
if (![[_movieDataInput targets] containsObject:self.alyceFilter])
{
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;
[_movieDataInput removeAllTargets];

[_movieDataInput addTarget:self.alyceFilter];
[self.alyceFilter addTarget:_filteredPreviewView];
}
[_currentFilterGroup setInputRotation:rotation atIndex:0];
}
else
{
Expand Down

0 comments on commit 400f6f2

Please sign in to comment.