home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / samples / mm / dive / show.c < prev    next >
C/C++ Source or Header  |  1999-05-11  |  50KB  |  1,344 lines

  1.  /**************************************************************************
  2.  *
  3.  * File Name        : SHOW.C
  4.  *
  5.  * Description      : This program provides the sample code of using DIVE APIs.
  6.  *
  7.  *                    Direct Interface Video Extension is developed for
  8.  *                    the entertainment, education, and games software
  9.  *                    to give the high-speed perforemance.
  10.  *
  11.  *
  12.  *
  13.  * Concepts         :
  14.  *
  15.  * Entry Points     : DirectMoveMem()
  16.  *                    ReadFile()
  17.  *                    Main()
  18.  *                    MyWindowProc()
  19.  *
  20.  * DIVE API's       :
  21.  *                    DiveSetSourcePalette
  22.  *                    DiveBlitImage
  23.  *                    DiveAllocImageBuffer
  24.  *                    DiveBeginImageBufferAccess
  25.  *                    DiveEndImageBufferAccess
  26.  *                    DiveOpen
  27.  *                    DiveSetDestinationPalette
  28.  *                    DiveFreeImageBuffer
  29.  *                    DiveClose
  30.  *                    DiveSetupBlitter
  31.  *
  32.  * Copyright        : COPYRIGHT IBM CORPORATION, 1991, 1992, 1993
  33.  *
  34.  *        DISCLAIMER OF WARRANTIES.  The following [enclosed] code is
  35.  *        sample code created by IBM Corporation. This sample code is not
  36.  *        part of any standard or IBM product and is provided to you solely
  37.  *        for  the purpose of assisting you in the development of your
  38.  *        applications.  The code is provided "AS IS", without
  39.  *        warranty of any kind.  IBM shall not be liable for any damages
  40.  *        arising out of your use of the sample code, even if they have been
  41.  *        advised of the possibility of such damages.
  42.  *
  43.  ****************************************************************************/
  44.  
  45. #define INCL_DOS
  46. #define INCL_GPI
  47. #define INCL_WIN
  48. #include <os2.h>
  49. #include <stdio.h>
  50. #include <stdlib.h>
  51. #include <string.h>
  52. #define  _MEERROR_H_
  53. #include <mmioos2.h>                   /* It is from MMPM toolkit           */
  54. #include <dive.h>
  55. #include <fourcc.h>
  56. #include "show.h"
  57.  
  58.  
  59. /* Function prototypes
  60. */
  61. MRESULT EXPENTRY MyWindowProc ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  62. MRESULT EXPENTRY MyDlgProc ( HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2 );
  63.  
  64. /* Global definitions
  65. */
  66. HAB       hab;                          /* PM anchor block handle            */
  67. ULONG     ulImage[MAX_FILE];            /* Image buffers from DIVE           */
  68. PVOID     pbImage[MAX_FILE];            /* Pointer to DIVE image buffer      */
  69. PVOID     pbSrcImage[MAX_FILE];         /* Pointer to Dos image buffer       */
  70. PBYTE     pPalette[MAX_FILE];           /* Pointer to bitmap palette area    */
  71. PSZ       pszMyWindow = "MyWindow";     /* Window class name                 */
  72. PSZ       pszTitleText = "DIVE SAMPLE"; /* Title bar text                    */
  73. ULONG     ulToEnd = 0;                  /* Controls the display thread       */
  74. DIVE_CAPS DiveCaps = {0};
  75. FOURCC    fccFormats[100] = {0};        /* Color format code                 */
  76. ULONG     ulFramesToTime=8;             /* Interval of frames to get time    */
  77. ULONG     ulNumFrames=0;                /* Frame counter                     */
  78.  
  79. /*  Default bitmap file name definitions
  80. **       These files are used only when EXE is called without parameter.
  81. */
  82. PSZ  pszDefFile[]   = { {"TPG20000.BMP"},
  83.                         {"TPG20001.BMP"},
  84.                         {"TPG20002.BMP"},
  85.                         {"TPG20003.BMP"},
  86.                         {"TPG20004.BMP"},
  87.                         {"TPG20005.BMP"},
  88.                         {"TPG20006.BMP"},
  89.                         {"TPG20007.BMP"},
  90.                         {"TPG20008.BMP"},
  91.                         {"TPG20009.BMP"},
  92.                         {"TPG20010.BMP"},
  93.                         {"TPG20011.BMP"},
  94.                         {"TPG20012.BMP"},
  95.                         {"TPG20013.BMP"},
  96.                         {"TPG20014.BMP"},
  97.                         {"TPG20015.BMP"} };
  98.  
  99. /*
  100. **  It is the definition how many time draw one bitmap continuously to
  101. **  look the picture better.
  102. */
  103. ULONG ulDrawCnt[] =   { 1,                       /* For TPG20000.BMP  */
  104.                         1,                       /* For TPG20001.BMP  */
  105.                         1,                       /* For TPG20002.BMP  */
  106.                         1,                       /* For TPG20003.BMP  */
  107.                         1,                       /* For TPG20004.BMP  */
  108.                         1,                       /* For TPG20005.BMP  */
  109.                         1,                       /* For TPG20006.BMP  */
  110.                         1,                       /* For TPG20007.BMP  */
  111.                         1,                       /* For TPG20008.BMP  */
  112.                         1,                       /* For TPG20009.BMP  */
  113.                         1,                       /* For TPG20010.BMP  */
  114.                         1,                       /* For TPG20011.BMP  */
  115.                         1,                       /* For TPG20012.BMP  */
  116.                         1,                       /* For TPG20013.BMP  */
  117.                         1,                       /* For TPG20014.BMP  */
  118.                         1 };                     /* For TPG20015.BMP  */
  119.  
  120. /****************************************************************************
  121.  *
  122.  * Name          : DirectMoveMem
  123.  *
  124.  * Description   : It is calling DIVE bitblt function periodically.
  125.  *                 And also it calculates how many frames per a second
  126.  *                 is able to be blit to the screen.
  127.  *
  128.  * Concepts      :
  129.  *
  130.  * Parameters    : Pointer to window data
  131.  *
  132.  * Return        : VOID
  133.  *
  134.  ****************************************************************************/
  135.  
  136. VOID APIENTRY DirectMoveMem ( ULONG parm1 )
  137.    {
  138.    ULONG    ulTime0, ulTime1;     /* output buffer for DosQierySysInfo      */
  139.    ULONG    ulIndexImage = 0;     /* Index of bitmap data                   */
  140.    CHAR     achFrameRate[48];     /* string buffer for WinSetWindowText     */
  141.    ULONG    ulFirstTime=0;        /* very first time flag for DiveSetSour.. */
  142.  
  143.    PWINDATA pwinData;             /* pointer to window data                 */
  144.    ULONG    ulCount = 0;          /* Counter for each bitmap                */
  145.    PBYTE    pDestAddress;         /* destination VRAM adrress               */
  146.    PBYTE    pSrcAddress;          /* source btimap data address             */
  147.  
  148.    BOOL     fFirstLineInRect;     /* Indicates start of drawing sequence    */
  149.    RECTL    rcl;                  /* Current rectangle to draw              */
  150.    ULONG    ulMoreLine;           /* Number of lines left to draw           */
  151.    ULONG    ulRemLinesInBank;     /* Number of lines left in bank           */
  152.    ULONG    ulBankNumber;         /* Bank number returned from DIVE         */
  153.    ULONG    ulCopyLengthBytes;    /* Length of scan line for current window */
  154.    ULONG    i;
  155.  
  156.    pwinData =(PWINDATA)parm1;
  157.  
  158.    while ( !ulToEnd )
  159.       {
  160.  
  161.       /* Check if it's time to start the blit-time counter.
  162.       */
  163.       if ( !ulNumFrames++ )
  164.          DosQuerySysInfo ( QSV_MS_COUNT, QSV_MS_COUNT, &ulTime0, 4L );
  165.  
  166.       /* Check if need to change the source palette.
  167.       **
  168.       ** In this sample case, this API should be called only once at
  169.       ** very first.  After this, it will not be called, because there is
  170.       ** assumption that all bitmap data have the sample palette.
  171.       */
  172.       if (( pwinData->fChgSrcPalette ) || (( !ulFirstTime ) &&
  173.             ( pwinData->ulnumColor  == 256 )) )
  174.          {
  175.          DiveSetSourcePalette ( pwinData->hDive, 0,
  176.                                   pwinData->ulnumColor,
  177.                                   pPalette[ulIndexImage] );
  178.          ulFirstTime = 0xFFFF;
  179.          }
  180.  
  181.       /* Check to see if images are in process of being converted
  182.       ** If not, then continue updating display
  183.       */
  184.       if ( ! pwinData->fDataInProcess )
  185.          {
  186.          /* Check if direct or blit mode
  187.          */
  188.          if (pwinData->fDirect)
  189.             {
  190.             /* Write image to frame buffer directly
  191.             */
  192.             if (!pwinData->fVrnDisabled)
  193.                {
  194.                /* Copy bitmap data for each rectangle
  195.                */
  196.                for (i = 0; i < pwinData->ulNumRcls; i++)
  197.                   {
  198.                   pSrcAddress = (PBYTE)pbImage[ulIndexImage];
  199.                   memcpy (&rcl, &pwinData->rcls[i], sizeof(RECTL) );
  200.  
  201.                   /* Size of scan line bounded by this rectangle
  202.                   */
  203.                   ulCopyLengthBytes = ( rcl.xRight - rcl.xLeft ) *
  204.                                       pwinData->ulColorSizeBytes;
  205.  
  206.                   /* Number of lines contained in this rectangle
  207.                   */
  208.                   ulMoreLine = rcl.yTop - rcl.yBottom;
  209.  
  210.                   /* Start position in source bitmap
  211.                   */
  212.                   pSrcAddress += ( pwinData->swp.cy - rcl.yTop )
  213.                                   * pwinData->ulLineSizeBytes +
  214.                                  ( rcl.xLeft * pwinData->ulColorSizeBytes );
  215.  
  216.                   /* Map rectangle to desktop coordinates
  217.                   */
  218.                   rcl.yTop    += pwinData->cyWindowPos;
  219.                   rcl.yBottom += pwinData->cyWindowPos;
  220.                   rcl.xRight  += pwinData->cxWindowPos;
  221.                   rcl.xLeft   += pwinData->cxWindowPos;
  222.  
  223.                  /* NOTICE !!! */
  224.                  /**** TEMPORARY ADJUSTMENT  start ****************************
  225.                   * If this adjustment is not here, DiveCalcFrameBufferAddress
  226.                   * returns 1 dot higher position.
  227.                   * Need to contact the devloper.
  228.                   *************************************************************/
  229.                   rcl.yTop --;
  230.                   rcl.yBottom --;
  231.                  /* end temporary adjustment */
  232.  
  233.                   fFirstLineInRect = TRUE;
  234.  
  235.                   while ( ulMoreLine )
  236.                      {
  237.                      if ( fFirstLineInRect )
  238.                         {
  239.                         /* Get VRAM start location
  240.                         */
  241.                         DiveCalcFrameBufferAddress ( pwinData->hDive,
  242.                                                        &rcl,
  243.                                                        &pDestAddress,
  244.                                                        &ulBankNumber,
  245.                                                        &ulRemLinesInBank );
  246.  
  247.                         if ( DiveAcquireFrameBuffer ( pwinData->hDive,
  248.                                                         &rcl ))
  249.                            break;
  250.  
  251.                         DiveSwitchBank ( pwinData->hDive, ulBankNumber );
  252.                         fFirstLineInRect = FALSE;
  253.                         }
  254.                      /* Copy one Line to display
  255.                      */
  256.                      memcpy ( pDestAddress, pSrcAddress, ulCopyLengthBytes );
  257.  
  258.                      /* Update source address
  259.                      */
  260.                      pSrcAddress += pwinData->ulLineSizeBytes;
  261.  
  262.                      ulMoreLine--;
  263.                      ulRemLinesInBank--;
  264.                      rcl.yTop--;
  265.  
  266.                      /* Check if time to switch banks.
  267.                      */
  268.                      if ( !ulRemLinesInBank )
  269.                         {
  270.                         DiveCalcFrameBufferAddress ( pwinData->hDive,
  271.                                                        &rcl,
  272.                                                        &pDestAddress,
  273.                                                        &ulBankNumber,
  274.                                                        &ulRemLinesInBank );
  275.  
  276.                         DiveSwitchBank ( pwinData->hDive, ulBankNumber );
  277.                         }
  278.                      else
  279.                         {
  280.                         /* update destination address.
  281.                         */
  282.                         pDestAddress += DiveCaps.ulScanLineBytes;
  283.                         }
  284.  
  285.                      } /* end while: go to next scan line */
  286.  
  287.                   DiveDeacquireFrameBuffer ( pwinData->hDive );
  288.                   } /* end for: go to next rectangle */
  289.                }/* end if */
  290.             }
  291.          else
  292.             {
  293.             /* Blit the image using DiveBlit
  294.             */
  295.             DiveBlitImage ( pwinData->hDive,
  296.                             ulImage[ulIndexImage],
  297.                             DIVE_BUFFER_SCREEN );
  298.          } /* endif */
  299.  
  300.          /* Updated the index for the bitmap data to be drawn next.
  301.          */
  302.          ulCount ++;
  303.          if ( ulCount >=  ulDrawCnt[ulIndexImage] )
  304.             {
  305.             ulIndexImage ++;
  306.             ulCount = 0;
  307.             }
  308.          if ( ulIndexImage >= pwinData->ulMaxFiles )
  309.             ulIndexImage = 0;
  310.  
  311.          /* Check to see if we have enough frames for a fairly accurate read.
  312.          */
  313.          if ( ulNumFrames>=ulFramesToTime )
  314.             {
  315.             DosQuerySysInfo ( QSV_MS_COUNT, QSV_MS_COUNT, &ulTime1, 4L );
  316.             ulTime1 -= ulTime0;
  317.             if ( ulTime1 )
  318.                sprintf ( achFrameRate, "%d: %d: %5.2f frames per second.",
  319.                            pwinData->hDive, ulFramesToTime,
  320.                            (float)ulFramesToTime * 1000.0 / (float)ulTime1 );
  321.             else
  322.                sprintf ( achFrameRate, "%d: %d: Lots of frames per second.",
  323.                            pwinData->hDive, ulFramesToTime );
  324.             WinPostMsg ( pwinData->hwndFrame, WM_COMMAND,
  325.                            (PVOID)ID_NEWTEXT, achFrameRate );
  326.             ulNumFrames = 0;
  327.  
  328.             /* Adjust number of frames to time based on last set.
  329.             */
  330.             if ( ulTime1 < 250 )
  331.                ulFramesToTime <<= 1;
  332.             if ( ulTime1 > 3000 )
  333.                ulFramesToTime >>= 1;
  334.             }
  335.  
  336.          /* Let other threads and processes have some time.
  337.          */
  338.          }
  339.       DosSleep ( 0 );
  340.       }
  341.  
  342.    return;
  343.    }
  344.  
  345. /****************************************************************************
  346.  *
  347.  * Name          : ReadFile
  348.  *
  349.  * Description   : It opens the file, and reads bitmap header and bitmap
  350.  *                 palette, and reads image data to the buffer allocated
  351.  *                 by DIVE APIs.
  352.  *
  353.  * Concepts      :
  354.  *
  355.  * Parameters    : Index for the file to open
  356.  *                 Pointer to the file name to open
  357.  *                 Pointer to window data
  358.  *
  359.  * Return        : 0 - succeed
  360.  *                 1 - fail
  361.  *
  362.  ****************************************************************************/
  363.  
  364.  
  365. unsigned long ReadFile ( ULONG iFile, unsigned char *pszFile,
  366.                                                        PWINDATA pwinData )
  367.    {
  368.    HFILE hFile;                 /* file handke                              */
  369.    ULONG ulNumBytes;            /* output for number of bytes actually read */
  370.    ULONG ulFileLength;          /* file length                              */
  371.    PBYTE pbBuffer;              /* pointer to the image/ temp. palette data */
  372.    ULONG ulScanLineBytes;       /* output for number of bytes a scan line   */
  373.    ULONG ulScanLines;           /* output for height of the buffer          */
  374.    PBITMAPFILEHEADER2 pImgHdr;  /* pointer to bitmapheader                  */
  375.    ULONG i, j;
  376.    PBYTE pbTmpDst;              /* temporaly destination pointer            */
  377.  
  378.    /* Attempt to open up the passed filename.
  379.    */
  380.    if ( DosOpen ( pszFile, &hFile, &ulNumBytes, 0L, FILE_NORMAL,
  381.                     OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW,
  382.                     OPEN_ACCESS_READONLY | OPEN_SHARE_DENYREADWRITE |
  383.                     OPEN_FLAGS_SEQUENTIAL | OPEN_FLAGS_NO_CACHE, 0L ) )
  384.       return ( 1 );
  385.  
  386.    /* Get the legnth of the file.
  387.    */
  388.    DosSetFilePtr ( hFile, 0L, FILE_END, &ulFileLength );
  389.    DosSetFilePtr ( hFile, 0L, FILE_BEGIN, &ulNumBytes );
  390.  
  391.    /* Allocate memory for bitmap file header
  392.    */
  393.    if ( DosAllocMem ( (PPVOID)&pImgHdr, sizeof(BITMAPFILEHEADER2),
  394.                         (ULONG) PAG_COMMIT | PAG_READ | PAG_WRITE) )
  395.       {
  396.       DosClose ( hFile );
  397.       return ( 1 );
  398.       }
  399.  
  400.    /* Read from the beginning of the header to cbFix in BITMAPINFOHEADER
  401.    ** to know the length of the header.
  402.    */
  403.    if ( DosRead ( hFile, pImgHdr,
  404.                     sizeof(BITMAPFILEHEADER2) - sizeof(BITMAPINFOHEADER2) +
  405.                     sizeof(ULONG),
  406.                     &ulNumBytes ))
  407.       {
  408.       DosFreeMem ( (PVOID)pImgHdr );
  409.       DosClose ( hFile );
  410.       return ( 1 );
  411.       }
  412.  
  413.    /* Read the rest of the header.
  414.    */
  415.    if ( DosRead ( hFile, (PBYTE)pImgHdr + ulNumBytes,
  416.                     pImgHdr->bmp2.cbFix - sizeof(ULONG),
  417.                     &ulNumBytes ))
  418.       {
  419.       DosFreeMem ( (PVOID)pImgHdr );
  420.       DosClose ( hFile );
  421.       return ( 1 );
  422.       }
  423.  
  424.     pwinData->ulnumColor = 1;
  425.  
  426.    /* Check the bitmap header format --  new or old one.
  427.    */
  428.    if ( pImgHdr->bmp2.cbFix != sizeof(BITMAPINFOHEADER) )
  429.       {
  430.       /*  Bitmap has new format (BITMAPFILEHEADER2)
  431.       */
  432.  
  433.       /* Check bitmap header to see if it can support.
  434.       */
  435.  
  436.       /* Set how many color bitmap data is supporting
  437.       */
  438.       pwinData->ulnumColor <<= pImgHdr->bmp2.cBitCount;
  439.  
  440.       /* Set bitmap width and height in pels.
  441.       */
  442.       pwinData->ulWidth  = pImgHdr->bmp2.cx;
  443.       pwinData->ulHeight = pImgHdr->bmp2.cy;
  444.  
  445.       /* Calculate source line size.  It should be double word boundary.
  446.       */
  447.       pwinData->ulSrcLineSizeBytes = ((( pImgHdr->bmp2.cx *
  448.                               ( pImgHdr->bmp2.cBitCount >> 3 )) + 3 ) / 4 ) * 4;
  449.  
  450.       /* Set bitmap coclor format.
  451.       */
  452.       switch ( pImgHdr->bmp2.cBitCount )
  453.          {
  454.          case 8:
  455.             pwinData->fccColorFormat = FOURCC_LUT8;
  456.             /* Alloate buffer for palette data in bitmap file.
  457.             */
  458.             if ( DosAllocMem ( (PPVOID) &(pPalette[iFile]),
  459.                                  pwinData->ulnumColor * sizeof(ULONG),
  460.                                  (ULONG) PAG_COMMIT | PAG_READ | PAG_WRITE) )
  461.                {
  462.                DosFreeMem ( (PVOID)pImgHdr );
  463.                DosClose ( hFile );
  464.                return ( 1 );
  465.                }
  466.  
  467.             /* Read palette data.
  468.             */
  469.             if ( DosRead ( hFile, pPalette[iFile],
  470.                              pwinData->ulnumColor * sizeof(ULONG),
  471.                              &ulNumBytes ))
  472.                {
  473.                DosFreeMem ( (PVOID)pImgHdr );
  474.                DosFreeMem ( (PVOID)(pPalette[iFile]) );
  475.                DosClose ( hFile );
  476.                return ( 1 );
  477.                }
  478.             break;
  479.          case 16:
  480.             pwinData->fccColorFormat = FOURCC_R565;
  481.             break;
  482.          case 24:
  483.             pwinData->fccColorFormat = FOURCC_BGR3;
  484.             break;
  485.          default:
  486.             DosFreeMem ( (PVOID)pImgHdr );
  487.             DosClose ( hFile );
  488.             return ( 1 );
  489.          } /* endswitch */
  490.  
  491.       }
  492.    else
  493.       {
  494.       /*  Bitmap has old format (BITMAPFILEHEADER)
  495.       */
  496.  
  497.        /* Set how many color bitmap data is supporting
  498.       */
  499.       pwinData->ulnumColor <<= ((PBITMAPFILEHEADER)pImgHdr)->bmp.cBitCount;
  500.  
  501.       /* Set bitmap width and height in pels.
  502.       */
  503.       pwinData->ulWidth  = ((PBITMAPFILEHEADER)pImgHdr)->bmp.cx;
  504.       pwinData->ulHeight = ((PBITMAPFILEHEADER)pImgHdr)->bmp.cy;
  505.  
  506.       /* Calculate source line size.  It should be double word boundary.
  507.       */
  508.       pwinData->ulSrcLineSizeBytes = ((( ((PBITMAPFILEHEADER)pImgHdr)->bmp.cx *
  509.            ( ((PBITMAPFILEHEADER)pImgHdr)->bmp.cBitCount >> 3 )) + 3 ) / 4 ) * 4;
  510.  
  511.       /* Set bitmap coclor format.
  512.       */
  513.       switch ( ((PBITMAPFILEHEADER)pImgHdr)->bmp.cBitCount )
  514.          {
  515.          case 8:
  516.             pwinData->fccColorFormat = FOURCC_LUT8;
  517.             /* Alloate buffer for temporally palette data in bitmap file
  518.             */
  519.             if ( DosAllocMem ( (PPVOID) &pbBuffer,
  520.                                  pwinData->ulnumColor * sizeof(RGB),
  521.                                  (ULONG) PAG_COMMIT | PAG_READ | PAG_WRITE) )
  522.                {
  523.                DosFreeMem ( (PVOID)pImgHdr );
  524.                DosClose ( hFile );
  525.                return ( 1 );
  526.                }
  527.             if ( DosAllocMem ( (PPVOID) &(pPalette[iFile]),
  528.                                  pwinData->ulnumColor * sizeof(ULONG),
  529.                                  (ULONG) PAG_COMMIT | PAG_READ | PAG_WRITE) )
  530.                {
  531.                DosFreeMem ( (PVOID)pImgHdr );
  532.                DosFreeMem( (PVOID)pbBuffer );
  533.                DosClose ( hFile );
  534.                return ( 1 );
  535.                }
  536.  
  537.             /* Read palette data
  538.             */
  539.             if ( DosRead ( hFile, pbBuffer,
  540.                              pwinData->ulnumColor * sizeof(RGB),
  541.                              &ulNumBytes ))
  542.                {
  543.                DosFreeMem ( (PVOID)pImgHdr );
  544.                DosFreeMem( (PVOID)pbBuffer );
  545.                DosFreeMem( (PVOID)pPalette[iFile] );
  546.                DosClose ( hFile );
  547.                return ( 1 );
  548.                }
  549.  
  550.             /* Make each color from 3 bytes to 4 bytes.
  551.             */
  552.             pbTmpDst = pPalette[iFile];
  553.             for ( i = 0; i < pwinData->ulnumColor; i++ )
  554.                {
  555.                *pbTmpDst ++= *pbBuffer++;
  556.                *pbTmpDst ++= *pbBuffer++;
  557.                *pbTmpDst ++= *pbBuffer++;
  558.                *pbTmpDst ++= 0;
  559.                } /* endfor */
  560.  
  561.             DosFreeMem( (PVOID)pbBuffer );
  562.             break;
  563.          case 16:
  564.             pwinData->fccColorFormat = FOURCC_R565;
  565.             break;
  566.          case 24:
  567.             pwinData->fccColorFormat = FOURCC_BGR3;
  568.             break;
  569.          default:
  570.             {
  571.             DosFreeMem ( (PVOID)pImgHdr );
  572.             DosClose ( hFile );
  573.             return ( 1 );
  574.             }
  575.          } /* endswitch */
  576.  
  577.  
  578.       }
  579.  
  580.  
  581.    /* Allocate a buffer for image data
  582.    */
  583.  
  584.    if ( DosAllocMem ( (PPVOID)&pbSrcImage[iFile], pwinData->ulSrcLineSizeBytes *
  585.                       pwinData->ulHeight, (ULONG) PAG_COMMIT | PAG_READ |
  586.                       PAG_WRITE) )
  587.       {
  588.       if ( pwinData->fccColorFormat == FOURCC_LUT8 )
  589.          DosFreeMem( (PVOID)pPalette[iFile] );
  590.       DosClose ( hFile );
  591.       return( 1 );
  592.       }
  593.  
  594.    /* Read image data
  595.    */
  596.    if ( DosRead ( hFile, pbSrcImage[iFile],
  597.                     pwinData->ulSrcLineSizeBytes * pwinData->ulHeight,
  598.                     &ulNumBytes ))
  599.       {
  600.       DosFreeMem ( pbSrcImage[iFile] );
  601.       if ( pwinData->fccColorFormat == FOURCC_LUT8 )
  602.          DosFreeMem( (PVOID)pPalette[iFile] );
  603.       DosClose ( hFile );
  604.       return( 1 );
  605.       }
  606.  
  607.    /* Close the file and release the access to the image buffer
  608.    */
  609.    DosFreeMem( (PVOID)pImgHdr );
  610.    DosClose ( hFile );
  611.    return ( 0 );
  612.    }
  613.  
  614.  
  615.  
  616. /****************************************************************************
  617.  *
  618.  * Name          : Main
  619.  *
  620.  * Description   : This is main routine of this sample program.
  621.  *
  622.  * Concepts      :
  623.  *
  624.  * Parameters    : At command prompt, when the user start this EXE without
  625.  *                 any parameters, like
  626.  *                    SHOW
  627.  *                 it shows 16 default bitmaps which has a sequence.
  628.  *                 When the user specifies the names of bitmap file, like
  629.  *                    SHOW XXXXXX.BMP YYYYYY.BMP
  630.  *                 it shows the bitmaps specified at command line in turn.
  631.  *
  632.  * Return        : 1 - fail
  633.  *                 0 - suceed
  634.  *
  635.  ****************************************************************************/
  636.  
  637. main ( int argc, char *argv[] )
  638.    {
  639.    TID       tidBlitThread;        /* Thread ID for DirectMemMove          */
  640.    HMQ       hmq;                  /* Message queue handle                 */
  641.    QMSG      qmsg;                 /* Message from message queue           */
  642.    ULONG     flCreate;             /* Window creation control flags        */
  643.    ULONG     i;                    /* Index for the files to open          */
  644.    PWINDATA  pwinData;             /* Pointer to window data               */
  645.    PLONG     pPal;                 /* Pointer to system physical palette   */
  646.  
  647.  
  648.    /* Initialize the presentation manager, and create a message queue.
  649.    */
  650.    hab = WinInitialize ( 0 );
  651.    hmq = WinCreateMsgQueue ( hab, 0 );
  652.  
  653.    /* Allocate a buffer for the window data
  654.    */
  655.    pwinData = (PWINDATA) malloc (sizeof(WINDATA));
  656.  
  657.    /* Get the screen capabilities, and if the system support only 16 colors
  658.    ** the sample should be terminated.
  659.    */
  660.    DiveCaps.pFormatData = fccFormats;
  661.    DiveCaps.ulFormatLength = 120;
  662.    DiveCaps.ulStructLen = sizeof(DIVE_CAPS);
  663.  
  664.    if ( DiveQueryCaps ( &DiveCaps, DIVE_BUFFER_SCREEN ))
  665.       {
  666.       WinMessageBox( HWND_DESKTOP, HWND_DESKTOP,
  667.           (PSZ)"usage: The sample program can not run on this system environment.",
  668.           (PSZ)"SHOW.EXE - DIVE Sample", 0, MB_OK | MB_INFORMATION );
  669.       free ( pwinData );
  670.       WinDestroyMsgQueue ( hmq );
  671.       WinTerminate ( hab );
  672.       return ( 1 );
  673.       }
  674.  
  675.    if ( DiveCaps.ulDepth < 8 )
  676.       {
  677.       WinMessageBox( HWND_DESKTOP, HWND_DESKTOP,
  678.           (PSZ)"usage: The sample program can not run on this system environment.",
  679.           (PSZ)"SHOW.EXE - DIVE Sample", 0, MB_OK | MB_INFORMATION );
  680.       free ( pwinData );
  681.       WinDestroyMsgQueue ( hmq );
  682.       WinTerminate ( hab );
  683.       return ( 1 );
  684.       }
  685.  
  686.    /* Calculate number of bytes per pell
  687.    */
  688.    pwinData->ulColorSizeBytes = DiveCaps.ulScanLineBytes/
  689.                                 DiveCaps.ulHorizontalResolution;
  690.  
  691.    /* Get an instance of DIVE APIs.
  692.    */
  693.    if ( DiveOpen ( &(pwinData->hDive), FALSE, 0 ) )
  694.       {
  695.  
  696.       WinMessageBox( HWND_DESKTOP, HWND_DESKTOP,
  697.                        (PSZ)"usage: The sample program can not run on this system environment.",
  698.                        (PSZ)"SHOW.EXE - DIVE Sample", 0, MB_OK | MB_INFORMATION );
  699.       free ( pwinData );
  700.       WinDestroyMsgQueue ( hmq );
  701.       WinTerminate ( hab );
  702.       return ( 1 );
  703.       }
  704.  
  705.  
  706.    /* Read bitmap files
  707.    */
  708.    if ( argc == 1 )                               /* Default case           */
  709.       {                                           /* Read DROI00XX.BMP file */
  710.       for ( i = 0, pwinData->ulMaxFiles = 0; i < MAX_FILE; i ++ )
  711.          {
  712.          if ( ReadFile ( i, pszDefFile[i], pwinData ))
  713.             {
  714.             WinMessageBox( HWND_DESKTOP, HWND_DESKTOP,
  715.                              (PSZ)"usage: SHOW failed to open bitmaps.",
  716.                              (PSZ)"Error!", 0, MB_OK | MB_MOVEABLE );
  717.             free ( pwinData );
  718.             WinDestroyMsgQueue ( hmq );
  719.             WinTerminate ( hab );
  720.             return ( 1 );
  721.             }
  722.          else
  723.             pwinData->ulMaxFiles ++;
  724.          }
  725.       }
  726.    else                 /* The case which the user specify bitmap file names */
  727.       {
  728.       if (( argc > 1 ) && ( argc <= MAX_FILE + 1))
  729.          {
  730.          for ( i = 1; i < (ULONG)(argc); i++ )
  731.              {
  732.              if ( ReadFile ( i-1, (unsigned char *)argv[i], pwinData ))
  733.                 {
  734.                 WinMessageBox( HWND_DESKTOP, HWND_DESKTOP,
  735.                                  (PSZ)"usage: SHOW failed to open bitmaps.",
  736.                                  (PSZ)"Error!", 0, MB_OK | MB_MOVEABLE );
  737.                 free ( pwinData );
  738.                 WinDestroyMsgQueue ( hmq );
  739.                 WinTerminate ( hab );
  740.                 return ( 1 );
  741.                 }
  742.              }
  743.           pwinData->ulMaxFiles = argc-1;
  744.          }
  745.       else
  746.          {
  747.          WinMessageBox( HWND_DESKTOP, HWND_DESKTOP,
  748.             (PSZ)"usage: SHOW failed to open bitmaps.",
  749.             (PSZ)"Error!", 0, MB_OK | MB_MOVEABLE );
  750.          free ( pwinData );
  751.          WinDestroyMsgQueue ( hmq );
  752.          WinTerminate ( hab );
  753.          return ( 1 );
  754.          }
  755.       }
  756.  
  757.    /* Register a window class, and create a standard window.
  758.    */
  759.    WinRegisterClass ( hab, pszMyWindow, MyWindowProc, 0, sizeof(ULONG) );
  760.    flCreate = FCF_TASKLIST | FCF_SYSMENU  | FCF_TITLEBAR | FCF_ICON |
  761.                   FCF_SIZEBORDER | FCF_MINMAX | FCF_MENU | FCF_SHELLPOSITION;
  762.    pwinData->hwndFrame = WinCreateStdWindow ( HWND_DESKTOP,
  763.                                               WS_VISIBLE, &flCreate,
  764.                                               pszMyWindow,
  765.                                               pszTitleText,
  766.                                               WS_SYNCPAINT | WS_VISIBLE,
  767.                                               0, ID_MAINWND,
  768.                                               &(pwinData->hwndClient));
  769.  
  770.    WinSetWindowULong (pwinData->hwndClient, 0, (ULONG)pwinData);
  771.  
  772.  
  773.    pwinData->cxWidthBorder = (LONG) WinQuerySysValue(HWND_DESKTOP, SV_CXSIZEBORDER);
  774.    pwinData->cyWidthBorder = (LONG) WinQuerySysValue(HWND_DESKTOP, SV_CYSIZEBORDER);
  775.    pwinData->cyTitleBar    = (LONG) WinQuerySysValue(HWND_DESKTOP, SV_CYTITLEBAR);
  776.    pwinData->cyMenu        = (LONG) WinQuerySysValue(HWND_DESKTOP, SV_CYMENU);
  777.  
  778.    pwinData->cxWidthWindow  = pwinData->ulWidth + pwinData->cxWidthBorder * 2;
  779.    pwinData->cyHeightWindow = pwinData->ulHeight + (pwinData->cyWidthBorder * 2 +
  780.                                        pwinData->cyTitleBar + pwinData->cyMenu );
  781.  
  782.    pwinData->cxWindowPos   = ( (LONG)WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN)
  783.                        - pwinData->cxWidthWindow ) / 2;
  784.    pwinData->cyWindowPos   = ( (LONG)WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN)
  785.                        - pwinData->cyHeightWindow ) / 2;
  786.  
  787.  
  788.    /* Set the window position and size.
  789.    */
  790.    WinSetWindowPos (pwinData->hwndFrame,
  791.                       HWND_TOP,
  792.                       pwinData->cxWindowPos, pwinData->cyWindowPos,
  793.                       pwinData->cxWidthWindow, pwinData->cyHeightWindow,
  794.                       SWP_SIZE | SWP_MOVE | SWP_SHOW | SWP_ACTIVATE);
  795.  
  796.  
  797.    /* Turn on visible region notification.
  798.    */
  799.    WinSetVisibleRegionNotify ( pwinData->hwndClient, TRUE );
  800.  
  801.    /* set the flag for the first time simulation of palette of bitmap data
  802.    */
  803.    pwinData->fChgSrcPalette = FALSE;
  804.    pwinData->fStartBlit = FALSE;
  805.    pwinData->fDataInProcess = FALSE;
  806.    pwinData->fDirect = FALSE;
  807.  
  808.    /* Send an invlaidation message to the client.
  809.    */
  810.    WinPostMsg ( pwinData->hwndFrame, WM_VRNENABLED, 0L, 0L );
  811.  
  812.    /* Start up the blitting thread.
  813.    */
  814.    if ( DosCreateThread ( &(pwinData->tidBlitThread),
  815.                             (PFNTHREAD) DirectMoveMem,
  816.                             (ULONG)pwinData, 0L, 8192L))
  817.       {
  818.       WinSetVisibleRegionNotify ( pwinData->hwndClient, FALSE );
  819.  
  820.       for ( i = 0; i < pwinData->ulMaxFiles; i++ )
  821.           DiveFreeImageBuffer ( pwinData->hDive, ulImage[i] );
  822.  
  823.       DiveClose ( pwinData->hDive );
  824.       WinDestroyWindow ( pwinData->hwndFrame );
  825.       free ( pwinData);
  826.       WinDestroyMsgQueue ( hmq );
  827.       WinTerminate ( hab );
  828.       return ( 1 );
  829.       }
  830.  
  831.    /* Set the proiroty of the blitting thread
  832.    */
  833.    DosSetPriority ( PRTYS_THREAD, PRTYC_IDLETIME,
  834.                       1, pwinData->tidBlitThread );
  835.  
  836.    /* While there are still messages, dispatch them.
  837.    */
  838.    while ( WinGetMsg ( hab, &qmsg, 0, 0, 0 ) )
  839.       WinDispatchMsg ( hab, &qmsg );
  840.  
  841.    /* Set the variable to end the running thread, and wait for it to end.
  842.    */
  843.    ulToEnd = 1;
  844.    DosWaitThread ( &(pwinData->tidBlitThread), DCWW_WAIT );
  845.  
  846.    /* Turn off visible region notificationm tidy up, and terminate.
  847.    */
  848.    WinSetVisibleRegionNotify ( pwinData->hwndClient, FALSE );
  849.  
  850.    /* Free the buffers allocated by DIVE and close DIVE
  851.    */
  852.    for  ( i = 0; i < pwinData->ulMaxFiles; i++ )
  853.        DiveFreeImageBuffer ( pwinData->hDive, ulImage[i] );
  854.    DiveClose ( pwinData->hDive );
  855.  
  856.    if ( pwinData->fccColorFormat == FOURCC_LUT8 )
  857.       {
  858.       for  ( i = 0; i < pwinData->ulMaxFiles; i++ )
  859.           DosFreeMem ( pPalette[i] );
  860.       }
  861.  
  862.    /* Process for termination
  863.    */
  864.    WinDestroyWindow ( pwinData->hwndFrame );
  865.    free ( pwinData );
  866.    WinDestroyMsgQueue ( hmq );
  867.    WinTerminate ( hab );
  868.    return ( 0 );
  869.    }
  870.  
  871. /****************************************************************************
  872.  *
  873.  * Name          : MyWindowProc
  874.  *
  875.  * Description   : It is the window procedure of this program.
  876.  *
  877.  * Concepts      :
  878.  *
  879.  * Parameters    : Message parameter 1
  880.  *                 Message parameter 2
  881.  *
  882.  * Return        : calling WinDefWindowProc
  883.  *
  884.  ****************************************************************************/
  885.  
  886. MRESULT EXPENTRY MyWindowProc ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
  887.    {
  888.    POINTL    pointl;                /* Point to offset from Desktop         */
  889.    HRGN      hrgn;                  /* Region handle                        */
  890.    HPS       hps;                   /* Presentation Space handle            */
  891.    RECTL     rcl;                   /* Current widow rectangle              */
  892.    ULONG     ulTmpImage;            /* For tmp image number                 */
  893.    RGNRECT   rgnCtl;                /* Processing control structure         */
  894.    PWINDATA  pwinData;              /* Pointer to window data               */
  895.    SETUP_BLITTER SetupBlitter;      /* structure for DiveSetupBlitter       */
  896.    ULONG     ulScanLineBytes;       /* Size of scan line for current window */
  897.    ULONG     ulScanLines;           /* Number of scan lines in window       */
  898.    ULONG     ulRemainder;           /* Used to check direct mode support    */
  899.    ULONG     i, rc;
  900.  
  901.    /* Get the pointer to window data
  902.    */
  903.    pwinData = (PWINDATA)WinQueryWindowULong (hwnd, 0);
  904.    if ( pwinData )
  905.       {
  906.       switch( msg )
  907.          {
  908.          case WM_COMMAND:
  909.             switch ( SHORT1FROMMP ( mp1 ) )
  910.                {
  911.                case ID_SNAP:
  912.                   {
  913.                   /* Use the initial width and height of the window such that
  914.                   ** the actual video area equals the source width and height.
  915.                   */
  916.  
  917.                   /* Set the new size of the window, but don't move it.
  918.                   */
  919.                   WinSetWindowPos ( pwinData->hwndFrame, HWND_TOP,
  920.                                       100, 100,
  921.                                       pwinData->cxWidthWindow,
  922.                                       pwinData->cyHeightWindow,
  923.                                       SWP_SIZE | SWP_ACTIVATE | SWP_SHOW );
  924.                   }
  925.                   break;
  926.  
  927.                case ID_QUERY:
  928.  
  929.                   /* Display screen capablilities in the dialog box
  930.                   */
  931.                   WinDlgBox ( HWND_DESKTOP, pwinData->hwndClient,
  932.                                MyDlgProc, (HMODULE)0,
  933.                                ID_DIALOG, (PVOID)pwinData );
  934.  
  935.                   break;
  936.  
  937.                case ID_EXIT:
  938.                   /* Post to quit the dispatch message loop.
  939.                   */
  940.                   WinPostMsg ( hwnd, WM_QUIT, 0L, 0L );
  941.                   break;
  942.  
  943.                case ID_NEWTEXT:
  944.                   /* Write new text string to the title bar
  945.                   */
  946.                   WinSetWindowText ( pwinData->hwndFrame, (PSZ)mp2 );
  947.                   break;
  948.  
  949.                case ID_DIRECT:
  950.                   /* Check to make sure that this system can support
  951.                    * direct mode.
  952.                    *
  953.                    * Note: if the screen aperture size is not an even
  954.                    *       multiple of the scan line size, then the
  955.                    *       system will have bank breaks within the
  956.                    *       scan line. This would make the direct mode
  957.                    *       blit alorithm too complicated for this
  958.                    *       sample. Therefore, if this condition exists
  959.                    *       the sample will not go into direct mode
  960.                    */
  961.  
  962.                   ulRemainder = DiveCaps.ulApertureSize %
  963.                                 DiveCaps.ulScanLineBytes;
  964.  
  965.                   if( !DiveCaps.fScreenDirect ||
  966.                       ( DiveCaps.fBankSwitched && ulRemainder ) )
  967.                   {
  968.                      WinMessageBox( HWND_DESKTOP, HWND_DESKTOP,
  969.                      (PSZ)"usage: Direct mode not supported in this environment.",
  970.                      (PSZ)"Error!", 0, MB_OK | MB_MOVEABLE );
  971.  
  972.                      break;
  973.                   }
  974.  
  975.                   pwinData->fDataInProcess = TRUE;
  976.  
  977.                   /* Set flag for direct frame buffer access
  978.                   */
  979.                   pwinData->fDirect = TRUE;
  980.  
  981.                   /* Post invalidation message.
  982.                   */
  983.                   WinPostMsg ( hwnd, WM_VRNENABLED, 0L, 0L );
  984.                   break;
  985.  
  986.                case ID_USEDIVE:
  987.                   pwinData->fDataInProcess = TRUE;
  988.  
  989.                   /* Set flag for dive blit mode
  990.                   */
  991.                   pwinData->fDirect = FALSE;
  992.  
  993.                   /* Post invalidation message.
  994.                   */
  995.                   WinPostMsg ( hwnd, WM_VRNENABLED, 0L, 0L );
  996.                   break;
  997.  
  998.                default:
  999.                   /* Let PM handle this message.
  1000.                   */
  1001.                   return WinDefWindowProc ( hwnd, msg, mp1, mp2 );
  1002.                }
  1003.             break;
  1004.  
  1005.          case WM_VRNDISABLED:
  1006.  
  1007.             pwinData->fDataInProcess = TRUE;
  1008.             DiveSetupBlitter ( pwinData->hDive, 0 );
  1009.             pwinData->fVrnDisabled = TRUE;
  1010.             break;
  1011.  
  1012.          case WM_VRNENABLED:
  1013.             pwinData->fDataInProcess = TRUE;
  1014.             hps = WinGetPS ( hwnd );
  1015.             if ( !hps )
  1016.                break;
  1017.             hrgn = GpiCreateRegion ( hps, 0L, NULL );
  1018.             if ( hrgn )
  1019.                {
  1020.                /* NOTE: If mp1 is zero, then this was just a move message.
  1021.                ** Illustrate the visible region on a WM_VRNENABLE.
  1022.                */
  1023.                WinQueryVisibleRegion ( hwnd, hrgn );
  1024.                rgnCtl.ircStart     = 0;
  1025.                rgnCtl.crc          = 50;
  1026.                rgnCtl.ulDirection  = 1;
  1027.  
  1028.                /* Get the all ORed rectangles
  1029.                */
  1030.                if ( GpiQueryRegionRects ( hps, hrgn, NULL,
  1031.                                           &rgnCtl, pwinData->rcls) )
  1032.                   {
  1033.                   pwinData->ulNumRcls = rgnCtl.crcReturned;
  1034.  
  1035.                   /* Now find the window position and size, relative to parent.
  1036.                   */
  1037.                   WinQueryWindowPos ( pwinData->hwndClient, &pwinData->swp );
  1038.  
  1039.                   rcl.xLeft   = 0;
  1040.                   rcl.yBottom = 0;
  1041.  
  1042.                   /* Convert the point to offset from desktop lower left.
  1043.                   */
  1044.                   pointl.x = pwinData->swp.x;
  1045.                   pointl.y = pwinData->swp.y;
  1046.  
  1047.                   WinMapWindowPoints ( pwinData->hwndFrame,
  1048.                                        HWND_DESKTOP, &pointl, 1 );
  1049.  
  1050.                   pwinData->cxWindowPos = pointl.x;
  1051.                   pwinData->cyWindowPos = pointl.y;
  1052.  
  1053.  
  1054.                   /* If the sample is in direct mode check to make sure
  1055.                   ** that the window is not too large. For direct mode the
  1056.                   ** window size is limited to 640x480. This is done to
  1057.                   ** avoide excesive swapping.
  1058.                   */
  1059.  
  1060.                   if ( pwinData->fDirect )
  1061.                      {
  1062.                      if ( pwinData->swp.cx > 640 )
  1063.                         {
  1064.                         WinSetWindowPos ( pwinData->hwndFrame, 0, 0, 0,
  1065.                                           640, pwinData->swp.cy, SWP_SIZE );
  1066.                         return ( FALSE );
  1067.                         }
  1068.  
  1069.                      if ( pwinData->swp.cy > 480 )
  1070.                         {
  1071.                         WinSetWindowPos ( pwinData->hwndFrame, 0, 0, 0,
  1072.                                           pwinData->swp.cx, 480, SWP_SIZE );
  1073.                         return ( FALSE );
  1074.                         }
  1075.                      }
  1076.  
  1077.  
  1078.  
  1079.                   /* Calculate size of scan line bounded by visible window
  1080.                   ** and round up to 4 pell increments.
  1081.                   */
  1082.                   i = pwinData->swp.cx * pwinData->ulColorSizeBytes;
  1083.                   pwinData->ulLineSizeBytes = i/4*4;
  1084.                   if (i - pwinData->ulLineSizeBytes)
  1085.                      pwinData->ulLineSizeBytes += 4;
  1086.  
  1087.                   }
  1088.                else
  1089.                   {
  1090.                   DiveSetupBlitter ( pwinData->hDive, 0 );
  1091.                   GpiDestroyRegion ( hps, hrgn );
  1092.                   break;
  1093.                   }
  1094.  
  1095.                GpiDestroyRegion( hps, hrgn );
  1096.                }
  1097.             WinReleasePS( hps );
  1098.  
  1099.  
  1100.             /* Tell DIVE about the new settings.
  1101.             */
  1102.             SetupBlitter.ulStructLen = sizeof ( SETUP_BLITTER );
  1103.             SetupBlitter.fccSrcColorFormat = pwinData->fccColorFormat;
  1104.             SetupBlitter.ulSrcWidth = pwinData->ulWidth;
  1105.             SetupBlitter.ulSrcHeight = pwinData->ulHeight;
  1106.             SetupBlitter.ulSrcPosX = 0;
  1107.             SetupBlitter.ulSrcPosY = 0;
  1108.             SetupBlitter.ulDitherType = 1;
  1109.             SetupBlitter.fInvert = TRUE;
  1110.  
  1111.             SetupBlitter.lDstPosX = 0;
  1112.             SetupBlitter.lDstPosY = 0;
  1113.             SetupBlitter.fccDstColorFormat = FOURCC_SCRN;
  1114.             SetupBlitter.lScreenPosX = 0;
  1115.             SetupBlitter.lScreenPosY = 0;
  1116.             SetupBlitter.ulNumDstRects = 1;
  1117.  
  1118.             /* If direct mode then stretch blit to video buffers
  1119.             */
  1120.             if ( pwinData->fDirect )
  1121.                {
  1122.                rcl.xRight  = pwinData->swp.cx;
  1123.                rcl.yTop    = pwinData->swp.cy;
  1124.                SetupBlitter.ulDstWidth = pwinData->swp.cx;
  1125.                SetupBlitter.ulDstHeight = pwinData->swp.cy;
  1126.                SetupBlitter.pVisDstRects = &rcl;
  1127.                }
  1128.             /* If blit mode then blit to video buffers without stretching
  1129.             */
  1130.             else
  1131.                {
  1132.                rcl.xRight = pwinData->ulWidth;
  1133.                rcl.yTop   = pwinData->ulHeight;
  1134.                SetupBlitter.ulDstWidth = pwinData->ulWidth;
  1135.                SetupBlitter.ulDstHeight = pwinData->ulHeight;
  1136.                SetupBlitter.pVisDstRects = &rcl;
  1137.                }
  1138.  
  1139.             DiveSetupBlitter ( pwinData->hDive, &SetupBlitter );
  1140.  
  1141.             for (i = 0; i < pwinData->ulMaxFiles ; i++ )
  1142.                {
  1143.                DiveFreeImageBuffer ( pwinData->hDive, ulImage[i] );
  1144.  
  1145.  
  1146.                /* Register source image buffer with DIVE
  1147.                */
  1148.                ulTmpImage = 0;
  1149.                if ( DiveAllocImageBuffer (pwinData->hDive,
  1150.                                           &ulTmpImage,
  1151.                                           pwinData->fccColorFormat,
  1152.                                           pwinData->ulWidth,
  1153.                                           pwinData->ulHeight,
  1154.                                           pwinData->ulSrcLineSizeBytes,
  1155.                                           (PBYTE)pbSrcImage[i] ) )
  1156.                   break;
  1157.  
  1158.                /* Allocate DIVE image buffer
  1159.                */
  1160.                if ( DiveAllocImageBuffer (pwinData->hDive,
  1161.                                           &(ulImage[i]),
  1162.                                           FOURCC_SCRN,
  1163.                                           rcl.xRight,
  1164.                                           rcl.yTop,
  1165.                                           0, 0) )
  1166.                   break;
  1167.  
  1168.                if ( DiveBeginImageBufferAccess ( pwinData->hDive,
  1169.                                                  ulImage[i],
  1170.                                                  (PPBYTE)&pbImage[i],
  1171.                                                  &ulScanLineBytes,
  1172.                                                  &ulScanLines ))
  1173.                   {
  1174.                   DiveFreeImageBuffer ( pwinData->hDive, ulTmpImage );
  1175.                   DiveFreeImageBuffer ( pwinData->hDive, ulImage[i] );
  1176.                   break;
  1177.                   }
  1178.  
  1179.                /* Blit source image to DIVE buffer
  1180.                */
  1181.                DiveBlitImage ( pwinData->hDive, ulTmpImage, ulImage[i] );
  1182.  
  1183.                DiveEndImageBufferAccess ( pwinData->hDive, ulImage[i] );
  1184.                DiveFreeImageBuffer ( pwinData->hDive, ulTmpImage );
  1185.                }
  1186.  
  1187.             /* Now setup blitter to blit to the screen
  1188.             ** Note: This code has no affect when in direct mode
  1189.             */
  1190.             SetupBlitter.fccSrcColorFormat = FOURCC_SCRN;
  1191.             SetupBlitter.lScreenPosX = pointl.x;
  1192.             SetupBlitter.lScreenPosY = pointl.y;
  1193.             SetupBlitter.fInvert = FALSE;
  1194.             SetupBlitter.ulDstWidth = pwinData->swp.cx;
  1195.             SetupBlitter.ulDstHeight = pwinData->swp.cy;
  1196.             SetupBlitter.ulNumDstRects = pwinData->ulNumRcls;
  1197.             SetupBlitter.pVisDstRects = pwinData->rcls;
  1198.  
  1199.             DiveSetupBlitter ( pwinData->hDive, &SetupBlitter );
  1200.  
  1201.             ulFramesToTime=4;
  1202.             ulNumFrames=1;
  1203.             pwinData->fDataInProcess = FALSE;
  1204.             pwinData->fVrnDisabled = FALSE;
  1205.  
  1206.             break;
  1207.  
  1208.  
  1209.          case WM_REALIZEPALETTE:
  1210.             /* This tells DIVE that the physical palette may have changed.
  1211.             */
  1212.             DiveSetDestinationPalette ( pwinData->hDive, 0, 0, 0 );
  1213.  
  1214.             break;
  1215.  
  1216.          case WM_CLOSE:
  1217.             /* Post to quit the dispatch message loop.
  1218.             */
  1219.             WinPostMsg ( hwnd, WM_QUIT, 0L, 0L );
  1220.             break;
  1221.  
  1222.          default:
  1223.             /* Let PM handle this message.
  1224.             */
  1225.             return WinDefWindowProc ( hwnd, msg, mp1, mp2 );
  1226.          }
  1227.       }
  1228.    else
  1229.       /* Let PM handle this message.
  1230.       */
  1231.       return WinDefWindowProc ( hwnd, msg, mp1, mp2 );
  1232.  
  1233.    return ( FALSE );
  1234.    }
  1235.  
  1236. /****************************************************************************
  1237.  *
  1238.  * Name          : MyDlgProc
  1239.  *
  1240.  * Description   : It is the dialog procedure of this program.
  1241.  *
  1242.  * Concepts      :
  1243.  *
  1244.  * Parameters    : Message parameter 1
  1245.  *                 Message parameter 2
  1246.  *
  1247.  * Return        : calling WinDefDlgProc
  1248.  *
  1249.  ****************************************************************************/
  1250.  
  1251. MRESULT EXPENTRY MyDlgProc ( HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2 )
  1252.    {
  1253.    CHAR      string[10];
  1254.    CHAR      *pString;
  1255.  
  1256.    switch( msg )
  1257.       {
  1258.       case WM_INITDLG:
  1259.  
  1260.          WinSetFocus ( HWND_DESKTOP, hwndDlg );
  1261.  
  1262.          if ( !DiveCaps.fScreenDirect )
  1263.             WinSetDlgItemText ( hwndDlg, ID_EF_11, "NO" );
  1264.          else
  1265.             WinSetDlgItemText ( hwndDlg, ID_EF_11, "YES" );
  1266.  
  1267.          if ( !DiveCaps.fBankSwitched )
  1268.             WinSetDlgItemText ( hwndDlg, ID_EF_12, "NO" );
  1269.          else
  1270.             WinSetDlgItemText ( hwndDlg, ID_EF_12, "YES" );
  1271.  
  1272.          pString = _ultoa ( DiveCaps.ulDepth, string, 10 );
  1273.          WinSetDlgItemText ( hwndDlg, ID_EF_13, pString );
  1274.  
  1275.          pString = _ultoa ( DiveCaps.ulHorizontalResolution,
  1276.                              string, 10 );
  1277.          WinSetDlgItemText ( hwndDlg, ID_EF_14, pString );
  1278.  
  1279.          pString = _ultoa ( DiveCaps.ulVerticalResolution, string, 10 );
  1280.          WinSetDlgItemText ( hwndDlg, ID_EF_15, pString );
  1281.  
  1282.          pString = _ultoa ( DiveCaps.ulScanLineBytes, string, 10 );
  1283.          WinSetDlgItemText ( hwndDlg, ID_EF_16, pString );
  1284.  
  1285.          switch (DiveCaps.fccColorEncoding)
  1286.             {
  1287.             case FOURCC_LUT8:
  1288.                WinSetDlgItemText ( hwndDlg, ID_EF_17, "256" );
  1289.                break;
  1290.             case FOURCC_R565:
  1291.                WinSetDlgItemText ( hwndDlg, ID_EF_17, "64K" );
  1292.                break;
  1293.             case FOURCC_R555:
  1294.                WinSetDlgItemText ( hwndDlg, ID_EF_17, "32K" );
  1295.                break;
  1296.             case FOURCC_R664:
  1297.                WinSetDlgItemText ( hwndDlg, ID_EF_17, "64K" );
  1298.                break;
  1299.             case FOURCC_RGB3:
  1300.                WinSetDlgItemText ( hwndDlg, ID_EF_17, "16M" );
  1301.                break;
  1302.             case FOURCC_BGR3:
  1303.                WinSetDlgItemText ( hwndDlg, ID_EF_17, "16M" );
  1304.                break;
  1305.             case FOURCC_RGB4:
  1306.                WinSetDlgItemText ( hwndDlg, ID_EF_17, "16M" );
  1307.                break;
  1308.             case FOURCC_BGR4:
  1309.                WinSetDlgItemText ( hwndDlg, ID_EF_17, "16M" );
  1310.                break;
  1311.             default:
  1312.                WinSetDlgItemText ( hwndDlg, ID_EF_17, "???" );
  1313.             } /* endswitch */
  1314.  
  1315.          pString = _ultoa ( DiveCaps.ulApertureSize, string, 10 );
  1316.          WinSetDlgItemText ( hwndDlg, ID_EF_18, pString );
  1317.  
  1318.          pString = _ultoa ( DiveCaps.ulInputFormats, string, 10 );
  1319.          WinSetDlgItemText ( hwndDlg, ID_EF_19, pString );
  1320.  
  1321.          pString = _ultoa ( DiveCaps.ulOutputFormats, string, 10 );
  1322.          WinSetDlgItemText ( hwndDlg, ID_EF_20, pString );
  1323.  
  1324.          break;
  1325.  
  1326.       case WM_COMMAND:
  1327.          switch ( SHORT1FROMMP ( mp1 ) )
  1328.             {
  1329.             case DID_OK:
  1330.  
  1331.                WinDismissDlg ( hwndDlg, TRUE );
  1332.                break;
  1333.             }
  1334.  
  1335.       default:
  1336.          return ( WinDefDlgProc (hwndDlg, msg, mp1, mp2) );
  1337.  
  1338.       }
  1339.  
  1340.    return( 0 );
  1341.  
  1342.    }
  1343.  
  1344.