ReactOS  0.4.15-dev-1389-g828d5fa
dib.cpp File Reference
#include "precomp.h"
Include dependency graph for dib.cpp:

Go to the source code of this file.

Functions

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)
 

Function Documentation

◆ CreateColorDIB()

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

Definition at line 30 of file dib.cpp.

31 {
33  if (!ret)
34  return NULL;
35 
36  if (rgb)
37  {
39  HGDIOBJ hbmOld = SelectObject(hdc, ret);
40  RECT rc;
41  SetRect(&rc, 0, 0, width, height);
42  HBRUSH hbr = CreateSolidBrush(rgb);
43  FillRect(hdc, &rc, hbr);
44  DeleteObject(hbr);
45  SelectObject(hdc, hbmOld);
46  DeleteDC(hdc);
47  }
48 
49  return ret;
50 }
GLint GLint GLsizei width
Definition: gl.h:1546
static HDC
Definition: imagelist.c:92
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1499
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
HBITMAP CreateDIBWithProperties(int width, int height)
Definition: dib.cpp:16
int ret
HDC hdc
Definition: main.c:9
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
BOOL WINAPI SetRect(_Out_ LPRECT, _In_ int, _In_ int, _In_ int, _In_ int)
_In_ ULONG _In_ ULONG rgb
Definition: winddi.h:3520
BOOL WINAPI DeleteDC(_In_ HDC)
#define NULL
Definition: types.h:112
HBRUSH WINAPI CreateSolidBrush(_In_ COLORREF)
static HBITMAP
Definition: button.c:44
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)

Referenced by SetBitmapAndInfo().

◆ CreateDIBWithProperties()

HBITMAP CreateDIBWithProperties ( int  width,
int  height 
)

Definition at line 16 of file dib.cpp.

17 {
18  BITMAPINFO bmi;
19  ZeroMemory(&bmi, sizeof(BITMAPINFO));
20  bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
21  bmi.bmiHeader.biWidth = width;
23  bmi.bmiHeader.biPlanes = 1;
24  bmi.bmiHeader.biBitCount = 24;
26  return CreateDIBSection(NULL, &bmi, DIB_RGB_COLORS, NULL, NULL, 0);
27 }
GLint GLint GLsizei width
Definition: gl.h:1546
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1475
struct tagBITMAPINFOHEADER BITMAPINFOHEADER
#define ZeroMemory
Definition: winbase.h:1648
DWORD biCompression
Definition: amvideo.idl:35
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
HBITMAP WINAPI CreateDIBSection(HDC hDC, CONST BITMAPINFO *BitmapInfo, UINT Usage, VOID **Bits, HANDLE hSection, DWORD dwOffset)
Definition: bitmap.c:197
#define NULL
Definition: types.h:112
#define DIB_RGB_COLORS
Definition: wingdi.h:366
#define BI_RGB
Definition: precomp.h:47

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

◆ DoLoadImageFile()

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

Definition at line 159 of file dib.cpp.

160 {
161  // find the file
163  HANDLE hFind = FindFirstFile(name, &find);
164  if (hFind == INVALID_HANDLE_VALUE)
165  {
166  // does not exist
167  CStringW strText;
168  strText.Format(IDS_LOADERRORTEXT, name);
169  MessageBoxW(hwnd, strText, NULL, MB_ICONERROR);
170  return NULL;
171  }
172  DWORD dwFileSize = find.nFileSizeLow; // get file size
173  FindClose(hFind);
174 
175  // is file empty?
176  if (dwFileSize == 0)
177  {
178  if (fIsMainFile)
179  {
180  FILETIME ft;
181  FileTimeToLocalFileTime(&find.ftLastWriteTime, &ft);
184  }
185  }
186 
187  // load the image
188  CImage img;
189  img.Load(name);
190  HBITMAP hBitmap = img.Detach();
191 
192  if (hBitmap == NULL)
193  {
194  // cannot open
195  CStringW strText;
196  strText.Format(IDS_LOADERRORTEXT, name);
197  MessageBoxW(hwnd, strText, NULL, MB_ICONERROR);
198  return NULL;
199  }
200 
201  if (fIsMainFile)
202  {
203  FILETIME ft;
204  FileTimeToLocalFileTime(&find.ftLastWriteTime, &ft);
207  }
208 
209  return hBitmap;
210 }
HBITMAP SetBitmapAndInfo(HBITMAP hBitmap, LPCTSTR name, DWORD dwFileSize, BOOL isFile)
Definition: dib.cpp:108
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define TRUE
Definition: types.h:120
DWORD dwFileSize
Definition: more.c:37
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
void __cdecl Format(UINT nFormatID,...)
Definition: cstringt.h:716
BOOL WINAPI FileTimeToLocalFileTime(IN CONST FILETIME *lpFileTime, OUT LPFILETIME lpLocalFileTime)
Definition: time.c:221
SYSTEMTIME fileTime
Definition: main.cpp:58
#define IDS_LOADERRORTEXT
Definition: definitions.h:238
#define FindFirstFile
Definition: winbase.h:3622
BOOL WINAPI FileTimeToSystemTime(IN CONST FILETIME *lpFileTime, OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:188
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
GLint GLvoid * img
Definition: gl.h:1956
unsigned long DWORD
Definition: ntddk_ex.h:95
#define MB_ICONERROR
Definition: winuser.h:781
#define NULL
Definition: types.h:112
static TAGID TAGID find
Definition: db.cpp:153
Definition: name.c:38
static HBITMAP
Definition: button.c:44
static HBITMAP hBitmap
Definition: timezone.c:26
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502

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

◆ GetDIBHeight()

int GetDIBHeight ( HBITMAP  hBitmap)

Definition at line 61 of file dib.cpp.

62 {
63  BITMAP bm;
64  GetObject(hBitmap, sizeof(BITMAP), &bm);
65  return bm.bmHeight;
66 }
#define GetObject
Definition: wingdi.h:4467
Definition: bl.h:1331
static HBITMAP hBitmap
Definition: timezone.c:26

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

◆ GetDIBWidth()

int GetDIBWidth ( HBITMAP  hBitmap)

Definition at line 53 of file dib.cpp.

54 {
55  BITMAP bm;
56  GetObject(hBitmap, sizeof(BITMAP), &bm);
57  return bm.bmWidth;
58 }
#define GetObject
Definition: wingdi.h:4467
Definition: bl.h:1331
static HBITMAP hBitmap
Definition: timezone.c:26

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

◆ SaveDIBToFile()

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

Definition at line 68 of file dib.cpp.

69 {
70  CImage img;
71  img.Attach(hBitmap);
72  img.Save(FileName); // TODO: error handling
73  img.Detach();
74 
76  HANDLE hFind = FindFirstFile(FileName, &find);
77  if (hFind == INVALID_HANDLE_VALUE)
78  {
80  return FALSE;
81  }
82  FindClose(hFind);
83 
84  // update time and size
85  FILETIME ft;
86  FileTimeToLocalFileTime(&find.ftLastWriteTime, &ft);
88  fileSize = find.nFileSizeLow;
89 
90  // TODO: update hRes and vRes
91 
93 
94  isAFile = TRUE;
95  imageSaved = TRUE;
96  return TRUE;
97 }
BOOL isAFile
Definition: main.cpp:53
int fileSize
Definition: main.cpp:55
#define TRUE
Definition: types.h:120
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
BOOL WINAPI FileTimeToLocalFileTime(IN CONST FILETIME *lpFileTime, OUT LPFILETIME lpLocalFileTime)
Definition: time.c:221
void SetMostRecentFile(LPCTSTR szPathName)
Definition: registry.cpp:146
SYSTEMTIME fileTime
Definition: main.cpp:58
#define FALSE
Definition: types.h:117
#define FindFirstFile
Definition: winbase.h:3622
BOOL WINAPI FileTimeToSystemTime(IN CONST FILETIME *lpFileTime, OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:188
GLint GLvoid * img
Definition: gl.h:1956
BOOL imageSaved
Definition: main.cpp:54
void ShowFileLoadError(LPCTSTR name)
Definition: dib.cpp:99
static TAGID TAGID find
Definition: db.cpp:153
RegistrySettings registrySettings
Definition: main.cpp:30
static HBITMAP hBitmap
Definition: timezone.c:26
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502

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

◆ SetBitmapAndInfo()

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

Definition at line 108 of file dib.cpp.

109 {
110  if (hBitmap == NULL)
111  {
112  COLORREF white = RGB(255, 255, 255);
114  registrySettings.BMPHeight, white);
115  if (hBitmap == NULL)
116  return FALSE;
117 
118  fileHPPM = fileVPPM = 2834;
119  ZeroMemory(&fileTime, sizeof(fileTime));
120  isFile = FALSE;
121  }
122  else
123  {
124  // update PPMs
125  HDC hScreenDC = GetDC(NULL);
126  fileHPPM = (int)(GetDeviceCaps(hScreenDC, LOGPIXELSX) * 1000 / 25.4);
127  fileVPPM = (int)(GetDeviceCaps(hScreenDC, LOGPIXELSY) * 1000 / 25.4);
128  ReleaseDC(NULL, hScreenDC);
129  }
130 
131  // update image
134 
135  // update fileSize
137 
138  // update filepathname
139  if (name && name[0])
141  else
143 
144  // set title
145  CString strTitle;
147  mainWindow.SetWindowText(strTitle);
148 
149  // update file info and recent
150  isAFile = isFile;
151  if (isAFile)
153 
154  imageSaved = TRUE;
155 
156  return hBitmap;
157 }
BOOL isAFile
Definition: main.cpp:53
#define LOGPIXELSX
Definition: wingdi.h:717
int fileSize
Definition: main.cpp:55
#define RGB(r, g, b)
Definition: precomp.h:62
HDC WINAPI GetDC(_In_opt_ HWND)
#define TRUE
Definition: types.h:120
DWORD dwFileSize
Definition: more.c:37
static HDC
Definition: imagelist.c:92
#define ZeroMemory
Definition: winbase.h:1648
void __cdecl Format(UINT nFormatID,...)
Definition: cstringt.h:716
BOOL SetWindowText(LPCTSTR lpszString)
Definition: atlwin.h:1232
DWORD BMPHeight
Definition: registry.h:17
void SetMostRecentFile(LPCTSTR szPathName)
Definition: registry.cpp:146
SYSTEMTIME fileTime
Definition: main.cpp:58
#define SIZEOF(_ar)
Definition: calc.h:97
#define FALSE
Definition: types.h:117
void ClearHistory(void)
Definition: history.cpp:102
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
int fileHPPM
Definition: main.cpp:56
void Insert(HBITMAP hbm)
Definition: history.cpp:108
DWORD BMPWidth
Definition: registry.h:18
HBITMAP CreateColorDIB(int width, int height, COLORREF rgb)
Definition: dib.cpp:30
DWORD COLORREF
Definition: windef.h:300
#define PathFindFileName
Definition: shlwapi.h:911
TCHAR filepathname[1000]
Definition: main.cpp:52
BOOL imageSaved
Definition: main.cpp:54
int WINAPI GetDeviceCaps(_In_opt_ HDC, _In_ int)
ImageModel imageModel
Definition: main.cpp:32
#define GetFullPathName
Definition: winbase.h:3661
HINSTANCE hProgInstance
Definition: main.cpp:50
#define NULL
Definition: types.h:112
Definition: name.c:38
#define LOGPIXELSY
Definition: wingdi.h:718
RegistrySettings registrySettings
Definition: main.cpp:30
#define IDS_WINDOWTITLE
Definition: definitions.h:204
static HBITMAP hBitmap
Definition: timezone.c:26
#define LoadString
Definition: winuser.h:5794
int fileVPPM
Definition: main.cpp:57
#define IDS_DEFAULTFILENAME
Definition: definitions.h:209
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
CMainWindow mainWindow
Definition: main.cpp:63

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

◆ ShowFileLoadError()

void ShowFileLoadError ( LPCTSTR  name)

Definition at line 99 of file dib.cpp.

100 {
101  CString strText;
102  strText.Format(IDS_LOADERRORTEXT, (LPCTSTR) name);
103  CString strProgramName;
104  strProgramName.LoadString(IDS_PROGRAMNAME);
105  mainWindow.MessageBox(strText, strProgramName, MB_OK | MB_ICONEXCLAMATION);
106 }
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
#define IDS_PROGRAMNAME
Definition: definitions.h:203
void __cdecl Format(UINT nFormatID,...)
Definition: cstringt.h:716
#define MB_ICONEXCLAMATION
Definition: winuser.h:779
#define IDS_LOADERRORTEXT
Definition: definitions.h:238
#define MB_OK
Definition: winuser.h:784
Definition: name.c:38
BOOL LoadString(_In_ UINT nID)
Definition: cstringt.h:554
int MessageBox(LPCTSTR lpszText, LPCTSTR lpszCaption=NULL, UINT nType=MB_OK)
Definition: atlwin.h:934
CMainWindow mainWindow
Definition: main.cpp:63

Referenced by SaveDIBToFile().