static HBITMAP CreateBitmap (HPS hpsMem, PRECTL prclTargetWnd)
{
    LONG        lFormats[24];              // bitmap data formats
    BITMAPINFOHEADER2 bmp;                       // bitmap info header
    HBITMAP         hbm;

    GpiQueryDeviceBitmapFormats( hpsMem, 24L, lFormats );
    memset( &bmp, 0, sizeof bmp);
    bmp.cbFix      = sizeof bmp;          // size of the header
    bmp.cx         = prclTargetWnd->xRight;
    bmp.cy         = prclTargetWnd->yTop;
    bmp.cPlanes    = (USHORT)lFormats[0];  // planes
    bmp.cBitCount  = (USHORT)lFormats[1];  // bit count

    hbm = GpiCreateBitmap(hpsMem,&bmp,0,NULL,NULL);
    assert (hbm != GPI_ERROR);

    GpiSetBitmap(hpsMem,hbm);

    return hbm;
}
Пример #2
0
int open_Vbuff(RECTL rclRect)
{
    static int LbmpBuffOld = 0;
    int LbmpBuff;
    PSZ pszData[4] = { "Display", NULL, NULL, NULL };
    SIZEL sizlPage = {0, 0};
    LONG alData[2];
//   RGB2 rgb, *prgb;
    int Numcolors,ii,s;
    extern ULONG ColorTable[256];

    ZbNx = rclRect.xRight - rclRect.xLeft   + 1;
    ZbNy = rclRect.yTop   - rclRect.yBottom + 1;
    //ZbNx = 640;
    //ZbNy = 480;
    //ZbNx = ((ZbNx-1)/32+1)*32;
    //ZbNy = ((ZbNy-1)/32+1)*32;
    if (ZbNx > 960)  ZbNx = 960;
    if (ZbNy > 1280) ZbNy = 1280;

    /* пеpесчет y_ZbNx */
    for(ii=0,s=0;ii<=ZbNy;ii++,s+= ZbNx) y_ZbNx[ii] = s;

    if(pBmpBuffer == NULL)
    {
      printf("Критическая ошибка: нет памяти");
      DosSleep(4000);
      exit(1);
    }

/* Create the memory device context and presentation space so they
 * are compatible with the screen device context and presentation space.
 */

     printf("pBmpBuffer=%lx\n", pBmpBuffer);

     if(hbm)
     {
        bmp.cx = ZbNx;
        bmp.cy = ZbNy;
        pbmi->cx = bmp.cx;
        pbmi->cy = bmp.cy;
        pbmi->cbImage = bmp.cbImage;
        return 0;
     }
          /* PSZ pszData[4] = { "Display", NULL, NULL, NULL }; */
      /* SIZEL sizlPage = {0, 0}; */

      /* Determine the device's plane/bit-count format. */
      GpiQueryDeviceBitmapFormats(hpsDesktop, 2, alData);

      bmp.cbFix = (ULONG) sizeof(BITMAPINFOHEADER2);
      bmp.cx = 16;
      bmp.cy = 16;
      bmp.cPlanes = alData[0];
      bmp.cBitCount = alData[1];

      if (bmp.cBitCount < 8)
      {   bmp.cPlanes = 1;
          bmp.cBitCount = 8;
      }
      bmp.cPlanes = 1;
      bmp.cBitCount = 8;

//!!
bmp.cBitCount = 24;

      bmp.ulCompression = BCA_UNCOMP;
      bmp.cbImage = 0;
      bmp.cxResolution = 70;
      bmp.cyResolution = 70;
      Numcolors = 230;
      //bmp.cclrUsed = Numcolors;
      //bmp.cclrImportant = Numcolors-30;
//!!
bmp.cclrUsed = 0;
bmp.cclrImportant = 0;

      bmp.usUnits = BRU_METRIC;
      bmp.usReserved = 0;
      bmp.usRecording = BRA_BOTTOMUP;
      bmp.usRendering = BRH_NOTHALFTONED;//BRH_ERRORDIFFUSION;
      bmp.cSize1 = 0;
      bmp.cSize2 = 0;
      bmp.ulColorEncoding = BCE_RGB;
      bmp.ulIdentifier = 1;

      ii = (sizeof(RGB2) * (1 << bmp.cPlanes) * (1 << bmp.cBitCount));
      if(bmp.cBitCount  > 8)
                           ii = 16;
      ii += sizeof(BITMAPINFO2);
      pbmi = (BITMAPINFO2 *) malloc(ii);

      pbmi->cbFix = bmp.cbFix;
      pbmi->cx = bmp.cx;
      pbmi->cy = bmp.cy;
      pbmi->cPlanes = bmp.cPlanes;
      pbmi->cBitCount = bmp.cBitCount;
      pbmi->ulCompression = BCA_UNCOMP;
      pbmi->cbImage = 1;
      pbmi->cxResolution = 70;
      pbmi->cyResolution = 70;

      pbmi->cclrUsed = Numcolors;
      pbmi->cclrImportant = Numcolors-20;
//!!
pbmi->cclrUsed = 0;
pbmi->cclrImportant = 0;
      pbmi->usUnits = BRU_METRIC;
      pbmi->usReserved = 0;
      pbmi->usRecording = BRA_BOTTOMUP;
      pbmi->usRendering = BRH_NOTHALFTONED;
//  pbmi->usRendering = BRH_ERRORDIFFUSION;
//  pbmi->usRendering = BRH_PANDA;
//  pbmi->usRendering = BRH_SUPERCIRCLE;
      pbmi->cSize1 = 0;
      pbmi->cSize2 = 0;
      pbmi->ulColorEncoding = BCE_RGB;
      pbmi->ulIdentifier = 1;

    bmp.cbImage = 0;//((ZbNx+31)/32) * ZbNy;
    bmp.cx = ZbNx;
    bmp.cy = ZbNy;
    pbmi->cx = bmp.cx;
    pbmi->cy = bmp.cy;
    pbmi->cbImage = bmp.cbImage;

//      prgb = (RGB2 *) (((PBYTE)pbmi)+bmp.cbFix);

   return 0;
}
Пример #3
0
// *******************************************************************************
// FUNCTION:     GetBitmapFromTrack
//
// FUNCTION USE: Creates a bitmap from a rectangle structure
//
// DESCRIPTION:  This function takes the rectangle structure that is created 
//               as a result of the tracking operation and creates a bitmap 
//               of that area.  
//
// PARAMETERS:   RECTL    tracking rectangle
//
// RETURNS:      HBITMAP  bitmap handle
//
// INTERNALS:    NONE
//
// HISTORY:
//
// *******************************************************************************
HBITMAP GetBitmapFromTrack (RECTL rclTrack)
{
 HAB                hab;                           
 HBITMAP            hbmTrack;
 HDC                hdcMemory;
 HPS                hpsMemory;
 HPS                hpsScreen;
 LONG               lFormats[2];
 POINTL             aptl[3];
 SIZEL              sizl;
 BITMAPINFOHEADER2  bmp2;

 // --------------------------------------------------------------------------                    
 // Get an anchor block handle                                                                    
 // --------------------------------------------------------------------------                    
 hab = WinQueryAnchorBlock(HWND_DESKTOP);

 // --------------------------------------------------------------------------                    
 // Get a memory device context                                                                  
 // --------------------------------------------------------------------------                    
 hdcMemory = DevOpenDC (hab, OD_MEMORY, "*", 0L, NULL, NULLHANDLE) ;

 // --------------------------------------------------------------------------                    
 // Set presentation space size                                                                
 // --------------------------------------------------------------------------                    
 sizl.cx = sizl.cy = 0 ;

 // --------------------------------------------------------------------------                             
 // Create a micro presentation space and associate it                                                                           
 // --------------------------------------------------------------------------                             
 hpsMemory = GpiCreatePS (hab,
                          hdcMemory,
                          &sizl,
                          PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC);

 // --------------------------------------------------------------------------           
 // Call GpiQueryDeviceBitmapFormats to get the number of bit planes                                   
 // --------------------------------------------------------------------------           
 GpiQueryDeviceBitmapFormats (hpsMemory,
                              2L,
                              lFormats);

 // --------------------------------------------------------------------------        
 // Initialize the bitmap info header structure                 
 // --------------------------------------------------------------------------        
 memset(&bmp2, 0, sizeof(BITMAPINFOHEADER2));

 // --------------------------------------------------------------------------                     
 // Populate the bitmap info header structure                                                    
 // --------------------------------------------------------------------------                     
 bmp2.cbFix     = sizeof bmp2;
 bmp2.cx        = (rclTrack.xRight - rclTrack.xLeft);
 bmp2.cy        = (rclTrack.yTop   - rclTrack.yBottom);
 bmp2.cPlanes   = lFormats[0];
 bmp2.cBitCount = lFormats[1];

 // --------------------------------------------------------------------------         
 // Create a bitmap representing the tracking rectangle                                
 // --------------------------------------------------------------------------         
 hbmTrack = GpiCreateBitmap (hpsMemory, &bmp2, 0L, NULL, NULL);

 if (hbmTrack == GPI_ERROR)
  {
   return GPI_ERROR;
  }

 else
  {
   // --------------------------------------------------------------------------        
   // Set the bitmap into our memory presentation space.                                                                      
   // --------------------------------------------------------------------------        
   GpiSetBitmap (hpsMemory, hbmTrack);
   hpsScreen = WinGetScreenPS (HWND_DESKTOP);
  
   aptl[0].x = 0;
   aptl[0].y = 0;
   aptl[1].x = bmp2.cx;
   aptl[1].y = bmp2.cy;
   aptl[2].x = rclTrack.xLeft;
   aptl[2].y = rclTrack.yBottom;
  
   WinLockVisRegions (HWND_DESKTOP, TRUE);
  
   // --------------------------------------------------------------------------                 
   // Bit blit the contents of the source presentation space into our target                     
   // presentation space.  This is how we copy the bitmap from the source to                     
   // the target.                                                                                
   // --------------------------------------------------------------------------                 
   GpiBitBlt (hpsMemory,      //  Target presentation space handle           
              hpsScreen,      //  Source presentation space handle           
              3L,             //  Number of Points                           
              aptl,           //  Array of Points                            
              ROP_SRCCOPY,    //  Mixing function (source copy)              
              BBO_IGNORE);    //  Options                                    
  
   WinLockVisRegions (HWND_DESKTOP, FALSE);
   WinReleasePS (hpsScreen);
  }

 // --------------------------------------------------------------------------                  
 // Free Graphics Engine Resources 
 // --------------------------------------------------------------------------                  
 GpiDestroyPS (hpsMemory);
 DevCloseDC (hdcMemory);

 // --------------------------------------------------------------------------                  
 // Return bitmap handle           
 // --------------------------------------------------------------------------                  
 return hbmTrack;
}
Пример #4
0
static VOID CreateROPBitmap(HWND hWnd)

{
BITMAPINFOHEADER  bmp;		   /* Bitmap Information Header		*/
BITMAPINFOHEADER2 bminfo2;	   /* Bitmap Information Header		*/
HBITMAP		  hbmConstruct;	   /* Bitmap Handle			*/
HDC		  hDC;		   /* Device Context Handle		*/
HPS		  hpsBitmap;	   /* Bitmap Presentation Space	Handle	*/
LONG		  cFormats;	   /* Formats Count			*/
LONG		  lROP = 0L;	   /* ROP Value				*/
PLONG		  plFormats;	   /* Formats Array			*/
POINTL		  aptl[4];	   /* Conversion Point			*/
RECTL		  rcl;		   /* Window Rectangle			*/
SIZEL		  sizl;		   /* Sizing Structure			*/
register INT i,	n;		   /* Loop Counters			*/

if ( hbmROP )
   GpiDeleteBitmap(hbmROP);

GpiQueryBitmapParameters(hbmView, &bmp);

		       /* Get bitmap device context handle for the main	*/
		       /* Client Window					*/

if ( !(hDC = DevOpenDC(hAB, OD_MEMORY, "*", 0L,	0L, 0L)) )
   return((HBITMAP)NULL);
		       /* Create bitmap	presentation space specifying	*/
		       /* entire map Client Window for size required	*/

WinQueryWindowRect(hWnd, &rcl);
lHorzRange = (cxROP = sizl.cx =	bmp.cx * 16L + 150L) - (cxWindow = rcl.xRight -	rcl.xLeft);
lVertRange = (cyROP = sizl.cy =	bmp.cy * 16L + 150L) - (cyWindow = rcl.yTop - rcl.yBottom);

WinSendMsg(hwndVScroll,	SBM_SETSCROLLBAR, MPFROMSHORT(lVertPos),
	   MPFROM2SHORT(0, lVertRange));
WinSendMsg(hwndVScroll,	SBM_SETTHUMBSIZE, MPFROM2SHORT(cyWindow, cyROP), 0L);

WinSendMsg(hwndHScroll,	SBM_SETSCROLLBAR, MPFROMSHORT(lHorzPos),
	   MPFROM2SHORT(0, lHorzRange));
WinSendMsg(hwndHScroll,	SBM_SETTHUMBSIZE, MPFROM2SHORT(cxWindow, cxROP), 0L);

rclROP.xLeft   = 0L;
rclROP.yBottom = cyROP - cyWindow;
rclROP.xRight  = cxWindow;
rclROP.yTop    = cyROP;

cxImage	= bmp.cx + 10L;
cyImage	= bmp.cy + 10L;

if ( !(hpsBitmap = GpiCreatePS(hAB, hDC, &sizl,	PU_PELS	| GPIT_NORMAL |	GPIA_ASSOC)) )
   {
		       /* Error	occurred during	creation of		*/
		       /* presentation space, close device context	*/
   DevCloseDC(hDC);
   return((HBITMAP)NULL);
   }
		       /* Get the number of bitmap formats that	the	*/
		       /* display driver supports			*/

DevQueryCaps(hDC, CAPS_BITMAP_FORMATS, 1L, &cFormats);

		       /* Get the bitmap display formats.  The first	*/
		       /* set within the array will be the one that	*/
		       /* most closely matches the display device.	*/

GpiQueryDeviceBitmapFormats(hpsBitmap, cFormats	* 2L,
			    plFormats =	(PLONG)malloc(2UL * cFormats * sizeof(LONG)));

		       /* Create actual	bitmap storage for colour wheel	*/
		       /* having the default plane and bit count	*/

memset(&bminfo2, 0, sizeof(BITMAPINFOHEADER2));
bminfo2.cbFix	  = sizeof(BITMAPINFOHEADER2);
bminfo2.cx	  = (ULONG)sizl.cx;
bminfo2.cy	  = (ULONG)sizl.cy;
bminfo2.cPlanes	  = (USHORT)plFormats[0];
bminfo2.cBitCount = (USHORT)plFormats[1];

free(plFormats);

if ( !(hbmConstruct = GpiCreateBitmap(hpsBitmap, &bminfo2, 0L, 0L, 0L))	)
   {
		       /* Error	occurred during	creation of bitmap	*/
		       /* storage, destroy presentation	space created	*/
		       /* and close device context opened		*/

   GpiDestroyPS(hpsBitmap);
   DevCloseDC(hDC);
   return((HBITMAP)NULL);
   }
		       /* Set bitmap as	current	bitmap to use		*/

GpiSetBitmap(hpsBitmap,	hbmConstruct);

		       /* Draw the page					*/
GpiErase(hpsBitmap);

aptl[0].x = 0L;
aptl[0].y = sizl.cy - bmp.cy;
aptl[1].x = bmp.cx;
aptl[1].y = sizl.cy;

aptl[2].x = aptl[2].y =	0L;
aptl[3].x = bmp.cx;
aptl[3].y = bmp.cy;

GpiSetPattern(hpsBitmap, lPattern);

for ( i	= 0; i < 16; i++ )
   {
   for ( n = 0;	n < 16;	n++ )
       {
       rcl.xLeft   = aptl[0].x;
       rcl.xRight  = aptl[1].x + 1L;
       rcl.yBottom = aptl[0].y;
       rcl.yTop	   = aptl[1].y + 1L;
       WinFillRect(hpsBitmap, &rcl, lFillColour);
       GpiWCBitBlt(hpsBitmap, hbmView, 4L, aptl, lROP++, BBO_IGNORE);
       aptl[0].x += (bmp.cx + 10L);
       aptl[1].x += (bmp.cx + 10L);
       }
   aptl[0].y -=	(bmp.cy	+ 10L);
   aptl[1].y -=	(bmp.cy	+ 10L);
   aptl[0].x = 0L;
   aptl[1].x = bmp.cx;
   }
		       /* Set the bitmap to allow completion of	bitmap	*/
		       /* in memory					*/

GpiSetBitmap(hpsBitmap,	(HDC)NULL);

		       /* Destroy the memory device context		*/

GpiAssociate(hpsBitmap,	(HDC)NULL);

		       /* Destroy the presentation spaces used		*/
GpiDestroyPS(hpsBitmap);
DevCloseDC(hDC);
		       /* Return the bitmap handle that	will be	used in	*/
		       /* painting the image on	the window		*/
hbmROP = hbmConstruct;
}
Пример #5
0
static void draw_stuff( HWND hwnd )
{
    HPS                 win_dc;
    RECTL               paint;
    RECTL               intersect;
#ifdef DRAW_ALL_AT_ONCE
    int                 old_top;
    int                 width, height;
    SIZEL               sizl = { 0, 0 };
    BITMAPINFOHEADER2   bmih;
    LONG                formats[24];
    POINTL              pts[3];
    LONG                old_cursor;
    LONG                hour_glass_cur;
    RECTL               interior;
    DEVOPENSTRUC        dop = { 0L, "DISPLAY", NULL, 0L,
                                0L, 0L, 0L, 0L, 0L };
#endif


    win_dc = WinBeginPaint( hwnd, 0, &paint );
    GpiCreateLogColorTable( win_dc, 0L, LCOLF_RGB, 0L, 0L, NULL );
#ifdef DRAW_ALL_AT_ONCE
    old_top = paint.yBottom;
    paint.yBottom = Draw_area.yTop;
#endif
    WinFillRect( win_dc, &paint, SYSCLR_WINDOW );
#ifdef DRAW_ALL_AT_ONCE
    paint.yBottom = old_top;
#endif
    if( WinIntersectRect( Main_hab, &intersect, &paint, &Draw_area ) ) {

#ifdef DRAW_ALL_AT_ONCE
        width = Draw_area.xRight - Draw_area.xLeft;
        height = Draw_area.yTop - Draw_area.yBottom;
        interior.xLeft = 0;
        interior.yBottom = 0;
        interior.xRight = width;
        interior.yTop = height;
        if( Draw_bitmap == NULLHANDLE ) {
            Hdc = DevOpenDC( Main_hab, OD_MEMORY, "*", 5L,
                                            (PDEVOPENDATA)&dop, NULLHANDLE );
            Mem_dc = GpiCreatePS( Main_hab, Hdc, &sizl, PU_PELS | GPIA_ASSOC );
            memset( &bmih, 0, sizeof( BITMAPINFOHEADER2 ) );
            GpiQueryDeviceBitmapFormats( Mem_dc, 24L, formats );
            bmih.cbFix = sizeof( BITMAPINFOHEADER2 );
            bmih.cx = width;
            bmih.cy = height;
            bmih.cPlanes = (USHORT) formats[0];
            bmih.cBitCount = (USHORT) formats[1];
            Draw_bitmap = GpiCreateBitmap( Mem_dc, &bmih, 0L, NULL, NULL );
            Old_bitmap = GpiSetBitmap( Mem_dc, Draw_bitmap );
            GpiCreateLogColorTable( Mem_dc, 0, LCOLF_RGB, 0, 0, NULL );
            WinFillRect( Mem_dc, &interior, SYSCLR_WINDOW );

            hour_glass_cur = WinQuerySysPointer( HWND_DESKTOP, SPTR_WAIT, FALSE );
            old_cursor = WinQueryPointer( HWND_DESKTOP );
            WinSetPointer( HWND_DESKTOP, hour_glass_cur );

            hThree_d = three_d_begin( Mem_dc, &interior );
            draw_room();
            three_d_draw( hThree_d );
            three_d_end( hThree_d );

            WinSetPointer( HWND_DESKTOP, old_cursor );
        }

        pts[0].x = Draw_area.xLeft;
        pts[0].y = Draw_area.yBottom;
        pts[1].x = Draw_area.xLeft + width;
        pts[1].y = Draw_area.yBottom + height;
        pts[2].x = 0;
        pts[2].y = 0;
        GpiBitBlt( win_dc, Mem_dc, 3, pts, ROP_SRCCOPY, BBO_IGNORE );
#else
        hThree_d = three_d_begin( win_dc, &Draw_area );
        draw_room();
        three_d_draw( hThree_d );
        three_d_end( hThree_d );
#endif

    }
    WinEndPaint( win_dc );
}