Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cocos/platform/CCImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,11 @@ bool Image::initWithPngData(const unsigned char * data, ssize_t dataLen)
{
premultipliedAlpha();
}
else
{
_hasPremultipliedAlpha = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why enable premultipliedAlpha even png format isn't RGBA8888, any errors? maybe you use CCImage in wrong way.

Copy link
Author

@chongchaoyu chongchaoyu Oct 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@drelaptop
oh, yes, if png format is not RGBA8888, premultipliedAlpha should not be true.

But, there is a case, I want to use PMA pngs to improve performance and prevent blend artifacts, so I use Image::setPNGPremultipliedAlphaEnabled(false), but it doesn't work, because CCImage.hasPremultipliedAlpha() will return false at Texture2D::initWithImage if you don't set premultipliedAlpha to true when png format is RGBA8888.

I will resubmit a PR, the code is like the followings:
1

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@drelaptop The new PR is #19138, you can check it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, you hope CCImage.hasPremultipliedAlpha() return true, but you did setPNGPremultipliedAlphaEnabled(false) before. that is confusing.

no need to new a PR for same bug fix, you can commit to same branch, then PR will auto update.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@drelaptop setPNGPremultipliedAlphaEnabled(false) changes PNG_PREMULTIPLIED_ALPHA_ENABLED to false, it tells cocos2dx that pngs have been PMAed by developers, so cocos2dx needn't to do premultipliedAlpha, premultipliedAlpha takes about 40ms for 2048*2048 pngs.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@drelaptop I read CCImage.cpp, and setPNGPremultipliedAlphaEnabled(false) maybe the only way to use PMAed pngs.
Doesn't cocos2dx support PMAed pngs?
2

}


if (row_pointers != nullptr)
{
Expand Down