2017-07-02 20:55:56 +01:00
|
|
|
#include "StdAfx.h"
|
|
|
|
|
2017-07-03 21:00:42 +01:00
|
|
|
#include <QFile>
|
2019-11-20 21:23:27 +00:00
|
|
|
#include <QImage>
|
2017-07-02 20:55:56 +01:00
|
|
|
|
|
|
|
#include "Log.h"
|
|
|
|
|
|
|
|
HRSRC FindResource(void *, const std::string & filename, const char *)
|
|
|
|
{
|
|
|
|
HRSRC result;
|
|
|
|
|
|
|
|
if (!filename.empty())
|
|
|
|
{
|
|
|
|
const std::string path = ":/resources/" + filename;
|
|
|
|
|
|
|
|
QFile res(QString::fromStdString(path));
|
|
|
|
if (res.exists() && res.open(QIODevice::ReadOnly))
|
|
|
|
{
|
|
|
|
QByteArray data = res.readAll();
|
|
|
|
result.data.assign(data.begin(), data.end());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result.data.empty())
|
|
|
|
{
|
|
|
|
LogFileOutput("FindResource: could not load resource %s\n", filename.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2019-11-20 21:23:27 +00:00
|
|
|
|
2019-11-23 18:17:44 +00:00
|
|
|
struct CBITMAP : public CHANDLE
|
|
|
|
{
|
|
|
|
QImage image;
|
|
|
|
};
|
|
|
|
|
2019-11-20 21:23:27 +00:00
|
|
|
HBITMAP LoadBitmap(HINSTANCE hInstance, const std::string & filename)
|
|
|
|
{
|
2019-11-24 19:30:58 +00:00
|
|
|
Q_UNUSED(hInstance)
|
|
|
|
|
2019-11-23 18:17:44 +00:00
|
|
|
QImage image;
|
2019-11-20 21:23:27 +00:00
|
|
|
if (!filename.empty())
|
|
|
|
{
|
|
|
|
const std::string path = ":/resources/" + filename + ".BMP";
|
2019-11-23 18:17:44 +00:00
|
|
|
image = QImage(QString::fromStdString(path));
|
2019-11-20 21:23:27 +00:00
|
|
|
}
|
|
|
|
|
2019-11-23 18:17:44 +00:00
|
|
|
if (image.isNull())
|
2019-11-20 21:23:27 +00:00
|
|
|
{
|
|
|
|
LogFileOutput("LoadBitmap: could not load resource %s\n", filename.c_str());
|
2019-11-23 18:17:44 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CBITMAP * bitmap = new CBITMAP;
|
|
|
|
bitmap->image = image;
|
|
|
|
return bitmap;
|
2019-11-20 21:23:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG GetBitmapBits(HBITMAP hbit, LONG cb, LPVOID lpvBits)
|
|
|
|
{
|
2019-11-23 18:17:44 +00:00
|
|
|
const CBITMAP & bitmap = dynamic_cast<CBITMAP&>(*hbit);
|
|
|
|
const uchar * bits = bitmap.image.bits();
|
|
|
|
const qsizetype size = bitmap.image.sizeInBytes();
|
2019-11-20 21:23:27 +00:00
|
|
|
const qsizetype requested = cb;
|
|
|
|
|
|
|
|
const qsizetype copied = std::min(requested, size);
|
|
|
|
|
|
|
|
uchar * dest = static_cast<uchar *>(lpvBits);
|
|
|
|
for (qsizetype i = 0; i < copied; ++i)
|
|
|
|
{
|
|
|
|
dest[i] = ~bits[i];
|
|
|
|
}
|
|
|
|
return copied;
|
|
|
|
}
|