BMP2POK graphics conversion tool

Worked first try

command line used:

bmp2pok.exe ditter.bmp -4



/*
 * BMP image as 4bpp (16 color index) data
 */

#include <stdint.h>

const uint16_t ditter_pal[] = {
63497,64437,31018,33715,50712,6474,11647,1066,1834,65508,64768,23209,65141,65437,43654,0
};

const uint8_t ditter[] = {
64,64,
255,255,255,255,255,255,255,255,85,85,85,85,85,85,85,85,51,51,51,51,51,51,51,51,119,119,119,119,119,119,119,119,255,255,255,255,255,255,255,255,101,101,101,101,101,101,101,101,51,51,51,51,51,51,51,51,119,119,119,119,119,119,119,119,
255,255,255,255,255,255,255,255,87,85,87,85,87,85,87,85,51,51,51,51,51,51,51,51,119,119,119,119,119,119,119,119,255,255,255,255,255,255,255,255,101,101,101,101,101,101,101,101,19,51,19,51,19,51,19,51,119,119,119,119,119,119,119,119,
255,255,255,255,255,255,255,255,85,85,85,85,85,85,85,85,51,51,51,51,51,51,51,51,119,119,119,119,119,119,119,119,255,255,255,255,255,255,255,255,101,101,101,101,101,101,101,101,51,51,51,51,51,51,51,51,119,119,119,119,119,119,119,119,
255,255,255,255,255,255,255,255,87,85,87,85,87,85,87,85,51,51,51,51,51,51,51,51,119,119,119,119,119,119,119,119,255,255,255,255,255,255,255,255,101,101,101,101,101,101,101,101,19,51,19,51,19,51,19,51,119,119,119,119,119,119,119,119,
255,255,255,255,255,255,255,255,85,85,85,85,85,85,85,85,51,51,51,51,51,51,51,51,119,119,119,119,119,119,119,119,255,255,255,255,255,255,255,255,101,101,101,101,101,101,101,101,51,51,51,51,51,51,51,51,119,119,119,119,119,119,119,119,
255,255,255,255,255,255,255,255,87,85,87,85,87,85,87,85,51,51,51,51,51,51,51,51,119,119,119,119,119,119,119,119,255,255,255,255,255,255,255,255,101,101,101,101,101,101,101,101,19,51,19,51,19,51,19,51,119,119,119,119,119,119,119,119,
255,255,255,255,255,255,255,255,85,85,85,85,85,85,85,85,51,51,51,51,51,51,51,51,119,119,119,119,119,119,119,119,255,255,255,255,255,255,255,255,101,101,101,101,101,101,101,101,51,51,51,51,51,51,51,51,119,119,119,119,119,119,119,119,
255,255,255,255,255,255,255,255,87,85,87,85,87,85,87,85,51,51,51,51,51,51,51,51,119,119,119,119,119,119,119,119,255,255,255,255,255,255,255,255,101,101,101,101,101,101,101,101,19,51,19,51,19,51,19,51,119,119,119,119,119,119,119,119,
225,234,225,234,225,234,225,234,187,187,187,187,187,187,187,187,227,228,227,228,227,228,227,228,221,221,221,221,221,221,221,221,174,147,174,147,174,147,174,147,235,235,235,235,235,235,235,235,67,195,67,195,67,195,67,195,221,221,221,221,221,221,221,221,
234,234,234,234,234,234,234,234,190,187,190,187,190,187,190,187,52,227,52,227,52,227,52,227,221,221,221,221,221,221,221,221,147,206,147,206,147,206,147,206,235,235,235,235,235,235,235,235,147,67,147,67,147,67,147,67,221,221,221,221,221,221,221,221,
225,234,225,234,225,234,225,234,187,187,187,187,187,187,187,187,227,228,227,228,227,228,227,228,221,221,221,221,221,221,221,221,174,147,174,147,174,147,174,147,235,235,235,235,235,235,235,235,67,195,67,195,67,195,67,195,221,221,221,221,221,221,221,221,
234,234,234,234,234,234,234,234,190,187,190,187,190,187,190,187,52,227,52,227,52,227,52,227,221,221,221,221,221,221,221,221,147,206,147,206,147,206,147,206,235,235,235,235,235,235,235,235,147,67,147,67,147,67,147,67,221,221,221,221,221,221,221,221,
225,234,225,234,225,234,225,234,187,187,187,187,187,187,187,187,227,228,227,228,227,228,227,228,221,221,221,221,221,221,221,221,174,147,174,147,174,147,174,147,235,235,235,235,235,235,235,235,67,195,67,195,67,195,67,195,221,221,221,221,221,221,221,221,
234,234,234,234,234,234,234,234,190,187,190,187,190,187,190,187,52,227,52,227,52,227,52,227,221,221,221,221,221,221,221,221,147,206,147,206,147,206,147,206,235,235,235,235,235,235,235,235,147,67,147,67,147,67,147,67,221,221,221,221,221,221,221,221,
225,234,225,234,225,234,225,234,187,187,187,187,187,187,187,187,227,228,227,228,227,228,227,228,221,221,221,221,221,221,221,221,174,147,174,147,174,147,174,147,235,235,235,235,235,235,235,235,67,195,67,195,67,195,67,195,221,221,221,221,221,221,221,221,
234,234,234,234,234,234,234,234,190,187,190,187,190,187,190,187,52,227,52,227,52,227,52,227,221,221,221,221,221,221,221,221,147,206,147,206,147,206,147,206,235,235,235,235,235,235,235,235,147,67,147,67,147,67,147,67,221,221,221,221,221,221,221,221,
0,14,0,14,0,14,0,14,26,170,26,170,26,170,26,170,169,169,169,169,169,169,169,169,184,57,184,57,184,57,184,57,224,224,224,224,224,224,224,224,170,170,170,170,170,170,170,170,153,153,153,153,153,153,153,153,152,152,152,152,152,152,152,152,
14,0,14,0,14,0,14,0,170,170,170,170,170,170,170,170,169,169,169,169,169,169,169,169,137,234,137,234,137,234,137,234,224,224,224,224,224,224,224,224,154,170,154,170,154,170,154,170,153,153,153,153,153,153,153,153,152,152,152,152,152,152,152,152,
0,14,0,14,0,14,0,14,26,170,26,170,26,170,26,170,169,169,169,169,169,169,169,169,184,57,184,57,184,57,184,57,224,224,224,224,224,224,224,224,170,170,170,170,170,170,170,170,153,153,153,153,153,153,153,153,152,152,152,152,152,152,152,152,
14,0,14,0,14,0,14,0,170,170,170,170,170,170,170,170,169,169,169,169,169,169,169,169,137,234,137,234,137,234,137,234,224,224,224,224,224,224,224,224,154,170,154,170,154,170,154,170,153,153,153,153,153,153,153,153,152,152,152,152,152,152,152,152,
0,14,0,14,0,14,0,14,26,170,26,170,26,170,26,170,169,169,169,169,169,169,169,169,184,57,184,57,184,57,184,57,224,224,224,224,224,224,224,224,170,170,170,170,170,170,170,170,153,153,153,153,153,153,153,153,152,152,152,152,152,152,152,152,
14,0,14,0,14,0,14,0,170,170,170,170,170,170,170,170,169,169,169,169,169,169,169,169,137,234,137,234,137,234,137,234,224,224,224,224,224,224,224,224,154,170,154,170,154,170,154,170,153,153,153,153,153,153,153,153,152,152,152,152,152,152,152,152,
0,14,0,14,0,14,0,14,26,170,26,170,26,170,26,170,169,169,169,169,169,169,169,169,184,57,184,57,184,57,184,57,224,224,224,224,224,224,224,224,170,170,170,170,170,170,170,170,153,153,153,153,153,153,153,153,152,152,152,152,152,152,152,152,
14,0,14,0,14,0,14,0,170,170,170,170,170,170,170,170,169,169,169,169,169,169,169,169,137,234,137,234,137,234,137,234,224,224,224,224,224,224,224,224,154,170,154,170,154,170,154,170,153,153,153,153,153,153,153,153,152,152,152,152,152,152,152,152,
100,100,100,100,100,100,100,100,86,54,86,54,86,54,86,54,35,3,35,3,35,3,35,3,204,204,204,204,204,204,204,204,70,70,70,70,70,70,70,70,99,99,99,99,99,99,99,99,16,19,16,19,16,19,16,19,204,156,204,156,204,156,204,156,
100,100,100,100,100,100,100,100,54,86,54,86,54,86,54,86,1,3,1,3,1,3,1,3,204,204,204,204,204,204,204,204,68,70,68,70,68,70,68,70,102,99,102,99,102,99,102,99,19,16,19,16,19,16,19,16,156,156,156,156,156,156,156,156,
100,100,100,100,100,100,100,100,86,54,86,54,86,54,86,54,35,3,35,3,35,3,35,3,204,204,204,204,204,204,204,204,70,70,70,70,70,70,70,70,99,99,99,99,99,99,99,99,16,19,16,19,16,19,16,19,204,156,204,156,204,156,204,156,
100,100,100,100,100,100,100,100,54,86,54,86,54,86,54,86,1,3,1,3,1,3,1,3,204,204,204,204,204,204,204,204,68,70,68,70,68,70,68,70,102,99,102,99,102,99,102,99,19,16,19,16,19,16,19,16,156,156,156,156,156,156,156,156,
100,100,100,100,100,100,100,100,86,54,86,54,86,54,86,54,35,3,35,3,35,3,35,3,204,204,204,204,204,204,204,204,70,70,70,70,70,70,70,70,99,99,99,99,99,99,99,99,16,19,16,19,16,19,16,19,204,156,204,156,204,156,204,156,
100,100,100,100,100,100,100,100,54,86,54,86,54,86,54,86,1,3,1,3,1,3,1,3,204,204,204,204,204,204,204,204,68,70,68,70,68,70,68,70,102,99,102,99,102,99,102,99,19,16,19,16,19,16,19,16,156,156,156,156,156,156,156,156,
100,100,100,100,100,100,100,100,86,54,86,54,86,54,86,54,35,3,35,3,35,3,35,3,204,204,204,204,204,204,204,204,70,70,70,70,70,70,70,70,99,99,99,99,99,99,99,99,16,19,16,19,16,19,16,19,204,156,204,156,204,156,204,156,
100,100,100,100,100,100,100,100,54,86,54,86,54,86,54,86,1,3,1,3,1,3,1,3,204,204,204,204,204,204,204,204,68,70,68,70,68,70,68,70,102,99,102,99,102,99,102,99,19,16,19,16,19,16,19,16,156,156,156,156,156,156,156,156,

};

ok i see so the format is the same to the one i did (i think)
how is the pallet order determent?

Palette order comes from the drawing program. The tool or Pokitto library does not do anything with it.

Could you please try it again, just to see you get it working?

Also, if you look at the source code, the windows part should be easy to strip out

i see, well the problem is your dealing with a very specific format of bmp
that have the index already in file, most other formats dont have that, so i have to solve that in a different way, curenty im going for a 1x16pixel pallet file that it can read and im trying to generate one from source image aswell

1 Like

I strongly suggest you take the source code and try to make your own version. It is quite a simple program, you will get much better control of what is happening.

still there is no way to extend the file formats with this setup and you got so many versions of bmp your not supporting

Correct. As you see from the source file, it is raw C reading info directly from a file. A much smarter way (and which we will do eventually) is to use some sort of an image processing library that allows many more types of input (png, gif, jpg etc). No point of writing all that by hand.

ehh, thats what im doing? lol im using a small library stb_image.h that reads the image files turns it into rgb (i even foced it to rgb) and im doing the conversion

1 Like

bug in -2 mode

input
BMP2POK.exe R.bmp -2
http://puu.sh/wbINB/8b76be1d9a.bmp

output



/*
 * BMP image as 2bpp (4 color) data
 */

#include <stdint.h>

const uint16_t R_pal[] = {
0,65535,63519,2047
};

const uint8_t R[] = {
12,12,
0,0,0,8,8,0,0,0,0,0,0,0,
0,0,0,0,8,0,252,255,8,16,0,255,
75,75,16,4,0,72,160,48,48,240,0,24,

};

1 Like

True. Never tested on such small pictures.

Will check to see whats the matter

Edit: I am actually making the BMP2POK linux version right now. I will fix that at the same time.

Edit2:
the problem is that 4 pixels are packed into a byte. So width needs to be divisible by 8. The program messes up counting. Working on it

Just tried unmodified BMP2POK with following image (12x12 pixels, 4 colors)

source (remember to save as 8-bit bmp):

Command line:

bmp2pok test2col.bmp -2

Output:

C:\poksim2\TOOLS\bmp2pok\bin\Debug>bmp2pok.exe test2col.bmp -2
Pokitto BMP to Pokitto bitmap conversion utility
Number of colours used: 4
Colour: 0  r:255 g:0   b:255
Colour: 1  r:0   g:255 b:255
Colour: 2  r:255 g:255 b:255
Colour: 3  r:0   g:0   b:0
Outputting c file: test2col.c

And in source file:



/*
 * BMP image as 2bpp (4 color) data
 */

#include <stdint.h>

const uint16_t test2col_pal[] = {
63519,2047,65535,0
};

const uint8_t test2col[] = {
12,12,
170,170,168,191,255,252,186,170,156,187,255,220,
187,168,220,187,188,220,187,188,220,187,128,220,
187,255,220,185,85,92,191,255,252,128,0,0,

};

Simulator code:

#include "Pokitto.h"

Pokitto::Core game;

/*
 * BMP image as 2bpp (4 color) data
 */

#include <stdint.h>

const uint16_t test2col_pal[] = {
63519,2047,65535,0
};

const uint8_t test2col[] = {
12,12,
170,170,168,191,255,252,186,170,156,187,255,220,
187,168,220,187,188,220,187,188,220,187,128,220,
187,255,220,185,85,92,191,255,252,128,0,0,

};

int main () {
game.begin();
game.display.load565Palette(test2col_pal);
game.display.setFont(fontAdventurer);
game.display.persistence = true;
while (game.isRunning()) {

    if (game.update()) {
        game.display.color=random(2)+1;
        game.display.setCursor(random(game.display.width),random(game.display.height));
        //game.display.print("Hello World!");
        game.display.drawBitmap(0,0,test2col);
    }

}

return 1;
}

Output (notice color 0 is pink here, thats why the background. Would need to define black as bg)

So it actually works like intended.

Please send me the .bmp file you are trying to convert to pokittodev (at) gmail.com and I will take a look at it

1 Like

Hey @adekto

I tried your source image.

It worked 100% correct.


/*
 * BMP image as 2bpp (4 color) data
 */

#include <stdint.h>

const uint16_t R_pal[] = {
0,65535,63519,2047
};

const uint8_t R[] = {
12,12,
0,0,0,0,0,0,0,0,0,128,0,0,
0,0,0,0,0,0,0,0,0,0,128,128,
0,0,0,0,0,0,0,0,0,128,0,128,

};


 

great, small request on output, an 0b (binary) representation might be easer for people to read or edit
and using 0x (hex) for the 16 color mode

Good point. I will add that.

But otherwise we really should work towards a more user-friendly tool.

I’ve managed to get a BMP2POK linux version running, but ran into a seriout problem: ubuntu has different endianness

i recomomend swapping over to stb_image
for the file loader since your only suporting windows bmp in a specific bit depth
this is a little bit more stable, i have had BMP2POK crash before XD

but will look into cross platform gui, maybe add some simple paint tools aswell or pallet swap previewer

It would be super useful if we could provide the command with a sprite width and height parameter for converting a sprite sheet into an array of sprites. That way we didn’t have to run this tool for every sprite we create, just call the sprite by index when drawing.

1 Like

Working on it. The tile mode already requires this approach.

1 Like

Hi @jonne, can you try with this image? https://www.dropbox.com/s/f2x4n4wwpk92t7v/chars.bmp?dl=0
I’m getting strange result with latest bmp2pok from github

Pokitto BMP to Pokitto bitmap conversion utility
file: chars.bmp strlen file: 9 justfile: chars Number of colours used: 0
Outputting c file: chars.c
1 Like

Downloading & checking

edit: it didnt like the palette in the bmp. changing to RGB and back to indexed with “exact” palette (2 colors remained) in Photoshop fixed the problem. Your .bmp had a 256 color palette. It should have been able to handle it but didn’t. I will look into this

bmp:
https://drive.google.com/open?id=0BweEjvtKj1KLR0FNN0lJRUNZa0E

.c:
https://drive.google.com/file/d/0BweEjvtKj1KLZmRmN2VWNTU2c3M/view?usp=sharing

edit: what was the source program for image? Photoshop / GIMP ?

found the bug / weird bmp “feature” will fix tomorrow. thanks @HomineLudens