home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM User 1995 January / CDuser6Jan95.iso / WING / TBLT.C_ / TBLT.C
C/C++ Source or Header  |  1994-06-19  |  4KB  |  138 lines

  1. /*
  2.  *    TBLT.C
  3.  *
  4.  *    (C) Copyright Microsoft Corp. 1993.  All rights reserved.
  5.  *
  6.  *    You have a royalty-free right to use, modify, reproduce and 
  7.  *    distribute the Sample Files (and/or any modified version) in 
  8.  *    any way you find useful, provided that you agree that 
  9.  *    Microsoft has no warranty obligations or liability for any 
  10.  *    Sample Application Files which are modified. 
  11.  */
  12.  
  13. #include<windows.h>
  14. #include<windowsx.h>
  15. #include<wing.h>
  16.  
  17. #include"dib.h"
  18.  
  19. extern    void PASCAL far TransCopyDIBBits( WORD DestSelector, DWORD DestOffset,
  20.     void const far *pSource, DWORD Width, DWORD Height, long DestWidth,
  21.     long SourceWidth, char unsigned TransparentColor );
  22.  
  23.  
  24. /*----------------------------------------------------------------------------
  25.  
  26. This function ignores the source origin and blts the entire source.
  27.  
  28. */
  29.  
  30. BOOL TransparentDIBits( BITMAPINFO far *pBufferHeader,
  31.     void huge *pBufferBits,
  32.     int nXOriginDest, int nYOriginDest, void const far *pBits,
  33.     BITMAPINFO const far *pBitmapInfo, int nXOriginSrc, int nYOriginSrc,
  34.     int iUsage, char unsigned TransparentColor )
  35. {
  36.     BOOL ReturnValue = FALSE;
  37.  
  38.     int NewDestinationXOrigin;
  39.     int NewDestinationYOrigin;
  40.     int DestinationDeltaX;
  41.     int DestinationDeltaY;
  42.     int Width;
  43.     int Height;
  44.     int NewSourceXOrigin;
  45.     int NewSourceYOrigin;
  46.     int Orientation = 1;
  47.     int DestinationHeight = DibHeight(&pBufferHeader->bmiHeader);
  48.     int SourceWidth = DibWidth(&pBitmapInfo->bmiHeader);
  49.     int SourceHeight = DibHeight(&pBitmapInfo->bmiHeader);
  50.  
  51.     char unsigned huge *pSource;
  52.     WORD DestSelector;
  53.     DWORD DestOffset;
  54.  
  55.     RECT SourceRectangle = { nXOriginDest, nYOriginDest,
  56.         nXOriginDest + SourceWidth, nYOriginDest + SourceHeight };
  57.  
  58.     RECT DestinationRectangle;
  59.  
  60.     RECT ClippedRectangle;
  61.  
  62.     if(DestinationHeight < 0)        // check for top-down DIB
  63.     {
  64.         Orientation = -1;
  65.         DestinationHeight = -DestinationHeight;
  66.     }
  67.  
  68.     DestinationRectangle.top = 0;
  69.     DestinationRectangle.left = 0;
  70.     DestinationRectangle.bottom = DestinationHeight;
  71.     DestinationRectangle.right = DibWidth(&pBufferHeader->bmiHeader);
  72.  
  73.     // intersect the destination rectangle with the destination DIB
  74.  
  75.     if(IntersectRect(&ClippedRectangle,&SourceRectangle,
  76.         &DestinationRectangle))
  77.     {
  78.         // default delta scan to width in bytes
  79.         long DestinationScanDelta = DibWidthBytes(&pBufferHeader->bmiHeader);
  80.  
  81.  
  82.         NewDestinationXOrigin = ClippedRectangle.left;
  83.         NewDestinationYOrigin = ClippedRectangle.top;
  84.  
  85.         DestinationDeltaX = NewDestinationXOrigin - nXOriginDest;
  86.         DestinationDeltaY = NewDestinationYOrigin - nYOriginDest;
  87.  
  88.         Width = ClippedRectangle.right - ClippedRectangle.left;
  89.         Height = ClippedRectangle.bottom - ClippedRectangle.top;
  90.  
  91.         pSource = (char unsigned huge *)pBits;
  92.  
  93.         NewSourceXOrigin = DestinationDeltaX;
  94.         NewSourceYOrigin = DestinationDeltaY;
  95.  
  96.         pSource += ((long)SourceHeight - (NewSourceYOrigin + Height)) *
  97.             (long)DibWidthBytes(&pBitmapInfo->bmiHeader)
  98.             + NewSourceXOrigin;
  99.  
  100.         // now we'll calculate the starting destination pointer taking into
  101.         // account we may have a top-down destination
  102.  
  103.         DestSelector = HIWORD(pBufferBits);
  104.  
  105.         if(Orientation < 0)
  106.         {
  107.             // destination is top-down
  108.  
  109.             DestinationScanDelta *= -1;
  110.  
  111.             DestOffset = (long)(NewDestinationYOrigin + Height - 1) *
  112.                 (long)DibWidthBytes(&pBufferHeader->bmiHeader) +
  113.                 NewDestinationXOrigin;
  114.         }
  115.         else
  116.         {
  117.             // destination is bottom-up
  118.  
  119.             DestOffset = ((long)DestinationHeight -
  120.                 (NewDestinationYOrigin + Height))
  121.                 * (long)DibWidthBytes(&pBufferHeader->bmiHeader) +
  122.                 NewDestinationXOrigin;
  123.         }
  124.  
  125.         TransCopyDIBBits(DestSelector,DestOffset,pSource,Width,Height,
  126.             DestinationScanDelta,
  127.             DibWidthBytes(&pBitmapInfo->bmiHeader),
  128.             TransparentColor);
  129.  
  130.         ReturnValue = TRUE;
  131.     }
  132.  
  133.     return ReturnValue;
  134. }
  135.  
  136. #if 0
  137. #endif
  138.