BMP2POK graphics conversion tool


#1

Hello all.

I just created the first repo on Github. Its the graphics conversion tool.

Please notice that these are development tools being released at an accelerated pace by request of the community. Better support and explanation and ease-of-use will be improved as we get on our way.

Here is a ready windows .exe also:

www.pokitto.com/public_html/tools/bin/bmp2pok.zip

Kaspersky Virus test:

Scan result
File is safe
File size
41.56 KB
File type
PE32/EXE
Scan date
May 02 2017 00:33:33


How to use Bitmap (BMP)?
#2

@jone is it ok if i refactor my 4bit sprite converter to output the same as this?
its a bit easer for me since mine is already cross platform, and supports multiple image formats


#3

Ofcourse it is OK. Remember to make the palette 565. Makes life a lot easier than R,G,B


#4

so finaly started up a windows machine, this thing dousnt work i got a 8bpp file and its not outputing
can you give me a test image/export of a test image so i can port my convertor XD


#5

Ok. Also post here the image that you tried to convert


#6

@adekto I know it works because i have used it a lot. Please post the image and the command line you were using. There are still some bugs (for example certain size images may be problematic) and I need more information from you about ehat happened. Thanks!


#7

cant post bmp files
https://ufile.io/xh72x


#8

did it work for you?


#9

I will be at my comp in 20 min and try it


#10

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,

};


#11

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


#12

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


#13

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


#14

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.


#15

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


Font Tilesets?
#16

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.


#17

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


#18

bug in -2 mode

input
BMP2POK.exe R.bmp -2

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,

};


#19

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


#20

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