Metropoli BBS
VIEWER: progp091.pas MODE: TEXT (ASCII)
{***************************************************************}
{ Transfer source block of dimension DX x DY from XS,YS         }
{ to XD, YD                                                     }
{***************************************************************}

procedure slow_bitblt(xs, ys, xd, yd, dx, dy, fn:word);
{xs, ys Source upper left corner}
{xd, yd Destination upper left  }
{dx, dy Dimensions of the block }
{fn Logical operation           }
const
COPY =  0;
CLEAR = 1;
FUN_OR = 2;
FUN_XOR = 3;
FUN_AND = 4;
var
x_incr, y_incr, x_max, y_max, x, y, i, j, value : integer;
begin
        {**************************************************************}
        { Compute starting points and directions of transfer            }
        {**************************************************************}
        x := 0;                         { Assume no overlap or ++       }
        y := 0;                         { i.e. xs > xd && ys > yd       }
        x_incr := 1;
        y_incr := 1;

        if xs <= xd then if xs+dx >= xd then
        begin { Reverse x direction if source overlaps left half of dest.}
                x := dx - 1;
                x_incr := -1;
        end;

        if ys > yd then if ys <= yd+dy then
        begin { Reverse y direction if source overlaps bottom half of dest}
                y := dy - 1;
                y_incr := -1;
        end;

        {**************************************************************}
        { Transfer the block                                            }
        {**************************************************************}

        for j := 0 to dy-1 do begin             { Loop over rasters     }
                for i := 0 to dx-1 do begin     { Loop over pixels      }
                        case fn of              { Select logical op     }

                        COPY :  begin
                                value := pixel_read(xs+x,ys+y);
                                pixel_write(xd+x,yd+y,value);
                                end;

                        CLEAR:  begin
                                value := 0;
                                pixel_write(xd+x,yd+y,value);
                                end;

                        FUN_OR: begin
                                value := pixel_read(xs+x,ys+y) or
                                        pixel_read(xd+x,yd+x);
                                pixel_write(xd+x,yd+y,value);
                                end;

                        FUN_XOR: begin
                                value := pixel_read(xs+x,ys+y) xor
                                        pixel_read(xd+x,yd+x);
                                pixel_write(xd+x,yd+y,value);
                                end;

                        FUN_AND: begin
                                value := pixel_read(xs+x,ys+y) and
                                        pixel_read(xd+x,yd+x);
                                pixel_write(xd+x,yd+y,value);
                                end;
                        end;

                        x := x + x_incr;        { Update pixel pointer }
                end;
                y := y + y_incr;                { Update raster pointer}
                x := x - dx * x_incr;           { Reset pixel pointer   }
        end;
end;

[ RETURN TO DIRECTORY ]