Code:
if ( Image->Color & 1 )
{
SCANLINE scan = {0};
scan.Palette = Palette;
scan.Dst = FullImg;
scan.Src = Data;
scan.SpanR = Image->SpanX;
scan.SpanI = Image->SpanY;
scan.Depth = Image->Depth;
scan.Flags = Image->Color;
scan.CMethod = Image->CompressionMethod;
scan.FMethod = Image->FilterMethod;
scan.IMethod = Image->InterlaceMethod;
#if 0
ScanLines( &scan );
#elif 0
ScanLinesZigZag( &scan );
#else
HUFFMAN_CHAR gophers[] =
{
{ 0, 13, { 4, 1 } },
{ 0, 6, { 2, 3 } },
{ 'g', 3, {0} },
{ 'o', 3, {0} },
{ 0, 7, { 5, 8 } },
{ 0, 3, { 6, 7 } },
{ 's', 1, {0} },
{ ' ', 2, {0} },
{ 0, 4, { 9, 12 } },
{ 0, 2, { 10, 11 } },
{ 'p', 1, {0} },
{ 'h', 1, {0} },
{ 0, 2, { 13, 14 } },
{ 'e', 1, {0} },
{ 'r', 1, {0} },
{ 0, 0, {0} }
};
BUFF Table = {0};
uchar go_go_gophers[] =
{
#if 1
0b01010110,
0b01110010,
0b00010001,
0b01011001,
0b11011000,
0b11011011,
0b00000010,
0b10101100,
0b11101100
#else
0b10110011,
0b01100110,
0b11010001,
0b01011001,
0b11000000
#endif
};
Table.addr = gophers;
Table.used = 8;
memset( Data->addr, 0, Data->size );
memcpy( Data->addr, go_go_gophers, 9 );
Data->used = 9;
DecodeHuffman( Alloc, &Table, FullImg, Data );
#endif
}
FullImg->used = Pixels;
return Image;
}
BUFF * DecodeHuffman( ALLOC *Alloc, BUFF *Table, BUFF *Dst, BUFF *Src )
{
uchar *dst;
uchar *src = Src->addr;
HUFFMAN_CHAR *tree, *n;
size_t bits = Src->used * CHAR_BIT, i = 0, b, end = bits;
#if 0
Table->used = 0;
Table = buff_inc_only( Alloc, Table, HUFFMAN_CHAR, Src->used );
if ( !Table )
return NULL;
#endif
tree = Table->addr;
printf( "%s\n", (char*)src );
while ( i != end )
{
uint spaces = 0, gs = 0, os = 0;
char *str = Dst->addr;
char add[2] = {0};
memset( str, 0, Dst->size );
b = i;
n = tree;
for ( b = i; b != end; ++b )
{
size_t byte = b / CHAR_BIT;
size_t bit = 1u << (CHAR_BIT - (b % CHAR_BIT));
bool dir = !!(src[byte] & bit);
n = tree + n->nxt[dir];
if ( n->sym )
{
gs += (n->sym == 'g');
os += (n->sym == 'o');
spaces += (n->sym == ' ');
add[0] = n->sym;
strcat( str, add );
n = tree;
//printf( "sym = '%c', num = %d, guess = %u, guessed = %u\n", ch->sym, ch->num, guess, guessed );
}
}
//if ( gs == 3 )
//if ( spaces == 2 && gs == 3 && os == 3 )
if ( strstr( str, "her" ) == str )
printf( "%s\n", str );
++i;
}
Dst = buff_inc_only( Alloc, Dst, uchar, bits );
if ( !Dst )
return NULL;
dst = Dst->addr;
return Dst;
}