aduros / flambe

Rapidly cook up games for HTML5, Flash, Android, and iOS.
https://github.com/aduros/flambe/wiki
MIT License
745 stars 118 forks source link

Stage3DTextureRoot.readPixels wrong ARGB to RGBA conversion #359

Open FredoFidel opened 8 years ago

FredoFidel commented 8 years ago

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