home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 8 / CDASC08.ISO / NEWS / 554 / JUIN / NEWBTMAP.PAS < prev    next >
Pascal/Delphi Source File  |  1993-10-07  |  2KB  |  87 lines

  1. {─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
  2. Msg  : 473 of 619
  3. From : Sean Palmer                         1:104/123.0          09 Jun 93  00:14
  4. To   : All
  5. Subj : Scaling bitmaps revisite
  6. ────────────────────────────────────────────────────────────────────────────────
  7. Well, I got a wild hair up my butt and decided to convert that
  8. bitmap scaler I posted into an inline assembler procedure (mostly)
  9. It's now quite a bit faster...
  10.  
  11. You guys should be paying me for this stuff!! 8)}
  12.  
  13. {by Sean Palmer}
  14. {public domain}
  15.  
  16. {bitmaps are limited to 256x256 (duh)}
  17. type
  18.  fixed=record case boolean of
  19.         true:(w:longint);
  20.         false:(f,i:word);
  21.         end;
  22.  
  23. procedure scaleBitmap(var bitmap;x,y:byte;x1,y1,x2,y2:word);
  24. var
  25.  s,w,h:word;  {xSkip,width,height}
  26.  sx,sy,cy:fixed; {xinc, yinc, ySrcPos}
  27. begin
  28.  w:=x2-x1+1;
  29.  h:=y2-y1+1;
  30.  sx.w:=x*$10000 div w;
  31.  sy.w:=y*$10000 div h;
  32.  s:=320-w;
  33.  cy.w:=0;
  34. asm
  35.  push ds
  36.  mov ds,word ptr bitmap+2;
  37.  mov ax,$A000; mov es,ax;  {setup screen seg}
  38.  cld
  39.  mov ax,320; mul y1; add ax,x1; mov di,ax; {calc screen adr}
  40. @L2:
  41.  mov ax,cy.i
  42.  mul x
  43.  mov bx,ax
  44.  add bx,word ptr bitmap {offset}
  45.  mov cx,w
  46.  mov si,0     {fraction of src adr (bx.si)}
  47.  mov dx,sx.f
  48. @L: mov al,[bx]
  49.  stosb
  50.  add si,dx
  51.  adc bx,sx.i    {if carry or sx.i<>0, new source pixel}
  52.  loop @L
  53.  add di,s     {skip to next screen row}
  54.  mov ax,sy.f; mov bx,sy.i;
  55.  add cy.f,ax; adc cy.i,bx;
  56.  dec word ptr h
  57.  jnz @L2
  58.  pop ds
  59.  end;
  60. end;
  61.  
  62. const
  63.  bmp:array[0..3,0..3]of byte=
  64.   ((0,1,2,3),
  65.    (1,2,3,4),
  66.    (2,3,4,5),
  67.    (3,4,5,6));
  68. var
  69.  bmp2:array[0..63,0..63]of byte;
  70.  
  71. var i,j:integer;
  72.  
  73. begin
  74.  for i:=0 to 63 do   {init bmp2}
  75.   for j:=0 to 63 do
  76.    bmp2[j,i]:=j+(i xor $19)+32;
  77.  asm mov ax,$13; int $10; end;   {init vga mode 13h}
  78.  for i:=2 to 99 do                 {test bmp}
  79.   scaleBitMap(bmp,4,4,0,0,i*2-1,i*2-1);
  80.  for i:=99 downto 2 do
  81.   scaleBitMap(bmp,4,4,0,0,i*2-1,197);
  82.  for i:=1 to 66 do                 {test bmp2}
  83.   scaleBitMap(bmp2,64,64,0,0,i*2-1,i*3-1);
  84.  for i:=66 downto 1 do
  85.   scaleBitMap(bmp2,64,64,0,0,i*2-1,i*2-1+66);
  86.  asm mov ax,$3; int $10; end;      {restore text mode}
  87.  end.