ReactOS 0.4.16-dev-197-g92996da
dib.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ROUND(x)   (INT)((x) + 0.5)
 

Functions

BOOL IsBitmapBlackAndWhite (HBITMAP hbm)
 
HBITMAP CreateDIBWithProperties (int width, int height)
 
HBITMAP CreateMonoBitmap (int width, int height, BOOL bWhite)
 
HBITMAP CreateColorDIB (int width, int height, COLORREF rgb)
 
HBITMAP CachedBufferDIB (HBITMAP hbm, int minimalWidth, int minimalHeight)
 
HBITMAP ConvertToBlackAndWhite (HBITMAP hbm)
 
HBITMAP CopyMonoImage (HBITMAP hbm, INT cx=0, INT cy=0)
 
static HBITMAP CopyDIBImage (HBITMAP hbm, INT cx=0, INT cy=0)
 
int GetDIBWidth (HBITMAP hbm)
 
int GetDIBHeight (HBITMAP hbm)
 
BOOL SaveDIBToFile (HBITMAP hBitmap, LPCWSTR FileName, BOOL fIsMainFile, REFGUID guidFileType=GUID_NULL)
 
HBITMAP DoLoadImageFile (HWND hwnd, LPCWSTR name, BOOL fIsMainFile)
 
void SetFileInfo (LPCWSTR name, LPWIN32_FIND_DATAW pFound, BOOL isAFile)
 
HBITMAP InitializeImage (LPCWSTR name, LPWIN32_FIND_DATAW pFound, BOOL isFile)
 
HBITMAP SetBitmapAndInfo (HBITMAP hBitmap, LPCWSTR name, LPWIN32_FIND_DATAW pFound, BOOL isFile)
 
HBITMAP Rotate90DegreeBlt (HDC hDC1, INT cx, INT cy, BOOL bRight, BOOL bMono)
 
HBITMAP SkewDIB (HDC hDC1, HBITMAP hbm, INT nDegree, BOOL bVertical, BOOL bMono=FALSE)
 
float PpcmFromDpi (float dpi)
 
HGLOBAL BitmapToClipboardDIB (HBITMAP hBitmap)
 
HBITMAP BitmapFromClipboardDIB (HGLOBAL hGlobal)
 
HBITMAP BitmapFromHEMF (HENHMETAFILE hEMF)
 
HBITMAP getSubImage (HBITMAP hbmWhole, const RECT &rcPartial)
 
void putSubImage (HBITMAP hbmWhole, const RECT &rcPartial, HBITMAP hbmPart)
 

Macro Definition Documentation

◆ ROUND

#define ROUND (   x)    (INT)((x) + 0.5)

Definition at line 42 of file dib.h.

Function Documentation

◆ BitmapFromClipboardDIB()

HBITMAP BitmapFromClipboardDIB ( HGLOBAL  hGlobal)

Definition at line 510 of file dib.cpp.

511{
512 CWaitCursor waitCursor;
513
514 LPBYTE pb = (LPBYTE)GlobalLock(hGlobal);
515 if (!pb)
516 return NULL;
517
519 pb += pbmi->bmiHeader.biSize;
520
521 INT cColors = 0, cbColors = 0;
522 if (pbmi->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
523 {
525 WORD BitCount = pbmci->bmciHeader.bcBitCount;
526 if (BitCount < 16)
527 {
528 cColors = (1 << BitCount);
529 cbColors = cColors * sizeof(RGBTRIPLE);
530 pb += cbColors;
531 }
532 }
533 else if (pbmi->bmiHeader.biSize >= sizeof(BITMAPINFOHEADER))
534 {
535 WORD BitCount = pbmi->bmiHeader.biBitCount;
536 if (BitCount < 16)
537 {
538 cColors = (1 << BitCount);
539 cbColors = cColors * sizeof(RGBQUAD);
540 pb += cbColors;
541 }
542 }
543
546 if (hBitmap)
547 {
549 }
550 DeleteDC(hDC);
551
552 GlobalUnlock(hGlobal);
553
554 return hBitmap;
555}
static HDC hDC
Definition: 3dtext.c:33
#define NULL
Definition: types.h:112
static HBITMAP hBitmap
Definition: timezone.c:26
ULONG RGBQUAD
Definition: precomp.h:59
unsigned short WORD
Definition: ntddk_ex.h:93
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
_Check_return_ long __cdecl labs(_In_ long x)
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:88
_In_ HBITMAP _In_ UINT _In_ UINT _Inout_ LPBITMAPINFO pbmi
Definition: ntgdi.h:2780
BITMAPCOREHEADER bmciHeader
Definition: wingdi.h:1453
USHORT biBitCount
Definition: precomp.h:46
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1476
unsigned char * LPBYTE
Definition: typedefs.h:53
int32_t INT
Definition: typedefs.h:58
HBITMAP WINAPI CreateDIBSection(HDC hDC, CONST BITMAPINFO *BitmapInfo, UINT Usage, VOID **Bits, HANDLE hSection, DWORD dwOffset)
Definition: bitmap.c:245
#define DIB_RGB_COLORS
Definition: wingdi.h:367
struct _BITMAPCOREINFO * LPBITMAPCOREINFO
struct tagRGBTRIPLE RGBTRIPLE
int WINAPI SetDIBits(_In_opt_ HDC, _In_ HBITMAP, _In_ UINT, _In_ UINT, _In_ CONST VOID *, _In_ CONST BITMAPINFO *, _In_ UINT)
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
struct tagBITMAPINFO * LPBITMAPINFO
BOOL WINAPI DeleteDC(_In_ HDC)

Referenced by CMainWindow::OnCommand().

◆ BitmapFromHEMF()

HBITMAP BitmapFromHEMF ( HENHMETAFILE  hEMF)

Definition at line 557 of file dib.cpp.

558{
559 CWaitCursor waitCursor;
560
562 if (!GetEnhMetaFileHeader(hEMF, sizeof(header), &header))
563 return NULL;
564
565 CRect rc = *(LPRECT)&header.rclBounds;
566 INT cx = rc.Width(), cy = rc.Height();
567 HBITMAP hbm = CreateColorDIB(cx, cy, RGB(255, 255, 255));
568 if (!hbm)
569 return NULL;
570
572 HGDIOBJ hbmOld = SelectObject(hDC, hbm);
573 PlayEnhMetaFile(hDC, hEMF, &rc);
574 SelectObject(hDC, hbmOld);
575 DeleteDC(hDC);
576
577 return hbm;
578}
int Width() const noexcept
Definition: atltypes.h:461
int Height() const noexcept
Definition: atltypes.h:318
HBITMAP CreateColorDIB(int width, int height, COLORREF rgb)
Definition: dib.cpp:65
#define RGB(r, g, b)
Definition: precomp.h:71
_In_ HBITMAP hbm
Definition: ntgdi.h:2776
_Out_opt_ int _Out_opt_ int * cy
Definition: commctrl.h:586
_Out_opt_ int * cx
Definition: commctrl.h:585
#define LPRECT
Definition: precomp.h:28
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1546
UINT WINAPI GetEnhMetaFileHeader(_In_ HENHMETAFILE hemf, _In_ UINT nSize, _Out_writes_bytes_opt_(nSize) LPENHMETAHEADER lpEnhMetaHeader)
BOOL WINAPI PlayEnhMetaFile(_In_ HDC, _In_ HENHMETAFILE, _In_ LPCRECT)

Referenced by CMainWindow::OnCommand().

◆ BitmapToClipboardDIB()

HGLOBAL BitmapToClipboardDIB ( HBITMAP  hBitmap)

Definition at line 447 of file dib.cpp.

448{
449 CWaitCursor waitCursor;
450
451 BITMAP bm;
452 if (!GetObjectW(hBitmap, sizeof(BITMAP), &bm))
453 return NULL;
454
455 BITMAPINFODX bmi;
456 ZeroMemory(&bmi, sizeof(bmi));
457 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
458 bmi.bmiHeader.biWidth = bm.bmWidth;
459 bmi.bmiHeader.biHeight = bm.bmHeight;
460 bmi.bmiHeader.biPlanes = 1;
461 bmi.bmiHeader.biBitCount = bm.bmBitsPixel;
463 bmi.bmiHeader.biSizeImage = bm.bmWidthBytes * bm.bmHeight;
464
465 INT cColors;
466 if (bm.bmBitsPixel < 16)
467 cColors = 1 << bm.bmBitsPixel;
468 else
469 cColors = 0;
470
472
473 if (cColors)
474 {
475 HGDIOBJ hbmOld = SelectObject(hDC, hBitmap);
476 cColors = GetDIBColorTable(hDC, 0, cColors, bmi.bmiColors);
477 SelectObject(hDC, hbmOld);
478 }
479
480 DWORD cbColors = cColors * sizeof(RGBQUAD);
481 DWORD dwSize = sizeof(BITMAPINFOHEADER) + cbColors + bmi.bmiHeader.biSizeImage;
483 if (hGlobal)
484 {
485 LPBYTE pb = (LPBYTE)GlobalLock(hGlobal);
486 if (pb)
487 {
488 CopyMemory(pb, &bmi, sizeof(BITMAPINFOHEADER));
489 pb += sizeof(BITMAPINFOHEADER);
490
491 CopyMemory(pb, bmi.bmiColors, cbColors);
492 pb += cbColors;
493
494 GetDIBits(hDC, hBitmap, 0, bm.bmHeight, pb, &bmi, DIB_RGB_COLORS);
495
496 GlobalUnlock(hGlobal);
497 }
498 else
499 {
500 GlobalFree(hGlobal);
501 hGlobal = NULL;
502 }
503 }
504
505 DeleteDC(hDC);
506
507 return hGlobal;
508}
#define BI_RGB
Definition: precomp.h:56
unsigned long DWORD
Definition: ntddk_ex.h:95
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
Definition: bl.h:1331
ULONG biCompression
Definition: precomp.h:47
RGBQUAD bmiColors[1]
Definition: wingdi.h:1477
UINT WINAPI GetDIBColorTable(HDC hDC, UINT iStartIndex, UINT cEntries, RGBQUAD *pColors)
Definition: palette.c:123
#define ZeroMemory
Definition: winbase.h:1736
#define CopyMemory
Definition: winbase.h:1734
#define GHND
Definition: winbase.h:322
#define GMEM_SHARE
Definition: winbase.h:330
int WINAPI GetObjectW(_In_ HANDLE h, _In_ int c, _Out_writes_bytes_opt_(c) LPVOID pv)
int WINAPI GetDIBits(_In_ HDC hdc, _In_ HBITMAP hbm, _In_ UINT start, _In_ UINT cLines, _Out_opt_ LPVOID lpvBits, _At_((LPBITMAPINFOHEADER) lpbmi, _Inout_) LPBITMAPINFO lpbmi, _In_ UINT usage)

Referenced by CMainWindow::OnCommand().

◆ CachedBufferDIB()

HBITMAP CachedBufferDIB ( HBITMAP  hbm,
int  minimalWidth,
int  minimalHeight 
)

Definition at line 115 of file dib.cpp.

116{
117 if (minimalWidth <= 0)
118 minimalWidth = 1;
119 if (minimalHeight <= 0)
120 minimalHeight = 1;
121
122 BITMAP bm;
123 if (!GetObjectW(hbm, sizeof(bm), &bm))
124 hbm = NULL;
125
126 if (hbm && minimalWidth <= bm.bmWidth && minimalHeight <= bm.bmHeight)
127 return hbm;
128
129 if (hbm)
131
132 return CreateDIBWithProperties((minimalWidth * 3) / 2, (minimalHeight * 3) / 2);
133}
HBITMAP CreateDIBWithProperties(int width, int height)
Definition: dib.cpp:32
pKey DeleteObject()

Referenced by CCanvasWindow::DoDraw(), CMiniatureWindow::OnPaint(), and CPaletteWindow::OnPaint().

◆ ConvertToBlackAndWhite()

HBITMAP ConvertToBlackAndWhite ( HBITMAP  hbm)

Definition at line 631 of file dib.cpp.

632{
633 CWaitCursor waitCursor;
634
635 BITMAP bm;
636 if (!::GetObjectW(hbm, sizeof(bm), &bm))
637 return NULL;
638
639 BITMAPINFOEX bmi;
640 ZeroMemory(&bmi, sizeof(bmi));
641 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
642 bmi.bmiHeader.biWidth = bm.bmWidth;
643 bmi.bmiHeader.biHeight = bm.bmHeight;
644 bmi.bmiHeader.biPlanes = 1;
645 bmi.bmiHeader.biBitCount = 1;
646 bmi.bmiColors[1].rgbBlue = 255;
647 bmi.bmiColors[1].rgbGreen = 255;
648 bmi.bmiColors[1].rgbRed = 255;
650 LPVOID pvMonoBits;
651 HBITMAP hMonoBitmap = ::CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, &pvMonoBits, NULL, 0);
652 if (!hMonoBitmap)
653 {
655 return NULL;
656 }
657
658 HBITMAP hNewBitmap = CreateDIBWithProperties(bm.bmWidth, bm.bmHeight);
659 if (hNewBitmap)
660 {
661 ::GetDIBits(hdc, hbm, 0, bm.bmHeight, pvMonoBits, &bmi, DIB_RGB_COLORS);
662 ::SetDIBits(hdc, hNewBitmap, 0, bm.bmHeight, pvMonoBits, &bmi, DIB_RGB_COLORS);
663 }
664 ::DeleteObject(hMonoBitmap);
666
667 return hNewBitmap;
668}
HDC hdc
Definition: main.c:9
UCHAR rgbBlue
Definition: bootanim.c:103
UCHAR rgbRed
Definition: bootanim.c:105
UCHAR rgbGreen
Definition: bootanim.c:104

Referenced by ImageModel::PushBlackAndWhite().

◆ CopyDIBImage()

static HBITMAP CopyDIBImage ( HBITMAP  hbm,
INT  cx = 0,
INT  cy = 0 
)
inlinestatic

Definition at line 19 of file dib.h.

20{
22}
#define IMAGE_BITMAP
Definition: winuser.h:211
#define LR_CREATEDIBSECTION
Definition: winuser.h:1101
#define LR_COPYRETURNORG
Definition: winuser.h:1093
HANDLE WINAPI CopyImage(_In_ HANDLE, _In_ UINT, _In_ int, _In_ int, _In_ UINT)
Definition: cursoricon.c:2024

Referenced by ImageModel::CopyBitmap(), SkewDIB(), SelectionModel::StretchSkew(), and ImageModel::StretchSkew().

◆ CopyMonoImage()

HBITMAP CopyMonoImage ( HBITMAP  hbm,
INT  cx = 0,
INT  cy = 0 
)

Definition at line 87 of file dib.cpp.

88{
89 BITMAP bm;
90 if (!::GetObjectW(hbm, sizeof(bm), &bm))
91 return NULL;
92
93 if (cx == 0 || cy == 0)
94 {
95 cx = bm.bmWidth;
96 cy = bm.bmHeight;
97 }
98
99 HBITMAP hbmNew = ::CreateBitmap(cx, cy, 1, 1, NULL);
100 if (!hbmNew)
101 return NULL;
102
105 HGDIOBJ hbm1Old = ::SelectObject(hdc1, hbm);
106 HGDIOBJ hbm2Old = ::SelectObject(hdc2, hbmNew);
107 ::StretchBlt(hdc2, 0, 0, cx, cy, hdc1, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
108 ::SelectObject(hdc1, hbm1Old);
109 ::SelectObject(hdc2, hbm2Old);
112 return hbmNew;
113}
HDC hdc1
Definition: SelectObject.c:10
HDC hdc2
Definition: SelectObject.c:10
HBITMAP WINAPI CreateBitmap(_In_ INT cx, _In_ INT cy, _In_ UINT cPlanes, _In_ UINT cBitsPerPel, _In_opt_ const VOID *pvBits)
BOOL WINAPI StretchBlt(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_opt_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_ DWORD)
#define SRCCOPY
Definition: wingdi.h:333

Referenced by SelectionModel::StretchSkew().

◆ CreateColorDIB()

HBITMAP CreateColorDIB ( int  width,
int  height,
COLORREF  rgb 
)

Definition at line 65 of file dib.cpp.

66{
68 if (!ret)
69 return NULL;
70
71 if (rgb)
72 {
74 HGDIOBJ hbmOld = SelectObject(hdc, ret);
75 RECT rc;
76 SetRect(&rc, 0, 0, width, height);
77 HBRUSH hbr = CreateSolidBrush(rgb);
78 FillRect(hdc, &rc, hbr);
79 DeleteObject(hbr);
80 SelectObject(hdc, hbmOld);
82 }
83
84 return ret;
85}
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
GLint GLint GLsizei width
Definition: gl.h:1546
int ret
_In_ ULONG _In_ ULONG rgb
Definition: winddi.h:3521
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
HBRUSH WINAPI CreateSolidBrush(_In_ COLORREF)
BOOL WINAPI SetRect(_Out_ LPRECT, _In_ int, _In_ int, _In_ int, _In_ int)

Referenced by BitmapFromHEMF(), ColorKeyedMaskBlt(), ImageModel::Crop(), SelectionModel::GetSelectionContents(), ImageModel::ImageModel(), InitializeImage(), and SkewDIB().

◆ CreateDIBWithProperties()

HBITMAP CreateDIBWithProperties ( int  width,
int  height 
)

Definition at line 32 of file dib.cpp.

33{
34 BITMAPINFO bmi;
35 ZeroMemory(&bmi, sizeof(BITMAPINFO));
36 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
39 bmi.bmiHeader.biPlanes = 1;
40 bmi.bmiHeader.biBitCount = 24;
41 return CreateDIBSection(NULL, &bmi, DIB_RGB_COLORS, NULL, NULL, 0);
42}

Referenced by CachedBufferDIB(), ConvertToBlackAndWhite(), CreateColorDIB(), getSubImage(), and Rotate90DegreeBlt().

◆ CreateMonoBitmap()

HBITMAP CreateMonoBitmap ( int  width,
int  height,
BOOL  bWhite 
)

Definition at line 45 of file dib.cpp.

46{
48 if (hbm == NULL)
49 return NULL;
50
51 if (bWhite)
52 {
54 HGDIOBJ hbmOld = SelectObject(hdc, hbm);
55 RECT rc = { 0, 0, width, height };
56 FillRect(hdc, &rc, (HBRUSH)GetStockObject(WHITE_BRUSH));
57 SelectObject(hdc, hbmOld);
59 }
60
61 return hbm;
62}
HGDIOBJ WINAPI GetStockObject(_In_ int)
#define WHITE_BRUSH
Definition: wingdi.h:902

Referenced by SkewDIB(), and SelectionModel::StretchSkew().

◆ DoLoadImageFile()

HBITMAP DoLoadImageFile ( HWND  hwnd,
LPCWSTR  name,
BOOL  fIsMainFile 
)

Definition at line 256 of file dib.cpp.

257{
258 CWaitCursor waitCursor;
259
260 // find the file
262 HANDLE hFind = ::FindFirstFileW(name, &find);
263 if (hFind == INVALID_HANDLE_VALUE) // does not exist
264 {
266 return NULL;
267 }
268 ::FindClose(hFind);
269
270 // is file empty?
271 if (find.nFileSizeLow == 0 && find.nFileSizeHigh == 0)
272 {
273 if (fIsMainFile)
274 return InitializeImage(name, &find, TRUE);
275 }
276
277 // load the image
279 float xDpi = 0, yDpi = 0;
280 HRESULT hr = img.LoadDx(name, &xDpi, &yDpi);
281 if (FAILED(hr) && fIsMainFile)
282 {
284 hr = img.LoadDx(name, &xDpi, &yDpi);
285 }
286 if (FAILED(hr))
287 {
288 ATLTRACE("hr: 0x%08lX\n", hr);
290 return NULL;
291 }
292
293 HBITMAP hBitmap = img.Detach();
294 if (!fIsMainFile)
295 return hBitmap;
296
297 if (xDpi <= 0 || yDpi <= 0)
298 {
299 HDC hDC = ::GetDC(NULL);
303 }
304
305 g_xDpi = xDpi;
306 g_yDpi = yDpi;
307
309 return hBitmap;
310}
#define ATLTRACE(format,...)
Definition: atltrace.h:269
VOID ShowError(DWORD dwLastError)
Definition: progress.c:29
#define IDS_LOADERRORTEXT
Definition: resource.h:220
void ClearHistory(void)
Definition: history.cpp:116
static TAGID TAGID find
Definition: db.cpp:155
HBITMAP InitializeImage(LPCWSTR name, LPWIN32_FIND_DATAW pFound, BOOL isFile)
Definition: dib.cpp:226
float g_xDpi
Definition: dib.cpp:11
float g_yDpi
Definition: dib.cpp:12
HBITMAP SetBitmapAndInfo(HBITMAP hBitmap, LPCWSTR name, LPWIN32_FIND_DATAW pFound, BOOL isFile)
Definition: dib.cpp:244
#define TRUE
Definition: types.h:120
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
HANDLE WINAPI FindFirstFileW(IN LPCWSTR lpFileName, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:320
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
GLint GLvoid * img
Definition: gl.h:1956
ImageModel imageModel
Definition: history.cpp:11
#define FAILED(hr)
Definition: intsafe.h:51
static float(__cdecl *square_half_float)(float x
HRESULT hr
Definition: shlfolder.c:183
Definition: name.c:39
int WINAPI GetDeviceCaps(_In_opt_ HDC, _In_ int)
#define LOGPIXELSY
Definition: wingdi.h:719
#define LOGPIXELSX
Definition: wingdi.h:718
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
HDC WINAPI GetDC(_In_opt_ HWND)

Referenced by CMainWindow::OnCommand(), CMainWindow::OnDropFiles(), and wWinMain().

◆ GetDIBHeight()

int GetDIBHeight ( HBITMAP  hbm)

Definition at line 144 of file dib.cpp.

145{
146 BITMAP bm;
147 ::GetObjectW(hBitmap, sizeof(BITMAP), &bm);
148 return bm.bmHeight;
149}

Referenced by ImageModel::GetHeight(), SelectionModel::InsertFromHBITMAP(), and CMainWindow::InsertSelectionFromHBITMAP().

◆ GetDIBWidth()

int GetDIBWidth ( HBITMAP  hbm)

Definition at line 136 of file dib.cpp.

137{
138 BITMAP bm;
139 ::GetObjectW(hBitmap, sizeof(BITMAP), &bm);
140 return bm.bmWidth;
141}

Referenced by ImageModel::GetWidth(), SelectionModel::InsertFromHBITMAP(), and CMainWindow::InsertSelectionFromHBITMAP().

◆ getSubImage()

HBITMAP getSubImage ( HBITMAP  hbmWhole,
const RECT rcPartial 
)

Definition at line 409 of file dib.cpp.

410{
411 CRect rc = rcPartial;
412 HBITMAP hbmPart = CreateDIBWithProperties(rc.Width(), rc.Height());
413 if (!hbmPart)
414 return NULL;
415
418 HGDIOBJ hbm1Old = ::SelectObject(hDC1, hbmWhole);
419 HGDIOBJ hbm2Old = ::SelectObject(hDC2, hbmPart);
420 ::BitBlt(hDC2, 0, 0, rc.Width(), rc.Height(), hDC1, rc.left, rc.top, SRCCOPY);
421 ::SelectObject(hDC1, hbm1Old);
422 ::SelectObject(hDC2, hbm2Old);
423 ::DeleteDC(hDC1);
424 ::DeleteDC(hDC2);
425 return hbmPart;
426}
static VOID BitBlt(_In_ ULONG Left, _In_ ULONG Top, _In_ ULONG Width, _In_ ULONG Height, _In_reads_bytes_(Delta *Height) PUCHAR Buffer, _In_ ULONG BitsPerPixel, _In_ ULONG Delta)
Definition: common.c:57
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306

Referenced by SelectionModel::GetSelectionContents(), ImageModel::PushImageForUndo(), and ImageModel::SwapPart().

◆ InitializeImage()

HBITMAP InitializeImage ( LPCWSTR  name,
LPWIN32_FIND_DATAW  pFound,
BOOL  isFile 
)

Definition at line 226 of file dib.cpp.

227{
228 COLORREF white = RGB(255, 255, 255);
230 if (hBitmap == NULL)
231 {
233 return NULL;
234 }
235
236 HDC hScreenDC = ::GetDC(NULL);
237 g_xDpi = (float)::GetDeviceCaps(hScreenDC, LOGPIXELSX);
238 g_yDpi = (float)::GetDeviceCaps(hScreenDC, LOGPIXELSY);
239 ::ReleaseDC(NULL, hScreenDC);
240
241 return SetBitmapAndInfo(hBitmap, name, pFound, isFile);
242}
void ShowOutOfMemory(void)
Definition: main.cpp:34
RegistrySettings registrySettings
Definition: registry.cpp:14
DWORD BMPWidth
Definition: registry.h:19
DWORD BMPHeight
Definition: registry.h:18
DWORD COLORREF
Definition: windef.h:300

Referenced by DoLoadImageFile(), CMainWindow::OnCommand(), and wWinMain().

◆ IsBitmapBlackAndWhite()

BOOL IsBitmapBlackAndWhite ( HBITMAP  hbm)

Definition at line 580 of file dib.cpp.

581{
582 CWaitCursor waitCursor;
583
584 BITMAP bm;
585 if (!::GetObjectW(hbm, sizeof(bm), &bm))
586 return FALSE;
587
588 if (bm.bmBitsPixel == 1)
589 return TRUE;
590
591 BITMAPINFOEX bmi;
592 ZeroMemory(&bmi, sizeof(bmi));
593 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
594 bmi.bmiHeader.biWidth = bm.bmWidth;
595 bmi.bmiHeader.biHeight = bm.bmHeight;
596 bmi.bmiHeader.biPlanes = 1;
597 bmi.bmiHeader.biBitCount = 24;
598
599 DWORD widthbytes = WIDTHBYTES(24 * bm.bmWidth);
600 DWORD cbBits = widthbytes * bm.bmHeight;
601 LPBYTE pbBits = new BYTE[cbBits];
602
604 ::GetDIBits(hdc, hbm, 0, bm.bmHeight, pbBits, &bmi, DIB_RGB_COLORS);
606
607 BOOL bBlackAndWhite = TRUE;
608 for (LONG y = 0; y < bm.bmHeight; ++y)
609 {
610 LPBYTE pbLine = &pbBits[widthbytes * y];
611 for (LONG x = 0; x < bm.bmWidth; ++x)
612 {
613 BYTE Blue = *pbLine++;
614 BYTE Green = *pbLine++;
615 BYTE Red = *pbLine++;
616 COLORREF rgbColor = RGB(Red, Green, Blue);
617 if (rgbColor != RGB(0, 0, 0) && rgbColor != RGB(255, 255, 255))
618 {
619 bBlackAndWhite = FALSE;
620 goto Finish;
621 }
622 }
623 }
624
625Finish:
626 delete[] pbBits;
627
628 return bBlackAndWhite;
629}
@ Green
Definition: bl.h:199
@ Red
Definition: bl.h:201
@ Blue
Definition: bl.h:198
#define WIDTHBYTES(i)
Definition: dib.cpp:15
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
long LONG
Definition: pedump.c:60
unsigned char BYTE
Definition: xxhash.c:193

Referenced by ImageModel::IsBlackAndWhite().

◆ PpcmFromDpi()

float PpcmFromDpi ( float  dpi)

Definition at line 25 of file dib.cpp.

26{
27 // 1 DPI is 0.0254 meter. 1 centimeter is 1/100 meter.
28 return dpi / (0.0254f * 100.0f);
29}
#define dpi
Definition: sysparams.c:23

Referenced by CAttributesDialog::OnEdit1(), CAttributesDialog::OnEdit2(), CAttributesDialog::OnInitDialog(), and CAttributesDialog::OnRadioButton2().

◆ putSubImage()

void putSubImage ( HBITMAP  hbmWhole,
const RECT rcPartial,
HBITMAP  hbmPart 
)

Definition at line 428 of file dib.cpp.

429{
430 CRect rc = rcPartial;
433 HGDIOBJ hbm1Old = ::SelectObject(hDC1, hbmWhole);
434 HGDIOBJ hbm2Old = ::SelectObject(hDC2, hbmPart);
435 ::BitBlt(hDC1, rc.left, rc.top, rc.Width(), rc.Height(), hDC2, 0, 0, SRCCOPY);
436 ::SelectObject(hDC1, hbm1Old);
437 ::SelectObject(hDC2, hbm2Old);
438 ::DeleteDC(hDC1);
439 ::DeleteDC(hDC2);
440}

Referenced by ImageModel::Crop(), and ImageModel::SwapPart().

◆ Rotate90DegreeBlt()

HBITMAP Rotate90DegreeBlt ( HDC  hDC1,
INT  cx,
INT  cy,
BOOL  bRight,
BOOL  bMono 
)

Definition at line 312 of file dib.cpp.

313{
314 HBITMAP hbm2;
315 if (bMono)
316 hbm2 = ::CreateBitmap(cy, cx, 1, 1, NULL);
317 else
319 if (!hbm2)
320 return NULL;
321
323 HGDIOBJ hbm2Old = SelectObject(hDC2, hbm2);
324 if (bRight)
325 {
326 for (INT y = 0; y < cy; ++y)
327 {
328 for (INT x = 0; x < cx; ++x)
329 {
330 COLORREF rgb = GetPixel(hDC1, x, y);
331 SetPixelV(hDC2, cy - (y + 1), x, rgb);
332 }
333 }
334 }
335 else
336 {
337 for (INT y = 0; y < cy; ++y)
338 {
339 for (INT x = 0; x < cx; ++x)
340 {
341 COLORREF rgb = GetPixel(hDC1, x, y);
342 SetPixelV(hDC2, y, cx - (x + 1), rgb);
343 }
344 }
345 }
346 SelectObject(hDC2, hbm2Old);
347 DeleteDC(hDC2);
348 return hbm2;
349}
DWORD GetPixel(LPDIRECTDRAWSURFACE7 Surface, UINT x, UINT y)
Definition: blt.cpp:2
BOOL WINAPI SetPixelV(_In_ HDC, _In_ int, _In_ int, _In_ COLORREF)

Referenced by ImageModel::RotateNTimes90Degrees(), and SelectionModel::RotateNTimes90Degrees().

◆ SaveDIBToFile()

BOOL SaveDIBToFile ( HBITMAP  hBitmap,
LPCWSTR  FileName,
BOOL  fIsMainFile,
REFGUID  guidFileType = GUID_NULL 
)

Definition at line 151 of file dib.cpp.

152{
153 CWaitCursor waitCursor;
154
156 img.Attach(hBitmap);
157 HRESULT hr = img.SaveDx(FileName, guidFileType, g_xDpi, g_yDpi);
158 img.Detach();
159
160 if (FAILED(hr))
161 {
163 return FALSE;
164 }
165
166 if (!fIsMainFile)
167 return TRUE;
168
171 if (hFind == INVALID_HANDLE_VALUE)
172 {
174 return FALSE;
175 }
176 ::FindClose(hFind);
177
180 return TRUE;
181}
BOOL g_imageSaved
Definition: main.cpp:21
#define IDS_SAVEERROR
Definition: resource.h:229
void SetFileInfo(LPCWSTR name, LPWIN32_FIND_DATAW pFound, BOOL isAFile)
Definition: dib.cpp:183

Referenced by CMainWindow::OnCommand(), OpenMailer(), and ImageModel::SaveImage().

◆ SetBitmapAndInfo()

HBITMAP SetBitmapAndInfo ( HBITMAP  hBitmap,
LPCWSTR  name,
LPWIN32_FIND_DATAW  pFound,
BOOL  isFile 
)

Definition at line 244 of file dib.cpp.

245{
246 // update image
250
251 SetFileInfo(name, pFound, isFile);
253 return hBitmap;
254}
CCanvasWindow canvasWindow
Definition: canvas.cpp:10
VOID updateScrollPos(INT x=0, INT y=0)
Definition: canvas.cpp:244
void PushImageForUndo()
Definition: history.cpp:127

Referenced by DoLoadImageFile(), and InitializeImage().

◆ SetFileInfo()

void SetFileInfo ( LPCWSTR  name,
LPWIN32_FIND_DATAW  pFound,
BOOL  isAFile 
)

Definition at line 183 of file dib.cpp.

184{
185 // update file time and size
186 if (pFound)
187 {
188 FILETIME ft;
191
192 g_fileSize = pFound->nFileSizeLow;
193 }
194 else
195 {
197 g_fileSize = 0;
198 }
199
200 // update g_szFileName
201 if (name && name[0])
202 {
203 CStringW strName = name;
205 // The following code won't work correctly when (name == g_szFileName):
206 // ::GetFullPathNameW(name, _countof(g_szFileName), g_szFileName, NULL);
207 }
208 else
209 {
211 }
212
213 // set title
214 CStringW strTitle;
216 mainWindow.SetWindowText(strTitle);
217
218 // update file info and recent
219 g_isAFile = isAFile;
220 if (g_isAFile)
222
224}
WCHAR g_szFileName[MAX_LONG_PATH]
Definition: main.cpp:18
CMainWindow mainWindow
Definition: main.cpp:25
BOOL g_isAFile
Definition: main.cpp:20
HINSTANCE g_hinstExe
Definition: main.cpp:17
#define IDS_DEFAULTFILENAME
Definition: resource.h:192
#define IDS_WINDOWTITLE
Definition: resource.h:187
void __cdecl Format(UINT nFormatID,...)
Definition: cstringt.h:818
BOOL SetWindowText(LPCTSTR lpszString)
Definition: atlwin.h:1300
void SetMostRecentFile(LPCWSTR szPathName)
Definition: registry.cpp:277
SYSTEMTIME g_fileTime
Definition: dib.cpp:13
INT g_fileSize
Definition: dib.cpp:10
DWORD WINAPI GetFullPathNameW(IN LPCWSTR lpFileName, IN DWORD nBufferLength, OUT LPWSTR lpBuffer, OUT LPWSTR *lpFilePart)
Definition: path.c:1106
BOOL WINAPI FileTimeToSystemTime(IN CONST FILETIME *lpFileTime, OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:188
BOOL WINAPI FileTimeToLocalFileTime(IN CONST FILETIME *lpFileTime, OUT LPFILETIME lpLocalFileTime)
Definition: time.c:221
LPWSTR WINAPI PathFindFileNameW(LPCWSTR lpszPath)
Definition: path.c:394
#define _countof(array)
Definition: sndvol32.h:70
FILETIME ftLastWriteTime
Definition: winbase.h:966
DWORD nFileSizeLow
Definition: winbase.h:968
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)

Referenced by SaveDIBToFile(), and SetBitmapAndInfo().

◆ SkewDIB()

HBITMAP SkewDIB ( HDC  hDC1,
HBITMAP  hbm,
INT  nDegree,
BOOL  bVertical,
BOOL  bMono = FALSE 
)

Definition at line 351 of file dib.cpp.

352{
353 CWaitCursor waitCursor;
354
355 if (nDegree == 0)
356 return CopyDIBImage(hbm);
357
358 const double eTan = tan(abs(nDegree) * M_PI / 180);
359
360 BITMAP bm;
361 ::GetObjectW(hbm, sizeof(bm), &bm);
362 INT cx = bm.bmWidth, cy = bm.bmHeight, dx = 0, dy = 0;
363 if (bVertical)
364 dy = INT(cx * eTan);
365 else
366 dx = INT(cy * eTan);
367
368 if (dx == 0 && dy == 0)
369 return CopyDIBImage(hbm);
370
371 HBITMAP hbmNew;
372 if (bMono)
373 hbmNew = CreateMonoBitmap(cx + dx, cy + dy, FALSE);
374 else
375 hbmNew = CreateColorDIB(cx + dx, cy + dy, RGB(255, 255, 255));
376 if (!hbmNew)
377 return NULL;
378
380 HGDIOBJ hbm2Old = SelectObject(hDC2, hbmNew);
381 if (bVertical)
382 {
383 for (INT x = 0; x < cx; ++x)
384 {
385 INT delta = INT(x * eTan);
386 if (nDegree > 0)
387 ::BitBlt(hDC2, x, (dy - delta), 1, cy, hDC1, x, 0, SRCCOPY);
388 else
389 ::BitBlt(hDC2, x, delta, 1, cy, hDC1, x, 0, SRCCOPY);
390 }
391 }
392 else
393 {
394 for (INT y = 0; y < cy; ++y)
395 {
396 INT delta = INT(y * eTan);
397 if (nDegree > 0)
398 ::BitBlt(hDC2, (dx - delta), y, cx, 1, hDC1, 0, y, SRCCOPY);
399 else
400 ::BitBlt(hDC2, delta, y, cx, 1, hDC1, 0, y, SRCCOPY);
401 }
402 }
403
404 SelectObject(hDC2, hbm2Old);
405 DeleteDC(hDC2);
406 return hbmNew;
407}
_STLP_DECLSPEC complex< float > _STLP_CALL tan(const complex< float > &)
static HBITMAP CopyDIBImage(HBITMAP hbm, INT cx=0, INT cy=0)
Definition: dib.h:19
HBITMAP CreateMonoBitmap(int width, int height, BOOL bWhite)
Definition: dib.cpp:45
#define abs(i)
Definition: fconv.c:206
GLint dy
Definition: linetemp.h:97
GLint dx
Definition: linetemp.h:97
#define M_PI
Definition: macros.h:263
#define INT
Definition: polytest.cpp:20

Referenced by SelectionModel::StretchSkew(), and ImageModel::StretchSkew().