ReactOS 0.4.15-dev-6679-g945ee4b
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)
 
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)
 
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 467 of file dib.cpp.

468{
469 CWaitCursor waitCursor;
470
471 LPBYTE pb = (LPBYTE)GlobalLock(hGlobal);
472 if (!pb)
473 return NULL;
474
476 pb += pbmi->bmiHeader.biSize;
477
478 INT cColors = 0, cbColors = 0;
479 if (pbmi->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
480 {
482 WORD BitCount = pbmci->bmciHeader.bcBitCount;
483 if (BitCount < 16)
484 {
485 cColors = (1 << BitCount);
486 cbColors = cColors * sizeof(RGBTRIPLE);
487 pb += cbColors;
488 }
489 }
490 else if (pbmi->bmiHeader.biSize >= sizeof(BITMAPINFOHEADER))
491 {
492 WORD BitCount = pbmi->bmiHeader.biBitCount;
493 if (BitCount < 16)
494 {
495 cColors = (1 << BitCount);
496 cbColors = cColors * sizeof(RGBQUAD);
497 pb += cbColors;
498 }
499 }
500
503 if (hBitmap)
504 {
506 }
507 DeleteDC(hDC);
508
509 GlobalUnlock(hGlobal);
510
511 return hBitmap;
512}
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:50
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:92
_In_ HBITMAP _In_ UINT _In_ UINT _Inout_ LPBITMAPINFO pbmi
Definition: ntgdi.h:2780
BITMAPCOREHEADER bmciHeader
Definition: wingdi.h:1453
USHORT biBitCount
Definition: precomp.h:37
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 514 of file dib.cpp.

515{
516 CWaitCursor waitCursor;
517
519 if (!GetEnhMetaFileHeader(hEMF, sizeof(header), &header))
520 return NULL;
521
522 CRect rc = *(LPRECT)&header.rclBounds;
523 INT cx = rc.Width(), cy = rc.Height();
524 HBITMAP hbm = CreateColorDIB(cx, cy, RGB(255, 255, 255));
525 if (!hbm)
526 return NULL;
527
529 HGDIOBJ hbmOld = SelectObject(hDC, hbm);
530 PlayEnhMetaFile(hDC, hEMF, &rc);
531 SelectObject(hDC, hbmOld);
532 DeleteDC(hDC);
533
534 return hbm;
535}
int Width() const
Definition: atltypes.h:407
int Height() const
Definition: atltypes.h:318
HBITMAP CreateColorDIB(int width, int height, COLORREF rgb)
Definition: dib.cpp:65
#define RGB(r, g, b)
Definition: precomp.h:62
_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:1539
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 404 of file dib.cpp.

405{
406 CWaitCursor waitCursor;
407
408 BITMAP bm;
409 if (!GetObject(hBitmap, sizeof(BITMAP), &bm))
410 return NULL;
411
412 BITMAPINFODX bmi;
413 ZeroMemory(&bmi, sizeof(bmi));
414 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
415 bmi.bmiHeader.biWidth = bm.bmWidth;
416 bmi.bmiHeader.biHeight = bm.bmHeight;
417 bmi.bmiHeader.biPlanes = 1;
418 bmi.bmiHeader.biBitCount = bm.bmBitsPixel;
420 bmi.bmiHeader.biSizeImage = bm.bmWidthBytes * bm.bmHeight;
421
422 INT cColors;
423 if (bm.bmBitsPixel < 16)
424 cColors = 1 << bm.bmBitsPixel;
425 else
426 cColors = 0;
427
429
430 if (cColors)
431 {
432 HGDIOBJ hbmOld = SelectObject(hDC, hBitmap);
433 cColors = GetDIBColorTable(hDC, 0, cColors, bmi.bmiColors);
434 SelectObject(hDC, hbmOld);
435 }
436
437 DWORD cbColors = cColors * sizeof(RGBQUAD);
438 DWORD dwSize = sizeof(BITMAPINFOHEADER) + cbColors + bmi.bmiHeader.biSizeImage;
440 if (hGlobal)
441 {
442 LPBYTE pb = (LPBYTE)GlobalLock(hGlobal);
443 if (pb)
444 {
445 CopyMemory(pb, &bmi, sizeof(BITMAPINFOHEADER));
446 pb += sizeof(BITMAPINFOHEADER);
447
448 CopyMemory(pb, bmi.bmiColors, cbColors);
449 pb += cbColors;
450
451 GetDIBits(hDC, hBitmap, 0, bm.bmHeight, pb, &bmi, DIB_RGB_COLORS);
452
453 GlobalUnlock(hGlobal);
454 }
455 else
456 {
457 GlobalFree(hGlobal);
458 hGlobal = NULL;
459 }
460 }
461
462 DeleteDC(hDC);
463
464 return hGlobal;
465}
#define BI_RGB
Definition: precomp.h:47
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:38
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:1700
#define CopyMemory
Definition: winbase.h:1698
#define GHND
Definition: winbase.h:297
#define GMEM_SHARE
Definition: winbase.h:305
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)
#define GetObject
Definition: wingdi.h:4468

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 (!GetObject(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 588 of file dib.cpp.

589{
590 CWaitCursor waitCursor;
591
592 BITMAP bm;
593 if (!::GetObject(hbm, sizeof(bm), &bm))
594 return NULL;
595
596 BITMAPINFOEX bmi;
597 ZeroMemory(&bmi, sizeof(bmi));
598 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
599 bmi.bmiHeader.biWidth = bm.bmWidth;
600 bmi.bmiHeader.biHeight = bm.bmHeight;
601 bmi.bmiHeader.biPlanes = 1;
602 bmi.bmiHeader.biBitCount = 1;
603 bmi.bmiColors[1].rgbBlue = 255;
604 bmi.bmiColors[1].rgbGreen = 255;
605 bmi.bmiColors[1].rgbRed = 255;
607 LPVOID pvMonoBits;
608 HBITMAP hMonoBitmap = ::CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, &pvMonoBits, NULL, 0);
609 if (!hMonoBitmap)
610 {
612 return NULL;
613 }
614
615 HBITMAP hNewBitmap = CreateDIBWithProperties(bm.bmWidth, bm.bmHeight);
616 if (hNewBitmap)
617 {
618 ::GetDIBits(hdc, hbm, 0, bm.bmHeight, pvMonoBits, &bmi, DIB_RGB_COLORS);
619 ::SetDIBits(hdc, hNewBitmap, 0, bm.bmHeight, pvMonoBits, &bmi, DIB_RGB_COLORS);
620 }
621 ::DeleteObject(hMonoBitmap);
623
624 return hNewBitmap;
625}
HDC hdc
Definition: main.c:9
UCHAR rgbBlue
Definition: bootanim.c:97
UCHAR rgbRed
Definition: bootanim.c:99
UCHAR rgbGreen
Definition: bootanim.c:98

Referenced by ImageModel::PushBlackAndWhite().

◆ CopyMonoImage()

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

Definition at line 87 of file dib.cpp.

88{
89 BITMAP bm;
90 if (!GetObject(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);
110 DeleteDC(hdc1);
111 DeleteDC(hdc2);
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(), 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(), ImageModel::Crop(), 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 252 of file dib.cpp.

253{
254 CWaitCursor waitCursor;
255
256 // find the file
258 HANDLE hFind = ::FindFirstFileW(name, &find);
259 if (hFind == INVALID_HANDLE_VALUE) // does not exist
260 {
262 return NULL;
263 }
264 ::FindClose(hFind);
265
266 // is file empty?
267 if (find.nFileSizeLow == 0 && find.nFileSizeHigh == 0)
268 {
269 if (fIsMainFile)
270 return InitializeImage(name, &find, TRUE);
271 }
272
273 // load the image
275 float xDpi = 0, yDpi = 0;
276 HRESULT hr = img.LoadDx(name, &xDpi, &yDpi);
277 if (FAILED(hr))
278 {
280 return NULL;
281 }
282
283 HBITMAP hBitmap = img.Detach();
284 if (!fIsMainFile)
285 return hBitmap;
286
287 if (xDpi <= 0 || yDpi <= 0)
288 {
289 HDC hDC = ::GetDC(NULL);
293 }
294
295 g_xDpi = xDpi;
296 g_yDpi = yDpi;
297
299 return hBitmap;
300}
VOID ShowError(DWORD dwLastError)
Definition: progress.c:29
#define IDS_LOADERRORTEXT
Definition: resource.h:217
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:241
#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
#define FAILED(hr)
Definition: intsafe.h:51
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 _tWinMain(), CMainWindow::OnCommand(), and CMainWindow::OnDropFiles().

◆ GetDIBHeight()

int GetDIBHeight ( HBITMAP  hBitmap)

Definition at line 144 of file dib.cpp.

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

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

◆ GetDIBWidth()

int GetDIBWidth ( HBITMAP  hBitmap)

Definition at line 136 of file dib.cpp.

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

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

◆ 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 return NULL;
232
233 HDC hScreenDC = ::GetDC(NULL);
234 g_xDpi = ::GetDeviceCaps(hScreenDC, LOGPIXELSX);
235 g_yDpi = ::GetDeviceCaps(hScreenDC, LOGPIXELSY);
236 ::ReleaseDC(NULL, hScreenDC);
237
238 return SetBitmapAndInfo(hBitmap, name, pFound, isFile);
239}
DWORD BMPWidth
Definition: registry.h:19
DWORD BMPHeight
Definition: registry.h:18
RegistrySettings registrySettings
Definition: registry.cpp:14
DWORD COLORREF
Definition: windef.h:300

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

◆ IsBitmapBlackAndWhite()

BOOL IsBitmapBlackAndWhite ( HBITMAP  hbm)

Definition at line 537 of file dib.cpp.

538{
539 CWaitCursor waitCursor;
540
541 BITMAP bm;
542 if (!::GetObjectW(hbm, sizeof(bm), &bm))
543 return FALSE;
544
545 if (bm.bmBitsPixel == 1)
546 return TRUE;
547
548 BITMAPINFOEX bmi;
549 ZeroMemory(&bmi, sizeof(bmi));
550 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
551 bmi.bmiHeader.biWidth = bm.bmWidth;
552 bmi.bmiHeader.biHeight = bm.bmHeight;
553 bmi.bmiHeader.biPlanes = 1;
554 bmi.bmiHeader.biBitCount = 24;
555
556 DWORD widthbytes = WIDTHBYTES(24 * bm.bmWidth);
557 DWORD cbBits = widthbytes * bm.bmHeight;
558 LPBYTE pbBits = new BYTE[cbBits];
559
561 ::GetDIBits(hdc, hbm, 0, bm.bmHeight, pbBits, &bmi, DIB_RGB_COLORS);
563
564 BOOL bBlackAndWhite = TRUE;
565 for (LONG y = 0; y < bm.bmHeight; ++y)
566 {
567 LPBYTE pbLine = &pbBits[widthbytes * y];
568 for (LONG x = 0; x < bm.bmWidth; ++x)
569 {
570 BYTE Blue = *pbLine++;
571 BYTE Green = *pbLine++;
572 BYTE Red = *pbLine++;
573 COLORREF rgbColor = RGB(Red, Green, Blue);
574 if (rgbColor != RGB(0, 0, 0) && rgbColor != RGB(255, 255, 255))
575 {
576 bBlackAndWhite = FALSE;
577 goto Finish;
578 }
579 }
580 }
581
582Finish:
583 delete[] pbBits;
584
585 return bBlackAndWhite;
586}
@ 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
int WINAPI GetObjectW(_In_ HANDLE h, _In_ int c, _Out_writes_bytes_opt_(c) LPVOID pv)
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().

◆ Rotate90DegreeBlt()

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

Definition at line 302 of file dib.cpp.

303{
304 HBITMAP hbm2;
305 if (bMono)
306 hbm2 = ::CreateBitmap(cy, cx, 1, 1, NULL);
307 else
309 if (!hbm2)
310 return NULL;
311
313 HGDIOBJ hbm2Old = SelectObject(hDC2, hbm2);
314 if (bRight)
315 {
316 for (INT y = 0; y < cy; ++y)
317 {
318 for (INT x = 0; x < cx; ++x)
319 {
320 COLORREF rgb = GetPixel(hDC1, x, y);
321 SetPixelV(hDC2, cy - (y + 1), x, rgb);
322 }
323 }
324 }
325 else
326 {
327 for (INT y = 0; y < cy; ++y)
328 {
329 for (INT x = 0; x < cx; ++x)
330 {
331 COLORREF rgb = GetPixel(hDC1, x, y);
332 SetPixelV(hDC2, y, cx - (x + 1), rgb);
333 }
334 }
335 }
336 SelectObject(hDC2, hbm2Old);
337 DeleteDC(hDC2);
338 return hbm2;
339}
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 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}
#define IDS_SAVEERROR
Definition: resource.h:226
void SetFileInfo(LPCWSTR name, LPWIN32_FIND_DATAW pFound, BOOL isAFile)
Definition: dib.cpp:183
BOOL g_imageSaved
Definition: main.cpp:19

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

◆ SetBitmapAndInfo()

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

Definition at line 241 of file dib.cpp.

242{
243 // update image
246
247 SetFileInfo(name, pFound, isFile);
249 return hBitmap;
250}
void PushImageForUndo(HBITMAP hbm=NULL)
Definition: history.cpp:106
void ClearHistory(void)
Definition: history.cpp:100
ImageModel imageModel
Definition: history.cpp:11

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 CString strTitle;
216 mainWindow.SetWindowText(strTitle);
217
218 // update file info and recent
219 g_isAFile = isAFile;
220 if (g_isAFile)
222
224}
#define IDS_DEFAULTFILENAME
Definition: resource.h:189
#define IDS_WINDOWTITLE
Definition: resource.h:184
void __cdecl Format(UINT nFormatID,...)
Definition: cstringt.h:818
BOOL SetWindowText(LPCTSTR lpszString)
Definition: atlwin.h:1300
void SetMostRecentFile(LPCTSTR szPathName)
Definition: registry.cpp:254
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
TCHAR g_szFileName[MAX_LONG_PATH]
Definition: main.cpp:16
CMainWindow mainWindow
Definition: main.cpp:22
BOOL g_isAFile
Definition: main.cpp:18
HINSTANCE g_hinstExe
Definition: main.cpp:15
#define PathFindFileName
Definition: shlwapi.h:911
#define _countof(array)
Definition: sndvol32.h:68
FILETIME ftLastWriteTime
Definition: winbase.h:942
DWORD nFileSizeLow
Definition: winbase.h:944
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 
)

Definition at line 341 of file dib.cpp.

342{
343 CWaitCursor waitCursor;
344
345 if (nDegree == 0)
346 return CopyDIBImage(hbm);
347
348 const double eTan = tan(abs(nDegree) * M_PI / 180);
349
350 BITMAP bm;
351 GetObjectW(hbm, sizeof(bm), &bm);
352 INT cx = bm.bmWidth, cy = bm.bmHeight, dx = 0, dy = 0;
353 if (bVertical)
354 dy = INT(cx * eTan);
355 else
356 dx = INT(cy * eTan);
357
358 if (dx == 0 && dy == 0)
359 return CopyDIBImage(hbm);
360
361 HBITMAP hbmNew;
362 if (bMono)
363 hbmNew = CreateMonoBitmap(cx + dx, cy + dy, FALSE);
364 else
365 hbmNew = CreateColorDIB(cx + dx, cy + dy, RGB(255, 255, 255));
366 if (!hbmNew)
367 return NULL;
368
370 HGDIOBJ hbm2Old = SelectObject(hDC2, hbmNew);
371 if (bVertical)
372 {
373 for (INT x = 0; x < cx; ++x)
374 {
375 INT delta = INT(x * eTan);
376 if (nDegree > 0)
377 BitBlt(hDC2, x, (dy - delta), 1, cy, hDC1, x, 0, SRCCOPY);
378 else
379 BitBlt(hDC2, x, delta, 1, cy, hDC1, x, 0, SRCCOPY);
380 }
381 }
382 else
383 {
384 for (INT y = 0; y < cy; ++y)
385 {
386 INT delta = INT(y * eTan);
387 if (nDegree > 0)
388 BitBlt(hDC2, (dx - delta), y, cx, 1, hDC1, 0, y, SRCCOPY);
389 else
390 BitBlt(hDC2, delta, y, cx, 1, hDC1, 0, y, SRCCOPY);
391 }
392 }
393
394 SelectObject(hDC2, hbm2Old);
395 DeleteDC(hDC2);
396 return hbmNew;
397}
_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
static VOID NTAPI 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:49
#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

◆ g_fileTime

SYSTEMTIME g_fileTime

Definition at line 13 of file dib.cpp.

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

◆ g_xDpi

◆ g_yDpi