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); }
static void refresh_rectangle( grPMSurface* surface, int x, int y, int w, int h ) { LOG(( "Os2PM: refresh_rectangle( %08lx, %d, %d, %d, %d )\n", (long)surface, x, y, w, h )); (void)x; (void)y; (void)w; (void)h; /* convert_rectangle( surface, x, y, w, h ); */ LOCK( surface->image_lock ); GpiSetBitmapBits( surface->image_ps, 0, surface->root.bitmap.rows, surface->root.bitmap.buffer, surface->bitmap_header ); UNLOCK( surface->image_lock ); WinInvalidateRect( surface->client_window, NULL, FALSE ); WinUpdateWindow( surface->frame_window ); }
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); } }
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); }
HBITMAP LoadBitmap ( HAB hab, HDC hdc, HPS hps, PSZ pszFileName ) { HBITMAP hbm; MMIOINFO mmioinfo; MMFORMATINFO mmFormatInfo; HMMIO hmmio; ULONG ulImageHeaderLength; MMIMAGEHEADER mmImgHdr; ULONG ulBytesRead; ULONG dwNumRowBytes; PBYTE pRowBuffer; ULONG dwRowCount; SIZEL ImageSize; ULONG dwHeight, dwWidth; SHORT wBitCount; FOURCC fccStorageSystem; ULONG dwPadBytes; ULONG dwRowBits; ULONG ulReturnCode; ULONG dwReturnCode; HBITMAP hbReturnCode; LONG lReturnCode; FOURCC fccIOProc; // DBGMessage(pszFileName); ulReturnCode = mmioIdentifyFile ( pszFileName, 0L, &mmFormatInfo, &fccStorageSystem, 0L, 0L); /* * If this file was NOT identified, then this function won't * work, so return an error by indicating an empty bitmap. */ if ( ulReturnCode == MMIO_ERROR ) { DBGMessage("Erro em mmioIdentifyFile"); return (0L); } /* * If mmioIdentifyFile did not find a custom-written IO proc which * can understand the image file, then it will return the DOS IO Proc * info because the image file IS a DOS file. */ if( mmFormatInfo.fccIOProc == FOURCC_DOS ) { WinMessageBox( HWND_DESKTOP, HWND_DESKTOP, "Image file could not be interpreted by any permanently or temporarily installed IO procedures.", pszFileName, (HMODULE) NULL, (ULONG) MB_OK | MB_MOVEABLE | MB_ERROR ); return ( 0L ); } /* * Ensure this is an IMAGE IOproc, and that it can read * translated data */ if ( (mmFormatInfo.ulMediaType != MMIO_MEDIATYPE_IMAGE) || ((mmFormatInfo.ulFlags & MMIO_CANREADTRANSLATED) == 0) ) { WinMessageBox( HWND_DESKTOP, HWND_DESKTOP, "No IMAGE IO Procedures exist which can translate the data in the image file specified.", pszFileName, (HMODULE) NULL, (ULONG) MB_OK | MB_MOVEABLE | MB_ERROR ); return (0L); } else { fccIOProc = mmFormatInfo.fccIOProc; } /* Clear out and initialize mminfo structure */ memset ( &mmioinfo, 0L, sizeof ( MMIOINFO ) ); mmioinfo.fccIOProc = fccIOProc; mmioinfo.ulTranslate = MMIO_TRANSLATEHEADER | MMIO_TRANSLATEDATA; hmmio = mmioOpen ( (PSZ) pszFileName, &mmioinfo, MMIO_READ | MMIO_DENYWRITE | MMIO_NOIDENTIFY ); if ( ! hmmio ) { /* If file could not be opened, return with error */ DBGMessage("Erro em mmioOpen"); return (0L); } dwReturnCode = mmioQueryHeaderLength ( hmmio, (PLONG)&ulImageHeaderLength, 0L, 0L); if ( ulImageHeaderLength != sizeof ( MMIMAGEHEADER ) ) { /* We have a problem.....possibly incompatible versions */ ulReturnCode = mmioClose (hmmio, 0L); return (0L); } ulReturnCode = mmioGetHeader ( hmmio, &mmImgHdr, (LONG) sizeof ( MMIMAGEHEADER ), (PLONG)&ulBytesRead, 0L, 0L); if ( ulReturnCode != MMIO_SUCCESS ) { /* Header unavailable */ DBGMessage("Erro em mmioGetHeader"); ulReturnCode = mmioClose (hmmio, 0L); return (0L); } /* * Determine the number of bytes required, per row. * PLANES MUST ALWAYS BE = 1 */ dwHeight = mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cy; dwWidth = mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cx; wBitCount = mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cBitCount; dwRowBits = dwWidth * mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cBitCount; dwNumRowBytes = dwRowBits >> 3; /* * Account for odd bits used in 1bpp or 4bpp images that are * NOT on byte boundaries. */ if ( dwRowBits % 8 ) { dwNumRowBytes++; } /* * Ensure the row length in bytes accounts for byte padding. * All bitmap data rows must are aligned on LONG/4-BYTE boundaries. * The data FROM an IOProc should always appear in this form. */ dwPadBytes = ( dwNumRowBytes % 4 ); if ( dwPadBytes ) { dwNumRowBytes += 4 - dwPadBytes; } /* Allocate space for ONE row of pels */ if ( DosAllocMem( (PPVOID)&pRowBuffer, (ULONG)dwNumRowBytes, fALLOC)) { ulReturnCode = mmioClose (hmmio, 0L); DBGMessage("Erro de alocacao de memoria"); return(0L); } /* *************************************************** Create a memory presentation space that includes the memory device context obtained above. ***************************************************/ ImageSize.cx = dwWidth; ImageSize.cy = dwHeight; /* *************************************************** Create an uninitialized bitmap. This is where we will put all of the bits once we read them in. ***************************************************/ hbm = GpiCreateBitmap ( hps, &mmImgHdr.mmXDIBHeader.BMPInfoHeader2, 0L, NULL, NULL); if ( !hbm ) { ulReturnCode = mmioClose (hmmio, 0L); DBGMessage("Erro ao criar bitmap"); return(0L); } /* *************************************************** Select the bitmap into the memory device context. *************************************************** */ hbReturnCode = GpiSetBitmap ( hps, hbm ); /**************************************************************** LOAD THE BITMAP DATA FROM THE FILE One line at a time, starting from the BOTTOM *************************************************************** */ for ( dwRowCount = 0; dwRowCount < dwHeight; dwRowCount++ ) { ulBytesRead = (ULONG) mmioRead ( hmmio, pRowBuffer, dwNumRowBytes ); if ( !ulBytesRead ) { break; } /* * Allow context switching while previewing.. Couldn't get * it to work. Perhaps will get to it when time is available... */ lReturnCode = GpiSetBitmapBits ( hps, (LONG) dwRowCount, (LONG) 1, (PBYTE) pRowBuffer, (PBITMAPINFO2) &mmImgHdr.mmXDIBHeader.BMPInfoHeader2); } ulReturnCode = mmioClose (hmmio, 0L); DosFreeMem(pRowBuffer); // DBGTracex(hbm); return(hbm); }