Jump to content

processPixelRGB not working in Safari


charlie_says
 Share

Recommended Posts

  • 4 weeks later...
On my iPad in Safari and Chrome "processPixelRGB" and "replaceRGB" methods don't work too.

But if you need to replace the color of the pixels, you can use something like this:

 

// BitmapData object in which we want replace color of pixels

var my_bitmapdata;

 

// RGBA of the color you want to replace

var r = 255;

var g = 255;

var b = 255;

var a = 255;

 

// RGBA of new color

var new_r, new_g, new_b, new_a;

 

var imgdata = my_bitmapdata.ctx.getImageData(0, 0, width, height);

var imgdatalen = imgdata.data.length;

 

// Iterate over every pixel in the bitmapdata

for (var i=0; i< imgdatalen/4; i++) {  

                

    if ( (imgdata.data[4*i] === r) && (imgdata.data[4*i+1] === g) && (imgdata.data[4*i+2] === b ) {

 

         imgdata.data[4*i] = new_r;    // RED (0-255)

         imgdata.data[4*i+1] = new_g;    // GREEN (0-255)

         imgdata.data[4*i+2] = new_b;    // BLUE (0-255)

         imgdata.data[4*i+3] = new_a;  // APLHA (0-255)

     }

}

 

my_bitmapdata.ctx.putImageData(imgdata, 0, 0);

 

In my case it is works properly.

Link to comment
Share on other sites

  • 2 weeks later...
  • 1 month later...
the processPixelRGB uses the setPixel32() to write and the getPixel() to read.

the getPixel() works on safari because uses the this.data instead of the this.pixels.

 

I think that modifying the BitmapData::setPixel32  with something like this: 

 

 

setPixel32: function (x, y, red, green, blue, alpha, immediate) {

 

        if (typeof immediate === 'undefined') { immediate = true; }

 

        if (x >= 0 && x <= this.width && y >= 0 && y <= this.height)

        {

            if (Phaser.Device.LITTLE_ENDIAN)

            {

                this.pixels[y * this.width + x] = (alpha << 24) | (blue << 16) | (green << 8) | red;

            }

            else

            {

                this.pixels[y * this.width + x] = (red << 24) | (green << 16) | (blue << 8) | alpha;

            }

            

        if(this.data!=null)

        {

             var index = ~~(x + (y * this.width));

            index*=4;

          this.data[index] = red;

         this.data[++index] = green;

          this.data[++index] = blue;

            this.data[++index] = alpha;

 

        }

 

            if (immediate)

            {

                this.context.putImageData(this.imageData, 0, 0);

                this.dirty = true;

            }

        }

 

        return this;

 

    },

 

 

should work.

basically on safari (osx and ios)  the this.pixels (the 32bit packed format) does not work and we have to use the this.data (separated compos).
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...