remove copying from CreateTexBuffer

This commit is contained in:
Ricardo Luís Vaz Silva 2024-04-11 21:14:09 -03:00 committed by Rachael Alexanderson
parent 3b6c8349da
commit 1c3764ec89
3 changed files with 23 additions and 6 deletions

View file

@ -253,6 +253,8 @@ public:
CopyPixelDataRGB(originx, originy, src.GetPixels(), src.GetWidth(), src.GetHeight(), 4, src.GetWidth()*4, 0, CF_BGRA, inf);
}
friend class FTexture;
};
bool ClipCopyPixelRect(const FClipRect *cr, int &originx, int &originy,

View file

@ -354,17 +354,29 @@ FTextureBuffer FTexture::CreateTexBuffer(int translation, int flags)
if (!checkonly)
{
buffer = new unsigned char[W * (H + 1) * 4];
memset(buffer, 0, W * (H + 1) * 4);
auto remap = translation <= 0 || IsLuminosityTranslation(translation) ? nullptr : GPalette.TranslationToTable(translation);
if (remap && remap->Inactive) remap = nullptr;
if (remap) translation = remap->Index;
FBitmap bmp(buffer, W * 4, W, H);
int trans;
auto Pixels = GetBgraBitmap(remap ? remap->Palette : nullptr, &trans);
bmp.Blit(exx, exx, Pixels);
if(!exx && Pixels.ClipRect.x == 0 && Pixels.ClipRect.y == 0 && Pixels.ClipRect.width == Pixels.Width && Pixels.ClipRect.height == Pixels.Height && (Pixels.FreeBuffer || !IsLuminosityTranslation(translation)))
{
buffer = Pixels.data;
result.mFreeBuffer = Pixels.FreeBuffer;
Pixels.FreeBuffer = false;
}
else
{
buffer = new unsigned char[W * (H + 1) * 4];
memset(buffer, 0, W * (H + 1) * 4);
FBitmap bmp(buffer, W * 4, W, H);
bmp.Blit(exx, exx, Pixels);
}
if (IsLuminosityTranslation(translation))
{
V_ApplyLuminosityTranslation(LuminosityTranslationDesc::fromInt(translation), buffer, W * H);

View file

@ -169,6 +169,7 @@ union FContentIdBuilder
struct FTextureBuffer
{
uint8_t *mBuffer = nullptr;
bool mFreeBuffer = true;
int mWidth = 0;
int mHeight = 0;
uint64_t mContentId = 0; // unique content identifier. (Two images created from the same image source with the same settings will return the same value.)
@ -177,7 +178,7 @@ struct FTextureBuffer
~FTextureBuffer()
{
if (mBuffer) delete[] mBuffer;
if (mBuffer && mFreeBuffer) delete[] mBuffer;
}
FTextureBuffer(const FTextureBuffer &other) = delete;
@ -187,6 +188,7 @@ struct FTextureBuffer
mWidth = other.mWidth;
mHeight = other.mHeight;
mContentId = other.mContentId;
mFreeBuffer = other.mFreeBuffer;
other.mBuffer = nullptr;
}
@ -196,6 +198,7 @@ struct FTextureBuffer
mWidth = other.mWidth;
mHeight = other.mHeight;
mContentId = other.mContentId;
mFreeBuffer = other.mFreeBuffer;
other.mBuffer = nullptr;
return *this;
}