是否可以通过我的应用程序分发图像单元?
Mac OS X Mavericks
我被告知该问题已在 Mac OS X 10.9 中修复
原始
我阅读了文档,但没有找到答案。它建议创建图像单元,需要将此单元放入 ~/Library/Graphics/Image Units
或 /Library/Graphics/Image Units
(将图像单元放入Your.app/Contents/Library/Graphics/Image Units
内无效)。
还有其他不推荐的方法来创建图像单元,它允许您分发 cikernels 并从代码中访问过滤器。但它会阻止您创建不可执行的过滤器,这会严重降低性能。
我查看了 Pixelmator 或 Acorn 等应用程序包的内容,发现它们也不使用图像单元。我希望这是一个错误,并且有一种方法可以在应用程序包中分发图像单元。
我正在寻找一种能够被 Mac App Store 验证接受的解决方案。
不允许使用不可执行过滤器的解决方案
从 CIPlugIn 标头: /** 加载由其 URL 指定的插件。 */
+ (void)loadPlugIn:(NSURL *)url allowNonExecutable:(BOOL)allowNonExecutable
AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_7;
/** Loads a plug-in specified by its URL.
If allowExecutableCode is NO, filters containing executable code will not be loaded. If YES, any kind of filter will be loaded. */
+ (void)loadPlugIn:(NSURL *)url allowExecutableCode:(BOOL)allowExecutableCode
AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER;
新方法未在官方文档中列出。因此,要加载包,您只需执行以下操作:
if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_6)
{
[CIPlugIn loadPlugIn:[[NSBundle mainBundle] URLForResource:@"YourPlugin" withExtension:@"plugin"]
allowNonExecutable:YES];
}
else
{
[CIPlugIn loadPlugIn:[[NSBundle mainBundle] URLForResource:@"YourPlugin" withExtension:@"plugin"]
allowExecutableCode:YES];
}
不幸的是,如果您尝试将 CIFilter 与 QuartzCore 框架(例如,与 CALayer)一起使用,应用程序将因堆栈溢出而崩溃。
frame #0: 0x00007fff8b6a5d36 CoreImage`-[CIFilter copyWithZone:] + 12
frame #1: 0x00007fff8b7d1c7e CoreImage`-[CIPlugInStandardFilter _provideFilterCopyWithZone:] + 18
frame #2: 0x00007fff8b6a5d59 CoreImage`-[CIFilter copyWithZone:] + 47
frame #3: 0x00007fff8b7d1c7e CoreImage`-[CIPlugInStandardFilter _provideFilterCopyWithZone:] + 18
frame #4: 0x00007fff8b6a5d59 CoreImage`-[CIFilter copyWithZone:] + 47
frame #5: 0x00007fff8b7d1c7e CoreImage`-[CIPlugInStandardFilter _provideFilterCopyWithZone:] + 18
frame #6: 0x00007fff8b6a5d59 CoreImage`-[CIFilter copyWithZone:] + 47
Mac OS X Mavericks
I was told that the issue was fixed in Mac OS X 10.9
Original
I read the documentation and didn't find the answer. It suggests to create Image Units, it requires to put this unit inside either ~/Library/Graphics/Image Units
or /Library/Graphics/Image Units
(putting the image unit inside Your.app/Contents/Library/Graphics/Image Units
has no effect).
There is other, non-recommeneded way, to create Image Unit, which allows you to distribute cikernels and access the filter from your code. But it prevent you from creating non executable filters which is a big lack of performance.
I looked through the contents of bundles of applications like Pixelmator or Acorn and found that they don't use Image Units as well. I hope this is a mistake and there is a way to distribute Image Units within an application bundle.
I'm looking for a solution that will be accepted by Mac App Store validation.
Solution which doesn't allow you to use non executable filters
From the CIPlugIn header:
/** Loads a plug-in specified by its URL. */
+ (void)loadPlugIn:(NSURL *)url allowNonExecutable:(BOOL)allowNonExecutable
AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_7;
/** Loads a plug-in specified by its URL.
If allowExecutableCode is NO, filters containing executable code will not be loaded. If YES, any kind of filter will be loaded. */
+ (void)loadPlugIn:(NSURL *)url allowExecutableCode:(BOOL)allowExecutableCode
AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER;
New method isn't listed in official docs. So, to load bundle you simply do:
if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_6)
{
[CIPlugIn loadPlugIn:[[NSBundle mainBundle] URLForResource:@"YourPlugin" withExtension:@"plugin"]
allowNonExecutable:YES];
}
else
{
[CIPlugIn loadPlugIn:[[NSBundle mainBundle] URLForResource:@"YourPlugin" withExtension:@"plugin"]
allowExecutableCode:YES];
}
Unfortunately if you try to use CIFilter with QuartzCore framework (e.g. with CALayer) app will crash because of stack overflow.
frame #0: 0x00007fff8b6a5d36 CoreImage`-[CIFilter copyWithZone:] + 12
frame #1: 0x00007fff8b7d1c7e CoreImage`-[CIPlugInStandardFilter _provideFilterCopyWithZone:] + 18
frame #2: 0x00007fff8b6a5d59 CoreImage`-[CIFilter copyWithZone:] + 47
frame #3: 0x00007fff8b7d1c7e CoreImage`-[CIPlugInStandardFilter _provideFilterCopyWithZone:] + 18
frame #4: 0x00007fff8b6a5d59 CoreImage`-[CIFilter copyWithZone:] + 47
frame #5: 0x00007fff8b7d1c7e CoreImage`-[CIPlugInStandardFilter _provideFilterCopyWithZone:] + 18
frame #6: 0x00007fff8b6a5d59 CoreImage`-[CIFilter copyWithZone:] + 47
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除了您提到的库路径之外,Mac OS X 还会在
YourApp.app/Contents/Library
中查找。我认为如果您将图像单元放入
YourApp.app/Contents/Library/Graphics/Image Units/
中,一切都应该有效。As well as the Library paths you mention, Mac OS X will also look in
YourApp.app/Contents/Library
.I think everything should work if you put your Image Unit in
YourApp.app/Contents/Library/Graphics/Image Units/
.