ReactOS  0.4.12-dev-43-g63b00d8
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)
 
int GetDIBWidth (HBITMAP hBitmap)
 
int GetDIBHeight (HBITMAP hBitmap)
 
void SaveDIBToFile (HBITMAP hBitmap, LPTSTR FileName, HDC hDC, LPSYSTEMTIME time, int *size, int hRes, int vRes)
 
void ShowFileLoadError (LPCTSTR name)
 
void LoadDIBFromFile (HBITMAP *hBitmap, LPCTSTR name, LPSYSTEMTIME time, int *size, int *hRes, int *vRes)
 

Function Documentation

◆ CreateDIBWithProperties()

HBITMAP CreateDIBWithProperties ( int  width,
int  height 
)

Definition at line 16 of file dib.cpp.

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

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:1453
struct tagBITMAPINFOHEADER BITMAPINFOHEADER
#define ZeroMemory
Definition: winbase.h:1635
DWORD biCompression
Definition: amvideo.idl:35
smooth NULL
Definition: ftsmooth.c:416
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 DIB_RGB_COLORS
Definition: wingdi.h:365
#define BI_RGB
Definition: precomp.h:35

◆ GetDIBHeight()

int GetDIBHeight ( HBITMAP  hBitmap)

Definition at line 38 of file dib.cpp.

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

39 {
40  BITMAP bm;
41  GetObject(hBitmap, sizeof(BITMAP), &bm);
42  return bm.bmHeight;
43 }
#define GetObject
Definition: wingdi.h:4445
Definition: bl.h:1331
static HBITMAP hBitmap
Definition: timezone.c:34

◆ GetDIBWidth()

int GetDIBWidth ( HBITMAP  hBitmap)

Definition at line 30 of file dib.cpp.

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

31 {
32  BITMAP bm;
33  GetObject(hBitmap, sizeof(BITMAP), &bm);
34  return bm.bmWidth;
35 }
#define GetObject
Definition: wingdi.h:4445
Definition: bl.h:1331
static HBITMAP hBitmap
Definition: timezone.c:34

◆ LoadDIBFromFile()

void LoadDIBFromFile ( HBITMAP hBitmap,
LPCTSTR  name,
LPSYSTEMTIME  time,
int size,
int hRes,
int vRes 
)

Definition at line 84 of file dib.cpp.

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

85 {
86  using namespace Gdiplus;
87  Bitmap img(CStringW(name), FALSE); // always use WCHAR string
88 
89  if (!hBitmap)
90  {
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  {
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 CloseHandle
Definition: compat.h:398
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
#define FILE_SHARE_READ
Definition: compat.h:125
struct Color Color
smooth NULL
Definition: ftsmooth.c:416
#define OPEN_EXISTING
Definition: compat.h:426
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 GENERIC_READ
Definition: compat.h:124
_In_ HANDLE hFile
Definition: mswsock.h:90
IN OUT PVCB OUT PDIRENT OUT PBCB IN BOOLEAN CreateFile
Definition: fatprocs.h:904
#define FILE_FLAG_SEQUENTIAL_SCAN
Definition: disk.h:43
void ShowFileLoadError(LPCTSTR name)
Definition: dib.cpp:74
Definition: name.c:36
CAtlStringW CStringW
Definition: atlstr.h:130
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
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:29

◆ SaveDIBToFile()

void SaveDIBToFile ( HBITMAP  hBitmap,
LPTSTR  FileName,
HDC  hDC,
LPSYSTEMTIME  time,
int size,
int  hRes,
int  vRes 
)

Definition at line 46 of file dib.cpp.

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

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 }
HBITMAP Detach()
Definition: atlimage.h:84
#define CloseHandle
Definition: compat.h:398
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
#define FILE_SHARE_READ
Definition: compat.h:125
smooth NULL
Definition: ftsmooth.c:416
#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 GENERIC_READ
Definition: compat.h:124
_In_ HANDLE hFile
Definition: mswsock.h:90
IN OUT PVCB OUT PDIRENT OUT PBCB IN BOOLEAN CreateFile
Definition: fatprocs.h:904
#define FILE_FLAG_SEQUENTIAL_SCAN
Definition: disk.h:43
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

◆ ShowFileLoadError()

void ShowFileLoadError ( LPCTSTR  name)

Definition at line 74 of file dib.cpp.

Referenced by LoadDIBFromFile().

75 {
76  CString strText;
78  CString strProgramName;
79  strProgramName.LoadString(IDS_PROGRAMNAME);
80  mainWindow.MessageBox(strText, strProgramName, MB_OK | MB_ICONEXCLAMATION);
81 }
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
#define IDS_PROGRAMNAME
Definition: definitions.h:203
void __cdecl Format(UINT nFormatID,...)
Definition: cstringt.h:668
#define MB_ICONEXCLAMATION
Definition: winuser.h:779
#define IDS_LOADERRORTEXT
Definition: definitions.h:238
#define MB_OK
Definition: winuser.h:784
Definition: name.c:36
BOOL LoadString(_In_ UINT nID)
Definition: cstringt.h:506
int MessageBox(LPCTSTR lpszText, LPCTSTR lpszCaption=NULL, UINT nType=MB_OK)
Definition: atlwin.h:925
CMainWindow mainWindow
Definition: main.cpp:62