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

📄 trnsform.c

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

    oldxor = _wpi_selectobject( xorpres, node->hxorbitmap );
    oldand = _wpi_selectobject( andpres, node->handbitmap );
    oldxorrot = _wpi_selectobject( rotxorpres, rotxorbmp );
    oldandrot = _wpi_selectobject( rotandpres, rotandbmp );

    _wpi_setstretchbltmode( xorpres, STRETCH_COLOUR );
    _wpi_stretchblt( xorpres, left, top, width, height, rotxorpres, 0, 0,
                                                    height, width, SRCCOPY );

    _wpi_setstretchbltmode( andpres, STRETCH_COLOUR );
    _wpi_stretchblt( andpres, left, top, width, height, rotandpres, 0, 0,
                                                    height, width, SRCCOPY );
    _wpi_selectobject( xorpres, oldxor );
    _wpi_selectobject( andpres, oldand );
    _wpi_selectobject( rotxorpres, oldxorrot );
    _wpi_selectobject( rotandpres, oldandrot );
    _wpi_deletecompatiblepres( xorpres, xordc );
    _wpi_deletecompatiblepres( andpres, anddc );
    _wpi_deletecompatiblepres( rotxorpres, rotxordc );
    _wpi_deletecompatiblepres( rotandpres, rotanddc );

    InvalidateRect( node->viewhwnd, NULL, TRUE );
    RecordImage(node->hwnd);
    BlowupImage( node->hwnd, NULL );
} /* stretchIntoArea */

/*
 * simpleRotate - simply rotates the image around the centre of the given
 *                rectangle.
 */
static void simpleRotate( img_node *node, WPI_RECT *rect, HBITMAP rotxorbmp,
                                HBITMAP rotandbmp, BOOL rectexists )
{
    WPI_POINT   topleft;
    WPI_POINT   centre_pt;
    WPI_PRES    pres;
    HDC         xordc;
    WPI_PRES    xorpres;
    HDC         anddc;
    WPI_PRES    andpres;
    HDC         rotxordc;
    WPI_PRES    rotxorpres;
    HDC         rotanddc;
    WPI_PRES    rotandpres;
    HBITMAP     oldxor;
    HBITMAP     oldand;
    HBITMAP     oldxorrot;
    HBITMAP     oldandrot;
    short       width;
    short       height;
    WPI_RECT    new_rect;
    IMGED_DIM   left;
    IMGED_DIM   top;
    IMGED_DIM   right;
    IMGED_DIM   bottom;

    width = (short)_wpi_getwidthrect( *rect );
    height = (short)_wpi_getheightrect( *rect );

    /*
     * PM NOTE:  The rectangle comes in with bottom = yTop and top = yBottom.
     * To use the same formula to calculate the centre pt and top left, we
     * use getwrectvalues.
     */
    _wpi_getwrectvalues( *rect, &left, &top, &right, &bottom );
    centre_pt.x = (width / 2) + left;
    centre_pt.y = (height / 2) + top;
    topleft.x = centre_pt.x - centre_pt.y + top;
    topleft.y = centre_pt.y - centre_pt.x + left;

    pres = _wpi_getpres( HWND_DESKTOP );
    xorpres = _wpi_createcompatiblepres( pres, Instance, &xordc );
    andpres = _wpi_createcompatiblepres( pres, Instance, &anddc );
    rotxorpres = _wpi_createcompatiblepres( pres, Instance, &rotxordc );
    rotandpres = _wpi_createcompatiblepres( pres, Instance, &rotanddc );
    _wpi_releasepres( HWND_DESKTOP, pres );

    _wpi_torgbmode( xorpres );
    _wpi_torgbmode( andpres );
    _wpi_torgbmode( rotxorpres );
    _wpi_torgbmode( rotandpres );

    oldxor = _wpi_selectobject( xorpres, node->hxorbitmap );
    oldand = _wpi_selectobject( andpres, node->handbitmap );
    oldxorrot = _wpi_selectobject( rotxorpres, rotxorbmp );
    oldandrot = _wpi_selectobject( rotandpres, rotandbmp );

    _wpi_getwrectvalues( *rect, &left, &top, &right, &bottom );
    _wpi_patblt( xorpres, left, top, width, height, WHITENESS );
    _wpi_patblt( andpres, left, top, width, height, BLACKNESS );

    _wpi_bitblt( xorpres, topleft.x, topleft.y, height, width, rotxorpres,
                                                            0, 0, SRCCOPY );
    _wpi_bitblt( andpres, topleft.x, topleft.y, height, width, rotandpres,
                                                            0, 0, SRCCOPY );

    _wpi_selectobject( xorpres, oldxor );
    _wpi_selectobject( andpres, oldand );
    _wpi_selectobject( rotxorpres, oldxorrot );
    _wpi_selectobject( rotandpres, oldandrot );
    _wpi_deletecompatiblepres( xorpres, xordc );
    _wpi_deletecompatiblepres( andpres, anddc );
    _wpi_deletecompatiblepres( rotxorpres, rotxordc );
    _wpi_deletecompatiblepres( rotandpres, rotanddc );

    InvalidateRect( node->viewhwnd, NULL, TRUE );
    RecordImage(node->hwnd);
    if ( DoKeepRect() ) {
        if (rectexists) {
            _wpi_setwrectvalues( &new_rect, topleft.x, topleft.y,
                                        topleft.x+height, topleft.y+width );
            SetDeviceClipRect( &new_rect );
        }
    } else {
        rectexists = rectexists;
        new_rect = new_rect;
        SetRectExists( FALSE );
    }

    BlowupImage( node->hwnd, NULL );
} /* simpleRotate */

static void IEPrintRotateAmt( int amt )
{
    IEPrintAmtText( WIE_ROTATIONPERCENT, amt );
}

/*
 * rotateTheImage - creates the rotated bitmaps
 */
static void rotateTheImage( img_node *node, int whichway, WPI_RECT *rect,
                                HBITMAP rotxorbmp, HBITMAP rotandbmp )
{
    WPI_PRES    pres;
    WPI_PRES    rotxorpres;
    HDC         rotxordc;
    WPI_PRES    xorpres;
    HDC         xordc;
    WPI_PRES    rotandpres;
    HDC         rotanddc;
    HBITMAP     oldandrot;
    HBITMAP     oldxorrot;
    HBITMAP     oldxor;
    short       new_height;
    short       new_width;
    long        i;
    long        amt_done;
    long        prev_amt;
    long        total_amt;
    long        temp;
    IMGED_DIM   left;
    IMGED_DIM   top;
    IMGED_DIM   right;
    IMGED_DIM   bottom;
    int         x;
    int         y;
    COLORREF    colour;
    bitmap_bits *xorbits;
    bitmap_bits *andbits;
    bitmap_bits *rotxorbits;
    bitmap_bits *rotandbits;

    new_height = (short)_wpi_getwidthrect( *rect );
    new_width = (short)_wpi_getheightrect( *rect );
    oldxor = NULL;

    amt_done = prev_amt = 0L;
    total_amt = (long)new_height * (long)new_width;
    i = 0L;
    _wpi_getwrectvalues(*rect, &left, &top, &right, &bottom);

    if (node->imgtype == BITMAP_IMG) {
        pres = _wpi_getpres( HWND_DESKTOP );
        xorpres = _wpi_createcompatiblepres( pres, Instance, &xordc );
        rotxorpres = _wpi_createcompatiblepres( pres, Instance, &rotxordc );
        rotandpres = _wpi_createcompatiblepres( pres, Instance, &rotanddc );
        _wpi_releasepres( HWND_DESKTOP, pres );

        _wpi_torgbmode( rotxorpres );
        _wpi_torgbmode( rotandpres );
        oldxorrot = _wpi_selectobject( rotxorpres, rotxorbmp );
        oldandrot = _wpi_selectobject( rotandpres, rotandbmp );

        _wpi_patblt( rotxorpres, 0, 0, new_width, new_height, WHITENESS );
        _wpi_patblt( rotandpres, 0, 0, new_width, new_height, BLACKNESS );
        _wpi_selectobject( rotxorpres, oldxorrot );
        _wpi_selectobject( rotandpres, oldandrot );
        _wpi_deletecompatiblepres( rotandpres, rotanddc );

        _imged_getthebits( xorbits, xorpres, node->hxorbitmap, oldxor );
        _imged_getthebits( rotxorbits, rotxorpres, rotxorbmp, oldxorrot );
        if (whichway == ROTATE_COUNTERCLOCKWISE) {
            for (y=0; y < new_height; ++y) {
                for (x=0; x < new_width; ++x) {

                    colour = _imged_getpixel( xorbits, xorpres, right - y - 1,
                                                                top + x );
                    _imged_setpixel( rotxorbits, rotxorpres, x, y, colour );

                    ++i;
                    temp = i * 100;
                    amt_done = temp / total_amt;
                    if (amt_done - prev_amt >= 2) {
                        IEPrintRotateAmt( amt_done );
                        prev_amt = amt_done;
                    }
                }
            }
        } else {
            for (y=0; y < new_height; ++y) {
                for (x=0; x < new_width; ++x) {
                    colour = _imged_getpixel( xorbits, xorpres, left + y,
                                                            bottom - x - 1 );
                    _imged_setpixel( rotxorbits, rotxorpres, x, y, colour );
                    ++i;
                    temp = i * 100;
                    amt_done = temp / total_amt;
                    if (amt_done - prev_amt >= 2) {
                        IEPrintRotateAmt( amt_done );
                        prev_amt = amt_done;
                    }
                }
            }
        }
        _imged_freethebits( xorbits, xorpres, node->hxorbitmap, FALSE, oldxor);
        _imged_freethebits(rotxorbits, rotxorpres, rotxorbmp, TRUE, oldxorrot);
        _wpi_deletecompatiblepres( xorpres, xordc );
        _wpi_deletecompatiblepres( rotxorpres, rotxordc );

    } else {
        // We can use the bits.c routines for icons and cursors.
        xorbits = GetTheBits( node->hxorbitmap );
        andbits = GetTheBits( node->handbitmap );
        rotxorbits = GetTheBits( rotxorbmp );
        rotandbits = GetTheBits( rotandbmp );

        if( whichway != IMGED_ROTATECC ) {
            for (y=0; y < new_height; ++y) {
                for (x=0; x < new_width; ++x) {
                    colour = MyGetPixel( xorbits, right - y - 1, top + x );
                    MySetPixel( rotxorbits, x, y, colour );

                    colour = MyGetPixel( andbits, right - y - 1, top + x );
                    MySetPixel( rotandbits, x, y, colour );
                    ++i;
                    temp = i * 100;
                    amt_done = temp / total_amt;
                    if (amt_done - prev_amt >= 2) {
                        IEPrintRotateAmt( amt_done );
                        prev_amt = amt_done;
                    }
                }
            }
        } else {
            for (y=0; y < new_height; ++y) {
                for (x=0; x < new_width; ++x) {
                    colour = MyGetPixel( xorbits, left + y, bottom - x - 1 );
                    MySetPixel( rotxorbits, x, y, colour );

                    colour = MyGetPixel( andbits, left + y, bottom - x - 1 );
                    MySetPixel( rotandbits, x, y, colour );
                    ++i;
                    temp = i * 100;
                    amt_done = temp / total_amt;
                    if (amt_done - prev_amt >= 2) {
                        IEPrintRotateAmt( amt_done );
                        prev_amt = amt_done;
                    }
                }
            }
        }
        FreeTheBits( xorbits, node->hxorbitmap, FALSE );
        FreeTheBits( andbits, node->handbitmap, FALSE );
        FreeTheBits( rotxorbits, rotxorbmp, TRUE );
        FreeTheBits( rotandbits, rotandbmp, TRUE );
    }
} /* rotateTheImage */

/*
 * RotateImage - rotates the image counter clockwise either clockwise or
 *               counter clockwise.
 */
void RotateImage( WORD whichway )
{
    img_node    *node;
    HBITMAP     rotxorbmp;
    HBITMAP     rotandbmp;
    HCURSOR     prevcursor;
    int         rotate_type;
    WPI_RECT    rotate_rect;

⌨️ 快捷键说明

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