1. Re: BitBlt

I sped up David Cuny's bitBlt().
I know he offered it as a generic, unoptimized
example, but I wanted to see how much faster I could make it go.
I managed to speed it up by a factor of 7.3 on the example
below, which copies a 20x20 image from a 100x100 image
into another 100x100 image. The main trick was to use slices
instead of an inner for-loop.

------- Cuny's reworked code follows...

-- I put together a generic blitter (included), but it's obviously slow.
WinMan
-- was based on an optimized version of this blitter, that understood 0 in
the
-- argument to be a screen, and handled clipping better. However, this
version
-- *is* generic.
-- I'd love to see a generic blitter added to the core Euphoria routines.
-- David Cuny

-- generic bit blitter
global constant
    CopyROP     = 1,    -- dst = src
    OrROP       = 2,    -- dst = dst OR src
    XorROP      = 3,    -- dst = dst XOR src
    EraseROP    = 4,    -- dst = (NOT src) AND dst
    NotCopyROP  = 5,    -- dst = NOT src
    NotOrROP    = 6,    -- dst = (NOT src) OR dst
    NotXorROP   = 7,    -- dst = (NOT src) XOR dst
    NotEraseROP = 8,    -- dst = src AND dst
    NotROP      = 9     -- dst = NOT dst

function opPixels( integer rop, object src, object dst )
    if    rop = CopyROP     then return src
    elsif rop = OrROP       then return or_bits(dst, src)
    elsif rop = XorROP      then return xor_bits(dst, src)
    elsif rop = EraseROP    then return and_bits( not(src), dst)
    elsif rop = NotCopyROP  then return not(src)
    elsif rop = NotOrROP    then return or_bits(not(src), dst)
    elsif rop = NotXorROP   then return xor_bits(not(src), dst)
    elsif rop = NotEraseROP then return and_bits(src, dst)
    elsif rop = NotROP      then return not(dst)
    end if
    -- error: unspecified rop code
end function

global function bitBlt( sequence dst, integer dx, integer dy,
   sequence src, integer sx, integer sy,
       integer sw, integer sh, integer rop )
    -- this function copies a block of pixels from one bitmap to
    -- another. bitBlt means bit block transfer.
    -- arguments:
    --
    --  dst     the device to copy to
    --  dx, dy  the position to copy to
    --  src     the device to copy from
    --  sx, sy  the position to copy from
    --  sw, sh  the width and height of the block to be copied
    --  rop     raster operation to be used when doing copying
    --
    -- this can obviously be specialized to operate *much* faster
    integer dx2, sx2, dyy

    -- avoid lots of -1's in the calculations
    dy = dy - sy
    sw = sw - 1
    dx2 = dx+sw
    sx2 = sx+sw
    for y = sy to sy+sh-1 do
        dyy = dy+y
        dst[dyy][dx..dx2] = opPixels( rop, src[y][sx..sx2],
                                                        dst[dyy][dx..dx2] )
    end for
    return dst
end function

-- timing test: copy 20x20 image
-- from a 100x100 to another 100x100
sequence source, dest, dest2
source = repeat(repeat(0, 100),100)
source[17][16..20] = 4
source[20][16..20] = 7
dest = source * 0
atom t
t = time()
for i = 1 to 10000 do
dest2 = bitBlt(dest, 81, 81,
                        source, 1, 1,
                        20,20,CopyROP)
end for
t = time() - t
? dest2
? t


Regards,
     Rob Craig
     Rapid Deployment Software
     http://members.aol.com/FilesEu/

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu