/* * IEStretchBlt */ static BOOL IEStretchBlt( WPI_PRES hdcDest, int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest, WPI_PRES hdcSrc, int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc, DWORD fdwRop, int bitcount ) { POINT slines; POINT dlines; POINT num_strips; unsigned long linesize; int x, y; int sw, sh, dw, dh; WPI_PRES srcpres; HDC srcdc; HBITMAP oldbitmap; HBITMAP newbitmap; num_strips.x = nWidthDest / 256; num_strips.x++; #if 0 if( nWidthDest > 32 ) { /* use the version that returns exact bytes needed for bits */ linesize = BITS_INTO_BYTES( (unsigned long)(nWidthDest * bitcount), 1 ); } else { /* use the version that rounds up to 32 bits */ linesize = BITS_TO_BYTES( (unsigned long)(nWidthDest * bitcount), 1 ); } #else /* use the version that rounds up to 32 bits */ linesize = BITS_TO_BYTES( (unsigned long)(nWidthDest * bitcount), 1 ); #endif num_strips.y = ((unsigned long)nHeightDest * linesize) / (16 * 1024); num_strips.y++; if( num_strips.x > nWidthSrc ) { num_strips.x = nWidthSrc; } else if( num_strips.x < nWidthSrc ) { num_strips.x += num_strips.x % 2; } if( num_strips.y > nHeightSrc ) { num_strips.y = nHeightSrc; } else if( num_strips.y < nHeightSrc ) { num_strips.y += num_strips.y % 2; } slines.x = nWidthSrc / num_strips.x; dlines.x = ((unsigned long)slines.x * (unsigned long)nWidthDest) / (unsigned long)nWidthSrc; slines.y = nHeightSrc / num_strips.y; dlines.y = ((unsigned long)slines.y * (unsigned long)nHeightDest) / (unsigned long)nHeightSrc; srcpres = _wpi_createcompatiblepres( hdcDest, Instance, &srcdc ); newbitmap = _wpi_createcompatiblebitmap( hdcDest, dlines.x, dlines.y ); oldbitmap = _wpi_selectobject( srcpres, newbitmap ); sw = slines.x; dw = dlines.x; for( x = 0; slines.x * x <= nWidthSrc; x++ ) { if( slines.x * x + sw > nWidthSrc ) { sw = nWidthSrc - x * slines.x; dw = nWidthDest - x * dlines.x; } sh = slines.y; dh = dlines.y; for( y = 0; slines.y * y <= nHeightSrc; y++ ) { if( slines.y * y + sh > nHeightSrc ) { sh = nHeightSrc - y * slines.y; dh = nHeightDest - y * dlines.y; } _wpi_stretchblt( srcpres, 0, 0, dw, dh, hdcSrc, nXOriginSrc + slines.x * x, nYOriginSrc + slines.y * y, sw, sh, fdwRop ); _wpi_bitblt( hdcDest, nXOriginDest + dlines.x * x, nYOriginDest + dlines.y * y, dw, dh, srcpres, 0, 0, SRCCOPY ); } } _wpi_selectobject( srcpres, oldbitmap ); _wpi_deleteobject( newbitmap ); _wpi_deletecompatiblepres( srcpres, srcdc ); return( TRUE ); } /* IEStretchBlt */
/* * FlipImage - flip 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 == NULL ) { 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, ColorPlanes, 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 */
/* * PasteImage - paste the image in the clipboard at the current point * - first check to see if the image was cut/copied from our program * - if it was, then we use the hXorClipped and hAndClipped bitmaps * we created in order to preserve the screen colors if ther were used * - otherwise, just copy from the clipboard */ void PasteImage( WPI_POINT *pt, WPI_POINT pointsize, HWND hwnd ) { HBITMAP hbitmap; HBITMAP hbitmapdup; HBITMAP holddup; HBITMAP oldbitmap; HBITMAP oldbitmap2; WPI_PRES pres; WPI_PRES mempres; HDC memdc; WPI_PRES clippres; HDC clipdc; WPI_RECT client; WPI_POINT truept; short width; short height; short clipwidth; short clipheight; img_node *node; int fstretchbmp; int bm_width, bm_height; WPI_RECTDIM left; WPI_RECTDIM right; WPI_RECTDIM top; WPI_RECTDIM bottom; WPI_RECTDIM client_l; WPI_RECTDIM client_r; WPI_RECTDIM client_t; WPI_RECTDIM client_b; #ifdef __OS2_PM__ int src_y, dest_y; #endif if( fEnableCutCopy ) { _wpi_getwrectvalues( clipRect.rect, &left, &top, &right, &bottom ); truept.x = left; truept.y = top; fstretchbmp = StretchPastedImage(); } else { truept.x = pt->x / pointsize.x; truept.y = pt->y / pointsize.y; fstretchbmp = -1; } node = SelectImage( hwnd ); pres = _wpi_getpres( node->viewhwnd ); if( _wpi_getclipboardowner( Instance ) == HMainWindow && node->imgtype != BITMAP_IMG ) { _wpi_getbitmapdim( hAndClipped, &bm_width, &bm_height ); GetClientRect( node->hwnd, &client ); if( fEnableCutCopy ) { width = (short)_wpi_getwidthrect( clipRect.rect ); height = (short)_wpi_getheightrect( clipRect.rect ); } else { _wpi_getrectvalues( client, &client_l, &client_t, &client_r, &client_b ); width = (short)( client_r / pointsize.x - truept.x ); if( width > (short)bm_width ) width = (short)bm_width; height = (short)( client_b / pointsize.y - truept.y ); if( height > (short)bm_height ) { height = (short)bm_height; } } mempres = _wpi_createcompatiblepres( pres, Instance, &memdc ); _wpi_setstretchbltmode( mempres, COLORONCOLOR ); clippres = _wpi_createcompatiblepres( pres, Instance, &clipdc ); oldbitmap = _wpi_selectbitmap( mempres, node->handbitmap ); oldbitmap2 = _wpi_selectbitmap( clippres, hAndClipped ); if( fstretchbmp == FALSE ) { clipwidth = (short)bm_width; if( clipwidth > (short)width ) clipwidth = (short)width; clipheight = (short)bm_height; if( clipheight > (short)height ) clipheight = (short)height; _wpi_patblt( mempres, truept.x, truept.y, width, height, BLACKNESS ); _wpi_bitblt( mempres, truept.x, truept.y, clipwidth, clipheight, clippres, 0, 0, SRCCOPY ); } else if( fstretchbmp == TRUE ) { _wpi_stretchblt( mempres, truept.x, truept.y, width, height, clippres, 0, 0, bm_width, bm_height, SRCCOPY); } else { _wpi_bitblt( mempres, truept.x, truept.y, width, height, clippres, 0, 0, SRCCOPY ); } _wpi_getoldbitmap( mempres, oldbitmap ); oldbitmap = _wpi_selectbitmap( mempres, node->hxorbitmap ); hbitmapdup = DuplicateBitmap( hXorClipped ); _wpi_getoldbitmap( clippres, oldbitmap2 ); oldbitmap2 = _wpi_selectbitmap( clippres, hbitmapdup ); if( fstretchbmp == FALSE ) { clipwidth = (short)bm_width; if( clipwidth > (short)width ) clipwidth = (short)width; clipheight = (short)bm_height; if( clipheight > (short)height ) clipheight = (short)height; _wpi_patblt( mempres, truept.x, truept.y, width, height, WHITENESS ); #ifdef __OS2_PM__ if( bm_height > height ) { src_y = bm_height - height; dest_y = truept.y; } else { src_y = 0; dest_y = truept.y + (height - bm_height); } _wpi_bitblt( mempres, truept.x, dest_y, clipwidth, clipheight, clippres, 0, src_y, SRCCOPY ); #else _wpi_bitblt( mempres, truept.x, truept.y, clipwidth, clipheight, clippres, 0, 0, SRCCOPY ); #endif } else if( fstretchbmp == TRUE ) { _wpi_stretchblt( mempres, truept.x, truept.y, width, height, clippres, 0, 0, bm_width, bm_height, SRCCOPY ); } else { _wpi_bitblt( mempres, truept.x, truept.y, width, height, clippres, 0, 0, SRCCOPY ); } _wpi_getoldbitmap( mempres, oldbitmap ); _wpi_getoldbitmap( clippres, oldbitmap2 ); _wpi_deletebitmap( hbitmapdup ); _wpi_deletecompatiblepres( mempres, memdc ); _wpi_deletecompatiblepres( clippres, clipdc ); } else { if( node->imgtype != BITMAP_IMG ) { CleanupClipboard(); } _wpi_openclipboard( Instance, HMainWindow ); hbitmap = _wpi_getclipboarddata( Instance, CF_BITMAP ); hbitmapdup = DuplicateBitmap( hbitmap ); _wpi_closeclipboard( Instance ); _wpi_getbitmapdim( hbitmapdup, &bm_width, &bm_height ); GetClientRect( node->hwnd, &client ); if( fEnableCutCopy ) { width = (short)_wpi_getwidthrect( clipRect.rect ); height = (short)_wpi_getheightrect( clipRect.rect ); } else { _wpi_getrectvalues( client, &client_l, &client_t, &client_r, &client_b ); width = (short)( client_r / pointsize.x - truept.x ); if( width > (short)bm_width ) width = (short)bm_width; height = (short)( client_b / pointsize.y - truept.y ); if( height > (short)bm_height ) { height = (short)bm_height; } } clippres = _wpi_createcompatiblepres( pres, Instance, &clipdc ); mempres = _wpi_createcompatiblepres( pres, Instance, &memdc ); _wpi_setstretchbltmode( mempres, COLORONCOLOR ); holddup = _wpi_selectbitmap( clippres, hbitmapdup ); oldbitmap = _wpi_selectbitmap( mempres, node->hxorbitmap ); if( fstretchbmp == FALSE ) { clipwidth = (short)bm_width; if( clipwidth > (short)width ) clipwidth = (short)width; clipheight = (short)bm_height; if( clipheight > (short)height ) clipheight = (short)height; _wpi_patblt( mempres, truept.x, truept.y, width, height, WHITENESS ); #ifdef __OS2_PM__ if( bm_height > height ) { src_y = bm_height - height; dest_y = truept.y; } else { src_y = 0; dest_y = truept.y + (height - bm_height); } _wpi_bitblt( mempres, truept.x, dest_y, clipwidth, clipheight, clippres, 0, src_y, SRCCOPY ); #else _wpi_bitblt( mempres, truept.x, truept.y, clipwidth, clipheight, clippres, 0, 0, SRCCOPY ); #endif } else if( fstretchbmp == TRUE ) { _wpi_stretchblt( mempres, truept.x, truept.y, width, height, clippres, 0, 0, bm_width, bm_height, SRCCOPY ); } else { _wpi_bitblt( mempres, truept.x, truept.y, width, height, clippres, 0, 0, SRCCOPY ); } _wpi_getoldbitmap( clippres, holddup ); _wpi_deletebitmap( hbitmapdup ); _wpi_deletecompatiblepres( clippres, clipdc ); _wpi_getoldbitmap( mempres, oldbitmap ); oldbitmap = _wpi_selectbitmap( mempres, node->handbitmap ); _wpi_patblt( mempres, truept.x, truept.y, width, height, BLACKNESS ); _wpi_getoldbitmap( mempres, oldbitmap ); _wpi_deletecompatiblepres( mempres, memdc ); } ReleaseCapture(); _wpi_releasepres( node->viewhwnd, pres ); InvalidateRect( node->viewhwnd, NULL, TRUE ); if( !fEnableCutCopy ) { _wpi_setcursor( prevCursor ); _wpi_destroycursor( pointCursor ); SetToolType( prevToolType ); } fEnableCutCopy = FALSE; RecordImage( hwnd ); BlowupImage( NULL, NULL ); PrintHintTextByID( WIE_BITMAPPASTED, NULL ); } /* PasteImage */
/* * stretchIntoArea - stretch 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 ); _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_COLOR ); _wpi_stretchblt( xorpres, left, top, width, height, rotxorpres, 0, 0, height, width, SRCCOPY ); _wpi_setstretchbltmode( andpres, STRETCH_COLOR ); _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 */
/* * ChangeImageSize - changes the size of the current image being edited */ void ChangeImageSize( void ) { img_node *node; WPI_DLGPROC dlgproc; WPI_DLGRESULT button_type; img_node new_node; WPI_PRES pres; HDC srcdc; WPI_PRES srcpres; HDC destdc; WPI_PRES destpres; HBITMAP oldsrc; HBITMAP olddest; int retcode; WPI_PARAM2 lparam; WPI_RECT rc; short new_width; short new_height; int y_src; int y_dest; char *title; char *text; node = GetCurrentNode(); if( node == NULL ) { return; } if( node->imgtype != BITMAP_IMG ) { return; } imgHeight = node->height; imgWidth = node->width; dlgproc = _wpi_makedlgprocinstance( ChangeSizeDlgProc, Instance ); button_type = _wpi_dialogbox( HMainWindow, dlgproc, Instance, IMAGESIZE, 0L ); _wpi_freedlgprocinstance( dlgproc ); if( button_type == DLGID_CANCEL ) { return; } if( imgWidth == node->width && imgHeight == node->height ) { PrintHintTextByID( WIE_IMAGESIZEUNCHANGED, NULL ); return; } title = IEAllocRCString( WIE_INFORMATIONTEXT ); text = IEAllocRCString( WIE_RESETUNDOSTACKWARNING ); retcode = _wpi_messagebox( HMainWindow, text, title, MB_YESNO | MB_ICONINFORMATION ); if( text != NULL ) { IEFreeRCString( text ); } if( title != NULL ) { IEFreeRCString( title ); } if( retcode == WPI_IDNO ) { return; } new_node.width = (short)imgWidth; new_node.height = (short)imgHeight; new_node.bitcount = node->bitcount; new_node.imgtype = BITMAP_IMG; MakeBitmap( &new_node, TRUE ); pres = _wpi_getpres( HWND_DESKTOP ); srcpres = _wpi_createcompatiblepres( pres, Instance, &srcdc ); destpres = _wpi_createcompatiblepres( pres, Instance, &destdc ); _wpi_releasepres( HWND_DESKTOP, pres ); oldsrc = _wpi_selectbitmap( srcpres, node->hxorbitmap ); olddest = _wpi_selectbitmap( destpres, new_node.hxorbitmap ); if( stretchImage ) { _wpi_stretchblt( destpres, 0, 0, imgWidth, imgHeight, srcpres, 0, 0, node->width, node->height, SRCCOPY ); } else { #ifdef __OS2_PM__ y_src = node->height - imgHeight; if( y_src < 0 ) { y_src = 0; y_dest = imgHeight - node->height; } else { y_dest = 0; } #else y_src = 0; y_dest = 0; #endif _wpi_bitblt( destpres, 0, y_dest, node->width, node->height, srcpres, 0, y_src, SRCCOPY ); } _wpi_getoldbitmap( srcpres, oldsrc ); oldsrc = _wpi_selectbitmap( srcpres, node->handbitmap ); _wpi_getoldbitmap( destpres, olddest ); olddest = _wpi_selectbitmap( destpres, new_node.handbitmap ); if( stretchImage ) { _wpi_stretchblt( destpres, 0, 0, imgWidth, imgHeight, srcpres, 0, 0, node->width, node->height, SRCCOPY ); } else { _wpi_bitblt( destpres, 0, 0, node->width, node->height, srcpres, 0, 0, SRCCOPY ); } _wpi_getoldbitmap( srcpres, oldsrc ); _wpi_getoldbitmap( destpres, olddest ); _wpi_deletebitmap( node->hxorbitmap ); _wpi_deletebitmap( node->handbitmap ); _wpi_deletecompatiblepres( srcpres, srcdc ); _wpi_deletecompatiblepres( destpres, destdc ); node->hxorbitmap = new_node.hxorbitmap; node->handbitmap = new_node.handbitmap; node->width = (short)imgWidth; node->height = (short)imgHeight; SetIsSaved( node->hwnd, FALSE ); ResetUndoStack( node ); RePositionViewWnd( node ); _wpi_getclientrect( node->hwnd, &rc ); new_width = (short)_wpi_getwidthrect( rc ); new_height = (short)_wpi_getheightrect( rc ); lparam = WPI_MAKEP2( new_width, new_height ); ResizeChild( lparam, node->hwnd, false ); DisplayImageText( node ); WriteSetSizeText( WIE_NEWIMAGESIZE, imgWidth, imgHeight ); } /* ChangeImageSize */