Fastes way to cut a form out of an img + collude

Im searching for the fastest way to cut a form (defined by a shape) out of an image and then collude it.
After that the form should be painted on the backbuffer over some sort of backgroundimage, which makes it necessarily to have bitmask transparency on the resulting image.

The way I do it now is that:


Color Alpha0 = new Color(0,true);          // creat a 100% transparent color                
int x[] = {20,40,0,40,0};
int y[] = {0,40,15,15,40};
Polygon Poly = new Polygon(x,y,5);         // create the form to cut-out from the texture

BufferedImage ImgTex = null;               // image for the texture
BufferedImage ImgGoal = null;              // image for the resulting cut-out
ImgTex  = ConfigGrfx.createCompatibleImage(60,60,Transparency.OPAQUE);
ImgGoal = ConfigGrfx.createCompatibleImage(60,60,Transparency.BITMASK);
            
Graphics2D GrfxTex  = ImgTex.createGraphics();
Graphics2D GrfxGoal = ImgGoal.createGraphics();
            
GrfxGoal.setBackground(Alpha0);
GrfxGoal.clearRect(0,0,60,60);      // make goalimage transparent
            
GrfxTex.setColor(Color.red);
GrfxTex.fillRect(0,0,60,60);        // fill the texture-image (in reality e.g. load a png) 

GrfxGoal.setColor(Color.black);
GrfxGoal.fill(Poly);                // draw the form on goalimage
            
// draw the texture over the form with spezial Composit, result ist cut-out from the texture
GrfxGoal.setComposite(AlphaComposite.SrcAtop);
GrfxGoal.drawImage(ImgTex,0,0,null);     

// paint "shadow" (50% darkness) over the texture
GrfxGoal.setComposite(AlphaComposite.SrcOver);
GrfxGoal.setColor(new Color(0.0f,0.0f,0.0f, 0.5f));
GrfxGoal.fill(Poly);

// and now draw it to backbuffer

the problem with that piece of code is, that it isn’t accalerated.
The form is calculated again every frame, so every frame the mastercopy in SysRam must be copied to VRam (if it is copied to it after all, because it’s redrawn so often) after draw the form on it.
And if I use a volatileImage I couldn’t draw it to the backbuffer, because it has no alpha, so I would draw the (nice textured) form with an ugly box around it.

So the question: is there a faster way for that?

Oh, and the code above isn’t the code I use in the loop, I just copied the important parts … I doesn’t make new BufferedImages every loop :slight_smile:

I don’t believe there’s a way to do this in 1.4.2 with hw acceleration.

Have you tried to use clipping to achieve the same effect? Create a shape for the cut out, set is as clip, and then render the image.