C-API: Querying information about a LCDBitmapTable

This is a feature request for being able to query basic information out of a LCDBitmapTable, possibly allowing access to the source image directly.

I have found at runtime that I’d like to do things like:

  • Draw the source image directly (eg: a tile picker in a tilemap editor)
  • Know what the tile size is
  • Know how many total tiles there are

Today, the only way to know this information is to bake it in somehow; either hard code it, or by providing some supplemental file that might describe this info.

It may suffice to have an API in the form of something like:

LCDBitmap* playdate->graphics->getTableSourceBitmap(LCDBitmapTable* table);

With the resulting LCDBitmap, developers could use existing API to query any information they want (e.g. getBitmapData).

1 Like

Did you miss

LCDBitmap* playdate->graphics-> getTableBitmap(LCDBitmapTable* table, int n);

perhaps? The compiler chops up the source image into cells and compiles those into LCDBitmaps, then packs them together with a small header and an offset table to make the LCDBitmapTable. So the original image doesn't exist as an LCDBitmap, but all of the component images are loaded into memory--getTableBitmap() is a quick lookup returning a pointer to the requested bitmap.

The one thing missing from the API is a way to get the number of bitmaps available or the original dimensions of the source image. You can do

int numBitmaps = 0;

while ( pd->graphics->getTableBitmap(table, numBitmaps) != NULL )
  ++numBitmaps;

to count the images (not as efficient as simply copying the value out of the header but it'll be quite fast if your table size isn't ridiculous), but we don't have a way to get the "cellsWide" value. I'll file a feature request for that!

1 Like

Did you miss LCDBitmap* playdate->graphics-> getTableBitmap(LCDBitmapTable* table, int n); perhaps?

Nope! I did know this existed and I am using that. I was just (incorrectly) assuming the “source” bitmap existed as a whole image somewhere in memory.

What you mention here, though...

The one thing missing from the API is a way to get the number of bitmaps available or the original dimensions of the source image.

Sounds like a nice to have (for both)!

This would let me reconstruct the source image to present to the user without having to hardcode such values.

Thanks!

1 Like

Would love to have the cell size and number of cells too.

Not sure what to expect when cells don't have a fixed size tho...