Skip to content

Allow RenderTexture to save out non-premultiplied alpha images #19781

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

Closed
rh101 opened this issue May 30, 2019 · 0 comments
Closed

Allow RenderTexture to save out non-premultiplied alpha images #19781

rh101 opened this issue May 30, 2019 · 0 comments
Milestone

Comments

@rh101
Copy link
Contributor

rh101 commented May 30, 2019

  • cocos2d-x version: 3.17.1
  • devices test on: Win32
  • developing environments
    • NDK version: N/A
    • Xcode version: N/A
    • VS version: VS2019

Steps to Reproduce:

The current implementation of RenderTexture has several issues.

Firstly, it does not set the premultiplied alpha flag on the image created by this method:

Image* RenderTexture::newImage(bool flipImage)
{
...
            image->initWithRawData(buffer, savedBufferWidth * savedBufferHeight * 4, savedBufferWidth, savedBufferHeight, 8);
        }
        else
        {
            image->initWithRawData(tempData, savedBufferWidth * savedBufferHeight * 4, savedBufferWidth, savedBufferHeight, 8);
        }
...
}

The correct code would be to change the initWithRawData calls to this:

            image->initWithRawData(buffer, savedBufferWidth * savedBufferHeight * 4, savedBufferWidth, savedBufferHeight, 8, true);
        }
        else
        {
            image->initWithRawData(tempData, savedBufferWidth * savedBufferHeight * 4, savedBufferWidth, savedBufferHeight, 8, true);

Secondly, there is no way to choose if you want to save the file as a non-premultiplied alpha PNG.

Reversing the PMA before saving the image is possible, and a new method can be added to do this, such as: RenderTexture::saveToFileAsNonPMA().

I'll create a pull request with the changes, along with modification of the tests to cater for this new method.

This fix may work for the following reported issues:
#18980
#18193

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

No branches or pull requests

2 participants