我试图编写一个将图像解包为单独四边形的函数。但由于某种原因,结果是扭曲的(有点拉伸45度),所以我必须错误地读取像素阵列,虽然我无法看到我的功能问题......
该函数需要2个unsigned char数组," source "和" 目标"和两个unsigned int值," 宽度"和" 身高"源图像。宽度可分为4,高度可分为3(两者都返回相同的值,因为纹理为600 * 450),因此每个面都是150 * 150像素。所以w / h值是正确的。然后它也需要2个整数," xIt "和" yIt "确定偏移量 - 应该读取150 * 150块。
这里的功能是:
const unsigned int trgImgWidth = width / 4;
const unsigned int trgImgHeight = height / 3;
unsigned int trgBufferOffset = 0;
// Compute pixel offset to start reading from
unsigned int Yoffset = yIt * trgImgHeight * width * 3;
unsigned int Xoffset = xIt * trgImgWidth * 3;
for (unsigned int y = 0; y < trgImgHeight; y++)
{
unsigned int o = Yoffset + Xoffset; // Offset of current line of pixels
for (unsigned int x = 0; x < trgImgWidth * 3; x++) // for each pixel component (rgb) in the line
{
target[trgBufferOffset] = source[o + x];
trgBufferOffset++;
}
Yoffset += width * 3;
}
任何人都会在这里看到我可能出错的地方?