home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / screen / stest / cvideo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-22  |  2.0 KB  |  91 lines

  1. #include "CVIDEO.H"
  2.  
  3. int Scaler(int a,int b,int c);
  4. void CBuildScaleTable(int size,int tsize);
  5.  
  6. // This table contains the translated x/y co-ordinates at this scaling size.
  7. static unsigned int ScaleTable[320];
  8.  
  9. // C version of the assembly language putblit routine.
  10. // The algorithm is IDENTICAL to the assembly implementation.
  11. void far CPutBlit(char far *blit,int xloc,int yloc)
  12. {
  13.     int far *temp;
  14.     int width,height,i,j;
  15.     char far *dest,far *base;
  16.  
  17.     temp = (int far *) blit;
  18.     width = *temp++;
  19.     height = *temp++;
  20.     blit+=4;
  21.  
  22.     dest = 0xA0000000+yloc*320+xloc;
  23.  
  24.     for (i=0; i<height; i++)
  25.     {
  26.         base = dest;
  27.         for (j=0; j<width; j++) *base++ = *blit++;
  28.         dest+=320;
  29.     }
  30. }
  31.  
  32. int  far CPutBlitSize(char far *blit,int xloc,int yloc,int size)
  33. {
  34.     int far *temp;
  35.     int width,height,i,j;
  36.     int owidth,oheight,tsize;
  37.     char far *dest,far *base;
  38.     char far *blitbase;
  39.  
  40.     if ( size > FULLSIZE || size <= 0 ) return(0); // Unable to display blit.
  41.     if ( size == FULLSIZE )
  42.         CPutBlit(blit,xloc,yloc);
  43.     else
  44.     {
  45.         temp = (int far *) blit;
  46.         width = *temp++;
  47.         height = *temp++;
  48.         blit+=4;
  49.  
  50.         dest = 0xA0000000+(unsigned int)(yloc*320)+(unsigned int)xloc;
  51.  
  52.         owidth    = Scaler(width,size,FULLSIZE);    // Find the output width.
  53.         oheight = Scaler(height,size,FULLSIZE);    // Find the output width.
  54.         if ( owidth > oheight )
  55.             tsize = owidth;
  56.         else
  57.             tsize = oheight;
  58.         CBuildScaleTable(size,tsize);
  59.         for (i=0; i<oheight; i++)
  60.         {
  61.             base = dest;
  62.             blitbase = blit+ScaleTable[i]*width;
  63.             for (j=0; j<owidth; j++) *base++ = *(blitbase+ScaleTable[j]);
  64.             dest+=320;
  65.         }
  66.  
  67.     }
  68.   return(1);
  69. }
  70.  
  71. // Build scaling table of size passed for a total width of the table
  72. // size passed.
  73. void CBuildScaleTable(int size,int tsize)
  74. {
  75.     long int accum;
  76.     int i;
  77.  
  78.     size = 65536L/size;
  79.     accum = 0;
  80.     for (i=0; i<tsize; i++)
  81.     {
  82.         ScaleTable[i] = accum>>8;  // Shift out fraction.
  83.         accum+=size;
  84.     }
  85. }
  86.  
  87. int Scaler(int a,int b,int c)
  88. {
  89.     return( (int) ( (long) a * (long) b / (long) c ) ) ;
  90. }
  91.