I want to invert the pixels of an LCDBitmap in-situ.
This post says there is a way to get 4bpp pixel data from the bitmap - is this only in Lua?
The only relevant C-API function I can find is:
void playdate->graphics->getBitmapData(LCDBitmap* bitmap, int* width, int* height, int* rowbytes, uint8_t** mask, uint8_t** data);
Which returns:
The data is 1 bit per pixel packed format, in MSB order
So I don't see how I can handle transparent pixels ... maybe these are automatically built into the mask at load-time, but loadBitmap()
does not specify.
Thoughts?
Ok, going with this for the moment.
It's a fairly "heavy" approach.
LCDBitmap *duplicateBitmapInverted( LCDBitmap *base )
{
assert( base );
LCDBitmap *bitmap_copy;
int width;
int height;
playdate->graphics->getBitmapData( base, &width, &height, NULL, NULL, NULL );
bitmap_copy = playdate->graphics->newBitmap( width, height, kColorClear );
if ( bitmap_copy != NULL )
{
playdate->graphics->pushContext( bitmap_copy );
playdate->graphics->setDrawMode( kDrawModeInverted );
playdate->graphics->drawBitmap( base, 0, 0, kBitmapUnflipped );
playdate->graphics->setDrawMode( kDrawModeCopy ); // maybe not correct
playdate->graphics->popContext();
}
return bitmap_copy;
}
JKaniarz
(John Kaniarz)
February 19, 2023, 7:51pm
#4
It might be easier to just flip the bits in the data.
for(int y=0; y < height; y++){
for(int x=0; x < width/8; x++){
data[x] = ~data[x];
}
data += rowbytes; //advance the pointer a row
}
this code is completely untested and is intended as inspiration.
Looks interesting!
So you're not specifically handling the transparency.
I will give it a test.