Re: [cocos2d-js-devel] Alpha Premultiplied Issue

31 views
Skip to first unread message

huabing.xu

unread,
May 29, 2014, 10:35:09 PM5/29/14
to Vision Ke, Ricardo Quesada, cocos2d-js-devel

Thanks Vision,


This data suggest that if we add premultiply alpha back when reading a png file. The performance decrease is no more than 25% in the worst cases. 


In fact if the code is called per frame, it cound be a huge performance penalty. But for loading of png file, in most cases, the data is not bad. For the running of this code snap cound be very infrequently.


If no one object to this, we will send to pull request to cocos2d repo to fix the ugly bug complained by our customers.


Thanks.


Best Regards
Harrison Xu

 Original Message 
Sender: Vision Ke<visibl...@gmail.com>
Recipient: cocos2d-js-devel<cocos2d-...@googlegroups.com>
Date: Thursday, May 29, 2014 02:56
Subject: [cocos2d-js-devel] Alpha Premultiplied Issue

Hi guys,

We have a bug reported that sprites initialized with transparent images have unpleasant black border in some cases.
http://www.cocos2d-x.org/issues/4850

There are more discussions from another thread illustrating the same issue.

The root cause has been figured out. When loading a PNG file as texture, we did alpha premultiplied operations in cocos2d-x 2.x, this is why it worked fine. But seems the behavior had been changed since 3.0 alpha, those codes had been removed on account of performance optimization.

We might have to bring the old codes back to resolve this issue. So I did some tests to see the performance decrease affected by enabling alpha premultiplied today.
The tests simply created several sprites with PNG images of different sizes, and recored their time costs respectively.
Below are the final result (on iPhone4s):

Image Size             Enable Alpha Premultiplied (µs)           Disable Alpha Premultiplied(µs)
32x32                     6770                                                 6126
64x64                     7676                                                 7169
128x128                 12569                                                10769
256x256                 41821                                                30948
512x512                 148200                                              120519
1024x1024              577649                                              470119

As is seen, when alpha premultiplied is enabled, the loading time increased by about 10~20%.

I am not sure if we should bring alpha premultiplied back for PNG. Besides the influence of performance, there might be some other things affected too.

Any suggestion for that?

Thanks.

--
You received this message because you are subscribed to the Google Groups "cocos2d JS development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cocos2d-js-dev...@googlegroups.com.
To post to this group, send email to cocos2d-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages