Path: utzoo!mnetor!uunet!husc6!hao!ames!ucbcad!ucbvax!dewey.soe.berkeley.edu!oster From: oster@dewey.soe.berkeley.edu (David Phillip Oster) Newsgroups: comp.sys.mac Subject: Re: image rotation Message-ID: <22140@ucbvax.BERKELEY.EDU> Date: 11 Dec 87 20:36:13 GMT References: <600@analog.UUCP> Sender: usenet@ucbvax.BERKELEY.EDU Reply-To: oster@dewey.soe.berkeley.edu.UUCP (David Phillip Oster) Organization: School of Education, UC-Berkeley Lines: 50 Keywords: CopyBits rotation bitmap MacTutor blitter In article <600@analog.UUCP> kim@analog.UUCP (Kim Helliwell) writes: >I am interested in any information anyone may have on algorithms for >rotating bitmaps by +/- 90 degrees. In the summer, Dr. Dobb's magazine of software tools said that they were planning a graphics issue and that outlines for articles could be posted to a certain computer mail account. Well, I sent them an article outline and got no reply, even though I logged in to the same machine they had an account on to post. My article was on this very topic. The article in MacTutor refers to a scheme described in the first Smalltalk-80 book. This scheme works well if all CopyBits took the same time, independent of their arguments. The scheme I use is: divide the picture to be rotated into 8x8 pixel blocks. (Pad the edges to make them come out exactly on block boundaries.) Now the destination coordinates of each block are pretty obvious: example: a b c d i e a e f g h => j f b i j k l k g c l h d The last remaining step is to take one of these 8x8 blocks and rotate it. The following C code is a schema for how you do that. for(i = 0, destBit = 1; i < 8; i++, destBit *= 2){ src = src8[i]; for(j = 0, srcBit = 0x80; j < 8; j++, srcBit /= 2){ if(src & srcBit){ /* if the srcbit is on */ dest8[j] |= destBit; /* turn the dest bit on */ }else{ /* else */ dest8[j] &= ~destBit; /* turn the dest bit off */ } } } Of course, you'd use plenty of register variables, and replace the explicit array referencing here with pointer arithmetic. Then you copybits from the offscreen bitmap where you have been doing the work back to the screen. I've programmed this up, and it _is_ fast. --- David Phillip Oster --A Sun 3/60 makes a poor Macintosh II. Arpa: oster@dewey.soe.berkeley.edu --A Macintosh II makes a poor Sun 3/60. Uucp: {uwvax,decvax,ihnp4}!ucbvax!oster%dewey.soe.berkeley.edu