When you use bitshifting and the pixel array directly, it doesn't seem to greatly impact the fps.
Code Example
Code Example
- // Tested with Processing 2.0b8
- PGraphics pg;
- void setup() {
- size(500, 500, P2D);
- pg = createGraphics(width, height, P2D);
- pg.beginDraw();
- pg.smooth(4);
- pg.noStroke();
- pg.endDraw();
- noStroke();
- fill(0, 255, 0);
- }
- void draw() {
- background(255); // white background
- rect(0, 175, width, 150); // green rectangle
- drawPG();
- if (mousePressed) ignoreAlpha(pg);
- image(pg, 0, 0);
- frame.setTitle(int(frameRate) + " fps");
- }
- void drawPG() {
- pg.beginDraw();
- pg.background(255, 0); // white 'invisible' background (also works with opaque white)
- pg.fill(255, 0, 0); // red opaque ellipse
- pg.ellipse(pg.width/2, pg.height/2, 250, 250);
- pg.fill(0, 0, 255, 125); // blue transparent ellipse
- pg.ellipse(mouseX, mouseY, 200, 200);
- pg.endDraw();
- }
- void ignoreAlpha(PGraphics pg) {
- pg.beginDraw();
- pg.loadPixels();
- for (int i=0; i<pg.pixels.length; i++) {
- color argb = pg.pixels[i];
- int a = (argb >> 24) & 0xFF;
- if (a!=255) {
- int r = (argb >> 16) & 0xFF;
- int g = (argb >> 8) & 0xFF;
- int b = argb & 0xFF;
- pg.pixels[i] = 255<<24 | r<<16 | g<<8 | b;
- }
- }
- pg.updatePixels();
- pg.endDraw();
- }