关于Pixel Bender

Mobius posted @ 2010年10月30日 06:16 in 未分类 with tags flash Pixel Bender Action Script 3 , 11415 阅读

Pixel Bender介绍

 

下面是摘自Adobe官方文档 Adobe Pixel Bender Developer’s Guide对Pixel Bender的介绍:

 

The Adobe Pixel Bender technology delivers a common image and video processing infrastructure which provides automatic runtime optimization on heterogeneous hardware. You can use the Pixel Bender kernel language to implement image processing algorithms (filters or effects) in a hardware-independent manner.

 

翻译(翻得烂,建议大家还是看原文吧):

Pixel Bender是Adobe开发的一套针对图像、视频处理的底层框架,可以依赖于多种不同硬件来进行优化加速。使用Pixel Bender,需要用专门的语言Pixel Bender kernel来编写图像处理逻辑(比如自定义滤镜或者特效)。

 

Pixel Bender development offers many advantages:

  1. Low learning curve Pixel Bender offers a small number of tools that are sufficient to write complex image-processing algorithms. Learning Pixel Bender is easier than learning C/C++ and each application’s plug-in SDK. You do not need to know any graphics shading language or multi-threading APIs.

  2. Parallel processing Pixel Bender allows the same filter to run efficiently on different GPU and CPU architectures, including multi-core and multiprocessor systems. It delivers excellent image processing performance in Adobe products.

  3. Supports all bit-depths The same kernel runs in 8-bit/16-bit/32-bit within the application.

  4. Support by multiple Adobe applications Pixel Bender is integrated with multiple Adobe applications. It allows you to develop filters that are portable among various Adobe products. There is an active Pixel Bender Exchange where developers share their filters.

 

翻译: 

Pixel Bender的优点:

  1. 容易学习。Pixel Bender提供了一些功能齐全的工具,可用于编写复杂的图像处理逻辑。学习简单,使用类似C++的语法,结构简单,而且不要求开发人员对图像shading language基础或多线程的API有所了解。
  2. 在8-bit/16-bit/32-bit的机器上都可运行。
  3. 多款Adobe产品支持(Photoshop、After Effect、Flash)。(“在一定规范下” -- 译者注)开发人员可编写一款各产品通用的滤镜。在Pixel Bender Exchange上,有很多开发人员还分享出来他们编写的滤镜。

 

Pixel Bender技术可应用于 Photoshop、After Effect、Flash等Adobe产品,但对于Flash的应用,会有比较大的限制:

  1. 只能应用使用ActionScript 3.0编写的swf,且使用Flash Player 10.0之后的版本。
  2. 除了if/else,无法使用任何形式的循环和其他程序流控制。
  3. 不支持数组。
  4. 不允许自定义函数或库。
  5. 不允许使用region functions。
  6. 不允许使用dependent values
  7. non-constant indices into vector values
  8. 无法调用GPU资源(至少到目前2010年10月份为止是这样)

 

=_=|||
确实是很多限制,一开始想使用Pixel Bender对Flash展示层做大规模优化的幻想破灭了。

 

 

Pixel Bender的应用场合

 

对于Pixel Bender的应用,主要有下面几种:

  • 自定义滤镜
  • 填充:即某块区域的绘制完全由Pixel Bender来生成,比如可用于制作游戏中特效。
  • Blend Mode
  • 32位的浮点运算(这一点是比较神奇,但不在谈论之列,后续可以再另外分享)

 

但是,有时候使用Pixel Bender写的滤镜效率并没有想象中那么高。下面有个例子:

首先,大家可以先看一下StackOverFlow上的这个贴:using PixelBender to double the size of a bitmap.

提问者提出了一个问题:

同样是将一张图片的尺寸放大一倍,使用Pixel Bender,和使用AS3自带的库类BitmapData.draw()方法,在执行时间上分别是前者是后者的4倍。

后面就有人回答:

在这个场景中,Pixel Bender代码对比的对象,其实是player底层代码(因为想BitmapData这种类肯定是player底层实现的),而不是ActionScript 3。所以对于一些player原生支持的功能,如果用Pixel Bender重新实现一遍,并不会快于player(否则,Adobe的工程师们早就利用Pixel Bender的技术去提高Flash Player的执行效率了)。

 

因此,Pixel Bender的效率应该是高于(远远高于)使用ActionScript直接控制像素;但在同一程序逻辑下,不会高于player本身的效率。

那么,Pixel Bender的应用场合应该是:当需要写一些自定义、灵活的滤镜效果,这时候就应该使用它。它是对那些效率高但不灵活的滤镜效果(player自带的)和效率低但很灵活的滤镜效果(AS3写)的一个折衷。

 

 

Pixel Bender与Flash结合的运行方式 

 

在Flash Player 10里集成了有一个Pixel Bender runtime,解释运行由Pixel Bender toolkit生成了pbj文件。Pixel Bender runtime之于pbj,就相当于Flash Player之于swf。

Pixel Bender runtime是使用多线程的,不会和player使用同一线程。在多核的机器上,可以使用多个cpu资源,所以在效率上是有很大提高的,而且不会导致Flash UI的阻塞。所以,我猜上一节中的案例应该是在单核环境中的。如果在多核环境中,Pixel Bender多个线程的执行速度应该会高于player一个线程的速度。

目前版本的Pixel Bender runtime(2010年10月份)是无法支持GPU加速的。那既然Pixel Bender Toolkit有GPU模式,那为什么不把这个功能集成到Flash Player中呢?这篇文章(Adobe Pixel Bender in Flash Player 10 Beta)有做介绍。作者是Flash Player的工程师,诉尽苦衷,主要考虑的还是那两个方面:1.平台兼容性;2.Flash Player的大小。

 

 

 

 

 参考资料

 

单色化滤镜的代码(MonochromeFilter.pbk)

<languageVersion: 1.0;>

kernel MonochromeFilter
<
    namespace: "com.tencent.qqshow";
    vendor: "Tencent";
    version: 1;
    description: "Monochrome Filter";
>
{
    parameter pixel4 color
    <
        defaultValue: float4(0.5, 0.5, 0.5, 1);
    >;
    
    output pixel4 dst;
    
    input image4 src;    

    void evaluatePixel()
    {
        pixel4 c = sampleNearest(src, outCoord());
        pixel4 target = c;
        
        //caculate the 256 grey level
        float gl = c.r * 0.3086 + c.g * 0.6094 + c.b * 0.082;
                
        if(gl < 0.5)
        {
            target.r = color.r * gl * 2.0;
            target.g = color.g * gl * 2.0;
            target.b = color.b * gl * 2.0;
        }
        else
        {
            target.r = color.r + (1.0 - color.r) * (gl - 0.5) * 2.0;
            target.g = color.g + (1.0 - color.g) * (gl - 0.5) * 2.0;
            target.b = color.b + (1.0 - color.b) * (gl - 0.5) * 2.0;
        }
        
        dst = target;
    }
}
Avatar_small
Layla Stephens 说:
2019年2月19日 13:32

The function of the mobile is chanced out for the suspects in the field. All the issues of the superior papers are narrated safely for the persons. The citizenship is regulated for the midst of the facilities for the clients in the functional program.

Avatar_small
gujarati whatsapp st 说:
2020年7月16日 15:00

Hello guys...this whatsapp status information is very useful for users.i like this post.please download some video in whatsapp for gujarati friends.
<a href="https://whatsappstatuses.xyz/category/gujarati/
">gujarati status video download</a>

Avatar_small
net worth 说:
2024年1月15日 15:47

The net worth of a person expresses how rich and popular they are, let's see who is the #1 at the present in idol net worth

Avatar_small
seo service london 说:
2024年5月18日 19:12

Thank you for the great piece of information. i would like to share some of the ethical argument topics and exploratory essay topics that you can help you when writing. once again thank you for awesome platform. I recently came across your blog and have been reading along. I thought I would leave my first comment. I don't know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often. Many thanks to you for sharing these kinds of wonderful content. In addition,

Avatar_small
카지노헌터 说:
2024年7月14日 14:08

Thanks for sharing this interesting article, I really appreciate it.You may be focused on unusual cracks and break in your walls, your home has a problem with the foundation. Do not worry about it we can create a solid foundation for your property by giving the highest quality sub-floor work. Our company is specialized in underpinning, restumping, and subfloor repairs.

Avatar_small
insolitofestival 说:
2024年7月14日 14:09

high-quality info! I latterly came across your weblog and were studying along. I notion i'd depart my first comment. I don’t realize what to mention except that i've. I clearly recognize the form of subjects you put up here. Thanks for sharing us a amazing statistics this is honestly useful. Good day! Thanks very an awful lot for this beneficial article. I really like it. This is an extraordinary motivating article. I'm practically satisfied along with your exceptional work. You put really extraordinarily supportive facts.

Avatar_small
here 说:
2024年7月14日 14:13

specially produced to cool consistently and help you display the products inside. So while the display increases product clarity, the clarity increases sales. And more sales mean more value for you.

Avatar_small
todongsan 说:
2024年7月14日 14:15

Worldwide best and fastest 3d Rendering outsource providers, Services may like Australia, Canada, United states, United kingdom, Newzealand and China countries, We 3D Rendering China provides many services for a purpose like 3d Industrial modeling,3d Architectural Rendering, 3d Medical Illustration

Avatar_small
website 说:
2024年7月14日 14:16

Really decent post. I just discovered your weblog and needed to say that I have truly delighted in searching your blog entries. After all I'll be subscribing to your food and I trust you compose again soon! This article was written by a real thinking writer. I agree many of the with the solid points made by the writer. I’ll be back. Thank you for helping people get the information they need. Great stuff as usual. Keep up the great work!!! Positive site, 

Avatar_small
먹튀검증백과 说:
2024年7月14日 14:17

advanced claim, desist stirring amongst this terrific perform. it is fine to understand that this topic is brute furthermore blanketed upon this internet site consequently commendation for taking the era to discuss this! thanks anew and once formerly anew!

Avatar_small
website 说:
2024年7月14日 14:19

Great article you shared here. Thanks for sharing this valuable article. If you are interested in learning how bathroom mirrors decorate your space Great site! I'm glad that I found U!

Avatar_small
먹튀프렌즈 说:
2024年7月14日 14:20

May I just say what a comfort to discover someone who actually knows what they are talking about online. You definitely realize how to bring an issue to light and make it important. More people should look at this and understand this side of your story. I was surprised you’re not more popular because you certainly possess the gift.|

Avatar_small
information 说:
2024年7月14日 14:22

advanced claim, desist stirring amongst this terrific perform. it is fine to understand that this topic is brute furthermore blanketed upon this internet site consequently commendation for taking the era to discuss this! thanks anew and once formerly anew!

Avatar_small
카디즈 说:
2024年7月14日 14:24

Worldwide best and fastest 3d Rendering outsource providers, Services may like Australia, Canada, United states, United kingdom, Newzealand and China countries, We 3D Rendering China provides many services for a purpose like 3d Industrial modeling,3d Architectural Rendering, 3d Medical Illustration

Avatar_small
메이저놀이터 说:
2024年7月14日 14:25

Really decent post. I just discovered your weblog and needed to say that I have truly delighted in searching your blog entries. After all I'll be subscribing to your food and I trust you compose again soon! This article was written by a real thinking writer. I agree many of the with the solid points made by the writer. I’ll be back. Thank you for helping people get the information they need. Great stuff as usual. Keep up the great work!!! Positive site, 

Avatar_small
get more info 说:
2024年7月14日 14:27

Really decent post. I just discovered your weblog and needed to say that I have truly delighted in searching your blog entries. After all I'll be subscribing to your food and I trust you compose again soon! This article was written by a real thinking writer. I agree many of the with the solid points made by the writer. I’ll be back. Thank you for helping people get the information they need. Great stuff as usual. Keep up the great work!!! Positive site, 

Avatar_small
touch-of-classic 说:
2024年7月14日 14:29

Worldwide best and fastest 3d Rendering outsource providers, Services may like Australia, Canada, United states, United kingdom, Newzealand and China countries, We 3D Rendering China provides many services for a purpose like 3d Industrial modeling,3d Architectural Rendering, 3d Medical Illustration

Avatar_small
View data 说:
2024年7月14日 14:30

Yes i am totally agreed with this article and i just want say that this article is very nice and very informative article.I will make sure to be reading your blog more. You made a good point but I can't help but wonder, what about the other side? !!!!!!THANKS!!!!!!

Avatar_small
View data 说:
2024年7月14日 14:31

Greetings, I do calculate your blog may really be having web program likeness issues. Whenever I research your blog in Safari, it looks fine anyway when opening in Internet Explorer, it makes them cover issues. I basically expected to give you a fast watch out! Other than that, great blog! This was really an entrancing point and I fairly agree with what you have referred to here!Hello, I have examined by far most of your posts. This post is apparently where I got the most supportive information for my investigation. An obligation of appreciation is all together for posting

Avatar_small
get more info 说:
2024年7月14日 16:55

Thank You So much for the informative blog. My Name Is Addy Carter here I can share some websites where you can get free calendars. These calendars are helpful in scheduling your daily weekly and monthly tasks. With the help of these websites, you can touch with your daily important tasks. All of these calendars are free of cost and offer PDF, Word, and other formats and a handy minimalist design that makes calendars easy to use and practical. For more information visit our website.

Avatar_small
good contents 说:
2024年7月14日 16:58

Thanks for every other excellent post. The place else may just anybody get that kind of information in such an ideal method of writing?I have a presentation next week, and I’m at the search for such info

Avatar_small
실험실먹튀검증 说:
2024年7月14日 18:43

Over these years, we have emerged as one of the most successful clinics in India and across the globe in offering infertility treatments. KIC is always at the forefront of research and development taking place in the global arena of infertility.

Avatar_small
모두의토토 说:
2024年7月14日 18:47

extremely good info! I lately got here throughout your weblis put up highly useful for me, because it consists of a part of facts. I typically want to peruse tke sure to be studying your weblog extra. You made an excellent point however i can't help however marvel, what approximately the alternative aspect? !!!!!! Thank you

Avatar_small
good information 说:
2024年7月14日 20:06

Please let me know if you’re looking for a article writer for your site. You have some really great posts and I feel I would be a good asset. If you ever want to take some of the load off, I’d absolutely love to write some material for your blog in exchange for a link back to mine. Please send me an email if interested. Thank you

Avatar_small
good contents 说:
2024年7月14日 20:41

Thanks for sharing this interesting article, I really appreciate it.You may be focused on unusual cracks and break in your walls, your home has a problem with the foundation. Do not worry about it we can create a solid foundation for your property by giving the highest quality sub-floor work. Our company is specialized in underpinning, restumping, and subfloor repairs.

Avatar_small
More details 说:
2024年7月14日 21:20

once i in the beginning commented i seem to have clicked on the -notify me whilst new feedback are brought- checkbox and now each time a comment is brought i am getting 4 emails with the exact equal comment. Is there a way you're capable of take away me from that provider? Thank you! When i look at your weblog web site in opera, it appears first-rate but whilst starting in net explorer, it has a few overlapping. 

Avatar_small
good information 说:
2024年7月14日 21:22

it is extremely important and large to pick out to your goods from an extensive sort of holograms reachable in the market these days. Hologram stickers are one of the exceptional strategies, and it is going to be a useful technique to your business. I should search web sites with applicable facts on given subject matter and provide them to instructor our opinion and the object.

Avatar_small
information 说:
2024年7月14日 22:23

Great article you shared here. Thanks for sharing this valuable article. If you are interested in learning how bathroom mirrors decorate your space Great site! I'm glad that I found U!

Avatar_small
totosidae 说:
2024年7月14日 22:27

I assume that is an informative proclaim and it is selected beneficial and informed. therefore, i might as soon as to thank you for the efforts you have got made in writing this newsletter.

Avatar_small
website 说:
2024年7月14日 23:08

Greetings, I do calculate your blog may really be having web program likeness issues. Whenever I research your blog in Safari, it looks fine anyway when opening in Internet Explorer, it makes them cover issues. I basically expected to give you a fast watch out! Other than that, great blog! This was really an entrancing point and I fairly agree with what you have referred to here

Avatar_small
토스맨 说:
2024年7月14日 23:09

high-quality info! I latterly came across your weblog and were studying along. I notion i'd depart my first comment. I don’t realize what to mention except that i've. I clearly recognize the form of subjects you put up here. Thanks for sharing us a amazing statistics this is honestly useful. Good day! Thanks very an awful lot for this beneficial article. I really like it. This is an extraordinary motivating article. I'm practically satisfied along with your exceptional work. You put really extraordinarily supportive facts.

Avatar_small
먹튀위젯 说:
2024年7月14日 23:54

Excellent read, I just passed this onto a friend who was doing a little research on that. And he actually bought me lunch as I found it for him smile Therefore let me rephrase that: Thank you for lunch


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter