Previous: 4.51.2.4.47. ogScale() To the Table of Contents Next: 4.51.2.4.49. ogSetAlpha()
4.51.2.4.47. ogScale() Table of Contents 4.51.2.4.49. ogSetAlpha()

- 4.51.2.4.48. -
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.48. ogScaleBuf()


4.51.2.4.48. ogScaleBuf()

Targets: MS-DOS, Win32 console


ObjGfx40 Unit

Scales a region of one surface to a region of another surface.

Declaration:
  procedure ogScaleBuf(dX1, dY1, dX2, dY2:int32; 
                        var srcObject:ogSurface; 
                        sX1, sY1, sX2, sY2:int32);
Remarks:

Scales the region defined by (sX1,sY1),(sX2,sY2) to the destination region (dX1,dY1),(dX2,dY2). Will do pixel conversion if the surfaces are not the same bitdepth or pixel format.

Restrictions:

Will do nothing if the any of the source coordinates are out of bounds. Will clip to valid coordinates in the destination surface if any of the destination coordinates are out of bounds, thus keeping the apsect ratio.

See also: Sample code:
{ogScale.pas}

uses
  ObjGfx40, CRT;

var 
  buf:^ogSurface;
  pixfmt:ogPixelFmt;
  xx, yy, zz:uInt32;
  sX1, sY1, sX2, sY2, dX1, dY1, dX2, dY2:uInt32;
    
begin
  new(buf, ogInit);

  {Set the screen up as 1024x768 in true colour}
  if not screen^.ogCreate(1024, 768, OG_PIXFMT_32BPP) then
    begin
      writeln('Error setting video mode');
      halt
    end;

  {Create a 320x200 buffer with the same pixel format as the screen}
  screen^.ogGetPixFmt(pixfmt);
  buf^.ogCreate(320, 256, pixfmt);

  {Draw the RGB cube}
  zz:=1;
  repeat
    with screen^ do
    for yy:=0 to 255 do
      for xx:=0 to 255 do
        if (yy=0) or (xx=255) or (zz=253) then
        ogSetPixel(256+256+(xx div 2)-(zz div 4),128+(yy div 2)+(zz div 4),
                   ogRGB(xx,255-yy,zz));
    inc(zz,2);
  until (zz>255);

  {Now scale sections of the cube to other portions of the screen}
  with screen^ do
    begin
     {Since we deal with the coordinates several times, set them up
      in variables.  These could be passed directly into ogScaleBuf()
      if desired.}

      sX1 := 512-63;
      sY1 := 256-63;
      sX2 := 512+63;
      sY2 := 255+63;
      dX1 := 0;
      dY1 := 384;
      dX2 := 255;
      dY2 := 384+255;

      {Draw this line first since it goes behind the scaled area}
      ogLine(dX1, dY2, sX1-1, sY2+1, ogRGB(255, 255, 255));

      ogScaleBuf(dX1, dY1, dX2, dY2, screen^, sX1, sY1, sX2, sY2);

      ogLine(dX1, dY1, sX1, sY1, ogRGB(255, 255, 255));
      ogLine(dX2, dY1, sX2, sY1, ogRGB(255, 255, 255));
      ogLine(dX2, dY2, sX2, sY2, ogRGB(255, 255, 255));
      ogRect(sX1, sY1, sX2, sY2, ogRGB(255, 255, 255));
      ogRect(dX1, dY1, dX2, dY2, ogRGB(255, 255, 255));

      sX1 := 511-40;
      sY1 := 255+20;
      sX2 := 511+40;
      sY2 := 255+40;
      dX1 := 700;
      dY1 := 400;
      dX2 := 850;
      dY2 := 700;

      ogLine(dX2, dY2, sX2, sY2, ogRGB(255, 255, 255));
      ogScaleBuf(dX1, dY1, dX2, dY2, screen^, sX1, sY1, sX2, sY2);
      ogLine(dX1, dY2, sX1, sY2, ogRGB(255, 255, 255));
      ogLine(dX2, dY1, sX2, sY1, ogRGB(255, 255, 255));
      ogLine(dX1, dY1, sX1, sY1, ogRGB(255, 255, 255));
      ogRect(sX1, sY1, sX2, sY2, ogRGB(255, 255, 255));
      ogRect(dX1, dY1, dX2, dY2, ogRGB(255, 255, 255));

      sX1 := 512+75;
      sY1 := 150;
      sX2 := 512+110;
      sY2 := 190;
      dX1 := ogGetMaxX-200;
      dY1 := 0;
      dX2 := ogGetMaxX;
      dY2 := 250;

      ogLine(dX2, dY1, sX2+1, sY1, ogRGB(255, 255, 255));
      ogLine(dX2, dY2, sX2+1, sY2+1, ogRGB(255, 255, 255));
      ogScaleBuf(dX1, dY1, dX2, dY2, screen^, sX1, sY1, sX2, sY2);
      ogLine(dX1, dY2, sX1, sY2, ogRGB(255, 255, 255));
      ogLine(dX1, dY1, sX1, sY1, ogRGB(255, 255, 255));
      ogRect(sX1, sY1, sX2, sY2, ogRGB(255, 255, 255));
      ogRect(dX1, dY1, dX2, dY2, ogRGB(255, 255, 255));
    end; {with}

    for xx:=0 to 5 do
      begin
        {Scale the screen to the buffer}
        buf^.ogScale(screen^);
        {Draw a white rectangle around the edge of Buf}
        buf^.ogRect(0, 0, buf^.ogGetMaxX, buf^.ogGetMaxY, buf^.ogRGB(255, 255, 255));
        {Copy Buf back to the screen (in the upper left)}
        screen^.ogCopy(buf^);
      end;

  readKey;
  dispose(buf, ogDone);
end.



Previous: 4.51.2.4.47. ogScale() To the Table of Contents Next: 4.51.2.4.49. ogSetAlpha()
4.51.2.4.47. ogScale() Table of Contents 4.51.2.4.49. ogSetAlpha()

- 4.51.2.4.48. -