- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在尝试解压缩 targa (RGB24_RLE) 图像数据。
我的算法是这样的:
static constexpr size_t kPacketHeaderSize = sizeof(char);
//http://paulbourke.net/dataformats/tga/
inline void DecompressRLE(unsigned int a_BytePerPixel, std::vector<CrByte>& a_In, std::vector<CrByte>& a_Out)
{
for (auto it = a_In.begin(); it != a_In.end();)
{
//Read packet header
int header = *it & 0xFF;
int count = (header & 0x7F) + 1;
if ((header & 0x80) != 0) //packet type
{
//For the run length packet, the header is followed by
//a single color value, which is assumed to be repeated
//the number of times specified in the header.
auto paStart = it + kPacketHeaderSize;
auto paEnd = paStart + a_BytePerPixel;
//Insert packets into output buffer
for (size_t pk = 0; pk < count; ++pk)
{
a_Out.insert(a_Out.end(), paStart, paEnd);
}
//Jump to next header
std::advance(it, kPacketHeaderSize + a_BytePerPixel);
}
else
{
//For the raw packet, the header s followed by
//the number of color values specified in the header.
auto paStart = it + kPacketHeaderSize;
auto paEnd = paStart + count * a_BytePerPixel;
//Insert packets into output buffer
a_Out.insert(a_Out.end(), paStart, paEnd);
//Jump to next header
std::advance(it, kPacketHeaderSize + count * a_BytePerPixel);
}
}
}
这里调用:
//Read compressed data
std::vector<CrByte> compressed(imageSize);
ifs.seekg(sizeof(Header), std::ifstream::beg);
ifs.read(reinterpret_cast<char*>(compressed.data()), imageSize);
//Decompress
std::vector<CrByte> decompressed(imageSize);
DecompressRLE(bytePerPixel, compressed, decompressed);
imageSize
定义如下:
size_t imageSize = hd.width * hd.height * bytePerPixel
但是,在 DecompressRLE() 完成后(对于 2048x2048 纹理,这需要很长时间)解压缩仍然是空的/仅包含零。也许我错过了一些东西。
count
有时似乎高得不合理,我认为这是不正常的。compressedSize
应该 小于 imageSize,否则不会被压缩。但是,使用 ifstream::tellg()
给我错误的结果。有帮助吗?
最佳答案
如果您仔细查看调试器中的变量,您会看到 std::vector<CrByte> decompressed(imageSize);
用 imageSize
声明一个 vector 其中的元素。在 DecompressRLE
然后在该 vector 的末尾插入,使其增长。这就是为什么您的解压缩图像充满零,也是为什么需要这么长时间(因为 vector 会定期调整大小)。
你要做的是预留空间:
std::vector<CrByte> decompressed;
decompressed.reserve(imageSize);
您的压缩缓冲区看起来比文件内容大,因此您仍在解压缩文件末尾。压缩后的文件大小应该在Header
.使用它。
关于c++ - Targa 运行长度编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43282492/
我目前正在尝试解压缩 targa (RGB24_RLE) 图像数据。 我的算法是这样的: static constexpr size_t kPacketHeaderSize = sizeof(char
我的 Targa 阅读器有非常非常小的问题。一个像素关闭,另外 2 个像素为黑色 :S 我正在加载的 24 位 targa 文件如下所示: 请注意左上角的白色像素。左上角的第一个像素是白色的。 但是当
由于是新人,我只能有两个链接,不能发布我的图片。对于不得不复制+粘贴地址给您带来的不便,我们深表歉意 我正在解析一个 Targa (.tga) 图像文件,其代码类似于在 steinsoft.net/i
我在尝试编写 *.tga 文件阅读器时遇到了问题。对于 32 位 targas,photoshop 用 255 填充 alpha channel ,这仍然是标准的,并且有效,但在 16 位 targa
如标题所示,我在加载 .tga 文件时遇到了问题。我一直在使用 this仅供引用,据我所知(除了使用 c++ 函数而不是 c 函数)我也在做同样的事情。我确实得到了一个纹理,但它应该是一个乱码版本,我
我正在尝试为我的 3D 模型创建纹理。只要我只加载图像文件,它就可以正常工作。我正在使用 Microsoft Visual C++ 2008 Express,我一直在寻找解决这个“问题”的方法,将资源
我是一名优秀的程序员,十分优秀!