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

Stage3DTextureRoot.readPixels wrong ARGB to RGBA conversion #359

Open
FredoFidel opened this issue Dec 16, 2015 · 0 comments
Open

Stage3DTextureRoot.readPixels wrong ARGB to RGBA conversion #359

FredoFidel opened this issue Dec 16, 2015 · 0 comments

Comments

@FredoFidel
Copy link

Line 65 in method readPixels the conversion from ARGB to RGBA give AGBA, not RGBA

Current conversion method :

    public function readPixels (x :Int, y :Int, width :Int, height :Int) :Bytes
    {
        assertNotDisposed();

        var bitmapData = _renderer.batcher.readPixels(this, x, y, width, height);
        var pixels = Bytes.ofData(bitmapData.getPixels(new Rectangle(0, 0, width, height)));
        bitmapData.dispose();

        var ii = 0, ll = pixels.length;
        while (ii < ll) {
            // Convert from ARGB to RGBA
            var alpha = pixels.get(ii);
            pixels.set(ii, pixels.get(++ii));
            pixels.set(ii, pixels.get(++ii));
            pixels.set(ii, pixels.get(++ii));
            pixels.set(ii, alpha);
            ++ii;
        }

        return pixels;
    }

Fixed conversion :

    public function readPixels (x :Int, y :Int, width :Int, height :Int) :Bytes
    {
        assertNotDisposed();

        var bitmapData = _renderer.batcher.readPixels(this, x, y, width, height);
        var pixels = Bytes.ofData(bitmapData.getPixels(new Rectangle(0, 0, width, height)));
        bitmapData.dispose();

        var ii = 0, ll = pixels.length;
        while (ii < ll) {
            // Convert from ARGB to RGBA
            var alpha = pixels.get(ii);
            pixels.set(ii, pixels.get(ii+1));
            pixels.set(ii+1, pixels.get(ii+2));
            pixels.set(ii+2, pixels.get(ii+3));
            pixels.set(ii+3, alpha);
            ii+=4; 
        }

        return pixels;
    }
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

1 participant