PS i write this RLE packing.. though i not tested if it works ok (im sometimes to wearylazy to test i just wrote and run as here)
//////////////////////////////
int CheckHowLongRepeatingSequenceOfUnsignedsHere(unsigned * input, unsigned * input_last)
{
int counter = 0;
for(unsigned * p = input; p<=input_last; p++)
{
if(*p==*input) counter++;
else break;
}
return counter;
}
int Encode31bitUnsignedsRLE(unsigned* input, int input_max, unsigned * output, int output_max)
{
int input_i = 0;
int output_i = 0;
for(;;)
{
if(input[input_i] & 0x80000000) ERROR_("error: 31 bit input values are assumed");
if( input_i>=input_max) return output_i;
if(output_i>=output_max) ERROR_("error: overflow in output (in EncodeRLE)");
int rep = CheckHowLongRepeatingSequenceOfUnsignedsHere(&input[input_i], &input[input_max-1]);
if(rep==1)
{
output[output_i] = input[input_i];
input_i ++;
output_i ++;
}
if(rep > 1)
{
output[output_i] = input[input_i] & 0x80000000;
output_i++;
output[output_i] = rep;
output_i++;
input_i += rep;
}
}
}
const int BitmapRLEEncoded_max = 4000*4000;
unsigned BitmapRLEEncoded[BitmapRLEEncoded_max];
int BitmapRLEEncoded_top = 0;
int EncodeBitmapRowRLE(int y)
{
int encoded_row_size = Encode31bitUnsignedsRLE(&indexed_map[y][0], map_x, &BitmapRLEEncoded[BitmapRLEEncoded_top], BitmapRLEEncoded_max - BitmapRLEEncoded_top );
return encoded_row_size;
}
int EncodeBitmapRLE()
{
int summaric_encoded_length = 0;
for(int y=0; y<map_y; y++)
{
int encoded_row_size = EncodeBitmapRowRLE(y);
flog("\n encoded row %d size %d", y, encoded_row_size );
summaric_encoded_length += encoded_row_size;
}
flog("\n summaric_encoded_length %d ", summaric_encoded_length );
}
///////////////////////////////
the results (im not sure if this encodes well though as i said) was
encoded row 0 size 315
encoded row 1 size 350
encoded row 2 size 400
encoded row 3 size 446
encoded row 4 size 514
encoded row 5 size 583
encoded row 6 size 565
encoded row 7 size 641
encoded row 8 size 666
encoded row 9 size 717
encoded row 10 size 736
encoded row 11 size 787
encoded row 12 size 801
encoded row 13 size 823
encoded row 14 size 843
encoded row 15 size 878
encoded row 16 size 916
encoded row 17 size 924
encoded row 18 size 926
encoded row 19 size 935
encoded row 20 size 903
encoded row 21 size 912
encoded row 22 size 886
encoded row 23 size 860
encoded row 24 size 835
encoded row 25 size 826
encoded row 26 size 865
encoded row 27 size 858
encoded row 28 size 854
encoded row 29 size 808
encoded row 30 size 864
encoded row 31 size 824
encoded row 32 size 818
encoded row 33 size 791
encoded row 34 size 796
encoded row 35 size 764
encoded row 36 size 766
encoded row 37 size 714
encoded row 38 size 796
encoded row 39 size 737
(...)
encoded row 1970 size 231
encoded row 1971 size 225
encoded row 1972 size 217
encoded row 1973 size 235
encoded row 1974 size 250
encoded row 1975 size 259
encoded row 1976 size 244
encoded row 1977 size 236
encoded row 1978 size 233
encoded row 1979 size 245
encoded row 1980 size 245
encoded row 1981 size 239
encoded row 1982 size 228
encoded row 1983 size 225
encoded row 1984 size 215
encoded row 1985 size 218
encoded row 1986 size 212
encoded row 1987 size 205
encoded row 1988 size 215
encoded row 1989 size 200
encoded row 1990 size 198
encoded row 1991 size 194
encoded row 1992 size 198
encoded row 1993 size 190
encoded row 1994 size 167
encoded row 1995 size 179
encoded row 1996 size 174
encoded row 1997 size 168
encoded row 1998 size 154
encoded row 1999 size 164
summaric_encoded_length 1257765
if so that would be 1.25 M ints it is quite well, better than even probably a bit eleborate indexing (i even encoded rows in separate encoding all rows as one could be probably only tiny better though)
if so that would be a full succes to me, though i need
to test if it is ok as i maybe not quite belive it and there are some errors here
this number is number of ints but those ints are indexes
and number of those indexes = number of unique colors and
can be encoded like in 8-16 bits (in present case even in 6 bits but it will grow, still for some time it will be 10 bits or less so for my case if this work it seems
good solution)
need to test if this really works well, i will check it later