ReactOS 0.4.15-dev-5893-g1bb4167
dib.cpp File Reference
#include "precomp.h"
#include <math.h>
Include dependency graph for dib.cpp:

Go to the source code of this file.

Macros

#define M_PI   3.14159265
 

Functions

float PpmFromDpi (float dpi)
 
HBITMAP CreateDIBWithProperties (int width, int height)
 
HBITMAP CreateColorDIB (int width, int height, COLORREF rgb)
 
int GetDIBWidth (HBITMAP hBitmap)
 
int GetDIBHeight (HBITMAP hBitmap)
 
BOOL SaveDIBToFile (HBITMAP hBitmap, LPTSTR FileName, HDC hDC)
 
void ShowFileLoadError (LPCTSTR name)
 
HBITMAP SetBitmapAndInfo (HBITMAP hBitmap, LPCTSTR name, DWORD dwFileSize, BOOL isFile)
 
HBITMAP DoLoadImageFile (HWND hwnd, LPCTSTR name, BOOL fIsMainFile)
 
HBITMAP Rotate90DegreeBlt (HDC hDC1, INT cx, INT cy, BOOL bRight)
 
HBITMAP SkewDIB (HDC hDC1, HBITMAP hbm, INT nDegree, BOOL bVertical)
 

Variables

INT fileSize = 0
 
float g_xDpi = 96
 
float g_yDpi = 96
 
SYSTEMTIME fileTime
 

Macro Definition Documentation

◆ M_PI

#define M_PI   3.14159265

Definition at line 259 of file dib.cpp.

Function Documentation

◆ CreateColorDIB()

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

Definition at line 40 of file dib.cpp.

41{
43 if (!ret)
44 return NULL;
45
46 if (rgb)
47 {
49 HGDIOBJ hbmOld = SelectObject(hdc, ret);
50 RECT rc;
51 SetRect(&rc, 0, 0, width, height);
52 HBRUSH hbr = CreateSolidBrush(rgb);
53 FillRect(hdc, &rc, hbr);
54 DeleteObject(hbr);
55 SelectObject(hdc, hbmOld);
57 }
58
59 return ret;
60}
HBITMAP CreateDIBWithProperties(int width, int height)
Definition: dib.cpp:26
#define NULL
Definition: types.h:112
pKey DeleteObject()
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
GLint GLint GLsizei width
Definition: gl.h:1546
HDC hdc
Definition: main.c:9
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:92
int ret
_In_ ULONG _In_ ULONG rgb
Definition: winddi.h:3521
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1539
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
HBRUSH WINAPI CreateSolidBrush(_In_ COLORREF)
BOOL WINAPI DeleteDC(_In_ HDC)
BOOL WINAPI SetRect(_Out_ LPRECT, _In_ int, _In_ int, _In_ int, _In_ int)

Referenced by SetBitmapAndInfo(), and SkewDIB().

◆ CreateDIBWithProperties()

HBITMAP CreateDIBWithProperties ( int  width,
int  height 
)

Definition at line 26 of file dib.cpp.

27{
28 BITMAPINFO bmi;
29 ZeroMemory(&bmi, sizeof(BITMAPINFO));
30 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
33 bmi.bmiHeader.biPlanes = 1;
34 bmi.bmiHeader.biBitCount = 24;
36 return CreateDIBSection(NULL, &bmi, DIB_RGB_COLORS, NULL, NULL, 0);
37}
#define BI_RGB
Definition: precomp.h:47
USHORT biBitCount
Definition: precomp.h:37
ULONG biCompression
Definition: precomp.h:38
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1476
HBITMAP WINAPI CreateDIBSection(HDC hDC, CONST BITMAPINFO *BitmapInfo, UINT Usage, VOID **Bits, HANDLE hSection, DWORD dwOffset)
Definition: bitmap.c:199
#define ZeroMemory
Definition: winbase.h:1670
#define DIB_RGB_COLORS
Definition: wingdi.h:367

Referenced by SelectionModel::CalculateBoundingBoxAndContents(), SelectionModel::CalculateContents(), CreateColorDIB(), ImageModel::Crop(), ImageModel::ImageModel(), Rotate90DegreeBlt(), and SelectionModel::ScaleContentsToFit().

◆ DoLoadImageFile()

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

Definition at line 164 of file dib.cpp.

165{
166 // find the file
168 HANDLE hFind = FindFirstFile(name, &find);
169 if (hFind == INVALID_HANDLE_VALUE)
170 {
171 // does not exist
172 CStringW strText;
173 strText.Format(IDS_LOADERRORTEXT, name);
174 MessageBoxW(hwnd, strText, NULL, MB_ICONERROR);
175 return NULL;
176 }
177 DWORD dwFileSize = find.nFileSizeLow; // get file size
178 FindClose(hFind);
179
180 // is file empty?
181 if (dwFileSize == 0)
182 {
183 if (fIsMainFile)
184 {
185 FILETIME ft;
186 FileTimeToLocalFileTime(&find.ftLastWriteTime, &ft);
189 }
190 }
191
192 // load the image
194 img.LoadDx(name, &g_xDpi, &g_yDpi);
195
196 if (g_xDpi <= 0)
197 g_xDpi = 96;
198 if (g_yDpi <= 0)
199 g_yDpi = 96;
200
201 HBITMAP hBitmap = img.Detach();
202
203 if (hBitmap == NULL)
204 {
205 // cannot open
206 CStringW strText;
207 strText.Format(IDS_LOADERRORTEXT, name);
208 MessageBoxW(hwnd, strText, NULL, MB_ICONERROR);
209 return NULL;
210 }
211
212 if (fIsMainFile)
213 {
214 FILETIME ft;
215 FileTimeToLocalFileTime(&find.ftLastWriteTime, &ft);
218 }
219
220 return hBitmap;
221}
#define IDS_LOADERRORTEXT
Definition: resource.h:215
void __cdecl Format(UINT nFormatID,...)
Definition: cstringt.h:753
static TAGID TAGID find
Definition: db.cpp:155
HBITMAP SetBitmapAndInfo(HBITMAP hBitmap, LPCTSTR name, DWORD dwFileSize, BOOL isFile)
Definition: dib.cpp:118
float g_xDpi
Definition: dib.cpp:13
float g_yDpi
Definition: dib.cpp:14
SYSTEMTIME fileTime
Definition: dib.cpp:15
#define TRUE
Definition: types.h:120
static HBITMAP hBitmap
Definition: timezone.c:26
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
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
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLvoid * img
Definition: gl.h:1956
DWORD dwFileSize
Definition: more.c:40
Definition: name.c:39
#define FindFirstFile
Definition: winbase.h:3653
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
int WINAPI MessageBoxW(_In_opt_ HWND hWnd, _In_opt_ LPCWSTR lpText, _In_opt_ LPCWSTR lpCaption, _In_ UINT uType)
#define MB_ICONERROR
Definition: winuser.h:781

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

◆ GetDIBHeight()

int GetDIBHeight ( HBITMAP  hBitmap)

◆ GetDIBWidth()

◆ PpmFromDpi()

float PpmFromDpi ( float  dpi)

Definition at line 20 of file dib.cpp.

21{
22 return dpi / 0.0254; // 1 DPI is 0.0254 meter.
23}
#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 
)

Definition at line 223 of file dib.cpp.

224{
226 if (!hbm2)
227 return NULL;
228
230 HGDIOBJ hbm2Old = SelectObject(hDC2, hbm2);
231 if (bRight)
232 {
233 for (INT y = 0; y < cy; ++y)
234 {
235 for (INT x = 0; x < cx; ++x)
236 {
237 COLORREF rgb = GetPixel(hDC1, x, y);
238 SetPixelV(hDC2, cy - (y + 1), x, rgb);
239 }
240 }
241 }
242 else
243 {
244 for (INT y = 0; y < cy; ++y)
245 {
246 for (INT x = 0; x < cx; ++x)
247 {
248 COLORREF rgb = GetPixel(hDC1, x, y);
249 SetPixelV(hDC2, y, cx - (x + 1), rgb);
250 }
251 }
252 }
253 SelectObject(hDC2, hbm2Old);
254 DeleteDC(hDC2);
255 return hbm2;
256}
DWORD GetPixel(LPDIRECTDRAWSURFACE7 Surface, UINT x, UINT y)
Definition: blt.cpp:2
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
_Out_opt_ int _Out_opt_ int * cy
Definition: commctrl.h:586
_Out_opt_ int * cx
Definition: commctrl.h:585
int32_t INT
Definition: typedefs.h:58
DWORD COLORREF
Definition: windef.h:300
BOOL WINAPI SetPixelV(_In_ HDC, _In_ int, _In_ int, _In_ COLORREF)

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

◆ SaveDIBToFile()

BOOL SaveDIBToFile ( HBITMAP  hBitmap,
LPTSTR  FileName,
HDC  hDC 
)

Definition at line 78 of file dib.cpp.

79{
81 img.Attach(hBitmap);
82 img.SaveDx(FileName, GUID_NULL, g_xDpi, g_yDpi); // TODO: error handling
83 img.Detach();
84
87 if (hFind == INVALID_HANDLE_VALUE)
88 {
90 return FALSE;
91 }
92 FindClose(hFind);
93
94 // update time and size
95 FILETIME ft;
96 FileTimeToLocalFileTime(&find.ftLastWriteTime, &ft);
98 fileSize = find.nFileSizeLow;
99
100 // TODO: update hRes and vRes
101
103
104 isAFile = TRUE;
106 return TRUE;
107}
void SetMostRecentFile(LPCTSTR szPathName)
Definition: registry.cpp:229
INT fileSize
Definition: dib.cpp:12
void ShowFileLoadError(LPCTSTR name)
Definition: dib.cpp:109
#define FALSE
Definition: types.h:117
BOOL imageSaved
Definition: main.cpp:18
RegistrySettings registrySettings
Definition: registry.cpp:15
BOOL isAFile
Definition: main.cpp:17
#define GUID_NULL
Definition: ks.h:106

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

◆ SetBitmapAndInfo()

HBITMAP SetBitmapAndInfo ( HBITMAP  hBitmap,
LPCTSTR  name,
DWORD  dwFileSize,
BOOL  isFile 
)

Definition at line 118 of file dib.cpp.

119{
120 if (hBitmap == NULL)
121 {
122 COLORREF white = RGB(255, 255, 255);
125 if (hBitmap == NULL)
126 return FALSE;
127
128 HDC hScreenDC = GetDC(NULL);
129 g_xDpi = GetDeviceCaps(hScreenDC, LOGPIXELSX);
130 g_yDpi = GetDeviceCaps(hScreenDC, LOGPIXELSY);
131 ReleaseDC(NULL, hScreenDC);
132
133 ZeroMemory(&fileTime, sizeof(fileTime));
134 }
135
136 // update image
139
140 // update fileSize
142
143 // update filepathname
144 if (name && name[0])
146 else
148
149 // set title
150 CString strTitle;
152 mainWindow.SetWindowText(strTitle);
153
154 // update file info and recent
155 isAFile = isFile;
156 if (isAFile)
158
160
161 return hBitmap;
162}
#define IDS_DEFAULTFILENAME
Definition: resource.h:186
#define IDS_WINDOWTITLE
Definition: resource.h:181
BOOL SetWindowText(LPCTSTR lpszString)
Definition: atlwin.h:1294
void Insert(HBITMAP hbm)
Definition: history.cpp:115
void ClearHistory(void)
Definition: history.cpp:109
DWORD BMPWidth
Definition: registry.h:20
DWORD BMPHeight
Definition: registry.h:19
HBITMAP CreateColorDIB(int width, int height, COLORREF rgb)
Definition: dib.cpp:40
#define RGB(r, g, b)
Definition: precomp.h:62
ImageModel imageModel
Definition: history.cpp:11
HINSTANCE hProgInstance
Definition: main.cpp:15
CMainWindow mainWindow
Definition: main.cpp:21
TCHAR filepathname[MAX_LONG_PATH]
Definition: main.cpp:16
#define PathFindFileName
Definition: shlwapi.h:911
#define _countof(array)
Definition: sndvol32.h:68
#define GetFullPathName
Definition: winbase.h:3692
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)
#define LoadString
Definition: winuser.h:5809

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

◆ ShowFileLoadError()

void ShowFileLoadError ( LPCTSTR  name)

Definition at line 109 of file dib.cpp.

110{
111 CString strText;
113 CString strProgramName;
114 strProgramName.LoadString(IDS_PROGRAMNAME);
115 mainWindow.MessageBox(strText, strProgramName, MB_OK | MB_ICONEXCLAMATION);
116}
#define IDS_PROGRAMNAME
Definition: resource.h:180
BOOL LoadString(_In_ UINT nID)
Definition: cstringt.h:591
int MessageBox(LPCTSTR lpszText, LPCTSTR lpszCaption=NULL, UINT nType=MB_OK)
Definition: atlwin.h:996
#define MB_ICONEXCLAMATION
Definition: winuser.h:779
#define MB_OK
Definition: winuser.h:784
const CHAR * LPCTSTR
Definition: xmlstorage.h:193

Referenced by SaveDIBToFile().

◆ SkewDIB()

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

Definition at line 262 of file dib.cpp.

263{
264 if (nDegree == 0)
265 return CopyDIBImage(hbm);
266
267 const double eTan = tan(abs(nDegree) * M_PI / 180);
268
269 BITMAP bm;
270 GetObjectW(hbm, sizeof(bm), &bm);
271 INT cx = bm.bmWidth, cy = bm.bmHeight, dx = 0, dy = 0;
272 if (bVertical)
273 dy = INT(cx * eTan);
274 else
275 dx = INT(cy * eTan);
276
277 if (dx == 0 && dy == 0)
278 return CopyDIBImage(hbm);
279
280 HBITMAP hbmNew = CreateColorDIB(cx + dx, cy + dy, RGB(255, 255, 255));
281 if (!hbmNew)
282 return NULL;
283
285 HGDIOBJ hbm2Old = SelectObject(hDC2, hbmNew);
286 if (bVertical)
287 {
288 for (INT x = 0; x < cx; ++x)
289 {
290 INT delta = INT(x * eTan);
291 if (nDegree > 0)
292 BitBlt(hDC2, x, (dy - delta), 1, cy, hDC1, x, 0, SRCCOPY);
293 else
294 BitBlt(hDC2, x, delta, 1, cy, hDC1, x, 0, SRCCOPY);
295 }
296 }
297 else
298 {
299 for (INT y = 0; y < cy; ++y)
300 {
301 INT delta = INT(y * eTan);
302 if (nDegree > 0)
303 BitBlt(hDC2, (dx - delta), y, cx, 1, hDC1, 0, y, SRCCOPY);
304 else
305 BitBlt(hDC2, delta, y, cx, 1, hDC1, 0, y, SRCCOPY);
306 }
307 }
308 SelectObject(hDC2, hbm2Old);
309 DeleteDC(hDC2);
310 return hbmNew;
311}
_STLP_DECLSPEC complex< float > _STLP_CALL tan(const complex< float > &)
static HBITMAP CopyDIBImage(HBITMAP hbm, INT cx=0, INT cy=0)
Definition: dib.h:14
#define M_PI
Definition: dib.cpp:259
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
_In_ HBITMAP hbm
Definition: ntgdi.h:2776
#define INT
Definition: polytest.cpp:20
int WINAPI GetObjectW(_In_ HANDLE h, _In_ int c, _Out_writes_bytes_opt_(c) LPVOID pv)
#define SRCCOPY
Definition: wingdi.h:333

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

Variable Documentation

◆ fileSize

◆ fileTime

◆ g_xDpi

◆ g_yDpi