Ejemplo n.º 1
0
void QFObjectRenderer::copyFrame()
{
  IClipboard clipboard(window_p->handle());
  PBYTE frameBuffer;
  ULONG scanLineBytes, scanLines;
  BITMAPINFOHEADER2 bmp = {0};
  BITMAPINFOHEADER2 bmpInfo;
  HBITMAP hbm;
  LONG errorCode;

  errorCode = DiveBeginImageBufferAccess(dive, frame[currentColumn][currentRow],
                                         &frameBuffer, &scanLineBytes, &scanLines);

  bmp.cbFix = sizeof(BITMAPINFOHEADER2);
  bmp.cx = movieSize().width();
  bmp.cy = movieSize().height();
  bmp.cPlanes = 1;
  bmp.cBitCount = 24;
  bmp.ulCompression = BCA_UNCOMP;
  bmp.cbImage = scanLineBytes * scanLines;
  bmp.usRecording = BRA_BOTTOMUP; /*  Must be BRA_BOTTOMUP. */
  bmp.usRendering = BRH_NOTHALFTONED; /*  Not used. */
  bmp.ulColorEncoding = BCE_RGB;

  bmpInfo = bmp;

  IGraphicContext context;
  hbm = GpiCreateBitmap(context.handle(), &bmp, CBM_INIT, frameBuffer, (PBITMAPINFO2)&bmpInfo);

  clipboard.setBitmap(hbm);

  GpiDeleteBitmap(hbm);
  errorCode = DiveEndImageBufferAccess(dive, frame[currentColumn][currentRow]);
}
Ejemplo n.º 2
0
LONG XBitmap::SetData(const BITMAPINFOHEADER2 * p, const LONG offset)
{
   LONG cScans;
   BITMAPINFOHEADER2 *data;

   LONG size = (((((BITMAPINFOHEADER2 *) p)->cBitCount * ((BITMAPINFOHEADER2 *) p)->cx) + 31) / 32) * 4 * ((BITMAPINFOHEADER2 *) p)->cPlanes * ((BITMAPINFOHEADER2 *) p)->cy;

   data = (PBITMAPINFOHEADER2) malloc(size);
   memcpy(data, p, size);

   if (data->cbFix == sizeof(BITMAPINFOHEADER))
      cScans = (ULONG) ((PBITMAPINFOHEADER) data)->cy;
   else
      cScans = data->cy;

   if (hbm != 0)
      GpiDeleteBitmap(hbm);

   hbm = GpiCreateBitmap(hps, data, CBM_INIT, (PBYTE) p + offset, (PBITMAPINFO2) data);

   if (hbm == GPI_ERROR)
      OOLThrow("error creating bitmap", 3);

   free(data);

   return 0;
}
Ejemplo n.º 3
0
QPixmap QPixmap::grabWindow(WId winId, int x, int y, int w, int h)
{
    QPixmap pm;

    if (w == 0 || h == 0)
        return pm;

    RECTL rcl;
    if (!WinQueryWindowRect(winId, &rcl))
        return pm;

    if (w < 0)
        w = rcl.xRight;
    if (h < 0)
        h = rcl.yTop;

    // flip y coordinate
    y = rcl.yTop - (y + h);

    HPS hps = qt_alloc_mem_ps(w, h);
    if (hps == NULLHANDLE)
        return pm;

    HBITMAP hbm = NULLHANDLE;

    // bitmap header + 2 palette entries (for the mask)
    BITMAPINFOHEADER2 bmh;
    bmh.cbFix = sizeof(BITMAPINFOHEADER2);

    // create the uninitialized bitmap to hold window pixels
    bmh.cx = w;
    bmh.cy = h;
    bmh.cPlanes = 1;
    bmh.cBitCount = 32;
    hbm = GpiCreateBitmap(hps, &bmh, 0, 0, 0);

    if (hbm != NULLHANDLE) {
        GpiSetBitmap(hps, hbm);
        HPS hpsWin = WinGetPS(winId);
        if (hpsWin != NULLHANDLE) {
            POINTL pnts[] = { {0, 0}, {w, h}, {x, y} };
            if (GpiBitBlt(hps, hpsWin, 3, pnts,
                          ROP_SRCCOPY, BBO_IGNORE) != GPI_ERROR) {
                GpiSetBitmap(hps, NULLHANDLE);
                pm = fromPmHBITMAP(hbm);
            }
            WinReleasePS(hpsWin);
        }
        GpiDeleteBitmap(hbm);
    }

    qt_free_mem_ps(hps);

    return pm;
}
Ejemplo n.º 4
0
gfxOS2Surface::gfxOS2Surface(const gfxIntSize& aSize,
                             gfxImageFormat aImageFormat)
    : mWnd(0), mSize(aSize)
{
#ifdef DEBUG_thebes_2
    printf("gfxOS2Surface[%#x]::gfxOS2Surface(Size=%dx%d, %d)\n", (unsigned int)this,
           aSize.width, aSize.height, aImageFormat);
#endif
    // in this case we don't have a window, so we create a memory presentation
    // space to construct the cairo surface on

    // create a PS, partly taken from nsOffscreenSurface::Init(), i.e. nsDrawingSurfaceOS2.cpp
    DEVOPENSTRUC dop = { 0, 0, 0, 0, 0 };
    SIZEL sizel = { 0, 0 }; // use same page size as device
    mDC = DevOpenDC(0, OD_MEMORY, (PSZ)"*", 5, (PDEVOPENDATA)&dop, NULLHANDLE);
    NS_ASSERTION(mDC != DEV_ERROR, "Could not create memory DC");

    mPS = GpiCreatePS(0, mDC, &sizel, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
    NS_ASSERTION(mPS != GPI_ERROR, "Could not create PS on memory DC!");

    // now create a bitmap of the right size
    BITMAPINFOHEADER2 hdr = { 0 };
    hdr.cbFix = sizeof(BITMAPINFOHEADER2);
    hdr.cx = mSize.width;
    hdr.cy = mSize.height;
    hdr.cPlanes = 1;

    // find bit depth
    LONG lBitCount = 0;
    DevQueryCaps(mDC, CAPS_COLOR_BITCOUNT, 1, &lBitCount);
    hdr.cBitCount = (USHORT)lBitCount;

    mBitmap = GpiCreateBitmap(mPS, &hdr, 0, 0, 0);
    NS_ASSERTION(mBitmap != GPI_ERROR, "Could not create bitmap in memory!");
    // set final stats & select bitmap into PS
    GpiSetBitmap(mPS, mBitmap);

    // now we can finally create the cairo surface on the in-memory PS
    cairo_surface_t *surf = cairo_os2_surface_create(mPS, mSize.width, mSize.height);
#ifdef DEBUG_thebes_2
    printf("  type(%#x)=%d (ID=%#x, h/w=%d/%d)\n", (unsigned int)surf,
           cairo_surface_get_type(surf), (unsigned int)mPS, mSize.width, mSize.height);
#endif
    // Normally, OS/2 cairo surfaces have to be forced to redraw completely
    // by calling cairo_surface_mark_dirty(surf), but Mozilla paints them in
    // full, so that is not necessary here.

    // manual refresh is done from nsWindow::OnPaint
    cairo_os2_surface_set_manual_window_refresh(surf, 1);

    Init(surf);
}
Ejemplo n.º 5
0
void DisplayVbuf(HPS  hpsBuffer, RECTL rect, int isChange)
{
    POINTL aptl[4];
    LONG   lhits;

    /* Create a bit map that is compatible with the display.            */
    if (isChange)
    {
        if (hbm) GpiDeleteBitmap(hbm);
        hbm = GpiCreateBitmap(hpsDesktop, &bmp, CBM_INIT, (PBYTE) pBmpBuffer, pbmi);
        GpiSetBitmap(hpsDesktop,hbm);
        GpiSetBitmapBits(hpsDesktop, 0,bmp.cy,(PBYTE) pBmpBuffer, pbmi); //?????
    }
    else
    {
        // GpiSetBitmap(hpsBuffer,hbm);
        // ii = GpiSetBitmapBits(hpsBuffer, 0,bmp.cy,(PBYTE) pBmpBuffer, pbmi);
        GpiSetBitmap(hpsDesktop,hbm);
        GpiSetBitmapBits(hpsDesktop, 0,bmp.cy,(PBYTE) pBmpBuffer, pbmi);
    }

    aptl[0].x = rect.xLeft;       /* Lower-left corner of destination rectangle  */
    aptl[0].y = rect.yBottom;     /* Lower-left corner of destination rectangle  */
    aptl[1].x = rect.xRight;      /* Upper-right corner of destination rectangle */
    aptl[1].y = rect.yTop;        /* Upper-right corner of destination rectangle */
    /* Source-rectangle dimensions (in device coordinates)                       */
    aptl[2].x = 0;                /* Lower-left corner of source rectangle       */
    aptl[2].y = 0;                /* Lower-left corner of source rectangle       */
    aptl[3].x = bmp.cx;           //  bmp.cx;
    aptl[3].y = bmp.cy;           // bmp.cy;

    pbmi->cy = bmp.cy;

    /* >>>>>>>>>>>>>>>>>>>>>>>>>>> */
    //lhits = GpiBitBlt(hpsBuffer , hpsMem,
    //     3,   /* 3-source rect=dest rect 4 Number of points in aptl */
    //     aptl, ROP_SRCCOPY,  BBO_IGNORE/* | BBO_PAL_COLORS*/ );

//       if(ii != GPI_OK)
//       {    ERRORID errid;
//            errid = WinGetLastError(hab);
//            ierr++;
//       }

    GpiSetBitmap(hpsDesktop,0);

//  rc = GpiDeleteBitmap(hbm);
}
Ejemplo n.º 6
0
/*@ XBitmap::LoadBMP(const char* filename)
@group loading a bitmap
@remarks Load a bitmap from a file. This method works faster than Load() but can only load bitmpas in OS2-BMP format
@parameters   char * fileName   filename of the file to load
@exceptions   If the method fails to create a new bitmap an exception of the type XException is thrown.
*/
void XBitmap :: LoadBMP(const char* filename)
{
   if (hbm)
      GpiDeleteBitmap(hbm);
   hbm = 0;

   XFile file;
   PBITMAPFILEHEADER p;
   if (file.Open(filename, XFILE_FAIL_IF_NEW | XFILE_OPEN_EXISTING, XFILE_READONLY, XFILE_SHARE_DENYNONE ) == 0)
   {
      XFileInfo info;
      file.GetFileInfo(&info);
      file.Seek(0, XFILE_BEGIN);
      p = (PBITMAPFILEHEADER) malloc(info.GetFileSize());
      file.Read(p, info.GetFileSize());
      file.Close();
   }
   else
      OOLThrow( "couldnït open file!", -1);

   if (owner )
   {
      hps = WinGetPS(owner->GetHandle());
      hbm = GpiCreateBitmap(hps, (PBITMAPINFOHEADER2) &p->bmp, CBM_INIT, (PBYTE) p + p->offBits, (PBITMAPINFO2) &p->bmp);
      if(hbm == 0)
         OOLThrow("error creating bitmap", 3);
   }
   else
      SetData((BITMAPINFOHEADER2 *) &p->bmp, p->offBits);
   free(p);
   XSize s;
   GetDimensions(&s);
   width = cx = s.GetWidth();
   height = cy = s.GetHeight();

   if (hbm == GPI_ERROR)
   {
      ULONG error = WinGetLastError(XApplication::GetApplication()->GetAnchorBlock());
      OOLThrow("couldnït load bitmap", error);
   }

   return;
}
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;
}
Ejemplo n.º 8
0
gfxOS2Surface::gfxOS2Surface(HDC aDC, const gfxIntSize& aSize)
    : mWnd(0), mDC(aDC), mBitmap(nullptr), mSize(aSize)
{
#ifdef DEBUG_thebes_2
    printf("gfxOS2Surface[%#x]::gfxOS2Surface(HDC=%#x, Size=%dx%d)\n", (unsigned int)this,
           (unsigned int)aDC, aSize.width, aSize.height);
#endif
    SIZEL sizel = { 0, 0 }; // use same page size as device
    mPS = GpiCreatePS(0, mDC, &sizel, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
    NS_ASSERTION(mPS != GPI_ERROR, "Could not create PS on print DC!");

    // now create a bitmap of the right size
    BITMAPINFOHEADER2 hdr = { 0 };
    hdr.cbFix = sizeof(BITMAPINFOHEADER2);
    hdr.cx = mSize.width;
    hdr.cy = mSize.height;
    hdr.cPlanes = 1;

    // find bit depth
    LONG lBitCount = 0;
    DevQueryCaps(mDC, CAPS_COLOR_BITCOUNT, 1, &lBitCount);
    hdr.cBitCount = (USHORT)lBitCount;

    mBitmap = GpiCreateBitmap(mPS, &hdr, 0, 0, 0);
    NS_ASSERTION(mBitmap != GPI_ERROR, "Could not create bitmap for printer!");
    // set final stats & select bitmap into PS
    GpiSetBitmap(mPS, mBitmap);

    // now we can finally create the cairo surface on the in-memory PS
    cairo_surface_t *surf = cairo_os2_surface_create(mPS, mSize.width, mSize.height);
#ifdef DEBUG_thebes_2
    printf("  type(%#x)=%d (ID=%#x, h/w=%d/%d)\n", (unsigned int)surf,
           cairo_surface_get_type(surf), (unsigned int)mPS, mSize.width, mSize.height);
#endif
    // Normally, OS/2 cairo surfaces have to be forced to redraw completely
    // by calling cairo_surface_mark_dirty(surf), but Mozilla paints them in
    // full, so that is not necessary here.

    Init(surf);
}
Ejemplo n.º 9
0
static bool qt_alloc_ps_with_bitmap(int w, int h, bool isMono,
                                    HPS &hps, HBITMAP &hbm)
{
    hps = qt_alloc_mem_ps(32, 32);
    if (hps == NULLHANDLE)
        return false;

    BITMAPINFOHEADER2 bmh;
    bmh.cbFix = sizeof(BITMAPINFOHEADER2);
    bmh.cx = w;
    bmh.cy = h;
    bmh.cPlanes = 1;
    bmh.cBitCount = isMono ? 1 : 32;
    hbm = GpiCreateBitmap(hps, &bmh, 0, 0, 0);
    if (hbm == NULLHANDLE) {
        qt_free_mem_ps(hps);
        return false;
    }

    GpiSetBitmap(hps, hbm);
    return true;
}
Ejemplo n.º 10
0
// manages changes in size
VOID WndResize( const HWND hwnd )
{
    wcprintf("WndResize");
    RECTL rWindow;
    LONG cyHeight, cxWidth;
    BITMAPINFOHEADER bmp;

    if( (hbmGlob = GpiSetBitmap( hpsBufferGlob, NULLHANDLE )) != NULLHANDLE ){
	wcprintf("wndresize: there was an old bitmap");
	GpiDeleteBitmap( hbmGlob );        // delete old stuff
    } else 
	wcprintf("wndresize: there was no old bitmap");

    // build the bitmap:
    WinQueryWindowRect( hwnd, &rWindow );
    cxWidth = rWindow.xRight - rWindow.xLeft;// - 2;
    cyHeight = rWindow.yTop - rWindow.yBottom; // - 2;
    wcprintf("wndResize: Breite: %d, H”he: %d", rWindow.xRight, rWindow.yTop );

    memset(&bmp, 0, sizeof(BITMAPINFOHEADER));
    bmp.cbFix = sizeof(BITMAPINFOHEADER);
    bmp.cx = (SHORT)cxWidth;
    bmp.cy = (SHORT)cyHeight;
    bmp.cPlanes = (SHORT)cColorPlanes;
    bmp.cBitCount = (SHORT)cColorBitCount;
    hbmGlob = GpiCreateBitmap(hpsBufferGlob, (PBITMAPINFOHEADER2)&bmp, 
			      0L, NULL, NULL); 
    if( hbmGlob == GPI_ERROR )
	DosBeep( 100, 500);
    GpiSetBitmap( hpsBufferGlob, hbmGlob);

    // calculate the size

//    if( !GpiSetPageViewport(hpsGlob, &rWindow) )
//	wcprintf("error 1");
return;
    if( !GpiSetPageViewport(hpsBufferGlob, &rWindow) )
	wcprintf("error 2");
}
Ejemplo n.º 11
0
/* one scan line at a time */
static int
os2prn_print_page(gx_device_printer * pdev, FILE * file)
{
    int raster = gdev_prn_raster(pdev);

    /* BMP scan lines are padded to 32 bits. */
    ulong bmp_raster = (raster + 3) & (~3);
    ulong bmp_raster_multi;
    int height = pdev->height;
    int depth = pdev->color_info.depth;
    byte *row;
    int y;
    int code = 0;		/* return code */
    POINTL apts[4];
    APIRET rc;
    POINTL aptsb[4];
    HBITMAP hbmp, hbmr;
    int i, lines;
    int ystart, yend;
    int yslice;

    struct bmi_s {
	BITMAPINFOHEADER2 h;
	RGB2 pal[256];
    } bmi;

    yslice = 65535 / bmp_raster;
    bmp_raster_multi = bmp_raster * yslice;
    row = (byte *) gs_malloc(pdev->memory, bmp_raster_multi, 1, "bmp file buffer");
    if (row == 0)		/* can't allocate row buffer */
	return_error(gs_error_VMerror);

    if (opdev->newframe)
	DevEscape(opdev->hdc, DEVESC_NEWFRAME, 0L, NULL, NULL, NULL);
    opdev->newframe = 1;

    /* Write the info header. */

    memset(&bmi.h, 0, sizeof(bmi.h));
    bmi.h.cbFix = sizeof(bmi.h);
    bmi.h.cx = pdev->width;	/* opdev->mdev.width; */
    /* bmi.h.cy = height; */
    bmi.h.cy = yslice;		/* size for memory PS */
    bmi.h.cPlanes = 1;
    bmi.h.cBitCount = pdev->color_info.depth;

    /* Write the palette. */

    if (depth <= 8) {
	int i;
	gx_color_value rgb[3];
	PRGB2 pq;

	bmi.h.cclrUsed = 1 << depth;
	bmi.h.cclrImportant = 1 << depth;
	for (i = 0; i != 1 << depth; i++) {
	    (*dev_proc(pdev, map_color_rgb)) ((gx_device *) pdev,
					      (gx_color_index) i, rgb);
	    pq = &bmi.pal[i];
	    pq->bRed = gx_color_value_to_byte(rgb[0]);
	    pq->bGreen = gx_color_value_to_byte(rgb[1]);
	    pq->bBlue = gx_color_value_to_byte(rgb[2]);
	    pq->fcOptions = 0;
	}
    } else {
	bmi.h.cclrUsed = 0;
	bmi.h.cclrImportant = 0;
    }

    /* for GpiDrawBits */
    /* target is inclusive */
    apts[0].x = 0;
    apts[0].y = 0;		/* filled in later */
    apts[1].x = pdev->width - 1;
    apts[1].y = 0;		/* filled in later */
    /* source is not inclusive of top & right borders */
    apts[2].x = 0;
    apts[2].y = 0;
    apts[3].x = pdev->width;
    apts[3].y = 0;		/* filled in later */

    /* for GpiBitBlt */
    /* target is not inclusive */
    aptsb[0].x = opdev->clipbox[0];
    aptsb[0].y = 0;		/* filled in later */
    aptsb[1].x = opdev->clipbox[2];
    aptsb[1].y = 0;		/* filled in later */
    /* source is not inclusive */
    aptsb[2].x = opdev->clipbox[0];
    aptsb[2].y = 0;
    aptsb[3].x = opdev->clipbox[2];
    aptsb[3].y = 0;		/* filled in later */

    /* write the bits */
    ystart = opdev->clipbox[3];
    yend = opdev->clipbox[1];
    y = ystart;
    while (y > yend) {
	/* create a bitmap for the memory DC */
	hbmp = GpiCreateBitmap(opdev->hpsMem, &bmi.h, 0L, NULL, NULL);
	if (hbmp == GPI_ERROR)
	    goto bmp_done;
	hbmr = GpiSetBitmap(opdev->hpsMem, hbmp);

	/* copy slice to memory bitmap */
	if (y > yend + yslice)
	    lines = yslice;
	else
	    lines = y - yend;
	y -= lines;
	for (i = lines - 1; i >= 0; i--)
	    gdev_prn_copy_scan_lines(pdev, ystart - 1 - (y + i), row + (bmp_raster * i), raster);
	apts[0].y = 0;		/* target */
	apts[1].y = lines;
	apts[3].y = lines - 1;	/* source */
	/* copy DIB bitmap to memory bitmap */
	rc = GpiDrawBits(opdev->hpsMem, row, (BITMAPINFO2 *) & bmi, 4, apts,
			 (depth != 1) ? ROP_SRCCOPY : ROP_NOTSRCCOPY, 0);

	/* copy slice to printer */
	aptsb[0].y = y;
	aptsb[1].y = y + lines;
	aptsb[3].y = lines;
	rc = GpiBitBlt(opdev->hps, opdev->hpsMem, 4, aptsb, ROP_SRCCOPY, BBO_IGNORE);

	/* delete bitmap */
	if (hbmr != HBM_ERROR)
	    GpiSetBitmap(opdev->hpsMem, (ULONG) 0);
	hbmr = HBM_ERROR;
	if (hbmp != GPI_ERROR)
	    GpiDeleteBitmap(hbmp);
	hbmp = GPI_ERROR;
    }

  bmp_done:
    if (row)
	gs_free(pdev->memory, (char *)row, bmp_raster_multi, 1, "bmp file buffer");

    return code;
}
Ejemplo n.º 12
0
VOID PMfrWriteClipbrdBmp(HAB hab)
   {

   HDC hdcClip;         /* memory DC and PS to extract from the clipboard */
   HPS hpsClip;
   HBITMAP hbmClip;
   SIZEL sizl;
   BITMAPINFOHEADER bmp;
   ULONG _far *alRGBColors;
   LONG errorcode;
   char _far *fp1;
   char _far *fp2;
   int i;

   if (WinOpenClipbrd(hab))
      {
      /* get the memory DC and PS to copy the bitmap */
      hdcClip = DevOpenDC (hab, OD_MEMORY, "*", 0L, NULL, NULL) ;

      sizl.cx = cp.cx; sizl.cy = cp.cy;

      hpsClip = GpiCreatePS (hab, hdcClip, &sizl,
                   PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC);

      bmp.cbFix   = sizeof bmp;
      bmp.cx      = cp.cx;
      bmp.cy      = cp.cy;
      bmp.cPlanes = cp.cPlanes;
      bmp.cBitCount = cp.cBitCount;
      hbmClip = GpiCreateBitmap (hpsClip, &bmp, 0L, NULL, NULL);

      GpiSetBitmap(hpsClip, hbmClip);

      /* initialize and black out the bitmap */
      alRGBColors = (ULONG _far *) _fmalloc(sizeof(ULONG) * cp.colors);
      /* beginning of source array */
      fp2 = (char _far *) &cp.pbmiMemory->argbColor[0];
      /* beginning of dest array */
      fp1 = (char _far *) &alRGBColors[0];
      for (i = 0; i < cp.colors; i++)
          {   /* copy base bytes for number of screen colors */
          alRGBColors[i] = 0;
          _fmemcpy(fp1, fp2, sizeof(RGB) );
          fp1 += sizeof(ULONG);
          fp2 += sizeof(RGB);
          }

      GpiSetMix ( hpsClip, FM_OVERPAINT) ;
      GpiSetBackMix (hpsClip, BM_LEAVEALONE) ;
      GpiCreateLogColorTable(hpsClip, LCOL_RESET | LCOL_REALIZABLE,
              LCOLF_CONSECRGB, 0L, cp.colors, alRGBColors);

      /* now copy the bits */
      cp.pbmiMemory->cx = cp.cx;
      cp.pbmiMemory->cy = cp.cy;
      cp.pbmiMemory->cPlanes = cp.cPlanes;
      cp.pbmiMemory->cBitCount = cp.cBitCount;
      errorcode = GpiSetBitmapBits(hpsClip, 0L, (LONG) cp.cy,
                                cp.pixels, cp.pbmiMemory);

      /* unlink the new bitmap */
      GpiSetBitmap(hpsClip, (HBITMAP) NULL);

      /* write to the clipboard */
      WinEmptyClipbrd (hab);
      WinSetClipbrdData (hab, (ULONG) hbmClip, CF_BITMAP, CFI_HANDLE);

      /* now clean up */

      _ffree(alRGBColors);
      GpiDestroyPS(hpsClip);
      DevCloseDC(hdcClip);

      WinCloseClipbrd(hab);
      }

   }
Ejemplo n.º 13
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;
}
Ejemplo n.º 14
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;
}
Ejemplo n.º 15
0
// *******************************************************************************                   
// FUNCTION:     CreateBitmap                                                                       
//                                                                                                   
// FUNCTION USE: Creates a bitmap                                         
//                                                                                                   
// DESCRIPTION:  Calls GpiCreateBitmap to create a bitmap based on the 
//               parameters passed to this call.
//                                                                                                   
// PARAMETERS:   HPS      memory presentation space handle                                           
//               LONG     horizontal size for bitmap 
//               LONG     vertical size for bitmap
//               SHORT    number of colors                                                           
//                                                                                                   
// RETURNS:      GPI_ERROR   if an error occurs                                                                    
//               HBITMAP     bitmap handle                                                                   
//                                                                                                   
// HISTORY:                                                                                          
//                                                                                                   
// *******************************************************************************                   
HBITMAP CreateBitmap(HPS hpsMemory, LONG lcxSize, LONG lcySize,  SHORT sNumColors)
{
 static BITMAPINFOHEADER2  bmp2;               
 static HBITMAP            hbmShadow;

 // --------------------------------------------------------------------------                     
 // Create a bitmap for shadow drawing                                                              
 // --------------------------------------------------------------------------                     
 memset(&bmp2, 0, sizeof(BITMAPINFOHEADER2));                                            
 bmp2.cbFix     = sizeof (bmp2);                                                            
 bmp2.cx        = lcxSize;                                                    
 bmp2.cy        = lcySize;                                                    
 bmp2.cPlanes   = 1;                                                                        

 // --------------------------------------------------------------------------               
 // If the user wants a 2 color (monochrome) bitmap / bit count is 1                                                    
 // --------------------------------------------------------------------------               
 if (sNumColors == 2) 
  {
   bmp2.cBitCount = 1;               
  } 

 // --------------------------------------------------------------------------               
 // If the user wants a 16 color bitmap / bit count is 4                                                   
 // --------------------------------------------------------------------------               
 else if (sNumColors == 16) 
  {
   bmp2.cBitCount = 4;               
  } 

 // --------------------------------------------------------------------------               
 // If the user wants a 256 color bitmap / bit count is 8                                                                
 // --------------------------------------------------------------------------               
 else if (sNumColors == 256)                                                                                           
  {
   bmp2.cBitCount = 8;                
  }

 // --------------------------------------------------------------------------      
 // Create our bitmap                                                              
 // --------------------------------------------------------------------------      
 hbmShadow = GpiCreateBitmap (hpsMemory,  // Memory Presentation Space handle               
                              &bmp2,      // Pointer to bitmap info header structure        
                              NULLHANDLE, // Options                                        
                              NULL,       // Buffer Address                                 
                              NULL);      // Pointer to bitmap info table structure         

 // --------------------------------------------------------------------------                   
 // If we got an error return it back to the caller                                
 // --------------------------------------------------------------------------                   
 if (hbmShadow == GPI_ERROR)                                                   
  {                                                                            
   return GPI_ERROR;                                                   
  }                                                                            

 // --------------------------------------------------------------------------                 
 // If everything is cool we got a valid bitmap handle so give it back 
 // to the caller.
 // --------------------------------------------------------------------------                 
 else
  {
   return hbmShadow;
  }
}
Ejemplo n.º 16
0
HBITMAP     CreateThumbnailBmp( CAMRecPtr pcr, char * pBuf)

{
    HBITMAP             hBmp = 0;
    uint32_t            ctr;
    HDC                 hdc = 0;
    HPS                 hps = 0;
    char *              pErr = 0;
    BITMAPINFOHEADER2 * pbmih = 0;
    RGB2 *              pRGB;
    SIZEL               sizl;
    CAMJThumb           cjt;

do {
    // decode the JPEG data from the camera
    memset( &cjt, 0, sizeof(cjt));
    cjt.pSrc = pBuf;
    cjt.cbSrc = pcr->tnsize;
    ctr = JpgDecodeThumbnail( &cjt);
    if (ctr) {
        printf( "JpgDecodeThumbnail - rc= 0x%x\n", (int)ctr);
        break;
    }

    // allocate a BITMAPINFOHEADER2 / BITMAPINFO2
    // suitable for 24-bit color or 8-bit grayscale
    ctr = sizeof(BITMAPINFOHEADER2);
    if (cjt.cbPix == 1)
        ctr += 256 * sizeof(RGB2);
        
    pbmih = (BITMAPINFOHEADER2*)malloc( ctr);
    memset( pbmih, 0, ctr);

    // if grayscale, create a default colormap
    if (cjt.cbPix == 1)
        for (ctr = 0, pRGB = (RGB2*)&pbmih[1]; ctr < 256; ctr++, pRGB++) {
            pRGB->bBlue  = ctr;
            pRGB->bGreen = ctr;
            pRGB->bRed   = ctr;
        }

    // init the BMIH
    pbmih->cbFix         = sizeof(BITMAPINFOHEADER2);
    pbmih->cx            = cjt.cxDst;
    pbmih->cy            = cjt.cyDst;
    pbmih->cPlanes       = 1;
    pbmih->cBitCount     = cjt.cbPix * 8;
    pbmih->ulCompression = BCA_UNCOMP;
    pbmih->cbImage       = cjt.cbDst;

    // create a memory DC
    hdc = DevOpenDC( 0, OD_MEMORY, "*", 0L, 0, 0);
    if (!hdc) {
        pErr = "DevOpenDC";
        break;
    }

    // create a square PS using the longer side so we can
    // reuse the PS if we have to rotate the bitmap
    sizl.cx = ((pbmih->cx >= pbmih->cy) ? pbmih->cx : pbmih->cy);
    sizl.cy = sizl.cx;

    hps = GpiCreatePS( 0, hdc, &sizl, PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC);
    if (!hps) {
        pErr = "GpiCreatePS";
        break;
    }

    // create a bitmap from the data
    hBmp = GpiCreateBitmap( hps, pbmih, CBM_INIT, cjt.pDst, (BITMAPINFO2*)pbmih);
    if (!hBmp) {
        pErr = "GpiCreateBitmap";
        break;
    }

    // if the bitmap should be rotated, replace the original one
    if (STAT_GETROT(pcr->status)) {
        HBITMAP hBmpRot = RotateBitmap( hps, hBmp, pbmih,
                                        STAT_GETROT(pcr->status));
        if (hBmpRot) {
            GpiDeleteBitmap( hBmp);
            hBmp = hBmpRot;
        }
    }

} while (0);

    if (pErr)
        printf( "CreateThumbnailBmp - %s failed\n", pErr);

    if (hps) {
        GpiSetBitmap( hps, 0);
        GpiDestroyPS( hps);
    }
    if (hdc)
        DevCloseDC( hdc);
    if (pbmih)
        free( pbmih);
    if (cjt.pDst)
        free( cjt.pDst);

    return (hBmp);
}
Ejemplo n.º 17
0
// *******************************************************************************                      
// FUNCTION:     DuplicateBitmap                                                                           
//                                                                                                      
// FUNCTION USE: Duplicates a bitmap                                                                        
//                                                                                                      
// DESCRIPTION:  Uses GpiBitBlt to make a copy of a bitmap by bit-bliting the 
//               contents of the source PS containing the bitmap, to the target 
//               presentation space.
//                                                                                                      
// PARAMETERS:   HBITMAP    source bitmap handle to copy                                              
//                                                                                                      
// RETURNS:      HBITMAP    target bitmap handle                                                                                                                      
//                                                                                                      
// HISTORY:                                                                                             
//                                                                                                      
// *******************************************************************************                      
HBITMAP DuplicateBitmap (HBITMAP hbmSource)                                                    
{                                                                                 
 HAB                hab;
 HBITMAP            hbmTarget;                                                        
 HDC                hdcSource;                                                
 HDC                hdcTarget;
 HPS                hpsSource;                                                
 HPS                hpsTarget;
 SIZEL              sizl;         
 POINTL             aptl[3];                                                       
 BOOL               bError = FALSE;
 BITMAPINFOHEADER2  bmp2;                                                           

 // --------------------------------------------------------------------------                      
 // Get an anchor block handle                                                                     
 // --------------------------------------------------------------------------                      
 hab = WinQueryAnchorBlock(HWND_DESKTOP);
                                                                                   
 // --------------------------------------------------------------------------                       
 // Create memory device context handles and presentation space handles                                                                      
 // --------------------------------------------------------------------------                       
 hdcSource = DevOpenDC (hab, OD_MEMORY, "*", 0L, NULL, NULLHANDLE);                  
 hdcTarget = DevOpenDC (hab, OD_MEMORY, "*", 0L, NULL, NULLHANDLE);                  
                                                                                   
 // --------------------------------------------------------------------------              
 // Set presentation space size                                                            
 // --------------------------------------------------------------------------              
 sizl.cx = 0;                                                         
 sizl.cy = 0;                                                            

 // --------------------------------------------------------------------------            
 // Create our source presentation space                                                           
 // --------------------------------------------------------------------------            
 hpsSource = GpiCreatePS (hab,        
                          hdcSource, 
                          &sizl,                                
                          PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC);                    
                                                                                   
 // --------------------------------------------------------------------------                
 // Create our target presentation space                                                      
 // --------------------------------------------------------------------------                
 hpsTarget = GpiCreatePS (hab, 
                          hdcTarget,                  
                          &sizl,
                          PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC);   
                                                                                   

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

 // --------------------------------------------------------------------------         
 // Set the size of the structure                                                      
 // --------------------------------------------------------------------------         
 bmp2.cbFix = sizeof (BITMAPINFOHEADER2);                                          

 // --------------------------------------------------------------------------        
 // Get the bitmap information header from the source bitmap                                      
 // --------------------------------------------------------------------------        
 GpiQueryBitmapInfoHeader (hbmSource, &bmp2);                                         

 // --------------------------------------------------------------------------          
 // Create our target bitmap using the bitmap information header from                                                   
 // our source bitmap.
 // --------------------------------------------------------------------------          
 hbmTarget = GpiCreateBitmap (hpsTarget, &bmp2, 0L, NULL, NULL);                         
                                                                                   
 // --------------------------------------------------------------------------                                                 
 // If everything is cool, set the bitmaps into our presentation spaces.                
 // --------------------------------------------------------------------------                   
 if (hbmTarget != GPI_ERROR)                     
  {                                                                            
   GpiSetBitmap (hpsSource, hbmSource);                                              
   GpiSetBitmap (hpsTarget, hbmTarget);                                              
                                                                                   
   aptl[0].x = 0;                                                  
   aptl[0].y = 0;
   aptl[1].x = bmp2.cx;                                                         
   aptl[1].y = bmp2.cy;                                                         
   aptl[2].x = 0;                                                        
   aptl[2].y = 0;
                                                                                   
   // --------------------------------------------------------------------------        
   // 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.
   // --------------------------------------------------------------------------        
   bError = GpiBitBlt (hpsTarget,      //  Target presentation space handle                    
                       hpsSource,      //  Source presentation space handle                
                       3L,             //  Number of Points                                
                       aptl,           //  Array of Points                                 
                       ROP_SRCCOPY,    //  Mixing function (source copy)         
                       BBO_IGNORE);    //  Options                                         

   // --------------------------------------------------------------------------                   
   // If we get an error copying from our source PS to our target PS                          
   // set the error flag to TRUE so that we can return GPI_ERROR back                              
   // to the caller.
   // --------------------------------------------------------------------------                   
   if (bError == GPI_ERROR) 
    {
     bError = TRUE;
    }

   // --------------------------------------------------------------------------                
   // If we got a value back from GpiBitBlt reset our error flag since                            
   // bError would be TRUE.
   // --------------------------------------------------------------------------                
   else
    {
     bError = FALSE;
    }
  }                                                                            

 // --------------------------------------------------------------------------            
 // If we get an error creating the bitmap set the bError flag to TRUE      
 // so we can return GPI_ERROR telling the caller that the function failed.
 // --------------------------------------------------------------------------            
 else
  {
   bError = TRUE;
  }

 // --------------------------------------------------------------------------                           
 // Regardless of what happens, we will free all of our graphics engine                            
 // resources by destroying our presentation spaces and device context 
 // handles.
 // --------------------------------------------------------------------------                           
 GpiDestroyPS (hpsSource);                                                           
 GpiDestroyPS (hpsTarget);                                                           
 DevCloseDC (hdcSource);                                                             
 DevCloseDC (hdcTarget);                                                             

 // --------------------------------------------------------------------------              
 // If we get an error trying to duplicate the bitmap, return GPI_ERROR.                   
 // --------------------------------------------------------------------------              
 if (bError) 
  {
   return GPI_ERROR;
  } 

 // --------------------------------------------------------------------------                          
 // If everthing worked like a champ, return the bitmap handle.                                        
 // --------------------------------------------------------------------------                          
 else
  {
   return hbmTarget;                                                                   
  }
}                                                                                 
Ejemplo n.º 18
0
 HBITMAP icqskin_createBackground(HWND hwnd, HBITMAP base)
 {
    SIZEL                sizl    = { 0, 0 };
    DEVOPENSTRUC         dop     = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
    HAB                  hab     = WinQueryAnchorBlock(hwnd);
    HBITMAP              btm     = NO_IMAGE;
    HWND                 owner   = WinQueryWindow(hwnd, QW_OWNER);
    HPS                  hps;
    HDC                  hdc;
    SWP                  swp;
    BITMAPINFOHEADER2    bmih;
    BITMAPINFOHEADER     bmpData;
    RECTL                rcl;
    HBITMAP              img;
    HBITMAP              msk;
    HBITMAP				 bg;
    POINTL               aptlPoints[4];
    POINTL               p;
    int                  f;
    int                  sz;

    WinQueryWindowPos(hwnd, &swp);

    hdc = DevOpenDC(hab, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE);
    hps = GpiCreatePS(hab, hdc, &sizl, PU_PELS | GPIT_MICRO | GPIA_ASSOC);

    /* Make base images */
    GpiQueryBitmapParameters(base, &bmpData);

    memset(&bmih,0, sizeof(BITMAPINFOHEADER2));
    bmih.cbFix        = sizeof(bmih);
    bmih.cx           = bmpData.cx;
    bmih.cy           = bmpData.cy;
    bmih.cPlanes      = 1;
    bmih.cBitCount    = 1;
    msk               = GpiCreateBitmap(hps, &bmih, 0L, NULL, NULL);

    GpiSetBitmap(hps,msk);

    aptlPoints[0].x=0;
    aptlPoints[0].y=0;
    aptlPoints[1].x=aptlPoints[0].x+bmpData.cx-1;
    aptlPoints[1].y=aptlPoints[0].y+bmpData.cy-1;
    aptlPoints[2].x=0;
    aptlPoints[2].y=0;
    aptlPoints[3].x=aptlPoints[2].x+bmpData.cx;
    aptlPoints[3].y=aptlPoints[2].y+bmpData.cy;

    GpiSetColor(hps,CLR_WHITE);
    GpiSetBackColor(hps,CLR_PINK);
    GpiWCBitBlt(hps,base,4,aptlPoints,ROP_NOTSRCCOPY,BBO_IGNORE);

    /* Create base image */

    bmih.cbFix        = sizeof(bmih);
    bmih.cx           = bmpData.cx;
    bmih.cy           = bmpData.cy;
    bmih.cPlanes      = 1;
    bmih.cBitCount    = 24;
    img               = GpiCreateBitmap(  hps, &bmih, 0L, NULL, NULL);

    GpiSetBitmap(hps,img);
    GpiSetColor(hps,CLR_WHITE);
    GpiSetBackColor(hps,CLR_BLACK);

    GpiWCBitBlt( hps,msk,4,aptlPoints,ROP_NOTSRCCOPY,BBO_IGNORE);
    GpiWCBitBlt( hps,base,4,aptlPoints,ROP_SRCAND,BBO_IGNORE);

    /* Draw background */

    memset(&bmih,0, sizeof(BITMAPINFOHEADER2));
    bmih.cbFix        = sizeof(bmih);
    bmih.cx           = swp.cx;
    bmih.cy           = swp.cy;
    bmih.cPlanes      = 1;
    bmih.cBitCount    = 24;

    btm = GpiCreateBitmap(hps,&bmih,0L,NULL,NULL);
    GpiSetBitmap(hps, btm);

    // Ask owner window to draw the background
    icqskin_loadPallete(hps, 0, (const ULONG *) WinSendMsg(hwnd,WMICQ_QUERYPALLETE,0,0));

    rcl.xLeft   =
    rcl.yBottom = 0;
    rcl.xRight  = swp.cx;
    rcl.yTop    = swp.cy;

    bg = icqskin_queryBackground(owner);

    if(!bg || bg == NO_IMAGE)
    {
       WinFillRect(hps, &rcl, ICQCLR_BACKGROUND);
    }
    else
    {
       WinMapWindowPoints(hwnd, owner, (POINTL *) &rcl, 2);
       p.x = p.y = 0;
       WinDrawBitmap(hps, bg, &rcl, &p, CLR_WHITE, CLR_BLACK, DBM_NORMAL);
    }

    GpiSetColor(hps,CLR_WHITE);
    GpiSetBackColor(hps,CLR_BLACK);

    if(swp.cx > bmpData.cx)
    {
       sz = bmpData.cx / 3;
       for(f=sz;f<(swp.cx-(sz*2));f += sz)
          drawTransparent(hps, img, msk, f, 0, sz, bmpData.cy, sz, 0);
       drawTransparent(hps, img, msk, swp.cx-(sz*2), 0, sz, bmpData.cy, sz, 0);
       drawTransparent(hps, img, msk, 0, 0, sz, bmpData.cy, 0, 0);
       drawTransparent(hps, img, msk, swp.cx-sz, 0, sz, bmpData.cy, bmpData.cx-sz, 0);
    }
    else
    {
       sz = swp.cx / 2;
       drawTransparent(hps, img, msk, 0, 0, sz, bmpData.cy, 0, 0);
       drawTransparent(hps, img, msk, sz, 0, sz, bmpData.cy, bmpData.cx-sz, 0);
    }

    // Release resources
    GpiSetBitmap(hps, NULLHANDLE);
    GpiDeleteBitmap(img);
    GpiDeleteBitmap(msk);
    GpiDestroyPS(hps);
    DevCloseDC(hdc);

    return btm;
 }
Ejemplo n.º 19
0
/****************************************************************\
 *  Name: ClkSize()
 *
 *  Purpose:When the window has been sized, we calculate  a page
 *	    rectangle which: (a) fills the window rectangle in either
 *	    the x or y dimension, (b) appears square, and (c) is centered
 *	    in the window rectangle
\****************************************************************/
VOID ClkSize (HWND hwnd)
{
    RECTL rclWindow;
    SIZEF sizef;
    LONG cxSquare, cySquare, cxEdge, cyEdge;
    LONG cyHeight;
    LONG cxWidth;
    HBITMAP hbm;
    BITMAPINFOHEADER bmp;

    /*
     * First get rid of any buffer bitmap already there.
     */
    hbm = GpiSetBitmap (hpsBuffer, NULLHANDLE);

    if (hbm != NULLHANDLE)
	GpiDeleteBitmap (hbm);

    /*
     * Get the width and height of the window rectangle.
     */
    WinQueryWindowRect (hwnd, &rclWindow);
    cxWidth = rclWindow.xRight - rclWindow.xLeft - 2;
    cyHeight = rclWindow.yTop - rclWindow.yBottom - 2;

    /*
     * Now create a bitmap the size of the window.
     */
    bmp.cbFix = sizeof(BITMAPINFOHEADER);
    bmp.cx = (SHORT)cxWidth;
    bmp.cy = (SHORT)cyHeight;
    bmp.cPlanes = (SHORT)cColorPlanes;
    bmp.cBitCount = (SHORT)cColorBitcount;
    hbm = GpiCreateBitmap(hpsBuffer, (PBITMAPINFOHEADER2)&bmp,
			  0x0000, (PBYTE)NULL, (PBITMAPINFO2)NULL);
    GpiSetBitmap (hpsBuffer, hbm);

    /*
     * Assume the size of the page rectangle is constrained in the y
     * dimension,compute the x size which would make the rectangle appear
     * square, then check the assumption and do the reverse calculation
     * if necessary.
     */
    cySquare = cyHeight - 2;
    cxSquare = ( cyHeight * cxRes ) / cyRes;

    if (cxWidth < cxSquare)
    {
	cxSquare = cxWidth - 2;
	cySquare = (cxWidth * cyRes) / cxRes;
    }

    /*
     * Fill in the page rectangle and set the page viewport.
     */
    RECTL rclPage;  // clkdata.c war global!! aber warum?

    cxEdge = (cxWidth - cxSquare ) / 2;
    cyEdge = (cyHeight - cySquare ) / 2;
    rclPage.xLeft = cxEdge;
    rclPage.xRight = cxWidth - cxEdge;
    rclPage.yBottom = cyEdge;
    rclPage.yTop = cyHeight - cyEdge;


    f = GpiSetPageViewport (hps, &rclPage);
    f = GpiSetPageViewport (hpsBuffer, &rclPage);

    fBufferDirty = TRUE;
}
Ejemplo n.º 20
0
/*!
    Creates a \c HBITMAP equivalent to the QPixmap. Returns the \c HBITMAP
    handle.

    If \a mask is not NULL, the mask mode is turned on. In this mode, the bitmap
    mask is also created from the QPixmap's mask and returned in the given
    variable. This bitmap mask will contain two vertically adjacent sections,
    the first of which is the AND mask and the second one is the XOR mask
    (according to WinCreatePointer() specification). Also, in mask mode, the
    HBITMAP returned for the pixmap itself will be prepared for masking (with
    transparent pixels made black). This mode is useful for creating system
    icons and pointers (\sa toPmHPOINTER()).

    if \a embedRealAlpha is \c true, the real alpha chennel (not the 1bpp mask)
    will be embedded in the high 8 bits of the 32-bit pixel value for each pixel
    in the created bitmap (which always has 1 plane and the 32-bit depth). This
    extra information isn't touched by PM/GPI but may be used by custom drawing
    routines to do real alpha blending.

    Note that if \a mask is not NULL but the pixmap does neither have a mask nor
    the alpha channel, an emptpy bitmap mask with no transparency (zeroed AND
    and XOR parts) will be created and returned.

    It is the caller's responsibility to free both returned \c HBITMAP handes
    after use.

    \warning This function is only available on OS/2.

    \sa fromPmHBITMAP(), toPmHPOINTER()
*/
HBITMAP QPixmap::toPmHBITMAP(HBITMAP *mask, bool embedRealAlpha) const
{
    if (data->classId() != QPixmapData::RasterClass) {
        QPixmapData *data = new QRasterPixmapData(depth() == 1 ?
                                                  QPixmapData::BitmapType :
                                                  QPixmapData::PixmapType);
        data->fromImage(toImage(), Qt::AutoColor);
        return QPixmap(data).toPmHBITMAP(mask, embedRealAlpha);
    }

    QRasterPixmapData* d = static_cast<QRasterPixmapData*>(data.data());
    int w = d->image.width();
    int h = d->image.height();

    HPS hps = qt_alloc_mem_ps(w, h * 2);
    if (hps == NULLHANDLE)
        return NULLHANDLE;

    HBITMAP hbm = NULLHANDLE;
    HBITMAP hbmMask = NULLHANDLE;

    // Note that we always use ARGB32 even if embedRealAlpha is false because
    // in this case we will use the alpha channel to dither the 1bpp mask
    QImage image = d->image.convertToFormat(QImage::Format_ARGB32);
    // flip the bitmap top to bottom for PM
    image = image.mirrored();

    // bitmap header + 2 palette entries (for the mask)
    char bmi[sizeof(BITMAPINFOHEADER2) + 4 * 2];
    memset(bmi, 0, sizeof(bmi));
    PBITMAPINFOHEADER2 bmh = (PBITMAPINFOHEADER2)bmi;
    bmh->cbFix = sizeof(BITMAPINFOHEADER2);
    PULONG pal = (PULONG)(bmi + sizeof(BITMAPINFOHEADER2));

    // create the normal bitmap from the pixmap data
    bmh->cx = w;
    bmh->cy = h;
    bmh->cPlanes = 1;
    bmh->cBitCount = 32;
    hbm = GpiCreateBitmap(hps, bmh, CBM_INIT, (PBYTE)(const uchar *)image.bits(),
                          (PBITMAPINFO2)&bmi);

    if (mask) {
        // get the mask
        QImage mask;
        if (hasAlpha()) {
            if (!embedRealAlpha) {
                // We prefer QImage::createAlphaMask() over QPixmap::mask()
                // since the former will dither while the latter will convert any
                // non-zero alpha value to an opaque pixel
                mask = image.createAlphaMask().convertToFormat(QImage::Format_Mono);

                // note: for some strange reason, createAlphaMask() (as opposed to
                // mask().toImage()) returns an image already flipped top to bottom,
                // so take it into account

                // create the AND mask
                mask.invertPixels();
                // add the XOR mask (and leave it zeroed)
                mask = mask.copy(0, -h, w, h * 2);
            } else {
                // if we embedded real alpha, we still need a mask if we are going
                // to create a pointer out of this pixmap (WinCreatePointerIndirect()
                // requirement), but we will use QPixmap::mask() because it won't be
                // able to destroy the alpha channel of non-fully transparent pixels
                // when preparing the color bitmap for masking later. We could also
                // skip this prepare step, but well, let's go this way, it won't hurt.
                mask = this->mask().toImage().convertToFormat(QImage::Format_Mono);

                // create the AND mask
                mask.invertPixels();
                // add the XOR mask (and leave it zeroed)
                mask = mask.copy(0, 0, w, h * 2);
                // flip the bitmap top to bottom for PM
                mask = mask.mirrored(false, true);
            }
        } else {
            mask = QImage(w, h * 2, QImage::Format_Mono);
            mask.fill(0);
        }

        // create the mask bitmap
        bmh->cbFix = sizeof(BITMAPINFOHEADER2);
        bmh->cx = w;
        bmh->cy = h * 2;
        bmh->cPlanes = 1;
        bmh->cBitCount = 1;
        bmh->cclrUsed = 2;
        pal[0] = 0;
        pal[1] = 0x00FFFFFF;
        hbmMask = GpiCreateBitmap(hps, bmh, CBM_INIT,
                                  (PBYTE)(const uchar *)mask.bits(),
                                  (PBITMAPINFO2)&bmi);

        // prepare the bitmap for masking by setting transparent pixels to black
        GpiSetBitmap(hps, hbm);

        POINTL ptls[] = {
            { 0, 0 }, { w - 1, h - 1 },     // dst: inclusive-inclusive
            { 0, h }, { w, h * 2 },         // src: inclusive-exclusive
        };
        ptls[0].y -= h;
        ptls[1].y -= h;
        enum { AllImageAttrs = IBB_COLOR | IBB_BACK_COLOR |
                               IBB_MIX_MODE | IBB_BACK_MIX_MODE };
        IMAGEBUNDLE ib = { CLR_TRUE, CLR_FALSE, FM_OVERPAINT, BM_OVERPAINT };
        GpiSetAttrs(hps, PRIM_IMAGE, AllImageAttrs, 0, (PBUNDLE)&ib);
        GpiDrawBits(hps, (PBYTE)(const uchar *)mask.bits(), (PBITMAPINFO2)&bmi,
                    4, ptls, ROP_SRCAND, BBO_IGNORE);
    }

    qt_free_mem_ps(hps);

    if (mask)
        *mask = hbmMask;

    return hbm;
}
Ejemplo n.º 21
0
 HBITMAP icqskin_createFrameBackground(HWND hwnd, HBITMAP bg, short cx, short cy, HBITMAP *img, HBITMAP *msk)
 {
#ifndef SKINNED_GUI
    return NO_IMAGE;
#else
    SIZEL                sizl    = { 0, 0 };
    DEVOPENSTRUC         dop     = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
    HAB                  hab     = WinQueryAnchorBlock(hwnd);
    HPS                  hps;
    HDC                  hdc;
    BITMAPINFOHEADER     bmpData;
    BITMAPINFOHEADER2    bmih;
    RECTL                rcl;
    int					 x;
    int                  y;
    int                  f;

    icqskin_deleteImage(bg);


    for(f=0;f<ICQFRAME_SKINBITMAPS && img[f] == NO_IMAGE;f++);

    if(f >= ICQFRAME_SKINBITMAPS)
       return NO_IMAGE;

    hdc = DevOpenDC(hab, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE);
    hps = GpiCreatePS(hab, hdc, &sizl, PU_PELS | GPIT_MICRO | GPIA_ASSOC);

    bmih.cbFix        = sizeof(bmih);
    bmih.cx           = cx;
    bmih.cy           = cy;
    bmih.cPlanes      = 1;
    bmih.cBitCount    = 24;
    bg                = GpiCreateBitmap(hps, &bmih, 0L, NULL, NULL);

    GpiSetBitmap(hps,bg);

    /* Clear background */
    rcl.xLeft   =
    rcl.yBottom = 0;
    rcl.xRight  = cx;

    rcl.yTop    = cy;

    DBGTrace(cx);
    DBGTrace(cy);

    icqskin_paintBackground(hwnd,hps,&rcl);

    GpiSelectPalette(hps,NULLHANDLE);
    GpiSetColor(hps,CLR_WHITE);
    GpiSetBackColor(hps,CLR_BLACK);

    /* Stretch images */
    y = cy;

    if(img[ICQFRAME_MIDSTRETCH] != NO_IMAGE)
    {
       if(img[ICQFRAME_TITLESTRETCH] != NO_IMAGE)
       {
          GpiQueryBitmapParameters(img[ICQFRAME_TITLESTRETCH], &bmpData);
          y -= bmpData.cy;
       }

       if(img[ICQFRAME_MIDLEFT] == NO_IMAGE)
       {
          x = 0;
       }
       else
       {
          GpiQueryBitmapParameters(img[ICQFRAME_MIDLEFT], &bmpData);
          x = bmpData.cx;
       }

       GpiQueryBitmapParameters(img[ICQFRAME_MIDSTRETCH], &bmpData);
       y -= bmpData.cy;

       do
       {
          for(f=x;f<cx;f+=bmpData.cx)
             drawFrameBG(img,msk, ICQFRAME_MIDSTRETCH, hps, f, y, bmpData.cx, bmpData.cy);
          y -= bmpData.cy;
       } while(y > 0);

    }

    if(img[ICQFRAME_TITLESTRETCH] != NO_IMAGE)
    {
       GpiQueryBitmapParameters(img[ICQFRAME_TITLESTRETCH], &bmpData);
       y = cy-bmpData.cy;
       for(x=0; x<cx; x += bmpData.cx)
          drawFrameBG(img,msk, ICQFRAME_TITLESTRETCH, hps, x, y, bmpData.cx, bmpData.cy);
    }

    if(img[ICQFRAME_MIDLEFT] != NO_IMAGE)
    {
       GpiQueryBitmapParameters(img[ICQFRAME_MIDLEFT], &bmpData);
       drawFrameBG(img,msk, ICQFRAME_MIDLEFT, hps, 0, 0, bmpData.cx, bmpData.cy);
    }

    if(img[ICQFRAME_MIDRIGHT] != NO_IMAGE)
    {
       GpiQueryBitmapParameters(img[ICQFRAME_MIDRIGHT], &bmpData);
       drawFrameBG(img,msk, ICQFRAME_MIDRIGHT, hps, cx-bmpData.cx, 0, bmpData.cx, bmpData.cy);
    }

    y = cy;
    if(img[ICQFRAME_TITLELEFT] != NO_IMAGE)
    {
       GpiQueryBitmapParameters(img[ICQFRAME_TITLELEFT], &bmpData);
       y -= bmpData.cy;
       drawFrameBG(img,msk, ICQFRAME_TITLELEFT, hps, 0, y, bmpData.cx, bmpData.cy);
    }

    if(img[ICQFRAME_TOPLEFT] != NO_IMAGE)
    {
       GpiQueryBitmapParameters(img[ICQFRAME_TOPLEFT], &bmpData);
       y -= bmpData.cy;
       drawFrameBG(img,msk, ICQFRAME_TOPLEFT, hps, 0, y, bmpData.cx, bmpData.cy);
    }


    if(img[ICQFRAME_MIDLEFT] != NO_IMAGE)
    {
       GpiQueryBitmapParameters(img[ICQFRAME_MIDLEFT], &bmpData);
       while(y > 0)
       {
          y -= bmpData.cy;
          drawFrameBG(img,msk, ICQFRAME_MIDLEFT, hps, 0, y, bmpData.cx, bmpData.cy);
       }
    }

    // Right images
    y = cy;

    if(img[ICQFRAME_TITLERIGHT] != NO_IMAGE)
    {
       GpiQueryBitmapParameters(img[ICQFRAME_TITLERIGHT], &bmpData);
       y -= bmpData.cy;
       drawFrameBG(img,msk, ICQFRAME_TITLERIGHT, hps, cx-bmpData.cx, y, bmpData.cx, bmpData.cy);
    }

    if(img[ICQFRAME_TOPRIGHT] != NO_IMAGE)
    {
       GpiQueryBitmapParameters(img[ICQFRAME_TOPRIGHT], &bmpData);
       y -= bmpData.cy;
       drawFrameBG(img,msk, ICQFRAME_TOPRIGHT, hps, cx-bmpData.cx, y, bmpData.cx, bmpData.cy);
    }

    if(img[ICQFRAME_MIDRIGHT] != NO_IMAGE)
    {
       GpiQueryBitmapParameters(img[ICQFRAME_MIDRIGHT], &bmpData);
       x = cx-bmpData.cx;
       while(y > 0)
       {
          y -= bmpData.cy;
          drawFrameBG(img,msk, ICQFRAME_MIDRIGHT, hps, x, y, bmpData.cx, bmpData.cy);
       }
    }

    // Bottom images
    if(img[ICQFRAME_BOTTOMSTRETCH] != NO_IMAGE)
    {
       GpiQueryBitmapParameters(img[ICQFRAME_BOTTOMSTRETCH], &bmpData);
       for(x=0; x<cx; x += bmpData.cx)
          drawFrameBG(img,msk, ICQFRAME_BOTTOMSTRETCH, hps, x, 0, bmpData.cx, bmpData.cy);

    }

    x = 0;
    if(img[ICQFRAME_BOTTOMLEFT] != NO_IMAGE)
    {
       GpiQueryBitmapParameters(img[ICQFRAME_BOTTOMLEFT], &bmpData);
       x += bmpData.cx;
       drawFrameBG(img,msk, ICQFRAME_BOTTOMLEFT, hps, 0, 0, bmpData.cx, bmpData.cy);
    }

    if(img[ICQFRAME_BOTTOMMIDLEFT] != NO_IMAGE)
    {
       GpiQueryBitmapParameters(img[ICQFRAME_BOTTOMMIDLEFT], &bmpData);
       drawFrameBG(img,msk, ICQFRAME_BOTTOMMIDLEFT, hps, x, 0, bmpData.cx, bmpData.cy);
    }

    x = cx;
    if(img[ICQFRAME_BOTTOMRIGHT] != NO_IMAGE)
    {
       GpiQueryBitmapParameters(img[ICQFRAME_BOTTOMRIGHT], &bmpData);
       x -= bmpData.cx;
       drawFrameBG(img,msk, ICQFRAME_BOTTOMRIGHT, hps, x, 0, bmpData.cx, bmpData.cy);
    }

    if(img[ICQFRAME_BOTTOMMIDRIGHT] != NO_IMAGE)
    {
       GpiQueryBitmapParameters(img[ICQFRAME_BOTTOMMIDRIGHT], &bmpData);
       x -= bmpData.cx;
       drawFrameBG(img,msk, ICQFRAME_BOTTOMMIDRIGHT, hps, x, 0, bmpData.cx, bmpData.cy);
    }

    /* Release image */
    GpiSetBitmap(hps, NULLHANDLE);
    GpiDestroyPS(hps);
    DevCloseDC(hdc);

    return bg;
#endif
 }
/****************************************************************\
 *
 *--------------------------------------------------------------
 *
 *  Name: ClkSize()
 *
 *  Purpose:When the window has been sized, we calculate  a page
 *          rectangle which: (a) fills the window rectangle in either
 *          the x or y dimension, (b) appears square, and (c) is centered
 *          in the window rectangle
 *  Usage:
 *
 *  Method:
 *          -
 *
 *          -
 *          -
 *
 *          -
 *          -
 *
 *  Returns:
 *
 *
\****************************************************************/
VOID ClkSize (HWND hwnd)
{
    RECTL rclWindow;
    SIZEF sizef;
    LONG cxSquare, cySquare, cxEdge, cyEdge;
    LONG cyHeight;
    LONG cxWidth;
    HBITMAP hbm;
    BITMAPINFOHEADER bmp;

    /*
     * First get rid of any buffer bitmap already there.
     */
    hbm = GpiSetBitmap (hpsBuffer, NULLHANDLE);

    if (hbm != NULLHANDLE)
        GpiDeleteBitmap (hbm);

    /*
     * Get the width and height of the window rectangle.
     */
    WinQueryWindowRect (hwnd, &rclWindow);
    cxWidth = rclWindow.xRight - rclWindow.xLeft - 2;
    cyHeight = rclWindow.yTop - rclWindow.yBottom - 2;

    /*
     * Now create a bitmap the size of the window.
     */
    bmp.cbFix = sizeof(BITMAPINFOHEADER);
    bmp.cx = (SHORT)cxWidth;
    bmp.cy = (SHORT)cyHeight;
    bmp.cPlanes = (SHORT)cColorPlanes;
    bmp.cBitCount = (SHORT)cColorBitcount;
    hbm = GpiCreateBitmap(hpsBuffer, (PBITMAPINFOHEADER2)&bmp,
                          0x0000, (PBYTE)NULL, (PBITMAPINFO2)NULL);
    GpiSetBitmap (hpsBuffer, hbm);

    /*
     * Assume the size of the page rectangle is constrained in the y
     * dimension,compute the x size which would make the rectangle appear
     * square, then check the assumption and do the reverse calculation
     * if necessary.
     */
    cySquare = cyHeight - 2;
    cxSquare = ( cyHeight * cxRes ) / cyRes;

    if (cxWidth < cxSquare)
    {
        cxSquare = cxWidth - 2;
        cySquare = (cxWidth * cyRes) / cxRes;
    }

    /*
     * Fill in the page rectangle and set the page viewport.
     */
    cxEdge = (cxWidth - cxSquare ) / 2;
    cyEdge = (cyHeight - cySquare ) / 2;
    rclPage.xLeft = cxEdge;
    rclPage.xRight = cxWidth - cxEdge;
    rclPage.yBottom = cyEdge;
    rclPage.yTop = cyHeight - cyEdge;

    /*
     * Determine where to put the date. If we have room under the clock, we
     * put it there. If we have more room on the left we put it there. If we
     * have more room in the midlle, it goes there.
     */
    if (cp.usDispMode & DM_DATE)
    {
        vclrDate[SURFACE] = vclrBG[SHADE];
        vclrDate[LIGHT] = vclrBG[LIGHT];
        vclrDate[SHADE] = vclrBG[SHADE];
        vclrDate[BACKGROUND] = vclrBG[SURFACE];
        if (cyHeight > (cySquare*6/5)) { /*Goes under*/
            vmatlfDateTrans.lM31 = (LONG)15;            /*Horizontal*/
            vmatlfDateTrans.lM32 = -(LONG)17;    /*vertical*/
            vmatlfDateScale.fxM11 = MAKEFIXED(2,0x8000);
            vmatlfDateScale.fxM22 = MAKEFIXED(2,0x8000);
            rclPage. yTop += cyEdge;
            rclPage. yBottom += cyEdge;
            vusDatePos = DP_UNDER;
        }
        else
        {
            if (cxWidth > (cxSquare * 31/10 ))
            {
                vmatlfDateTrans.lM31 = -(LONG)53 ;            /*Horizontal*/
                vmatlfDateTrans.lM32 = (LONG)04;    /*vertical*/
                vmatlfDateScale.fxM11 = MAKEFIXED(7,0xe000);
                vmatlfDateScale.fxM22 = MAKEFIXED(7,0xe000);
                rclPage.xRight += cxEdge;
                rclPage.xLeft += cxEdge;
                vusDatePos = DP_LEFTMIDDLE;

            }
            else
            {
                if (cxWidth > (cxSquare * 2)) { /*Goes on the left*/
                    vmatlfDateTrans.lM31 = -(LONG)52 ;            /*Horizontal*/
                    vmatlfDateTrans.lM32 = (LONG)2;    /*vertical*/
                    vmatlfDateScale.fxM11 = MAKEFIXED(3,0xd000);
                    vmatlfDateScale.fxM22 = MAKEFIXED(3,0xd000);
                    rclPage.xRight += cxEdge;
                    rclPage.xLeft += cxEdge;
                    vusDatePos = DP_LEFTDOWN  ;

                }
                else
                {   /*Goes inside*/
                    vmatlfDateTrans.lM31 = (LONG)24 ;            /*Horizontal*/
                    vmatlfDateTrans.lM32 = (LONG)23;    /*vertical*/
                    vmatlfDateScale.fxM11 = MAKEFIXED(2,0);
                    vmatlfDateScale.fxM22 = MAKEFIXED(2,0);
                    vclrDate[SURFACE] = vclrFace[SHADE] ;
                    vclrDate[LIGHT] = vclrFace[LIGHT] ;
                    vclrDate[SHADE] = vclrFace[SHADE];
                    vclrDate[BACKGROUND] = vclrFace[SURFACE];
                    vusDatePos = DP_INSIDE;
                }
            }
        }
    }

    f = GpiSetPageViewport (hps, &rclPage);
    f = GpiSetPageViewport (hpsBuffer, &rclPage);

    /*
     * Are we iconic?
     */
    f = WinQueryWindowPos (hwndFrame, &swp);
    fIconic = (BOOL)(swp.fl & SWP_MINIMIZE );
    fShowSecondHand = (BOOL) !(fIconic);

    GpiQueryCharBox(hpsBuffer, &sizef);
    GpiSetCharBox(hpsBuffer, &sizef);

    fBufferDirty = TRUE;
}
BOOL CandyBarZFrameBorderPaintProc(HWND hwnd, RECTL * rect, HPS hpsFrame, short sState)
{
    CBZDATA     *pCBZData;
    CBZSHARE    *pCBZShare;
    PSPAINT     *pPaint;
    TEMPPAINT   *pFramePaint;
    BOOL        rc;
    int         i;
    ULONG       ulDataOffset;

    if (DosGetNamedSharedMem((PPVOID) & pCBZShare, CBZ_SHARE,  PAG_READ) != NO_ERROR)
    {
        return (FALSE);
    }
    ulDataOffset = pCBZShare->ulDataOffset;
    DosFreeMem(pCBZShare);

    // get window data
    if ((pCBZData = WinQueryWindowPtr(CandyBarZGetTopLevelFrameHWND(hwnd), ulDataOffset)) == NULL
            || !pCBZData->bFrameBorderEnabled  )
    {
        return (FALSE);
    }

    if (pCBZData->sFrameBorderIndex >= pCBZData->sPushButtonIndex)
    {
        return (FALSE);
    }

    // alloc paint struct
    if (DosAllocMem((PPVOID) & pFramePaint,
                    sizeof(TEMPPAINT),
                    PAG_READ | PAG_WRITE | PAG_COMMIT) != NO_ERROR)
    {
        return (FALSE);
    }
    memset(pFramePaint, 0, sizeof(TEMPPAINT));

    pFramePaint->hab = WinQueryAnchorBlock(hwnd);

    // alloc paint struct
    if (DosAllocMem((PPVOID) & pPaint,
                    sizeof(PSPAINT),
                    PAG_READ | PAG_WRITE | PAG_COMMIT) != NO_ERROR)
    {
        DosFreeMem(pFramePaint);
        return (FALSE);
    }
    memset(pPaint, 0, sizeof(PSPAINT));

    //Text plugin needs this for quering presentation parameters.
    pPaint->hwnd = hwnd;

    // entire window
    pPaint->rectlWindow = pPaint->rectlUpdate = *rect;

    // get PS
    pPaint->hpsWin = hpsFrame;

    // we will blt and draw gradient text into the hps associated with this dc
    if ((pFramePaint->hdc = DevOpenDC(pFramePaint->hab, OD_MEMORY, "*", 0L, (PDEVOPENDATA) NULL, NULLHANDLE))
            == NULLHANDLE)
    {
        DosFreeMem(pPaint);
        DosFreeMem(pFramePaint);
        return (FALSE);
    }
    // create hps2 for hdc2.  hps for hdc depends on size of bitmap, so it's not created until
    // we know if it's active or not.  create for size of window, then we blt only portion
    // needed
    pFramePaint->slHPS.cx = pPaint->rectlWindow.xRight;
    pFramePaint->slHPS.cy = pPaint->rectlWindow.yTop;

    if ((pPaint->hps = GpiCreatePS(pFramePaint->hab,
                                   pFramePaint->hdc,
                                   &(pFramePaint->slHPS),
                          PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC))
            == NULLHANDLE)
    {
        DevCloseDC(pFramePaint->hdc);
        DosFreeMem(pPaint);
        DosFreeMem(pFramePaint);
        return (FALSE);
    }

    pFramePaint->bif2.cbFix = sizeof(BITMAPINFOHEADER2);
    pFramePaint->bif2.cx = pPaint->rectlWindow.xRight;
    pFramePaint->bif2.cy = pPaint->rectlWindow.yTop;
    pFramePaint->bif2.cBitCount = 24;
    pFramePaint->bif2.cPlanes = 1;
    if ((pFramePaint->hbmTemp = GpiCreateBitmap(pPaint->hps,  // create bitmap
                                 (PBITMAPINFOHEADER2) & (pFramePaint->bif2),
                                                (ULONG) 0,
                                                (PSZ) NULL,
                       (PBITMAPINFO2) & (pFramePaint->bif2))) == NULLHANDLE)
    {
        GpiDestroyPS(pPaint->hps);
        DevCloseDC(pFramePaint->hdc);
        DosFreeMem(pPaint);
        DosFreeMem(pFramePaint);
        return (FALSE);
    }
    if (GpiSetBitmap(pPaint->hps, pFramePaint->hbmTemp) == HBM_ERROR)
    {
        GpiDeleteBitmap(pFramePaint->hbmTemp);
        GpiDestroyPS(pPaint->hps);
        DevCloseDC(pFramePaint->hdc);
        DosFreeMem(pPaint);
        DosFreeMem(pFramePaint);
        return (FALSE);
    }

    // set color table into rgb mode.  otherwise colors between 0 and
    // 15 are interpreted as indexes
    GpiCreateLogColorTable(pPaint->hps, 0, LCOLF_RGB, 0, 0, NULL);

    {
        //fill ps with default bg color...
        ULONG attrFound;
        long lColor;
        if ( (WinQueryPresParam(hwnd, PP_BACKGROUNDCOLOR, 0, &attrFound, sizeof(attrFound),
                                                &lColor, QPF_PURERGBCOLOR)) == 0 )
           lColor = WinQuerySysColor(HWND_DESKTOP, SYSCLR_DIALOGBACKGROUND, 0);
        // fill with default color
        WinFillRect(pPaint->hps, &(pPaint->rectlUpdate), lColor);
    }

    // call Plugins Paint Procedures here
    for (i = pCBZData->sFrameBorderIndex; i < pCBZData->sPushButtonIndex; i++)
    {
        if ( !(pCBZData->Plugins[i].pfnPluginRender(pPaint, pCBZData->Plugins[i].pData, sState)) )
        {
            GpiSetBitmap(pPaint->hps, NULLHANDLE);
            GpiDeleteBitmap(pFramePaint->hbmTemp);
            GpiDestroyPS(pPaint->hps);
            DevCloseDC(pFramePaint->hdc);
            DosFreeMem(pPaint);
            DosFreeMem(pFramePaint);
            return (FALSE);
        }
    }


    if ((rc = BltToWindow(pPaint)) == TRUE)
    {
        //paint sucessful, validate the window
//        WinQueryWindowRect(hwnd, &(pPaint->rectlUpdate));
        WinValidateRect(hwnd, &(pPaint->rectlUpdate), FALSE);
    }
    GpiSetBitmap(pPaint->hps, NULLHANDLE);
    GpiDeleteBitmap(pFramePaint->hbmTemp);
    GpiDestroyPS(pPaint->hps);
    DevCloseDC(pFramePaint->hdc);
    DosFreeMem(pPaint);
    DosFreeMem(pFramePaint);

    return (rc);
}
Ejemplo n.º 24
0
static void
_cairo_os2_surface_get_pixels_from_screen (cairo_os2_surface_t *surface,
                                           HPS                  hps_begin_paint,
                                           PRECTL               prcl_begin_paint_rect)
{
    HPS hps;
    HDC hdc;
    SIZEL sizlTemp;
    HBITMAP hbmpTemp;
    BITMAPINFO2 bmi2Temp;
    POINTL aptlPoints[4];
    int y;
    unsigned char *pchTemp;

    /* To copy pixels from screen to our buffer, we do the following steps:
     *
     * - Blit pixels from screen to a HBITMAP:
     *   -- Create Memory Device Context
     *   -- Create a PS into it
     *   -- Create a HBITMAP
     *   -- Select HBITMAP into memory PS
     *   -- Blit dirty pixels from screen to HBITMAP
     * - Copy HBITMAP lines (pixels) into our buffer
     * - Free resources
     */

    /* Create a memory device context */
    hdc = DevOpenDC (0, OD_MEMORY,"*",0L, NULL, NULLHANDLE);
    if (!hdc) {
        return;
    }

    /* Create a memory PS */
    sizlTemp.cx = prcl_begin_paint_rect->xRight - prcl_begin_paint_rect->xLeft;
    sizlTemp.cy = prcl_begin_paint_rect->yTop - prcl_begin_paint_rect->yBottom;
    hps = GpiCreatePS (0,
                       hdc,
                       &sizlTemp,
                       PU_PELS | GPIT_NORMAL | GPIA_ASSOC);
    if (!hps) {
        DevCloseDC (hdc);
        return;
    }

    /* Create an uninitialized bitmap. */
    /* Prepare BITMAPINFO2 structure for our buffer */
    memset (&bmi2Temp, 0, sizeof (bmi2Temp));
    bmi2Temp.cbFix = sizeof (BITMAPINFOHEADER2);
    bmi2Temp.cx = sizlTemp.cx;
    bmi2Temp.cy = sizlTemp.cy;
    bmi2Temp.cPlanes = 1;
    bmi2Temp.cBitCount = 32;

    hbmpTemp = GpiCreateBitmap (hps,
                                (PBITMAPINFOHEADER2) &bmi2Temp,
                                0,
                                NULL,
                                NULL);

    if (!hbmpTemp) {
        GpiDestroyPS (hps);
        DevCloseDC (hdc);
        return;
    }

    /* Select the bitmap into the memory device context. */
    GpiSetBitmap (hps, hbmpTemp);

    /* Target coordinates (Noninclusive) */
    aptlPoints[0].x = 0;
    aptlPoints[0].y = 0;

    aptlPoints[1].x = sizlTemp.cx;
    aptlPoints[1].y = sizlTemp.cy;

    /* Source coordinates (Inclusive) */
    aptlPoints[2].x = prcl_begin_paint_rect->xLeft;
    aptlPoints[2].y = surface->bitmap_info.cy - prcl_begin_paint_rect->yBottom;

    aptlPoints[3].x = prcl_begin_paint_rect->xRight;
    aptlPoints[3].y = surface->bitmap_info.cy - prcl_begin_paint_rect->yTop;

    /* Blit pixels from screen to bitmap */
    GpiBitBlt (hps,
               hps_begin_paint,
               4,
               aptlPoints,
               ROP_SRCCOPY,
               BBO_IGNORE);

    /* Now we have to extract the pixels from the bitmap. */
    pchTemp =
        surface->pixels +
        (prcl_begin_paint_rect->yBottom)*surface->bitmap_info.cx*4 +
        prcl_begin_paint_rect->xLeft*4;
    for (y = 0; y < sizlTemp.cy; y++) {
        /* Get one line of pixels */
        GpiQueryBitmapBits (hps,
                            sizlTemp.cy - y - 1, /* lScanStart */
                            1,                   /* lScans */
                            (PBYTE)pchTemp,
                            &bmi2Temp);

        /* Go for next line */
        pchTemp += surface->bitmap_info.cx*4;
    }

    /* Clean up resources */
    GpiSetBitmap (hps, (HBITMAP) NULL);
    GpiDeleteBitmap (hbmpTemp);
    GpiDestroyPS (hps);
    DevCloseDC (hdc);
}
Ejemplo n.º 25
0
HBITMAP PSBMBLTToSize( HAB hab, HPS hps, HBITMAP hbm, float fScale, ULONG ulOptions )
{
    BITMAPINFOHEADER2   bif2Before;
    BITMAPINFOHEADER2   bif2After;
    SIZEL               slAfter;
    ULONG               ulScreenWidth;
    ULONG               ulScreenHeight;
    HDC                 hdcAfter;
    HPS                 hpsAfter;
    HBITMAP             hbmAfter;
    POINTL              aptl[ 4 ];
    float               fAspect;
    HBITMAP             hbmOld;

    if( ( hbmOld = GpiSetBitmap( hps, hbm ) ) == HBM_ERROR )
    {
        return( NULLHANDLE );
    }

    memset( &bif2Before, 0, sizeof( bif2Before ) );                 // get current info
    bif2Before.cbFix = sizeof( bif2Before );
    if( GpiQueryBitmapInfoHeader( hbm, &bif2Before ) != TRUE )
    {
        GpiSetBitmap( hps, hbmOld );
        return( NULLHANDLE );
    }

    ulScreenWidth = WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN );  // screen width
    ulScreenHeight = WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN ); // screen height

    fAspect = ( bif2Before.cx * 1.0 ) / ( bif2Before.cy * 1.0 );    // calculate aspect ratio

    if( ulOptions & SCALE_LARGEST )
    {
        if( bif2Before.cx > bif2Before.cy )
        {
            slAfter.cx = ( LONG )( ulScreenWidth * fScale );
            slAfter.cy = ( LONG )( slAfter.cx / fAspect );
        }
        else
        {
            slAfter.cy = ( LONG )( ulScreenHeight * fScale );
            slAfter.cx = ( LONG )( slAfter.cy * fAspect );
        }
    }
    else if( ulOptions & SCALE_SMALLEST )
    {
        if( bif2Before.cx < bif2Before.cy )
        {
            slAfter.cx = ( LONG )( ulScreenWidth * fScale );
            slAfter.cy = ( LONG )( slAfter.cx / fAspect );
        }
        else
        {
            slAfter.cy = ( LONG )( ulScreenHeight * fScale );
            slAfter.cx = ( LONG )( slAfter.cy * fAspect );
        }
    }
    else if( ulOptions & SCALE_HORIZONTAL )
    {
        slAfter.cx = ( LONG )( ulScreenWidth * fScale );
        if( ulOptions & SCALE_VERTICAL )                        // basically, screw the aspect
        {
            slAfter.cy = ( LONG )( ulScreenHeight * fScale );
        }
        else
        {
            slAfter.cy = ( LONG )( slAfter.cx / fAspect );
        }
    }
    else if( ulOptions & SCALE_VERTICAL )
    {
        slAfter.cy = ( LONG )( ulScreenHeight * fScale );
        slAfter.cx = ( LONG )( slAfter.cy * fAspect );
    }
    else
    {
        GpiSetBitmap( hps, hbmOld );
        return( NULLHANDLE );
    }

    if( ( hdcAfter = DevOpenDC( hab, OD_MEMORY, "*", 0L, ( PDEVOPENDATA )NULL, NULLHANDLE ) )
        == NULLHANDLE )
    {
        GpiSetBitmap( hps, hbmOld );
        return( NULLHANDLE );
    }
    if( ( hpsAfter = GpiCreatePS(   hab,
                                    hdcAfter,
                                    &slAfter,
                                    PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC ) ) == NULLHANDLE )
    {
        DevCloseDC( hdcAfter );
        GpiSetBitmap( hps, hbmOld );
        return( NULLHANDLE );
    }

    memset( &bif2After, 0, sizeof( bif2After ) );
    bif2After.cbFix = sizeof( bif2After );
    bif2After.cx = slAfter.cx;
    bif2After.cy = slAfter.cy;
    bif2After.cBitCount = bif2Before.cBitCount;
    bif2After.cPlanes = bif2Before.cPlanes;

    if( ( hbmAfter = GpiCreateBitmap(   hpsAfter,                 // create bitmap
                                        ( PBITMAPINFOHEADER2 )&( bif2After ),
                                        ( ULONG )FALSE,
                                        NULL,
                                        NULL ) ) == NULLHANDLE )
    {
        GpiDestroyPS( hpsAfter );
        DevCloseDC( hdcAfter );
        GpiSetBitmap( hps, hbmOld );
        return( NULLHANDLE );
    }

    if( GpiSetBitmap( hpsAfter, hbmAfter ) == HBM_ERROR )
    {
        GpiDeleteBitmap( hbmAfter );
        GpiDestroyPS( hpsAfter );
        DevCloseDC( hdcAfter );
        GpiSetBitmap( hps, hbmOld );
        return( NULLHANDLE );
    }

    aptl[ 0 ].x = 0;
    aptl[ 0 ].y = 0;
    aptl[ 1 ].x = slAfter.cx;
    aptl[ 1 ].y = slAfter.cy;
    aptl[ 2 ].x = 0;
    aptl[ 2 ].y = 0;
    aptl[ 3 ].x = bif2Before.cx;
    aptl[ 3 ].y = bif2Before.cy;

    if( GpiBitBlt(  hpsAfter,
                    hps,
                    4L,
                    aptl,
                    ROP_SRCCOPY,
                    BBO_IGNORE ) == GPI_ERROR )
    {
        GpiSetBitmap( hpsAfter, NULLHANDLE );
        GpiDeleteBitmap( hbmAfter );
        GpiDestroyPS( hpsAfter );
        DevCloseDC( hdcAfter );
        GpiSetBitmap( hps, hbmOld );
        return( NULLHANDLE );
    }

    GpiSetBitmapDimension( hbmAfter, &slAfter );

    GpiSetBitmap( hpsAfter, NULLHANDLE );
    GpiDestroyPS( hpsAfter );
    DevCloseDC( hdcAfter );
    GpiSetBitmap( hps, hbmOld );

    return( hbmAfter );
}
  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.º 27
0
HBITMAP SetupBitmapFromFile(HWND hwnd, char *pszFileName /*, long lVertical2*/)
{
    HAB hab = WinQueryAnchorBlock(hwnd);
    PSTBFILE *pFile;
    HBITMAP hbm;

    if (DosAllocMem((PPVOID) & pFile, sizeof(PSTBFILE), PAG_READ | PAG_WRITE | PAG_COMMIT)
            != NO_ERROR)
    {
        return (NULLHANDLE);
    }
    memset(pFile, 0, sizeof(PSTBFILE));

    if (PSMMFillImageFormat(pszFileName, &(pFile->mmFormat), &(pFile->mmioInfo)) != TRUE)
    {
        DosFreeMem(pFile);
        return (NULLHANDLE);
    }
    if ((pFile->hmmio = PSMMInitializeImageFile(pszFileName,
                                                &(pFile->mmioInfo),
                                         &(pFile->mmImgHdr))) == NULLHANDLE)
    {
        DosFreeMem(pFile);
        return (NULLHANDLE);
    }
    pFile->cbRow = ((pFile->mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cx *
      pFile->mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cBitCount + 31) / 32) * 4;
    pFile->cbData = pFile->cbRow * pFile->mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cy;

    if (DosAllocMem(&(pFile->pvImage), pFile->cbData, PAG_READ | PAG_WRITE | PAG_COMMIT) != NO_ERROR)
    {
        PSMMCloseImageFile(pFile->hmmio);
        DosFreeMem(pFile);
        return (NULLHANDLE);
    }
    if (PSMMReadImageFile(pFile->hmmio, pFile->pvImage, pFile->cbData) != TRUE)
    {
        DosFreeMem(pFile->pvImage);
        PSMMCloseImageFile(pFile->hmmio);
        DosFreeMem(pFile);
    }
    PSMMCloseImageFile(pFile->hmmio);

    // convert data to system bitcount
    pFile->hdc = DevOpenDC(hab, OD_MEMORY, "*", 0L, (PDEVOPENDATA) NULL, NULLHANDLE);
    pFile->slHPS.cx = pFile->mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cx;
    pFile->slHPS.cy = pFile->mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cy;
    pFile->hps = GpiCreatePS(hab,
                             pFile->hdc,
                             &(pFile->slHPS),
                          PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC);
    pFile->hbm = GpiCreateBitmap(pFile->hps,
                             &(pFile->mmImgHdr.mmXDIBHeader.BMPInfoHeader2),
                                 0L,
                                 NULL,
                                 NULL);
    GpiSetBitmap(pFile->hps, pFile->hbm);
    GpiSetBitmapBits(pFile->hps,
                     0L,
                     (long) pFile->slHPS.cy,
                     (PBYTE) pFile->pvImage,
            (PBITMAPINFO2) & (pFile->mmImgHdr.mmXDIBHeader.BMPInfoHeader2));

    hbm = pFile->hbm;

    GpiDeleteBitmap(pFile->hbm);

    // free everything up
    GpiSetBitmap(pFile->hps, NULLHANDLE);
    GpiDestroyPS(pFile->hps);
    DevCloseDC(pFile->hdc);
    DosFreeMem(pFile->pvImage);
    DosFreeMem(pFile);

    return (hbm);
}
Ejemplo n.º 28
0
XBitmap XBitmap::operator = (const XBitmap & b)
{
/****
   BITMAPINFOHEADER2 * head;

   head = (BITMAPINFOHEADER2 *) malloc( sizeof(BITMAPINFOHEADER2));
   owner = b.owner;

   if (owner && hps == 0)
      hps = WinGetPS(owner->GetHandle());

   if (hbm != 0)
      GpiDeleteBitmap(hbm);

   head->cbFix = sizeof(BITMAPINFOHEADER2);

   GpiSetBitmap(b.hps, b.hbm);
   if( GpiQueryBitmapInfoHeader(b.hbm, head) == FALSE)
      OOLThrow("error copying bitmap", 3);

   LONG offBits = sizeof(BITMAPINFO2) + (sizeof(RGB2) * (1 << head->cBitCount));

   LONG size = (((head->cBitCount * head->cx) + 31) / 32) * 4 * head->cPlanes * head->cy;

   head = (BITMAPINFOHEADER2 *) realloc(head, offBits);

   void * buffer = malloc(size);
   if( GpiQueryBitmapBits(b.hps, 0, head->cy, (PBYTE) buffer, (BITMAPINFO2 *) head) == GPI_ALTERROR)
      OOLThrow("error query bitmap data", 3);

//   hbm = GpiCreateBitmap(hps, (PBITMAPINFOHEADER2) &p->bmp, CBM_INIT, (PBYTE) p + p->offBits, (PBITMAPINFO2) &p->bmp);
   hbm = GpiCreateBitmap(hps, (PBITMAPINFOHEADER2) head, CBM_INIT, (PBYTE) buffer, (PBITMAPINFO2) head);
   if(hbm == 0)
      XProcess::Beep(300,300);

   GpiSetBitmap(hps, hbm);

   XSize s;
   b.GetDimensions(&s);
   cx = s.GetWidth();
   cy = s.GetHeight();

   width = b.width;
   height = b.height;
   p = b.p;
   free(head);
   free(buffer);
   return *this;
****/
   BITMAPFILEHEADER2 * head;

   owner = b.owner;

   if (owner && hps == 0)
      hps = WinGetPS(owner->GetHandle());

   if (hbm != 0)
      GpiDeleteBitmap(hbm);

   head = (BITMAPFILEHEADER2 *) malloc(sizeof(BITMAPFILEHEADER2));
   head->bmp2.cbFix = sizeof(BITMAPINFOHEADER2);

   GpiQueryBitmapInfoHeader(b.hbm, &head->bmp2);
   head->offBits = sizeof(BITMAPFILEHEADER2) + (sizeof(RGB2) * (1 << head->bmp2.cBitCount));
   LONG size = head->offBits + (((head->bmp2.cBitCount * head->bmp2.cx) + 31) / 32) * 4 * head->bmp2.cPlanes * head->bmp2.cy;

   head = (BITMAPFILEHEADER2 *) realloc(head, size);

   head->usType = BFT_BMAP;
   head->xHotspot = head->yHotspot = 0;
   head->cbSize = sizeof(BITMAPFILEHEADER2);
   GpiSetBitmap(hps, b.hbm);
/***
head->bmp2.cbFix=16;
head->bmp2.cPlanes =1;
head->bmp2.cBitCount = 1;
****/
   GpiQueryBitmapBits(hps, 0, head->bmp2.cy, (PBYTE) head + head->offBits, (BITMAPINFO2 *) &head->bmp2);
   hbm = GpiCreateBitmap(hps, (PBITMAPINFOHEADER2) &head->bmp2, CBM_INIT, (PBYTE) head + head->offBits, (PBITMAPINFO2) &head->bmp2);

   GpiSetBitmap(hps, hbm);

   XSize s;
   b.GetDimensions(&s);
   cx = s.GetWidth();
   cy = s.GetHeight();

   width = b.width;
   height = b.height;
   p = b.p;
   free(head);

   return *this;
}
Ejemplo n.º 29
0
static void
_cairo_os2_surface_get_pixels_from_screen (cairo_os2_surface_t *surface,
                                           HPS                  hps_begin_paint,
                                           PRECTL               prcl_begin_paint_rect)
{
    HPS hps;
    HDC hdc;
    HAB hab;
    SIZEL sizlTemp;
    HBITMAP hbmpTemp;
    BITMAPINFO2 bmi2Temp;
    POINTL aptlPoints[4];
    int y;
    unsigned char *pchTemp;

    /* To copy pixels from screen to our buffer, we do the following steps:
     *
     * - Blit pixels from screen to a HBITMAP:
     *   -- Create Memory Device Context
     *   -- Create a PS into it
     *   -- Create a HBITMAP
     *   -- Select HBITMAP into memory PS
     *   -- Blit dirty pixels from screen to HBITMAP
     * - Copy HBITMAP lines (pixels) into our buffer
     * - Free resources
     *
     * These steps will require an Anchor Block (HAB). However,
     * WinQUeryAnchorBlock () documentation says that HAB is not
     * used in current OS/2 implementations, OS/2 deduces all information
     * it needs from the TID. Anyway, we'd be in trouble if we'd have to
     * get a HAB where we only know a HPS...
     * So, we'll simply use a fake HAB.
     */

    hab = (HAB) 1; /* OS/2 doesn't really use HAB... */

    /* Create a memory device context */
    hdc = DevOpenDC (hab, OD_MEMORY,"*",0L, NULL, NULLHANDLE);
    if (!hdc) {
        return;
    }

    /* Create a memory PS */
    sizlTemp.cx = prcl_begin_paint_rect->xRight - prcl_begin_paint_rect->xLeft;
    sizlTemp.cy = prcl_begin_paint_rect->yTop - prcl_begin_paint_rect->yBottom;
    hps = GpiCreatePS (hab,
                       hdc,
                       &sizlTemp,
                       PU_PELS | GPIT_NORMAL | GPIA_ASSOC);
    if (!hps) {
        DevCloseDC (hdc);
        return;
    }

    /* Create an uninitialized bitmap. */
    /* Prepare BITMAPINFO2 structure for our buffer */
    memset (&bmi2Temp, 0, sizeof (bmi2Temp));
    bmi2Temp.cbFix = sizeof (BITMAPINFOHEADER2);
    bmi2Temp.cx = sizlTemp.cx;
    bmi2Temp.cy = sizlTemp.cy;
    bmi2Temp.cPlanes = 1;
    bmi2Temp.cBitCount = 32;

    hbmpTemp = GpiCreateBitmap (hps,
                                (PBITMAPINFOHEADER2) &bmi2Temp,
                                0,
                                NULL,
                                NULL);

    if (!hbmpTemp) {
        GpiDestroyPS (hps);
        DevCloseDC (hdc);
        return;
    }

    /* Select the bitmap into the memory device context. */
    GpiSetBitmap (hps, hbmpTemp);

    /* Target coordinates (Noninclusive) */
    aptlPoints[0].x = 0;
    aptlPoints[0].y = 0;

    aptlPoints[1].x = sizlTemp.cx;
    aptlPoints[1].y = sizlTemp.cy;

    /* Source coordinates (Inclusive) */
    aptlPoints[2].x = prcl_begin_paint_rect->xLeft;
    aptlPoints[2].y = surface->bitmap_info.cy - prcl_begin_paint_rect->yBottom;

    aptlPoints[3].x = prcl_begin_paint_rect->xRight;
    aptlPoints[3].y = surface->bitmap_info.cy - prcl_begin_paint_rect->yTop;

    /* Blit pixels from screen to bitmap */
    GpiBitBlt (hps,
               hps_begin_paint,
               4,
               aptlPoints,
               ROP_SRCCOPY,
               BBO_IGNORE);

    /* Now we have to extract the pixels from the bitmap. */
    pchTemp =
        surface->pixels +
        (prcl_begin_paint_rect->yBottom)*surface->bitmap_info.cx*4 +
        prcl_begin_paint_rect->xLeft*4;
    for (y = 0; y < sizlTemp.cy; y++) {
        /* Get one line of pixels */
        GpiQueryBitmapBits (hps,
                            sizlTemp.cy - y - 1, /* lScanStart */
                            1,                   /* lScans */
                            pchTemp,
                            &bmi2Temp);

        /* Go for next line */
        pchTemp += surface->bitmap_info.cx*4;
    }

    /* Clean up resources */
    GpiSetBitmap (hps, (HBITMAP) NULL);
    GpiDeleteBitmap (hbmpTemp);
    GpiDestroyPS (hps);
    DevCloseDC (hdc);
}
Ejemplo n.º 30
0
BOOL CreateImages(PLUGINSHARE *pPluginData)
{
    int     i;
    HBITMAP hbmTemp;
    HAB     hab = WinQueryAnchorBlock(HWND_DESKTOP);
    HDC     hdcSrc, hdcDest;
    HPS     hpsSrc, hpsDest;
    SIZEL   slHPS;
    BITMAPINFOHEADER2 bif2Src, bif2Dest;
    POINTL aptl[4];

    if (pPluginData == NULL)
        return (FALSE);

    hbmTemp = SetupBitmapFromFile(HWND_DESKTOP, pPluginData->szImageFile/*, 22*/);

    if (hbmTemp == NULLHANDLE)
        return FALSE;

    memset(&bif2Src, 0, sizeof(bif2Src));
    bif2Src.cbFix = sizeof(bif2Src);
    GpiQueryBitmapInfoHeader(hbmTemp, &bif2Src);
    hdcSrc = DevOpenDC(hab, OD_MEMORY, "*", 0L, (PDEVOPENDATA) NULL, NULLHANDLE);
    slHPS.cx = bif2Src.cx;
    slHPS.cy = bif2Src.cy;
    pPluginData->ulCx=slHPS.cx;
    pPluginData->ulCy=slHPS.cy;

    hpsSrc = GpiCreatePS(hab,
                      hdcSrc,
                      &slHPS,
                      PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC);
    GpiSetBitmap(hpsSrc, hbmTemp);

    hdcDest = DevOpenDC(hab, OD_MEMORY, "*", 0L, (PDEVOPENDATA) NULL, NULLHANDLE);


    slHPS.cx = bif2Src.cx / 2;
    slHPS.cy = bif2Src.cy / 5;
    hpsDest = GpiCreatePS(hab,
                      hdcDest,
                      &slHPS,
                      PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC);

    memset(&bif2Dest, 0, sizeof(bif2Dest));
    bif2Dest.cbFix = sizeof(bif2Dest);
    bif2Dest.cx = slHPS.cx;
    bif2Dest.cy = slHPS.cy;
    bif2Dest.cBitCount = 24;
    bif2Dest.cPlanes = 1;

//Close Button
    pPluginData->hbmActiveClose = GpiCreateBitmap(hpsDest,
                                    &bif2Dest,
                                    0L,
                                    NULL,
                                    NULL);

    GpiSetBitmap(hpsDest, pPluginData->hbmActiveClose);

    aptl[0].x = 0;
    aptl[0].y = 0;
    aptl[1].x = slHPS.cx;
    aptl[1].y = slHPS.cy;
    aptl[2].x = 0;
    aptl[2].y = 0;
    aptl[3].x = slHPS.cx;
    aptl[3].y = slHPS.cy;
    GpiBitBlt(hpsDest, hpsSrc, 4, aptl, ROP_SRCCOPY, BBO_IGNORE);

//Minimize Button
    pPluginData->hbmActiveMinimize = GpiCreateBitmap(hpsDest,
                                    &bif2Dest,
                                    0L,
                                    NULL,
                                    NULL);

    GpiSetBitmap(hpsDest, pPluginData->hbmActiveMinimize);

    aptl[0].x = 0;
    aptl[0].y = 0;
    aptl[1].x = slHPS.cx;
    aptl[1].y = slHPS.cy;
    aptl[2].x = 0;
    aptl[2].y = slHPS.cy * 1;
    aptl[3].x = aptl[2].x + slHPS.cx;
    aptl[3].y = aptl[2].y + slHPS.cy;
    GpiBitBlt(hpsDest, hpsSrc, 4, aptl, ROP_SRCCOPY, BBO_IGNORE);

//Maximize Button
    pPluginData->hbmActiveMaximize = GpiCreateBitmap(hpsDest,
                                    &bif2Dest,
                                    0L,
                                    NULL,
                                    NULL);

    GpiSetBitmap(hpsDest, pPluginData->hbmActiveMaximize);

    aptl[0].x = 0;
    aptl[0].y = 0;
    aptl[1].x = slHPS.cx;
    aptl[1].y = slHPS.cy;
    aptl[2].x = 0;
    aptl[2].y = slHPS.cy * 2;
    aptl[3].x = aptl[2].x + slHPS.cx;
    aptl[3].y = aptl[2].y + slHPS.cy;
    GpiBitBlt(hpsDest, hpsSrc, 4, aptl, ROP_SRCCOPY, BBO_IGNORE);

//Restore Button
    pPluginData->hbmActiveRestore = GpiCreateBitmap(hpsDest,
                                    &bif2Dest,
                                    0L,
                                    NULL,
                                    NULL);

    GpiSetBitmap(hpsDest, pPluginData->hbmActiveRestore);

    aptl[0].x = 0;
    aptl[0].y = 0;
    aptl[1].x = slHPS.cx;
    aptl[1].y = slHPS.cy;
    aptl[2].x = 0;
    aptl[2].y = slHPS.cy * 3;
    aptl[3].x = aptl[2].x + slHPS.cx;
    aptl[3].y = aptl[2].y + slHPS.cy;
    GpiBitBlt(hpsDest, hpsSrc, 4, aptl, ROP_SRCCOPY, BBO_IGNORE);

//Hide Button
    pPluginData->hbmActiveHide = GpiCreateBitmap(hpsDest,
                                    &bif2Dest,
                                    0L,
                                    NULL,
                                    NULL);

    GpiSetBitmap(hpsDest, pPluginData->hbmActiveHide);

    aptl[0].x = 0;
    aptl[0].y = 0;
    aptl[1].x = slHPS.cx;
    aptl[1].y = slHPS.cy;
    aptl[2].x = 0;
    aptl[2].y = slHPS.cy * 4;
    aptl[3].x = aptl[2].x + slHPS.cx;
    aptl[3].y = aptl[2].y + slHPS.cy;
    GpiBitBlt(hpsDest, hpsSrc, 4, aptl, ROP_SRCCOPY, BBO_IGNORE);



    /* Inactive... */

//Close Button
    pPluginData->hbmInactiveClose = GpiCreateBitmap(hpsDest,
                                    &bif2Dest,
                                    0L,
                                    NULL,
                                    NULL);

    GpiSetBitmap(hpsDest, pPluginData->hbmInactiveClose);

    aptl[0].x = 0;
    aptl[0].y = 0;
    aptl[1].x = slHPS.cx;
    aptl[1].y = slHPS.cy;
    aptl[2].x = slHPS.cx ;
    aptl[2].y = 0;
    aptl[3].x = aptl[2].x + slHPS.cx;
    aptl[3].y = aptl[2].y + slHPS.cy;
    GpiBitBlt(hpsDest, hpsSrc, 4, aptl, ROP_SRCCOPY, BBO_IGNORE);

//Minimize Button
    pPluginData->hbmInactiveMinimize = GpiCreateBitmap(hpsDest,
                                    &bif2Dest,
                                    0L,
                                    NULL,
                                    NULL);

    GpiSetBitmap(hpsDest, pPluginData->hbmInactiveMinimize);

    aptl[0].x = 0;
    aptl[0].y = 0;
    aptl[1].x = slHPS.cx;
    aptl[1].y = slHPS.cy;
    aptl[2].x = slHPS.cx;
    aptl[2].y = slHPS.cy * 1;
    aptl[3].x = aptl[2].x + slHPS.cx;
    aptl[3].y = aptl[2].y + slHPS.cy;
    GpiBitBlt(hpsDest, hpsSrc, 4, aptl, ROP_SRCCOPY, BBO_IGNORE);

//Maximize Button
    pPluginData->hbmInactiveMaximize = GpiCreateBitmap(hpsDest,
                                    &bif2Dest,
                                    0L,
                                    NULL,
                                    NULL);

    GpiSetBitmap(hpsDest, pPluginData->hbmInactiveMaximize);

    aptl[0].x = 0;
    aptl[0].y = 0;
    aptl[1].x = slHPS.cx;
    aptl[1].y = slHPS.cy;
    aptl[2].x = slHPS.cx;
    aptl[2].y = slHPS.cy * 2;
    aptl[3].x = aptl[2].x + slHPS.cx;
    aptl[3].y = aptl[2].y + slHPS.cy;
    GpiBitBlt(hpsDest, hpsSrc, 4, aptl, ROP_SRCCOPY, BBO_IGNORE);


//Restore Button
    pPluginData->hbmInactiveRestore = GpiCreateBitmap(hpsDest,
                                    &bif2Dest,
                                    0L,
                                    NULL,
                                    NULL);

    GpiSetBitmap(hpsDest, pPluginData->hbmInactiveRestore);

    aptl[0].x = 0;
    aptl[0].y = 0;
    aptl[1].x = slHPS.cx;
    aptl[1].y = slHPS.cy;
    aptl[2].x = slHPS.cx;
    aptl[2].y = slHPS.cy * 3;
    aptl[3].x = aptl[2].x + slHPS.cx;
    aptl[3].y = aptl[2].y + slHPS.cy;
    GpiBitBlt(hpsDest, hpsSrc, 4, aptl, ROP_SRCCOPY, BBO_IGNORE);


//Hide Button
    pPluginData->hbmInactiveHide = GpiCreateBitmap(hpsDest,
                                    &bif2Dest,
                                    0L,
                                    NULL,
                                    NULL);

    GpiSetBitmap(hpsDest, pPluginData->hbmInactiveHide);

    aptl[0].x = 0;
    aptl[0].y = 0;
    aptl[1].x = slHPS.cx;
    aptl[1].y = slHPS.cy;
    aptl[2].x = slHPS.cx;
    aptl[2].y = slHPS.cy * 4;
    aptl[3].x = aptl[2].x + slHPS.cx;
    aptl[3].y = aptl[2].y + slHPS.cy;
    GpiBitBlt(hpsDest, hpsSrc, 4, aptl, ROP_SRCCOPY, BBO_IGNORE);

   GpiSetBitmap(hpsSrc, NULLHANDLE);

    if (hbmTemp != NULLHANDLE)
        GpiDeleteBitmap(hbmTemp);
    if (hpsSrc != NULLHANDLE)
        GpiDestroyPS(hpsSrc);
    if (hdcSrc != NULLHANDLE)
        DevCloseDC(hdcSrc);


    GpiSetBitmap(hpsDest, NULLHANDLE);
    if (hpsDest != NULLHANDLE)
        GpiDestroyPS(hpsDest);
    if (hdcDest != NULLHANDLE)
        DevCloseDC(hdcDest);

    return TRUE;
}