change scanline filter.

git-svn-id: svn://qnap.local/TwoTerm/trunk@2004 5590a31f-7b70-45f8-8c82-aa3a8e5f4507
This commit is contained in:
Kelvin Sherlock 2011-01-20 23:24:03 +00:00
parent 480d7ef93a
commit 04d96f94ce
3 changed files with 23 additions and 17 deletions

View File

@ -3,17 +3,23 @@
*
*/
kernel vec4 scanline(sampler image, float opacity)
kernel vec4 scanline(sampler image, float strength)
{
vec2 coord = samplerCoord(image);
vec4 fudge = vec4( 0.4, 0.4, 0.4, 0.0 );
vec2 coord = samplerCoord(image);
vec4 pixel = sample(image, coord);
float isOdd = mod(floor(coord.y), 2.0);
// isOdd == 0 --> return pixel
// isOdd == 1 --> return pixel * opacity
//float multiplier = compare(isOdd - 1.0, 1.0, opacity);
float multiplier = isOdd == 0.0 ? 1.0 : opacity;
return pixel * multiplier;
fudge *= strength;
float yy = mod(coord.y, 2.0);
fudge *= (yy < 1.0) ? 1.0 : -1.0;
pixel = unpremultiply(pixel);
pixel += fudge;
return premultiply(pixel);
}

View File

@ -11,7 +11,7 @@
@interface ScanLineFilter : CIFilter {
NSNumber *inputOpacity;
NSNumber *inputStrength;
CIImage *inputImage;
}

View File

@ -47,10 +47,10 @@ static CIKernel *_kernel = nil;
[NSNumber numberWithDouble: 0.00], kCIAttributeMax,
[NSNumber numberWithDouble: 0.00], kCIAttributeSliderMin,
[NSNumber numberWithDouble: 1.00], kCIAttributeSliderMax,
[NSNumber numberWithDouble: 0.50], kCIAttributeDefault,
[NSNumber numberWithDouble: 0.40], kCIAttributeDefault,
[NSNumber numberWithDouble: 0.00], kCIAttributeIdentity,
kCIAttributeTypeDistance, kCIAttributeType,
nil], @"inputOpacity",
nil], @"inputStrength",
nil];
}
@ -59,16 +59,16 @@ static CIKernel *_kernel = nil;
// called when setting up for fragment program and also calls fragment program
- (CIImage *)outputImage
{
float opacity;
float strength;
CISampler *src;
src = [CISampler samplerWithImage:inputImage];
opacity = [inputOpacity floatValue];
if (opacity < 0) opacity = 0;
if (opacity > 1.0) opacity = 1.0;
strength = [inputStrength floatValue];
if (strength < 0) strength = 0;
if (strength > 1.0) strength = 1.0;
return [self apply: _kernel, src, [NSNumber numberWithFloat: opacity], nil];
return [self apply: _kernel, src, [NSNumber numberWithFloat: strength], nil];
}