image sheets - what size is more memory efficient?

Hello guys,

I’m sort of confused regarding the texture memory issue. Could you please help me sort out these questions?

QUESTION 1) 

I read somewhere here that now image sheets don’t have to be the power of 2 (e.g. 512, 1024 etc)

Does it mean that I can load an image of size 120x120 and it will occupy that exact size in texture memory?

Or it will consume the round up to power of two, so it would take 128x128 in memory?

example1: 

file: some.png (120x120)

code:

local sheet = { frames = { { name = "some.png", x = 0, y = 0, width = 120, height = 120 }, }

will reserve 120x120 or it will round up to 128x128 pixels in memory?

QUESTION 2)

What consumes texture memory: the ACTUAL image file dimensions in pixels 

OR - the size I say in my code that the image has if I want to down or upscale it.

example: 

file: some.png (1024x1024)

code:

local sheet = { frames = { -- frame #1 { name = "some.png", x = 0, y = 0, width = 512, height = 512 }, -- frame #2 { name = "some.png", x = 0, y = 0, width = 2048, height = 2048 }, }

here frame #1 will reserve: 512x512 and frame #2: 2048x2048, or both will take 1024x1024 pixels in memory?

I hope I was clear enough so you get my point :slight_smile:

thanks!

Hi @whammy,

The memory occupied will be the next-highest power of 2. So, for a 120x120 image, it will take up the same memory as a 128x128 image. This is described in more detail here under “Conserving Texture Memory”:

http://docs.coronalabs.com/guide/basics/optimization/index.html#texturemem

In your second question, the sizes you declare in the “frame” are actually related to the the overall image sheet size, so you can’t just set them arbitrarily. You need to pick the frame x/y/size from the sheet, and then if you want to scale it up or down, you do that separately using the scale functions.

Hope this helps,

Brent

Hi Brent, thank you for your reply!
Regarding my second question: what about setting the size of the whole sheet?
If I had a file: some.png (1024x1024) and I declare this at the end of the table:

sheetContentWidth = 512, – width of original 1x size of entire sheet
sheetContentHeight = 512 – height of original 1x size of entire sheet

OR this:

sheetContentWidth = 2048, – width of original 1x size of entire sheet
sheetContentHeight = 2048, – height of original 1x size of entire sheet

Would it occupy once 512x512 and another time 2048x2048 pixels in memory,
Or it would consume 1024x1024 (the actual image sheet file size) in both examples?

I’m still a litle confused :slight_smile:
Take care,
Olaf

Hi Olaf,

The sheet is loaded into memory before any frames are pulled from it, so the memory allocated will be for the 1024x1024 dimensions. Those parameters you mention (sheetContentWidth, sheetContentHeight) don’t actually set the size of the sheet… instead, they are used by Corona so it knows the dimensions of the sheet for dynamically-selected images (different size images displayed depending on the resolution of the device, as dictated by image suffixes).

If you haven’t read the guide on that, it’s a good place to start.

http://docs.coronalabs.com/guide/basics/configSettings/index.html#dynamicimages

I know it’s a bit confusing at first, so ask whatever questions you need and I’ll clarify as best I can.

Brent

Thanks Brent, I appreciate your help!

Hi @whammy,

The memory occupied will be the next-highest power of 2. So, for a 120x120 image, it will take up the same memory as a 128x128 image. This is described in more detail here under “Conserving Texture Memory”:

http://docs.coronalabs.com/guide/basics/optimization/index.html#texturemem

In your second question, the sizes you declare in the “frame” are actually related to the the overall image sheet size, so you can’t just set them arbitrarily. You need to pick the frame x/y/size from the sheet, and then if you want to scale it up or down, you do that separately using the scale functions.

Hope this helps,

Brent

Hi Brent, thank you for your reply!
Regarding my second question: what about setting the size of the whole sheet?
If I had a file: some.png (1024x1024) and I declare this at the end of the table:

sheetContentWidth = 512, – width of original 1x size of entire sheet
sheetContentHeight = 512 – height of original 1x size of entire sheet

OR this:

sheetContentWidth = 2048, – width of original 1x size of entire sheet
sheetContentHeight = 2048, – height of original 1x size of entire sheet

Would it occupy once 512x512 and another time 2048x2048 pixels in memory,
Or it would consume 1024x1024 (the actual image sheet file size) in both examples?

I’m still a litle confused :slight_smile:
Take care,
Olaf

Hi Olaf,

The sheet is loaded into memory before any frames are pulled from it, so the memory allocated will be for the 1024x1024 dimensions. Those parameters you mention (sheetContentWidth, sheetContentHeight) don’t actually set the size of the sheet… instead, they are used by Corona so it knows the dimensions of the sheet for dynamically-selected images (different size images displayed depending on the resolution of the device, as dictated by image suffixes).

If you haven’t read the guide on that, it’s a good place to start.

http://docs.coronalabs.com/guide/basics/configSettings/index.html#dynamicimages

I know it’s a bit confusing at first, so ask whatever questions you need and I’ll clarify as best I can.

Brent

Thanks Brent, I appreciate your help!