2015-05-08 16:02:36 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: PAINT for ReactOS
|
|
|
|
* LICENSE: LGPL
|
2015-09-09 13:13:35 +00:00
|
|
|
* FILE: base/applications/mspaint/dib.cpp
|
2015-05-08 16:02:36 +00:00
|
|
|
* PURPOSE: Some DIB related functions
|
|
|
|
* PROGRAMMERS: Benedikt Freisen
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *********************************************************/
|
|
|
|
|
|
|
|
#include "precomp.h"
|
|
|
|
|
|
|
|
/* FUNCTIONS ********************************************************/
|
|
|
|
|
|
|
|
HBITMAP
|
|
|
|
CreateDIBWithProperties(int width, int height)
|
|
|
|
{
|
|
|
|
BITMAPINFO bmi;
|
|
|
|
ZeroMemory(&bmi, sizeof(BITMAPINFO));
|
|
|
|
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
|
|
|
bmi.bmiHeader.biWidth = width;
|
|
|
|
bmi.bmiHeader.biHeight = height;
|
|
|
|
bmi.bmiHeader.biPlanes = 1;
|
|
|
|
bmi.bmiHeader.biBitCount = 24;
|
|
|
|
bmi.bmiHeader.biCompression = BI_RGB;
|
|
|
|
return CreateDIBSection(NULL, &bmi, DIB_RGB_COLORS, NULL, NULL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
GetDIBWidth(HBITMAP hBitmap)
|
|
|
|
{
|
|
|
|
BITMAP bm;
|
|
|
|
GetObject(hBitmap, sizeof(BITMAP), &bm);
|
|
|
|
return bm.bmWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
GetDIBHeight(HBITMAP hBitmap)
|
|
|
|
{
|
|
|
|
BITMAP bm;
|
|
|
|
GetObject(hBitmap, sizeof(BITMAP), &bm);
|
|
|
|
return bm.bmHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SaveDIBToFile(HBITMAP hBitmap, LPTSTR FileName, HDC hDC, LPSYSTEMTIME time, int *size, int hRes, int vRes)
|
|
|
|
{
|
2016-09-26 19:53:42 +00:00
|
|
|
CImage img;
|
|
|
|
img.Attach(hBitmap);
|
|
|
|
img.Save(FileName); // TODO: error handling
|
|
|
|
img.Detach();
|
2015-05-08 16:02:36 +00:00
|
|
|
|
2016-09-26 19:53:42 +00:00
|
|
|
// update time and size
|
2015-05-08 16:02:36 +00:00
|
|
|
|
2016-09-26 19:53:42 +00:00
|
|
|
HANDLE hFile =
|
|
|
|
CreateFile(FileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
2015-05-08 16:02:36 +00:00
|
|
|
if (hFile == INVALID_HANDLE_VALUE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (time)
|
|
|
|
{
|
|
|
|
FILETIME ft;
|
|
|
|
GetFileTime(hFile, NULL, NULL, &ft);
|
|
|
|
FileTimeToSystemTime(&ft, time);
|
|
|
|
}
|
|
|
|
if (size)
|
|
|
|
*size = GetFileSize(hFile, NULL);
|
|
|
|
|
2016-09-26 19:53:42 +00:00
|
|
|
// TODO: update hRes and vRes
|
|
|
|
|
2015-05-08 16:02:36 +00:00
|
|
|
CloseHandle(hFile);
|
|
|
|
}
|
|
|
|
|
2016-09-26 19:53:42 +00:00
|
|
|
void ShowFileLoadError(LPCTSTR name)
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2016-10-09 11:42:37 +00:00
|
|
|
CString strText;
|
|
|
|
strText.Format(IDS_LOADERRORTEXT, (LPCTSTR) name);
|
|
|
|
CString strProgramName;
|
|
|
|
strProgramName.LoadString(IDS_PROGRAMNAME);
|
|
|
|
mainWindow.MessageBox(strText, strProgramName, MB_OK | MB_ICONEXCLAMATION);
|
2015-05-08 16:02:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-09-26 19:53:42 +00:00
|
|
|
LoadDIBFromFile(HBITMAP * hBitmap, LPCTSTR name, LPSYSTEMTIME time, int *size, int *hRes, int *vRes)
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2019-12-28 13:30:21 +00:00
|
|
|
CImage img;
|
|
|
|
img.Load(name);
|
|
|
|
*hBitmap = img.Detach();
|
2015-05-08 16:02:36 +00:00
|
|
|
|
|
|
|
if (!hBitmap)
|
|
|
|
{
|
|
|
|
ShowFileLoadError(name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-26 19:53:42 +00:00
|
|
|
// update time and size
|
|
|
|
HANDLE hFile =
|
2015-05-08 16:02:36 +00:00
|
|
|
CreateFile(name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
|
|
|
if (hFile == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
ShowFileLoadError(name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (time)
|
|
|
|
{
|
|
|
|
FILETIME ft;
|
|
|
|
GetFileTime(hFile, NULL, NULL, &ft);
|
|
|
|
FileTimeToSystemTime(&ft, time);
|
|
|
|
}
|
|
|
|
if (size)
|
|
|
|
*size = GetFileSize(hFile, NULL);
|
|
|
|
|
2019-12-28 13:30:21 +00:00
|
|
|
HDC hScreenDC = GetDC(NULL);
|
|
|
|
*hRes = (int)(GetDeviceCaps(hScreenDC, LOGPIXELSX) * 1000 / 25.4);
|
|
|
|
*vRes = (int)(GetDeviceCaps(hScreenDC, LOGPIXELSY) * 1000 / 25.4);
|
|
|
|
ReleaseDC(NULL, hScreenDC);
|
2015-05-08 16:02:36 +00:00
|
|
|
|
|
|
|
CloseHandle(hFile);
|
|
|
|
}
|