水平翻转一位位图线
我正在寻找一种算法来水平翻转 1 位位图线。请记住这些行是 DWORD 对齐的!
我目前正在将 RLE 流取消编码为每像素 8 位缓冲区,然后重新编码为 1 位行,但是,我想尝试将其全部保留在 1 位空间中,以努力增加其速度。分析表明程序的这一部分与其余部分相比相对较慢。
示例行(翻转前):
FF FF FF FF 77 AE F0 00
示例行(翻转后):
F7 5E EF FF FF FF F0 00
I'm looking for an algorithm to flip a 1 Bit Bitmap line horizontally. Remember these lines are DWORD aligned!
I'm currently unencoding an RLE stream to an 8 bit-per-pixel buffer, then re-encoding to a 1 bit line, however, I would like to try and keep it all in the 1 bit space in an effort to increase its speed. Profiling indicates this portion of the program to be relatively slow compared to the rest.
Example line (Before Flip):
FF FF FF FF 77 AE F0 00
Example line (After Flip):
F7 5E EF FF FF FF F0 00
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建一个转换表来交换字节中的位:
现在您可以使用该表来交换字节,然后只需将该字节存储在结果中的正确位置即可:
输出:
Create a conversion table to swap the bits in a byte:
Now you can use the table to swap a byte, then you just have to store the byte in the right place in the result:
Output:
以下代码读取并反转 32 位块中的数据作为整数。用于反转位的代码被分为两部分,因为在小端机器上将四个字节读取为 32 位整数会反转字节顺序。
它有点丑陋,而且对错误的鲁棒性不强……但它只是示例代码。它输出以下内容。
The following code reads and reverses the data in blocks of 32 bits as integers. The code to reverse the bits is split into two parts because on a little endian machine reading four bytes as an 32 bit integer reverses the byte order.
It is a bit ugly and not robust against errors ... but it is just sample code. And it outputs the following.