#include "ArrayFormatter.h"
// Put your list of images here...
const long Pumpkin2b[] PROGMEM =
{
0xff000000, 0xffeb5e00, 0xffeb5e00, 0xffeb5e00, 0xffeb5e00, 0xffeb5e00, 0xffeb5e00, 0xff000000,
0xffeb5e00, 0xffeb5e00, 0xfffa0505, 0xfffa0505, 0xfffa0505, 0xfffa0505, 0xffeb5e00, 0xffeb5e00,
0xffeb5e00, 0xfffa0505, 0xfffa0505, 0xfffaf7f5, 0xfffa0505, 0xfffa0505, 0xfffa0505, 0xffeb5e00,
0xffeb5e00, 0xffeb5e00, 0xffeb5e00, 0xffeb5e00, 0xffeb5e00, 0xffeb5e00, 0xffeb5e00, 0xffeb5e00,
0xffeb5e00, 0xffeb5e00, 0xfffa0505, 0xffeb5e00, 0xffeb5e00, 0xfffa0505, 0xffeb5e00, 0xffeb5e00,
0xff000000, 0xffeb5e00, 0xffeb5e00, 0xffeb5e00, 0xffeb5e00, 0xffeb5e00, 0xffeb5e00, 0xff000000,
0xff000000, 0xff000000, 0xff000000, 0xff0c6624, 0xff0c6624, 0xff000000, 0xff000000, 0xff000000,
0xff000000, 0xff000000, 0xff0c6624, 0xff0c6624, 0xff000000, 0xff000000, 0xff000000, 0xff000000
};
// Table of 8x8 pixart
const long* const images[] PROGMEM = { /*Pumpkin3, Pumpkin2a,*/ Pumpkin2b }; //Bat1, Ghost, Heart, Pumpkin1, Pumpkin2,
// An array to store all the different colors used in the images
uint32_t colorsList[256];
// This function will read all pixel colors of all images,
// to make a list of all used colors, and store them in the colorsList array,
// then it will generate and print indexes arrays for all images, and the colorsList lookup array
// you can directly copy the printed content to use in your code
void printArrays()
{
ArrayFormatter::printer( Serial );
ArrayFormatter af1, af2;
char str[50];
uint8_t colorsCounter = 0;
uint8_t imagesCount = sizeof( images ) / sizeof( images[0] );
af1.start( "const uint8_t images[][64] PROGMEM", 1, true );
for ( size_t i = 0; i < imagesCount; ++i )
{
uint32_t * image = pgm_read_ptr( &images[i] );
uint8_t colorIndex = 0;
af1.add();
snprintf( str, sizeof( str ), "image %02u", i );
af2.start( str, 8 );
for ( size_t j = 0; j < 64; ++j )
{
uint32_t pixelColor = pgm_read_dword( &image[j] );
uint8_t k = 0;
for ( ; k < colorsCounter; ++k )
{
if ( pixelColor == colorsList[k] )
{
colorIndex = k;
break;
}
}
if ( k == colorsCounter )
{
colorIndex = k;
colorsList[colorsCounter++] = pixelColor;
}
snprintf( str, sizeof( str ), "%2hhu", colorIndex );
af2.add( str );
}
af2.end();
}
af1.end();
Serial.println();
af1.start( "const uint32_t colorsList[] PROGMEM", 1 );
for ( size_t i = 0; i < colorsCounter; ++i )
{
snprintf( str, sizeof( str ), "0x%08lX", colorsList[i] );
af1.add( str );
}
af1.end();
}
void setup()
{
Serial.begin( 921600 );
printArrays();
}
void loop()
{
}