-
-
Notifications
You must be signed in to change notification settings - Fork 438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert SVG bitmap to BGRA unpremultiplied #3829
base: master
Are you sure you want to change the base?
Conversation
static enum eColorIndex : int | ||
{ | ||
R = 0, | ||
G = 1, | ||
B = 2, | ||
A = 3 | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static
has no effect here.
Enum may be private
Values can be be assigned by default here. You don't need all these = 0
, = 1
...
It declares R, G, B, A as valid values in CClientVectorGraphicDisplay methods. It's not critical, but bad
The next lunasvg version has no Faster convert function void CClientVectorGraphicDisplay::UnpremultiplyBitmap(Bitmap &bitmap)
{
auto width = bitmap.width();
auto height = bitmap.height();
auto stride = bitmap.stride();
auto rowData = bitmap.data();
for (std::uint32_t y = 0; y < height; y++)
{
auto data = rowData;
for (std::uint32_t x = 0; x < width; x++)
{
auto &b = data[0];
auto &g = data[1];
auto &r = data[2];
auto &a = data[3];
if (a != 0)
{
r = (r * 255) / a;
g = (g * 255) / a;
b = (b * 255) / a;
}
data += 4;
}
rowData += stride;
}
} Avoid additional memory allocation and memcpy IDirect3DSurface9* surface = m_pVectorGraphic->GetRenderItem()->m_pD3DRenderTargetSurface;
if (!surface)
return;
// Lock surface
D3DLOCKED_RECT LockedRect;
if (SUCCEEDED(surface->LockRect(&LockedRect, nullptr, D3DLOCK_DISCARD)))
{
auto surfaceData = static_cast<std::uint8_t*>(LockedRect.pBits);
auto stride = static_cast<std::uint32_t>(LockedRect.Pitch);
Bitmap bitmap{surfaceData, pVectorGraphicItem->m_uiSizeX, pVectorGraphicItem->m_uiSizeY, stride};
svgDocument->render(bitmap);
UnpremultiplyBitmap(bitmap);
// Unlock surface
surface->UnlockRect();
} |
Just making sure status is known, as this was discussed on Discord - I tried the above code but unfortunately the size of the resulting texture seems to be slightly off, by a few pixels? I'll get some screenshots later, but in this case it looks like drawing a 103x103 rect to a 100x100 canvas at 0x0. Maybe there are differences in texture generation from |
Resolves #3828
bg.png