Skip to content

Commit

Permalink
Ported a few more filters to the Mac. Added the ability to lock on to…
Browse files Browse the repository at this point in the history
… a specific UUID for a Mac camera.
  • Loading branch information
BradLarson committed May 5, 2013
1 parent d5c1ddc commit 67d2644
Show file tree
Hide file tree
Showing 14 changed files with 508 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,15 @@ typedef enum {
GPUIMAGE_AMATORKA,
GPUIMAGE_MISSETIKATE,
GPUIMAGE_SOFTELEGANCE,
GPUIMAGE_PIXELLATE,
GPUIMAGE_COLORINVERT,
GPUIMAGE_GRAYSCALE,
GPUIMAGE_HISTOGRAM,
GPUIMAGE_AVERAGECOLOR,
GPUIMAGE_LUMINOSITY,
GPUIMAGE_THRESHOLD,
GPUIMAGE_ADAPTIVETHRESHOLD,
GPUIMAGE_AVERAGELUMINANCETHRESHOLD,
GPUIMAGE_PIXELLATE,
GPUIMAGE_SOBELEDGEDETECTION,
GPUIMAGE_SKETCH,
GPUIMAGE_TOON,
Expand Down
114 changes: 114 additions & 0 deletions examples/Mac/FilterShowcase/SLSFilterShowcaseWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,57 @@ - (void)changeSelectedRow:(NSUInteger)newRowIndex;
currentlySelectedFilter = [[GPUImageSoftEleganceFilter alloc] init];
self.enableSlider = NO;
}; break;
case GPUIMAGE_COLORINVERT:
{
currentlySelectedFilter = [[GPUImageColorInvertFilter alloc] init];
self.enableSlider = NO;
}; break;
case GPUIMAGE_HISTOGRAM:
{
currentlySelectedFilter = [[GPUImageHistogramFilter alloc] init];

self.minimumSliderValue = 4.0;
self.maximumSliderValue = 32.0;
self.currentSliderValue = 16.0;
self.enableSlider = YES;
}; break;
case GPUIMAGE_AVERAGECOLOR:
{
currentlySelectedFilter = [[GPUImageAverageColor alloc] init];
self.enableSlider = NO;
}; break;
case GPUIMAGE_LUMINOSITY:
{
currentlySelectedFilter = [[GPUImageLuminosity alloc] init];
self.enableSlider = NO;
}; break;
case GPUIMAGE_THRESHOLD:
{
currentlySelectedFilter = [[GPUImageLuminanceThresholdFilter alloc] init];

self.minimumSliderValue = 0.0;
self.maximumSliderValue = 1.0;
self.currentSliderValue = 0.5;
self.enableSlider = YES;
}; break;
case GPUIMAGE_ADAPTIVETHRESHOLD:
{
currentlySelectedFilter = [[GPUImageAdaptiveThresholdFilter alloc] init];

self.minimumSliderValue = 1.0;
self.maximumSliderValue = 20.0;
self.currentSliderValue = 1.0;
self.enableSlider = YES;
}; break;
case GPUIMAGE_AVERAGELUMINANCETHRESHOLD:
{
currentlySelectedFilter = [[GPUImageAverageLuminanceThresholdFilter alloc] init];

self.minimumSliderValue = 0.0;
self.maximumSliderValue = 2.0;
self.currentSliderValue = 1.0;
self.enableSlider = YES;
}; break;
case GPUIMAGE_GRAYSCALE:
{
currentlySelectedFilter = [[GPUImageGrayscaleFilter alloc] init];
Expand Down Expand Up @@ -634,6 +685,58 @@ - (void)changeSelectedRow:(NSUInteger)newRowIndex;

[blendFilter addTarget:self.glView];
}
else if (currentlySelectedRow == GPUIMAGE_HISTOGRAM)
{
[currentlySelectedFilter removeTarget:self.glView];

// I'm adding an intermediary filter because glReadPixels() requires something to be rendered for its glReadPixels() operation to work
[inputCamera removeTarget:currentlySelectedFilter];
GPUImageGammaFilter *gammaFilter = [[GPUImageGammaFilter alloc] init];
[inputCamera addTarget:gammaFilter];
[gammaFilter addTarget:currentlySelectedFilter];

GPUImageHistogramGenerator *histogramGraph = [[GPUImageHistogramGenerator alloc] init];

[histogramGraph forceProcessingAtSize:CGSizeMake(256.0, 144.0)];
[currentlySelectedFilter addTarget:histogramGraph];

GPUImageAlphaBlendFilter *blendFilter = [[GPUImageAlphaBlendFilter alloc] init];
blendFilter.mix = 0.75;
[blendFilter forceProcessingAtSize:CGSizeMake(256.0, 144.0)];

[inputCamera addTarget:blendFilter];
[histogramGraph addTarget:blendFilter];

[blendFilter addTarget:self.glView];
}
else if (currentlySelectedRow == GPUIMAGE_AVERAGECOLOR)
{
[currentlySelectedFilter removeTarget:self.glView];

GPUImageSolidColorGenerator *colorGenerator = [[GPUImageSolidColorGenerator alloc] init];
[colorGenerator forceProcessingAtSize:[self.glView sizeInPixels]];

[(GPUImageAverageColor *)currentlySelectedFilter setColorAverageProcessingFinishedBlock:^(CGFloat redComponent, CGFloat greenComponent, CGFloat blueComponent, CGFloat alphaComponent, CMTime frameTime) {
[colorGenerator setColorRed:redComponent green:greenComponent blue:blueComponent alpha:alphaComponent];
// NSLog(@"Average color: %f, %f, %f, %f", redComponent, greenComponent, blueComponent, alphaComponent);
}];

[colorGenerator addTarget:self.glView];
}
else if (currentlySelectedRow == GPUIMAGE_LUMINOSITY)
{
[currentlySelectedFilter removeTarget:self.glView];

GPUImageSolidColorGenerator *colorGenerator = [[GPUImageSolidColorGenerator alloc] init];
[colorGenerator forceProcessingAtSize:[self.glView sizeInPixels]];

[(GPUImageLuminosity *)currentlySelectedFilter setLuminosityProcessingFinishedBlock:^(CGFloat luminosity, CMTime frameTime) {
[colorGenerator setColorRed:luminosity green:luminosity blue:luminosity alpha:1.0];
}];

[colorGenerator addTarget:self.glView];
}

}

#pragma mark -
Expand Down Expand Up @@ -663,6 +766,10 @@ - (void)setCurrentSliderValue:(CGFloat)newValue;
case GPUIMAGE_HAZE: [(GPUImageHazeFilter *)currentlySelectedFilter setDistance:_currentSliderValue]; break;
case GPUIMAGE_SEPIA: [(GPUImageSepiaFilter *)currentlySelectedFilter setIntensity:_currentSliderValue]; break;
case GPUIMAGE_PIXELLATE: [(GPUImagePixellateFilter *)currentlySelectedFilter setFractionalWidthOfAPixel:_currentSliderValue]; break;
case GPUIMAGE_HISTOGRAM: [(GPUImageHistogramFilter *)currentlySelectedFilter setDownsamplingFactor:round(_currentSliderValue)]; break;
case GPUIMAGE_THRESHOLD: [(GPUImageLuminanceThresholdFilter *)currentlySelectedFilter setThreshold:_currentSliderValue]; break;
case GPUIMAGE_ADAPTIVETHRESHOLD: [(GPUImageAdaptiveThresholdFilter *)currentlySelectedFilter setBlurSize:_currentSliderValue]; break;
case GPUIMAGE_AVERAGELUMINANCETHRESHOLD: [(GPUImageAverageLuminanceThresholdFilter *)currentlySelectedFilter setThresholdMultiplier:_currentSliderValue]; break;
case GPUIMAGE_EMBOSS: [(GPUImageEmbossFilter *)currentlySelectedFilter setIntensity:_currentSliderValue]; break;
case GPUIMAGE_KUWAHARA: [(GPUImageKuwaharaFilter *)currentlySelectedFilter setRadius:round(_currentSliderValue)]; break;
case GPUIMAGE_SHARPEN: [(GPUImageSharpenFilter *)currentlySelectedFilter setSharpness:_currentSliderValue]; break;
Expand Down Expand Up @@ -718,6 +825,12 @@ - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColu
case GPUIMAGE_MONOCHROME: tableRowTitle = @"Monochrome"; break;
case GPUIMAGE_PIXELLATE: tableRowTitle = @"Pixellate"; break;
case GPUIMAGE_GRAYSCALE: tableRowTitle = @"Grayscale"; break;
case GPUIMAGE_HISTOGRAM: tableRowTitle = @"Histogram"; break;
case GPUIMAGE_AVERAGECOLOR: tableRowTitle = @"Average color"; break;
case GPUIMAGE_LUMINOSITY: tableRowTitle = @"Average luminosity"; break;
case GPUIMAGE_THRESHOLD: tableRowTitle = @"Threshold"; break;
case GPUIMAGE_ADAPTIVETHRESHOLD: tableRowTitle = @"Adaptive threshold"; break;
case GPUIMAGE_AVERAGELUMINANCETHRESHOLD: tableRowTitle = @"Average luminance threshold"; break;
case GPUIMAGE_SOBELEDGEDETECTION: tableRowTitle = @"Sobel edge detection"; break;
case GPUIMAGE_SKETCH: tableRowTitle = @"Sketch"; break;
case GPUIMAGE_TOON: tableRowTitle = @"Toon"; break;
Expand All @@ -740,6 +853,7 @@ - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColu
case GPUIMAGE_AMATORKA: tableRowTitle = @"Amatorka (Lookup)"; break;
case GPUIMAGE_MISSETIKATE: tableRowTitle = @"Miss Etikate (Lookup)"; break;
case GPUIMAGE_SOFTELEGANCE: tableRowTitle = @"Soft elegance (Lookup)"; break;
case GPUIMAGE_COLORINVERT: tableRowTitle = @"Color invert"; break;
case GPUIMAGE_GAUSSIAN: tableRowTitle = @"Gaussian blur"; break;
case GPUIMAGE_GAUSSIAN_SELECTIVE: tableRowTitle = @"Gaussian selective blur"; break;
case GPUIMAGE_GAUSSIAN_POSITION: tableRowTitle = @"Gaussian (centered)"; break;
Expand Down
Loading

0 comments on commit 67d2644

Please sign in to comment.