Newsgroups: comp.sys.amiga.programmer Path: utzoo!utgpu!watserv1!watdragon!rose.waterloo.edu!ccplumb From: ccplumb@rose.waterloo.edu (Colin Plumb) Subject: Re: best way to reverse a bitplane? Message-ID: <1991Apr29.202206.240@watdragon.waterloo.edu> Sender: news@watdragon.waterloo.edu (News Owner) Organization: University of Waterloo References: <1991Apr29.101302.1@atmo2.atmo.arizona.edu> Date: Mon, 29 Apr 1991 20:22:06 GMT Lines: 30 leuthold@atmo2.atmo.arizona.edu wrote: >What is the best way to reverse a bitplane? A brute force method would be >to reverse the bytes and then reverse the bits in each byte. The only way I >can think of to reverse the bits in each byte is to mask each bit off then >shift it to its new place and add it to the new byte. Is there a better way? Yes, table look-up. A 256 byte table wouldn't take up much more room than your bit-reversing code, and would be a lot faster. Oh, and the best way to reverse a bitplane is to swap bytes in from the ends. In C, UBYTE *p1, *p2; UBYTE c1, c2; extern UBYTE table[256]; p1 = ; p2 = p1 + ; /* Note: assumed even, and >0 */ do { c1 = *p1; c2 = *--p2; *p1++ = table[c2]; *p2 = table[c1]; } while (p1 != p2); Translating this into assembler is easy. Just keep the high parts of the registers holding c1 and c2 clear, and use the indexed addressing mode. -- -Colin