⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fill.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
    _wpi_deletebitmap( screenbitmap );

    /*
     * First fill the screen bitmap with a colour we know will force the
     * pixels to change (we know that either black or white will do).  We
     * also fill the xor bitmap with the colour since it may be a dithered
     * colour.
     */
    screendup = DuplicateBitmap( bigbitmap );

    pres = _wpi_getpres( HWND_DESKTOP );
    screenpres = _wpi_createcompatiblepres( pres, Instance, &screendc );
    _wpi_releasepres( HWND_DESKTOP, pres );

    _wpi_torgbmode( screenpres );

    oldscreen = _wpi_selectobject( screenpres, bigbitmap );
    if ( _wpi_getpixel(screenpres, fillinfo->pt.x, fillinfo->pt.y) == BLACK ) {
        fillcolour = WHITE;
    } else {
        fillcolour = BLACK;
    }

    hbrush = _wpi_createsolidbrush( fillcolour );
    oldbrush = _wpi_selectobject( screenpres, hbrush );
    _wpi_extfloodfill( screenpres, fillinfo->pt.x, fillinfo->pt.y,
                        _wpi_getpixel(screenpres, fillinfo->pt.x,
                        fillinfo->pt.y), FLOODFILLSURFACE );
    _wpi_selectobject( screenpres, oldbrush );
    _wpi_deleteobject( hbrush );
    _wpi_selectobject( screenpres, oldscreen );
    _wpi_deletecompatiblepres( screenpres, screendc );

    xorbits = GetTheBits( node->hxorbitmap );
    screenbeforebits = GetTheBits( screendup );
    screenbits = GetTheBits( bigbitmap );
    andbits = GetTheBits( node->handbitmap );

    /*
     * Now go through every pixel and see if it changed on the screen.  If
     * it did then it should change on the XOR and AND bitmaps
     */
    for (x=0; x < node->width; ++x) {
        for (y=0; y < node->height; ++y) {
            screenchanged = (MyGetPixel(screenbits, x, y) !=
                                        MyGetPixel(screenbeforebits, x, y));

            if (screenchanged) {
                MySetPixel( xorbits, x, y, fillinfo->xorcolour );
                MySetPixel( andbits, x, y, fillinfo->andcolour );
            }
        }
    }
    FreeTheBits( andbits, node->handbitmap, TRUE );
    FreeTheBits( xorbits, node->hxorbitmap, TRUE );
    FreeTheBits( screenbeforebits, screendup, FALSE );
    FreeTheBits( screenbits, bigbitmap, FALSE );

    _wpi_deletebitmap( bigbitmap );
    _wpi_deletebitmap( screendup );
} /* fillScreenFirst */

#else

/*
 * fillScreenFirst - We fill the screen bitmap first and find out which
 *                   pixels have changed.  We use these pixels to determine
 *                   which should change in the AND and XOR bitmaps.
 *                   Windows version
 */
static void fillScreenFirst( fill_info_struct *fillinfo, img_node *node )
{
    HDC         hdc;
    HDC         xordc;
    HDC         xordcbefore;
    HDC         screendc;
    HDC         screendcbefore;
    HDC         anddc;
    HBRUSH      oldbrush;
    HBRUSH      hbrush;
    HBITMAP     oldxorbmp;
    HBITMAP     oldandbmp;
    HBITMAP     xorbmpbefore;
    HBITMAP     oldxorbmpbefore;
    HBITMAP     screenbitmap;
    HBITMAP     screendup;
    HBITMAP     oldscreen;
    HBITMAP     oldscreendup;
    HBITMAP     bigbitmap;      // bigger bitmap we actually fill
    COLORREF    xorcolour;
    COLORREF    fillcolour;
    BOOL        xorchanged;
    BOOL        screenchanged;
    short       x,y;

    /*
     * create a copy of the screen bitmap but make it one bigger so that
     * the fill won't screw up on the right hand side of the bitmap.
     */
    screenbitmap = CreateViewBitmap( node );
    bigbitmap = makeBiggerBitmap( screenbitmap, &(fillinfo->pt) );

    /*
     * First fill the screen bitmap with a colour we know will force the
     * pixels to change (we know that either black or white will do).  We
     * also fill the xor bitmap with the colour since it may be a dithered
     * colour.
     */
    screendup = DuplicateBitmap( bigbitmap );

    hdc = GetDC( NULL );
    screendc = CreateCompatibleDC( hdc );
    xordc = CreateCompatibleDC( hdc );
    screendcbefore = CreateCompatibleDC( hdc );
    xordcbefore = CreateCompatibleDC( hdc );
    anddc = CreateCompatibleDC( hdc );
    ReleaseDC( NULL, hdc );

    oldscreen = SelectObject( screendc, bigbitmap );
    if (GetPixel(screendc, fillinfo->pt.x, fillinfo->pt.y) == BLACK) {
        fillcolour = WHITE;
    } else {
        fillcolour = BLACK;
    }
    hbrush = CreateSolidBrush( fillcolour );
    oldbrush = SelectObject( screendc, hbrush );
    ExtFloodFill( screendc, fillinfo->pt.x, fillinfo->pt.y,
                        GetPixel(screendc, fillinfo->pt.x, fillinfo->pt.y),
                        FLOODFILLSURFACE );
    SelectObject( screendc, oldbrush );
    DeleteObject( hbrush );

    xorbmpbefore = DuplicateBitmap( node->hxorbitmap );
    oldxorbmp = SelectObject( xordc, node->hxorbitmap );
    hbrush = CreateSolidBrush( fillinfo->xorcolour );
    oldbrush = SelectObject( xordc, hbrush );
    ExtFloodFill( xordc, fillinfo->pt.x, fillinfo->pt.y,
                        GetPixel(xordc, fillinfo->pt.x, fillinfo->pt.y),
                        FLOODFILLSURFACE );
    SelectObject( xordc, oldbrush );
    DeleteObject( hbrush );

    oldxorbmpbefore = SelectObject( xordcbefore, xorbmpbefore );
    oldscreendup = SelectObject( screendcbefore, screendup );
    oldandbmp = SelectObject( anddc, node->handbitmap );

    /*
     * Now go through every pixel and see if it changed on the screen.  If
     * it did not change, it should not have changed on the xor bitmap.
     */
    for (x=0; x < node->width; ++x) {
        for (y=0; y < node->height; ++y) {
            xorcolour = GetPixel(xordcbefore, x, y);

            xorchanged = (GetPixel(xordc, x, y) != xorcolour);
            screenchanged = (GetPixel(screendc, x, y) != GetPixel(screendcbefore, x, y));

            if (!screenchanged) {
                if (xorchanged) {
                    SetPixel( xordc, x, y, xorcolour );
                }
            } else {
                SetPixel( anddc, x, y, fillinfo->andcolour );
            }
        }
    }
    SelectObject( screendc, oldscreen);
    DeleteDC( screendc );

    SelectObject( screendcbefore, oldscreendup);
    DeleteDC( screendcbefore );

    SelectObject( xordcbefore, oldxorbmpbefore );
    DeleteDC( xordcbefore );

    SelectObject( anddc, oldandbmp );
    DeleteDC( anddc );

    SelectObject( xordc, oldxorbmp );
    DeleteDC( xordc );

    DeleteObject( xorbmpbefore );
    DeleteObject( screenbitmap );
    DeleteObject( bigbitmap );
    DeleteObject( screendup );

} /* fillScreenFirst */

#endif

/*
 * Fill - This routine handles the filling of the image.  If the image is
 * a bitmap, we simply do a flood fill on the xorbitmap.  For icons and
 * cursors we have to consider the AND bitmap and the potential of screen
 * colours to screw us up.
 */
void Fill( fill_info_struct *fillinfo, img_node *node )
{
    int         fillcase;
    HCURSOR     prev_cursor;

    prev_cursor = _wpi_setcursor( _wpi_getsyscursor(IDC_WAIT) );
    fillcase = getFillCase( fillinfo, node );

    switch( fillcase ) {
    case NORMAL_FILL:
        fillNormal( fillinfo, node );
        break;

    case DIFFERENT_FILL:
        fillScreenFirst( fillinfo, node );
        break;

    default:
        WImgEditError( WIE_ERR_BAD_FILLCASE, WIE_INTERNAL_003 );
        break;
    }
    _wpi_setcursor( prev_cursor );

} /* Fill */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -