Path: utzoo!attcan!uunet!seismo!sundc!pitstop!sun!wind!naughton From: naughton%wind@Sun.COM (Patrick Naughton) Newsgroups: comp.graphics Subject: Re: Sun pixrect rops Summary: Bits or Bytes? Keywords: ROP Message-ID: <57237@sun.uucp> Date: 20 Jun 88 17:58:25 GMT References: <11115@agate.BERKELEY.EDU> Sender: news@sun.uucp Reply-To: naughton@Sun.COM (Patrick Naughton) Followup-To: comp.graphics Distribution: na Organization: Sun Microsystems, Mountain View Lines: 59 Paul Chernoff (chernoff@cartan.berkeley.edu) wrote: > > I would like to know why the Sun pixrect operation > for copying a "vertical" rectangle of a given size > (say 1 by 500) takes much longer than the corresponding > operation for copying a "horizontal" rectangle (say 500x1). and Chuck Brunow (loci@csccat.uucp) replied: > Probably because a raster is "horizontally" oriented in RAM. > Writeing 500 pixels across means memory in sequence, whereas > vertical writes must do a mapping computation for each line. > > At least that's the way that other machines work (unix-pc, > various ibm graphics. etc.) but I'm not sure about Sun's. While it is true that the address calculation for the next scanline takes longer than the calculation of the next byte, (y += bytes_per_scanline vs. y++) the more significant reason for the speed difference between a "flip horizontal" and a "flip vertical" is the bit operations, (rotate and shift) that must be performed on the horizontal version. To flip vertically, all operations are on byte (or other machine word) sized objects. These operations are "cheap" as they move 8 (or more) pixels to the desired position in one instruction. To flip horizontally, the bits in the byte (or other word) must be reversed. On most architectures, this requires more than one instruction, and in fact, usually a loop of n, where n is the machine word size. It is important to note that this is only an issue with bit-mapped displays. That is, each bit in a given display byte represents a pixel, which will be light or dark depending on its value, (1 or 0). If you are dealing with a color display such as a Sun CG2, where each pixel is represented by a byte, which is in turn a pointer to a 256 entry RGB color LUT, there will be no performance difference between horizontal and vertical flips since no bit operations are required. Patrick J. Naughton ARPA: naughton@Sun.COM Window Systems Group UUCP: ...!sun!naughton Sun Microsystems, Inc. AT&T: 415/336-2979 /\ \ \ Sun Microsystems, Inc \ \ \ 2550 Garcia Avenue \ \ \ Mountain View, CA 94043 / \ \ / (415) 960-1300 / / \/ / / (415) 336-2979 / / /\ / / /\ TLX 287815 \/ / / \/ / / / / /\ / / Patrick J. Naughton / \ \ / Software Engineer \ \ \ Window Systems \ \ \ \ \ Sun!naughton || naughton@Sun.COM \/