C 中的位打包
我正在尝试将 RGB 图像转换为 ARGB 图像,基本上只是为 alpha 通道添加 255。 我想知道是否有任何包方法可以在不迭代的情况下执行此操作? 因此,要迭代 RGB 数据并将 255 附加到每个像素。
I'm trying to convert an RGB image to an ARGB image, basically just adding 255 in for the alpha channel. I was wondering if there is any pack method to do this without iteration? So to iterate over my RGB data and append the 255 to each pixel.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
C 没有“方法”……不,这听起来不像标准库中的例程。 我认为你需要自己编码,使用如下内容:
基本假设:
还要注意循环的顺序; 由于缓存,这会对现实世界的性能产生巨大的影响。 这段代码按顺序接触内存中接近的像素,这很好地称为“良好的局部性”。
将指针更改为指向下一个像素而不是声明地址 (
rgba[4 * y * width + 4 * x + 3]
) 也是一种优化,并且(对我来说)很容易理解。C doesn't have "methods" ... And no, this doesn't sound like anything there's a routine for in the standard library. I think you need to code it yourself, using something like this:
Basic assumptions:
Also note order of loops; this can make a huge difference to real-world performance due to caching. This code touches pixels that are close in memory in sequence, which is good called "good locality".
Changing the pointer to point at the next pixel rather than stating the address (
rgba[4 * y * width + 4 * x + 3]
) is also an optimization, and (to me) easy enough to understand.