mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-02-21 03:21:28 +00:00
remove copying from CreateTexBuffer
This commit is contained in:
parent
3b6c8349da
commit
1c3764ec89
3 changed files with 23 additions and 6 deletions
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue