ReactOS 0.4.17-dev-357-ga8f14ff
dib.cpp File Reference
#include "precomp.h"
Include dependency graph for dib.cpp:

Go to the source code of this file.

Classes

struct  BITMAPINFOEX
 
struct  BITMAPINFODX
 

Macros

#define WIDTHBYTES(i)   (((i) + 31) / 32 * 4)
 

Functions

float PpcmFromDpi (float dpi)
 
HBITMAP CreateDIBWithProperties (int width, int height)
 
HBITMAP CreateMonoBitmap (int width, int height, BOOL bWhite)
 
HBITMAP CreateColorDIB (int width, int height, COLORREF rgb)
 
HBITMAP CopyMonoImage (HBITMAP hbm, INT cx, INT cy, INT stretchMode)
 
HBITMAP CopyDIBImage (HBITMAP hbm, INT cx, INT cy, INT stretchMode)
 
HBITMAP CachedBufferDIB (HBITMAP hbm, int minimalWidth, int minimalHeight)
 
int GetDIBWidth (HBITMAP hBitmap)
 
int GetDIBHeight (HBITMAP hBitmap)
 
BOOL SaveDIBToFile (HBITMAP hBitmap, LPCWSTR FileName, BOOL fIsMainFile, REFGUID guidFileType)
 
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 DoLoadImageFile (HWND hwnd, LPCWSTR name, BOOL fIsMainFile)
 
HBITMAP Rotate90DegreeBlt (HDC hDC1, INT cx, INT cy, BOOL bRight, BOOL bMono)
 
HBITMAP SkewDIB (HDC hDC1, HBITMAP hbm, INT nDegree, BOOL bVertical, BOOL bMono)
 
HBITMAP getSubImage (HBITMAP hbmWhole, const RECT &rcPartial)
 
void putSubImage (HBITMAP hbmWhole, const RECT &rcPartial, HBITMAP hbmPart)
 
HGLOBAL BitmapToClipboardDIB (HBITMAP hBitmap)
 
HBITMAP BitmapFromClipboardDIB (HGLOBAL hGlobal)
 
HBITMAP BitmapFromHEMF (HENHMETAFILE hEMF)
 
BOOL IsBitmapBlackAndWhite (HBITMAP hbm)
 
HBITMAP ConvertToBlackAndWhite (HBITMAP hbm)
 

Variables

INT g_fileSize = 0
 
float g_xDpi = 96
 
float g_yDpi = 96
 
SYSTEMTIME g_fileTime
 

Macro Definition Documentation

◆ WIDTHBYTES

#define WIDTHBYTES (   i)    (((i) + 31) / 32 * 4)

Definition at line 15 of file dib.cpp.

Function Documentation

◆ BitmapFromClipboardDIB()

HBITMAP BitmapFromClipboardDIB ( HGLOBAL  hGlobal)

Definition at line 538 of file dib.cpp.

539{
540 CWaitCursor waitCursor;
541
542 LPBYTE pb = (LPBYTE)GlobalLock(hGlobal);
543 if (!pb)
544 return NULL;
545
547 pb += pbmi->bmiHeader.biSize;
548
549 INT cColors = 0, cbColors = 0;
550 if (pbmi->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
551 {
553 WORD BitCount = pbmci->bmciHeader.bcBitCount;
554 if (BitCount < 16)
555 {
556 cColors = (1 << BitCount);
557 cbColors = cColors * sizeof(RGBTRIPLE);
558 pb += cbColors;
559 }
560 }
561 else if (pbmi->bmiHeader.biSize >= sizeof(BITMAPINFOHEADER))
562 {
563 WORD BitCount = pbmi->bmiHeader.biBitCount;
564 if (BitCount < 16)
565 {
566 cColors = (1 << BitCount);
567 cbColors = cColors * sizeof(RGBQUAD);
568 pb += cbColors;
569 }
570 }
571
574 if (hBitmap)
575 {
577 }
578 DeleteDC(hDC);
579
580 GlobalUnlock(hGlobal);
581
582 return hBitmap;
583}
static HDC hDC
Definition: 3dtext.c:33
#define NULL
Definition: types.h:112
static HBITMAP hBitmap
Definition: timezone.c:26
_ACRTIMP __msvcrt_long __cdecl labs(__msvcrt_long)
Definition: math.c:680
ULONG RGBQUAD
Definition: precomp.h:47
unsigned short WORD
Definition: ntddk_ex.h:93
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
static ERESOURCE GlobalLock
Definition: sys_arch.c:8
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:1899
USHORT biBitCount
Definition: precomp.h:34
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1922
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 585 of file dib.cpp.

586{
587 CWaitCursor waitCursor;
588
590 if (!GetEnhMetaFileHeader(hEMF, sizeof(header), &header))
591 return NULL;
592
593 CRect rc = *(LPRECT)&header.rclBounds;
594 INT cx = rc.Width(), cy = rc.Height();
595 HBITMAP hbm = CreateColorDIB(cx, cy, RGB(255, 255, 255));
596 if (!hbm)
597 return NULL;
598
600 HGDIOBJ hbmOld = SelectObject(hDC, hbm);
601 PlayEnhMetaFile(hDC, hEMF, &rc);
602 SelectObject(hDC, hbmOld);
603 DeleteDC(hDC);
604
605 return hbm;
606}
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:67
_Out_opt_ int _Out_opt_ int * cy
Definition: commctrl.h:586
_Out_opt_ int * cx
Definition: commctrl.h:585
_In_ HBITMAP hbm
Definition: ntgdi.h:2776
#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 475 of file dib.cpp.

476{
477 CWaitCursor waitCursor;
478
479 BITMAP bm;
480 if (!GetObjectW(hBitmap, sizeof(BITMAP), &bm))
481 return NULL;
482
483 BITMAPINFODX bmi;
484 ZeroMemory(&bmi, sizeof(bmi));
485 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
486 bmi.bmiHeader.biWidth = bm.bmWidth;
487 bmi.bmiHeader.biHeight = bm.bmHeight;
488 bmi.bmiHeader.biPlanes = 1;
492
493 INT cColors;
494 if (bm.bmBitsPixel < 16)
495 cColors = 1 << bm.bmBitsPixel;
496 else
497 cColors = 0;
498
500
501 if (cColors)
502 {
503 HGDIOBJ hbmOld = SelectObject(hDC, hBitmap);
504 cColors = GetDIBColorTable(hDC, 0, cColors, bmi.bmiColors);
505 SelectObject(hDC, hbmOld);
506 }
507
508 DWORD cbColors = cColors * sizeof(RGBQUAD);
509 DWORD dwSize = sizeof(BITMAPINFOHEADER) + cbColors + bmi.bmiHeader.biSizeImage;
511 if (hGlobal)
512 {
513 LPBYTE pb = (LPBYTE)GlobalLock(hGlobal);
514 if (pb)
515 {
516 CopyMemory(pb, &bmi, sizeof(BITMAPINFOHEADER));
517 pb += sizeof(BITMAPINFOHEADER);
518
519 CopyMemory(pb, bmi.bmiColors, cbColors);
520 pb += cbColors;
521
522 GetDIBits(hDC, hBitmap, 0, bm.bmHeight, pb, &bmi, DIB_RGB_COLORS);
523
524 GlobalUnlock(hGlobal);
525 }
526 else
527 {
528 GlobalFree(hGlobal);
529 hGlobal = NULL;
530 }
531 }
532
533 DeleteDC(hDC);
534
535 return hGlobal;
536}
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
#define ZeroMemory
Definition: minwinbase.h:31
#define CopyMemory
Definition: minwinbase.h:29
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
ULONG biCompression
Definition: precomp.h:35
RGBQUAD bmiColors[1]
Definition: wingdi.h:1923
LONG bmHeight
Definition: wingdi.h:1869
LONG bmWidth
Definition: wingdi.h:1868
LONG bmWidthBytes
Definition: wingdi.h:1870
WORD bmBitsPixel
Definition: wingdi.h:1872
#define BI_RGB
Definition: uefivid.c:46
UINT WINAPI GetDIBColorTable(HDC hDC, UINT iStartIndex, UINT cEntries, RGBQUAD *pColors)
Definition: palette.c:123
#define GHND
Definition: winbase.h:321
#define GMEM_SHARE
Definition: winbase.h:329
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 142 of file dib.cpp.

143{
144 if (minimalWidth <= 0)
145 minimalWidth = 1;
146 if (minimalHeight <= 0)
147 minimalHeight = 1;
148
149 BITMAP bm;
150 if (!GetObjectW(hbm, sizeof(bm), &bm))
151 hbm = NULL;
152
153 if (hbm && minimalWidth <= bm.bmWidth && minimalHeight <= bm.bmHeight)
154 return hbm;
155
156 if (hbm)
158
159 return CreateDIBWithProperties((minimalWidth * 3) / 2, (minimalHeight * 3) / 2);
160}
HBITMAP CreateDIBWithProperties(int width, int height)
Definition: dib.cpp:32
pKey DeleteObject()

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

◆ ConvertToBlackAndWhite()

HBITMAP ConvertToBlackAndWhite ( HBITMAP  hbm)

Definition at line 659 of file dib.cpp.

660{
661 CWaitCursor waitCursor;
662
663 BITMAP bm;
664 if (!::GetObjectW(hbm, sizeof(bm), &bm))
665 return NULL;
666
667 BITMAPINFOEX bmi;
668 ZeroMemory(&bmi, sizeof(bmi));
669 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
670 bmi.bmiHeader.biWidth = bm.bmWidth;
671 bmi.bmiHeader.biHeight = bm.bmHeight;
672 bmi.bmiHeader.biPlanes = 1;
673 bmi.bmiHeader.biBitCount = 1;
674 bmi.bmiColors[1].rgbBlue = 255;
675 bmi.bmiColors[1].rgbGreen = 255;
676 bmi.bmiColors[1].rgbRed = 255;
678 LPVOID pvMonoBits;
679 HBITMAP hMonoBitmap = ::CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, &pvMonoBits, NULL, 0);
680 if (!hMonoBitmap)
681 {
683 return NULL;
684 }
685
686 HBITMAP hNewBitmap = CreateDIBWithProperties(bm.bmWidth, bm.bmHeight);
687 if (hNewBitmap)
688 {
689 ::GetDIBits(hdc, hbm, 0, bm.bmHeight, pvMonoBits, &bmi, DIB_RGB_COLORS);
690 ::SetDIBits(hdc, hNewBitmap, 0, bm.bmHeight, pvMonoBits, &bmi, DIB_RGB_COLORS);
691 }
692 ::DeleteObject(hMonoBitmap);
694
695 return hNewBitmap;
696}
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()

HBITMAP CopyDIBImage ( HBITMAP  hbm,
INT  cx,
INT  cy,
INT  stretchMode 
)

Definition at line 113 of file dib.cpp.

114{
115 if (stretchMode == STRETCH_HALFTONE)
117
118 BITMAP bm;
119 if (!::GetObjectW(hbm, sizeof(bm), &bm))
120 return NULL;
121
122 if (cx == 0 || cy == 0)
123 {
124 cx = bm.bmWidth;
125 cy = bm.bmHeight;
126 }
127
131 HGDIOBJ hbm1Old = ::SelectObject(hdc1, hbm);
132 HGDIOBJ hbm2Old = ::SelectObject(hdc2, hbmNew);
133 ::SetStretchBltMode(hdc2, stretchMode);
134 ::StretchBlt(hdc2, 0, 0, cx, cy, hdc1, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
135 ::SelectObject(hdc1, hbm1Old);
136 ::SelectObject(hdc2, hbm2Old);
139 return hbmNew;
140}
HDC hdc1
Definition: SelectObject.c:10
HDC hdc2
Definition: SelectObject.c:10
#define STRETCH_HALFTONE
Definition: wingdi.h:959
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
int WINAPI SetStretchBltMode(_In_ HDC, _In_ int)
Definition: dc.c:1373
#define IMAGE_BITMAP
Definition: winuser.h:211
#define LR_CREATEDIBSECTION
Definition: winuser.h:1109
HANDLE WINAPI CopyImage(_In_ HANDLE, _In_ UINT, _In_ int, _In_ int, _In_ UINT)
Definition: cursoricon.c:2307

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

◆ CopyMonoImage()

HBITMAP CopyMonoImage ( HBITMAP  hbm,
INT  cx,
INT  cy,
INT  stretchMode 
)

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
101 HBITMAP hbmNew = ::CreateBitmap(cx, cy, 1, 1, NULL);
102 HGDIOBJ hbm1Old = ::SelectObject(hdc1, hbm);
103 HGDIOBJ hbm2Old = ::SelectObject(hdc2, hbmNew);
104 ::SetStretchBltMode(hdc2, stretchMode);
105 ::StretchBlt(hdc2, 0, 0, cx, cy, hdc1, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
106 ::SelectObject(hdc1, hbm1Old);
107 ::SelectObject(hdc2, hbm2Old);
110 return hbmNew;
111}
HBITMAP WINAPI CreateBitmap(_In_ INT cx, _In_ INT cy, _In_ UINT cPlanes, _In_ UINT cBitsPerPel, _In_opt_ const VOID *pvBits)

Referenced by CStyledCursor::CreateStyledCursor(), and 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}
return ret
Definition: mutex.c:146
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
GLint GLint GLsizei width
Definition: gl.h:1546
_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 
)

◆ 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 284 of file dib.cpp.

285{
286 CWaitCursor waitCursor;
287
288 // find the file
290 HANDLE hFind = ::FindFirstFileW(name, &find);
291 if (hFind == INVALID_HANDLE_VALUE) // does not exist
292 {
294 return NULL;
295 }
296 ::FindClose(hFind);
297
298 // is file empty?
299 if (find.nFileSizeLow == 0 && find.nFileSizeHigh == 0)
300 {
301 if (fIsMainFile)
302 return InitializeImage(name, &find, TRUE);
303 }
304
305 // load the image
307 float xDpi = 0, yDpi = 0;
308 HRESULT hr = img.LoadDx(name, &xDpi, &yDpi);
309 if (FAILED(hr) && fIsMainFile)
310 {
312 hr = img.LoadDx(name, &xDpi, &yDpi);
313 }
314 if (FAILED(hr))
315 {
316 ATLTRACE("hr: 0x%08lX\n", hr);
318 return NULL;
319 }
320
321 HBITMAP hBitmap = img.Detach();
322 if (!fIsMainFile)
323 return hBitmap;
324
325 if (xDpi <= 0 || yDpi <= 0)
326 {
327 HDC hDC = ::GetDC(NULL);
331 }
332
333 g_xDpi = xDpi;
334 g_yDpi = yDpi;
335
337 return hBitmap;
338}
#define ATLTRACE(format,...)
Definition: atltrace.h:269
VOID ShowError(DWORD dwLastError)
Definition: progress.c:29
#define IDS_LOADERRORTEXT
Definition: resource.h:222
void ClearHistory(void)
Definition: history.cpp:114
static TAGID TAGID find
Definition: db.cpp:156
HRESULT hr
Definition: delayimp.cpp:582
HBITMAP InitializeImage(LPCWSTR name, LPWIN32_FIND_DATAW pFound, BOOL isFile)
Definition: dib.cpp:253
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:272
#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
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  hBitmap)

Definition at line 171 of file dib.cpp.

172{
173 BITMAP bm;
174 ::GetObjectW(hBitmap, sizeof(BITMAP), &bm);
175 return bm.bmHeight;
176}

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

◆ GetDIBWidth()

int GetDIBWidth ( HBITMAP  hBitmap)

Definition at line 163 of file dib.cpp.

164{
165 BITMAP bm;
166 ::GetObjectW(hBitmap, sizeof(BITMAP), &bm);
167 return bm.bmWidth;
168}

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

◆ getSubImage()

HBITMAP getSubImage ( HBITMAP  hbmWhole,
const RECT rcPartial 
)

Definition at line 437 of file dib.cpp.

438{
439 CRect rc = rcPartial;
440 HBITMAP hbmPart = CreateDIBWithProperties(rc.Width(), rc.Height());
441 if (!hbmPart)
442 return NULL;
443
446 HGDIOBJ hbm1Old = ::SelectObject(hDC1, hbmWhole);
447 HGDIOBJ hbm2Old = ::SelectObject(hDC2, hbmPart);
448 ::BitBlt(hDC2, 0, 0, rc.Width(), rc.Height(), hDC1, rc.left, rc.top, SRCCOPY);
449 ::SelectObject(hDC1, hbm1Old);
450 ::SelectObject(hDC2, hbm2Old);
451 ::DeleteDC(hDC1);
452 ::DeleteDC(hDC2);
453 return hbmPart;
454}
static VOID BitBlt(_In_ ULONG Left, _In_ ULONG Top, _In_ ULONG Width, _In_ ULONG Height, _In_reads_bytes_(Height *Stride) PUCHAR Buffer, _In_ ULONG BitsPerPixel, _In_ ULONG Stride)
Definition: common.c:42
LONG top
Definition: windef.h:107
LONG left
Definition: windef.h:106

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

◆ InitializeImage()

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

Definition at line 253 of file dib.cpp.

254{
255 COLORREF white = RGB(255, 255, 255);
257 if (hBitmap == NULL)
258 {
261 return NULL;
262 }
263
264 HDC hScreenDC = ::GetDC(NULL);
265 g_xDpi = (float)::GetDeviceCaps(hScreenDC, LOGPIXELSX);
266 g_yDpi = (float)::GetDeviceCaps(hScreenDC, LOGPIXELSY);
267 ::ReleaseDC(NULL, hScreenDC);
268
269 return SetBitmapAndInfo(hBitmap, name, pFound, isFile);
270}
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:100

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

◆ IsBitmapBlackAndWhite()

BOOL IsBitmapBlackAndWhite ( HBITMAP  hbm)

Definition at line 608 of file dib.cpp.

609{
610 CWaitCursor waitCursor;
611
612 BITMAP bm;
613 if (!::GetObjectW(hbm, sizeof(bm), &bm))
614 return FALSE;
615
616 if (bm.bmBitsPixel == 1)
617 return TRUE;
618
619 BITMAPINFOEX bmi;
620 ZeroMemory(&bmi, sizeof(bmi));
621 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
622 bmi.bmiHeader.biWidth = bm.bmWidth;
623 bmi.bmiHeader.biHeight = bm.bmHeight;
624 bmi.bmiHeader.biPlanes = 1;
625 bmi.bmiHeader.biBitCount = 24;
626
627 DWORD widthbytes = WIDTHBYTES(24 * bm.bmWidth);
628 DWORD cbBits = widthbytes * bm.bmHeight;
629 LPBYTE pbBits = new BYTE[cbBits];
630
632 ::GetDIBits(hdc, hbm, 0, bm.bmHeight, pbBits, &bmi, DIB_RGB_COLORS);
634
635 BOOL bBlackAndWhite = TRUE;
636 for (LONG y = 0; y < bm.bmHeight; ++y)
637 {
638 LPBYTE pbLine = &pbBits[widthbytes * y];
639 for (LONG x = 0; x < bm.bmWidth; ++x)
640 {
641 BYTE Blue = *pbLine++;
642 BYTE Green = *pbLine++;
643 BYTE Red = *pbLine++;
644 COLORREF rgbColor = RGB(Red, Green, Blue);
645 if (rgbColor != RGB(0, 0, 0) && rgbColor != RGB(255, 255, 255))
646 {
647 bBlackAndWhite = FALSE;
648 goto Finish;
649 }
650 }
651 }
652
653Finish:
654 delete[] pbBits;
655
656 return bBlackAndWhite;
657}
#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 456 of file dib.cpp.

457{
458 CRect rc = rcPartial;
461 HGDIOBJ hbm1Old = ::SelectObject(hDC1, hbmWhole);
462 HGDIOBJ hbm2Old = ::SelectObject(hDC2, hbmPart);
463 ::BitBlt(hDC1, rc.left, rc.top, rc.Width(), rc.Height(), hDC2, 0, 0, SRCCOPY);
464 ::SelectObject(hDC1, hbm1Old);
465 ::SelectObject(hDC2, hbm2Old);
466 ::DeleteDC(hDC1);
467 ::DeleteDC(hDC2);
468}

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

◆ Rotate90DegreeBlt()

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

Definition at line 340 of file dib.cpp.

341{
342 HBITMAP hbm2;
343 if (bMono)
344 hbm2 = ::CreateBitmap(cy, cx, 1, 1, NULL);
345 else
347 if (!hbm2)
348 return NULL;
349
351 HGDIOBJ hbm2Old = SelectObject(hDC2, hbm2);
352 if (bRight)
353 {
354 for (INT y = 0; y < cy; ++y)
355 {
356 for (INT x = 0; x < cx; ++x)
357 {
358 COLORREF rgb = GetPixel(hDC1, x, y);
359 SetPixelV(hDC2, cy - (y + 1), x, rgb);
360 }
361 }
362 }
363 else
364 {
365 for (INT y = 0; y < cy; ++y)
366 {
367 for (INT x = 0; x < cx; ++x)
368 {
369 COLORREF rgb = GetPixel(hDC1, x, y);
370 SetPixelV(hDC2, y, cx - (x + 1), rgb);
371 }
372 }
373 }
374 SelectObject(hDC2, hbm2Old);
375 DeleteDC(hDC2);
376 return hbm2;
377}
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 
)

Definition at line 178 of file dib.cpp.

179{
180 CWaitCursor waitCursor;
181
183 img.Attach(hBitmap);
184 HRESULT hr = img.SaveDx(FileName, guidFileType, g_xDpi, g_yDpi);
185 img.Detach();
186
187 if (FAILED(hr))
188 {
190 return FALSE;
191 }
192
193 if (!fIsMainFile)
194 return TRUE;
195
198 if (hFind == INVALID_HANDLE_VALUE)
199 {
201 return FALSE;
202 }
203 ::FindClose(hFind);
204
207 return TRUE;
208}
BOOL g_imageSaved
Definition: main.cpp:21
#define IDS_SAVEERROR
Definition: resource.h:231
void SetFileInfo(LPCWSTR name, LPWIN32_FIND_DATAW pFound, BOOL isAFile)
Definition: dib.cpp:210

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

◆ SetBitmapAndInfo()

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

Definition at line 272 of file dib.cpp.

273{
274 // update image
278
279 SetFileInfo(name, pFound, isFile);
281 return hBitmap;
282}
CCanvasWindow canvasWindow
Definition: canvas.cpp:11
VOID updateScrollPos(INT x=0, INT y=0)
Definition: canvas.cpp:402
void PushImageForUndo()
Definition: history.cpp:125

Referenced by DoLoadImageFile(), and InitializeImage().

◆ SetFileInfo()

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

Definition at line 210 of file dib.cpp.

211{
212 // update file time and size
213 if (pFound)
214 {
215 FILETIME ft;
218
219 g_fileSize = pFound->nFileSizeLow;
220 }
221 else
222 {
224 g_fileSize = 0;
225 }
226
227 // update g_szFileName
228 if (name && name[0])
229 {
230 CStringW strName = name;
232 // The following code won't work correctly when (name == g_szFileName):
233 // ::GetFullPathNameW(name, _countof(g_szFileName), g_szFileName, NULL);
234 }
235 else
236 {
238 }
239
240 // set title
241 CStringW strTitle;
243 mainWindow.SetWindowText(strTitle);
244
245 // update file info and recent
246 g_isAFile = isAFile;
247 if (g_isAFile)
249
251}
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:194
#define IDS_WINDOWTITLE
Definition: resource.h:189
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:183
BOOL WINAPI FileTimeToLocalFileTime(IN CONST FILETIME *lpFileTime, OUT LPFILETIME lpLocalFileTime)
Definition: time.c:216
WCHAR *WINAPI PathFindFileNameW(const WCHAR *path)
Definition: path.c:1677
#define LoadStringW
Definition: utils.h:64
#define _countof(array)
Definition: sndvol32.h:70
FILETIME ftLastWriteTime
Definition: minwinbase.h:286

Referenced by SaveDIBToFile(), and SetBitmapAndInfo().

◆ SkewDIB()

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

Definition at line 379 of file dib.cpp.

380{
381 CWaitCursor waitCursor;
382
383 if (nDegree == 0)
384 return CopyDIBImage(hbm);
385
386 const double eTan = tan(abs(nDegree) * M_PI / 180);
387
388 BITMAP bm;
389 ::GetObjectW(hbm, sizeof(bm), &bm);
390 INT cx = bm.bmWidth, cy = bm.bmHeight, dx = 0, dy = 0;
391 if (bVertical)
392 dy = INT(cx * eTan);
393 else
394 dx = INT(cy * eTan);
395
396 if (dx == 0 && dy == 0)
397 return CopyDIBImage(hbm);
398
399 HBITMAP hbmNew;
400 if (bMono)
401 hbmNew = CreateMonoBitmap(cx + dx, cy + dy, FALSE);
402 else
403 hbmNew = CreateColorDIB(cx + dx, cy + dy, RGB(255, 255, 255));
404 if (!hbmNew)
405 return NULL;
406
408 HGDIOBJ hbm2Old = SelectObject(hDC2, hbmNew);
409 if (bVertical)
410 {
411 for (INT x = 0; x < cx; ++x)
412 {
413 INT delta = INT(x * eTan);
414 if (nDegree > 0)
415 ::BitBlt(hDC2, x, (dy - delta), 1, cy, hDC1, x, 0, SRCCOPY);
416 else
417 ::BitBlt(hDC2, x, delta, 1, cy, hDC1, x, 0, SRCCOPY);
418 }
419 }
420 else
421 {
422 for (INT y = 0; y < cy; ++y)
423 {
424 INT delta = INT(y * eTan);
425 if (nDegree > 0)
426 ::BitBlt(hDC2, (dx - delta), y, cx, 1, hDC1, 0, y, SRCCOPY);
427 else
428 ::BitBlt(hDC2, delta, y, cx, 1, hDC1, 0, y, SRCCOPY);
429 }
430 }
431
432 SelectObject(hDC2, hbm2Old);
433 DeleteDC(hDC2);
434 return hbmNew;
435}
HBITMAP CreateMonoBitmap(int width, int height, BOOL bWhite)
Definition: dib.cpp:45
HBITMAP CopyDIBImage(HBITMAP hbm, INT cx, INT cy, INT stretchMode)
Definition: dib.cpp:113
_ACRTIMP double __cdecl tan(double)
Definition: tan.c:122
#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().

Variable Documentation

◆ g_fileSize

INT g_fileSize = 0

Definition at line 10 of file dib.cpp.

Referenced by CAttributesDialog::OnInitDialog(), and SetFileInfo().

◆ g_fileTime

SYSTEMTIME g_fileTime

Definition at line 13 of file dib.cpp.

Referenced by CAttributesDialog::OnInitDialog(), and SetFileInfo().

◆ g_xDpi

◆ g_yDpi