added missing properties
This commit is contained in:
1 parent
63ff80cac9
commit
ef2e1b4680
4 files changed
+189
-1
No files matched your search
@@ -31,7 +31,10 @@
|
||||
#include "Cevo/CevoTexture.h"
|
||||
#include "Dpi/DpiPixelPointer.h"
|
||||
|
||||
#include <QFileInfo>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace Cevo {
|
||||
@@ -48,6 +51,119 @@ QColor colorFromDelphi(int value)
|
||||
return QColor(value & 0xFF, (value >> 8) & 0xFF, (value >> 16) & 0xFF);
|
||||
}
|
||||
|
||||
int gamma = 100;
|
||||
GraphicSets grExt;
|
||||
QString graphicsDir;
|
||||
|
||||
namespace {
|
||||
|
||||
std::array<std::uint8_t, 256> gammaLookupTable;
|
||||
|
||||
void initGammaLookupTable()
|
||||
{
|
||||
gammaLookupTable[0] = 0;
|
||||
for (int i = 1; i <= 255; ++i) {
|
||||
const double p = std::round(255.0 * std::exp(std::log(i / 255.0) * 100.0 / gamma));
|
||||
Q_ASSERT(p >= 0 && p < 256);
|
||||
gammaLookupTable[static_cast<std::size_t>(i)] = static_cast<std::uint8_t>(p);
|
||||
}
|
||||
}
|
||||
|
||||
int hexCharToInt(QChar c)
|
||||
{
|
||||
if (c >= QLatin1Char('0') && c <= QLatin1Char('9'))
|
||||
return c.toLatin1() - '0';
|
||||
if (c >= QLatin1Char('A') && c <= QLatin1Char('F'))
|
||||
return c.toLatin1() - 'A' + 10;
|
||||
if (c >= QLatin1Char('a') && c <= QLatin1Char('f'))
|
||||
return c.toLatin1() - 'a' + 10;
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void applyGammaToBitmap(Dpi::Bitmap &bitmap)
|
||||
{
|
||||
if (gamma == 100)
|
||||
return;
|
||||
initGammaLookupTable();
|
||||
Dpi::PixelPointer pixel(&bitmap.image(), 0, 0);
|
||||
for (int y = 0; y < bitmap.height(); ++y) {
|
||||
for (int x = 0; x < bitmap.width(); ++x) {
|
||||
const QRgb c = pixel.pixelARGB();
|
||||
pixel.setPixelARGB(qRgb(gammaLookupTable[static_cast<std::size_t>(qRed(c))],
|
||||
gammaLookupTable[static_cast<std::size_t>(qGreen(c))],
|
||||
gammaLookupTable[static_cast<std::size_t>(qBlue(c))]));
|
||||
pixel.nextPixel();
|
||||
}
|
||||
pixel.nextLine();
|
||||
}
|
||||
}
|
||||
|
||||
QColor hexStringToColor(const QString &text)
|
||||
{
|
||||
QString s = text;
|
||||
while (!s.isEmpty() && s.at(0) == QLatin1Char(' '))
|
||||
s.remove(0, 1);
|
||||
s += QStringLiteral("000000");
|
||||
if (gamma == 100) {
|
||||
return QColor(0x10 * hexCharToInt(s.at(0)) + hexCharToInt(s.at(1)),
|
||||
0x10 * hexCharToInt(s.at(2)) + hexCharToInt(s.at(3)),
|
||||
0x10 * hexCharToInt(s.at(4)) + hexCharToInt(s.at(5)));
|
||||
}
|
||||
initGammaLookupTable();
|
||||
return QColor(gammaLookupTable[static_cast<std::size_t>(0x10 * hexCharToInt(s.at(0)) + hexCharToInt(s.at(1)))],
|
||||
gammaLookupTable[static_cast<std::size_t>(0x10 * hexCharToInt(s.at(2)) + hexCharToInt(s.at(3)))],
|
||||
gammaLookupTable[static_cast<std::size_t>(0x10 * hexCharToInt(s.at(4)) + hexCharToInt(s.at(5)))]);
|
||||
}
|
||||
|
||||
GraphicSet *loadGraphicSet(const QString &name, bool transparency)
|
||||
{
|
||||
GraphicSet *result = grExt.searchByName(name);
|
||||
if (result)
|
||||
return result;
|
||||
result = &grExt.addNew(name);
|
||||
|
||||
const QString fileName = graphicsDir + QLatin1Char('/') + name;
|
||||
// Do not apply gamma during file load as it would affect transparency colors too.
|
||||
result->data.loadFromFile(fileName);
|
||||
if (result->data.width() == 0 || result->data.height() == 0)
|
||||
return nullptr;
|
||||
|
||||
const QString grsFileName = QFileInfo(fileName).path() + QLatin1Char('/') +
|
||||
QFileInfo(fileName).completeBaseName() + QLatin1String(GraphicSetFileExt);
|
||||
if (QFileInfo::exists(grsFileName))
|
||||
result->loadFromFile(grsFileName);
|
||||
|
||||
result->resetPixUsed();
|
||||
|
||||
if (transparency) {
|
||||
constexpr QRgb TransparentColor1 = 0xFF00FF;
|
||||
constexpr QRgb TransparentColor2 = 0x7F007F;
|
||||
result->mask.setSize(result->data.width(), result->data.height());
|
||||
Dpi::PixelPointer dataPixel(&result->data.image(), 0, 0);
|
||||
Dpi::PixelPointer maskPixel(&result->mask.image(), 0, 0);
|
||||
for (int y = 0; y < result->data.height(); ++y) {
|
||||
for (int x = 0; x < result->data.width(); ++x) {
|
||||
const QRgb originalColor = dataPixel.pixelARGB() & 0xFFFFFFu;
|
||||
if (originalColor == TransparentColor1 || originalColor == TransparentColor2) {
|
||||
maskPixel.setPixelRGB(qRgb(0xFF, 0xFF, 0xFF));
|
||||
dataPixel.setPixelRGB(0);
|
||||
} else {
|
||||
maskPixel.setPixelRGB(0);
|
||||
}
|
||||
dataPixel.nextPixel();
|
||||
maskPixel.nextPixel();
|
||||
}
|
||||
dataPixel.nextLine();
|
||||
maskPixel.nextLine();
|
||||
}
|
||||
if (gamma != 100)
|
||||
applyGammaToBitmap(result->data);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void bitBltBitmap(Dpi::Bitmap &dest, int x, int y, int width, int height,
|
||||
Dpi::Bitmap &src, int xSrc, int ySrc, RasterOp rop)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user