home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / diveex.zip / show.c < prev    next >
Text File  |  1994-03-30  |  5KB  |  120 lines

  1. #define INCL_32
  2. #define INCL_DOS
  3. #include <os2.h>
  4. #include <pmbitmap.h>
  5. #include <stdio.h>
  6. #include "direct.h"
  7.  
  8.  
  9.  
  10. main ( int argc, char *argv[] )
  11.    {
  12.    HFILE hFile;
  13.    ULONG ulNumBytes, ulFileLength;
  14.    PBYTE pbImageBottom, pbBMP;
  15.    ULONG rc;
  16.    PBITMAPFILEHEADER2 pbmfHeader;
  17.  
  18.    /* Check the number of command line arguments.                            */
  19.    if ( argc != 2 )
  20.       {
  21.       printf ( "usage: SHOW filein.bmp\n" );
  22.       printf ( "   Jams ab 8-bit bitmap image directly to the upper\n" );
  23.       printf ( "   left corner of the screen.  Clipping is not exemplified.\n" );
  24.       printf ( "   Note this code example works only if:\n" );
  25.       printf ( "      1) SMVDD.SYS is installed propery in four CONFIG.SYS\n" );
  26.       printf ( "         (You can get this from the MMPM/2 install disks), and\n" );
  27.       printf ( "      2) Your adapter has an aperture enabled, and\n" );
  28.       printf ( "      3) Your adapter is in 8, 16, or 24 bit bit color mode, and\n" );
  29.       printf ( "      4) Your bitmap is 8-bit only (i.e. this does no color conversion).\n" );
  30.       return ( 0 );
  31.       }
  32.  
  33.    /* Attempt to open up the passed filename.                                */
  34.    if ( DosOpen ( (PSZ)argv[1], &hFile, &ulNumBytes, 0L, FILE_NORMAL,
  35.                OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW,
  36.                OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE |
  37.                OPEN_FLAGS_SEQUENTIAL | OPEN_FLAGS_NO_CACHE, 0L ) )
  38.       {
  39.       printf ( "File \"%s\" not found.\n", argv[1] );
  40.       return ( 1 );
  41.       }
  42.  
  43.    /* Read in the entire bitmap into memory.                                 */
  44.    DosSetFilePtr ( hFile, 0L, FILE_END, &ulFileLength );
  45.    DosSetFilePtr ( hFile, 0L, FILE_BEGIN, &ulNumBytes );
  46.    if ( DosAllocMem ( (PPVOID) &pbBMP, ulFileLength,
  47.                    (ULONG) PAG_COMMIT | PAG_READ | PAG_WRITE) )
  48.       {
  49.       printf ( "Error while opening up some system RAM.\n" );
  50.       DosClose ( hFile );
  51.       return ( 1 );
  52.       }
  53.    DosRead ( hFile, pbBMP, ulFileLength, &ulNumBytes );
  54.    DosClose ( hFile );
  55.    pbmfHeader = (PBITMAPFILEHEADER2) pbBMP;
  56.    if ( ulNumBytes!=ulFileLength || pbmfHeader->usType!=BFT_BMAP )
  57.       {
  58.       printf ( "\"%s\" is not a type \"BM\" bitmap, it's \"%c%c\".\n",
  59.                      argv[1], pbmfHeader->usType, pbmfHeader->usType>>8 );
  60.       DosFreeMem ( pbBMP );
  61.       return ( 1 );
  62.       }
  63.  
  64.    /* Check a few things to see if we can proceed.                           */
  65.    if ( pbmfHeader->bmp2.cPlanes!=1 )
  66.       {
  67.       printf ( "Only single plane bitmaps are supported\n" );
  68.       DosFreeMem ( pbBMP );
  69.       return ( 1 );
  70.       }
  71.    if ( pbmfHeader->bmp2.cBitCount!=8 )
  72.       {
  73.       printf ( "Only 8 bit bitmaps are supported\n" );
  74.       DosFreeMem ( pbBMP );
  75.       return ( 1 );
  76.       }
  77.    if ( pbmfHeader->bmp2.ulCompression )
  78.       {
  79.       printf ( "Only uncompressed bitmaps are supported\n" );
  80.       DosFreeMem ( pbBMP );
  81.       return ( 1 );
  82.       }
  83.    if ( pbmfHeader->bmp2.cy>480 || pbmfHeader->bmp2.cx>640 )
  84.       {
  85.       printf ( "Bitmaps with dimensions larger than 640x480 are not supported\n" );
  86.       DosFreeMem ( pbBMP );
  87.       return ( 1 );
  88.       }
  89.  
  90.    /* Remember, images are stored up-side-down in bitmap form, but the       */
  91.    /* frame buffer needs it right-size-up -- we must invert on output!!!     */
  92.    pbImageBottom= pbBMP + pbmfHeader->offBits + ( ( pbmfHeader->bmp2.cx *
  93.         (pbmfHeader->bmp2.cy-1) * pbmfHeader->bmp2.cBitCount + 7 ) >> 3 );
  94.  
  95.    /* Try to get direct screen access.                                       */
  96.    if ( DirectScreenInit () )
  97.       {
  98.       printf ( "The display driver doesn't suport direct screen access.\n" );
  99.       DosFreeMem ( pbBMP );
  100.       return ( 1 );
  101.       }
  102.  
  103.    /* Print out information specific to your adapter.                        */
  104.    DirectPrintInfo();
  105.  
  106.    /* Display the bitmap.                                                    */
  107.    if ( rc = DirectScreenDisplay ( pbImageBottom, pbBMP + 14 + pbmfHeader->bmp2.cbFix,
  108.                      pbmfHeader->bmp2.cx, pbmfHeader->bmp2.cy ) )
  109.       printf ( "%2.2d: Aperture found okay, but unable to acquire frame buffer or blit.\n", rc );
  110.    else
  111.       printf ( "You should now see the bitmap on the screen.\n" );
  112.  
  113.    /* Close the video device driver.                                         */
  114.    DirectScreenTerm();
  115.  
  116.    /* Free up the image RAM.                                                 */
  117.    DosFreeMem ( pbBMP );
  118.    return ( 0 );
  119.    }
  120.