Here's a little python script I wrote to convert any image file into a C buffer to use with Rax's marvellous H3OSDK lib.
It relies on
Python Imaging Library so most image format are handled (even animated gif).
The script is used through command line with following options:
Code: Select all
usage: img2h3 [-h] [--contrast CONTRAST] [--name NAME] [--undersample UNDERSAMPLE] [--invertin] [--invertout]
[--output OUTPUT]
imagefile
Image To H3lib Converter. Convert any image to C buffer tu use with rax's H3OSDK lib.
https://github.com/raxrax/oricH3OSDK
positional arguments:
imagefile image file to convert
optional arguments:
-h, --help show this help message and exit
--contrast CONTRAST Contrast Adjustment (positive float value). Default 1.5
--name NAME name of the buffer. Default 'image'
--undersample UNDERSAMPLE
Number of frame to skip between two exported frames (only applies to animated gif)
--invertin invert input image (negative)
--invertout invert ouput image (negative)
--output OUTPUT file where to write buffer. Default ouput is stdout
For exemple: img2h3 --contrast 3.5 --name buffer_img --invertout image.bmp
Still images are converted into a C buffer looking like:
Code: Select all
unsigned char image[]= { 0x28, 0x24, 0x30, 0x20, 0x38, 0x20, 0x32, 0x29,
0x30, 0x29, 0x9, 0x35, 0x28, 0x21, 0x31, 0x24,
...
};
that can be loaded into the H3 canvas with a fonction like:
Code: Select all
void h3LoadImage(unsigned char *image){
memcpy((unsigned char*)(0xb800 + 32 * 8),image,640);
}
Animated gifs are stored frame by frame :
Code: Select all
unsigned char anim_00[]= {
...
};
unsigned char anim_01[]= {
...
};
...
unsigned char anim_0n[]= {
...
};
And a supplementary array is created that gives pointers on each frames.
Code: Select all
unsigned char* anim[] = {anim_00,
anim_01,
...
anim_0n,
};
possible results are illustrated below: