[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Drawing into Bitmaps



    Date: Mon, 27 Jan 1992 22:36 PST
    From: myers@atr-la.atr.co.jp (John K. Myers)

    I need the following functionality: a macro that encloses a body of drawing
    routines, with the argument of an existing bitmap, such that the figures
    drawn by the drawing routines in absolute coordinates are drawn into the bitmap;
    figures drawn overlapping or outside of  the edges of the bitmap are clipped;
    and the alu is preserved (allowing selective erasing, flipping, etc.).

You already got the right answer for this, but I thought that I
would point out that tv:with-output-to-bitmap actually returns
five values, the bitmap and the four "bounding box" edge
coordinates.  Thus, you can find out where in the "absolute"
coordinate system the top-left edge of the bitmap should be
placed by capturing the second and third return values, and then
use those offsets as the TO-X and TO-y args in your call to
BITBLT.

    My current routine is the following:
    (defmacro draw-into-bitmap (my-bitmap &rest body)
    "Wrapper for drawing into a bitmap, instead of onto the screen.
       The body *must* use magic variable STREAM as the output.
       UNFORTUNATELY AUTO-ADJUSTS THE BITMAT TO THE UPPER LEFT.
       Remember in bitmaps, X points to the right, Y points down.
    "
      `(multiple-value-bind (my-width my-height ignore-span-width)   (decode-raster-array ,my-bitmap)
	 (let ((buffer  (tv:with-output-to-bitmap (stream) ,@body)))
	     (multiple-value-bind (new-width new-height ignore-span-width)   (decode-raster-array buffer)
	       (setq my-width (min my-width new-width))
	       (setq my-height (min my-height new-height))
	       (bitblt tv:alu-ior my-width my-height buffer 0 0 ,my-bitmap 0 0)   ;1 bits set; 0 bits left alone
	       )
	     )
	 )
    )