static
  grPMSurface*  init_surface( grPMSurface*  surface,
                              grBitmap*     bitmap )
  {
    PBITMAPINFO2  bit;
    SIZEL         sizl = { 0, 0 };
    LONG          palette[256];
    LOG(( "Os2PM: init_surface( %08lx, %08lx )\n",
          (long)surface, (long)bitmap ));

    LOG(( "       -- input bitmap =\n" ));
    LOG(( "       --   mode   = %d\n", bitmap->mode ));
    LOG(( "       --   grays  = %d\n", bitmap->grays ));
    LOG(( "       --   width  = %d\n", bitmap->width ));
    LOG(( "       --   height = %d\n", bitmap->rows ));

    /* create the bitmap - under OS/2, we support all modes as PM */
    /* handles all conversions automatically..                    */
    if ( grNewBitmap( bitmap->mode,
                      bitmap->grays,
                      bitmap->width,
                      bitmap->rows,
                      bitmap ) )
      return 0;

    LOG(( "       -- output bitmap =\n" ));
    LOG(( "       --   mode   = %d\n", bitmap->mode ));
    LOG(( "       --   grays  = %d\n", bitmap->grays ));
    LOG(( "       --   width  = %d\n", bitmap->width ));
    LOG(( "       --   height = %d\n", bitmap->rows ));

    bitmap->pitch = -bitmap->pitch;
    surface->root.bitmap = *bitmap;

    /* create the image and event lock */
    DosCreateEventSem( NULL, &surface->event_lock, 0, TRUE  );
    DosCreateMutexSem( NULL, &surface->image_lock, 0, FALSE );

    /* create the image's presentation space */
    surface->image_dc = DevOpenDC( gr_anchor,
                                   OD_MEMORY, (PSZ)"*", 0L, 0L, 0L );

    surface->image_ps = GpiCreatePS( gr_anchor,
                                     surface->image_dc,
                                     &sizl,
                                     PU_PELS    | GPIT_MICRO |
                                     GPIA_ASSOC | GPIF_DEFAULT );

    GpiSetBackMix( surface->image_ps, BM_OVERPAINT );

    /* create the image's PM bitmap */
    bit = (PBITMAPINFO2)grAlloc( sizeof(BITMAPINFO2) + 256*sizeof(RGB2) );
    surface->bitmap_header = bit;

    bit->cbFix   = sizeof( BITMAPINFOHEADER2 );
    bit->cx      = surface->root.bitmap.width;
    bit->cy      = surface->root.bitmap.rows;
    bit->cPlanes = 1;

    bit->argbColor[0].bBlue  = 255;
    bit->argbColor[0].bGreen = 0;
    bit->argbColor[0].bRed   = 0;

    bit->argbColor[1].bBlue  = 0;
    bit->argbColor[1].bGreen = 255;
    bit->argbColor[1].bRed   = 0;

    bit->cBitCount = (bitmap->mode == gr_pixel_mode_gray ? 8 : 1 );

    if (bitmap->mode == gr_pixel_mode_gray)
    {
      RGB2*  color = bit->argbColor;
      int    x, count;

      count = bitmap->grays;
      for ( x = 0; x < count; x++, color++ )
      {
        color->bBlue  =
        color->bGreen =
        color->bRed   = (((count-x)*255)/count);
      }
    }
    else
    {
      RGB2*  color = bit->argbColor;

      color[0].bBlue  =
      color[0].bGreen =
      color[0].bRed   = 0;

      color[1].bBlue  =
      color[1].bGreen =
      color[1].bRed   = 255;
    }

    surface->os2_bitmap = GpiCreateBitmap( surface->image_ps,
                                           (PBITMAPINFOHEADER2)bit,
                                           0L, NULL, NULL );

    GpiSetBitmap( surface->image_ps, surface->os2_bitmap );

    bit->cbFix = sizeof( BITMAPINFOHEADER2 );
    GpiQueryBitmapInfoHeader( surface->os2_bitmap,
                              (PBITMAPINFOHEADER2)bit );
    surface->bitmap_header = bit;

    /* for gr_pixel_mode_gray, create a gray-levels logical palette */
    if ( bitmap->mode == gr_pixel_mode_gray )
    {
      int     x, count;

      count = bitmap->grays;
      for ( x = 0; x < count; x++ )
        palette[x] = (((count-x)*255)/count) * 0x010101;

      /* create logical color table */
      GpiCreateLogColorTable( surface->image_ps,
                              (ULONG) LCOL_PURECOLOR,
                              (LONG)  LCOLF_CONSECRGB,
                              (LONG)  0L,
                              (LONG)  count,
                              (PLONG) palette );

      /* now, copy the color indexes to surface->shades */
      for ( x = 0; x < count; x++ )
        surface->shades[x] = GpiQueryColorIndex( surface->image_ps,
                                                 0, palette[x] );
    }

    /* set up the blit points array */
    surface->blit_points[1].x = surface->root.bitmap.width;
    surface->blit_points[1].y = surface->root.bitmap.rows;
    surface->blit_points[3]   = surface->blit_points[1];

    /* Finally, create the event handling thread for the surface's window */
    DosCreateThread( &surface->message_thread,
                     (PFNTHREAD) RunPMWindow,
                     (ULONG)     surface,
                     0UL,
                     32920 );

    /* wait for the window creation */
    LOCK(surface->image_lock);
    UNLOCK(surface->image_lock);

    surface->root.done         = (grDoneSurfaceFunc) done_surface;
    surface->root.refresh_rect = (grRefreshRectFunc) refresh_rectangle;
    surface->root.set_title    = (grSetTitleFunc)    set_title;
    surface->root.listen_event = (grListenEventFunc) listen_event;

    /* convert_rectangle( surface, 0, 0, bitmap->width, bitmap->rows ); */
    return surface;
  }
Ejemplo n.º 2
0
  grArosSurface*  init_surface( grArosSurface*  surface,
                             grBitmap*    bitmap )
  {
    printf("init_surface: width = %d  height = %d\n",
    		bitmap->width,
		bitmap->rows);
    
    bitmap->width = (bitmap->width + 15) & ~15;
    surface->bpr = bitmap->width / 8;
    
    if (grNewBitmap(bitmap->mode,
    		    bitmap->grays,
		    bitmap->width,
		    bitmap->rows,
		    bitmap)) return 0;
		
    surface->win = OpenWindowTags(0, WA_Left, 20,
    				     WA_Top, 20,
				     WA_InnerWidth, bitmap->width,
				     WA_InnerHeight, bitmap->rows,
				     WA_AutoAdjust, TRUE,
				     WA_Title, "Freetype demo",
				     WA_CloseGadget, TRUE,
				     WA_DepthGadget, TRUE,
				     WA_Activate, TRUE,
				     WA_IDCMP, IDCMP_VANILLAKEY | IDCMP_RAWKEY,
				     TAG_DONE);

    if (!surface->win)
    {
      puts("Could not open window!");
      grDoneBitmap(bitmap);
      return 0;
    }					    

    puts("Window opened.");

    surface->grays = ( bitmap->mode == gr_pixel_mode_gray &&
                       bitmap->grays >= 2 );

    if (surface->grays)
    {
      WORD i;
      
      if (GetBitMapAttr(surface->win->RPort->BitMap, BMA_DEPTH <= 8))
      {
        puts("Need hi/true color screen!");
	CloseWindow(surface->win);
	grDoneBitmap(bitmap);
	return 0;
      }
      
      for(i = 0; i < bitmap->grays; i++)
      {
        LONG red, green, blue;
	
	red = green = blue = (bitmap->grays - i) * 255 / bitmap->grays;
	
        surface->cgfxcoltab[i] = (red << 16) | (green << 8) | blue;
      }
    }	          
    surface->root.bitmap       = *bitmap;
    surface->root.done         = (grDoneSurfaceFunc) done_surface;
    surface->root.refresh_rect = (grRefreshRectFunc) refresh_rectangle;
    surface->root.set_title    = (grSetTitleFunc)    set_title;
    surface->root.listen_event = (grListenEventFunc) listen_event;
    
    return surface;
  }