Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug: PremultipliedAlpha is not working for png #19112

Closed
wants to merge 1 commit into from

Conversation

chongchaoyu
Copy link

No description provided.

@chongchaoyu chongchaoyu changed the title PremultipliedAlpha is not working for png Fixbug: PremultipliedAlpha is not working for png Oct 12, 2018
@chongchaoyu chongchaoyu changed the title Fixbug: PremultipliedAlpha is not working for png Fix bug: PremultipliedAlpha is not working for png Oct 12, 2018
@@ -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

@chongchaoyu
Copy link
Author

New PR is #19138.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants