Replace drawmode?

When I want to copy (a piece) of image A to image B, I first have to clear the target area in image B and then draw the relevant part of A to B.

Is it possible to completely disregard what was in the target area of B?

rationale: performance enhancement when using buffers

Sorry, I'm not sure what you mean. The default draw mode for images is "copy", which does replace the pixels in the target. Can you post a bit of code showing where the issue is?

Let's call the default draw mode Copy and this newly requested drawmode Replace.

When I draw image A to B, the pixels in B should be completely disregarded.

When a pixel in A is transparent and the pixel at the same position in B is black, I want that pixel to become transparent in B when using Replace. When using Copy, B's pixel would remain black

Without testing, my understanding is that you would need to do the following.

  1. Set draw mode to copy.
  2. Remove the mask from A.
  3. Draw A to B.
  4. Draw A's mask to B's mask.
  5. Add the mask to A again.
  6. Done.

Strictly speaking, you can get away with not adding and removing the mask.

ohhhhhh so it copies the mask too. Got it! Should be easy to do. In the mean time you should be able to get the same result by using getMaskImage(). Untested code follows:

gfx.lockFocus(b)
a:draw(x,y)
gfx.lockFocus(b:getMaskImage())
a:getMaskImage():draw(x,y)
gfx.unlockFocus()

uggggh I got all the way to the merge request (even remembered to add the documentation!) before I realized I'm using the mask to handle clipping on the edges. This isn't quite as simple as I thought it'd be. :confused:

clip

1 Like

Yeah, I don't think there's really any advantage to doing this under the hood. We'd still have to do separate passes on the image and mask layers like in that snippet above, so might as well leave it in Lua so it's more flexible.

1 Like

Shame, but thanks for the effort!

1 Like