ReactOS  0.4.12-dev-721-g03c3dd5
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.

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:1454
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:366
#define BI_RGB
Definition: precomp.h:35

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

◆ GetDIBHeight()

int GetDIBHeight ( HBITMAP  hBitmap)

Definition at line 38 of file dib.cpp.

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

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

◆ GetDIBWidth()

int GetDIBWidth ( HBITMAP  hBitmap)

Definition at line 30 of file dib.cpp.

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

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

◆ LoadDIBFromFile()

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

Definition at line 84 of file dib.cpp.

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 =
101  {
103  return;
104  }
105 
106  if (time)
107  {
108  FILETIME ft;
109  GetFileTime(hFile, NULL, NULL, &ft);
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 
120 }
#define CloseHandle
Definition: compat.h:398
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
__u16 time
Definition: mkdosfs.c:366
#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

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

◆ 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.

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 =
58  return;
59 
60  if (time)
61  {
62  FILETIME ft;
63  GetFileTime(hFile, NULL, NULL, &ft);
65  }
66  if (size)
68 
69  // TODO: update hRes and vRes
70 
72 }
#define CloseHandle
Definition: compat.h:398
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
__u16 time
Definition: mkdosfs.c:366
#define FILE_SHARE_READ
Definition: compat.h:125
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
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

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

◆ ShowFileLoadError()

void ShowFileLoadError ( LPCTSTR  name)

Definition at line 74 of file dib.cpp.

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:934
CMainWindow mainWindow
Definition: main.cpp:62

Referenced by LoadDIBFromFile().