Ignore:
Timestamp:
Dec 22, 2001, 12:10:30 PM (24 years ago)
Author:
umoeller
Message:

Misc fixes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/helpers/gpih.c

    r111 r126  
    6262// array for querying device capabilities (gpihQueryDisplayCaps)
    6363LONG            DisplayCaps[CAPS_DEVICE_POLYSET_POINTS] = {0};
    64 BOOL            fCapsQueried = FALSE;
     64BOOL            G_fCapsQueried = FALSE;
    6565
    6666/*
     
    171171 *      This function will load all the device capabilities
    172172 *      only once into a global array and re-use them afterwards.
     173 *
     174 *@@changed V0.9.16 (2001-12-18) [umoeller]: fixed multiple loads
    173175 */
    174176
    175177ULONG gpihQueryDisplayCaps(ULONG ulIndex)
    176178{
    177     if (!fCapsQueried)
     179    if (!G_fCapsQueried)
    178180    {
    179181        HPS hps = WinGetScreenPS(HWND_DESKTOP);
    180182        HDC hdc = GpiQueryDevice(hps);
    181183        DevQueryCaps(hdc, 0, CAPS_DEVICE_POLYSET_POINTS, &DisplayCaps[0]);
     184        G_fCapsQueried = TRUE;      // was missing V0.9.16 (2001-12-18) [umoeller]
    182185    }
    183186
     
    14591462/*
    14601463 *@@ gpihCreateBitmap:
     1464 *      calls gpihCreateBitmap2 with cPlanes and cBitCount == 0
     1465 *      for compatibility with exports. Widgets might
     1466 *      have used this func.
     1467 *
     1468 *@@changed V0.9.0 [umoeller]: function prototype changed to cx and cy
     1469 *@@changed V0.9.16 (2001-12-18) [umoeller]: now using optimized gpihCreateBitmap2
     1470 */
     1471
     1472HBITMAP gpihCreateBitmap(HPS hpsMem,        // in: memory DC
     1473                         ULONG cx,          // in: width of new bitmap
     1474                         ULONG cy)          // in: height of new bitmap
     1475{
     1476    return (gpihCreateBitmap2(hpsMem,
     1477                              cx,
     1478                              cy,
     1479                              0,
     1480                              0));            // current screen bit count
     1481}
     1482
     1483/*
     1484 *@@ gpihCreateBitmap2:
    14611485 *      creates a new bitmap for a given memory PS.
    14621486 *      This bitmap will have the cPlanes and bitcount
     
    14721496 *      Returns the bitmap handle or NULLHANDLE upon errors.
    14731497 *
    1474  *@@changed V0.9.0 [umoeller]: function prototype changed to cx and cy
    1475  */
    1476 
    1477 HBITMAP gpihCreateBitmap(HPS hpsMem,        // in: memory DC
    1478                          ULONG cx,          // in: width of new bitmap
    1479                          ULONG cy)          // in: height of new bitmap
     1498 *@@added V0.9.16 (2001-12-18) [umoeller]
     1499 */
     1500
     1501HBITMAP gpihCreateBitmap2(HPS hpsMem,        // in: memory DC
     1502                          ULONG cx,          // in: width of new bitmap
     1503                          ULONG cy,          // in: height of new bitmap
     1504                          ULONG cPlanes,     // in: color planes (usually 1); if 0, current screen is used
     1505                          ULONG cBitCount)   // in: either 1, 4, or 24; if 0, current screen value
    14801506{
    14811507    HBITMAP hbm = NULLHANDLE;
    14821508    LONG alData[2];
    14831509    BITMAPINFOHEADER2 bih2;
    1484     PBITMAPINFO2 pbmi = NULL;
     1510    // PBITMAPINFO2 pbmi = NULL;
    14851511
    14861512    // determine the device's plane/bit-count format;
     
    14931519        bih2.cx = cx; // (prcl->xRight - prcl->xLeft);       changed V0.9.0
    14941520        bih2.cy = cy; // (prcl->yTop - prcl->yBottom);       changed V0.9.0
    1495         bih2.cPlanes = alData[0];
    1496         bih2.cBitCount = alData[1];
     1521        bih2.cPlanes = (cPlanes) ? cPlanes : alData[0];
     1522        bih2.cBitCount = (cBitCount) ? cBitCount : alData[1];
     1523            _Pmpf((__FUNCTION__ ": cPlanes %d, cBitCount %d",
     1524                        bih2.cPlanes, bih2.cBitCount));
    14971525        bih2.ulCompression = BCA_UNCOMP;
    14981526        bih2.cbImage = (    (   (bih2.cx
     
    15151543        bih2.ulIdentifier = 0;              // application-specific data
    15161544
    1517         // allocate memory for info header
    1518         if (DosAllocMem((PPVOID)&pbmi,
    1519                         sizeof(BITMAPINFO2) +
    1520                             (sizeof(RGB2)
    1521                                 * (1 << bih2.cPlanes)
    1522                                 * (1 << bih2.cBitCount)
    1523                             ),
    1524                         PAG_COMMIT | PAG_READ | PAG_WRITE)
    1525             == NO_ERROR)
    1526         {
    1527             pbmi->cbFix = bih2.cbFix;
    1528             pbmi->cx = bih2.cx;
    1529             pbmi->cy = bih2.cy;
    1530             pbmi->cPlanes = bih2.cPlanes;
    1531             pbmi->cBitCount = bih2.cBitCount;
    1532             pbmi->ulCompression = BCA_UNCOMP;
    1533             pbmi->cbImage = ((bih2.cx+31)/32) * bih2.cy;
    1534             pbmi->cxResolution = 70;
    1535             pbmi->cyResolution = 70;
    1536             pbmi->cclrUsed = 2;
    1537             pbmi->cclrImportant = 0;
    1538             pbmi->usUnits = BRU_METRIC;
    1539             pbmi->usReserved = 0;
    1540             pbmi->usRecording = BRA_BOTTOMUP;
    1541             pbmi->usRendering = BRH_NOTHALFTONED;
    1542             pbmi->cSize1 = 0;
    1543             pbmi->cSize2 = 0;
    1544             pbmi->ulColorEncoding = BCE_RGB;
    1545             pbmi->ulIdentifier = 0;
    1546 
    1547             // create a bit map that is compatible with the display
    1548             hbm = GpiCreateBitmap(hpsMem,
    1549                                   &bih2,
    1550                                   FALSE,
    1551                                   NULL,
    1552                                   pbmi);
    1553 
    1554             // free the memory we allocated previously; GPI has
    1555             // allocated all the resources it needs itself, so
    1556             // we can release this
    1557             DosFreeMem(pbmi);
    1558         }
     1545        // create a bit map that is compatible with the display
     1546        hbm = GpiCreateBitmap(hpsMem,
     1547                              &bih2,
     1548                              0,            // do not initialize
     1549                              NULL,
     1550                              NULL);
    15591551    }
    15601552
     
    20862078/*
    20872079 *@@ gpihCreateXBitmap:
     2080 *      calls gpihCreateXBitmap2 with cPlanes and cBitCount == 0
     2081 *      for compatibility with exports. Widgets might
     2082 *      have used this func.
     2083 *
     2084 *@@added V0.9.12 (2001-05-20) [umoeller]
     2085 *@@changed V0.9.16 (2001-12-18) [umoeller]: now using optimized gpihCreateXBitmap2
     2086 */
     2087
     2088PXBITMAP gpihCreateXBitmap(HAB hab,         // in: anchor block
     2089                           LONG cx,         // in: bitmap width
     2090                           LONG cy)         // in: bitmap height
     2091{
     2092    return (gpihCreateXBitmap2(hab,
     2093                               cx,
     2094                               cy,
     2095                               0,
     2096                               0));
     2097}
     2098
     2099/*
     2100 *@@ gpihCreateXBitmap:
    20882101 *      creates an XBitmap, which is returned in an
    20892102 *      _XBITMAP structure.
     
    21242137 *      to more than 100 lines.
    21252138 *
    2126  *@@added V0.9.12 (2001-05-20) [umoeller]
    2127  */
    2128 
    2129 PXBITMAP gpihCreateXBitmap(HAB hab,         // in: anchor block
    2130                            LONG cx,         // in: bitmap width
    2131                            LONG cy)         // in: bitmap height
     2139 *@@added V0.9.16 (2001-12-18) [umoeller]
     2140 */
     2141
     2142PXBITMAP gpihCreateXBitmap2(HAB hab,         // in: anchor block
     2143                            LONG cx,         // in: bitmap width
     2144                            LONG cy,         // in: bitmap height
     2145                            ULONG cPlanes,     // in: color planes (usually 1); if 0, current screen is used
     2146                            ULONG cBitCount)   // in: either 1, 4, or 24; if 0, current screen value
    21322147{
    21332148    BOOL fOK = FALSE;
     
    21452160                            &pbmp->hpsMem))
    21462161        {
    2147             gpihSwitchToRGB(pbmp->hpsMem);
    2148             if (pbmp->hbm = gpihCreateBitmap(pbmp->hpsMem,
    2149                                              cx,
    2150                                              cy))
     2162            if (cBitCount != 1)
     2163                // not monochrome bitmap:
     2164                gpihSwitchToRGB(pbmp->hpsMem);
     2165
     2166            if (pbmp->hbm = gpihCreateBitmap2(pbmp->hpsMem,
     2167                                              cx,
     2168                                              cy,
     2169                                              cPlanes,
     2170                                              cBitCount))
    21512171            {
    21522172                if (GpiSetBitmap(pbmp->hpsMem,
     
    21622182
    21632183    return (pbmp);
     2184}
     2185
     2186/*
     2187 *@@ gpihDetachBitmap:
     2188 *      "detaches" the bitmap from the given XBITMAP.
     2189 *      This will deselect the bitmap from the internal
     2190 *      memory PS so it can be used with many OS/2 APIs
     2191 *      that require that the bitmap not be selected
     2192 *      into any memory PS.
     2193 *
     2194 *      Note that it then becomes the responsibility
     2195 *      of the caller to explicitly call GpiDeleteBitmap
     2196 *      because it will not be deleted by gpihDestroyXBitmap.
     2197 *
     2198 *@@added V0.9.16 (2001-12-18) [umoeller]
     2199 */
     2200
     2201HBITMAP gpihDetachBitmap(PXBITMAP pbmp)
     2202{
     2203    HBITMAP hbm = pbmp->hbm;
     2204    pbmp->hbm = NULLHANDLE;
     2205    GpiSetBitmap(pbmp->hpsMem, NULLHANDLE);
     2206
     2207    return (hbm);
    21642208}
    21652209
Note: See TracChangeset for help on using the changeset viewer.