mirror of
https://github.com/reactos/reactos.git
synced 2025-08-04 23:45:42 +00:00
[MSPAINT] Implement skew (#4362)
- Add SkewDIB helper function in dib.cpp. - Implement Stretch and Skew feature by SelectionModel::StretchSkew and ImageModel::StretchSkew. - Move ColorKeyedMaskBlt function. CORE-16634
This commit is contained in:
parent
2d90919047
commit
dfd06ee8fc
9 changed files with 165 additions and 39 deletions
|
@ -9,6 +9,7 @@
|
|||
/* INCLUDES *********************************************************/
|
||||
|
||||
#include "precomp.h"
|
||||
#include <math.h>
|
||||
|
||||
/* FUNCTIONS ********************************************************/
|
||||
|
||||
|
@ -243,3 +244,58 @@ HBITMAP Rotate90DegreeBlt(HDC hDC1, INT cx, INT cy, BOOL bRight)
|
|||
DeleteDC(hDC2);
|
||||
return hbm2;
|
||||
}
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265
|
||||
#endif
|
||||
|
||||
HBITMAP SkewDIB(HDC hDC1, HBITMAP hbm, INT nDegree, BOOL bVertical)
|
||||
{
|
||||
if (nDegree == 0)
|
||||
return CopyDIBImage(hbm);
|
||||
|
||||
const double eTan = tan(abs(nDegree) * M_PI / 180);
|
||||
|
||||
BITMAP bm;
|
||||
GetObjectW(hbm, sizeof(bm), &bm);
|
||||
INT cx = bm.bmWidth, cy = bm.bmHeight, dx = 0, dy = 0;
|
||||
if (bVertical)
|
||||
dy = INT(cx * eTan);
|
||||
else
|
||||
dx = INT(cy * eTan);
|
||||
|
||||
if (dx == 0 && dy == 0)
|
||||
return CopyDIBImage(hbm);
|
||||
|
||||
HBITMAP hbmNew = CreateColorDIB(cx + dx, cy + dy, RGB(255, 255, 255));
|
||||
if (!hbmNew)
|
||||
return NULL;
|
||||
|
||||
HDC hDC2 = CreateCompatibleDC(NULL);
|
||||
HGDIOBJ hbm2Old = SelectObject(hDC2, hbmNew);
|
||||
if (bVertical)
|
||||
{
|
||||
for (INT x = 0; x < cx; ++x)
|
||||
{
|
||||
INT delta = INT(x * eTan);
|
||||
if (nDegree > 0)
|
||||
BitBlt(hDC2, x, (dy - delta), 1, cy, hDC1, x, 0, SRCCOPY);
|
||||
else
|
||||
BitBlt(hDC2, x, delta, 1, cy, hDC1, x, 0, SRCCOPY);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (INT y = 0; y < cy; ++y)
|
||||
{
|
||||
INT delta = INT(y * eTan);
|
||||
if (nDegree > 0)
|
||||
BitBlt(hDC2, (dx - delta), y, cx, 1, hDC1, 0, y, SRCCOPY);
|
||||
else
|
||||
BitBlt(hDC2, delta, y, cx, 1, hDC1, 0, y, SRCCOPY);
|
||||
}
|
||||
}
|
||||
SelectObject(hDC2, hbm2Old);
|
||||
DeleteDC(hDC2);
|
||||
return hbmNew;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue