1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-07-07 08:45:59 +02:00

Theme update

This commit is contained in:
Brian Fiete 2020-10-05 14:25:55 -07:00
parent 9650e10e88
commit 1523000e80
16 changed files with 80 additions and 30 deletions

View file

@ -142,6 +142,31 @@ void ImageData::PremultiplyAlpha()
packedColor->g = (packedColor->g * packedColor->a) / 255;
packedColor->b = (packedColor->b * packedColor->a) / 255;
if (mIsAdditive)
packedColor->a = 0;
}
}
}
void ImageData::UnPremultiplyAlpha()
{
if (mBits == NULL)
return;
if (mAlphaPremultiplied)
{
mAlphaPremultiplied = false;
int size = mWidth * mHeight;
for (int i = 0; i < size; i++)
{
PackedColor* packedColor = (PackedColor*)(mBits + i);
if (packedColor->a != 0)
{
packedColor->r = BF_MIN((packedColor->r * 255) / packedColor->a, 255);
packedColor->g = BF_MIN((packedColor->g * 255) / packedColor->a, 255);
packedColor->b = BF_MIN((packedColor->b * 255) / packedColor->a, 255);
}
if (mIsAdditive)
packedColor->a = 0;
}

View file

@ -46,6 +46,7 @@ public:
virtual bool LoadFromFile(const StringImpl& path);
virtual bool ReadData() { return false; }
virtual void PremultiplyAlpha();
virtual void UnPremultiplyAlpha();
};
NS_BF_END;

View file

@ -1485,6 +1485,19 @@ ImageData* PSDReader::ReadImageData()
}
}
}
for (int i = 0; i < aSize; i++)
{
PackedColor& packedColor = *(PackedColor*)(&imageData->mBits[i]);
if (packedColor.a != 0)
{
packedColor.r = BF_CLAMP((packedColor.r - (0xFF - packedColor.a)) * 0xFF / packedColor.a, 0, 0xFF);
packedColor.g = BF_CLAMP((packedColor.g - (0xFF - packedColor.a)) * 0xFF / packedColor.a, 0, 0xFF);
packedColor.b = BF_CLAMP((packedColor.b - (0xFF - packedColor.a)) * 0xFF / packedColor.a, 0, 0xFF);
}
}
if (rowLengths != NULL)
{
for (int i = 0; i < mChannels; i++)