deb4998ba50060c48cce222fd18a8eed053918d7vboxsync/************************************************************
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncCopyright 1987 by Sun Microsystems, Inc. Mountain View, CA.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync All Rights Reserved
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncPermission to use, copy, modify, and distribute this
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncsoftware and its documentation for any purpose and without
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncfee is hereby granted, provided that the above copyright no-
deb4998ba50060c48cce222fd18a8eed053918d7vboxsynctice appear in all copies and that both that copyright no-
deb4998ba50060c48cce222fd18a8eed053918d7vboxsynctice and this permission notice appear in supporting docu-
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncmentation, and that the names of Sun or The Open Group
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncnot be used in advertising or publicity pertaining to
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncdistribution of the software without specific prior
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncwritten permission. Sun and The Open Group make no
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncrepresentations about the suitability of this software for
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncany purpose. It is provided "as is" without any express or
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncimplied warranty.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncSUN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncINCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE LI-
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncPROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncTHE USE OR PERFORMANCE OF THIS SOFTWARE.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync********************************************************/
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync/* Optimizations for PSZ == 32 added by Kyle Marvin (marvin@vitec.com) */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#if defined(XFREE86) || ( defined(__OpenBSD__) && defined(__alpha__) ) \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync || (defined(__bsdi__))
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * ==========================================================================
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * Converted from mfb to support memory-mapped color framebuffer by smarks@sun,
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * April-May 1987.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * The way I did the conversion was to consider each longword as an
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * array of four bytes instead of an array of 32 one-bit pixels. So
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * getbits() and putbits() retain much the same calling sequence, but
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * they move bytes around instead of bits. Of course, this entails the
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * removal of all of the one-bit-pixel dependencies from the other
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * files, but the major bit-hacking stuff should be covered here.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * I've created some new macros that make it easier to understand what's
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * going on in the pixel calculations, and that make it easier to change the
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * pixel size.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * name explanation
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * ---- -----------
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * PSZ pixel size (in bits)
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * PGSZ pixel group size (in bits)
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * PGSZB pixel group size (in bytes)
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * PGSZBMSK mask with lowest PGSZB bits set to 1
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * PPW pixels per word (pixels per pixel group)
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * PPWMSK mask with lowest PPW bits set to 1
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * PLST index of last pixel in a word (should be PPW-1)
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * PIM pixel index mask (index within a pixel group)
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * PWSH pixel-to-word shift (should be log2(PPW))
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * PMSK mask with lowest PSZ bits set to 1
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * Here are some sample values. In the notation cfbA,B: A is PSZ, and
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * B is PGSZB. All the other values are derived from these
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * two. This table does not show all combinations!
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * name cfb8,4 cfb24,4 cfb32,4 cfb8,8 cfb24,8 cfb32,8
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * ---- ------ ------- ------ ------ ------ -------
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * PSZ 8 24 32 8 24 32
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * PGSZ 32 32 32 64 64 64
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * PGSZB 4 4 4 8 8 8
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * PGSZBMSK 0xF 0xF? 0xF 0xFF 0xFF 0xFF
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * PPW 4 1 1 8 2 2
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * PPWMSK 0xF 0x1 0x1 0xFF 0x3? 0x3
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * PLST 3 0 0 7 1 1
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * PIM 0x3 0x0 0x0 0x7 0x1? 0x1
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * PWSH 2 0 0 3 1 1
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * PMSK 0xFF 0xFFFFFF 0xFFFFFFFF 0xFF 0xFFFFFF 0xFFFFFFFF
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * I have also added a new macro, PFILL, that takes one pixel and
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * replicates it throughout a word. This macro definition is dependent
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * upon pixel and word size; it doesn't use macros like PPW and so
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * forth. Examples: for monochrome, PFILL(1) => 0xffffffff, PFILL(0) =>
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * 0x00000000. For 8-bit color, PFILL(0x5d) => 0x5d5d5d5d. This macro
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * is used primarily for replicating a plane mask into a word.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * Color framebuffers operations also support the notion of a plane
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * mask. This mask determines which planes of the framebuffer can be
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * altered; the others are left unchanged. I have added another
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * parameter to the putbits and putbitsrop macros that is the plane
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * ==========================================================================
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * Keith Packard (keithp@suse.com)
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * 64bit code is no longer supported; it requires DIX support
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * for repadding images which significantly impacts performance
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * PSZ needs to be defined before we get here. Usually it comes from a
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * -DPSZ=foo on the compilation command line.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * PixelGroup is the data type used to operate on groups of pixels.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * We typedef it here to CARD32 with the assumption that you
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * want to manipulate 32 bits worth of pixels at a time as you can. If CARD32
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * is not appropriate for your server, define it to something else
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * before including this file. In this case you will also have to define
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * PGSZB to the size in bytes of PixelGroup.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#endif /* PixelGroup */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define PPWMSK (((PixelGroup)1 << PPW) - 1) /* instead of BITMSK */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync/* set PWSH = log2(PPW) using brute force */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#endif /* PPW == 16 */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#endif /* PPW == 8 */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#endif /* PPW == 4 */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#endif /* PPW == 2 */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#endif /* PPW == 1 */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync/* Defining PIXEL_ADDR means that individual pixels are addressable by this
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * machine (as type PixelType). A possible CFB architecture which supported
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * 8-bits-per-pixel on a non byte-addressable machine would not have this
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * Defining FOUR_BIT_CODE means that cfb knows how to stipple on this machine;
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * eventually, stippling code for 16 and 32 bit devices should be written
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * which would allow them to also use FOUR_BIT_CODE. There isn't that
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * much to do in those cases, but it would make them quite a bit faster.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync/*#undef PIM
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define PIM 3*/
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync/* the following notes use the following conventions:
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncSCREEN LEFT SCREEN RIGHT
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncin this file and maskbits.c, left and right refer to screen coordinates,
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncNOT bit numbering in registers.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsynccfbstarttab[n]
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync pixels[0,n-1] = 0's pixels[n,PPW-1] = 1's
deb4998ba50060c48cce222fd18a8eed053918d7vboxsynccfbendtab[n] =
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync pixels[0,n-1] = 1's pixels[n,PPW-1] = 0's
deb4998ba50060c48cce222fd18a8eed053918d7vboxsynccfbstartpartial[], cfbendpartial[]
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync these are used as accelerators for doing putbits and masking out
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncbits that are all contained between longword boudaries. the extra
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync256 bytes of data seems a small price to pay -- code is smaller,
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncand narrow things (e.g. window borders) go faster.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncthe names may seem misleading; they are derived not from which end
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncof the word the bits are turned on, but at which end of a scanline
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncthe table tends to be used.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsynclook at the tables and macros to understand boundary conditions.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync(careful readers will note that starttab[n] = ~endtab[n] for n != 0)
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync-----------------------------------------------------------------------
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncthese two macros depend on the screen's bit ordering.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncin both of them x is a screen position. they are used to
deb4998ba50060c48cce222fd18a8eed053918d7vboxsynccombine bits collected from multiple longwords into a
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncsingle destination longword, and to unpack a single
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncsource longword into multiple destinations.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncSCRLEFT(dst, x)
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync takes dst[x, PPW] and moves them to dst[0, PPW-x]
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync the contents of the rest of dst are 0 ONLY IF
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync dst is UNSIGNED.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync is cast as an unsigned.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync this is a right shift on the VAX, left shift on
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync Sun and pc-rt.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncSCRRIGHT(dst, x)
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync takes dst[0,x] and moves them to dst[PPW-x, PPW]
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync the contents of the rest of dst are 0 ONLY IF
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync dst is UNSIGNED.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync this is a left shift on the VAX, right shift on
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync Sun and pc-rt.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncthe remaining macros are cpu-independent; all bit order dependencies
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncare built into the tables and the two macros above.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncmaskbits(x, w, startmask, endmask, nlw)
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync for a span of width w starting at position x, returns
deb4998ba50060c48cce222fd18a8eed053918d7vboxsynca mask for ragged pixels at start, mask for ragged pixels at end,
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncand the number of whole longwords between the ends.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncmaskpartialbits(x, w, mask)
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync works like maskbits(), except all the pixels are in the
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync same longword (i.e. (x&0xPIM + w) <= PPW)
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncmask32bits(x, w, startmask, endmask, nlw)
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync as maskbits, but does not calculate nlw. it is used by
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync cfbGlyphBlt to put down glyphs <= PPW bits wide.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncgetbits(psrc, x, w, dst)
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync starting at position x in psrc (x < PPW), collect w
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync pixels and put them in the screen left portion of dst.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync psrc is a longword pointer. this may span longword boundaries.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync it special-cases fetching all w bits from one longword.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync +--------+--------+ +--------+
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync | | m |n| | ==> | m |n| |
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync +--------+--------+ +--------+
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync psrc psrc+1 dst
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync m = PPW - x
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync implementation:
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync get m pixels, move to screen-left of dst, zeroing rest of dst;
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync get n pixels from next word, move screen-right by m, zeroing
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync lower m pixels of word.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync OR the two things together.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncputbits(src, x, w, pdst, planemask)
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync starting at position x in pdst, put down the screen-leftmost
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync w bits of src. pdst is a longword pointer. this may
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync span longword boundaries.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync it special-cases putting all w bits into the same longword.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync +--------+ +--------+--------+
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync | m |n| | ==> | | m |n| |
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync +--------+ +--------+--------+
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync dst pdst pdst+1
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync m = PPW - x
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync implementation:
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync get m pixels, shift screen-right by x, zero screen-leftmost x
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync pixels; zero rightmost m bits of *pdst and OR in stuff
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync from before the semicolon.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync shift src screen-left by m, zero bits n-32;
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync zero leftmost n pixels of *(pdst+1) and OR in the
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync stuff from before the semicolon.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncputbitsrop(src, x, w, pdst, planemask, ROP)
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync like putbits but calls DoRop with the rasterop ROP (see cfb.h for
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncgetleftbits(psrc, w, dst)
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync get the leftmost w (w<=PPW) bits from *psrc and put them
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync in dst. this is used by the cfbGlyphBlt code for glyphs
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync <=PPW bits wide.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#else /* (BITMAP_BIT_ORDER == LSBFirst) */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#endif /* (BITMAP_BIT_ORDER == MSBFirst) */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * Note that the shift direction is independent of the byte ordering of the
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * machine. The following is portable code.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#endif /* PPW == 16 */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * Reduced raster op - using precomputed values, perform the above
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * in three instructions
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define DoRRop(dst, and, xor) (((dst) & (and)) ^ (xor))
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync mask = cfbstartpartial[(x) & 3] & cfbendpartial[((x)+(w)) & 3];
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync register int idx; \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync dst = BitLeft((*(psrc) &cfbmask[idx]), cfb24Shift[idx]); \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync dst = BitLeft((*(psrc) &cfbmask[idx]), cfb24Shift[idx]) | \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync BitRight(((*((psrc)+1)) &cfbmask[idx+1]), cfb24Shift[idx+1]); \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define putbits24(src, w, pdst, planemask, index) {\
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync register unsigned int idx; \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync dstpixel = BitLeft((*(pdst) &cfbmask[idx]), cfb24Shift[idx]); \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync dstpixel = BitLeft((*(pdst) &cfbmask[idx]), cfb24Shift[idx])| \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync BitRight(((*((pdst)+1)) &cfbmask[idx+1]), cfb24Shift[idx+1]); \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync (BitLeft(dstpixel, cfb24Shift[idx]) & cfbmask[idx]); \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync *(pdst) |= (BitRight(dstpixel, cfb24Shift[idx]) & cfbmask[idx]); \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define putbitsrop24(src, x, pdst, planemask, rop) \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync register unsigned int idx; \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync dstpixel = BitLeft((*(pdst) &cfbmask[idx]), cfb24Shift[idx]); \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync dstpixel = BitLeft((*(pdst) &cfbmask[idx]), cfb24Shift[idx])| \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync BitRight(((*((pdst)+1)) &cfbmask[idx+1]), cfb24Shift[idx+1]); \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync *((pdst)+1) = ((*((pdst)+1)) & cfbrmask[idx+1]) | \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync (BitLeft(dstpixel, cfb24Shift[idx+1]) & (cfbmask[idx+1])); \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync *(pdst) |= (BitRight(dstpixel, cfb24Shift[idx]) & cfbmask[idx]); \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync# else /* PSZ == 24 && PPW == 1 */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync mask = cfbstartpartial[(x) & PIM] & cfbendpartial[((x) + (w)) & PIM];
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define putbitsrop24(src, x, pdst, planemask, rop) \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#endif /* PSZ == 24 && PPW == 1 */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncif ( ((x) + (w)) <= PPW) \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncif ( ((x)+(w)) <= PPW) \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync *(pdst) = (*(pdst) & ~tmpmask) | (SCRRIGHT(src, x) & tmpmask); \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync unsigned int m; \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync unsigned int n; \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync n = (w) - m; \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync *((pdst)+1) = (*((pdst)+1) & (cfbstarttab[n] | ~pm)) | \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync asm ("bfextu %3{%1:%2},%0" \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync : "=d" (dst) : "di" (x), "di" (w), "o" (*(char *)(psrc)))
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync asm ("bfins %3,%0{%1:%2}" \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync : "di" (x), "di" (w), "d" (src), "0" (*(char *) (pdst)))
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync FASTPUTBITS(SCRRIGHT(src, PPW-(w)), (x) * PSZ, (w) * PSZ, pdst); \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#endif /* mc68020 */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define putbitsrop(src, x, w, pdst, planemask, rop) \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncif ( ((x)+(w)) <= PPW) \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync n = (w) - m; \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync *(pdst) = (*(pdst) & (cfbendtab[x] | ~pm)) | (t2 & (cfbstarttab[x] & pm));\
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync *((pdst)+1) = (*((pdst)+1) & (cfbstarttab[n] | ~pm)) | \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#else /* PSZ == 32 && PPW == 1*/
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * These macros can be optimized for 32-bit pixels since there is no
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * need to worry about left/right edge masking. These macros were
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * derived from the above using the following reductions:
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * - x & PIW = 0 [since PIW = 0]
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * - all masking tables are only indexed by 0 [ due to above ]
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * - cfbstartab[0] and cfbendtab[0] = 0 [ no left/right edge masks]
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * - cfbstartpartial[0] and cfbendpartial[0] = ~0 [no partial pixel mask]
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * Macro reduction based upon constants cannot be performed automatically
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * by the compiler since it does not know the contents of the masking
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * For 32-bit operations, getbits(), putbits(), and putbitsrop()
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * will only be invoked with x = 0 and w = PPW (1). The getbits()
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * macro is only called within left/right edge logic, which doesn't
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * happen for 32-bit pixels.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync *(pdst) = (*(pdst) & ~planemask) | (src & planemask);
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define putbitsrop(src, x, w, pdst, planemask, rop) \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync *(pdst) = (*(pdst) & ~planemask) | (t1 & planemask); \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#endif /* PSZ != 32 */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * Use these macros only when you're using the MergeRop stuff
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync/* useful only when not spanning destination longwords */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync/* useful only when spanning destination longwords */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync pdst[0] = DoMaskMergeRop(_t1,pdst[0],_startmask); \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncif ((x) + (w) <= PPW) {\
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define getleftbits(psrc, w, dst) dst = *((unsigned int *) psrc)
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync dst = BitLeft(((*((unsigned int *) psrc))&cfbmask[index]), cfb24Shift[index]); \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync dst |= BitRight(((*((unsigned int *) psrc)+1)&cfbmask[index]), cfb4Shift[index]); \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync dst = BitLeft((*((unsigned int *) psrc)),cfb24Shift[index]); \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#endif /* GETLEFTBITS_ALIGNMENT == 1 */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync if ( ((x) + (w)) > 32) \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync dst |= (BitRight((unsigned) *((psrc)+1), 32-(x))); \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync getglyphbits( ((unsigned int *)(((char *)(psrc))-1)), 8, (w), (dst) ); \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#endif /* GETLEFTBITS_ALIGNMENT == 2 */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#endif /* GETLEFTBITS_ALIGNMENT == 4 */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * getstipplepixels( psrcstip, x, w, ones, psrcpix, destpix )
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * Converts bits to pixels in a reasonable way. Takes w (1 <= w <= PPW)
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * bits from *psrcstip, starting at bit x; call this a quartet of bits.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * Then, takes the pixels from *psrcpix corresponding to the one-bits (if
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * ones is TRUE) or the zero-bits (if ones is FALSE) of the quartet
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * and puts these pixels into destpix.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * getstipplepixels( &(0x08192A3B), 17, 4, 1, &(0x4C5D6E7F), dest )
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * 0x08192A3B = 0000 1000 0001 1001 0010 1010 0011 1011
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * This will take 4 bits starting at bit 17, so the quartet is 0x5 = 0101.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * It will take pixels from 0x4C5D6E7F corresponding to the one-bits in this
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * quartet, so dest = 0x005D007F.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * XXX Works with both byte order.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * XXX This works for all values of x and w within a doubleword.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define getstipplepixels( psrcstip, x, w, ones, psrcpix, destpix ) \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync q = (*(psrcstip)) << m; \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync q = (*(psrcstip)) >> -m; \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync *(destpix) = (*(psrcpix)) & QuartetPixelMaskTable[q]; \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync/* I just copied this to get the linker satisfied on PowerPC,
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * so this may not be correct at all.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define getstipplepixels24(psrcstip,xt,ones,psrcpix,destpix,stipindex) \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync *(destpix) = (*(psrcpix)) & QuartetPixelMaskTable[q]; \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#else /* BITMAP_BIT_ORDER == LSB */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync/* this must load 32 bits worth; for most machines, thats an int */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define getstipplepixels( psrcstip, xt, w, ones, psrcpix, destpix ) \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync q |= (CfbFetchUnaligned((psrcstip)+1)) << ((PPW*PSZ)-(xt)); \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync *(destpix) = (*(psrcpix)) & QuartetPixelMaskTable[q]; \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define getstipplepixels24(psrcstip,xt,w,ones,psrcpix,destpix,stipindex,srcindex,dstindex) \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync register unsigned int sidx; \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync register unsigned int didx; \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync/* if((srcindex)!=0)*/ \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync/* src = (((*(psrcpix)) << cfb24Shift[sidx]) & (cfbmask[sidx])) |*/ \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync/* (((*((psrcpix)+1)) << cfb24Shift[sidx+1]) & (cfbmask[sidx+1])); */\
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync (BitLeft(src, cfb24Shift[didx]) & (cfbmask[didx])); \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync *(destpix) |= (BitRight(src, cfb24Shift[didx]) & cfbmask[didx]); \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define getstipplepixels24(psrcstip,xt,ones,psrcpix,destpix,stipindex) \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync *(destpix) = (*(psrcpix)) & QuartetPixelMaskTable[q]; \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#endif /* PSZ == 24 */