Skip to content
Browse files

Removed histogram filter. iOS does not support texture reads in verte…

…x shaders, so this won't work at all.
  • Loading branch information...
1 parent 8fcea7f commit 85810363a193397c4b5e864e092cd1050da8ac62 @BradLarson committed Apr 27, 2012
View
1 examples/FilterShowcase/FilterShowcase/ShowcaseFilterListController.m
@@ -69,7 +69,6 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
case GPUIMAGE_UNSHARPMASK: cell.textLabel.text = @"Unsharp mask"; break;
case GPUIMAGE_GAMMA: cell.textLabel.text = @"Gamma"; break;
case GPUIMAGE_HAZE: cell.textLabel.text = @"Haze"; break;
- case GPUIMAGE_HISTOGRAM: cell.textLabel.text = @"Histogram"; break;
case GPUIMAGE_THRESHOLD: cell.textLabel.text = @"Threshold"; break;
case GPUIMAGE_ADAPTIVETHRESHOLD: cell.textLabel.text = @"Adaptive threshold"; break;
case GPUIMAGE_CROP: cell.textLabel.text = @"Crop"; break;
View
1 examples/FilterShowcase/FilterShowcase/ShowcaseFilterViewController.h
@@ -17,7 +17,6 @@ typedef enum {
GPUIMAGE_SEPIA,
GPUIMAGE_COLORINVERT,
GPUIMAGE_GRAYSCALE,
- GPUIMAGE_HISTOGRAM,
GPUIMAGE_THRESHOLD,
GPUIMAGE_ADAPTIVETHRESHOLD,
GPUIMAGE_PIXELLATE,
View
12 examples/FilterShowcase/FilterShowcase/ShowcaseFilterViewController.m
@@ -199,17 +199,6 @@ - (void)setupFilter;
filter = [[GPUImageHazeFilter alloc] init];
}; break;
- case GPUIMAGE_HISTOGRAM:
- {
- self.title = @"Histogram";
- self.filterSettingsSlider.hidden = NO;
-
- [self.filterSettingsSlider setMinimumValue:0.0];
- [self.filterSettingsSlider setMaximumValue:0.1];
- [self.filterSettingsSlider setValue:0.1];
-
- filter = [[GPUImageHistogramFilter alloc] initWithHistogramType:kGPUImageHistogramRed];
- }; break;
case GPUIMAGE_THRESHOLD:
{
self.title = @"Luminance Threshold";
@@ -686,7 +675,6 @@ - (IBAction)updateFilterFromSlider:(id)sender;
case GPUIMAGE_BRIGHTNESS: [(GPUImageBrightnessFilter *)filter setBrightness:[(UISlider *)sender value]]; break;
case GPUIMAGE_EXPOSURE: [(GPUImageExposureFilter *)filter setExposure:[(UISlider *)sender value]]; break;
case GPUIMAGE_SHARPEN: [(GPUImageSharpenFilter *)filter setSharpness:[(UISlider *)sender value]]; break;
- case GPUIMAGE_HISTOGRAM: [(GPUImageHistogramFilter *)filter setScalingFactor:[(UISlider *)sender value]]; break;
case GPUIMAGE_UNSHARPMASK: [(GPUImageUnsharpMaskFilter *)filter setIntensity:[(UISlider *)sender value]]; break;
// case GPUIMAGE_UNSHARPMASK: [(GPUImageUnsharpMaskFilter *)filter setBlurSize:[(UISlider *)sender value]]; break;
case GPUIMAGE_GAMMA: [(GPUImageGammaFilter *)filter setGamma:[(UISlider *)sender value]]; break;
View
8 framework/GPUImage.xcodeproj/project.pbxproj
@@ -34,8 +34,6 @@
BC245DCB14DDBED7009FE7EB /* GPUImageFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = BC245DC914DDBED7009FE7EB /* GPUImageFilter.m */; };
BC54D563151904FF003F4A41 /* GPUImageChromaKeyBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = BC54D561151904FF003F4A41 /* GPUImageChromaKeyBlendFilter.h */; };
BC54D564151904FF003F4A41 /* GPUImageChromaKeyBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = BC54D562151904FF003F4A41 /* GPUImageChromaKeyBlendFilter.m */; };
- BC6ED9C21549CA0600966798 /* GPUImageHistogramFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = BC6ED9C01549CA0600966798 /* GPUImageHistogramFilter.h */; };
- BC6ED9C31549CA0600966798 /* GPUImageHistogramFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = BC6ED9C11549CA0600966798 /* GPUImageHistogramFilter.m */; };
BC7D95D51523EE67000DF037 /* GPUImageStillCamera.h in Headers */ = {isa = PBXBuildFile; fileRef = BC7D95D31523EE67000DF037 /* GPUImageStillCamera.h */; };
BC7D95D61523EE67000DF037 /* GPUImageStillCamera.m in Sources */ = {isa = PBXBuildFile; fileRef = BC7D95D41523EE67000DF037 /* GPUImageStillCamera.m */; };
BC982B5314F07F790001FF6F /* GPUImageColorInvertFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = BC982B4F14F07F790001FF6F /* GPUImageColorInvertFilter.h */; };
@@ -210,8 +208,6 @@
BC245DC914DDBED7009FE7EB /* GPUImageFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageFilter.m; path = Source/GPUImageFilter.m; sourceTree = SOURCE_ROOT; };
BC54D561151904FF003F4A41 /* GPUImageChromaKeyBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageChromaKeyBlendFilter.h; path = Source/GPUImageChromaKeyBlendFilter.h; sourceTree = SOURCE_ROOT; };
BC54D562151904FF003F4A41 /* GPUImageChromaKeyBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageChromaKeyBlendFilter.m; path = Source/GPUImageChromaKeyBlendFilter.m; sourceTree = SOURCE_ROOT; };
- BC6ED9C01549CA0600966798 /* GPUImageHistogramFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageHistogramFilter.h; path = Source/GPUImageHistogramFilter.h; sourceTree = SOURCE_ROOT; };
- BC6ED9C11549CA0600966798 /* GPUImageHistogramFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageHistogramFilter.m; path = Source/GPUImageHistogramFilter.m; sourceTree = SOURCE_ROOT; };
BC7D95D31523EE67000DF037 /* GPUImageStillCamera.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageStillCamera.h; path = Source/GPUImageStillCamera.h; sourceTree = SOURCE_ROOT; };
BC7D95D41523EE67000DF037 /* GPUImageStillCamera.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageStillCamera.m; path = Source/GPUImageStillCamera.m; sourceTree = SOURCE_ROOT; };
BC982B4F14F07F790001FF6F /* GPUImageColorInvertFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageColorInvertFilter.h; path = Source/GPUImageColorInvertFilter.h; sourceTree = SOURCE_ROOT; };
@@ -407,8 +403,6 @@
BCC94ABA151E4FD6008554B4 /* GPUImageLuminanceThresholdFilter.m */,
BCC1E5CA151EA6610006EFA5 /* GPUImageAdaptiveThresholdFilter.h */,
BCC1E5CB151EA6610006EFA5 /* GPUImageAdaptiveThresholdFilter.m */,
- BC6ED9C01549CA0600966798 /* GPUImageHistogramFilter.h */,
- BC6ED9C11549CA0600966798 /* GPUImageHistogramFilter.m */,
);
name = "Color processing";
sourceTree = "<group>";
@@ -731,7 +725,6 @@
BCF3D722153E0E0C009A1FE5 /* GPUImageThresholdEdgeDetection.h in Headers */,
BCF3D730153F0D6F009A1FE5 /* GPUImageSmoothToonFilter.h in Headers */,
83AE9FCD1540E92800F7FC13 /* GPUImageMaskFilter.h in Headers */,
- BC6ED9C21549CA0600966798 /* GPUImageHistogramFilter.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -905,7 +898,6 @@
BCF3D723153E0E0C009A1FE5 /* GPUImageThresholdEdgeDetection.m in Sources */,
BCF3D731153F0D6F009A1FE5 /* GPUImageSmoothToonFilter.m in Sources */,
83AE9FCE1540E92800F7FC13 /* GPUImageMaskFilter.m in Sources */,
- BC6ED9C31549CA0600966798 /* GPUImageHistogramFilter.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
3 framework/Source/GPUImage.h
@@ -71,5 +71,4 @@
#import "GPUImageEmbossFilter.h"
#import "GPUImageCannyEdgeDetectionFilter.h"
#import "GPUImageThresholdEdgeDetection.h"
-#import "GPUImageMaskFilter.h"
-#import "GPUImageHistogramFilter.h"
+#import "GPUImageMaskFilter.h"
View
25 framework/Source/GPUImageHistogramFilter.h
@@ -1,25 +0,0 @@
-#import "GPUImageFilter.h"
-
-typedef enum { kGPUImageHistogramRed, kGPUImageHistogramGreen, kGPUImageHistogramBlue, kGPUImageHistogramLuminance} GPUImageHistogramType;
-
-@interface GPUImageHistogramFilter : GPUImageFilter
-{
- GPUImageHistogramType histogramType;
-
- GLfloat *vertexSamplingCoordinates, *textureSamplingCoordinates;
- GLint scalingFactorUniform;
-}
-
-// These properties control the density of the grid overlaid on the image which is used to sample the colors for the histogram. By default, this is set to 100 in either direction
-@property(readwrite, nonatomic) NSUInteger samplingDensityInX, samplingDensityInY;
-
-// This dictates the scaling of the histogram heights. By default this is 0.004 (1/255)
-@property(readwrite, nonatomic) CGFloat scalingFactor;
-
-// Initialization and teardown
-- (id)initWithHistogramType:(GPUImageHistogramType)newHistogramType;
-
-// Rendering
-- (void)generatePointCoordinates;
-
-@end
View
248 framework/Source/GPUImageHistogramFilter.m
@@ -1,248 +0,0 @@
-#import "GPUImageHistogramFilter.h"
-
-// Unlike other filters, this one uses a grid of GL_POINTs to sample the incoming image in a grid. A custom vertex shader reads the color in the texture at its position
-// and outputs a bin position in the final histogram as the vertex position. That point is then written into the image of the histogram using translucent pixels.
-// The degree of translucency is controlled by the scalingFactor, which lets you adjust the dynamic range of the histogram. The histogram can only be generated for one
-// color channel or luminance value at a time.
-
-NSString *const kGPUImageRedHistogramSamplingVertexShaderString = SHADER_STRING
-(
-// attribute vec4 position;
- attribute vec4 inputTextureCoordinate;
-
- uniform sampler2D inputImageTexture;
-
- void main()
- {
- float colorAtThisVertex = texture2D(inputImageTexture, inputTextureCoordinate.xy).x;
-// gl_Position = vec4(-1.0 + 2.0 * colorAtThisVertex, 0.0, 0.0, 1.0);
- gl_Position = vec4(colorAtThisVertex, 0.0, 0.0, 1.0);
-// gl_Position = vec4(inputTextureCoordinate.x, 0.0, 0.0, 1.0);
- gl_PointSize = 4.0;
- }
-);
-
-//NSString *const kGPUImageGreenHistogramSamplingVertexShaderString = SHADER_STRING
-//(
-// attribute vec4 position;
-// attribute vec4 inputTextureCoordinate;
-//
-// void main()
-// {
-// vec4 notUsed = texture2D(inputImageTexture, vec2(0.0, 0.0));
-// highp float colorAtThisVertex = texture2D(inputImageTexture, inputTextureCoordinate.uv).g;
-// gl_Position = vec4(-1.0 + 2.0 * colorAtThisVertex, 0.0, 0.0, 1.0);
-// }
-//);
-//
-//NSString *const kGPUImageBlueHistogramSamplingVertexShaderString = SHADER_STRING
-//(
-// attribute vec4 position;
-// attribute vec4 inputTextureCoordinate;
-//
-//// uniform sampler2D inputImageTexture;
-//
-// void main()
-// {
-// highp float colorAtThisVertex = texture2D(inputImageTexture, inputTextureCoordinate.uv).b;
-// gl_Position = vec4(-1.0 + 2.0 * colorAtThisVertex, 0.0, 0.0, 1.0);
-// }
-//);
-//
-//NSString *const kGPUImageLuminanceHistogramSamplingVertexShaderString = SHADER_STRING
-//(
-// attribute vec4 position;
-// attribute vec4 inputTextureCoordinate;
-//
-// uniform sampler2D inputImageTexture;
-//
-// const highp vec3 W = vec3(0.2125, 0.7154, 0.0721);
-//
-// void main()
-// {
-// highp float luminance = dot(texture2D(inputImageTexture, inputTextureCoordinate.uv).rgb, W);
-// gl_Position = vec4(-1.0 + 2.0 * luminance, 0.0, 0.0, 1.0);
-// }
-//);
-
-NSString *const kGPUImageHistogramAccumulationFragmentShaderString = SHADER_STRING
-(
- uniform highp float scalingFactor;
-
-// uniform sampler2D inputImageTexture;
-
- void main()
- {
-// lowp vec4 notUsed = texture2D(inputImageTexture, vec2(0.0, 0.0));
-
-// gl_FragColor = vec4(1.0, notUsed.r, 0.0, 1.0);
- gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
- }
- );
-
-@implementation GPUImageHistogramFilter
-
-@synthesize samplingDensityInX = _samplingDensityInX;
-@synthesize samplingDensityInY = _samplingDensityInY;
-@synthesize scalingFactor = _scalingFactor;
-
-#pragma mark -
-#pragma mark Initialization and teardown
-
-- (id)initWithHistogramType:(GPUImageHistogramType)newHistogramType;
-{
- if (!(self = [super initWithVertexShaderFromString:kGPUImageRedHistogramSamplingVertexShaderString fragmentShaderFromString:kGPUImageHistogramAccumulationFragmentShaderString]))
- {
- return nil;
- }
-
- /*
- switch (newHistogramType)
- {
- case kGPUImageHistogramRed:
- {
- if (!(self = [super initWithVertexShaderFromString:kGPUImageRedHistogramSamplingVertexShaderString fragmentShaderFromString:kGPUImageHistogramAccumulationFragmentShaderString]))
- {
- return nil;
- }
- }; break;
- case kGPUImageHistogramGreen:
- {
- if (!(self = [super initWithVertexShaderFromString:kGPUImageGreenHistogramSamplingVertexShaderString fragmentShaderFromString:kGPUImageHistogramAccumulationFragmentShaderString]))
- {
- return nil;
- }
- }; break;
- case kGPUImageHistogramBlue:
- {
- if (!(self = [super initWithVertexShaderFromString:kGPUImageBlueHistogramSamplingVertexShaderString fragmentShaderFromString:kGPUImageHistogramAccumulationFragmentShaderString]))
- {
- return nil;
- }
- }; break;
- case kGPUImageHistogramLuminance:
- {
- if (!(self = [super initWithVertexShaderFromString:kGPUImageLuminanceHistogramSamplingVertexShaderString fragmentShaderFromString:kGPUImageHistogramAccumulationFragmentShaderString]))
- {
- return nil;
- }
- }; break;
- }
-*/
- histogramType = newHistogramType;
-
- _samplingDensityInX = 3;
- _samplingDensityInY = 1;
-
- scalingFactorUniform = [filterProgram uniformIndex:@"scalingFactor"];
- self.scalingFactor = 0.1;
-
- [self forceProcessingAtSize:CGSizeMake(256.0, 3.0)]; // Output just 256 pixels of color information for whatever bin
-
- return self;
-}
-
-- (void)dealloc;
-{
- if (vertexSamplingCoordinates != NULL)
- {
- free(vertexSamplingCoordinates);
- free(textureSamplingCoordinates);
- }
-}
-
-#pragma mark -
-#pragma mark Rendering
-
-//- (CGSize)sizeOfFBO;
-//{
-// return CGSizeMake(256.0, 3.0);
-//}
-
-- (void)generatePointCoordinates;
-{
- vertexSamplingCoordinates = calloc(_samplingDensityInX * _samplingDensityInY * 2, sizeof(GLfloat));
- textureSamplingCoordinates = calloc(_samplingDensityInX * _samplingDensityInY * 2, sizeof(GLfloat));
-
- GLfloat fractionalSpacingInX = 1.0 / (GLfloat)_samplingDensityInX;
- GLfloat fractionalSpacingInY = 1.0 / (GLfloat)_samplingDensityInY;
-
- for (NSUInteger currentYIndex = 0; currentYIndex < _samplingDensityInY; currentYIndex++)
- {
- GLfloat currentYTextureLocation = (GLfloat)currentYIndex * fractionalSpacingInY;
- GLfloat currentYVertexLocation = -1.0 + 2.0 * (GLfloat)currentYIndex * fractionalSpacingInY;
-
- for (NSUInteger currentXIndex = 0; currentXIndex < _samplingDensityInX; currentXIndex++)
- {
- GLfloat currentXTextureLocation = (GLfloat)currentXIndex * fractionalSpacingInX;
- NSInteger basePointerPosition = currentYIndex * _samplingDensityInX + currentXIndex;
-
- NSLog(@"Texture coord: %f, %f", currentXTextureLocation, currentYTextureLocation);
- textureSamplingCoordinates[basePointerPosition * 2] = currentXTextureLocation;
- textureSamplingCoordinates[(basePointerPosition * 2) + 1] = currentYTextureLocation;
-
- GLfloat currentXVertexLocation = -1.0 + 2.0 * (GLfloat)currentXIndex * fractionalSpacingInX;
-
- textureSamplingCoordinates[basePointerPosition * 2] = currentXVertexLocation;
- textureSamplingCoordinates[(basePointerPosition * 2) + 1] = currentYVertexLocation;
- }
- }
-}
-
-- (void)newFrameReadyAtTime:(CMTime)frameTime;
-{
- if (vertexSamplingCoordinates == NULL)
- {
- [self generatePointCoordinates];
- }
-
- [self renderToTextureWithVertices:vertexSamplingCoordinates textureCoordinates:textureSamplingCoordinates sourceTexture:filterSourceTexture];
-
- [self informTargetsAboutNewFrameAtTime:frameTime];
-}
-
-- (void)renderToTextureWithVertices:(const GLfloat *)vertices textureCoordinates:(const GLfloat *)textureCoordinates sourceTexture:(GLuint)sourceTexture;
-{
- [GPUImageOpenGLESContext useImageProcessingContext];
- [self setFilterFBO];
-
- [filterProgram use];
-
- glClearColor(0.0, 0.0, 1.0, 1.0);
- glClear(GL_COLOR_BUFFER_BIT);
-
-// glBlendEquation(GL_FUNC_ADD);
-// glBlendFunc(GL_ONE, GL_ONE);
-// glEnable(GL_BLEND);
- glActiveTexture(GL_TEXTURE2);
- glBindTexture(GL_TEXTURE_2D, sourceTexture);
-
- NSLog(@"Input texture uniform: %d", filterInputTextureUniform);
- NSLog(@"Texture attrib: %d, position attrib: %d", filterTextureCoordinateAttribute, filterPositionAttribute);
-
- glUniform1i(filterInputTextureUniform, 2);
-
-// glVertexAttribPointer(filterPositionAttribute, 2, GL_FLOAT, 0, 0, vertices);
- glVertexAttribPointer(filterTextureCoordinateAttribute, 2, GL_FLOAT, 0, 0, textureCoordinates);
- GLenum error = glGetError();
- NSLog(@"Error before: %d", error);
- glDrawArrays(GL_POINTS, 0, _samplingDensityInX * _samplingDensityInY);
-
- error = glGetError();
- NSLog(@"Error after: %d", error);
-// glDisable(GL_BLEND);
-}
-
-#pragma mark -
-#pragma mark Accessors
-
-- (void)setScalingFactor:(CGFloat)newValue;
-{
-// _scalingFactor = newValue;
-//
-// [GPUImageOpenGLESContext useImageProcessingContext];
-// [filterProgram use];
-// glUniform1f(scalingFactorUniform, _scalingFactor);
-}
-
-@end

0 comments on commit 8581036

Please sign in to comment.
Something went wrong with that request. Please try again.