Fix image buffer stride issues

This commit is contained in:
nsubiron 2018-09-29 18:27:37 +02:00
parent 367a6b51eb
commit 282789548e
1 changed files with 5 additions and 6 deletions

View File

@ -134,7 +134,7 @@ void FPixelReader::WritePixelsToBuffer(
const uint32 BytesPerPixel = 4u; // PF_R8G8B8A8 const uint32 BytesPerPixel = 4u; // PF_R8G8B8A8
const uint32 Width = Texture->GetSizeX(); const uint32 Width = Texture->GetSizeX();
const uint32 Height = Texture->GetSizeY(); const uint32 Height = Texture->GetSizeY();
const uint32 ExpectedStride = Width * Height * BytesPerPixel; const uint32 ExpectedStride = Width * BytesPerPixel;
uint32 SrcStride; uint32 SrcStride;
LockTexture Lock(Texture, SrcStride); LockTexture Lock(Texture, SrcStride);
@ -144,14 +144,13 @@ void FPixelReader::WritePixelsToBuffer(
// result stride from the lock: // result stride from the lock:
if (IsD3DPlatform(GMaxRHIShaderPlatform, false) && (ExpectedStride != SrcStride)) if (IsD3DPlatform(GMaxRHIShaderPlatform, false) && (ExpectedStride != SrcStride))
{ {
Buffer.reset(Offset + ExpectedStride); Buffer.reset(Offset + ExpectedStride * Height);
auto DstRow = Buffer.begin() + Offset; auto DstRow = Buffer.begin() + Offset;
const uint32 RowStride = Width * BytesPerPixel;
const uint8 *SrcRow = Lock.Source; const uint8 *SrcRow = Lock.Source;
for (uint32 Row = 0u; Row < Height; ++Row) for (uint32 Row = 0u; Row < Height; ++Row)
{ {
FMemory::Memcpy(DstRow, SrcRow, RowStride); FMemory::Memcpy(DstRow, SrcRow, ExpectedStride);
DstRow += RowStride; DstRow += ExpectedStride;
SrcRow += SrcStride; SrcRow += SrcStride;
} }
} }
@ -160,6 +159,6 @@ void FPixelReader::WritePixelsToBuffer(
{ {
check(ExpectedStride == SrcStride); check(ExpectedStride == SrcStride);
const uint8 *Source = Lock.Source; const uint8 *Source = Lock.Source;
Buffer.copy_from(Offset, Source, SrcStride); Buffer.copy_from(Offset, Source, ExpectedStride * Height);
} }
} }