📄 trnsform.c
字号:
/****************************************************************************
*
* 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"
#include <string.h>
#include "settings.h"
/*
* FlipImage - flips the image along either the x-axis or the y-axis.
*/
void FlipImage( WORD whichway )
{
img_node *node;
short width;
short height;
short destwidth;
short destheight;
short new_left;
short new_top;
WPI_RECT dims;
HBITMAP xorflip;
HBITMAP oldflip;
HBITMAP oldbitmap;
HBITMAP andflip;
WPI_PRES pres;
WPI_PRES mempres;
HDC memdc;
WPI_PRES flippres;
HDC flipdc;
HCURSOR prevcursor;
IMGED_DIM bottom;
IMGED_DIM left;
IMGED_DIM right;
IMGED_DIM top;
node = GetCurrentNode();
if (!node) return;
PrintHintTextByID( WIE_FLIPPINGIMAGE, NULL );
prevcursor = _wpi_setcursor( _wpi_getsyscursor(IDC_WAIT) );
if ( !(DoesRectExist(&dims)) ) {
_wpi_setwrectvalues( &dims, 0, 0, (IMGED_DIM)node->width,
(IMGED_DIM)node->height );
}
width = (short)_wpi_getwidthrect( dims );
height = (short)_wpi_getheightrect( dims );
pres = _wpi_getpres( HWND_DESKTOP );
if (node->bitcount == 1) {
xorflip = _wpi_createbitmap( width, height, 1, 1, NULL );
} else {
#if 1
xorflip = _wpi_createcompatiblebitmap( pres, width, height );
#else
xorflip = _wpi_createbitmap( width, height, ColourPlanes, BitsPerPixel,
NULL );
#endif
}
andflip = _wpi_createbitmap( width, height, 1, 1, NULL );
mempres = _wpi_createcompatiblepres( pres, Instance, &memdc );
flippres = _wpi_createcompatiblepres( pres, Instance, &flipdc );
_wpi_releasepres( HWND_DESKTOP, pres );
_wpi_getrectvalues( dims, &left, &top, &right, &bottom );
_wpi_preparemono( flippres, BLACK, WHITE );
oldbitmap = _wpi_selectobject( mempres, node->hxorbitmap );
oldflip = _wpi_selectobject( flippres, xorflip );
_wpi_bitblt( flippres, 0, 0, width, height, mempres, left, top, SRCCOPY );
_wpi_selectobject( mempres, oldbitmap );
_wpi_selectobject( flippres, oldflip );
oldbitmap = _wpi_selectobject( mempres, node->handbitmap );
oldflip = _wpi_selectobject( flippres, andflip );
_wpi_bitblt( flippres, 0, 0, width, height, mempres, left, top, SRCCOPY );
if (whichway == IMGED_FLIPVERT) {
destwidth = -1 * width;
new_left = right - 1;
new_top = top;
destheight = height;
} else {
destwidth = width;
new_left = left;
new_top = bottom - 1;
destheight = -1 * height;
}
_wpi_stretchblt( mempres, new_left, new_top, destwidth, destheight,
flippres, 0, 0, width, height, SRCCOPY );
_wpi_selectobject( mempres, oldbitmap );
oldbitmap = _wpi_selectobject( mempres, node->hxorbitmap );
_wpi_selectobject( flippres, oldflip );
oldflip = _wpi_selectobject( flippres, xorflip );
_wpi_stretchblt( mempres, new_left, new_top, destwidth, destheight,
flippres, 0, 0, width, height, SRCCOPY );
_wpi_selectobject( mempres, oldbitmap );
_wpi_selectobject( flippres, oldflip );
_wpi_deleteobject( xorflip );
_wpi_deleteobject( andflip );
_wpi_deletecompatiblepres( mempres, memdc );
_wpi_deletecompatiblepres( flippres, flipdc );
InvalidateRect( node->viewhwnd, NULL, TRUE );
if( !DoKeepRect() ) {
SetRectExists( FALSE );
}
RecordImage(node->hwnd);
BlowupImage( node->hwnd, NULL );
if( whichway == IMGED_FLIPHORZ ) {
PrintHintTextByID( WIE_IMAGEREFLECTEDH, NULL );
} else {
PrintHintTextByID( WIE_IMAGEREFLECTEDV, NULL );
}
_wpi_setcursor( prevcursor );
} /* FlipImage */
/*
* clipIntoArea - clips the bitmaps into the area when rotating
*/
static void clipIntoArea( img_node *node, WPI_RECT *rect, HBITMAP rotxorbmp,
HBITMAP rotandbmp )
{
WPI_PRES pres;
WPI_PRES xorpres;
HDC xordc;
WPI_PRES andpres;
HDC anddc;
WPI_PRES rotxorpres;
HDC rotxordc;
WPI_PRES rotandpres;
HDC rotanddc;
HBITMAP oldxor;
HBITMAP oldand;
HBITMAP oldxorrot;
HBITMAP oldandrot;
short width;
short height;
WPI_POINT centre_pt;
WPI_POINT topleft;
short start_x;
short start_y;
short new_width;
short new_height;
IMGED_DIM left;
IMGED_DIM right;
IMGED_DIM top;
IMGED_DIM bottom;
width = (short)_wpi_getwidthrect( *rect );
height = (short)_wpi_getheightrect( *rect );
/*
* PM NOTE: We use getwrectvalues so that 'topleft' can really be
* replace with 'bottomleft' (which is our origin for blitting in PM).
* Hence the value of 'top' is really the bottom of our rectangle.
*/
_wpi_getwrectvalues( *rect, &left, &top, &right, &bottom );
centre_pt.x = (width / 2) + left;
centre_pt.y = (height / 2) + top;
topleft.x = max( left, centre_pt.x - centre_pt.y + top );
topleft.y = max( top, centre_pt.y - centre_pt.x + left );
if (topleft.x == left) {
start_x = (short)(left - (centre_pt.x - centre_pt.y + top));
new_width = width;
} else {
start_x = 0;
new_width = height;
}
if (topleft.y == top) {
start_y = (short)(top - (centre_pt.y - centre_pt.x + left));
new_height = height;
} else {
start_y = 0;
new_height = width;
}
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_patblt( xorpres, left, top, width, height, WHITENESS );
_wpi_patblt( andpres, left, top, width, height, BLACKNESS );
_wpi_bitblt( xorpres, topleft.x, topleft.y, new_width, new_height,
rotxorpres, start_x, start_y, SRCCOPY );
_wpi_bitblt( andpres, topleft.x, topleft.y, new_width, new_height,
rotandpres, start_x, start_y, 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 );
} /* clipIntoArea */
/*
* stretchIntoArea - stretches the rotated image into the area specified.
*/
static void stretchIntoArea( img_node *node, WPI_RECT *rect,
HBITMAP rotxorbmp, HBITMAP rotandbmp )
{
WPI_PRES pres;
WPI_PRES xorpres;
HDC xordc;
WPI_PRES andpres;
HDC anddc;
WPI_PRES rotxorpres;
HDC rotxordc;
WPI_PRES rotandpres;
HDC rotanddc;
HBITMAP oldxor;
HBITMAP oldand;
HBITMAP oldxorrot;
HBITMAP oldandrot;
short width;
short height;
IMGED_DIM left;
IMGED_DIM right;
IMGED_DIM bottom;
IMGED_DIM top;
width = (short)_wpi_getwidthrect( *rect );
height = (short)_wpi_getheightrect( *rect );
_wpi_getwrectvalues( *rect, &left, &top, &right, &bottom );
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 );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -