opengl c++:如何将 32 位 png 文件转换为 16 位 565RGB 文件
我正在尝试将 32 位 png 文件转换为 16 位文件格式,我了解如何在彼此之间转换 16 位文件格式(例如 RGB565 RGBA4444),但是我不确定如何从 32 位转换为 16 位。
我的主要问题是:如何找到 32 位 png 的存储方式(每个 8 位分配给 R、B、G 和 A 值)?
如何失去精度但仍保持大致相同的值?
提前致谢
I am trying to convert 32bit png files to 16 bit file formats, I understand how to convert 16 bit file formats between eachother (e.g RGB565 RGBA4444) However I'm not sure how to go about converting from a 32 bit to a 16 bit.
My main questions are: How do I find how the 32 bit pngs stored (are 8 bits each assigned to R,B,G, and A values)?
How do I lost precision but still maintain roughly the same value?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 libpng 比手动实现要好得多。
You'd be much better off using libpng than implementing this by hand.
我不熟悉 32 位 png 像素的确切布局,但假设它与其他格式相对一致,您可能想做类似的事情:
考虑这个伪代码。
有人可能会争辩说,屏蔽最低有效位(尤其是从 8 位转换为 4 位时)并不是在两者之间进行转换的好方法,而且他们是对的。您可以使用转换函数:
I am not familiar with the exact layout of the 32bit png pixel, but assuming it is relatively consistent with other formats you probably want to do something similar to this:
Consider this pseudocode.
One could argue that masking off the least significant bits, especially when converting from 8 bit to 4 bit, is not a very good way to convert between the two, and they would be right. You could instead use a conversion function: