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

📄 fill.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************
*
*                            Open Watcom Project
*
*    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
*  ========================================================================
*
*    This file contains Original Code and/or Modifications of Original
*    Code as defined in and that are subject to the Sybase Open Watcom
*    Public License version 1.0 (the 'License'). You may not use this file
*    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
*    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
*    provided with the Original Code and Modifications, and is also
*    available at www.sybase.com/developer/opensource.
*
*    The Original Code and all software distributed under the License are
*    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
*    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
*    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
*    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
*    NON-INFRINGEMENT. Please see the License for the specific language
*    governing rights and limitations under the License.
*
*  ========================================================================
*
* Description:  WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
*               DESCRIBE IT HERE!
*
****************************************************************************/


#include "imgedit.h"

/*
 * makeBiggerBitmap - makes a bitmap 1 pixel wider and 1 higher than that
 *                    of the given bitmap
 */
static HBITMAP makeBiggerBitmap( HBITMAP hbitmap, WPI_POINT *pt )
{
    WPI_PRES    pres;
    WPI_PRES    srcpres;
    HDC         srcdc;
    WPI_PRES    destpres;
    HDC         destdc;
    HBITMAP     newbitmap;
    HBITMAP     oldsrcbmp;
    HBITMAP     olddestbmp;
    int         bmwidth;
    int         bmheight;
    int         bmplanes;
    int         bmbitspixel;

    _wpi_getbitmapparms( hbitmap, &bmwidth, &bmheight, &bmplanes, NULL,
                                                        &bmbitspixel );
    newbitmap = _wpi_createbitmap(bmwidth+1, bmheight+1, bmplanes, bmbitspixel,
                                                                        NULL );
    pres = _wpi_getpres( HWND_DESKTOP );
    srcpres = _wpi_createcompatiblepres( pres, Instance, &srcdc );
    destpres = _wpi_createcompatiblepres( pres, Instance, &destdc );
    _wpi_releasepres( HWND_DESKTOP, pres );
    _wpi_torgbmode( srcpres );
    _wpi_torgbmode( destpres );

    olddestbmp = _wpi_selectobject( destpres, newbitmap );
    oldsrcbmp = _wpi_selectobject( srcpres, hbitmap );

    if ( _wpi_getpixel(srcpres, pt->x, pt->y) == BLACK ) {
        _wpi_patblt( destpres, 0, 0, bmwidth+1, bmheight+1, WHITENESS );
    } else {
        _wpi_patblt( destpres, 0, 0, bmwidth+1, bmheight+1, BLACKNESS );
    }
    /*
     * put the old bitmap in the top left corner of our new bitmap
     * (bottom left for PM)
     */
    _wpi_bitblt( destpres, 0, 0, bmwidth, bmheight, srcpres, 0, 0, SRCCOPY );
    _wpi_selectobject( destpres, olddestbmp );
    _wpi_selectobject( srcpres, oldsrcbmp );
    _wpi_deletecompatiblepres( destpres, destdc );
    _wpi_deletecompatiblepres( srcpres, srcdc );

    return( newbitmap );
} /* makeBiggerBitmap */

/*
 * getFillCase - There are a number of different possible cases when filling
 *               an image.  This routine determines which case we are in.
 */
static int getFillCase( fill_info_struct *fillinfo, img_node *node )
{
    WPI_PRES    pres;
    WPI_PRES    andpres;
    HDC         anddc;
    WPI_PRES    xorpres;
    HDC         xordc;
    HBITMAP     oldbitmap;
    COLORREF    andpixel;
    COLORREF    xorpixel;

    if (fillinfo->img_type == BITMAP_IMG) {
        return( NORMAL_FILL );
    }

    pres = _wpi_getpres( HWND_DESKTOP );
    andpres = _wpi_createcompatiblepres( pres, Instance, &anddc );
    _wpi_releasepres( HWND_DESKTOP, pres );
    _wpi_torgbmode( andpres );

    oldbitmap = _wpi_selectobject( andpres, node->handbitmap );
    andpixel = _wpi_getpixel( andpres, fillinfo->pt.x, fillinfo->pt.y );
    _wpi_selectobject( andpres, oldbitmap );
    _wpi_deletecompatiblepres( andpres, anddc );

    if (andpixel == BLACK) {
        pres = _wpi_getpres( HWND_DESKTOP );
        xorpres = _wpi_createcompatiblepres( pres, Instance, &xordc );
        _wpi_releasepres( HWND_DESKTOP, pres );
        _wpi_torgbmode( xorpres );

        oldbitmap = _wpi_selectobject( xorpres, node->hxorbitmap );
        xorpixel = _wpi_getpixel( xorpres, fillinfo->pt.x, fillinfo->pt.y );
        _wpi_selectobject( xorpres, oldbitmap );
        _wpi_deletecompatiblepres( xorpres, xordc );
        if (xorpixel == BLACK || xorpixel == WHITE) {
            return( DIFFERENT_FILL );
        }
        if ( fillinfo->colourtype == NORMAL_CLR ) {
            return( NORMAL_FILL );
        } else {
            return (DIFFERENT_FILL);
        }
    } else {
        return( DIFFERENT_FILL );
    }
} /* getFillCase */

/*
 * fillNormal - This routine just does a normal fill on the xorbitmap and
 *              leaves the and bitmap alone.
 */
static void fillNormal( fill_info_struct *fillinfo, img_node *node )
{
    WPI_PRES    pres;
    WPI_PRES    xormempres;
    HDC         xormemdc;
    WPI_PRES    dupmempres;
    HDC         dupmemdc;
    HBRUSH      oldbrush;
    HBRUSH      hbrush;
    HBITMAP     oldxorbmp;
    HBITMAP     oldbitmap;
    HBITMAP     bigbitmap;

    pres = _wpi_getpres( HWND_DESKTOP );
    xormempres = _wpi_createcompatiblepres( pres, Instance, &xormemdc );
    dupmempres = _wpi_createcompatiblepres( pres, Instance, &dupmemdc );
    _wpi_releasepres( HWND_DESKTOP, pres );

    /*
     * Because ExtFloodFill seems to screw up on the right side of the
     * bitmap, I create a bitmap 1 bigger on the right, and fill with
     * another colour (black or white) so that we can avoid the right
     * side screw up thing.
     */
    bigbitmap = makeBiggerBitmap( node->hxorbitmap, &(fillinfo->pt) );

    _wpi_torgbmode( dupmempres );
    _wpi_torgbmode( xormempres );
    hbrush = _wpi_createsolidbrush( fillinfo->xorcolour );
    oldbrush = _wpi_selectobject( dupmempres, hbrush );
    oldbitmap = _wpi_selectobject( dupmempres, bigbitmap );

    _wpi_extfloodfill( dupmempres, fillinfo->pt.x, fillinfo->pt.y,
                        _wpi_getpixel(dupmempres, fillinfo->pt.x,
                        fillinfo->pt.y), FLOODFILLSURFACE );

    oldxorbmp = _wpi_selectobject( xormempres, node->hxorbitmap );

    _wpi_bitblt( xormempres, 0, 0, node->width, node->height, dupmempres,
                                                            0, 0, SRCCOPY );

    _wpi_selectobject( dupmempres, oldbrush );
    _wpi_deleteobject( hbrush );
    _wpi_selectobject( xormempres, oldxorbmp );
    _wpi_deletecompatiblepres( xormempres, xormemdc );
    _wpi_selectobject( dupmempres, oldbitmap );
    _wpi_deletecompatiblepres( dupmempres, dupmemdc );
    _wpi_deletebitmap( bigbitmap );
} /* fillNormal */

#ifdef __OS2_PM__
/*
 * 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.
 *                   PM version
 */
static void fillScreenFirst( fill_info_struct *fillinfo, img_node *node )
{
    WPI_PRES    pres;
    HDC         screendc;
    WPI_PRES    screenpres;
    HBRUSH      oldbrush;
    HBRUSH      hbrush;
    HBITMAP     screenbitmap;
    HBITMAP     screendup;
    HBITMAP     oldscreen;
    HBITMAP     bigbitmap;      // bigger bitmap we actually fill
    COLORREF    fillcolour;
    BOOL        screenchanged;
    short       x,y;
    bitmap_bits *xorbits;
    bitmap_bits *screenbeforebits;
    bitmap_bits *screenbits;
    bitmap_bits *andbits;

    /*
     * 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) );

⌨️ 快捷键说明

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