[Announcement] BMP decoder & direct draw from a file

Hi,

I have now implemented a BMP-image decoder for the Pokitto system sw. There is also a function for direct drawing a 24-bit image from a file to the screen.

Features:

  • Read a BMP-image from a file to a Pokitto bitmap
  • Read a BMP-RLE-image from a file to a Pokitto bitmap
  • Read a 24-bit BMP-image from a file and directly draw it to the screen. No RAM buffers are allocated by the decoder.
  • You can select a region of the 24-bit file and draw it to any position on screen. This makes possible to implement e.g. sprite sheet animation or panning. Thought, that depends on the speed of SD in real HW. There is also room for speed optimization as now the image is opened and closed after every draw.

The feature is available as soon as Jonne gets it merged to the main branch. The new functions are as follows:

extern int openImageFileFromSD(char*, uint16_t **, uint8_t **);
extern int directDrawImageFileFromSD(int16_t /*sx*/, int16_t /*sy*/, char* /*filepath*/);
extern int directDrawImageFileFromSD(uint16_t /*ix*/, uint16_t /*iy*/, uint16_t /*iw*/, uint16_t /*ih*/, int16_t /*sx*/, int16_t /*sy*/, char* /*filepath*/);

Example:

#include "Pokitto.h"
Pokitto::Core game;

int main(){
	game.begin();
	game.display.persistence=1;
	game.display.width = 220; // full size
	game.display.height = 174;
	game.setFrameRate(60);

	bool mustDraw = true;
        while (game.isRunning()) {
         if (game.update(true)) {

            if(mustDraw) {
                int ret = directDrawImageFileFromSD(0,0,0,0,0,0,"..\\..\\..\\EXAMPLES\\test_24bit_300x400.bmp");
                mustDraw = false;
            }
        }
     }
    return 1;
}

There are a test functions for these features in the hello.cpp -file (e.g. image panning example).

4 Likes

Excellent! Great work!

1 Like

This reminds me of the old Qbasic days, when ā€˜goodā€™ was being able to load an 8bit bmp in screen13 mode!
:slight_smile:
Great work Hanski!

1 Like

I also added a parameter to the Update() function to tell not to update the screen buffer to the screen. That way you can use direct drawing, but still update keypresses, audio, etc.

This is the reason why I have not merged yet. You see, update() is called with no parameters by many existing programs, that it will break a lot of projects (I have about 50-60 softwares that will run on pokitto). I am thinking about the most elegant way to solve this - I understand your reasoning. I am just thinking what is the best way to implement it.

Iā€™m sure you can set a default value for a parameter?

Void functionName (bool variable = 0){
}

Would that not be enough?

1 Like

Yep. That would do the trick.

Merged and tested to work, thanks @Hanski !!

Glad to hear!

Btw. It is enough to have the default parameter in the function declaration.

1 Like

Thats where it is, I had a brain fart (I was editing in the Github online editor). Having it in the definition will throw an error

I seem to be having a little problem with this.
Iā€™ve got my bitmapā€™s color depth at 4, and Iā€™ve used the setColorDepth() function to set the gameā€™s color depth to 4 as well. However, when I try to run the program, I get this error:
The image color depth should be the same as screen color depth (%d)!
Anybody know how I could fix this? Also, is there a way to make this use a certain folder as a root directory (instead of going all the way down to C, go down only to pokittosim-master)?

That error message is incorrect, have to fix it.
The function directDrawImageFileFromSD is meant for drawing full color (24 bit) images directly to the screen. It does not support any other type of images.

Can you use normal buffered draw: openImageFileFromSD() & drawBitmap() ? Example of that is in the file ā€œexamples/RLEBitmap.cppā€.

This example canā€™t be compiled on Mbed.

What kind of error it gives?

1 Like

Error: Identifier ā€œdirectDrawImageFileFromSDā€ is undefined in ā€œmain.cppā€, Line: 16, Col: 28

2 Likes

Missing lib in the online ide. Will be fixed.

Thanks for the notice

2 Likes

Donā€™t worry Petar I will get to this. Iā€™m down with a really strong flu and Iā€™m trying to get back to activity.