setMask method takes huge amount of time

I have very simple 1024x768 sized png images that are 7KB in size at an average. I apply the same size masks which are only 3-4KB, but the masking process takes 1500ms of time. As I have 5-15 pics in each scene this is not acceptable. The weird thing is that when I do the same thing with an onTouch function it only takes 2ms. Below is the code:

[lua]

for i=1,totalParts do

  local t1 = system.getTimer()

  background[i] = display.newRect(0, 0, display.contentWidth, display.contentHeight)

  background[i]:setFillColor(255, 255, 255)

  local mask = graphics.newMask( “mask.png” )        

  background[i]:setMask( mask )

  mainScreen:insert(background[i])

  local t2 = system.getTimer()

  print(“time passed=”, t2-t1)

end

[/lua]

When I run the above code “time passed” prints around 1500ms. Am I doing something wrong?

Have you tried commenting out various lines one at a time to see the time usage of various calls (didn’t see any specifics in your post about that)?

Also, something to keep in mind is that the images might be 7k on disk, but they are 4MB in memory (which is what the graphics engine uses), and it sounds like the mask is 4MB too. (1024x768 @ 32bpp --> 1024x1024x4Bpp == 4MB per image decompressed / loaded into texture memory - search the forum for posts on texture memory).

As far as the setMask taking 1.5 seconds, don’t know about that. There’s pretty strict rules about masks - size, bit depth etc. I typically use 8 bit pngs for masks, not 32 bit (since the docs say it will be converted to 8 bit anyway when applied – maybe there’s a delay there?), and my similar size masks don’t take 1.5 seconds to setMask(). Let us know what you discover!

Have you tried commenting out various lines one at a time to see the time usage of various calls (didn’t see any specifics in your post about that)?

Also, something to keep in mind is that the images might be 7k on disk, but they are 4MB in memory (which is what the graphics engine uses), and it sounds like the mask is 4MB too. (1024x768 @ 32bpp --> 1024x1024x4Bpp == 4MB per image decompressed / loaded into texture memory - search the forum for posts on texture memory).

As far as the setMask taking 1.5 seconds, don’t know about that. There’s pretty strict rules about masks - size, bit depth etc. I typically use 8 bit pngs for masks, not 32 bit (since the docs say it will be converted to 8 bit anyway when applied – maybe there’s a delay there?), and my similar size masks don’t take 1.5 seconds to setMask(). Let us know what you discover!