Skip to content

Stage3DTextureRoot.readPixels wrong ARGB to RGBA conversion #359

Description

@FredoFidel

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions