mirror of
https://github.com/reactos/reactos.git
synced 2024-10-23 06:16:04 +00:00
3abdd259bb
This fixes the regression of mspaint not being able any longer to overwrite an existing file. The regression was once introduced by 0.4.7-dev-118-g44fc547ffa
when trying to determine the resolution on load. Our new fix does cover both issues and even reduces imports: win-win. fix cherry picked from commit 0.4.14-dev-691-gbe40a0e296
121 lines
2.9 KiB
C++
121 lines
2.9 KiB
C++
/*
|
|
* PROJECT: PAINT for ReactOS
|
|
* LICENSE: LGPL
|
|
* FILE: base/applications/mspaint/dib.cpp
|
|
* 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)
|
|
{
|
|
CImage img;
|
|
img.Attach(hBitmap);
|
|
img.Save(FileName); // TODO: error handling
|
|
img.Detach();
|
|
|
|
// update time and size
|
|
|
|
HANDLE hFile =
|
|
CreateFile(FileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
|
if (hFile == INVALID_HANDLE_VALUE)
|
|
return;
|
|
|
|
if (time)
|
|
{
|
|
FILETIME ft;
|
|
GetFileTime(hFile, NULL, NULL, &ft);
|
|
FileTimeToSystemTime(&ft, time);
|
|
}
|
|
if (size)
|
|
*size = GetFileSize(hFile, NULL);
|
|
|
|
// TODO: update hRes and vRes
|
|
|
|
CloseHandle(hFile);
|
|
}
|
|
|
|
void ShowFileLoadError(LPCTSTR name)
|
|
{
|
|
CString strText;
|
|
strText.Format(IDS_LOADERRORTEXT, (LPCTSTR) name);
|
|
CString strProgramName;
|
|
strProgramName.LoadString(IDS_PROGRAMNAME);
|
|
mainWindow.MessageBox(strText, strProgramName, MB_OK | MB_ICONEXCLAMATION);
|
|
}
|
|
|
|
void
|
|
LoadDIBFromFile(HBITMAP * hBitmap, LPCTSTR name, LPSYSTEMTIME time, int *size, int *hRes, int *vRes)
|
|
{
|
|
CImage img;
|
|
img.Load(name);
|
|
*hBitmap = img.Detach();
|
|
|
|
if (!hBitmap)
|
|
{
|
|
ShowFileLoadError(name);
|
|
return;
|
|
}
|
|
|
|
// update time and size
|
|
HANDLE hFile =
|
|
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);
|
|
|
|
HDC hScreenDC = GetDC(NULL);
|
|
*hRes = (int)(GetDeviceCaps(hScreenDC, LOGPIXELSX) * 1000 / 25.4);
|
|
*vRes = (int)(GetDeviceCaps(hScreenDC, LOGPIXELSY) * 1000 / 25.4);
|
|
ReleaseDC(NULL, hScreenDC);
|
|
|
|
CloseHandle(hFile);
|
|
}
|