Converting bitmaps for RETRO and LCD_ST7735

After having some success in some basic game code for RETRO using the OC-provided DisplayN18 driver’s fillRect API, I wanted to see if I could work with bitmaps.

I did a prototype that used the DisplayN18 driver’s setPixel API, but that seemed kind of cumbersome. I re-discovered @ taylorza’s LCD_ST7735 driver library, which also works with the Display N18, since it uses the ST7735 controller. Chris’ library also has APIs specifically for drawing bitmaps on the screen, both a full bitmap, and a portion of a bitmap (useful for sprite sheets, for example).

However…as far as I’m aware, there isn’t any way to upload bitmap files to the mbed online IDE, and even if there were, I’m not sure how you’d use the file.

For my prototype, I simply created an array of type bool, and used a 1 to indicate a white pixel, and 0 to indicate a black pixel, and used the setPixel API to draw the appropriate color while looping through the array.

Similarly, I was able to get a prototype of drawing a bitmap with the LCD_ST7735 library’s drawBitmap function by creating an array of uint16_t containing the color value for each pixel, using the Color565 class Chris also includes in the library.

But creating this array manually is exceedingly tedious, so I was wondering if anyone is aware of either utilities or techniques for converting an existing bitmap image file into the required array? I could probably whip something up myself, but figured it made sense to ask before reinventing the wheel. :slight_smile:

Just FYI. With 565 the whole image is ~40Kb. More than what is available.

Wasn’t planning on using full-screen images. The two bitmaps I’ve experimented with have both been 8x8.

But that does remind me that the limited memory situation would probably limit the ability to use sprite sheets pretty dramatically. Another challenge to solve.

OK, so I decided to take matters into my own hands and built a quick-and-dirty Windows Forms (yeah, I went there…I’m sure I’ll get grief from WPF fans) app to build 8x8 bitmaps and convert them to the initialization code needed for the drawBitmap function in @ taylorza’s LCD_ST7735 library. Attaching a screenshot below.

More than happy to share the code, if other folks would find it useful. And for folks who’d prefer bigger bitmaps, it’d be pretty easy to extend this for 16x16 or larger (though memory and rendering time could become an issue at larger sizes.

Behold, 8x8 Mario!


@ devhammer - You beat me to it… I just posted a quick code share of a real quick and dirty console application that I put together that converts image files to the RGB565 format for use with the LCD library.

Here is also a quick demo of using the generated data, but I guess you have worked all that out already.

To use the tool, just run the .exe and pass it an image as a command line argument and it will spit out a .h file ready to consume. I just use it internally so the code is not pretty or robust.

@ taylorza - Tested the demo code. Works fine.

I left a question for you on the library page…in my test app, I’m seeing the Red and Blue colors swapped when using the named colors from the Color565.h. Have you seen this, or is it just me doing something wonky?

@ devhammer - Good job! Can’t wait to see your game. :wink:

@ devhammer - There are 2 formats for the ST7735 panels, either RGB or BGR, the last argument to the constructor for the library allows you to select which you have. I think in the demo I just posted it is RGB which should match the RETRO, other demos I posted earlier might have BGR because some of the screens I got on eBay where that format so it just depends which panel I was using at the time.

I will post a reply on them bed site for others.

Before you get your hopes up, the Mario thing was just to show off the utility…I’m not working on a Mario clone for RETRO. At least not yet. :wink:

Well, I feel kinda dumb now. Knowing the answer, it should have been obvious, particularly in the LCD_DEMO code, since it included that argument in the constructor.

Oh well, at least now my colors are shiny, and I’ve got two different ways to generate and save bitmaps. A good day by any measure. :slight_smile:

@ devhammer - Well I am glad you are sorted and I should apologize for not posting that code before, but truth be told it is a little embarrassing the code is really quick and dirty anyway it is out there now :slight_smile:

@ taylorza - Dude, as far as I’m concerned, there is no shame in code that works, and yours does what it’s supposed to do. :smiley: