Skip to content
This repository has been archived by the owner on Jun 29, 2021. It is now read-only.

Commit

Permalink
register filter with display name
Browse files Browse the repository at this point in the history
  • Loading branch information
YuAo committed Jan 31, 2016
1 parent 9268bd7 commit eb96e53
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 22 deletions.
3 changes: 2 additions & 1 deletion Sources/YUCIColorLookup.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ + (void)load {
if ([CIFilter respondsToSelector:@selector(registerFilterName:constructor:classAttributes:)]) {
[CIFilter registerFilterName:NSStringFromClass([YUCIColorLookup class])
constructor:[YUCIFilterConstructor constructor]
classAttributes:@{kCIAttributeFilterCategories: @[kCICategoryStillImage,kCICategoryVideo,kCICategoryColorEffect,kCICategoryInterlaced,kCICategoryNonSquarePixels]}];
classAttributes:@{kCIAttributeFilterCategories: @[kCICategoryStillImage,kCICategoryVideo,kCICategoryColorEffect,kCICategoryInterlaced,kCICategoryNonSquarePixels],
kCIAttributeFilterDisplayName: @"Color Lookup"}];
}
}
});
Expand Down
3 changes: 2 additions & 1 deletion Sources/YUCIRGBToneCurve.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ + (void)load {
if ([CIFilter respondsToSelector:@selector(registerFilterName:constructor:classAttributes:)]) {
[CIFilter registerFilterName:NSStringFromClass([YUCIRGBToneCurve class])
constructor:[YUCIFilterConstructor constructor]
classAttributes:@{kCIAttributeFilterCategories: @[kCICategoryStillImage,kCICategoryVideo, kCICategoryColorAdjustment,kCICategoryInterlaced]}];
classAttributes:@{kCIAttributeFilterCategories: @[kCICategoryStillImage,kCICategoryVideo, kCICategoryColorAdjustment,kCICategoryInterlaced],
kCIAttributeFilterDisplayName: @"RGB Tone Curve"}];
}
}
});
Expand Down
24 changes: 7 additions & 17 deletions VividDemo/VividDemo/FilterStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,24 @@

import CoreImage

class FilterItem {
let name: String
let filter: CIFilter?

init(name: String, filter: CIFilter?) {
self.name = name
self.filter = filter
}
}

class FilterStore {
static let filters: [FilterItem] = {
var filters = [FilterItem]()
static let filters: [CIFilter?] = {
var filters = [CIFilter?]()

filters.append(FilterItem(name: "No Filter", filter: nil))
filters.append(nil)

filters.append(FilterItem(name: "Color Lookup", filter: CIFilter(
filters.append(CIFilter(
name: "YUCIColorLookup",
withInputParameters:[
"inputColorLookupTable": CIImage(contentsOfURL: NSBundle.mainBundle().URLForResource("color_lookup_miss_etikate", withExtension: "png")!)!
]))
])
)

filters.append(FilterItem(name: "RGB Tone Curve", filter: CIFilter(
filters.append(CIFilter(
name: "YUCIRGBToneCurve",
withInputParameters:[
"inputRGBCompositeControlPoints": [CIVector(x: 0, y: 0),CIVector(x: 0.5, y: 0.7), CIVector(x: 1, y: 1)]
]))
])
)

return filters
Expand Down
7 changes: 4 additions & 3 deletions VividDemo/VividDemo/MainWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ class MainWindowController: NSWindowController {

self.filtersToolbarItem.minSize.height = 32
self.filtersPopUpButton.menu?.removeAllItems()
for filterItem in FilterStore.filters {
let menuItem = NSMenuItem(title: filterItem.name, action: nil, keyEquivalent: "")
menuItem.representedObject = filterItem.filter
for filter in FilterStore.filters {
let filterName = (filter?.attributes[kCIAttributeFilterDisplayName] as? String) ?? "Unknown"
let menuItem = NSMenuItem(title: (filter != nil ? filterName : "No Filter"), action: nil, keyEquivalent: "")
menuItem.representedObject = filter
self.filtersPopUpButton.menu?.addItem(menuItem)
}
}
Expand Down

0 comments on commit eb96e53

Please sign in to comment.