⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vmdib.cpp

📁 TOOL (Tiny Object Oriented Language) is an easily-embedded, object-oriented, C++-like-language inter
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    
      if ( lpbi->biClrUsed == 0L )
      {
        lpbi->biClrUsed = DibNumColors( lpbi );
      }
    }
    GlobalUnlock( hbi );
    return( TRUE );
  }
  return( FALSE );
}
/* End of function "DibInfo"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  ReadDibBitmapInfo

       DESCRIPTION:  

             INPUT:  fh - 
            OUTPUT:  none

           RETURNS:  HANDLE - 
*/
HANDLE WINAPI ReadDibBitmapInfo( int fh )
{
  DWORD     off;
  HANDLE    hbi = NULL;
  int       size;
  int       i;
  WORD      nNumColors;

  RGBQUAD FAR       *pRgb;
  BITMAPINFOHEADER   bi;
  BITMAPCOREHEADER   bc;
  LPBITMAPINFOHEADER lpbi;
  BITMAPFILEHEADER   bf;
  DWORD              dwWidth = 0;
  DWORD              dwHeight = 0;
  WORD               wPlanes, wBitCount;

  if ( fh == -1 )
  {
    return( NULL );
  }

  // Reset file pointer and read file header
  //
  off = _llseek( fh, 0L, SEEK_CUR );
  if ( sizeof( bf ) != _lread( fh, (LPSTR)&bf, sizeof( bf ) ) )
  {
    return( FALSE );
  }

  // Do we have a RC HEADER? 
  //
  if ( !ISDIB( bf.bfType ) ) 
  {
    bf.bfOffBits = 0L;
    _llseek( fh, off, SEEK_SET );
  }
  if ( sizeof( bi ) != _lread( fh, (LPSTR)&bi, sizeof( bi ) ) )
  {
    return( FALSE );
  }

  nNumColors = DibNumColors( &bi );

  // Check the nature (BITMAPINFO or BITMAPCORE) of the info. block
  // and extract the field information accordingly. If a BITMAPCOREHEADER,
  // transfer it's field information to a BITMAPINFOHEADER-style block
  //
  switch ( size = (int)bi.biSize )
  {
    case sizeof( BITMAPINFOHEADER ):
    {
    }
    break;

    case sizeof( BITMAPCOREHEADER ):
    {
      bc = *(BITMAPCOREHEADER*)&bi;

      dwWidth   = (DWORD)bc.bcWidth;
      dwHeight  = (DWORD)bc.bcHeight;
      wPlanes   = bc.bcPlanes;
      wBitCount = bc.bcBitCount;

      bi.biSize               = sizeof(BITMAPINFOHEADER);
      bi.biWidth              = dwWidth;
      bi.biHeight             = dwHeight;
      bi.biPlanes             = wPlanes;
      bi.biBitCount           = wBitCount;

      bi.biCompression        = BI_RGB;
      bi.biSizeImage          = 0;
      bi.biXPelsPerMeter      = 0;
      bi.biYPelsPerMeter      = 0;
      bi.biClrUsed            = nNumColors;
      bi.biClrImportant       = nNumColors;

      _llseek( fh, (LONG)sizeof( BITMAPCOREHEADER ) - sizeof( BITMAPINFOHEADER ), SEEK_CUR );
    }
    break;

    default:
    {
      // Not a DIB!
      //
      return( NULL );
    }
  }

  //  Fill in some default values if they are zero
  //
  if ( bi.biSizeImage == 0 )
  {
    bi.biSizeImage = WIDTHBYTES( (DWORD)bi.biWidth * bi.biBitCount ) * bi.biHeight;
  }
  if ( bi.biClrUsed == 0 )
  {
    bi.biClrUsed = DibNumColors( &bi );
  }

  // Allocate for the BITMAPINFO structure and the color table.
  //
  hbi = GlobalAlloc(GHND, (LONG)bi.biSize + nNumColors * sizeof( RGBQUAD ) );

  if ( !hbi )
  {
    return( NULL );
  }
  
  lpbi  = (LPBITMAPINFOHEADER)GlobalLock( hbi );
  *lpbi = bi;

  // Get a pointer to the color table
  //
  pRgb = (RGBQUAD FAR*)( (LPSTR)lpbi + bi.biSize );

  if ( nNumColors )
  {
    if ( size == sizeof( BITMAPCOREHEADER ) )
    {
      // Convert a old color table (3 byte RGBTRIPLEs) to a new
      // color table (4 byte RGBQUADs)
      //
      _lread( fh, (LPSTR)pRgb, nNumColors * sizeof( RGBTRIPLE ) );

      for ( i = nNumColors - 1; i >= 0; i-- )
      {
        RGBQUAD rgb;

        rgb.rgbRed      = ( (RGBTRIPLE FAR*)pRgb )[ i ].rgbtRed;
        rgb.rgbBlue     = ( (RGBTRIPLE FAR*)pRgb )[ i ].rgbtBlue;
        rgb.rgbGreen    = ( (RGBTRIPLE FAR*)pRgb )[ i ].rgbtGreen;
        rgb.rgbReserved = (BYTE)0;

        pRgb[ i ] = rgb;
      }
    }
    else
    {
      _lread( fh, (LPSTR)pRgb, nNumColors * sizeof( RGBQUAD ) );
    }
  }

  if ( bf.bfOffBits != 0L )
  {
    _llseek( fh, off + bf.bfOffBits, SEEK_SET );
  }
  GlobalUnlock( hbi );
  return( hbi );
}
/* End of function "ReadDibBitmapInfo"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  PaletteSize

       DESCRIPTION:  

             INPUT:  pv - 
            OUTPUT:  none

           RETURNS:  WORD - 
*/
WORD WINAPI PaletteSize( VOID FAR* pv )
{
  LPBITMAPINFOHEADER lpbi;
  WORD               NumColors;

  lpbi      = (LPBITMAPINFOHEADER)pv;
  NumColors = DibNumColors(lpbi);

  if ( lpbi->biSize == sizeof( BITMAPCOREHEADER ) )
  {
    return( NumColors * sizeof( RGBTRIPLE ) );
  }
  else
  {
    return( NumColors * sizeof( RGBQUAD ) );
  }
}
/* End of function "PaletteSize"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  DibNumColors

       DESCRIPTION:  

             INPUT:  pv - 
            OUTPUT:  none

           RETURNS:  WORD - 
*/
WORD WINAPI DibNumColors( VOID FAR* pv )
{
  int                 bits;
  LPBITMAPINFOHEADER  lpbi;
  LPBITMAPCOREHEADER  lpbc;

  lpbi = ( (LPBITMAPINFOHEADER) pv );
  lpbc = ( (LPBITMAPCOREHEADER) pv );

  // With the BITMAPINFO format headers, the size of the palette
  // is in biClrUsed, whereas in the BITMAPCORE - style headers, it
  // is dependent on the bits per pixel ( = 2 raised to the power of
  // bits/pixel).
  //
  if ( lpbi->biSize != sizeof( BITMAPCOREHEADER ) )
  {
    if ( lpbi->biClrUsed != 0 )
    {
      return( (WORD) lpbi->biClrUsed );
    }
    bits = lpbi->biBitCount;
  }
  else
  {
    bits = lpbc->bcBitCount;
  }

  switch ( bits )
  {
    case 1:
    {
      return( 2 ); 
    }
    break;

    case 4:
    {
      return( 16 );
    }
    break;

    case 8:
    {
      return( 256 );
    }
    break;

    default:
    {
      // A 24 bitcount DIB has no color table
      //
      return( 0 );
    }
    break;
  }
}
/* End of function "DibNumColors"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  StretchDibBlt

       DESCRIPTION:  

             INPUT:  hdc - 
                     x - 
                     y - 
                     dx - 
                     dy - 
                     hdib - 
                     x0 - 
                     y0 - 
                     dx0 - 
                     dy0 - 
                     rop - 
            OUTPUT:  

           RETURNS:  BOOL - 
*/
BOOL WINAPI StretchDibBlt( HDC hdc, int x, int y, int dx, int dy, HANDLE hdib, int x0, int y0, int dx0, int dy0, LONG rop )
{
  LPBITMAPINFOHEADER lpbi;
  LPSTR              pBuf;
  BOOL               f;

  lpbi = (LPBITMAPINFOHEADER)GlobalLock( hdib );

  if ( !lpbi )
  {
    return( FALSE );
  }

  pBuf = (LPSTR)lpbi + (WORD)lpbi->biSize + PaletteSize( lpbi );

  f = StretchDIBits ( hdc,
                      x, 
                      y,
                      dx, 
                      dy,
                      x0, 
                      y0,
                      dx0, 
                      dy0,
                      pBuf, 
                      (LPBITMAPINFO)lpbi,
                      DIB_RGB_COLORS,
                      rop );

  GlobalUnlock( hdib );
  return( f );
}
/* End of function "StretchDibBlt"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  lread

       DESCRIPTION:  

             INPUT:  fh - 
                     pv - 
                     ul - 
            OUTPUT:  

           RETURNS:  DWORD - 
*/
DWORD PASCAL lread( int fh, VOID far* pv, DWORD ul )
{
  DWORD  ulT = ul;
  BYTE*  hp = (unsigned char*)pv;

  while ( ul > (DWORD)MAXREAD ) 
  {
    if ( _lread( fh, (LPSTR)hp, (WORD)MAXREAD) != MAXREAD )
    {
      return( 0 );
    }
    ul -= MAXREAD;
    hp += MAXREAD;
  }
  if ( _lread( fh, (LPSTR)hp, (WORD)ul ) != (WORD)ul )
  {
    return( 0 );
  }
  return( ulT );
}
/* End of function "lread"
/*****************************************************************************/


/*****************************************************************************/
/* Check-in history */
/*
 *$Log:  $
*/
/*****************************************************************************/


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -