home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / grafik / xlib / demo2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-12  |  6.4 KB  |  211 lines

  1. /*************************************************************************
  2.  
  3. DEMO 2
  4.  
  5. Demonstrates the speed difference between compiled bitmap,  conventional
  6. masked planar bitmap, and video bitmap blits.
  7.  
  8. **************************************************************************/
  9.  
  10.  
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <conio.h>
  15. #include <ctype.h>
  16. #include <alloc.h>
  17. #include <dos.h>
  18. #include "xlib.h"
  19. #include "xcbitmap.h"
  20. #include "xpbitmap.h"
  21. #include "xvbitmap.h"
  22. #include "xbmtools.h"
  23. #include  "xtext.h"
  24. #include  "xrect.h"
  25.  
  26. /* Macro to make pointer parameters model independent */
  27. #define FARPTR(x) (MK_FP(FP_SEG(x),FP_OFF(x)))
  28.  
  29. char turtle[] = {
  30.     20,30,
  31. /*  |      .       |       .      |       .      |      .       */
  32.     8,14, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  33.     8, 2,14, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  34.     8, 2, 2, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  35.     8, 0, 2,14, 0, 0,14,14,14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  36.     8, 0, 2, 5, 0, 4, 4, 4, 4,14,14, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  37.     8, 0, 2, 2, 4, 4, 0, 4, 4, 0, 4,14, 0, 0, 0, 0, 0, 0, 0, 0,
  38.     0, 0, 2, 4, 4, 4, 0, 4, 4, 0, 4, 4,14, 0, 0, 0, 0, 0, 0, 0,
  39.     0, 0, 2, 4, 4, 4, 0, 0, 0, 0, 4, 4,14, 0, 0, 0, 0, 0, 0, 0,
  40.     0, 0, 0, 0, 4, 0, 4, 4, 4, 0, 0, 0, 4, 0, 0, 2, 2, 0, 0, 0,
  41.     0, 0, 0, 4, 0, 4, 4, 4, 0, 4, 4, 4, 0,14, 0, 0, 2, 2, 0, 0,
  42.     0, 0, 0, 4, 4, 0, 0, 0, 4, 4, 0, 4, 0, 4, 2, 2, 2, 2, 0, 0,
  43.     0, 0, 0, 4, 4, 4, 0, 4, 4, 0, 4, 4, 0, 4,14, 2, 2, 2, 0, 0,
  44.     0, 0, 0, 4, 4, 4, 0, 0, 0, 4, 4, 0, 4, 0, 0, 2, 2, 0, 0, 0,
  45.     0, 0, 0, 2, 4, 4, 4, 4, 4, 4, 4, 0, 4, 4,14, 2, 0, 0, 0, 0,
  46.     0, 0, 2, 2, 0, 4, 4, 4, 4, 0, 0, 4, 4, 4, 4, 0, 0, 0, 0, 0,
  47.     2, 2, 2, 2, 4, 0, 0, 4, 4, 0, 4, 4, 0, 4,14, 0, 0, 0, 0, 0,
  48.     0, 2, 2, 0, 4, 4, 4, 0, 0, 4, 4, 0, 4, 0, 2, 0, 0, 0, 0, 0,
  49.     0, 0, 0, 0, 0, 4, 4, 0, 4, 4, 4, 0, 4, 4, 2,14, 0, 0, 0, 0,
  50.     0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 0, 4, 0, 2, 2,14,14, 0, 0,
  51.     0, 0, 0, 0, 0, 0, 0, 4, 4, 0, 0, 4, 4, 2, 2, 2, 2, 2,14, 0,
  52.     0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2, 5,14, 0,
  53.     0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 2, 2, 0, 0, 2, 2, 2, 0, 2,14,
  54.     0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 2, 2, 2,14,
  55.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 2, 2, 2,
  56.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, 0,
  57.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0,
  58.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0,
  59.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0,
  60.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0,
  61.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  62.     };
  63.  
  64.  
  65. char far *pbm, far *vbm;
  66. char far *newfnt;
  67.  
  68. char far *
  69. AllocatedSprite(int width, int height, int logical_width, char far * bitmap)
  70. {
  71.     char far * result;
  72.     int size;
  73.  
  74.     pbm = farmalloc(width * height + 2);
  75.     x_bm_to_pbm(bitmap,pbm);
  76.  
  77.     result = farmalloc((width * height * 7) / 2 + 25);
  78.     if (result == 0)
  79.         return(0);
  80.     size = x_compile_bitmap(logical_width, bitmap, result);
  81.  
  82.     return farrealloc(result, size);
  83. }
  84.  
  85.  
  86. void load_user_fonts(){
  87.   FILE *f;
  88.   int i; char c;
  89.   f=fopen("6x8b.fnt","rb");
  90.   newfnt = farmalloc(256*8+4);
  91.   for (i=0;i<256*8+4;i++){
  92.     fread(&c,1,1,f);
  93.     *(newfnt+i)=c;
  94.   }
  95.   fclose(f);
  96.   x_text_init();
  97.   x_register_userfont(newfnt);
  98.   x_set_font(2);
  99. }
  100.  
  101. void
  102. main()
  103. {
  104.     int i,j;
  105.     double ratio,ratio2;
  106.     struct time pbm_t0,pbm_t1,cbm_t0,cbm_t1,vbm_t0,vbm_t1;
  107.     long vbm_ticks,pbm_ticks,cbm_ticks;
  108.     char far * TurtleSprite;
  109.  
  110.     x_set_mode(7,360);
  111.  
  112.  
  113.     TurtleSprite = AllocatedSprite(20, 30, 90,FARPTR(turtle));
  114.  
  115.     vbm = x_make_vbm(MK_FP(_DS,turtle),&NonVisual_Offs);
  116.     if (!vbm) {
  117.       sound(1000);
  118.       delay(100);
  119.       nosound();
  120.     }
  121.  
  122.     load_user_fonts();
  123.     x_bgprintf(0,0,0,14,0,
  124.       "This is a demo to show the speed difference between");
  125.     x_bgprintf(0,8,0,14,0,
  126.       "compiled, planar and video bitmaps.  The bitmap:");
  127.  
  128.     x_put_cbitmap(140, 18, 0, TurtleSprite);
  129.  
  130.     x_bgprintf(0,48,0,14,0,
  131.       "This demo uses the NON CLIPPED, MASKED versions of");
  132.     x_bgprintf(0,56,0,14,0,
  133.        "       'PBM' and VBM' put functions");
  134.     x_bgprintf(0,78,0,14,0,
  135.       "Press a key to start with PLANAR BITMAP demo");
  136.  
  137.     getch();
  138.     x_rect_fill(0,0,ScrnPhysicalPixelWidth,ScrnPhysicalHeight,0,0);
  139.  
  140.  
  141.     gettime(&pbm_t0);
  142.     for (j=0;j<(ScrnPhysicalHeight/30);j++)
  143.       for (i=0;i<(ScrnPhysicalPixelWidth/20);i++)
  144.     x_put_masked_pbm(i*20, j*30, 0, pbm);
  145.     gettime(&pbm_t1);
  146.     pbm_ticks = (((long)pbm_t1.ti_hund
  147.         +((long)pbm_t1.ti_sec*100)
  148.         +((long)pbm_t1.ti_min*6000)) -
  149.         (((long)pbm_t0.ti_hund
  150.         +((long)pbm_t0.ti_sec*100)
  151.         +((long)pbm_t0.ti_min*6000))));
  152.  
  153.  
  154.     x_bgprintf(0,0,0,14,0,
  155.       "Press a key to start with the VIDEO BITMAP demo");
  156.  
  157.     getch();
  158.     x_rect_fill(0,0,ScrnPhysicalPixelWidth,ScrnPhysicalHeight,0,0);
  159.  
  160.  
  161.     gettime(&vbm_t0);
  162.     for (j=0;j<(ScrnPhysicalHeight/30);j++)
  163.       for (i=0;i<(ScrnPhysicalPixelWidth/20);i++)
  164.     x_put_masked_vbm(i*20, j*30, 0, vbm);
  165.     gettime(&vbm_t1);
  166.     vbm_ticks = (((long)vbm_t1.ti_hund
  167.         +((long)vbm_t1.ti_sec*100)
  168.         +((long)vbm_t1.ti_min*6000)) -
  169.         (((long)vbm_t0.ti_hund
  170.         +((long)vbm_t0.ti_sec*100)
  171.         +((long)vbm_t0.ti_min*6000))));
  172.  
  173.  
  174.  
  175.  
  176.     x_bgprintf(0,0,0,14,0,
  177.       "Now Press a key to start with COMPILED BITMAP demo");
  178.  
  179.     getch();
  180.     x_rect_fill(0,0,ScrnPhysicalPixelWidth,ScrnPhysicalHeight,0,0);
  181.  
  182.     gettime(&cbm_t0);
  183.     for (j=0;j<(ScrnPhysicalHeight/30);j++)
  184.       for (i=0;i<(ScrnPhysicalPixelWidth/20);i++)
  185.     x_put_cbitmap(i*20, j*30, 0, TurtleSprite);
  186.     gettime(&cbm_t1);
  187.     cbm_ticks = (((long)cbm_t1.ti_hund
  188.         +((long)cbm_t1.ti_sec*100)
  189.         +((long)cbm_t1.ti_min*6000)) -
  190.         (((long)cbm_t0.ti_hund
  191.         +((long)cbm_t0.ti_sec*100)
  192.         +((long)cbm_t0.ti_min*6000))));
  193.     ratio = pbm_ticks*(double)1.0/cbm_ticks;
  194.     ratio2 = vbm_ticks*(double)1.0/cbm_ticks;
  195.  
  196.     x_set_font(1);
  197.     x_bgprintf(0,ScrnPhysicalHeight-30,0,14,0,
  198.       "s/100 PBM=%ld VBM=%ld CBM=%ld - %4.1lf:%4.1lf:1",
  199.       pbm_ticks,vbm_ticks,cbm_ticks,ratio,ratio2);
  200.     x_set_font(2);
  201.     x_bgprintf(0,ScrnPhysicalHeight-16,0,14,0,
  202.       "Timing is rough but still,  quite impressive ! ");
  203.     x_bgprintf(0,ScrnPhysicalHeight-8,0,14,0,
  204.       "Clipping slows things down considerably. ");
  205.  
  206.  
  207.     getch();
  208.     x_text_mode();
  209. }
  210.  
  211.