我有以下图像,我想旋转并翻转它以使其适合全屏分辨率。 我正在进行以下转换,旋转,但它不起作用。
size_t bpp = Ogre::PixelUtil::getNumElemBytes(source.getFormat());
const unsigned char *srcData = source.getData();
unsigned char *dstData = new unsigned char[width * height * bpp];
size_t srcPitch = source.getRowSpan();
size_t dstPitch = width * bpp;
ImageDescriptor sourceImage(source.getWidth(), source.getHeight(), bpp);
ImageDescriptor rotatedTarget(source.getHeight(), source.getWidth(), bpp); // note width/height swap
unsigned char *rotated = new unsigned char[source.getHeight() * source.getWidth() * bpp];
for (std::size_t row = 0; row < rotatedTarget.mHeight; ++row) {
for (std::size_t col = 0; col < rotatedTarget.mWidth; ++col) {
for (std::size_t chan = 0; chan < rotatedTarget.mChannels; ++chan) {
rotated[rotatedTarget.offset(col, row, chan)] =
srcData[sourceImage.offset(row, col, chan)];
}
}
}
struct ImageDescriptor {
std::size_t mWidth;
std::size_t mHeight;
std::size_t mChannels;
ImageDescriptor(std::size_t width, std::size_t height, std::size_t channels)
{
mWidth = width;
mHeight = height;
mChannels = channels;
}
std::size_t stride() const { return mWidth * mChannels; }
const std::size_t offset(std::size_t row, std::size_t col, std::size_t chan) {
assert(0 <= row && row < mHeight);
assert(0 <= col && col < mWidth);
assert(0 <= chan && chan < mChannels);
// return row*stride() + col*mChannels + chan;
// or, depending on your coordinate system ...
return (mHeight - row - 1)*stride() + col*mChannels + chan;
}
std::size_t size() const { return mHeight * stride(); }
};
有什么想法吗?
答案 0 :(得分:0)
很简单,反转行,改变
rotated[rotatedTarget.offset(col, row, chan)] =
srcData[sourceImage.offset(row, col, chan)];
到
rotated[rotatedTarget.offset(rotatedTarget.mWidth-col-1, row, chan)] =
srcData[sourceImage.offset(row, col, chan)];
无论如何都是这样的。我对你的代码感到有点困惑。