1 // Copyright (c) 2009 Yanagi Asakura
3 // This software is provided 'as-is', without any express or implied
4 // warranty. In no event will the authors be held liable for any damages
5 // arising from the use of this software.
7 // Permission is granted to anyone to use this software for any purpose,
8 // including commercial applications, and to alter it and redistribute it
9 // freely, subject to the following restrictions:
11 // 1. The origin of this software must not be misrepresented; you must not
12 // claim that you wrote the original software. If you use this software
13 // in a product, an acknowledgment in the product documentation would be
14 // appreciated but is not required.
16 // 2. Altered source versions must be plainly marked as such, and must not be
17 // misrepresented as being the original software.
19 // 3. This notice may not be removed or altered from any source
26 // Created by 柳 on 09/09/02.
27 // Copyright 2009 Yanagi Entertainment. All rights reserved.
30 #import "ElisCustomFilter.h"
32 @implementation ElisCustomFilter
34 static CIKernel* s_opacityKernel = nil;
38 if(s_opacityKernel == nil){
39 // NSBundle *bundle = [NSBundle bundleForClass:[self class]];
40 NSBundle* bundle = [NSBundle mainBundle];
41 NSString *code = [NSString stringWithContentsOfFile:[bundle pathForResource:@"ElisCoreImageKernel" ofType:@"cikernel"]];
43 NSArray *kernels = [CIKernel kernelsWithString:code];
44 s_opacityKernel = [[kernels objectAtIndex:0] retain];
52 NSLog(@"Initializing Custom Filter ...");
54 [CIFilter registerFilterName:@"CHOpacity"
56 classAttributes:[NSDictionary dictionaryWithObjectsAndKeys:@"Change", kCIAttributeFilterDisplayName,
57 [NSArray arrayWithObjects:kCICategoryColorAdjustment, kCICategoryVideo, kCICategoryStillImage,
58 kCICategoryNonSquarePixels, nil], kCIAttributeFilterCategories, nil]];
59 // [NSDictionary dictionaryWithObjectsAndKeys:
60 // [NSNumber numberWithDouble:0.0], kCIAttributeMin,
61 // [NSNumber numberWithDouble:1.0], kCIAttributeMax,
62 // [NSNumber numberWithDouble:0.0], kCIAttributeSliderMin,
63 // [NSNumber numberWithDouble:1.0], kCIAttributeSliderMax,
64 // [NSNumber numberWithDouble:1.0], kCIAttributeDefault,
65 // [NSNumber numberWithDouble:1.0], kCIAttributeIdentity,
66 // kCIAttributeTypeScalar, kCIAttributeType, nil], @"inputOpacity", nil]];
69 - (NSDictionary*)customAttributes
71 return [NSDictionary dictionaryWithObjectsAndKeys:
72 [NSDictionary dictionaryWithObjectsAndKeys:
73 [NSNumber numberWithDouble:0.0], kCIAttributeMin,
74 [NSNumber numberWithDouble:1.0], kCIAttributeMax,
75 [NSNumber numberWithDouble:0.0], kCIAttributeSliderMin,
76 [NSNumber numberWithDouble:1.0], kCIAttributeSliderMax,
77 [NSNumber numberWithDouble:1.0], kCIAttributeDefault,
78 [NSNumber numberWithDouble:1.0], kCIAttributeIdentity,
79 kCIAttributeTypeScalar, kCIAttributeType, nil], @"inputOpacity", nil];
82 - (CIImage*)outputImage
84 CISampler *src = [CISampler samplerWithImage:inputImage];
86 return [self apply:s_opacityKernel, src, inputOpacity, kCIApplyOptionDefinition, [src definition], nil];
89 + (CIFilter*)filterWithName:(NSString *)name
93 filter = [[self alloc] init];
94 return [filter autorelease];