mirror of
https://github.com/yuzu-emu/FasTC
synced 2024-11-23 14:23:37 +00:00
Make sure that we assume pixels are in block stream order when accessing.
This commit is contained in:
parent
1424765866
commit
3bc9510996
1 changed files with 20 additions and 3 deletions
|
@ -1,7 +1,24 @@
|
|||
#include "ImageWriter.h"
|
||||
|
||||
uint32 ImageWriter::GetChannelForPixel(uint32 x, uint32 y, uint32 ch) {
|
||||
uint32 bytesPerRow = GetWidth() * 4;
|
||||
uint32 byteLocation = y * bytesPerRow + x*4 + ch;
|
||||
return m_PixelData[byteLocation];
|
||||
|
||||
// Assume pixels are in block stream order, hence we would need to first find
|
||||
// the block that contains pixel (x, y) and then find the byte location for it.
|
||||
|
||||
const uint32 blocksPerRow = GetWidth() / 4;
|
||||
const uint32 blockIdxX = x / 4;
|
||||
const uint32 blockIdxY = y / 4;
|
||||
const uint32 blockIdx = blockIdxY * blocksPerRow + blockIdxX;
|
||||
|
||||
// Now we find the offset in the block
|
||||
const uint32 blockOffsetX = x % 4;
|
||||
const uint32 blockOffsetY = y % 4;
|
||||
const uint32 pixelOffset = blockOffsetY * 4 + blockOffsetX;
|
||||
|
||||
// There are 16 pixels per block and bytes per pixel...
|
||||
uint32 dataOffset = blockIdx * 4 * 16;
|
||||
dataOffset += 4 * pixelOffset;
|
||||
dataOffset += ch;
|
||||
|
||||
return m_PixelData[dataOffset];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue