ReactOS  0.4.12-dev-102-g4b7f1e0
dib.cpp
Go to the documentation of this file.
1 /*
2  * PROJECT: PAINT for ReactOS
3  * LICENSE: LGPL
4  * FILE: base/applications/mspaint/dib.cpp
5  * PURPOSE: Some DIB related functions
6  * PROGRAMMERS: Benedikt Freisen
7  */
8 
9 /* INCLUDES *********************************************************/
10 
11 #include "precomp.h"
12 
13 /* FUNCTIONS ********************************************************/
14 
15 HBITMAP
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 }
28 
29 int
31 {
32  BITMAP bm;
33  GetObject(hBitmap, sizeof(BITMAP), &bm);
34  return bm.bmWidth;
35 }
36 
37 int
39 {
40  BITMAP bm;
41  GetObject(hBitmap, sizeof(BITMAP), &bm);
42  return bm.bmHeight;
43 }
44 
45 void
47 {
48  CImage img;
49  img.Attach(hBitmap);
50  img.Save(FileName); // TODO: error handling
51  img.Detach();
52 
53  // update time and size
54 
55  HANDLE hFile =
57  if (hFile == INVALID_HANDLE_VALUE)
58  return;
59 
60  if (time)
61  {
62  FILETIME ft;
63  GetFileTime(hFile, NULL, NULL, &ft);
64  FileTimeToSystemTime(&ft, time);
65  }
66  if (size)
67  *size = GetFileSize(hFile, NULL);
68 
69  // TODO: update hRes and vRes
70 
71  CloseHandle(hFile);
72 }
73 
75 {
76  CString strText;
77  strText.Format(IDS_LOADERRORTEXT, (LPCTSTR) name);
78  CString strProgramName;
79  strProgramName.LoadString(IDS_PROGRAMNAME);
80  mainWindow.MessageBox(strText, strProgramName, MB_OK | MB_ICONEXCLAMATION);
81 }
82 
83 void
84 LoadDIBFromFile(HBITMAP * hBitmap, LPCTSTR name, LPSYSTEMTIME time, int *size, int *hRes, int *vRes)
85 {
86  using namespace Gdiplus;
87  Bitmap img(CStringW(name), FALSE); // always use WCHAR string
88 
89  if (!hBitmap)
90  {
91  ShowFileLoadError(name);
92  return;
93  }
94 
95  img.GetHBITMAP(Color(255, 255, 255), hBitmap);
96 
97  // update time and size
98  HANDLE hFile =
100  if (hFile == INVALID_HANDLE_VALUE)
101  {
102  ShowFileLoadError(name);
103  return;
104  }
105 
106  if (time)
107  {
108  FILETIME ft;
109  GetFileTime(hFile, NULL, NULL, &ft);
110  FileTimeToSystemTime(&ft, time);
111  }
112  if (size)
113  *size = GetFileSize(hFile, NULL);
114 
115  // update hRes and vRes
116  *hRes = (int) (img.GetHorizontalResolution() * 1000 / 25.4);
117  *vRes = (int) (img.GetVerticalResolution() * 1000 / 25.4);
118 
119  CloseHandle(hFile);
120 }
#define HDC
Definition: msvc.h:22
GLint GLint GLsizei width
Definition: gl.h:1546
HBITMAP Detach()
Definition: atlimage.h:84
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
#define CloseHandle
Definition: compat.h:398
#define HBITMAP
Definition: msvc.h:28
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1453
void SaveDIBToFile(HBITMAP hBitmap, LPTSTR FileName, HDC hDC, LPSYSTEMTIME time, int *size, int hRes, int vRes)
Definition: dib.cpp:46
struct tagBITMAPINFOHEADER BITMAPINFOHEADER
#define IDS_PROGRAMNAME
Definition: definitions.h:203
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
#define ZeroMemory
Definition: winbase.h:1635
void __cdecl Format(UINT nFormatID,...)
Definition: cstringt.h:668
int GetDIBHeight(HBITMAP hBitmap)
Definition: dib.cpp:38
__u16 time
Definition: mkdosfs.c:366
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define FILE_SHARE_READ
Definition: compat.h:125
struct Color Color
#define MB_ICONEXCLAMATION
Definition: winuser.h:779
void LoadDIBFromFile(HBITMAP *hBitmap, LPCTSTR name, LPSYSTEMTIME time, int *size, int *hRes, int *vRes)
Definition: dib.cpp:84
int GetDIBWidth(HBITMAP hBitmap)
Definition: dib.cpp:30
REAL GetHorizontalResolution(VOID)
#define IDS_LOADERRORTEXT
Definition: definitions.h:238
DWORD biCompression
Definition: amvideo.idl:35
smooth NULL
Definition: ftsmooth.c:416
HBITMAP CreateDIBWithProperties(int width, int height)
Definition: dib.cpp:16
#define OPEN_EXISTING
Definition: compat.h:426
HRESULT Save(IStream *pStream, GUID *guidFileType) const
Definition: atlimage.h:526
BOOL WINAPI FileTimeToSystemTime(IN CONST FILETIME *lpFileTime, OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:178
GLsizeiptr size
Definition: glext.h:5919
GLint GLvoid * img
Definition: gl.h:1956
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:481
#define GetObject
Definition: wingdi.h:4445
REAL GetVerticalResolution(VOID)
#define GENERIC_READ
Definition: compat.h:124
_In_ HANDLE hFile
Definition: mswsock.h:90
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
static HDC hDC
Definition: 3dtext.c:33
IN OUT PVCB OUT PDIRENT OUT PBCB IN BOOLEAN CreateFile
Definition: fatprocs.h:904
#define FILE_FLAG_SEQUENTIAL_SCAN
Definition: disk.h:43
HBITMAP WINAPI CreateDIBSection(HDC hDC, CONST BITMAPINFO *BitmapInfo, UINT Usage, VOID **Bits, HANDLE hSection, DWORD dwOffset)
Definition: bitmap.c:197
Definition: bl.h:1331
#define MB_OK
Definition: winuser.h:784
void ShowFileLoadError(LPCTSTR name)
Definition: dib.cpp:74
Definition: name.c:36
Status GetHBITMAP(const Color &colorBackground, HBITMAP *hbmReturn)
BOOL LoadString(_In_ UINT nID)
Definition: cstringt.h:506
CAtlStringW CStringW
Definition: atlstr.h:130
#define DIB_RGB_COLORS
Definition: wingdi.h:365
int MessageBox(LPCTSTR lpszText, LPCTSTR lpszCaption=NULL, UINT nType=MB_OK)
Definition: atlwin.h:925
#define BI_RGB
Definition: precomp.h:35
static HBITMAP hBitmap
Definition: timezone.c:34
BOOL WINAPI GetFileTime(IN HANDLE hFile, OUT LPFILETIME lpCreationTime OPTIONAL, OUT LPFILETIME lpLastAccessTime OPTIONAL, OUT LPFILETIME lpLastWriteTime OPTIONAL)
Definition: fileinfo.c:1046
void Attach(HBITMAP hBitmap, DIBOrientation eOrientation=DIBOR_DEFAULT)
Definition: atlimage.h:79
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:29
CMainWindow mainWindow
Definition: main.cpp:62