Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wasatch!cs.utexas.edu!uunet!mcsun!sunic!tut!santra!kampi.hut.fi!jmunkki From: jmunkki@kampi.hut.fi (Juri Munkki) Newsgroups: comp.sys.mac.programmer Subject: Re: Aligining bitmaps? Message-ID: <24780@santra.UUCP> Date: 29 Aug 89 10:31:56 GMT References: <3791@ncsuvx.ncsu.edu> Sender: news@santra.UUCP Reply-To: jmunkki@kampi.hut.fi (Juri Munkki) Organization: Helsinki University of Technology, Finland Lines: 77 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. > >Also, how much speed difference is there between an aligned and unaligned >one-to-one CopyBits? I assume that performance is no better for an >odd-byte-aligned bitmap than it is for a totally unaligned bitmap, right? The speed difference is visible. I assume that you have an offscreen bitmap that you regularly copy into a window. The best solution for alignment is to shift the bitmap instead of forcing the window. You will only waste a few bytes for the extra margin necessary. Here are a few code fragments: /* >> AdjustVidPort adjusts the offscreen bitmap so that >> CopyBits can always work in 32 bit alignment. >> >> Call AdjustVidPort whenever your window has moved. >> >> The method was originally suggested by Larry Rosenstein >> from Apple's Advanced Technology Group. */ void AdjustVidPort() { BitMap temporary; GrafPtr saved; GetPort(&saved); SetPort(&VidPort); /* Save old port location: */ temporary=VidPort.portBits; /* Align port with magic formula: */ MovePortTo((HMARGIN-VTWind->portBits.bounds.left) & 31,0); /* Align image: */ CopyBits( &temporary, &VidPort.portBits, &VidPort.portRect, &VidPort.portRect, 0,srcCopy); SetPort(saved); } /* Open an offscreen grafport for VT100 screen ** Make it 32 pixels wider than absolutely necessary. */ RowBytes= ((ts.hsize*ts.charwidth+47)/16)*2; ... VidPort.portBits.bounds.left=0; VidPort.portBits.bounds.right=ts.hsize*ts.charwidth+32; VidPort.portBits.bounds.top=0; VidPort.portBits.bounds.bottom=ts.vsize*ts.lineheight; VidPort.portRect=VidPort.portBits.bounds; VidPort.portRect.right-=32; RectRgn(VidPort.visRgn,&VidPort.portRect); RectRgn(VidPort.clipRgn,&VidPort.portRect); The above code makes sure that all your drawing is long word aligned. My terminal program doubled speed in cases where the window was badly positioned. All this has no effect on color screens, because I'm using a B&W bitmap even when the screen is in color. You would have to make small changes to apply the same technique to color pixmaps. _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ | Juri Munkki jmunkki@hut.fi jmunkki@fingate.bitnet I Want Ne | | Helsinki University of Technology Computing Centre My Own XT | ^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^