Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!brutus.cs.uiuc.edu!apple!Apple.COM!lsr From: lsr@Apple.COM (Larry Rosenstein) Newsgroups: comp.sys.mac.programmer Subject: Re: Aligining bitmaps? Message-ID: <3967@internal.Apple.COM> Date: 29 Aug 89 02:04:04 GMT Sender: usenet@Apple.COM Organization: Objects-R-Us, Apple Computer, Inc. Lines: 67 References:<3791@ncsuvx.ncsu.edu> <15288@dartvax.Dartmouth.EDU> In article <15288@dartvax.Dartmouth.EDU> earleh@eleazar.dartmouth.edu (Earle R. Horton) writes: > In article <3791@ncsuvx.ncsu.edu> jnh@ecemwl.UUCP (Joseph N. Hall) writes: > >What is the most straightforward procedure for ensuring that a window's > >portBits begin on a word boundary? What I would like to do is check after > >the user creates or resizes a graphics window and shift the window horizontally > >(if necessary) so that it will be aligned for later updates from an offscreen > >bitmap. > > I don't know what you mean by straightforward, but ANDing the > horizontal coordinate with NOT-0x0F before calling MoveWindow() should > work fine. Resize and create should not be a problem, but moving the As someone noticed, Hypercard grids the window position and shows this by gridding the gray outline. Another approach is to perform the alignment offscreen by allocating an offscreen bitmap that is 16 bits wider than necessary. Then you use a similar calculation to Earl's and align the offscreen buffer before copying it on the screen. I used this technique in the old MacApp Paint program and it worked very well. (And it looked much better than doing unaligned CopyBits.) In this case, you don't have to worry about non-standard window behavior. I'm positive that alignment is important for 1-bit deep bitmaps on a 68000-based machine. (It might be that on a 68020 machine it's not necessary.) As I recall, it required 1/2 second on a MacPlus to align a MacPaint image offscreen. I did this by calling CopyBits with the same bitmaps as source and destination. Also, notice that what counts is the global coordinates of the destination. If you use my trick of aligning the offscreen bitmap, then you will need to compute the global coordinates of your window. To do this first call SetPort(yourWindow), assign (0, 0) to a Point, and use LocalToGlobal. Finally, I'm not sure that a word boundary is optimal alignment for Color Quickdraw. I think you might want to use longword alignment. I haven't done any stuff with offscreen pixmaps, so I don't know for sure. > and the screen depth is greater than one. Byte alignment seems to be > all that's necessary. Where did you get your information that word > alignment is needed? I don't know about color, but for 1-bit deep images, word alignment alows QuickDraw to fetch and store longwords at a time (except for the edges). If you are only byte aligned then it may have to fetch things a byte at a time. (On a 68000 you can't fetch and store a word on an odd boundary; on a 68020 you can fetch and store on odd byte boundaries, but you pay a speed penalty.) > I don't notice any difference between aligned or non-aligned > BitMaps with a black and white screen. On the other hand, these are > subjective results since I haven't done formal timing. On a MacPlus it is noticeable, although I haven't done any formal measurements, either. Larry Rosenstein, Apple Computer, Inc. Object Specialist Internet: lsr@Apple.com UUCP: {nsc, sun}!apple!lsr AppleLink: Rosenstein1