Previous: 4.51.2.4.7. ogClone() To the Table of Contents Next: 4.51.2.4.9. ogCopyLineFrom()
4.51.2.4.7. ogClone() Table of Contents 4.51.2.4.9. ogCopyLineFrom()

- 4.51.2.4.8. -
Table of Contents
4. Standard Units
4.51. ObjGfx40 - ObjectGraphics 4.0 Unit
4.51.2. ObjGfx40 Unit Object Types
4.51.2.4. ogSurface object
4.51.2.4.8. ogCopy()


4.51.2.4.8. ogCopy()

Targets: MS-DOS, Win32 console


ObjGfx40 Unit

Copies one ogSurface to another.

Declaration:
  procedure ogCopy(var srcObject:ogSurface);
Remarks:

If the source surface is larger than the destination surface, the image will be clipped to the destination buffer. If the destination is larger than the source, the source surface will appear at (0,0) of the destination. If the source and destination pixel formats and/or bitdepth is different, this method will convert the buffer as needed. Going from a high/true colour buffer to an 8BPP buffer can be very slow.

This is identical to calling:

    dest.ogCopyBuf(0, 0, source,
                   0, 0, source.ogGetMaxX, source.ogGetMaxY);
but is slightly more efficient.

Restrictions:

When dealing with two 8BPP buffers, this method does a byte for byte copy and does not check for differing palettes, nor will it remap pixel colours to the destination palette.

See also: Sample code:
{ogCopy.pas}

uses
  ObjGfx40, CRT;

var 
  buf8, buf16, buf24, buf32:^ogSurface;
  count:uInt32;

begin
  new(buf8, ogInit);
  new(buf16, ogInit);
  new(buf24, ogInit);
  new(buf32, ogInit);

  {create buffers with default pixel format for their bitdepth}

  if not buf8^.ogCreate(800, 600, OG_PIXFMT_8BPP) then
   begin
    writeln('Error allocating memory');
    halt
   end;

  if not buf16^.ogCreate(800, 600, OG_PIXFMT_16BPP) then
   begin
    writeln('Error allocating memory');
    halt
   end;

  if not buf24^.ogCreate(800, 600, OG_PIXFMT_24BPP) then
   begin
    writeln('Error allocating memory');
    halt
   end;

  if not buf32^.ogCreate(800, 600, OG_PIXFMT_32BPP) then
   begin
    writeln('Error allocating memory');
    halt
   end;

  if not screen^.ogCreate(800, 600, OG_PIXFMT_32BPP) then
   begin
    writeln('Error setting video mode');
    halt
   end;

  {Draw some rectangles and circles into the 8bpp buffer}

  with buf8^ do
    for count:=0 to ogGetMaxX div 2 do
      ogRect(ogGetMaxX div 2-count,ogGetMaxY div 2 -count,
             ogGetMaxX div 2+count,ogGetMaxY div 2 +count,(count mod 240)+16);

  with buf8^ do
     for count:=0 to ogGetMaxX div 2 do
       ogCircle(ogGetMaxX div 2,ogGetMaxY div 2,count,(count mod 240)+16);

  {Copy the original buffer into buf16.ogCopy() takes care of the pixel
   conversion}

  buf16^.ogCopy(buf8^);
  
  {Copy the 16bpp buffer into buf24.ogCopy() takes care of the pixel
   conversion}

  buf24^.ogCopy(buf16^);

  {Copy the 24bpp buffer into buf32.ogCopy() takes care of the pixel
   conversion}

  buf32^.ogCopy(buf24^);

  {Note thnat Screen^.ogCopy(buf8^); would accomplish the same thing but
   be much faster.  This method was used for demonstration only}
  screen^.ogCopy(buf32^);

  readKey;
  dispose(buf32, ogDone);
  dispose(buf24, ogDone);
  dispose(buf16, ogDone);
  dispose(buf8, ogDone);
end.



Previous: 4.51.2.4.7. ogClone() To the Table of Contents Next: 4.51.2.4.9. ogCopyLineFrom()
4.51.2.4.7. ogClone() Table of Contents 4.51.2.4.9. ogCopyLineFrom()

- 4.51.2.4.8. -