From: Shawn Hargreaves Newsgroups: comp.os.msdos.djgpp Subject: Re: "Remapping" Bitmaps In Allegro Date: Tue, 7 Jan 1997 20:07:03 +0000 Organization: None Lines: 20 Distribution: world Message-ID: References: <19970106 DOT 150910 DOT 9934 DOT 1 DOT MSnakes AT juno DOT com> NNTP-Posting-Host: talula.demon.co.uk MIME-Version: 1.0 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Matt J Reiferson writes: >still not final, so I set out to write a function that would take the current >main pallete and "remap" it to all the tiles. This way I would not >have to keep each individual picture updated (the program would do it for >me). The problem is it doesn't work right, the tiles still don't display >correctly, could anyone tell me what's wrong with the following function: > > cerror += abs(desired[cur_data].r-actual[index].r); I suspect this line is the problem. The color fields in a pallete are unsigned chars. Subtract one from another, and if the actual value is greater than the desired one (ie. approx 50% of the time), it will wrap around and give the wrong result. Try casting the values first, eg: cerror += abs((int)desired[cur_data].r-(int)actual[index].r); /* * Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/ * Ghoti: 'gh' as in 'enough', 'o' as in 'women', and 'ti' as in 'nation'. */