Copying while respecting the tint()?

The following code is pretty good in creating a passable stroke for a paint program. It completely resolves the problem of errant hues when using stroke() alpha. And it works fine for smaller images. It gets clunky for larger images as its copying the whole image for every mouse drag when it doesn't have to. It really just has to copy a small rectangle the size of the drag. Figuring the rect is not a problem. I just can't find a copy method that respects tint(). copy() doesn't and blend() doesn't. I guess my biggest question is WHY? I'd add to that why copy() isn't overloaded to accept floats other than for sadistic purposes or ugly code full of casts.

Is there any way to change these methods? A long time ago when graphics were 4 bits and cpu's were measured in megahertz you could use interrupts to change almost anything - even rom routines. Any way to rewire these methods?

PGraphics strokePG1,strokePG,canvasPG;
PImage temp;
import codeanticode.tablet.*;
float opacity = 200;
float pressure,ppressure;
Tablet tablet;
void setup(){
     size(600,600,JAVA2D);
     strokePG = createGraphics(600,600);
     strokePG1 = createGraphics(600,600);
     canvasPG = createGraphics(600,600);
     temp = createImage(600, 600, ARGB);
     tablet = new Tablet(this);
     canvasPG.beginDraw();
     canvasPG.background(200,200,255);
     canvasPG.endDraw();
     strokePG1.beginDraw();
     strokePG1.strokeWeight(20);
     strokePG1.stroke(150,80,40);
     strokePG1.endDraw();
}
void draw(){
     noTint();
     image(canvasPG,0,0);
     if (mousePressed) {
          temp.pixels = strokePG.pixels;
          temp.updatePixels();
          tint(255, 255, 255, opacity);
          image(temp, 0, 0); // using the temp image directly screws things up
      } 


}
void mousePressed(){
     strokePG1.beginDraw();
     strokePG1.clear();
     strokePG1.line(mouseX,mouseY,mouseX,mouseY);
     strokePG1.endDraw();
     pressure = 30 * tablet.getPressure();
     strokePG.beginDraw();
     strokePG.tint(255,255,255,pressure);
     strokePG.image(strokePG1,0,0);
     strokePG.endDraw();

}
void mouseDragged(){
     strokePG1.beginDraw();
     strokePG1.clear();
     strokePG1.line(pmouseX,pmouseY,mouseX,mouseY);
     strokePG1.endDraw();
     ppressure = pressure;
     pressure = 30 *tablet.getPressure();
     pressure = (pressure + ppressure)/2;
     ppressure = pressure;
     strokePG.beginDraw();
     strokePG.tint(255,255,255,pressure);
     strokePG.image(strokePG1,0,0);
     strokePG.endDraw();


}
void mouseReleased(){     
     canvasPG.beginDraw();
     canvasPG.tint(255,opacity);
     canvasPG.image(strokePG,0,0);     
     canvasPG.endDraw(); 
     strokePG.beginDraw();
     strokePG.clear();
     strokePG.endDraw();

}

Answers

  • That was me. It works for smaller images. Its too clunky for larger images as it copies the whole image every mouse drag. Iterating the pixels of a smaller rect is not an option because mixing colors using the pixels alphas creates significant errant hues. tint() works differently. There is no problem with errant hues using tint(). But I think the solution is as simple as creating a small 600 X 600 stroke buffer, instead of a stroke buffer the size of the entire canvas might solve the problem. I think it would be hard to have a single mouse drag over six hundred pixels. I'm going to give that a try.

Sign In or Register to comment.